Tag Info

New answers tagged

0

Personally I would use wp_get_current_user(), no globals: function plugin_admin_init() { $user = wp_get_current_user(); }


1

Maybe you use the hook deleted_post and create a rewrite. The hook runs just after a post or page is deleted. Action function arguments is post- or page-ID.


1

The problem is that you can't distinguish form an anonymous function and another, so yes, it is possible to remove a closure (i.e. anonymous function) but if more than one closure act on same filter at same priority you have to make a choice, remove them all, ore remove only one (without knowing exactly which). I'll show how to remove them all using a ...


2

Scripts and stylesheets should always be loaded in the head or in the footer via the wp_enqueue_scripts action hook. wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end The init hook executes before wp_head which is to early for script to load in the header. The wp_enqueue_scripts action hook is ...


2

You should first load your scripts with a hook on wp_enqueue_scripts like this for example : add_action( 'wp_enqueue_scripts', 'load_my_scripts' ); function load_my_scripts() { wp_enqueue_script( 'jquery' ); } What I like to do is, register my script with a hook on init and then enqueue them with a hook on wp_enqueue_scripts: // Register Scripts ...


1

setup_theme run on init theme, before after_setup_theme. The follow order on frontend, was fired in my test: load_textdomain plugins_loaded auth_cookie_valid set_current_user sanitize_comment_cookies setup_theme after_setup_theme init


3

'the_posts' is an action fired everytime WP_Query get posts, for main query and for other secondary queries, so when you do something like: $foo = new WP_Query($args); in a widget or elsewhere (shortcode, related posts...) 'the_posts' is triggered again. However there is only one main query, so you can use a conditional and do what you do only if the ...


0

Because you calling get_post_types() in functions.php that is excuted before 'init' action. Look this picture http://www.rarst.net/images/wordpress_core_load.png if you add an echo inside function test function test(){ $args = array( 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, ...


1

In your code, you are executing get_post_types() before the post type is registered. Try, for example, this: function test(){ $args = array( 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'exclude_from_search' => true, ...


1

What if you add your filter, with the priority 11, so it goes after? That's ugly, but might work in your case. add_filter( 'manage_edit-comments_columns', function( $default ) { unset( $default['smr_comment_rate'] ); return $default; }, 11, 1 );


0

date_error seems to be a function of that class, so you'll have to use add_action('edit_user_profile', array($this, 'date_error')); However I am not entirely sure that'll work because I don't know when this function is called. It might already be too late to register the hook.


0

I have created new colums in a SQL table 'wp_users'. Those fields are "giodo", "handel" and "regulamin". Don't add columns to Core tables. There is no guarantee that these won't be destroyed or corrupted on next update. What you should be using is user meta, and in fact that appears to be what you are actually using: add_action('user_register', ...


0

To use get_term_by we need the term object before it gets deleted. Therefore, we should use the action hook delete_term_taxonomy that runs before the term is deleted. Now, we can go ahead and perform some tasks such as deleting all the postmeta related to the term being deleted. The code is: add_action( 'delete_term_taxonomy', function($tt_id) { ...


0

The hook that is running before deleting the term is 'delete_term_taxonomy' And it is the hook needed in order to use the term_id before it gets deleted. Now, we can proceed to retrieve the term object and delete the postmeta related to the term being deleted. The code is as follows: add_action( 'delete_term_taxonomy', function($tt_id) { $taxonomy = ...


0

I finally found the solution to delete all the postmeta related to the term being deleted. For this, we need to use the action hook 'delete_term_taxonomy' because it is executed before the term is deleted; therefore, we can find the term object and use it inside the hook. Then, we proceed to perform certain task such as deleting all postmeta related to the ...


0

Actually, you can use multiple actions, at least this is what at the end of the wp_delete_term function, which runs when you click Delete on a taxonomy term: do_action( 'delete_term_taxonomy', $tt_id ); do_action( 'deleted_term_taxonomy', $tt_id ); do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term ); do_action( "delete_$taxonomy", $term, ...


3

There are several hooks in get_the_post_thumbnail for example begin_fetch_post_thumbnail_html end_fetch_post_thumbnail_html /wp-includes/post-thumbnail-template.php You could add a function to one of these actions which removes your filter on first run. If you need further help with this please add some code how you filter the_content.


0

Adding hooks on hooks seems to me pretty profligate-- a waste of resources. If you do that, you have two or more calls to add_user_func_array(), where you would otherwise only have one and that is not to mention the other work that is done processing before that point. The exceptions are: When you need to use a function and need to make sure that that ...


3

Sometimes you want to run some code before deciding to add an action, or a filter. This may involve checking the user's permissions, checking the type of page request, checking whether another plugin is active etc. Some of those checks may not be possible until some way through WordPress' execution - so it's reasonably common to do that work in an init ...


2

If necessary it is easier to remove one function from init than two (or maybe fifty) from all over. It is commonly recommended to not run anything before init hook in general, so that's typical starting point even when it isn't forced by required technical implications.



Top 50 recent answers are included