[wp-hackers] add_action arrays?

Jacob Santos wordpress at santosj.name
Thu Sep 24 00:09:34 UTC 2009


You are not alone and others have pointed out the obvious omission of documentation about the aforementioned array callback format in WordPress inline documentation. This is, as I have pointed out before, because PHP itselfs has documentation on this and a check for callable "type"[1] should have lead you to many great resources on this information. Meh, I believe a little attempt at explaining this is also in WordPress, but where I'm unsure, and I could be mistaken.

As others have provided said information in this thread, I would assume this matter to be closed. However, since this is the second time that I'm aware of someone having a problem with lack of PHP information, I think providing a link to the callable "type"[1] documentation should be provided in WordPress to provide an opportunity for fellow WordPress developers, as well as plugin and theme developers to learn.

I was also unaware that this was a general PHP help forum. Well, to be fair, if said question was posted on PHP help forums, the response might have been, "RTFM" or "Ask WordPress" along with some disparaging remark about your mother or your lack of certain skills, but with a 'z' instead of a 's' and I will assume in some ironic attempt to be clever[2].

I'm not exactly sure how one would fit in pointers to the callable type, I believe it is somewhere already in the plugin API inline documentation, but there is a lot of wording, much of which is relevant to WordPress specifically. I believe it might have been put in arbitrary at one point once it was realized that one might not have any idea what the callable type actually was and couldn't be concerned to search on Google or PHP.net, but then it was realized that you must be this tall to ride and those that aren't are probably going suffer from other, more pressing problems. 

Jacob Santos

[1] While PHP suggests that it isn't an actual native type, not like it is in JavaScript, it still has some "magic" to it like a language type. Well, we're not speaking of PHP5.3 which makes it closer to one, but still not native.

[2] We've all done this, right, at some point? Good times.

On Wed, 23 Sep 2009 08:00:45 -0400
Thomas Belknap <dragonfly at dragonflyeye.net> wrote:

> I've seen a few plugins and bits of code internal to WordPress use the
> following convention:
> add_action('pre_get_posts', array(&$this, 'postFilter'));
> But this usage is not documented anywhere? I attempted to use the same
> convention and got the following error:
> call_user_func_array() [function.call-user-func-array]: First argument
> is expected to be a valid callback, 'Array' was given in blah, blah,
> blah...
> I was looking at the code for add_action and add_filter, and they
> definitely seem to not take arrays into account as far as I can tell.
> Is this a deprecated way of doing things? Is there some other way to
> hook an object method into an action or filter?
> Thanks!

More information about the wp-hackers mailing list