| 1 |
<?php |
| 2 |
/** |
| 3 |
* Users list. |
| 4 |
* |
| 5 |
* Copyright: © 2009-2011 |
| 6 |
* {@link http://www.websharks-inc.com/ WebSharks, Inc.} |
| 7 |
* ( coded in the USA ) |
| 8 |
* |
| 9 |
* Released under the terms of the GNU General Public License. |
| 10 |
* You should have received a copy of the GNU General Public License, |
| 11 |
* along with this software. In the main directory, see: /licensing/ |
| 12 |
* If not, see: {@link http://www.gnu.org/licenses/}. |
| 13 |
* |
| 14 |
* @package s2Member\Users_List |
| 15 |
* @since 3.5 |
| 16 |
*/ |
| 17 |
if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"])) |
| 18 |
exit ("Do not access this file directly."); |
| 19 |
/**/ |
| 20 |
if (!class_exists ("c_ws_plugin__s2member_users_list")) |
| 21 |
{ |
| 22 |
/** |
| 23 |
* Users list. |
| 24 |
* |
| 25 |
* @package s2Member\Users_List |
| 26 |
* @since 3.5 |
| 27 |
*/ |
| 28 |
class c_ws_plugin__s2member_users_list |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Adds Custom Fields to the admin Profile editing page. |
| 32 |
* |
| 33 |
* @package s2Member\Users_List |
| 34 |
* @since 3.5 |
| 35 |
* |
| 36 |
* @attaches-to: ``add_action("edit_user_profile");`` |
| 37 |
* @attaches-to: ``add_action("show_user_profile");`` |
| 38 |
* |
| 39 |
* @param obj $user Expects a `WP_User` object passed in by the Action Hook. |
| 40 |
* @return inner Return-value of inner routine. |
| 41 |
*/ |
| 42 |
public static function users_list_edit_cols ($user = FALSE) |
| 43 |
{ |
| 44 |
return c_ws_plugin__s2member_users_list_in::users_list_edit_cols ($user); |
| 45 |
} |
| 46 |
/** |
| 47 |
* Saves Custom Fields after an admin updates Profile. |
| 48 |
* |
| 49 |
* @package s2Member\Users_List |
| 50 |
* @since 3.5 |
| 51 |
* |
| 52 |
* @attaches-to: ``add_action("edit_user_profile_update");`` |
| 53 |
* @attaches-to: ``add_action("personal_options_update");`` |
| 54 |
* |
| 55 |
* @param int|str $user_id Expects a numeric WordPress® User ID passed in by the Action Hook. |
| 56 |
* @return inner Return-value of inner routine. |
| 57 |
*/ |
| 58 |
public static function users_list_update_cols ($user_id = FALSE) |
| 59 |
{ |
| 60 |
return c_ws_plugin__s2member_users_list_in::users_list_update_cols ($user_id); |
| 61 |
} |
| 62 |
/** |
| 63 |
* Modifies the search query. |
| 64 |
* |
| 65 |
* Affects searches performed in the list of Users. |
| 66 |
* |
| 67 |
* @package s2Member\Users_List |
| 68 |
* @since 3.5 |
| 69 |
* |
| 70 |
* @attaches-to: ``add_action("pre_user_query");`` |
| 71 |
* |
| 72 |
* @param obj $query Expects a `WP_User_Query` object, by reference. |
| 73 |
* @return null After possibly modifying the ``$query`` object. |
| 74 |
*/ |
| 75 |
public static function users_list_query (&$query = FALSE) |
| 76 |
{ |
| 77 |
global $wpdb; /* Need this global object reference. */ |
| 78 |
/**/ |
| 79 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 80 |
do_action ("ws_plugin__s2member_before_users_list_search", get_defined_vars ()); |
| 81 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 82 |
/**/ |
| 83 |
if (isset ($query->query_vars) && !is_network_admin ()) /* NOT in Network admin panels. */ |
| 84 |
if (is_array ($qv = $query->query_vars) && ($s = trim ($qv["search"], "* \t\n\r\0\x0B")) && ($s = "%" . esc_sql (like_escape ($s)) . "%")) |
| 85 |
{ |
| 86 |
$query->query_from = " FROM `" . $wpdb->users . "` INNER JOIN `" . $wpdb->usermeta . "` ON `" . $wpdb->users . "`.`ID` = `" . $wpdb->usermeta . "`.`user_id`"; |
| 87 |
/**/ |
| 88 |
$query->query_where = " WHERE '1' = '1' AND (" . apply_filters ("ws_plugin__s2member_before_users_list_search_where_or_before", "", get_defined_vars ()); |
| 89 |
$query->query_where .= " (`" . $wpdb->usermeta . "`.`meta_key` = '" . $wpdb->prefix . "s2member_subscr_id' AND `" . $wpdb->usermeta . "`.`meta_value` LIKE '" . $s . "')"; |
| 90 |
$query->query_where .= " OR (`" . $wpdb->usermeta . "`.`meta_key` = '" . $wpdb->prefix . "s2member_custom' AND `" . $wpdb->usermeta . "`.`meta_value` LIKE '" . $s . "')"; |
| 91 |
$query->query_where .= " OR (`" . $wpdb->usermeta . "`.`meta_key` = '" . $wpdb->prefix . "s2member_custom_fields' AND `" . $wpdb->usermeta . "`.`meta_value` LIKE '" . $s . "')"; |
| 92 |
$query->query_where .= " OR `user_login` LIKE '" . $s . "' OR `user_nicename` LIKE '" . $s . "' OR `user_email` LIKE '" . $s . "' OR `user_url` LIKE '" . $s . "' OR `display_name` LIKE '" . $s . "'"; |
| 93 |
$query->query_where .= apply_filters ("ws_plugin__s2member_before_users_list_search_where_or_after", "", get_defined_vars ()) . ")"; /* Leaving room for additional searches here. */ |
| 94 |
$query->query_where .= " AND `" . $wpdb->users . "`.`ID` IN(SELECT DISTINCT(`user_id`) FROM `" . $wpdb->usermeta . "` WHERE `meta_key` = '" . $wpdb->prefix . "capabilities'" ./**/ |
| 95 |
(($qv["role"]) ? " AND `meta_value` LIKE '%" . esc_sql (like_escape ($qv["role"])) . "%'" : "") . ")"; |
| 96 |
/**/ |
| 97 |
$query->query_from = apply_filters ("ws_plugin__s2member_before_users_list_search_from", $query->query_from, get_defined_vars ()); |
| 98 |
$query->query_where = apply_filters ("ws_plugin__s2member_before_users_list_search_where", $query->query_where, get_defined_vars ()); |
| 99 |
} |
| 100 |
/**/ |
| 101 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 102 |
do_action ("ws_plugin__s2member_after_users_list_search", get_defined_vars ()); |
| 103 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 104 |
/**/ |
| 105 |
return; /* Return for uniformity. */ |
| 106 |
} |
| 107 |
/** |
| 108 |
* Adds columns to the list of Users. |
| 109 |
* |
| 110 |
* @package s2Member\Users_List |
| 111 |
* @since 3.5 |
| 112 |
* |
| 113 |
* @attaches-to: ``add_filter ("manage_users_columns");`` |
| 114 |
* |
| 115 |
* @param array $columns Expects an array of columns to be passed through by the Filter. |
| 116 |
* @return array Array of columns, merged with columns introduced by this routine. |
| 117 |
*/ |
| 118 |
public static function users_list_cols ($cols = FALSE) |
| 119 |
{ |
| 120 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 121 |
do_action ("ws_plugin__s2member_before_users_list_cols", get_defined_vars ()); |
| 122 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 123 |
/**/ |
| 124 |
$cols["s2member_registration_time"] = "Registration Date"; |
| 125 |
/**/ |
| 126 |
if (apply_filters ("ws_plugin__s2member_users_list_cols_display_paid_registration_times", false)) |
| 127 |
$cols["s2member_paid_registration_times"] = "Paid Registr. Date"; |
| 128 |
/**/ |
| 129 |
$cols["s2member_subscr_id"] = "Paid Subscr. ID"; |
| 130 |
/**/ |
| 131 |
if (!is_multisite () || !c_ws_plugin__s2member_utils_conds::is_multisite_farm () || is_main_site ()) |
| 132 |
$cols["s2member_ccaps"] = "Custom Capabilities"; |
| 133 |
/**/ |
| 134 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"]) |
| 135 |
foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field) |
| 136 |
{ |
| 137 |
$field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"])); |
| 138 |
$field_id_class = preg_replace ("/_/", "-", $field_var); |
| 139 |
/**/ |
| 140 |
$field_title = ucwords (preg_replace ("/_/", " ", $field_var)); |
| 141 |
$cols["s2member_custom_field_" . $field_var] = $field_title; |
| 142 |
} |
| 143 |
/**/ |
| 144 |
$cols["s2member_login_counter"] = "# Of Logins"; |
| 145 |
/**/ |
| 146 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 147 |
do_action ("ws_plugin__s2member_during_users_list_cols", get_defined_vars ()); |
| 148 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 149 |
/**/ |
| 150 |
return apply_filters ("ws_plugin__s2member_users_list_cols", $cols, get_defined_vars ()); |
| 151 |
} |
| 152 |
/** |
| 153 |
* Displays column data in the row of details. |
| 154 |
* |
| 155 |
* @package s2Member\Users_List |
| 156 |
* @since 3.5 |
| 157 |
* |
| 158 |
* @attaches-to: ``add_filter ("manage_users_custom_column");`` |
| 159 |
* |
| 160 |
* @param str $val A value for this column, passed through by the Filter. |
| 161 |
* @param str $col The name of the column for which we might need to supply data for. |
| 162 |
* @param int|str $user_id Expects a WordPress® User ID, passed through by the Filter. |
| 163 |
* @return str A column value introduced by this routine, or existing value, or, if empty, a dash. |
| 164 |
*/ |
| 165 |
public static function users_list_display_cols ($val = FALSE, $col = FALSE, $user_id = FALSE) |
| 166 |
{ |
| 167 |
static $user, $last_user_id; /* Used internally for optimization. */ |
| 168 |
static $fields, $last_fields_id; /* Used for optimization. */ |
| 169 |
/**/ |
| 170 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 171 |
do_action ("ws_plugin__s2member_before_users_list_display_cols", get_defined_vars ()); |
| 172 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 173 |
/**/ |
| 174 |
$user = (is_object ($user) && $user_id === $last_user_id) ? $user : new WP_User ($user_id); |
| 175 |
/**/ |
| 176 |
if ($col === "s2member_registration_time") |
| 177 |
$val = (($time = strtotime (get_date_from_gmt ($user->user_registered)))) ? esc_html (date ("D M jS, Y", $time)) . '<br /><small>@ precisely ' . esc_html (date ("g:i a", $time)) . '</small>' : "—"; |
| 178 |
/**/ |
| 179 |
else if ($col === "s2member_paid_registration_times") |
| 180 |
{ |
| 181 |
$val = ""; /* Initialize $val before we begin. */ |
| 182 |
if (is_array ($v = get_user_option ("s2member_paid_registration_times", $user_id))) |
| 183 |
foreach ($v as $level => $time) /* Go through each Paid Registration Time. */ |
| 184 |
{ |
| 185 |
$time = strtotime (get_date_from_gmt (date ("Y-m-d H:i:s", $time))); |
| 186 |
/**/ |
| 187 |
if ($level === "level") /* First Payment Time, regardless of Level. */ |
| 188 |
$val .= (($val) ? "<br />" : "") . '<span title="' . esc_attr (date ("D M jS, Y", $time)) . ' @ precisely ' . esc_attr (date ("g:i a", $time)) . '">' . esc_html (date ("D M jS, Y", $time)) . '</span>'; |
| 189 |
else if (preg_match ("/^level([0-9]+)$/i", $level) && ($level = preg_replace ("/^level/", "", $level))) |
| 190 |
$val .= (($val) ? "<br />" : "") . '<small><em>@Level ' . esc_html ($level) . ': <span title="' . esc_attr (date ("D M jS, Y", $time)) . ' @ precisely ' . esc_attr (date ("g:i a", $time)) . '">' . esc_html (date ("D M jS, Y", $time)) . '</span></em></small>'; |
| 191 |
} |
| 192 |
} |
| 193 |
/**/ |
| 194 |
else if ($col === "s2member_subscr_id") |
| 195 |
$val = ($v = get_user_option ("s2member_subscr_id", $user_id)) ? esc_html ($v) : "—"; |
| 196 |
/**/ |
| 197 |
else if ($col === "s2member_ccaps") /* Custom Capabilities. */ |
| 198 |
{ |
| 199 |
foreach ($user->allcaps as $cap => $cap_enabled) |
| 200 |
if (preg_match ("/^access_s2member_ccap_/", $cap)) |
| 201 |
$ccaps[] = preg_replace ("/^access_s2member_ccap_/", "", $cap); |
| 202 |
/**/ |
| 203 |
$val = (!empty ($ccaps)) ? implode ("<br />", $ccaps) : "—"; |
| 204 |
} |
| 205 |
/**/ |
| 206 |
else if (preg_match ("/^s2member_custom_field_/", $col)) |
| 207 |
{ |
| 208 |
if (!$last_fields_id || $last_fields_id !== $user_id) |
| 209 |
$fields = get_user_option ("s2member_custom_fields", $user_id); |
| 210 |
/**/ |
| 211 |
$field_var = preg_replace ("/^s2member_custom_field_/", "", $col); |
| 212 |
/**/ |
| 213 |
if (isset ($fields[$field_var]) && is_string ($fields[$field_var]) && preg_match ("/^http(s?)\:/i", $fields[$field_var])) |
| 214 |
$val = '<a href="' . esc_attr ($fields[$field_var]) . '" target="_blank">' . esc_html (substr ($fields[$field_var], strpos ($fields[$field_var], ":") + 3, 25) . "...") . '</a>'; |
| 215 |
/**/ |
| 216 |
else if (isset ($fields[$field_var]) && is_array ($fields[$field_var]) && !empty ($fields[$field_var])) |
| 217 |
$val = preg_replace ("/-\|br\|-/", "<br />", esc_html (implode ("-|br|-", $fields[$field_var]))); |
| 218 |
/**/ |
| 219 |
else if (isset ($fields[$field_var]) && is_string ($fields[$field_var]) && strlen ($fields[$field_var])) |
| 220 |
$val = esc_html ($fields[$field_var]); |
| 221 |
/**/ |
| 222 |
$last_fields_id = $user_id; /* Record this. */ |
| 223 |
} |
| 224 |
/**/ |
| 225 |
else if ($col === "s2member_login_counter") |
| 226 |
$val = ($v = get_user_option ("s2member_login_counter", $user_id)) ? esc_html ($v) : "—"; |
| 227 |
/**/ |
| 228 |
$last_user_id = $user_id; /* Record this for internal optimizations. */ |
| 229 |
/**/ |
| 230 |
return apply_filters ("ws_plugin__s2member_users_list_display_cols", ((strlen ($val)) ? $val : "—"), get_defined_vars ()); |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
?> |