Bambang pramusintha

Archive for the ‘Uncategorized’ Category

In Uncategorized on July 20, 2012 at 1:02 am

How Method Callbacks are handled in WordPress 2.3+

Here is best explaination where you can building for a new private function was introduced to manage object referenced method callbacks.
The form of which is below.

$myplugin = new MyPlugin();

add_action( ‘init’, array(&$myplugin, ‘_init’) );

As you can see, the callback references the $myplugin variable along with the method in the second element. The reason this can cause a problem, is if you unset the variable afterwards.

$myplugin = new MyPlugin();

add_action( ‘init’, array(&$myplugin, ‘_init’) );


If you think this will magically remove the reference in the hook array, you are mistaken. PHP will retain the reference to the object and will call the method. This will hinder, but not prevent the removal of the object’s callbacks later.

For a workaround, you can recreate the object reference and it should (purely conjecture) recreate the needed hook string to reference to previously added object reference callback. This will not work if two or more object references of the same class were created, so it is assumed that in most cases only one object reference will be created. If only one were created and destroyed, it might be possible to remove the callbacks from the action or filter using the Plugin API. To more explaination, lets see the original pages…

Function Documentation

Prior to WordPress 2.3.0, there was a bug that prevented object referenced method callbacks from being removed. In WordPress 2.3.x and upcoming WordPress 2.5, in order to remove the original method in the class, you have to use the original object reference. In PHP4, where objects are passed by value, this can be a problem, but PHP5 users shouldn’t have much to worry about as long as the variable they are using holds the original class reference.

Explanation of Problem Prior to WordPress 2.3

To demonstrate the problem, take a look at this code. If you were to run this prior to WordPress 2.3, the hook would not be removed because you changed the class property $test.

class MyPlugin
    var $test;

    function MyPlugin() {
        $this->test = false;
        add_action('init', array(&$this, '_init'));
        $this->test = true;

    function init() {
        remove_action('init', array(&$this, '_init));

This is a poor example, in that…

View original post 424 more words


Hello world!

In Uncategorized on June 5, 2012 at 7:21 pm

Welcome to! This is your very first post. Click the Edit link to modify or delete it, or start a new post. If you like, use this post to tell readers why you started this blog and what you plan to do with it.

Happy blogging!

%d bloggers like this: