Tag Info

Hot answers tagged

4

The name of the current hook is always current_filter(). Despite its name, this function returns the name of actions too. Usage example: Move the textarea in a comment form. The current priority is: key( $GLOBALS['wp_filter'][ $hook ] ).


3

There is a dynamic hook right before any new metadata is added: do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value ); It would be add_post_meta for posts accordingly. Note that you might to tinker some to catch this precisely in the case of new post being created, for example hook into publish_post first, note the ID, and add to this ...


3

Make the hook name specific to what it does, not where it is called. Do not pass multiple parameters, because that is not easy to extend. Pass a parameter object instead. Example Create the parameter object with an interface for dependency injection: interface Validation_Parameters { public function id(); public function errors(); // not a ...


3

wp_loaded is called long, long before the post content is fetched. Put that code into a plugin. Also, you shouldn't echo anything that early. The HTTP headers aren't sent yet on wp_loaded, so you will get the Headers already sent error, and your user authentication will not work: you cannot log in anymore.


2

OK, so your first problem is that $current_user->roles is an array and not a string, so your condition won't be true ;) My another concern would be the hook you're using. Some plugins may use it for other purposes, and killing the script can be harmful. And... there is much better hook for this ;) First solution: using login_redirect hook function ...


1

For mee it seems that the template_redirect hook worked. Thanks to Pieter Goosen. Heres a solution that should work on earlier hooks: function gdymc_object_exists( $object_id ) { return ( get_the_title( $object_id ) ) ? true : false; } function gdymc_objectID() { if( is_numeric( $_GET['page_id'] ) ): $object_id = $_GET['page_id']; ...


1

I understand, that you add the possibilties for developers to change the html, typical a template part. That is the point, that I think you should use the default functionality for this job. get_page_template() can be overridden via the page_template filter. A simple example for the dev to change your templates from your plugin. add_filter( ...


1

Method 1 is much more robust and extendable, in my opinion. The main reason is that to add or remove forms, with Method 1 you just add or remove a function rather than modify an existing one, as in Method 2. a) Thus, with Method 1 you can add or remove functionality from other files, in particular from separate modules of your plugin or other external ...


1

You cannot insert the do_action() inside the class like that, it's gonna give you a fatal error. Instead you could use an array $skins to store all the skin functions (as closures), and the magic method _call() to call them: class skinclass { private $skins = array(); function __construct() { $this->skins = apply_filters( 'add_skin', ...



Only top voted, non community-wiki answers of a minimum length are eligible