开发者

Accessing class from Wordpress filter

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

I'm trying to add a fi开发者_StackOverflowlter 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 ;)


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'));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜