Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 );**
26 changes: 17 additions & 9 deletions custom-add-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Author: Harshit Sanghvi <[email protected]>
* Author URI: http://sanghviharshit.com
* License: GPL3
* Version: 2.0.2
* Version: 2.0.3
*/

// If this file is called directly, abort.
Expand Down Expand Up @@ -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';


/**
Expand Down Expand Up @@ -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&#8217; uh?'));

$permission = apply_filters('custom_add_user_permission',current_user_can( 'create_users' ));
$error_msg = apply_filters('custom_add_user_error_msg',__('Cheatin&#8217; uh?'));

if ( ! $permission )
wp_die($error_msg);

if ( ! is_multisite() ) {
$user_id = edit_user();
Expand All @@ -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(
'<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
'<h1>' . $error_msg . '</h1>' .
'<p>' . __( 'Sorry, you are not allowed to create users.' ) . '</p>',
403
);
Expand Down Expand Up @@ -253,7 +258,7 @@ public function custom_createuser() {
} else {
if ( ! current_user_can( 'promote_user', $user_details->ID ) ) {
wp_die(
'<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
'<h1>' . $error_msg . '</h1>' .
'<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>',
403
);
Expand Down Expand Up @@ -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&#8217; uh?'));

if ( ! current_user_can('promote_user', $user_details->ID) )
wp_die(__('Cheatin&#8217; uh?'));
if ( ! $permission )
wp_die($error_msg);

// Adding an existing user to this blog
$new_user_email = $user_details->user_email;
Expand Down