Tag Info

New answers tagged

0

Every system keeps evolving till the end; Same goes for WordPress. I think reason why post action hooks have evolved much then user related action hooks is because community have been focused on using posts related functionality more then users related stuff. As we all are aware of the fact that; A single author publishes multiple posts Anyways ...


0

I believe you can get the same result what you are looking for with filter hook post_updated_messages. You just need the post id for the confirmation thing that you are doing which you can do over here as well using $_GET['post'] which contains your post id. Here is function which will do the thing. function your_modified_message( $messages ){ ...


0

For removing an action hook you should use the same action name, callback name and the priority that was used to add a action in parent theme. And register it on init add_action( 'init', 'remove_action'); function remove_action() { remove_action( 'woocommerce_before_shop_loop','storefront_sorting_wrapper',9 ); } Read about remove_action


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( ...


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.


0

in my opinion this is a valid scenario, its a solid way to offer your plugin as an interface to other plugins but still each plugin can be active or inactive and wp will not crash (in comparison to calling a method directly which may not exist because a plugin was not activated i solved it by passing an object, like so: // define action with param for ...


0

if you create your own hook, here is example. // lets say we have three parameters [ https://codex.wordpress.org/Function_Reference/add_filter ] add_filter( 'filter_name', 'my_func', 10, 3 ); my_func( $first, $second, $third ) { // code } then implement hook: // [ https://codex.wordpress.org/Function_Reference/apply_filters ] echo apply_filters( ...


0

answer ^^ add_action( 'load-edit.php', function() { global $typenow; // Not our post type, bail out if( 'community' !== $typenow ) return; // Administrator users don't need this, bail out if( current_user_can('add_users') ) return; // Only the Mine tab fills this conditions, redirect if( !isset( $_GET['post_status'] ) && !isset( ...


0

Try this way: add_action( 'save_post', 'myFunc'); function myFunc(){ if ($post->post_type == 'cpt' ) { // do action here } OR add_action( 'save_post', 'myFunc'); function myFunc(){ if ( 'cpt' == get_post_type() ) { // do action here }


0

As @Pieter said, you can use transition_post_status: function wpse_187997_job_status( $new_status, $old_status, $post ) { if ( $post->post_type === 'job' && $new_status !== $old_status ) { // Post type "job" and status has changed } } add_action( 'transition_post_status', 'wpse_187997_job_status', 10, 3 );


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 ...


0

The first thing to do is ensure that your template's header.php and footer.php files contain, respectively, calls to wp_head() and wp_footer(). Without those functions, no actions hooked to wp_head / wp_footer will work.


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', ...


0

What about using save_post or wp_insert_post hook, both have @param     int               $post_ID     Post ID. @param     WP_Post     $post          Post object. @param ...


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 ] ).


0

I think you need to do the add_action( 'wp_head', 'add_meta_tags' , 10 ); in your functions.php instead of the template to get the function called. And it adds it then everywhere where you have wp_head(). So if you want to only call it content-share.php you need some conditioning logic like if (is_page_template('page-templates/content-share.php')) { ...


0

Your problem is with the conditional, not with the used action (I think). This line is probably not verifying in any situation: if( ( $_POST['post_status'] == 'publish' ) && ( $goalsupport === $totalsupport ) ) { I can not now what $goalsupport and $goalsupport are, both variables are undefined in your code, so I'm going to remove them. Change ...


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" ...



Top 50 recent answers are included