switch_to_blog(): Load textdomain

You could hook into the action switch_blog. You get the new blog ID as the first argument here. But loading the complete translation files here is expensive, you also have to restore the old files after that. WordPress does not use native gettext functions, but some custom code that is much slower. See #17268. The … Read more

What is the earliest possible hook for safely using `is_front_page`?

The parse_query() method of the WP_Query class sets the variables on which the conditional tags are based. The parse_query hook are executed before returning from parse_query() method, variables are already set (eg. is_home, used by is_front_page()) and is_front_page() will work, but function that changes the current state can be hooked to parse_query (it’s still parse_query() … Read more

Do WordPress Core Filenames Work as Hooks?

The short answer is ‘yes’. Taken from this article the suffix of those ‘screen specific hooks’ is given by: For custom admin pages added via add_menu_page() – including settings pages – (and related functions) it is the screen ID (the value returned by add_menu_page()) For the admin page listing posts of any post type, it … Read more

Adding onload to body

And here’s a jQuery solution (as Mike suggested in his first comment). function add_my_scripts() { wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘my_init_script’, SCRIPTSRC, ‘jquery’, ‘1.0’ ); } add_action( ‘init’, ‘add_my_scripts’ ); Then add a script to your plug-in that does this: jQuery.noConflict(); jQuery(document).ready(function($) { init(); }); This will start jQuery in no conflict mode (if it isn’t … Read more

Implementing advanced add_* function wrappers

For simple cases like quick one-liner returns one should remember that it’s possible to hook an anonymous function directly in the add filter call, e.g: add_filter(‘some_filter_hook’, function($v){return str_replace(‘..’, ‘.’, $v);}); add_action(‘some_action_hook’, function(){echo ‘….’;});

trigger save_post event programmatically

It’s wp_insert_post() vs. wp_update_post() – where update will ultimately also call: return wp_insert_post( $postarr, $wp_error, $fire_after_hooks ); The term “once” implies that it is being fired “afterwards”. /** * Fires once a post has been saved. * * @since 1.5.0 * * @param int $post_ID Post ID. * @param WP_Post $post Post object. * @param … Read more

Is there a WordPress core & plugins update action hook?

Hooks The hooks you’re searching for are ‘pre_set_site_transient_update_plugins’ and ‘upgrader_post_install’ The later takes three arguments. Example: function upgrader_post_install_cb( $true, $hook_extra, $result ) and should be used for: Move & activate the plugin, echo the update message. Moving plugins Moving works like this: $wp_filesystem->move( $result[‘destination’] ,’your_destination_path’ ); Then use activate_plugin( ‘path/file’ ); after moving.

Hooks for trashing, deleting, saving, restoring custom post type

Two action hooks run when a post is trashed wp_trash_post before the post is trashed and trashed_post afterwards. These run for any post type including attachments. See wp-includes/post.php If you want to limit your function to a specific post type you need to run a check in you callback function. function my_trash_action( $post_id ) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)