When to call `add_rewrite_rule` for safety

The easiest solution to this is to hook your add calls on to the last action which gets fired before the rules are rebuilt during the flush process. The first part of the flushing process is to delete the rewrite_rules option. When this happening the following actions will fire: do_action( ‘delete_option’, $option ); do_action( “delete_option_$option”, … Read more

Load different template file when condition met?

Can you perform the logic on the template_include filter? Else, you could set a global/constant and use that in template_include to serve up the appropriate template. The template_include filter filers the path to the template file to be included. To avoid errors you should check if the template exists – locate_template does this for theme/child-theme … Read more

admin_notices after register_uninstall / deactivate_hook

The short answer is no, it is not possible. When you deactivate your plugin, it’s deactivated so doesn’t run your admin_notices action when the admin screen is refreshed. You can confirm it for yourself by using the action in a slightly different way. In your deactivation function include the following line: set_transient(‘my_deactivation_transient’, ‘My plugin is … Read more

With what hook can I address all posts from all custom post types when they are published?

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     bool            $update     Whether this is an existing post being updated or not. as parameters. It is pretty self-explaining that the $update can be used to determine, if it … Read more

Change text of Description in Image Library

Even if is not very flexible filter you can use the gettex hook. Only be aware that this filter runs for every string being translated, so can affect performarce if over-used. To narrow the performance impact you can add it only of admin footer, and remove it just after had use it: add_action(‘admin_footer’, function() { … Read more

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