views:

14

answers:

1

I'm probably making a mess of this...

I'm trying to add a filter to the_content that will add a method from an external class, but keep going round in circles.

Can anyone point me in the right direction??

class MyClass {

    var foo;
    var bar;

    function myMethod($id) {
            // some code
    }
}

I'm stuck on accessing myMethod($id) from within a plugin filter like so:

function extendPost($content, '') {
    global $post;
    $id = $post->ID;
    $class = new MyClass();
    // this is where i get stuck
    $myMethod = $class->myMethod($id) // ??;
    $content.= "<div>" . $myMethod . "</div>";
}

add_filter('the_content', 'extendPost');

Any help would be ace. I'd really like to get some sleep tonight ;)

A: 

add_filter() takes a standard PHP callback as an argument.

To apply the extendPost() method of the object $myObject;

add_filter('the_content', array(&myObject, 'extendPost'));

To apply the extendPost() method of the class myClass;

add_filter('the_content', array('myClass', 'extendPost'));
TheDeadMedic