Tag Info

New answers tagged

-1

do_action is an event and there are many of them throughout your WordPress instance, in the core or your themes and plugins. (Hypothetical) So even when you put an add_action in your plugin file but the theme files are read first by order of execution your add_action function will still fire at that event or time of the do_action it is hooked to. This is ...


4

Please check also wp-includes/general-templates.php but wp_head() hooks 'wp_head' like this: function wp_head() { do_action( 'wp_head' ); } So I would change your code like this for example: add_action( 'wp_head', 'my_prepare_pick_data' ); add_action( 'my_add_meta_tags', 'my_add_meta_tags' ); function my_prepare_pick_data() { $pick_data = new ...


1

you can use load-{page-hook}. It is called prior to the admin screen loading. add_action( 'load-post-new.php', 'post_listing_page' ); function post_listing_page() { // 'add new' page, you may have to check post type.. } {page-hook} on the 'add new' page of any post type, it is post-new.php {page-hook} on the edit page of any post type, it is ...


0

function on_post_scheduled( $post_id, $post ) { // If this is just a revision, don't do anything. if ( wp_is_post_revision( $post_id ) ) return; // If this is a 'post' post and post status is future. if ( ('post' == $post->post_type) && ('future' == $post->post_status)) { // do the thing zhu li! ...


0

I think Михаил Семёнов is right, but I had to get another push by cybmeta in another thread, which lead to this: functions.php: $menu_alterations = array( 'user' => array('my-userA', 'my-userB'), 'items' => array('plugins.php', 'options-general.php'), 'action' => false, ); include get_template_directory() . ...


1

If anyone should be faced with this problem, check if you have defined a callback function to set the user_login on pre_user_login. This filter is applied inside the wp_insert_user()-function and produced a same username again. Therefore the nicename was changed by adding a "-2". So, my problem was that I reset the user_logins again and again, instead of ...


1

You are using it wrong. add_action: attachs a function to an action hook. In your code, you are attaching alter_item funtion to admin_menu action hook. So, when admin_menu action happens, alter_item function is executed. According to codex, no parameters are passed to functions attached to admin_menu. So, the parameters your are trying to use in alter_item ...


0

If you use do_action( 'woo_collections_menu' ); in the template, then your function must echo its value. Otherwise, you are returning the data into a black hole, nothing is outputting what you're returning. If you use a filter, then you should return the value. The point of a filter is to take a value, filter that value through a function, then do something ...


0

I still couldn't figure out how to return $woo_menu; with my first example code, but I realized things don't break if I keep the rest of the structure as far as the variable goes and just echo once at the very end. This seems to work for me. Whether this is good practice or not, leave me a comment, but for now, this is the solution I'm using. Thanks. ...


1

From my understanding of actions (as opposed to filters), an action simply does something and stops processing. No return value is actually made use of. You might change your code to be a filter by accepting an argument (say the html to append to) and then make a call like the following where you want to grab the code: $html_block = ...


1

It's becouse you'r calling alter_item function outside action admin_menu here's working example i just made, try to figure what's wrong with your's by your self, if you fail i'll explain add_action( 'admin_menu', 'alter_items' ); function alter_items() { global $current_user, $menu; get_currentuserinfo(); $scopes = apply_filters( 'alter_items', ...


1

You are using after_theme_switch action but the correct name is after_switch_theme. Also, you won't see the echo statements on after_theme_switch and switch_theme. To debug things in that hooks you can use, for example, error_log() function and look for messages in PHP error log file (you need to have errors "On" and/or WP_DEBUG enabled). I've tested this ...


1

As an alternative, you can make use of the 'transition_post_status' hook for this. This hook is fired whenever a post's status is changed. In your case, you need to check whether the old and new status of the post is the same, which is publish You can also set conditionals according to $post, which is the current post being updated/published etc. You can ...


1

You can user Milo 's answer or you can use the conditional inside the hooked function, and then compare the post_date and the post_modified. add_action('save_post', array($this, 'updatePost'), 10, 3); function updatePost($post_id){ // If this is just a revision, don't send the email. if ( wp_is_post_revision( $post_id ) ) return; $post = ...


1

You can use post status transition actions for this. function wpd_updating_a_published_post( $post ){ // do something } add_action( 'publish_to_publish', 'wpd_updating_a_published_post', 10, 1 );


1

Hooks are going to be your best friend here. You can filter post content by using the the_content filter for example: add_filter('the_content', 'wse_174099_append_to_content'); function wse_174099_append_to_content( $content ) { //get your data $custom_items = get_option( 'option_name' ); $content .= wpautop( $custom_items ); //always ...



Top 50 recent answers are included