Skip to content
Open
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
78 changes: 50 additions & 28 deletions confirm-user-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down Expand Up @@ -85,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
Expand All @@ -102,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;

Expand All @@ -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' ) );
}


Expand Down Expand Up @@ -372,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;
Expand All @@ -389,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;
Expand Down Expand Up @@ -471,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' );
?>
<form method="post" id="confirm-user-registration-settings" data-success="<?php _e( 'Settings saved', 'confirm-user-registration' ); ?>" data-error="<?php _e( '<strong>ERROR:</strong> Could not save settings', 'confirm-user-registration' ); ?>">
<div class="icon32" id="icon-tools"><br></div><h2><?php _e( 'Confirm User Registration Settings', 'confirm-user-registration' ); ?></h2>
Expand Down Expand Up @@ -543,7 +550,7 @@ public function management_users( $tab )
<select name="action">
<option value=""><?php _e( 'Bulk Actions' ); ?></option>
<option value="<?php echo $action_data ?>"><?php echo $title ?></option>
<?php if ( current_user_can( 'delete_users' ) ) : ?>
<?php if ( current_user_can( 'delete_users' ) && ! is_multisite() ) : ?>
<option value="delete"><?php _e( 'Delete' ); ?></option>
<?php endif; ?>
</select>
Expand All @@ -568,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 );
?>
<tr id="user-<?php echo $user->ID ?>" class="<?php echo $class ?>">
<th>
Expand All @@ -581,13 +588,13 @@ public function management_users( $tab )
<a href="user-edit.php?user_id=<?php echo $user->ID ?>"><?php echo $user->display_name ?></a>
<div class="row-actions">
<?php if ( current_user_can( 'edit_user', $user->ID ) ) : ?>
<span class="edit"><a href="<?php echo admin_url( 'user-edit.php?user_id=' . $user->ID ) ?>"><?php _e( 'Edit' ); ?></a>
<span class="edit"><a href="<?php echo network_admin_url( 'user-edit.php?user_id=' . $user->ID ) ?>"><?php _e( 'Edit' ); ?></a>
<?php endif; ?>
<?php if ( current_user_can( 'edit_user', $user->ID ) && current_user_can( 'delete_user', $user->ID ) && $user_ID != $user->ID ) : ?>
&nbsp;|&nbsp;</span>
<?php endif; ?>
<?php if ( current_user_can( 'delete_user', $user->ID ) && $user_ID != $user->ID ) : ?>
<span class="delete"><a href="<?php echo admin_url( 'users.php?action=delete&user=' . $user->ID . '&_wpnonce=' . wp_create_nonce( 'bulk-users' ) ) ?>"><?php _e( 'Delete' ); ?></a></span>
<span class="delete"><a href="<?php echo $this->delete_user_link( $user->ID ); ?>"><?php _e( 'Delete' ); ?></a></span>
<?php endif; ?>
</div>
</td>
Expand Down Expand Up @@ -648,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);

?>
<div class="updated message">
Expand All @@ -670,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";
Expand Down Expand Up @@ -698,14 +705,29 @@ 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;
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;