WordPress Plugin Coding Problem
I'm trying to convert a plugin I wrote proc开发者_如何转开发edurally to be class based, and it's not working for some unknown reason. So I wrote cut down my plugin code to be about as minimilistic as possible. When it runs, it comes back with no content.
<?PHP
/**
* Plugin Name: A1 Test
* Version: 1.0.0
* Plugin URI:
* Description: Test
* Author:
* Author URI:
*/
if ( ! class_exists("TestingDemo") )
{
class TestingDemo
{
function TestingDemo_filter( $buffer )
{
$buffer = preg_replace_callback( '@\[testing\s*=\s*"(.*?)\s*"\]@si',
array(&$this, "TestingDemo_replace"), $buffer );
}
function TestingDemo_replace( $matches )
{
$message = $matches[1];
return "Testing Worked..... {$message}";
}
}
}
if ( class_exists("TestingDemo") )
{
$TestingDemos = new TestingDemo();
}
if ( isset($TestingDemos) )
{
add_filter( 'the_content', array(&$TestingDemos, 'TestingDemo_filter') );
}
I believe you need a return value for your TestingDemo_filter()
function. A Wordpress filter function needs to take a string as input, and return the modified string. Since you've set up TestingDemo_filter()
as the actual filter function, it's going to need a return value.
Edit
I just tested your code, and it definitely works when you add a return
statement to TestingDemo_filter()
.
精彩评论