diff --git a/README.md b/README.md index ade0c5e..fddcb55 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,23 @@ This plugin addresses all the above issues by - 2. In the WordPress Network Admin dashboard, navigate to the *Plugins* page 3. **Activate** or **Network Activate** (multisite) 'Custom Add User' from your Plugins page. - +## Hooks + +#### FILTER: custom_add_user_permission + +**function prevent_user_registration($permission){ + //put a limit to add user + if(count_users > 10){ + return false; + } + return $permission; +} +add_filter('custom_add_user_permission','prevent_user_registration', 10, 1 );** + +#### FILTER: custom_add_user_error_msg + +**function message_add_user($msg){ + $msg = _('An error occurred. Please try again.'); + return $msg; +} +add_filter('custom_add_user_error_msg', 'message_add_user', 10, 1 );** diff --git a/custom-add-user.php b/custom-add-user.php index 2f478de..776cfdf 100644 --- a/custom-add-user.php +++ b/custom-add-user.php @@ -14,7 +14,7 @@ * Author: Harshit Sanghvi * Author URI: http://sanghviharshit.com * License: GPL3 - * Version: 2.0.2 + * Version: 2.0.3 */ // If this file is called directly, abort. @@ -47,6 +47,8 @@ class Custom_Add_User { var $network_settings; /** @var array $settings The plugin network or site options depending on localization in admin page */ var $current_settings; + /** @var string $version The plugin version */ + var $version = '2.0.3'; /** @@ -192,9 +194,12 @@ public function custom_content_below_add_user_form($type) { public function custom_createuser() { global $wpdb; check_admin_referer( 'create-user', '_wpnonce_create-user' ); - - if ( ! current_user_can('create_users') ) - wp_die(__('Cheatin’ uh?')); + + $permission = apply_filters('custom_add_user_permission',current_user_can( 'create_users' )); + $error_msg = apply_filters('custom_add_user_error_msg',__('Cheatin’ uh?')); + + if ( ! $permission ) + wp_die($error_msg); if ( ! is_multisite() ) { $user_id = edit_user(); @@ -220,9 +225,9 @@ public function custom_createuser() { $user_details = get_user_by( 'login', $user_login ); if ( !$user_details ) { - if ( ! current_user_can( 'create_users' ) ) { + if ( ! $permission ) { wp_die( - '

' . __( 'Cheatin’ uh?' ) . '

' . + '

' . $error_msg . '

' . '

' . __( 'Sorry, you are not allowed to create users.' ) . '

', 403 ); @@ -253,7 +258,7 @@ public function custom_createuser() { } else { if ( ! current_user_can( 'promote_user', $user_details->ID ) ) { wp_die( - '

' . __( 'Cheatin’ uh?' ) . '

' . + '

' . $error_msg . '

' . '

' . __( 'Sorry, you are not allowed to add users to this network.' ) . '

', 403 ); @@ -298,9 +303,12 @@ public function custom_adduser() { wp_redirect( add_query_arg( array('update' => 'does_not_exist'), 'user-new.php' ) ); die(); } + + $permission = apply_filters('custom_add_user_permission',current_user_can('promote_user', $user_details->ID)); + $error_msg = apply_filters('custom_add_user_error_msg',__('Cheatin’ uh?')); - if ( ! current_user_can('promote_user', $user_details->ID) ) - wp_die(__('Cheatin’ uh?')); + if ( ! $permission ) + wp_die($error_msg); // Adding an existing user to this blog $new_user_email = $user_details->user_email;