Which hook should be used to add an action containing a redirect?
Like kaiser answered template_redirect hook is indeed appropriate for redirects. Also you should use wp_redirect() function, rather than setting header.
Like kaiser answered template_redirect hook is indeed appropriate for redirects. Also you should use wp_redirect() function, rather than setting header.
You can see the detailed list of the hook using this snippet: $hook_name=”admin_bar_menu”; global $wp_filter; var_dump( $wp_filter[$hook_name] );
Try to see the function with better names: apply_filters( $filter_name, // used for add_filter( $filter_name, ‘callback’ ); $value_to_change, // the only variable whose value you can change $context_1, // context $context_2 // more context ); So when that function is called as: // wp-login.php line 94 apply_filters( ‘login_body_class’, $classes, $action ); You can use … … Read more
Thanks to @toscho for the useful answer, but it felt a bit hackish to me, so I poked around a bit and figured out I could add a filter instead: function wpa18013_add_pages_to_dropdown( $pages, $r ){ if(‘page_on_front’ == $r[‘name’]){ $args = array( ‘post_type’ => ‘stack’ ); $stacks = get_posts($args); $pages = array_merge($pages, $stacks); } return $pages; … Read more
Here are some random thoughts on this: Question #1 How much money did we send to grandma? For 100 page loads, we sent her 100 x $1 = $100. Here we actually mean 100 x do_action( ‘init’ ) calls. It didn’t matter that we added it twice with: add_action( ‘init’,’send_money_to_grandma’ ); add_action( ‘init’,’send_money_to_grandma’ ); because … Read more
Overview Basically the “Plugin API,” which summons Filters and Hooks, consists out of the following functions: apply_filters() – execute do_action – execute apply_filters_ref_array() – execute do_action_ref_array() – execute add_filter() – add to stack add_action() – add to stack Basic Internals Overall there’re a couple of globals (what else in WordPress world) involved: global $wp_filter, $wp_actions, … Read more
Use do_action( ‘unique_name’ ) to create your own actions. You can use that to offer an API for your plugin, so other plugins can register callbacks for your custom action. Example: Do I need to call do_action in my plugin? But you can use custom actions (or filters) in a theme too. Example: Best practice … Read more
The wp_insert_post_data filter can do that: add_filter( ‘wp_insert_post_data’ , ‘filter_post_data’ , ’99’, 2 ); function filter_post_data( $data , $postarr ) { // Change post title $data[‘post_title’] .= ‘_suffix’; return $data; }
You can do it like this (put in your functions.php) : function add_admin_scripts( $hook ) { global $post; if ( $hook == ‘post-new.php’ || $hook == ‘post.php’ ) { if ( ‘recipes’ === $post->post_type ) { wp_enqueue_script( ‘myscript’, get_stylesheet_directory_uri().’/js/myscript.js’ ); } } } add_action( ‘admin_enqueue_scripts’, ‘add_admin_scripts’, 10, 1 );
You can use the wp hook and check the global $wp_query object or any conditional. add_action( ‘wp’, ‘wpse69369_special_thingy’ ); function wpse69369_special_thingy() { if ( ‘special_cpt’ === get_post_type() AND is_singular() ) return print “Yo World!”; return printf( ‘<p>Nothing to see here! Check the object!<br /></p><pre>%s</pre>’, var_export( $GLOBALS[‘wp_query’], true ) ); } See: wp in codex.wordpress.org and … Read more