From bd3770e9d14050309ef2b3f3df86430679261ecc Mon Sep 17 00:00:00 2001 From: r-a-y Date: Tue, 3 Dec 2013 15:52:44 -0800 Subject: [PATCH 1/5] For multisite, register admin menu with the 'network_admin_menu' hook. This allows the "Confirm User Registration" admin page to be viewed under the "Network Admin > Users" menu. Also, this commit moves the admin scripts to the admin_menu() method. --- confirm-user-registration.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/confirm-user-registration.php b/confirm-user-registration.php index 782d5d1..7a6f0c7 100644 --- a/confirm-user-registration.php +++ b/confirm-user-registration.php @@ -46,10 +46,7 @@ class Confirm_User_Registration */ function __construct() { - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); - - add_action( 'admin_print_scripts-users_page_confirm-user-registration', array( $this, 'enqueue_scripts' ) ); - add_action( 'admin_print_styles-users_page_confirm-user-registration', array( $this, 'enqueue_styles' ) ); + add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'wp_ajax_confirm-user-registration-save_settings', array( $this, 'save_settings' ) ); add_action( 'admin_init', array( $this, 'load_plugin_textdomain' ) ); @@ -136,7 +133,17 @@ public function activation() **/ public function admin_menu() { - add_users_page( _x( 'Confirm User Registration', 'Menu title', 'confirm-user-registration' ), _x( 'Confirm User Registration', 'Page title', 'confirm-user-registration' ), 'promote_users', 'confirm-user-registration', array( $this, 'management' ) ); + $page = add_submenu_page( + 'users.php', + _x( 'Confirm User Registration', 'Page title', 'confirm-user-registration' ), + _x( 'Confirm User Registration', 'Menu title', 'confirm-user-registration' ), + is_multisite() ? 'manage_network_users' : 'promote_users', + 'confirm-user-registration', + array( $this, 'management' ) + ); + + add_action( "admin_print_scripts-{$page}", array( $this, 'enqueue_scripts' ) ); + add_action( "admin_print_styles-{$page}", array( $this, 'enqueue_styles' ) ); } From 1d6bd973c005ac01b1dabe8668a24fd191644c9e Mon Sep 17 00:00:00 2001 From: r-a-y Date: Tue, 3 Dec 2013 15:58:37 -0800 Subject: [PATCH 2/5] Switch out single-site option calls for network-site option calls. Using the network-site option function calls should be backwards- compatible with single-site and allows for the plugin to work on multisite installs. --- confirm-user-registration.php | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/confirm-user-registration.php b/confirm-user-registration.php index 7a6f0c7..80ca492 100644 --- a/confirm-user-registration.php +++ b/confirm-user-registration.php @@ -82,7 +82,7 @@ public function activation() endif; - add_option( 'confirm-user-registration', array( + add_site_option( 'confirm-user-registration', array( # Notifcation to admin 'administrator' => get_bloginfo('admin_email'), # Notification to users @@ -99,23 +99,23 @@ public function activation() if ( $this->is_upgrade() ) : // Create new option array - add_option( 'confirm-user-registration', array( + add_site_option( 'confirm-user-registration', array( # Notifcation to admin - 'administrator' => get_option( 'cur_administrator' ), + 'administrator' => get_site_option( 'cur_administrator' ), # Notification to users - 'error' => get_option( 'cur_error' ), + 'error' => get_site_option( 'cur_error' ), # Mail - 'from' => get_option( 'cur_from' ), - 'subject' => get_option( 'cur_subject' ), - 'message' => get_option( 'cur_message' ) + 'from' => get_site_option( 'cur_from' ), + 'subject' => get_site_option( 'cur_subject' ), + 'message' => get_site_option( 'cur_message' ) )); // Cleanup - delete_option( 'cur_administrator' ); - delete_option( 'cur_error' ); - delete_option( 'cur_from' ); - delete_option( 'cur_subject' ); - delete_option( 'cur_message' ); + delete_site_option( 'cur_administrator' ); + delete_site_option( 'cur_error' ); + delete_site_option( 'cur_from' ); + delete_site_option( 'cur_subject' ); + delete_site_option( 'cur_message' ); endif; @@ -379,7 +379,7 @@ public function is_authenticated( $user_id ) **/ public function is_first_time() { - if ( !get_option( 'cur_from' ) && !get_option( 'confirm-user-registration' ) ) : + if ( !get_site_option( 'cur_from' ) && !get_site_option( 'confirm-user-registration' ) ) : return TRUE; else : return FALSE; @@ -396,7 +396,7 @@ public function is_first_time() **/ public function is_upgrade() { - if ( get_option( 'cur_from' ) ) : + if ( get_site_option( 'cur_from' ) ) : return TRUE; else : return FALSE; @@ -478,7 +478,7 @@ public function management_nav() public function management_settings() { $this->save_settings(); - $options = get_option( 'confirm-user-registration' ); + $options = get_site_option( 'confirm-user-registration' ); ?>

@@ -575,7 +575,7 @@ public function management_users( $tab ) foreach ( $users as $user ) : $class = ( $i % 2 == 1 ) ? 'alternate' : 'default'; $user_data = get_userdata( $user->ID ); - $user_registered = mysql2date(get_option('date_format'), $user->user_registered); + $user_registered = mysql2date( get_option('date_format'), $user->user_registered ); ?> @@ -655,7 +655,7 @@ public function save_settings() ); $options = apply_filters( 'confirm-user-registration-save-options', $options ); - update_option( 'confirm-user-registration', $options); + update_site_option( 'confirm-user-registration', $options); ?>
@@ -677,7 +677,7 @@ public function save_settings() **/ public function send_notification( $user_id ) { - $options = get_option( 'confirm-user-registration' ); + $options = get_site_option( 'confirm-user-registration' ); $user = get_userdata( $user_id ); $headers = 'FROM:' . $options['from'] . "\r\n"; @@ -705,7 +705,7 @@ public function wp_authenticate_user( $user ) return $user[0]; else : $user = new WP_Error(); - $options = get_option( 'confirm-user-registration' ); + $options = get_site_option( 'confirm-user-registration' ); $error_message = apply_filters( 'confirm-user-registration-error-message', $options['error'] ); $user->add( 'error', $error_message ); return $user; From 71a802b3f51821e3640c76fdd4f13b194cd04644 Mon Sep 17 00:00:00 2001 From: r-a-y Date: Tue, 3 Dec 2013 16:13:54 -0800 Subject: [PATCH 3/5] Alter 'Edit' user link to use network_admin_url(). More multisite compatibility! --- confirm-user-registration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/confirm-user-registration.php b/confirm-user-registration.php index 80ca492..b16ba0b 100644 --- a/confirm-user-registration.php +++ b/confirm-user-registration.php @@ -588,7 +588,7 @@ public function management_users( $tab ) display_name ?>
ID ) ) : ?> - + ID ) && current_user_can( 'delete_user', $user->ID ) && $user_ID != $user->ID ) : ?>  |  From 5eeb52955baad359430dd82069f447ef94133a7b Mon Sep 17 00:00:00 2001 From: r-a-y Date: Tue, 3 Dec 2013 16:17:48 -0800 Subject: [PATCH 4/5] Alter 'Delete' user link to be multisite-compatible. Created a new class method - delete_user_link() - to do this. --- confirm-user-registration.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/confirm-user-registration.php b/confirm-user-registration.php index b16ba0b..be26b6d 100644 --- a/confirm-user-registration.php +++ b/confirm-user-registration.php @@ -594,7 +594,7 @@ public function management_users( $tab )  |  ID ) && $user_ID != $user->ID ) : ?> - +
@@ -712,7 +712,22 @@ public function wp_authenticate_user( $user ) endif; } - + /** + * Returns the delete user link used on the CUR users list table. + * + * Multisite-compatible. + * + * @access protected + * @return string + * @author r-a-y + */ + protected function delete_user_link( $user_id = 0 ) { + if ( is_multisite() ) { + return network_admin_url( 'users.php?action=deleteuser&id=' . $user_id . '&_wpnonce=' . wp_create_nonce( 'deleteuser' ) ); + } else { + return admin_url( 'users.php?action=delete&user=' . $user_id . '&_wpnonce=' . wp_create_nonce( 'bulk-users' ) ); + } + } } new Confirm_User_Registration; From 1d61d324c946741b9337bab5383a6289ee4c7c69 Mon Sep 17 00:00:00 2001 From: r-a-y Date: Tue, 10 Dec 2013 21:45:24 -0800 Subject: [PATCH 5/5] Do not allow 'Delete' bulk action on multisite. This doesn't work properly. Multisite administrators should use the main "Users" dashboard to manage user deletion instead. --- confirm-user-registration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/confirm-user-registration.php b/confirm-user-registration.php index be26b6d..cde6387 100644 --- a/confirm-user-registration.php +++ b/confirm-user-registration.php @@ -550,7 +550,7 @@ public function management_users( $tab )