Tag Info

Hot answers tagged

11

I don't think there exist one, but you could create your own, wpse_empty_trash, with something like this: /** * Add a custom hook 'wpse_empty_trash' */ add_action( 'load-edit.php', function() { add_action( 'before_delete_post', function ( $post_id ) { if( 'trash' === get_post_status( $post_id ) && filter_input( ...


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

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

When you send an AJAX request, wp-admin/admin-ajax.php is called, not your template file. This separate request has no knowledge of all existing code in all existing templates, because they aren’t even included. What is included: the theme’s functions.php and plugin files. This is why your callback works in a plugin. As a rule of thumb: templates should ...


1

Makes no difference. Despite the fact add_action doesn't actually check if the callback is indeed callable (i.e. is a valid function/class/method), PHP will first "load" function and class definitions before executing inline code, hence why you can do something like: wpse_185390_function(); // Perfectly fine, even though the function is defined "afterwards" ...


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

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