views:

28

answers:

1

I'm trying to convert a plugin I wrote procedurally 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') );
}
+1  A: 

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().

zombat
Duh! I cannot blieve i forgot the return.. :( I spent hours trying to figure out what I did wrong.. It's good to have a fresh pair of eyes look at it. Thanks..
Brad
Ha ha, no problem. We've all been there ;)
zombat