Is it possible to use object in add_action?

You can do this: class testclass { function test() { echo ‘howdy’; } } add_action(‘wp_head’,array(‘testclass’,’test’)); Or this: $t = new testclass(); add_action(‘wp_head’,array($t,’test’)); It doesn’t work like… $t = new testclass(); add_action(‘wp_head’,’t’); // or this either, for good measure $t = new testclass(); add_action(‘wp_head’,array(‘t’)); .. but I am not sure what you are trying to accomplish … Read more

Removing an action from an external plugin class

Maybe I got you wrong, but why don’t you just put the following line in your functions.php: remove_action(‘eazyest_gallery_thumbnails’, ‘ezg_thumbnails’); If you have a class function hooked to an action, you can use the class name instead of the class object: remove_action( ‘eazyest_gallery_thumbnails’, array(‘EazyestFrontendClassName’, ‘ezg_thumbnails’) ); Right now, I don’t see why this wouldn’t be working. … Read more

Add something to beginning of the content

the_content is also a filter, into which the content is passed as an argument. You simply prepend your content and then return like so. add_filter(‘the_content’,’prepend_this’); function prepend_this($content) { $content = “string to prepend” . $content; return $content }

Cron jobs in a class

I was working with wp_cron last week in a plugin and we have a fight and are no longer on speaking terms, but for reference this is what I do; 1) – set the scheduled cron event on register_activation_hook 2) – remove the scheduled cron event on register_deactivation_hook If you are concerned that your scheduled … Read more

Difference between do_action(‘admin_enqueue_scripts’, $hook_suffix) and do_action(“admin_print_styles-$hook_suffix”) syntax

For … do_action(‘admin_enqueue_scripts’, $hook_suffix); … the callback gets the hook suffix as first parameter. Since it is an action you don’t have to return anything. You can use it in a rather flexible callback function: add_action(‘admin_enqueue_scripts’, ‘wpse_49993_admin_script_callback’ ); function wpse_49993_admin_script_callback( $hook_suffix ) { switch ( $hook_suffix ) { case ‘index.php’: // dashboard // do one … Read more

Are ‘wp_ajax’ and ‘wp_ajax_nopriv’ exclusive to authenticated and non-authenticated users?

Looking at the WordPress source code, I’d say that wp_ajax_nopriv_* fires only if you’re not logged in, and wp_ajax_* fires otherwise. Here’s the relevant bit, in admin-ajax.php, lines 85-115 in version 5.0.3: if ( is_user_logged_in() ) { // If no action is registered, return a Bad Request response. if ( ! has_action( ‘wp_ajax_’ . $_REQUEST[‘action’] … Read more

Create posts on user registration

You kind of answered the question yourself already, Create a function that will create the 3 posts ex: function create_new_user_posts($user_id){ if (!$user_id>0) return; //here we know the user has been created so to create //3 posts we call wp_insert_post 3 times. // Create post object $my_bio_post = array( ‘post_title’ => ‘bio’, ‘post_content’ => ‘This is … Read more