Does the event ‘wp_version_check’ even exist? What is it doing?

The function checks your version of WP for possible updates. It appears that there is a transient in the database named ‘update_core’, so it’s stored in the $wpdb->options table as ‘_site_transient_update_core’. The value of that transient is a serialized object that has information, I’m not an expert on wp_version_check, but it uses that transient to … Read more

Difference between do_action_ref_array() and do_action()

If you pass an array to do_action_ref_array(), each element’s value of that array will be passed as a separate parameter to the callback. The keys are lost. If you pass an array to do_action(), the complete array will be passed as one single parameter to the callback. The keys stay intact. Let’s look at the … Read more

Remove an action from an external Class

A simple way to achieve this (but without the Class approach) is by filtering the output of wp_head action hook using the output buffering. In your theme’s header.php, wrap the wp_head() call with ob_start($cb) and ob_end_flush(); functions like: ob_start(‘ad_filter_wp_head_output’); wp_head(); ob_end_flush(); Now in theme functions.php file, declare your output callback function (ad_filter_wp_head_output in this case): … Read more

How to do_action and get a return value?

The cool thing is a filter is the same as an action, only it returns a value, so just set it up as a filter instead: add_filter( ‘myplugin_clean_logs’, array( ‘MyPlugin_Logs’, ‘clean_logs’ ) ); Then something like: $affected_rows=””; $affected_rows = apply_filters( ‘myplugin_clean_logs’, $affected_rows ); should pass $affected_rows to clean_logs() (and whatever other functions you may have … Read more

How to know what priority to use with add_action()?

range of priority values? range of priority values? Generally, speaking, you can’t know a priori what priority something is hooked with. The priority needed depends on how other callbacks where hooked in. Often that is the default value of 10 but it could be anywhere between PHP_INT_MIN (negative integers are still integers) and PHP_INT_MAX and … Read more

Remove parent theme action in child

For removing an action hook you should use the same action name, callback name and the priority that was used to add a action in parent theme. And register it on init add_action( ‘init’, ‘remove_my_action’); function remove_my_action() { remove_action( ‘woocommerce_before_shop_loop’,’storefront_sorting_wrapper’,9 ); } Read about remove_action

Why does save_post action fire when creating a new post?

When you click ‘New Post’, you’re simply loading the page wp-admin/post-new.php. In doing so, WordPress will always create a new post (an ‘Auto Draft’) to ensure all other features (such as media uploads) and plugins work as normal, even before you actually save a draft or publish the post. And this, in turn, triggers save_post. … Read more

add_action reference a class

No, you cannot ‘initialise’ or instantiate the class through a hook, not directly. Some additional code is always required ( and it is not a desirable thing to be able to do that, as you’re opening a can of worms for yourself. Here is a better way of doing it: class MyClass { function __construct() … Read more

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