wordpress - Why does wpmu_new_user not fire inside of a plugin but does inside functions.php? -


i have project complete sites within wordpress multisite blog automatically add users corresponding sites (where plugin enabled)

i hope worded correctly.

the problem: wpmu_new_user hook not fire inside of plugin inside of functions.php

this code:

 add_action( 'wpmu_new_user', 'register_hack_action', 10, 1 );  add_action( 'wpmu_activate_user', 'register_hack_action', 10, 1);   function register_hack_action( $user_id ) {  $this_id = get_current_blog_id();  if ( !defined('abspath') ) {     // nothing } else {     include_once( abspath . 'wp-admin/includes/plugin.php' );  }  $blog_list = get_blog_list( 0, 'all' ); foreach ($blog_list $blog) {     switch_to_blog($blog['blog_id']);     if ( is_plugin_active( 'register-hack/register-hack.php' ) ) {         // add user blog         add_user_to_blog($blog['blog_id'], $user_id, 'subscriber');     }        }     } 

this works fine when add snippet functions.php. when add plugin (which goes wp-content/plugins) , activated on sites, not work. if can try you'll see mean.. don't understand why not work. need inside of plugin , work.

only extensive debugging answer this... kind of stuff better placed inside must use plugin.

must-use plugins (a.k.a. mu-plugins) plugins installed in special directory inside content folder , automatically enabled on sites in installation. must-use plugins not show in default list of plugins on plugins page of wp-admin – although appear in special must-use section – , cannot disabled except removing plugin file must-use directory, found in wp-content/mu-plugins default.

i don't understand why you're using include_once, please, test removing that.


especulations:

  • as normal plugin, should network activated , try encapsulate actions with:

    add_action( 'plugins_loaded', function() {      add_action( 'wpmu_new_user', 'register_hack_action', 10, 1 );      add_action( 'wpmu_activate_user', 'register_hack_action', 10, 1); }); 
  • maybe you're putting inside main site theme?

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -