Skip to content

Commit

Permalink
Merge pull request #32 from chesio/minor-code-cleanup
Browse files Browse the repository at this point in the history
Minor code cleanup
  • Loading branch information
Arsenal21 committed May 31, 2016
2 parents fe80d0b + 9636936 commit c25aaa2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function validate_change_username_form()
function get_all_admin_accounts($blog_id='') {
//TODO: Have included the "blog_id" variable for future use for cases where people want to search particular blog (eg, multi-site)
if ($blog_id) {
$admin_users = get_users('blog_id='.$blog_id.'orderby=login&role=administrator');
$admin_users = get_users('blog_id='.$blog_id.'&orderby=login&role=administrator');
} else {
$admin_users = get_users('orderby=login&role=administrator');
}
Expand All @@ -333,8 +333,8 @@ function get_all_admin_accounts($blog_id='') {
}else {
$account_output .= '<td>'.$entry->user_login.'</td>';
}
$user_acct_edit_link = get_option('siteurl').'/wp-admin/user-edit.php?user_id=';
$account_output .= '<td><a href="'.$user_acct_edit_link.$entry->ID.'" target="_blank">Edit User</a></td>';
$user_acct_edit_link = admin_url('user-edit.php?user_id=' . $entry->ID);
$account_output .= '<td><a href="'.$user_acct_edit_link.'" target="_blank">Edit User</a></td>';
$account_output .= '</tr>';
}
$account_output .= '</table>';
Expand Down
28 changes: 9 additions & 19 deletions all-in-one-wp-security/classes/wp-security-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,32 @@ static function check_user_exists($username)
//If multisite
if (AIOWPSecurity_Utility::is_multisite_install()) {
$blog_id = get_current_blog_id();
$admin_users = get_users('blog_id=' . $blog_id . 'orderby=login&role=administrator');
$acct_name_exists = false;
$admin_users = get_users('blog_id=' . $blog_id . '&orderby=login&role=administrator');
foreach ($admin_users as $user) {
if ($user->user_login == $username) {
$acct_name_exists = true;
break;
return true;
}
}
return $acct_name_exists;
return false;
}

//check users table
$sanitized_username = sanitize_text_field($username);
$sql_1 = $wpdb->prepare("SELECT user_login FROM $wpdb->users WHERE user_login=%s", $sanitized_username);
$user_login = $wpdb->get_var($sql_1);
if ($user_login == $sanitized_username) {
$users_table_value_exists = true;
return true;
} else {
//make sure that the sanitized username is an integer before comparing it to the users table's ID column
$sanitized_username_is_an_integer = (1 === preg_match('/^\d+$/', $sanitized_username)) ? true : false;
$sanitized_username_is_an_integer = (1 === preg_match('/^\d+$/', $sanitized_username));
if ($sanitized_username_is_an_integer) {
$sql_2 = $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE ID=%d", intval($sanitized_username));
$userid = $wpdb->get_var($sql_2);
$users_table_value_exists = ($userid == $sanitized_username) ? true : false;
return ($userid == $sanitized_username);
} else {
$users_table_value_exists = false;
return false;
}
}
return $users_table_value_exists;

}

/*
Expand Down Expand Up @@ -163,11 +159,7 @@ static function get_cookie_value($cookie_name)

static function is_multisite_install()
{
if (function_exists('is_multisite') && is_multisite()) {
return true;
} else {
return false;
}
return function_exists('is_multisite') && is_multisite();
}

//This is a general yellow box message for when we want to suppress a feature's config items because site is subsite of multi-site
Expand Down Expand Up @@ -305,9 +297,7 @@ static function event_logger($event_type, $username = '')

//Some initialising
$url = '';
$ip_or_host = '';
$referer_info = '';
$event_data = '';

$events_table_name = AIOWPSEC_TBL_EVENTS;

Expand Down Expand Up @@ -428,7 +418,7 @@ static function lock_IP($ip, $lock_reason = '', $username = '')
*/
static function get_blog_ids()
{
global $wpdb, $aio_wp_security;
global $wpdb;
if (AIOWPSecurity_Utility::is_multisite_install()) {
global $wpdb;
$blog_ids = $wpdb->get_col("SELECT blog_id FROM " . $wpdb->prefix . "blogs");
Expand Down

0 comments on commit c25aaa2

Please sign in to comment.