How to use the do_action () with parameter

The correct way is to pass first argument as a unique string which acts as an identifier for the action & any additional arguments after that do_action(‘unique_action_tag’, $parameter1, $parameter2,,,, & so on); To attach functions to this action you’ll do // 10 is the priority, higher means executed first // 2 is number of arguments … Read more

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

Deactivate plugin for a specific user group

I think the answer to this Disable plugin / plugin action via theme is good for base knowledge on how to disable plugins from code. Adapting that knowledge to your needs will leave us with this: add_action(‘admin_init’, ‘my_filter_the_plugins’); function my_filter_the_plugins() { global $current_user; if (in_array(‘media_manager’, $current_user->roles)) { deactivate_plugins( // deactivate for media_manager array( ‘/advanced-page-manager/advanced_page_manager.php’ ), … Read more

add_action(‘wp_ajax_[action name]’, myfunction) problem

In my projects I do it like that PHP function foo() { echo ‘bar’; } add_action(‘wp_ajax_foo’, ‘foo’ ); // executed when logged in add_action(‘wp_ajax_nopriv_foo’, ‘foo’ ); // executed when logged out Javascript data = { action: ‘foo’, avalue: ‘some value’, ‘anothervalue’: ‘another value’ }; jQuery.post(ajaxurl, data, function(response){ alert(response); });

Why are you using add_action for shortcode?

If you take a look at the Codex page about add_shortcode() you won’t see anything about the need of an add_action() before you can use add_shortcode(). So, you can just put your add_shortcode() directly into your functions.php. This is what I do too. See this article – WordPress Shortcodes: A Complete Guide about the use … Read more

How to validate XML-RPC post creation and cancel when needed?

It looks like the xmlrpc_prepare_post filter is only applied to the output of the wp_getPost and wp_getRevision methods of the wp_xmlrpc_server class. It would be great if this code line: do_action( ‘xmlrpc_call’, ‘wp.newPost’ ); would be replaced with extra input arguments, for example: do_action( ‘xmlrpc_call’, ‘wp.newPost’, …, $content_struct ); but that’s not going to happen … Read more