PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.43
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.43
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
← All changes | includes/helpers/misc.php +470 -696 1.2.711.2.43 View file →
@@ -1,6 +1,5 @@
1 1 <?php
2 -
3 2 /**
4 3 * Converts string value to options array.
5 4 * Used in select, multiselect and radio fields.
6 5 * Wraps inside optgroup if available.
@@ -89,9 +88,9 @@
89 88 $input_arr = explode(',', $input);
90 89
91 90 if (!empty($input_arr)) {
92 91 foreach ($input_arr as $input_str) {
93 - $input_str = trim(stripslashes($input_str));
92 + $input_str = trim( stripslashes( $input_str ) );
94 93
95 94 if (strpos($input_str, "/") !== false) {
96 95 $input_str = explode("/", $input_str, 2);
97 96 $label = trim($input_str[0]);
@@ -132,30 +131,29 @@
132 131 * @param float $scale Image scale ratio.
133 132 *
134 133 * @return mixed Resized image.
135 134 */
136 -function uwp_resizeThumbnailImage($thumb_image_name, $image, $x, $y, $src_w, $src_h, $scale, $wp_error = false)
137 -{
135 +function uwp_resizeThumbnailImage( $thumb_image_name, $image, $x, $y, $src_w, $src_h, $scale, $wp_error = false ) {
138 136 uwp_set_php_limits();
139 137
140 138 // Ignore image creation warnings
141 - @ini_set('gd.jpeg_ignore_warning', 1);
139 + @ini_set( 'gd.jpeg_ignore_warning', 1 );
142 140
143 - $newImageWidth = ceil($src_w * $scale);
144 - $newImageHeight = ceil($src_h * $scale);
141 + $newImageWidth = ceil( $src_w * $scale );
142 + $newImageHeight = ceil( $src_h * $scale );
145 143
146 144 /** @noinspection PhpUnusedLocalVariableInspection */
147 - list($imagewidth, $imageheight, $imageType) = getimagesize($image);
148 - $imageType = image_type_to_mime_type($imageType);
145 + list( $imagewidth, $imageheight, $imageType ) = getimagesize( $image );
146 + $imageType = image_type_to_mime_type( $imageType );
149 147
150 - if (function_exists('wp_crop_image')) {
151 - $wp_crop = ! in_array($imageType, array('image/gif', 'image/pjpeg', 'image/jpeg', 'image/jpg', 'image/png', 'image/x-png', 'image/webp')) ? true : false;
152 - $wp_crop = apply_filters('uwp_resize_image_use_wp_crop_image', $wp_crop, $imageType, $image, $thumb_image_name, $x, $y, $src_w, $src_h, $scale);
148 + if ( function_exists( 'wp_crop_image' ) ) {
149 + $wp_crop = ! in_array( $imageType, array( 'image/gif', 'image/pjpeg', 'image/jpeg', 'image/jpg', 'image/png', 'image/x-png', 'image/webp' ) ) ? true : false;
150 + $wp_crop = apply_filters( 'uwp_resize_image_use_wp_crop_image', $wp_crop, $imageType, $image, $thumb_image_name, $x, $y, $src_w, $src_h, $scale );
153 151
154 - if ($wp_crop) {
155 - $cropped = wp_crop_image($image, $x, $y, $src_w, $src_h, $newImageWidth, $newImageHeight, false, $thumb_image_name);
152 + if ( $wp_crop ) {
153 + $cropped = wp_crop_image( $image, $x, $y, $src_w, $src_h, $newImageWidth, $newImageHeight, false, $thumb_image_name );
156 154
157 - if ($wp_error && is_wp_error($cropped)) {
155 + if ( $wp_error && is_wp_error( $cropped ) ) {
158 156 return $cropped;
159 157 }
160 158
161 159 return $thumb_image_name;
@@ -161,29 +159,29 @@
161 159 return $thumb_image_name;
162 160 }
163 161 }
164 162
165 - $newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
163 + $newImage = imagecreatetruecolor( $newImageWidth, $newImageHeight );
166 164 $source = false;
167 165
168 - switch ($imageType) {
166 + switch( $imageType ) {
169 167 case "image/gif":
170 - $source = imagecreatefromgif($image);
168 + $source = imagecreatefromgif( $image );
171 169 break;
172 170 case "image/pjpeg":
173 171 case "image/jpeg":
174 172 case "image/jpg":
175 - $source = imagecreatefromjpeg($image);
173 + $source = imagecreatefromjpeg( $image );
176 174 break;
177 175 case "image/png":
178 176 case "image/x-png":
179 - $source = imagecreatefrompng($image);
180 - if (apply_filters('uwp_keep_png_transperent', true, $thumb_image_name, $image, $x, $y, $src_w, $src_h)) {
181 - $background = imagecolorallocate($newImage, 0, 0, 0);
177 + $source = imagecreatefrompng( $image );
178 + if ( apply_filters( 'uwp_keep_png_transperent', true, $thumb_image_name, $image, $x, $y, $src_w, $src_h ) ) {
179 + $background = imagecolorallocate( $newImage, 0, 0, 0 );
182 180
183 - imagecolortransparent($newImage, $background);
184 - imagealphablending($newImage, false);
185 - imagesavealpha($newImage, true);
181 + imagecolortransparent( $newImage, $background );
182 + imagealphablending( $newImage, false );
183 + imagesavealpha( $newImage, true );
186 184 }
187 185 break;
188 186 case "image/webp":
189 187 if (function_exists('imagecreatefromwebp')) {
@@ -193,38 +191,38 @@
193 191 }
194 192 break;
195 193 }
196 194
197 - imagecopyresampled($newImage, $source, 0, 0, $x, $y, $newImageWidth, $newImageHeight, $src_w, $src_h);
195 + imagecopyresampled( $newImage, $source, 0, 0, $x, $y, $newImageWidth, $newImageHeight, $src_w, $src_h );
198 196
199 - $quality = apply_filters('uwp_resize_thumb_quality', 100);
197 + $quality = apply_filters( 'uwp_resize_thumb_quality', 100 );
200 198
201 - switch ($imageType) {
199 + switch( $imageType ) {
202 200 case "image/gif":
203 - imagegif($newImage, $thumb_image_name);
201 + imagegif( $newImage, $thumb_image_name );
204 202 break;
205 203 case "image/pjpeg":
206 204 case "image/jpeg":
207 205 case "image/jpg":
208 - imagejpeg($newImage, $thumb_image_name, $quality);
206 + imagejpeg( $newImage, $thumb_image_name, $quality );
209 207 break;
210 208 case "image/png":
211 209 case "image/x-png":
212 - imagepng($newImage, $thumb_image_name);
210 + imagepng( $newImage, $thumb_image_name );
213 211 break;
214 212 case "image/webp":
215 213 if (function_exists('imagewebp')) {
216 - imagewebp($newImage, $thumb_image_name, $quality);
214 + imagewebp( $newImage, $thumb_image_name, $quality );
217 215 } else {
218 - imagepng($newImage, $thumb_image_name);
216 + imagepng( $newImage, $thumb_image_name );
219 217 }
220 218 break;
221 219 }
222 220
223 - chmod($thumb_image_name, 0777);
221 + chmod( $thumb_image_name, 0777 );
224 222 imagedestroy($newImage);
225 223 imagedestroy($source);
226 -
224 +
227 225 return $thumb_image_name;
228 226 }
229 227
230 228 /**
@@ -229,32 +227,31 @@
229 227
230 228 /**
231 229 * Try to set higher limits on the fly
232 230 */
233 -function uwp_set_php_limits()
234 -{
235 - error_reporting(0);
231 +function uwp_set_php_limits() {
232 + error_reporting( 0 );
236 233
237 234 // try to set higher limits for import
238 - $max_input_time = ini_get('max_input_time');
239 - $max_execution_time = ini_get('max_execution_time');
240 - $memory_limit = ini_get('memory_limit');
235 + $max_input_time = ini_get( 'max_input_time' );
236 + $max_execution_time = ini_get( 'max_execution_time' );
237 + $memory_limit = ini_get( 'memory_limit' );
241 238
242 - if ($max_input_time !== 0 && $max_input_time != -1 && (! $max_input_time || $max_input_time < 3000)) {
243 - ini_set('max_input_time', 3000);
239 + if ( $max_input_time !== 0 && $max_input_time != -1 && ( ! $max_input_time || $max_input_time < 3000 ) ) {
240 + ini_set( 'max_input_time', 3000 );
244 241 }
245 242
246 - if ($max_execution_time !== 0 && (! $max_execution_time || $max_execution_time < 3000)) {
247 - ini_set('max_execution_time', 3000);
243 + if ( $max_execution_time !== 0 && ( ! $max_execution_time || $max_execution_time < 3000 ) ) {
244 + ini_set( 'max_execution_time', 3000 );
248 245 }
249 246
250 - if ($memory_limit && str_replace('M', '', $memory_limit)) {
251 - if (str_replace('M', '', $memory_limit) < 256) {
252 - ini_set('memory_limit', '256M');
247 + if ( $memory_limit && str_replace( 'M', '', $memory_limit ) ) {
248 + if ( str_replace( 'M', '', $memory_limit ) < 256 ) {
249 + ini_set( 'memory_limit', '256M' );
253 250 }
254 251 }
255 252
256 - ini_set('auto_detect_line_endings', true);
253 + ini_set( 'auto_detect_line_endings', true );
257 254 }
258 255
259 256 /**
260 257 * Logs the error message.
@@ -265,25 +262,23 @@
265 262 * @param array|object|string $log Error message.
266 263 *
267 264 * @return void
268 265 */
269 -function uwp_error_log($log)
270 -{
266 +function uwp_error_log($log){
271 267 /*
272 268 * A filter to override the debugging setting for function uwp_error_log().
273 269 */
274 - $should_log = apply_filters('uwp_log_errors', uwp_get_option('enable_uwp_error_log', 0));
275 - if (1 == $should_log) {
276 - if (is_array($log) || is_object($log)) {
277 - error_log(print_r($log, true));
270 + $should_log = apply_filters( 'uwp_log_errors', uwp_get_option('enable_uwp_error_log', 0));
271 + if ( 1 == $should_log ) {
272 + if ( is_array( $log ) || is_object( $log ) ) {
273 + error_log( print_r( $log, true ) );
278 274 } else {
279 - error_log($log);
275 + error_log( $log );
280 276 }
281 277 }
282 278 }
283 279
284 -function uwp_get_excluded_users_list()
285 -{
280 +function uwp_get_excluded_users_list() {
286 281
287 282 $args = array(
288 283 'fields' => 'ID',
289 284 'meta_query' => array(
@@ -304,11 +299,11 @@
304 299 $inactive_users = new WP_User_Query($args);
305 300 $exclude_users = $inactive_users->get_results();
306 301
307 302 $excluded_globally = uwp_get_option('users_excluded_from_list');
308 - if (!empty($excluded_globally)) {
303 + if ( !empty($excluded_globally) ) {
309 304
310 - if (is_array($excluded_globally)) {
305 + if(is_array($excluded_globally)) {
311 306 $exclude_users = array_merge($exclude_users, $excluded_globally);
312 307 } else {
313 308 $excluded_users = str_replace(' ', '', $excluded_globally);
314 309 $users_array = explode(',', $excluded_users);
@@ -319,213 +314,145 @@
319 314 return $exclude_users;
320 315 }
321 316
322 317 /**
323 - * Retrieves a list of users with optional filtering, searching, and sorting.
318 + * Prints the users page main content.
324 319 *
325 - * @since 1.0.0
326 - * @package userswp
320 + * @since 1.0.0
321 + * @package userswp
327 322 *
328 - * @param array $roles Optional. Array of user roles to filter by. Default empty array.
329 - * @return array {
330 - * Array of users and pagination data.
331 - *
332 - * @type array $users Array of WP_User objects.
333 - * @type int $total_users Total number of users found.
334 - * }
323 + * @return array $users array of users
335 324 */
336 -function get_uwp_users_list( $roles = array() )
337 -{
325 +function get_uwp_users_list($roles = array()) {
326 +
338 327 global $wpdb;
339 328
340 - // Sanitize and validate input parameters
341 329 $keyword = false;
342 - if ( isset( $_GET['uwps'] ) && ! empty( $_GET['uwps'] ) ) {
343 - $keyword = sanitize_text_field( wp_unslash( $_GET['uwps'] ) );
330 + if (isset($_GET['uwps']) && $_GET['uwps'] != '') {
331 + $keyword = stripslashes(strip_tags($_GET['uwps']));
344 332 }
345 333
346 - // Get pagination parameter with proper fallback
347 - $paged = 1;
348 - if ( isset( $_GET['paged'] ) && ! empty( $_GET['paged'] ) ) {
349 - $paged = absint( $_GET['paged'] );
350 - } elseif ( is_front_page() ) {
351 - $page_var = get_query_var( 'page' );
352 - $paged = absint( $page_var ) > 0 ? absint( $page_var ) : 1;
334 + if ( is_front_page() ) {
335 + $paged = ( get_query_var( 'page' ) ) ? absint( get_query_var( 'page' ) ) : 1;
353 336 } else {
354 - $paged_var = get_query_var( 'paged' );
355 - $paged = absint( $paged_var ) > 0 ? absint( $paged_var ) : 1;
337 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
356 338 }
357 339
358 - // Get number of items per page
359 - $number = absint( uwp_get_option( 'users_no_of_items', 10 ) );
360 - $number = $number > 0 ? $number : 10;
340 + $number = uwp_get_option('users_no_of_items', 10);
341 + $number = !empty($number) ? $number : 10;
361 342
362 - // Get search where clause from filters
363 343 $where = '';
364 - $where = apply_filters( 'uwp_users_search_where', $where, $keyword );
344 + $where = apply_filters('uwp_users_search_where', $where, $keyword);
365 345
366 - // Get excluded users list
367 346 $exclude_users = uwp_get_excluded_users_list();
368 - $exclude_users = apply_filters( 'uwp_excluded_users_from_list', $exclude_users, $where, $keyword );
369 - $exclude_users = ! empty( $exclude_users ) ? array_unique( $exclude_users ) : array();
347 + $exclude_users = apply_filters('uwp_excluded_users_from_list', $exclude_users, $where, $keyword);
348 + $exclude_users = !empty($exclude_users) ? array_unique($exclude_users): array();
370 349
371 - // Initialize sorting parameters
372 - $exclude_query = ' ';
373 - $order_by = 'uwp_meta_value';
374 - $order = 'ASC';
375 - $meta_key = '';
350 + $exclude_query = ' ';$order_by = 'uwp_meta_value'; $order = 'ASC';
376 351
377 - // Get and sanitize sort parameter
378 - $sort_by = '';
379 - if ( isset( $_GET['uwp_sort_by'] ) && ! empty( $_GET['uwp_sort_by'] ) ) {
380 - $sort_by = sanitize_text_field( wp_unslash( $_GET['uwp_sort_by'] ) );
381 - }
352 + if (isset($_GET['uwp_sort_by']) && $_GET['uwp_sort_by'] != '') {
353 + $sort_by = strip_tags(esc_sql($_GET['uwp_sort_by']));
354 + } else {
355 + $sort_by = '';
356 + }
382 357
383 - // Process sorting parameters
384 - if ( ! empty( $sort_by ) ) {
385 - // Handle special cases for newer/older
386 - if ( 'newer' === $sort_by ) {
387 - $order_by = 'user_registered';
388 - $order = 'DESC';
389 - } elseif ( 'older' === $sort_by ) {
390 - $order_by = 'user_registered';
391 - $order = 'ASC';
392 - } else {
393 - // Handle _asc and _desc suffixes
394 - if ( substr( $sort_by, -4 ) === '_asc' ) {
395 - $order_by = substr( $sort_by, 0, -4 );
396 - $order = 'ASC';
397 - } elseif ( substr( $sort_by, -5 ) === '_desc' ) {
398 - $order_by = substr( $sort_by, 0, -5 );
358 + if ($sort_by) {
359 + switch ( $sort_by ) {
360 + case "newer":
361 + $order_by = 'registered';
399 362 $order = 'DESC';
400 - } else {
401 - // Default to ASC if no suffix
402 - $order_by = $sort_by;
363 + break;
364 + case "older":
365 + $order_by = 'registered';
403 366 $order = 'ASC';
404 - }
367 + break;
405 368 }
406 369 }
407 370
408 - // Build exclude query for excluded users
409 - if ( ! empty( $exclude_users ) ) {
410 - $exclude_users_list = implode( ',', array_map( 'absint', $exclude_users ) );
411 - $exclude_query = 'AND ' . $wpdb->users . '.ID NOT IN (' . $exclude_users_list . ')';
371 + if(!empty($exclude_users)) {
372 + $exclude_users_list = implode(',', $exclude_users);
373 + $exclude_query = 'AND '. $wpdb->users.'.ID NOT IN ('.$exclude_users_list.')';
412 374 }
413 375
414 376 $users = array();
415 377
416 - // Check if we have search criteria
417 - if ( $keyword || $where ) {
378 + if($keyword || $where ) {
418 379
419 - // Build search query based on whether we have custom where clause
420 - if ( empty( $where ) ) {
421 - // Standard search query with keyword
422 - $search_term = '%' . $wpdb->esc_like( $keyword ) . '%';
423 - $user_query = $wpdb->prepare(
424 - "SELECT DISTINCT SQL_CALC_FOUND_ROWS {$wpdb->users}.*
425 - FROM {$wpdb->users}
426 - LEFT JOIN {$wpdb->usermeta} AS first_name_meta ON ( {$wpdb->users}.ID = first_name_meta.user_id AND first_name_meta.meta_key = 'first_name' )
427 - LEFT JOIN {$wpdb->usermeta} AS last_name_meta ON ( {$wpdb->users}.ID = last_name_meta.user_id AND last_name_meta.meta_key = 'last_name' )
428 - LEFT JOIN {$wpdb->usermeta} AS nickname_meta ON ( {$wpdb->users}.ID = nickname_meta.user_id AND nickname_meta.meta_key = 'nickname' )
429 - WHERE 1=1
430 - {$exclude_query}
431 - AND (
432 - first_name_meta.meta_value LIKE %s
433 - OR last_name_meta.meta_value LIKE %s
434 - OR nickname_meta.meta_value LIKE %s
435 - OR user_login LIKE %s
436 - OR user_nicename LIKE %s
437 - OR display_name LIKE %s
380 + if (empty($where)) {
381 + $user_query = $wpdb->prepare("SELECT DISTINCT SQL_CALC_FOUND_ROWS $wpdb->users.*
382 + FROM $wpdb->users
383 + INNER JOIN $wpdb->usermeta
384 + ON ( $wpdb->users.ID = $wpdb->usermeta.user_id )
385 + WHERE 1=1
386 + $exclude_query
387 + AND (
388 + ( $wpdb->usermeta.meta_key = 'first_name' AND $wpdb->usermeta.meta_value LIKE %s )
389 + OR
390 + ( $wpdb->usermeta.meta_key = 'last_name' AND $wpdb->usermeta.meta_value LIKE %s )
391 + OR user_login LIKE %s OR user_nicename LIKE %s OR display_name LIKE %s
392 + )
393 + ORDER BY display_name ASC",
394 + array(
395 + '%' . $keyword . '%',
396 + '%' . $keyword . '%',
397 + '%' . $keyword . '%',
398 + '%' . $keyword . '%',
399 + '%' . $keyword . '%',
438 400 )
439 - ORDER BY display_name ASC",
440 - $search_term,
441 - $search_term,
442 - $search_term,
443 - $search_term,
444 - $search_term,
445 - $search_term
446 401 );
447 - } else {
448 - // Custom where clause with uwp_usermeta table
402 + } else{
449 403 $usermeta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
450 404 $keyword_query = '';
451 405
452 - if ( $keyword ) {
453 - $search_term = '%' . $wpdb->esc_like( $keyword ) . '%';
454 - $keyword_query = $wpdb->prepare(
455 - " AND (( {$wpdb->usermeta}.meta_key = 'first_name' AND {$wpdb->usermeta}.meta_value LIKE %s )
456 - OR ( {$wpdb->usermeta}.meta_key = 'last_name' AND {$wpdb->usermeta}.meta_value LIKE %s )
457 - OR ( {$wpdb->usermeta}.meta_key = 'nickname' AND {$wpdb->usermeta}.meta_value LIKE %s )
458 - OR user_login LIKE %s
459 - OR user_nicename LIKE %s
460 - OR display_name LIKE %s)",
461 - $search_term,
462 - $search_term,
463 - $search_term,
464 - $search_term,
465 - $search_term,
466 - $search_term
467 - );
406 + if($keyword) {
407 + $keyword_query = " AND (( $wpdb->usermeta.meta_key = 'first_name' AND $wpdb->usermeta.meta_value LIKE '$keyword' )
408 + OR ( $wpdb->usermeta.meta_key = 'last_name' AND $wpdb->usermeta.meta_value LIKE '$keyword' )
409 + OR 'user_login' LIKE '$keyword' OR 'user_nicename' LIKE '$keyword' OR 'display_name' LIKE '$keyword')";
468 410 }
469 411
470 - $user_query = "SELECT DISTINCT SQL_CALC_FOUND_ROWS {$wpdb->users}.*
471 - FROM {$wpdb->users}
472 - INNER JOIN {$wpdb->usermeta} ON ( {$wpdb->users}.ID = {$wpdb->usermeta}.user_id )
473 - INNER JOIN {$usermeta_table} ON ( {$wpdb->users}.ID = {$usermeta_table}.user_id )
474 - WHERE 1=1 {$keyword_query} {$exclude_query} {$where}
475 - ORDER BY display_name ASC";
412 + $user_query = "SELECT DISTINCT SQL_CALC_FOUND_ROWS $wpdb->users.* FROM $wpdb->users
413 + INNER JOIN $wpdb->usermeta ON ( $wpdb->users.ID = $wpdb->usermeta.user_id )
414 + INNER JOIN $usermeta_table ON ( $wpdb->users.ID = $usermeta_table.user_id )
415 + WHERE 1=1 $keyword_query $exclude_query $where ORDER BY display_name ASC";
476 416 }
477 417
478 - // Execute search query
479 - $user_results = $wpdb->get_results( $user_query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
480 - $get_users = wp_list_pluck( $user_results, 'ID' );
418 + $user_results = $wpdb->get_results($user_query); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
419 + $get_users = wp_list_pluck($user_results, 'ID');
481 420
482 - // Filter by roles if specified
483 - if ( ! empty( $roles ) && is_array( $roles ) ) {
484 - $role_users = get_users( array(
485 - 'role__in' => $roles,
486 - 'fields' => array( 'ID' )
487 - ) );
488 - $role_user_ids = wp_list_pluck( $role_users, 'ID' );
489 -
490 - if ( ! empty( $get_users ) && ! empty( $role_user_ids ) ) {
491 - $get_users = array_intersect( $get_users, $role_user_ids );
421 + if(isset($roles) && is_array($roles) && count($roles) > 0){
422 + $users = get_users( array( 'role__in' => $roles, 'fields' => array('ID') ) );
423 + $users = wp_list_pluck( $users, 'ID' );
424 + if($get_users && count($get_users) > 0 && $users && count($users) > 0){
425 + foreach ($get_users as $key => $get_user){
426 + if(!in_array($get_user, $users)){
427 + unset($get_users[$key]);
428 + }
429 + }
492 430 }
493 431 }
494 432
495 - // Process results if we have users
496 - if ( ! empty( $get_users ) && is_array( $get_users ) ) {
497 - // Prepare WP_User_Query arguments
433 + if(!empty($get_users) && is_array($get_users) && count($get_users) > 0){
434 +
498 435 $args = array(
499 436 'include' => $get_users,
500 - 'number' => $number,
501 - 'paged' => $paged,
437 + 'number' => (int) $number,
438 + 'paged' => (int) $paged,
502 439 );
503 440
504 - // Add exclude users if any
505 - if ( ! empty( $exclude_users ) ) {
441 + if(!empty($exclude_users)) {
506 442 $args['exclude'] = $exclude_users;
507 443 }
508 444
509 - // Add meta_key if specified
510 - if ( ! empty( $meta_key ) ) {
445 + if(!empty($meta_key)) {
511 446 $args['meta_key'] = $meta_key;
512 447 }
513 448
514 - // Handle sorting
515 - if ( ! empty( $order_by ) && ! empty( $order ) ) {
516 - if ( in_array( $order_by, array( 'first_name', 'last_name' ), true ) ) {
517 - $args['meta_key'] = $order_by;
518 - $args['orderby'] = 'meta_value';
519 - $args['order'] = $order;
520 - } else {
521 - $args['orderby'] = $order_by;
522 - $args['order'] = $order;
523 - }
449 + if(!empty($order_by) && !empty($order) ) {
450 + $args['orderby'] = $order_by;
451 + $args['order'] = $order;
524 452 }
525 453
526 - // Execute WP_User_Query
527 - $uwp_users_query = new WP_User_Query( $args );
454 + $uwp_users_query = new WP_User_Query($args);
528 455 $users['users'] = $uwp_users_query->get_results();
529 456 $users['total_users'] = $uwp_users_query->get_total();
530 457
531 458 } else {
@@ -531,49 +458,51 @@
531 458 } else {
532 459 $users['users'] = array();
533 460 $users['total_users'] = 0;
534 461 }
462 +
535 463 } else {
536 - // No search criteria - get all users with optional role filtering
537 464 $args = array(
538 - 'number' => $number,
539 - 'paged' => $paged,
465 + 'number' => (int) $number,
466 + 'paged' => (int) $paged,
540 467 );
541 468
542 - // Add exclude users if any
543 - if ( ! empty( $exclude_users ) ) {
469 + $roles_args = array(
470 + 'fields' => array('ID'),
471 + );
472 +
473 + if(!empty($exclude_users)) {
544 474 $args['exclude'] = $exclude_users;
475 + $roles_args['exclude'] = $exclude_users;
545 476 }
546 477
547 - // Filter by roles if specified
548 - if ( ! empty( $roles ) && is_array( $roles ) ) {
549 - $args['role__in'] = $roles;
478 + if(isset($roles) && is_array($roles) && count($roles) > 0){
479 + $include_users = array();
480 + $roles_args['role__in'] = $roles;
481 + $users = get_users( $roles_args );
482 + $users = wp_list_pluck( $users, 'ID' );
483 + if($users && count($users) > 0){
484 + $include_users = array_merge($include_users, $users);
485 + $args['include'] = $include_users;
486 + }
550 487 }
551 488
552 - // Add meta_key if specified
553 - if ( ! empty( $meta_key ) ) {
489 + if(!empty($meta_key)) {
554 490 $args['meta_key'] = $meta_key;
555 491 }
556 492
557 - // Handle sorting
558 - if ( ! empty( $order_by ) && ! empty( $order ) ) {
559 - if ( in_array( $order_by, array( 'first_name', 'last_name' ), true ) ) {
560 - $args['meta_key'] = $order_by;
561 - $args['orderby'] = 'meta_value';
562 - $args['order'] = $order;
563 - } else {
564 - $args['orderby'] = $order_by;
565 - $args['order'] = $order;
566 - }
493 + if(!empty($order_by) && !empty($order) ) {
494 + $args['orderby'] = $order_by;
495 + $args['order'] = $order;
567 496 }
568 497
569 - // Execute WP_User_Query
570 - $uwp_users_query = new WP_User_Query( $args );
498 + $uwp_users_query = new WP_User_Query($args);
571 499 $users['users'] = $uwp_users_query->get_results();
572 500 $users['total_users'] = $uwp_users_query->get_total();
573 501 }
574 502
575 503 return $users;
504 +
576 505 }
577 506
578 507 /**
579 508 * Returns the Users page layout class based on the setting.
@@ -582,17 +511,16 @@
582 511 * @package userswp
583 512 *
584 513 * @return string Layout class.
585 514 */
586 -function uwp_get_layout_class($layout, $count_only = false)
587 -{
588 - if (!$layout) {
589 - if (uwp_get_option("design_style", 'bootstrap')) {
590 - $value = '3col';
591 - } else {
515 +function uwp_get_layout_class($layout, $count_only = false) {
516 + if(!$layout){
517 + if(uwp_get_option("design_style",'bootstrap')){
518 + $value = '3col';
519 + } else {
592 520 $value = 'list';
593 - }
594 - $layout = uwp_get_option('users_default_layout', $value);
521 + }
522 + $layout = uwp_get_option('users_default_layout', $value);
595 523 }
596 524
597 525 switch ($layout) {
598 526 case "list":
@@ -625,22 +553,22 @@
625 553 $bs_class = "row-cols-md-3";
626 554 $col_count = 1;
627 555 }
628 556
629 - if ($count_only) {
557 + if($count_only){
630 558 return $col_count;
631 559 }
632 560
633 - if (uwp_get_option("design_style", 'bootstrap')) {
634 - return $bs_class;
635 - }
561 + if(uwp_get_option("design_style",'bootstrap')){
562 + return $bs_class;
563 + }
636 564
637 565 return $class;
638 566 }
639 567
640 -add_filter('uwp_users_list_ul_extra_class', 'uwp_get_layout_class', 10, 1);
568 +add_filter( 'uwp_users_list_ul_extra_class', 'uwp_get_layout_class', 10, 1 );
641 569
642 -add_filter('get_user_option_metaboxhidden_nav-menus', 'uwp_always_nav_menu_visibility', 10, 3);
570 +add_filter( 'get_user_option_metaboxhidden_nav-menus', 'uwp_always_nav_menu_visibility', 10, 3 );
643 571
644 572 /**
645 573 * Filters nav menu visibility option value.
646 574 *
@@ -652,12 +580,12 @@
652 580 * @param WP_User $user WP_User object of the user whose option is being retrieved.
653 581 *
654 582 * @return array Filtered value.
655 583 */
656 -function uwp_always_nav_menu_visibility($result, $option, $user)
584 +function uwp_always_nav_menu_visibility( $result, $option, $user )
657 585 {
658 - if (is_array($result) && in_array('add-users-wp-nav-menu', $result)) {
659 - $result = array_diff($result, array('add-users-wp-nav-menu'));
586 + if( is_array($result) && in_array( 'add-users-wp-nav-menu', $result ) ) {
587 + $result = array_diff( $result, array( 'add-users-wp-nav-menu' ) );
660 588 }
661 589
662 590 return $result;
663 591 }
@@ -675,21 +603,20 @@
675 603 * @param string $type Tab type.
676 604 *
677 605 * @return string Title.
678 606 */
679 -function uwp_account_privacy_page_title($title, $type)
680 -{
607 +function uwp_account_privacy_page_title($title, $type) {
681 608
682 609 if ($type == 'privacy') {
683 - $title = __('Privacy', 'userswp');
610 + $title = __( 'Privacy', 'userswp' );
684 611 } elseif ($type == 'notifications') {
685 - $title = __('E-Mail Notifications', 'userswp');
612 + $title = __( 'E-Mail Notifications', 'userswp' );
686 613 } elseif ($type == 'delete-account') {
687 - $title = __('Delete Account', 'userswp');
614 + $title = __( 'Delete Account', 'userswp' );
688 615 } elseif ($type == 'change-password') {
689 - $title = __('Change Password', 'userswp');
690 - } elseif ($type == 'wp2fa') {
691 - $title = __('Two-factor Authentication Settings', 'userswp');
616 + $title = __( 'Change Password', 'userswp' );
617 + } elseif ($type == 'wp2fa') {
618 + $title = __( 'Two-factor Authentication Settings', 'userswp' );
692 619 }
693 620
694 621 return $title;
695 622 }
@@ -703,11 +630,10 @@
703 630 * @package userswp
704 631 *
705 632 * @return void
706 633 */
707 -function uwp_add_account_menu_links()
708 -{
709 - global $aui_bs5;
634 +function uwp_add_account_menu_links() {
635 + global $aui_bs5;
710 636
711 637 if (isset($_GET['type'])) {
712 638 $type = strip_tags(esc_sql($_GET['type']));
713 639 } else {
@@ -724,12 +650,12 @@
724 650 }
725 651
726 652 $legacy = '<ul class="uwp_account_menu">';
727 653 ob_start();
728 -?>
729 - <ul class="<?php echo $aui_bs5 ? 'nav' : 'navbar-nav'; ?> m-0 p-0 mt-3 list-unstyled flex-lg-column flex-row flex-wrap" aria-labelledby="account_settings">
654 + ?>
655 + <ul class="<?php echo $aui_bs5 ? 'nav' : 'navbar-nav'; ?> m-0 p-0 mt-3 list-unstyled flex-lg-column flex-row flex-wrap" aria-labelledby="account_settings">
730 656 <?php
731 - foreach ($account_available_tabs as $tab_id => $tab) {
657 + foreach( $account_available_tabs as $tab_id => $tab ) {
732 658
733 659 if ($tab_id == 'account') {
734 660 $tab_url = $account_page_link;
735 661 } else {
@@ -743,26 +669,26 @@
743 669 }
744 670
745 671 $active = $type == $tab_id ? ' active' : '';
746 672
747 - ?>
748 - <li class="nav-item m-0 p-0 list-unstyled mx-md-2 mx-2">
749 - <a class="nav-link text-decoration-none uwp-account-<?php echo esc_attr($tab_id . ' ' . $active); ?>" href="<?php echo esc_url($tab_url); ?>"><?php echo '<i class="' . esc_attr($tab["icon"]) . ' mr-1 fa-fw"></i>' . esc_html($tab['title']); ?></a>
750 - </li>
751 - <?php
673 + ?>
674 + <li class="nav-item m-0 p-0 list-unstyled mx-md-2 mx-2">
675 + <a class="nav-link text-decoration-none uwp-account-<?php echo esc_attr( $tab_id.' '.$active ); ?>" href="<?php echo esc_url( $tab_url ); ?>"><?php echo '<i class="'.esc_attr($tab["icon"]).' mr-1 fa-fw"></i>'.esc_html($tab['title']); ?></a>
676 + </li>
677 + <?php
752 678
753 - $legacy .= '<li id="uwp-account-' . $tab_id . '">';
754 - $legacy .= '<a class="' . $active . '" href="' . esc_url($tab_url) . '">';
755 - $legacy .= '<i class="' . esc_attr($tab["icon"]) . '"></i>' . esc_html($tab["title"]);
679 + $legacy .= '<li id="uwp-account-'.$tab_id.'">';
680 + $legacy .= '<a class="'.$active.'" href="'.esc_url( $tab_url ).'">';
681 + $legacy .= '<i class="'.esc_attr($tab["icon"]).'"></i>'.esc_html($tab["title"]);
756 682 $legacy .= '</a></li>';
757 683 }
758 684 ?>
759 - </ul>
685 + </ul>
760 686 <?php
761 687 $legacy .= '</ul>';
762 688 $bs_output = ob_get_clean();
763 689 $style = uwp_get_option('design_style', 'bootstrap');
764 - if (!empty($style)) {
690 + if(!empty($style)){
765 691 echo $bs_output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
766 692 } else {
767 693 echo $legacy; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
768 694 }
@@ -795,9 +721,9 @@
795 721 $extras_table_name,
796 722 array(
797 723 'sort_order' => $count,
798 724 ),
799 - array('id' => $cf, 'form_id' => $form_id)
725 + array( 'id' => $cf, 'form_id' => $form_id )
800 726 );
801 727
802 728 $count++;
803 729 }
@@ -818,10 +744,9 @@
818 744 * @param string $charset Charset.
819 745 *
820 746 * @return string Converted string.
821 747 */
822 -function uwp_ucwords($string, $charset = 'UTF-8')
823 -{
748 +function uwp_ucwords($string, $charset='UTF-8') {
824 749 if (function_exists('mb_convert_case')) {
825 750 return mb_convert_case($string, MB_CASE_TITLE, $charset);
826 751 } else {
827 752 return ucwords($string);
@@ -860,8 +785,9 @@
860 785 function uwp_add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NOT NULL")
861 786 {
862 787 $table = new UsersWP_Tables();
863 788 return $table->add_column_if_not_exist($db, $column, $column_attr);
789 +
864 790 }
865 791
866 792 /**
867 793 * Returns excluded custom fields.
@@ -870,16 +796,15 @@
870 796 * @package userswp
871 797 *
872 798 * @return array Excluded custom fields.
873 799 */
874 -function uwp_get_excluded_fields()
875 -{
800 +function uwp_get_excluded_fields() {
876 801 $excluded = array(
877 802 'password',
878 803 'confirm_password',
879 804 'user_privacy',
880 805 );
881 - return apply_filters('uwp_excluded_fields', $excluded);
806 + return apply_filters('uwp_excluded_fields',$excluded);
882 807 }
883 808
884 809 /**
885 810 * Formats the currency using currency separator.
@@ -891,10 +816,9 @@
891 816 * @param array|string $cf Custom field info.
892 817 *
893 818 * @return string Formatted currency.
894 819 */
895 -function uwp_currency_format_number($number = '', $cf = '')
896 -{
820 +function uwp_currency_format_number($number='',$cf=''){
897 821
898 822 $cs = isset($cf['extra_fields']) ? maybe_unserialize($cf['extra_fields']) : '';
899 823
900 824 $symbol = isset($cs['currency_symbol']) ? $cs['currency_symbol'] : '$';
@@ -901,46 +825,36 @@
901 825 $decimals = isset($cf['decimal_point']) && $cf['decimal_point'] ? $cf['decimal_point'] : 2;
902 826 $decimal_display = isset($cf['decimal_display']) && $cf['decimal_display'] ? $cf['decimal_display'] : 'if';
903 827 $decimalpoint = '.';
904 828
905 - if (isset($cs['decimal_separator']) && $cs['decimal_separator'] == 'comma') {
829 + if(isset($cs['decimal_separator']) && $cs['decimal_separator']=='comma'){
906 830 $decimalpoint = ',';
907 831 }
908 832
909 833 $separator = ',';
910 834
911 - if (isset($cs['thousand_separator'])) {
912 - if ($cs['thousand_separator'] == 'comma') {
913 - $separator = ',';
914 - }
915 - if ($cs['thousand_separator'] == 'slash') {
916 - $separator = '\\';
917 - }
918 - if ($cs['thousand_separator'] == 'period') {
919 - $separator = '.';
920 - }
921 - if ($cs['thousand_separator'] == 'space') {
922 - $separator = ' ';
923 - }
924 - if ($cs['thousand_separator'] == 'none') {
925 - $separator = '';
926 - }
835 + if(isset($cs['thousand_separator'])){
836 + if($cs['thousand_separator']=='comma'){$separator = ',';}
837 + if($cs['thousand_separator']=='slash'){$separator = '\\';}
838 + if($cs['thousand_separator']=='period'){$separator = '.';}
839 + if($cs['thousand_separator']=='space'){$separator = ' ';}
840 + if($cs['thousand_separator']=='none'){$separator = '';}
927 841 }
928 842
929 843 $currency_symbol_placement = isset($cs['currency_symbol_placement']) ? $cs['currency_symbol_placement'] : 'left';
930 844
931 - if ($decimals > 0 && $decimal_display == 'if') {
932 - if (is_int($number) || floor($number) == $number)
845 + if($decimals>0 && $decimal_display=='if'){
846 + if(is_int($number) || floor( $number ) == $number)
933 847 $decimals = 0;
934 848 }
935 849
936 - $number = number_format($number, $decimals, $decimalpoint, $separator);
850 + $number = number_format($number,$decimals,$decimalpoint,$separator);
937 851
938 852
939 853
940 - if ($currency_symbol_placement == 'left') {
854 + if($currency_symbol_placement=='left'){
941 855 $number = $symbol . $number;
942 - } else {
856 + }else{
943 857 $number = $number . $symbol;
944 858 }
945 859
946 860
@@ -955,10 +869,9 @@
955 869 * @package userswp
956 870 *
957 871 * @return bool
958 872 */
959 -function uwp_can_make_profile_private()
960 -{
873 +function uwp_can_make_profile_private() {
961 874 $make_profile_private = apply_filters('uwp_user_can_make_profile_private', false);
962 875 return $make_profile_private;
963 876 }
964 877
@@ -969,21 +882,20 @@
969 882 * @package userswp
970 883 *
971 884 * @return string Installation type.
972 885 */
973 -function uwp_get_installation_type()
974 -{
886 +function uwp_get_installation_type() {
975 887 // *. Single Site
976 888 if (!is_multisite()) {
977 889 return "single";
978 890 } else {
979 891 // Multisite
980 - if (! function_exists('is_plugin_active_for_network')) {
981 - require_once(ABSPATH . '/wp-admin/includes/plugin.php');
892 + if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
893 + require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
982 894 }
983 895
984 896 // Network active.
985 - if (is_plugin_active_for_network('userswp/userswp.php')) {
897 + if ( is_plugin_active_for_network( 'userswp/userswp.php' ) ) {
986 898 if (defined('UWP_ROOT_PAGES')) {
987 899 if (UWP_ROOT_PAGES == 'all') {
988 900 // *. Multisite - Network Active - Pages on all sites
989 901 return "multi_na_all";
@@ -1010,10 +922,9 @@
1010 922 * @package userswp
1011 923 *
1012 924 * @return string Table prefix
1013 925 */
1014 -function uwp_get_table_prefix()
1015 -{
926 +function uwp_get_table_prefix() {
1016 927 $tables = new UsersWP_Tables();
1017 928 return $tables->get_table_prefix();
1018 929 }
1019 930
@@ -1024,10 +935,9 @@
1024 935 * @package userswp
1025 936 *
1026 937 * @return string Table prefix
1027 938 */
1028 -function get_usermeta_table_prefix()
1029 -{
939 +function get_usermeta_table_prefix() {
1030 940 $tables = new UsersWP_Tables();
1031 941 return $tables->get_usermeta_table_prefix();
1032 942 }
1033 943
@@ -1042,10 +952,9 @@
1042 952 * @param string $value Custom field value.
1043 953 *
1044 954 * @return string Converted custom field value string.
1045 955 */
1046 -function uwp_maybe_serialize($key, $value)
1047 -{
956 +function uwp_maybe_serialize($key, $value) {
1048 957 $field = uwp_get_custom_field_info($key);
1049 958 if (isset($field->field_type) && $field->field_type == 'multiselect' && is_array($value)) {
1050 959 $value = implode(",", $value);
1051 960 }
@@ -1062,10 +971,9 @@
1062 971 * @param string $value Custom field value.
1063 972 *
1064 973 * @return array Converted custom field value array.
1065 974 */
1066 -function uwp_maybe_unserialize($key, $value)
1067 -{
975 +function uwp_maybe_unserialize($key, $value) {
1068 976 $field = uwp_get_custom_field_info($key);
1069 977 if (isset($field->field_type) && $field->field_type == 'multiselect' && $value) {
1070 978 $value = explode(",", $value);
1071 979 }
@@ -1093,10 +1001,9 @@
1093 1001 * @package userswp
1094 1002 *
1095 1003 * @return string IP address.
1096 1004 */
1097 -function uwp_get_ip()
1098 -{
1005 +function uwp_get_ip() {
1099 1006 if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
1100 1007 //check ip from share internet
1101 1008 $ip = $_SERVER['HTTP_CLIENT_IP'];
1102 1009 } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
@@ -1157,23 +1064,22 @@
1157 1064 * @param string $type Field type.
1158 1065 *
1159 1066 * @return string Font awesome icon value.
1160 1067 */
1161 -function uwp_field_type_to_fa_icon($type)
1162 -{
1068 +function uwp_field_type_to_fa_icon($type) {
1163 1069 $field_types = array(
1164 1070 'text' => 'fas fa-minus',
1165 1071 'datepicker' => 'fas fa-calendar-alt',
1166 1072 'textarea' => 'fas fa-bars',
1167 - 'time' => 'far fa-clock',
1168 - 'checkbox' => 'far fa-check-square',
1169 - 'phone' => 'far fa-phone',
1170 - 'radio' => 'far fa-dot-circle',
1171 - 'email' => 'far fa-envelope',
1172 - 'select' => 'far fa-caret-square-down',
1173 - 'multiselect' => 'far fa-caret-square-down',
1174 - 'url' => 'fas fa-link',
1175 - 'file' => 'fas fa-file'
1073 + 'time' =>'far fa-clock',
1074 + 'checkbox' =>'far fa-check-square',
1075 + 'phone' =>'far fa-phone',
1076 + 'radio' =>'far fa-dot-circle',
1077 + 'email' =>'far fa-envelope',
1078 + 'select' =>'far fa-caret-square-down',
1079 + 'multiselect' =>'far fa-caret-square-down',
1080 + 'url' =>'fas fa-link',
1081 + 'file' =>'fas fa-file'
1176 1082 );
1177 1083
1178 1084 if (isset($field_types[$type])) {
1179 1085 return $field_types[$type];
@@ -1179,8 +1085,9 @@
1179 1085 return $field_types[$type];
1180 1086 } else {
1181 1087 return "";
1182 1088 }
1089 +
1183 1090 }
1184 1091
1185 1092 /**
1186 1093 * Check wpml active or not.
@@ -1188,12 +1095,11 @@
1188 1095 * @since 1.0.7
1189 1096 *
1190 1097 * @return True if WPML is active else False.
1191 1098 */
1192 -function uwp_is_wpml()
1193 -{
1194 - if (defined('ICL_SITEPRESS_VERSION') && ! ICL_PLUGIN_INACTIVE && class_exists('SitePress') && function_exists('icl_object_id')) {
1195 - return true;
1099 +function uwp_is_wpml() {
1100 + if ( defined( 'ICL_SITEPRESS_VERSION' ) && ! ICL_PLUGIN_INACTIVE && class_exists( 'SitePress' ) && function_exists( 'icl_object_id' ) ) {
1101 + return true;
1196 1102 }
1197 1103
1198 1104 return false;
1199 1105 }
@@ -1212,15 +1118,14 @@
1212 1118 * the original if the translation is missing and $return_original_if_missing is set to TRUE.
1213 1119 *
1214 1120 * @return int|NULL
1215 1121 */
1216 -function uwp_wpml_object_id($element_id, $element_type = 'post', $return_original_if_missing = false, $ulanguage_code = null)
1217 -{
1218 - if (uwp_is_wpml()) {
1219 - if (function_exists('wpml_object_id_filter')) {
1220 - return apply_filters('wpml_object_id', $element_id, $element_type, $return_original_if_missing, $ulanguage_code);
1122 +function uwp_wpml_object_id( $element_id, $element_type = 'post', $return_original_if_missing = false, $ulanguage_code = null ) {
1123 + if ( uwp_is_wpml() ) {
1124 + if ( function_exists( 'wpml_object_id_filter' ) ) {
1125 + return apply_filters( 'wpml_object_id', $element_id, $element_type, $return_original_if_missing, $ulanguage_code );
1221 1126 } else {
1222 - return icl_object_id($element_id, $element_type, $return_original_if_missing, $ulanguage_code);
1127 + return icl_object_id( $element_id, $element_type, $return_original_if_missing, $ulanguage_code );
1223 1128 }
1224 1129 }
1225 1130
1226 1131 return $element_id;
@@ -1230,15 +1135,14 @@
1230 1135 * Check if we might be on localhost.
1231 1136 *
1232 1137 * @return bool
1233 1138 */
1234 -function uwp_is_localhost()
1235 -{
1139 +function uwp_is_localhost(){
1236 1140 $localhost = false;
1237 1141
1238 - if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'localhost') {
1142 + if( isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME']=='localhost' ){
1239 1143 $localhost = true;
1240 - } elseif (isset($_SERVER['SERVER_ADDR']) && ($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] == '::1')) {
1144 + }elseif(isset($_SERVER['SERVER_ADDR']) && ( $_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] == '::1' ) ){
1241 1145 $localhost = true;
1242 1146 }
1243 1147
1244 1148 return $localhost;
@@ -1243,13 +1147,12 @@
1243 1147
1244 1148 return $localhost;
1245 1149 }
1246 1150
1247 -function uwp_get_default_avatar_uri()
1248 -{
1151 +function uwp_get_default_avatar_uri(){
1249 1152 $default = uwp_get_option('profile_default_profile', '');
1250 - if (empty($default)) {
1251 - $default = USERSWP_PLUGIN_URL . "assets/images/no_profile.png";
1153 + if(empty($default)){
1154 + $default = USERSWP_PLUGIN_URL."assets/images/no_profile.png";
1252 1155 } else {
1253 1156 $default = wp_get_attachment_url($default);
1254 1157 }
1255 1158
@@ -1255,19 +1158,17 @@
1255 1158
1256 1159 return apply_filters('uwp_default_avatar_uri', $default);
1257 1160 }
1258 1161
1259 -function uwp_get_default_thumb_uri()
1260 -{
1261 - $thumb_url = USERSWP_PLUGIN_URL . "assets/images/no_thumb.png";
1162 +function uwp_get_default_thumb_uri(){
1163 + $thumb_url = USERSWP_PLUGIN_URL."assets/images/no_thumb.png";
1262 1164 return apply_filters('uwp_default_thumb_uri', $thumb_url);
1263 1165 }
1264 1166
1265 -function uwp_get_default_banner_uri()
1266 -{
1167 +function uwp_get_default_banner_uri(){
1267 1168 $banner = uwp_get_option('profile_default_banner', '');
1268 - if (empty($banner)) {
1269 - $banner_url = USERSWP_PLUGIN_URL . "assets/images/banner.png";
1169 + if(empty($banner)) {
1170 + $banner_url = USERSWP_PLUGIN_URL."assets/images/banner.png";
1270 1171 } else {
1271 1172 $banner_url = wp_get_attachment_url($banner);
1272 1173 }
1273 1174 return apply_filters('uwp_default_banner_uri', $banner_url);
@@ -1279,19 +1180,18 @@
1279 1180 * @param $uploads array upload variable array
1280 1181 *
1281 1182 * @return array updated upload variable array.
1282 1183 */
1283 -function uwp_handle_multisite_profile_image($uploads)
1284 -{
1285 - if (! function_exists('is_plugin_active_for_network')) {
1286 - require_once(ABSPATH . '/wp-admin/includes/plugin.php');
1184 +function uwp_handle_multisite_profile_image($uploads){
1185 + if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
1186 + require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
1287 1187 }
1288 1188
1289 1189 // Network active.
1290 - if (is_plugin_active_for_network('userswp/userswp.php')) {
1190 + if ( is_plugin_active_for_network( 'userswp/userswp.php' ) ) {
1291 1191 $main_site = get_network()->site_id;
1292 - switch_to_blog($main_site);
1293 - remove_filter('upload_dir', 'uwp_handle_multisite_profile_image');
1192 + switch_to_blog( $main_site );
1193 + remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image');
1294 1194 $uploads = wp_upload_dir();
1295 1195 restore_current_blog();
1296 1196 }
1297 1197
@@ -1306,13 +1206,12 @@
1306 1206 * @since 2.0.0
1307 1207 * @param $size
1308 1208 * @return int
1309 1209 */
1310 -function uwp_let_to_num($size)
1311 -{
1312 - $l = substr($size, -1);
1313 - $ret = substr($size, 0, -1);
1314 - switch (strtoupper($l)) {
1210 +function uwp_let_to_num( $size ) {
1211 + $l = substr( $size, -1 );
1212 + $ret = substr( $size, 0, -1 );
1213 + switch ( strtoupper( $l ) ) {
1315 1214 case 'P':
1316 1215 $ret *= 1024;
1317 1216 case 'T':
1318 1217 $ret *= 1024;
@@ -1325,32 +1224,31 @@
1325 1224 }
1326 1225 return $ret;
1327 1226 }
1328 1227
1329 -function uwp_format_decimal($number, $dp = false, $trim_zeros = false)
1330 -{
1228 +function uwp_format_decimal($number, $dp = false, $trim_zeros = false){
1331 1229 $locale = localeconv();
1332 - $decimals = array(uwp_get_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point']);
1230 + $decimals = array( uwp_get_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] );
1333 1231
1334 1232 // Remove locale from string.
1335 - if (! is_float($number)) {
1336 - $number = str_replace($decimals, '.', $number);
1337 - $number = preg_replace('/[^0-9\.,-]/', '', uwp_clean($number));
1233 + if ( ! is_float( $number ) ) {
1234 + $number = str_replace( $decimals, '.', $number );
1235 + $number = preg_replace( '/[^0-9\.,-]/', '', uwp_clean( $number ) );
1338 1236 }
1339 1237
1340 - if (false !== $dp) {
1341 - $dp = intval('' == $dp ? uwp_get_decimal_separator() : $dp);
1342 - $number = number_format(floatval($number), $dp, '.', '');
1238 + if ( false !== $dp ) {
1239 + $dp = intval( '' == $dp ? uwp_get_decimal_separator() : $dp );
1240 + $number = number_format( floatval( $number ), $dp, '.', '' );
1343 1241 // DP is false - don't use number format, just return a string in our format
1344 - } elseif (is_float($number)) {
1242 + } elseif ( is_float( $number ) ) {
1345 1243 // DP is false - don't use number format, just return a string using whatever is given. Remove scientific notation using sprintf.
1346 - $number = str_replace($decimals, '.', sprintf('%.' . uwp_get_rounding_precision() . 'f', $number));
1244 + $number = str_replace( $decimals, '.', sprintf( '%.' . uwp_get_rounding_precision() . 'f', $number ) );
1347 1245 // We already had a float, so trailing zeros are not needed.
1348 1246 $trim_zeros = true;
1349 1247 }
1350 1248
1351 - if ($trim_zeros && strstr($number, '.')) {
1352 - $number = rtrim(rtrim($number, '0'), '.');
1249 + if ( $trim_zeros && strstr( $number, '.' ) ) {
1250 + $number = rtrim( rtrim( $number, '0' ), '.' );
1353 1251 }
1354 1252
1355 1253 return $number;
1356 1254 }
@@ -1359,12 +1257,11 @@
1359 1257 * Return the decimal separator.
1360 1258 * @since 1.0.20
1361 1259 * @return string
1362 1260 */
1363 -function uwp_get_decimal_separator()
1364 -{
1365 - $separator = apply_filters('uwp_decimal_separator', '.');
1366 - return $separator ? stripslashes($separator) : '.';
1261 +function uwp_get_decimal_separator() {
1262 + $separator = apply_filters( 'uwp_decimal_separator', '.' );
1263 + return $separator ? stripslashes( $separator ) : '.';
1367 1264 }
1368 1265
1369 1266 /**
1370 1267 * Get rounding precision for internal UWP calculations.
@@ -1372,13 +1269,12 @@
1372 1269 *
1373 1270 * @since 1.0.20
1374 1271 * @return int
1375 1272 */
1376 -function uwp_get_rounding_precision()
1377 -{
1273 +function uwp_get_rounding_precision() {
1378 1274 $precision = uwp_get_decimal_separator() + 2;
1379 - if (defined(UWP_ROUNDING_PRECISION) && absint(UWP_ROUNDING_PRECISION) > $precision) {
1380 - $precision = absint(UWP_ROUNDING_PRECISION);
1275 + if ( defined(UWP_ROUNDING_PRECISION) && absint( UWP_ROUNDING_PRECISION ) > $precision ) {
1276 + $precision = absint( UWP_ROUNDING_PRECISION );
1381 1277 }
1382 1278 return $precision;
1383 1279 }
1384 1280
@@ -1389,16 +1285,16 @@
1389 1285 * @param string|array $var
1390 1286 *
1391 1287 * @return string|array
1392 1288 */
1393 -function uwp_clean($var)
1394 -{
1289 +function uwp_clean( $var ) {
1395 1290
1396 - if (is_array($var)) {
1397 - return array_map('uwp_clean', $var);
1291 + if ( is_array( $var ) ) {
1292 + return array_map( 'uwp_clean', $var );
1398 1293 } else {
1399 - return is_scalar($var) ? sanitize_text_field($var) : $var;
1294 + return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
1400 1295 }
1296 +
1401 1297 }
1402 1298
1403 1299 /**
1404 1300 * Define a constant if it is not already defined.
@@ -1407,33 +1303,30 @@
1407 1303 *
1408 1304 * @param string $name Constant name.
1409 1305 * @param string $value Value.
1410 1306 */
1411 -function uwp_maybe_define($name, $value)
1412 -{
1413 - if (! defined($name)) {
1414 - define($name, $value);
1307 +function uwp_maybe_define( $name, $value ) {
1308 + if ( ! defined( $name ) ) {
1309 + define( $name, $value );
1415 1310 }
1416 1311 }
1417 1312
1418 -function uwp_insert_usermeta()
1419 -{
1313 +function uwp_insert_usermeta(){
1420 1314 global $wpdb;
1421 - $sort = "user_registered";
1315 + $sort= "user_registered";
1422 1316
1423 - $all_users_id = $wpdb->get_col($wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1424 - "SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC",
1425 - $sort
1426 - ));
1317 + $all_users_id = $wpdb->get_col( $wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1318 + "SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC"
1319 + , $sort ));
1427 1320
1428 1321 //we got all the IDs, now loop through them to get individual IDs
1429 - foreach ($all_users_id as $user_id) {
1322 + foreach ( $all_users_id as $user_id ) {
1430 1323 $user_data = get_userdata($user_id);
1431 1324
1432 1325 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
1433 1326 $user_meta = array(
1434 1327 'username' => $user_data->user_login,
1435 - 'email' => sanitize_email($user_data->user_email),
1328 + 'email' => sanitize_email( $user_data->user_email ),
1436 1329 'first_name' => $user_data->first_name,
1437 1330 'last_name' => $user_data->last_name,
1438 1331 'display_name' => $user_data->display_name,
1439 1332 );
@@ -1439,15 +1332,15 @@
1439 1332 );
1440 1333
1441 1334 $users = $wpdb->get_var($wpdb->prepare("SELECT COUNT(user_id) FROM {$meta_table} WHERE user_id = %d", $user_id)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1442 1335
1443 - if (!empty($users)) {
1336 + if(!empty($users)) {
1444 1337 $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1445 1338 $meta_table,
1446 1339 $user_meta,
1447 1340 array('user_id' => $user_id)
1448 1341 );
1449 - } else {
1342 + } else {
1450 1343 $user_meta['user_id'] = $user_id;
1451 1344 $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
1452 1345 $meta_table,
1453 1346 $user_meta
@@ -1455,34 +1348,32 @@
1455 1348 }
1456 1349 }
1457 1350 }
1458 1351
1459 -function uwp_get_localize_data()
1460 -{
1461 - $pass_msg = uwp_get_option("register_uwp_strong_pass_msg");
1352 +function uwp_get_localize_data(){
1462 1353 $uwp_localize_data = array(
1463 1354 'uwp_more_char_limit' => 100,
1464 - 'uwp_more_text' => __('more', 'userswp'),
1465 - 'uwp_less_text' => __('less', 'userswp'),
1466 - 'error' => __('Something went wrong.', 'userswp'),
1467 - 'error_retry' => __('Something went wrong, please retry.', 'userswp'),
1355 + 'uwp_more_text' => __('more','userswp'),
1356 + 'uwp_less_text' => __('less','userswp'),
1357 + 'error' => __('Something went wrong.','userswp'),
1358 + 'error_retry' => __('Something went wrong, please retry.','userswp'),
1468 1359 'uwp_more_ellipses_text' => '...',
1469 1360 'ajaxurl' => admin_url('admin-ajax.php'),
1470 - 'login_modal' => uwp_get_option("design_style", 'bootstrap') == 'bootstrap' && uwp_get_option("login_modal", 1) ? 1 : '',
1471 - 'register_modal' => uwp_get_option("design_style", 'bootstrap') == 'bootstrap' && uwp_get_option("register_modal", 1) ? 1 : '',
1472 - 'forgot_modal' => uwp_get_option("design_style", 'bootstrap') == 'bootstrap' && uwp_get_option("forgot_modal", 1) ? 1 : '',
1473 - 'uwp_pass_strength' => uwp_get_option("register_min_password_strength", 0),
1474 - 'uwp_strong_pass_msg' => !empty($pass_msg) ? $pass_msg : __("Please enter valid strong password.", "userswp"),
1361 + 'login_modal' => uwp_get_option("design_style",'bootstrap')=='bootstrap' && uwp_get_option("login_modal",1) ? 1 : '',
1362 + 'register_modal' => uwp_get_option("design_style",'bootstrap')=='bootstrap' && uwp_get_option("register_modal",1) ? 1 : '',
1363 + 'forgot_modal' => uwp_get_option("design_style",'bootstrap')=='bootstrap' && uwp_get_option("forgot_modal",1) ? 1 : '',
1364 + 'uwp_pass_strength' => uwp_get_option("register_min_password_strength",0),
1365 + 'uwp_strong_pass_msg' => uwp_get_option("register_uwp_strong_pass_msg",__("Please enter valid strong password.", "userswp")),
1475 1366 'default_banner' => uwp_get_default_banner_uri(),
1476 - 'basicNonce' => esc_attr(wp_create_nonce('uwp_basic_nonce'))
1367 + 'basicNonce' => esc_attr( wp_create_nonce( 'uwp_basic_nonce' ) )
1477 1368 );
1478 1369
1479 1370 return apply_filters('uwp_localize_data', $uwp_localize_data);
1480 1371 }
1481 1372
1482 -function uwp_is_page_builder() {
1483 - if (
1484 - ( isset( $_GET['elementor-preview'] ) && $_GET['elementor-preview'] > 0 ) // elementor
1373 +function uwp_is_page_builder(){
1374 + if(
1375 + (isset($_GET['elementor-preview']) && $_GET['elementor-preview'] > 0) // elementor
1485 1376 || isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) // divi
1486 1377 || isset( $_REQUEST['fl_builder'] ) // beaver
1487 1378 || ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) // siteorigin
1488 1379 || ! empty( $_REQUEST['cornerstone_preview'] ) // cornerstone
@@ -1487,12 +1378,9 @@
1487 1378 || ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) // siteorigin
1488 1379 || ! empty( $_REQUEST['cornerstone_preview'] ) // cornerstone
1489 1380 || ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) // fusion builder
1490 1381 || ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) // oxygen
1491 - || ( function_exists( 'bricks_is_builder' ) && ( bricks_is_builder() || bricks_is_builder_call() ) ) // Bricks Builder
1492 - || ( \function_exists( 'Breakdance\\isRequestFromBuilderIframe' ) && ( \Breakdance\isRequestFromBuilderIframe() || \Breakdance\isRequestFromBuilderSsr() ) ) // Breakdance Builder
1493 - || ( function_exists( 'znhg_kallyas_theme_config' ) && ! empty( $_REQUEST['zn_pb_edit'] ) ) // Kallyas theme Zion builder
1494 - ) {
1382 + ){
1495 1383 return true; // builder.
1496 1384 }
1497 1385
1498 1386 return false;
@@ -1505,18 +1393,17 @@
1505 1393 * @param bool $allow_html Allow sanitized HTML if true or escape
1506 1394 *
1507 1395 * @return string
1508 1396 */
1509 -function uwp_help_tip($tip, $allow_html = false)
1510 -{
1511 - global $aui_bs5;
1512 - if ($allow_html) {
1513 - $tip = uwp_sanitize_tooltip($tip);
1397 +function uwp_help_tip( $tip, $allow_html = false ) {
1398 + global $aui_bs5;
1399 + if ( $allow_html ) {
1400 + $tip = uwp_sanitize_tooltip( $tip );
1514 1401 } else {
1515 - $tip = esc_attr($tip);
1402 + $tip = esc_attr( $tip );
1516 1403 }
1517 1404
1518 - $ml = $aui_bs5 ? 'ms-2 float-end' : 'ml-2 float-right';
1405 + $ml = $aui_bs5 ? 'ms-2 float-end' : 'ml-2 float-right';
1519 1406
1520 1407 return '<span class="uwp-help-tip dashicons dashicons-editor-help text-muted ' . $ml . '" title="' . $tip . '" data-bs-toggle="tooltip" data-bs-html="true"></span>';
1521 1408 }
1522 1409
@@ -1527,11 +1414,10 @@
1527 1414 *
1528 1415 * @param string $var
1529 1416 * @return string
1530 1417 */
1531 -function uwp_sanitize_tooltip($var)
1532 -{
1533 - return htmlspecialchars(wp_kses(html_entity_decode($var), array(
1418 +function uwp_sanitize_tooltip( $var ) {
1419 + return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1534 1420 'br' => array(),
1535 1421 'em' => array(),
1536 1422 'strong' => array(),
1537 1423 'small' => array(),
@@ -1539,40 +1425,38 @@
1539 1425 'ul' => array(),
1540 1426 'li' => array(),
1541 1427 'ol' => array(),
1542 1428 'p' => array(),
1543 - )));
1429 + ) ) );
1544 1430 }
1545 1431
1546 -function uwp_all_email_tags($inline = true, $extra_tags = array())
1547 -{
1548 - $tags = array('[#site_name#]', '[#site_name_url#]', '[#to_name#]', '[#from_name#]', '[#from_email#]', '[#user_name#]', '[#username#]', '[#user_email#]', '[#first_name#]', '[#last_name#]', '[#login_details#]', '[#date_time#]', '[#current_date#]', '[#login_url#]', '[#user_login#]', '[#profile_link#]');
1432 +function uwp_all_email_tags( $inline = true, $extra_tags = array() ){
1433 + $tags = array( '[#site_name#]', '[#site_name_url#]', '[#to_name#]', '[#from_name#]', '[#from_email#]', '[#user_name#]', '[#username#]', '[#user_email#]', '[#first_name#]', '[#last_name#]','[#login_details#]', '[#date_time#]', '[#current_date#]', '[#login_url#]', '[#user_login#]', '[#profile_link#]' );
1549 1434
1550 - if (is_array($extra_tags) && count($extra_tags) > 0) {
1435 + if(is_array($extra_tags) && count($extra_tags) > 0){
1551 1436 $tags = array_merge($extra_tags, $tags);
1552 1437 }
1553 1438
1554 - $tags = apply_filters('uwp_all_email_tags', $tags);
1439 + $tags = apply_filters( 'uwp_all_email_tags', $tags );
1555 1440
1556 - if ($inline) {
1557 - $tags = '<code>' . implode('</code> <code>', $tags) . '</code>';
1441 + if ( $inline ) {
1442 + $tags = '<code>' . implode( '</code> <code>', $tags ) . '</code>';
1558 1443 }
1559 1444
1560 1445 return $tags;
1561 1446 }
1562 1447
1563 -function uwp_wp_new_user_notification_tags($inline = true, $extra_tags = array())
1564 -{
1565 - $tags = array('[#site_name#]', '[#site_name_url#]', '[#to_name#]', '[#from_name#]', '[#from_email#]', '[#user_name#]', '[#username#]', '[#user_email#]', '[#date_time#]', '[#current_date#]', '[#login_url#]', '[#user_login#]',);
1448 +function uwp_wp_new_user_notification_tags( $inline = true, $extra_tags = array() ){
1449 + $tags = array( '[#site_name#]', '[#site_name_url#]', '[#to_name#]', '[#from_name#]', '[#from_email#]', '[#user_name#]', '[#username#]', '[#user_email#]', '[#date_time#]', '[#current_date#]', '[#login_url#]', '[#user_login#]', );
1566 1450
1567 - if (is_array($extra_tags) && count($extra_tags) > 0) {
1451 + if(is_array($extra_tags) && count($extra_tags) > 0){
1568 1452 $tags = array_merge($tags, $extra_tags);
1569 1453 }
1570 1454
1571 - $tags = apply_filters('uwp_wp_new_user_notification_email_tags', $tags);
1455 + $tags = apply_filters( 'uwp_wp_new_user_notification_email_tags', $tags );
1572 1456
1573 - if ($inline) {
1574 - $tags = '<code>' . implode('</code> <code>', $tags) . '</code>';
1457 + if ( $inline ) {
1458 + $tags = '<code>' . implode( '</code> <code>', $tags ) . '</code>';
1575 1459 }
1576 1460
1577 1461 return $tags;
1578 1462 }
@@ -1577,26 +1461,24 @@
1577 1461 return $tags;
1578 1462 }
1579 1463
1580 1464
1581 -function uwp_delete_account_email_tags($inline = true)
1582 -{
1583 - $tags = array('[#site_name#]', '[#site_name_url#]', '[#from_name#]', '[#from_email#]', '[#date_time#]', '[#current_date#]', '[#login_url#]', '[#user_login#]');
1465 +function uwp_delete_account_email_tags( $inline = true ){
1466 + $tags = array( '[#site_name#]', '[#site_name_url#]', '[#from_name#]', '[#from_email#]', '[#date_time#]', '[#current_date#]', '[#login_url#]', '[#user_login#]' );
1584 1467
1585 - $tags = apply_filters('uwp_delete_account_email_tags', $tags);
1468 + $tags = apply_filters( 'uwp_delete_account_email_tags', $tags );
1586 1469
1587 - if ($inline) {
1588 - $tags = '<code>' . implode('</code> <code>', $tags) . '</code>';
1470 + if ( $inline ) {
1471 + $tags = '<code>' . implode( '</code> <code>', $tags ) . '</code>';
1589 1472 }
1590 1473
1591 1474 return $tags;
1592 1475 }
1593 1476
1594 -function uwp_authbox_tags($inline = true)
1595 -{
1477 +function uwp_authbox_tags( $inline = true ){
1596 1478 global $wpdb;
1597 1479
1598 - $tags = array('[#post_id#]', '[#author_id#]', '[#author_display_name#]', '[#author_name#]', '[#author_link#]', '[#author_bio#]', '[#author_image#]', '[#author_image_url#]', '[#post_modified#]', '[#post_date#]', '[#author_nicename#]', '[#author_registered#]', '[#author_website#]');
1480 + $tags = array( '[#post_id#]', '[#author_id#]', '[#author_display_name#]', '[#author_name#]', '[#author_link#]', '[#author_bio#]', '[#author_image#]', '[#author_image_url#]', '[#post_modified#]', '[#post_date#]', '[#author_nicename#]', '[#author_registered#]', '[#author_website#]' );
1599 1481
1600 1482 $tags = apply_filters('uwp_author_box_default_tags', $tags, $inline);
1601 1483
1602 1484 $table_name = uwp_get_table_prefix() . 'uwp_usermeta';
@@ -1604,42 +1486,43 @@
1604 1486 $excluded = uwp_get_excluded_fields();
1605 1487
1606 1488 $columns = $wpdb->get_col("show columns from $table_name"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1607 1489
1608 - $extra_tags = array_diff($columns, $excluded);
1490 + $extra_tags = array_diff($columns,$excluded);
1609 1491
1610 - if (!empty($extra_tags) && '' != $extra_tags) {
1492 + if( !empty( $extra_tags ) && '' != $extra_tags ) {
1611 1493
1612 - foreach ($extra_tags as $tag_val) {
1613 - $tags[] = '[#' . $tag_val . '#]';
1494 + foreach ( $extra_tags as $tag_val ) {
1495 + $tags[] = '[#'.$tag_val.'#]';
1614 1496 }
1497 +
1615 1498 }
1616 1499
1617 - $tags = apply_filters('uwp_all_author_box_tags', $tags);
1500 + $tags = apply_filters( 'uwp_all_author_box_tags', $tags );
1618 1501
1619 - if ($inline) {
1620 - $tags = '<code>' . implode('</code> <code>', $tags) . '</code>';
1502 + if ( $inline ) {
1503 + $tags = '<code>' . implode( '</code> <code>', $tags ) . '</code>';
1621 1504 }
1622 1505
1623 1506 return $tags;
1624 1507 }
1625 1508
1626 -function uwp_get_posttypes()
1627 -{
1509 +function uwp_get_posttypes() {
1628 1510
1629 - $exclude_posts = array('attachment', 'revision', 'nav_menu_item', 'custom_css', 'uwp-post');
1511 + $exclude_posts = array('attachment','revision','nav_menu_item','custom_css','uwp-post');
1630 1512 $exclude_posttype = apply_filters('uwp_exclude_register_posttype', $exclude_posts);
1631 1513
1632 - $all_posttyps = get_post_types(array('public' => true,), 'objects');
1514 + $all_posttyps = get_post_types(array('public' => true,),'objects');
1633 1515
1634 1516 $display_posttypes = array();
1635 1517
1636 - if (!empty($all_posttyps) && '' != $all_posttyps) {
1637 - foreach ($all_posttyps as $pt_keys => $pt_values) {
1518 + if( !empty( $all_posttyps ) && '' != $all_posttyps ) {
1519 + foreach ( $all_posttyps as $pt_keys => $pt_values ) {
1638 1520
1639 - if (!in_array($pt_values->name, $exclude_posttype)) {
1521 + if( !in_array($pt_values->name,$exclude_posttype) ) {
1640 1522 $display_posttypes[$pt_values->name] = $pt_values->label;
1641 1523 }
1524 +
1642 1525 }
1643 1526 }
1644 1527
1645 1528 return $display_posttypes;
@@ -1644,10 +1527,9 @@
1644 1527
1645 1528 return $display_posttypes;
1646 1529 }
1647 1530
1648 -function uwp_get_user_by_author_slug()
1649 -{
1531 +function uwp_get_user_by_author_slug(){
1650 1532 $url_type = apply_filters('uwp_profile_url_type', 'slug');
1651 1533 $author_slug = get_query_var('uwp_profile');
1652 1534 if ($url_type == 'id') {
1653 1535 $user = get_user_by('id', $author_slug);
@@ -1657,10 +1539,9 @@
1657 1539
1658 1540 return $user;
1659 1541 }
1660 1542
1661 -function uwp_get_show_in_locations()
1662 -{
1543 +function uwp_get_show_in_locations(){
1663 1544 $show_in_locations = array(
1664 1545 "[users]" => __("Users Page", 'userswp'),
1665 1546 "[more_info]" => __("More info tab", 'userswp'),
1666 1547 "[profile_side]" => __("Profile side (non bootstrap)", 'userswp'),
@@ -1671,18 +1552,17 @@
1671 1552
1672 1553 return $show_in_locations;
1673 1554 }
1674 1555
1675 -function uwp_get_displayed_user()
1676 -{
1556 +function uwp_get_displayed_user(){
1677 1557 global $uwp_user;
1678 1558 $user = uwp_get_user_by_author_slug(); // for user displayed in profile
1679 1559
1680 - if (!$user && is_user_logged_in()) {
1560 + if(!$user && is_user_logged_in()){
1681 1561 $user = get_userdata(get_current_user_id()); // for user currently logged in
1682 1562 }
1683 1563
1684 - if (isset($uwp_user) && !empty($uwp_user) && $uwp_user instanceof WP_User) { // for user displaying in loop
1564 + if(isset($uwp_user) && !empty($uwp_user) && $uwp_user instanceof WP_User){ // for user displaying in loop
1685 1565 $user = $uwp_user;
1686 1566 }
1687 1567
1688 1568 return apply_filters('uwp_get_displayed_user', $user);
@@ -1687,12 +1567,11 @@
1687 1567
1688 1568 return apply_filters('uwp_get_displayed_user', $user);
1689 1569 }
1690 1570
1691 -function uwp_is_gdv2()
1692 -{
1571 +function uwp_is_gdv2(){
1693 1572
1694 - if (defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION, '2.0.0.0', '>=')) {
1573 + if(defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.0', '>=') ) {
1695 1574 return true;
1696 1575 }
1697 1576
1698 1577 return false;
@@ -1697,13 +1576,12 @@
1697 1576
1698 1577 return false;
1699 1578 }
1700 1579
1701 -function uwp_get_blogname()
1702 -{
1703 - $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1580 +function uwp_get_blogname() {
1581 + $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
1704 1582
1705 - return apply_filters('uwp_get_blogname', $blogname);
1583 + return apply_filters( 'uwp_get_blogname', $blogname );
1706 1584 }
1707 1585
1708 1586 /**
1709 1587 * RGB from hex.
@@ -1712,24 +1590,23 @@
1712 1590 *
1713 1591 * @param string $color Color.
1714 1592 * @return array $rgb.
1715 1593 */
1716 -function uwp_rgb_from_hex($color)
1717 -{
1718 - $color = str_replace('#', '', $color);
1594 +function uwp_rgb_from_hex( $color ) {
1595 + $color = str_replace( '#', '', $color );
1719 1596
1720 1597 // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
1721 - $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
1722 - if (empty($color)) {
1598 + $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
1599 + if ( empty( $color ) ) {
1723 1600 return NULL;
1724 1601 }
1725 1602
1726 - $color = str_split($color);
1603 + $color = str_split( $color );
1727 1604
1728 1605 $rgb = array();
1729 - $rgb['R'] = hexdec($color[0] . $color[1]);
1730 - $rgb['G'] = hexdec($color[2] . $color[3]);
1731 - $rgb['B'] = hexdec($color[4] . $color[5]);
1606 + $rgb['R'] = hexdec( $color[0].$color[1] );
1607 + $rgb['G'] = hexdec( $color[2].$color[3] );
1608 + $rgb['B'] = hexdec( $color[4].$color[5] );
1732 1609
1733 1610 return $rgb;
1734 1611 }
1735 1612
@@ -1741,23 +1618,22 @@
1741 1618 * @param string $color Color.
1742 1619 * @param int $factor Optional. Factor. Default 30.
1743 1620 * @return string $color.
1744 1621 */
1745 -function uwp_hex_darker($color, $factor = 30)
1746 -{
1747 - $base = uwp_rgb_from_hex($color);
1748 - if (empty($base)) {
1622 +function uwp_hex_darker( $color, $factor = 30 ) {
1623 + $base = uwp_rgb_from_hex( $color );
1624 + if ( empty( $base ) ) {
1749 1625 return $color;
1750 1626 }
1751 1627
1752 1628 $color = '#';
1753 - foreach ($base as $k => $v) {
1629 + foreach ( $base as $k => $v ) {
1754 1630 $amount = $v / 100;
1755 - $amount = round($amount * $factor);
1631 + $amount = round( $amount * $factor );
1756 1632 $new_decimal = $v - $amount;
1757 1633
1758 - $new_hex_component = dechex($new_decimal);
1759 - if (strlen($new_hex_component) < 2) {
1634 + $new_hex_component = dechex( $new_decimal );
1635 + if ( strlen( $new_hex_component ) < 2 ) {
1760 1636 $new_hex_component = "0" . $new_hex_component;
1761 1637 }
1762 1638 $color .= $new_hex_component;
1763 1639 }
@@ -1773,25 +1649,24 @@
1773 1649 * @param string $color Color.
1774 1650 * @param int $factor Optional. factor. Default 30.
1775 1651 * @return string $color.
1776 1652 */
1777 -function uwp_hex_lighter($color, $factor = 30)
1778 -{
1779 - $base = uwp_rgb_from_hex($color);
1780 - if (empty($base)) {
1653 +function uwp_hex_lighter( $color, $factor = 30 ) {
1654 + $base = uwp_rgb_from_hex( $color );
1655 + if ( empty( $base ) ) {
1781 1656 return $color;
1782 1657 }
1783 1658
1784 1659 $color = '#';
1785 1660
1786 - foreach ($base as $k => $v) {
1661 + foreach ( $base as $k => $v ) {
1787 1662 $amount = 255 - $v;
1788 1663 $amount = $amount / 100;
1789 - $amount = round($amount * $factor);
1664 + $amount = round( $amount * $factor );
1790 1665 $new_decimal = $v + $amount;
1791 1666
1792 - $new_hex_component = dechex($new_decimal);
1793 - if (strlen($new_hex_component) < 2) {
1667 + $new_hex_component = dechex( $new_decimal );
1668 + if ( strlen( $new_hex_component ) < 2 ) {
1794 1669 $new_hex_component = "0" . $new_hex_component;
1795 1670 }
1796 1671 $color .= $new_hex_component;
1797 1672 }
@@ -1808,20 +1683,19 @@
1808 1683 * @param string $dark Optional. Dark. Default #000000.
1809 1684 * @param string $light Optional. Light. Default #FFFFFF.
1810 1685 * @return string
1811 1686 */
1812 -function uwp_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF')
1813 -{
1814 - $hex = str_replace('#', '', $color);
1815 - if (empty($hex)) {
1687 +function uwp_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
1688 + $hex = str_replace( '#', '', $color );
1689 + if ( empty( $hex ) ) {
1816 1690 return $color;
1817 1691 }
1818 1692
1819 - $c_r = hexdec(substr($hex, 0, 2));
1820 - $c_g = hexdec(substr($hex, 2, 2));
1821 - $c_b = hexdec(substr($hex, 4, 2));
1693 + $c_r = hexdec( substr( $hex, 0, 2 ) );
1694 + $c_g = hexdec( substr( $hex, 2, 2 ) );
1695 + $c_b = hexdec( substr( $hex, 4, 2 ) );
1822 1696
1823 - $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
1697 + $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
1824 1698
1825 1699 return $brightness > 155 ? $dark : $light;
1826 1700 }
1827 1701
@@ -1832,16 +1706,15 @@
1832 1706 *
1833 1707 * @param string $hex hex.
1834 1708 * @return string
1835 1709 */
1836 -function uwp_format_hex($hex)
1837 -{
1838 - $hex = trim(str_replace('#', '', $hex));
1839 - if (empty($hex)) {
1710 +function uwp_format_hex( $hex ) {
1711 + $hex = trim( str_replace( '#', '', $hex ) );
1712 + if ( empty( $hex ) ) {
1840 1713 return NULL;
1841 1714 }
1842 1715
1843 - if (strlen($hex) == 3) {
1716 + if ( strlen( $hex ) == 3 ) {
1844 1717 $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
1845 1718 }
1846 1719
1847 1720 return $hex ? '#' . $hex : null;
@@ -1855,49 +1728,40 @@
1855 1728 * @param int $user_id User ID.
1856 1729 *
1857 1730 * @return string $activation_link
1858 1731 */
1859 -function uwp_get_activation_link($user_id)
1860 -{
1732 +function uwp_get_activation_link($user_id){
1861 1733
1862 1734 global $wpdb, $wp_hasher;
1863 1735
1864 - if (!$user_id) {
1736 + if(!$user_id){
1865 1737 return false;
1866 1738 }
1867 1739
1868 1740 $user_data = get_userdata($user_id);
1869 1741
1870 - $key = wp_generate_password(20, false);
1742 + $key = wp_generate_password( 20, false );
1871 1743
1872 - do_action('uwp_activation_key', $user_data->user_login, $key);
1744 + do_action( 'uwp_activation_key', $user_data->user_login, $key );
1873 1745
1874 - if ( function_exists( 'wp_fast_hash' ) ) {
1875 - $hashed = wp_fast_hash( $key );
1876 - } else {
1877 - if ( empty( $wp_hasher ) ) {
1878 - require_once ABSPATH . 'wp-includes/class-phpass.php';
1879 - $wp_hasher = new PasswordHash( 8, true );
1880 - }
1881 - $hashed = $wp_hasher->HashPassword( $key );
1746 + if ( empty( $wp_hasher ) ) {
1747 + require_once ABSPATH . 'wp-includes/class-phpass.php';
1748 + $wp_hasher = new PasswordHash( 8, true );
1882 1749 }
1883 - $wpdb->update($wpdb->users, array('user_activation_key' => time() . ":" . $hashed), array('user_login' => $user_data->user_login)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1884 - update_user_meta($user_id, 'uwp_mod', 'email_unconfirmed');
1750 + $hashed = $wp_hasher->HashPassword( $key );
1751 + $wpdb->update( $wpdb->users, array( 'user_activation_key' => time().":".$hashed ), array( 'user_login' => $user_data->user_login ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1752 + update_user_meta( $user_id, 'uwp_mod', 'email_unconfirmed' );
1885 1753
1886 - $activation_args = array(
1887 - 'uwp_activate' => 'yes',
1888 - 'key' => $key,
1889 - 'login' => rawurlencode($user_data->user_login)
1890 - );
1891 -
1892 - $activation_args = apply_filters('uwp_activation_link_args', $activation_args, $user_id, $user_data);
1893 -
1894 1754 $activation_link = add_query_arg(
1895 - $activation_args,
1755 + array(
1756 + 'uwp_activate' => 'yes',
1757 + 'key' => $key,
1758 + 'login' => $user_data->user_login
1759 + ),
1896 1760 home_url('/login/')
1897 1761 );
1898 1762
1899 - return apply_filters('uwp_activation_link', $activation_link, $user_id, $user_data, $activation_args);
1763 + return $activation_link;
1900 1764 }
1901 1765
1902 1766 /**
1903 1767 * Checks a version number against the core version and adds a admin notice if requirements are not met.
@@ -1906,18 +1770,17 @@
1906 1770 * @param $version
1907 1771 *
1908 1772 * @return bool
1909 1773 */
1910 -function uwp_min_version_check($name, $version)
1911 -{
1912 - if (version_compare(USERSWP_VERSION, $version, '<')) {
1913 - add_action('admin_notices', function () use (&$name) {
1914 - ?>
1915 - <div class="notice notice-error is-dismissible">
1916 - <p><?php echo esc_html(wp_sprintf(__("%s requires a newer version of UsersWP and will not run until the UsersWP plugin is updated.", "userswp"), $name)); ?></p>
1917 - </div>
1918 -<?php
1919 - });
1774 +function uwp_min_version_check( $name, $version ) {
1775 + if ( version_compare( USERSWP_VERSION, $version, '<' ) ) {
1776 + add_action( 'admin_notices', function () use ( &$name ) {
1777 + ?>
1778 + <div class="notice notice-error is-dismissible">
1779 + <p><?php echo esc_html( wp_sprintf( __( "%s requires a newer version of UsersWP and will not run until the UsersWP plugin is updated.", "userswp" ), $name ) ); ?></p>
1780 + </div>
1781 + <?php
1782 + } );
1920 1783
1921 1784 return false;
1922 1785 }
1923 1786
@@ -1923,22 +1786,22 @@
1923 1786
1924 1787 return true;
1925 1788 }
1926 1789
1927 -function uwp_get_user_roles($exclude = array())
1928 -{
1790 +function uwp_get_user_roles($exclude = array()) {
1929 1791 $user_roles = array();
1930 - if (!function_exists('get_editable_roles')) {
1931 - require_once(ABSPATH . '/wp-admin/includes/user.php');
1792 + if ( !function_exists('get_editable_roles') ) {
1793 + require_once( ABSPATH . '/wp-admin/includes/user.php' );
1932 1794 }
1933 1795
1934 1796 $wp_roles = get_editable_roles();
1935 - if (!empty($wp_roles) && is_array($wp_roles)) {
1936 - foreach ($wp_roles as $role => $details) {
1937 - if (in_array($role, $exclude)) {
1797 + if(!empty($wp_roles) && is_array($wp_roles)) {
1798 + foreach ( $wp_roles as $role => $details ) {
1799 + if ( in_array( $role, $exclude ) ) {
1938 1800 } else {
1939 - $user_roles[esc_attr($role)] = !empty($details['name']) ? translate_user_role($details['name']) : $role;
1801 + $user_roles[ esc_attr( $role ) ] = !empty($details['name']) ? translate_user_role( $details['name'] ): $role;
1940 1802 }
1803 +
1941 1804 }
1942 1805 }
1943 1806
1944 1807 return $user_roles;
@@ -1943,13 +1806,12 @@
1943 1806
1944 1807 return $user_roles;
1945 1808 }
1946 1809
1947 -function uwp_get_sort_by_order_list()
1948 -{
1810 +function uwp_get_sort_by_order_list(){
1949 1811
1950 1812 $cache = wp_cache_get("uwp_get_sort_options");
1951 - if ($cache !== false) {
1813 + if($cache !== false){
1952 1814 return $cache;
1953 1815 }
1954 1816
1955 1817 global $wpdb;
@@ -1954,32 +1816,29 @@
1954 1816
1955 1817 global $wpdb;
1956 1818 $table_name = uwp_get_table_prefix() . 'uwp_user_sorting';
1957 1819
1958 - $sort_options_raw = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE is_active = %d AND field_type != 'address' AND tab_parent = '0' ORDER BY sort_order ASC", array(1))); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
1820 + $sort_options_raw = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $table_name . " WHERE is_active = %d AND field_type != 'address' AND tab_parent = '0' ORDER BY sort_order ASC", array( 1 ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
1959 1821
1960 1822 $sort_options = array();
1961 1823
1962 - if (! empty($sort_options_raw) && count($sort_options_raw) > 1) {
1963 - foreach ($sort_options_raw as $sort) {
1964 - $sort = stripslashes_deep($sort);
1824 + if ( ! empty( $sort_options_raw ) && count( $sort_options_raw ) > 1 ) {
1825 + foreach ( $sort_options_raw as $sort ) {
1826 + $sort = stripslashes_deep( $sort );
1965 1827
1966 - $sort->site_title = __(wp_unslash($sort->site_title), 'userswp');
1828 + $sort->site_title = __( wp_unslash( $sort->site_title ), 'userswp' );
1967 1829
1968 - if ($sort->htmlvar_name == 'comment_count') {
1830 + if ( $sort->htmlvar_name == 'comment_count' ) {
1969 1831 $sort->htmlvar_name = 'rating_count';
1970 1832 }
1971 1833
1972 1834 $key = $sort->htmlvar_name;
1973 - if (!in_array($key, array('newer', 'older'))) {
1974 - if ($sort->sort == 'asc') {
1975 - $key = esc_attr($sort->htmlvar_name . "_asc");
1976 - } elseif ($sort->sort == 'desc') {
1977 - $key = esc_attr($sort->htmlvar_name . "_desc");
1978 - }
1835 + if ( !in_array($key, array('newer', 'older')) ) {
1836 + if($sort->sort == 'asc'){$key = esc_attr($sort->htmlvar_name."_asc");}
1837 + elseif($sort->sort == 'desc'){$key = esc_attr($sort->htmlvar_name."_desc");}
1979 1838 }
1980 1839
1981 - $sort_options[$key] = wp_unslash($sort->site_title);
1840 + $sort_options[$key] = wp_unslash( $sort->site_title );
1982 1841 }
1983 1842 }
1984 1843
1985 1844 /**
@@ -1986,139 +1845,54 @@
1986 1845 * Filter post sort options.
1987 1846 *
1988 1847 * @param array $sort_options Unfiltered sort field array.
1989 1848 */
1990 - $sort_options = apply_filters('uwp_available_users_layout', $sort_options);
1849 + $sort_options = apply_filters( 'uwp_available_users_layout', $sort_options );
1991 1850
1992 - wp_cache_set("uwp_get_sort_options", $sort_options);
1851 + wp_cache_set("uwp_get_sort_options", $sort_options );
1993 1852
1994 1853 return $sort_options;
1995 1854 }
1996 1855
1997 -function uwp_get_default_sort()
1998 -{
1856 +function uwp_get_default_sort(){
1999 1857
2000 1858 $cache = wp_cache_get("uwp_get_default_sort");
2001 1859
2002 - if ($cache !== false) {
1860 + if($cache !== false){
2003 1861 return $cache;
2004 1862 }
2005 1863
2006 1864 $default_sort = 'newer_asc';
2007 1865
2008 - global $wpdb;
1866 + global $wpdb;
2009 1867 $table_name = uwp_get_table_prefix() . 'uwp_user_sorting';
2010 1868
2011 - $field = $wpdb->get_row("SELECT htmlvar_name, sort, field_type FROM " . $table_name . " WHERE is_active = 1 AND is_default = 1 ORDER BY sort_order ASC"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
2012 - if (! empty($field)) {
2013 - if ($field->field_type == 'random') {
1869 + $field = $wpdb->get_row("SELECT htmlvar_name, sort, field_type FROM " . $table_name . " WHERE is_active = 1 AND is_default = 1 ORDER BY sort_order ASC" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
1870 + if ( ! empty( $field ) ) {
1871 + if ( $field->field_type == 'random' ) {
2014 1872 $default_sort = 'random';
2015 - } elseif ('newer' == $field->htmlvar_name) {
2016 - $default_sort = 'user_registered_desc';
2017 - } elseif ('older' == $field->htmlvar_name) {
1873 + } elseif ( 'newer' == $field->htmlvar_name) {
1874 + $default_sort = 'user_registered_desc';
1875 + } elseif ( 'older' == $field->htmlvar_name ) {
2018 1876 $default_sort = 'user_registered_asc';
2019 - } else {
1877 + }else {
2020 1878 $default_sort = $field->htmlvar_name . '_' . $field->sort;
2021 1879 }
2022 1880 }
2023 1881
2024 - wp_cache_set("uwp_get_default_sort", $default_sort);
1882 + wp_cache_set("uwp_get_default_sort", $default_sort );
2025 1883
2026 1884 return $default_sort;
1885 +
2027 1886 }
2028 1887
2029 -function uwp_get_username($user_id)
2030 -{
2031 - $user_data = get_userdata($user_id);
1888 +function uwp_get_username( $user_id ) {
1889 + $user_data = get_userdata( $user_id );
2032 1890
2033 - if (! $user_data) {
1891 + if ( ! $user_data ) {
2034 1892 return '';
2035 1893 }
2036 1894
2037 - $display_name = ! empty($user_data->display_name) ? $user_data->display_name : $user_data->user_login;
1895 + $display_name = ! empty( $user_data->display_name ) ? $user_data->display_name : $user_data->user_login;
2038 1896
2039 - return apply_filters('uwp_get_username', $display_name, $user_id, $user_data);
2040 -}
2041 -
2042 -/**
2043 - * File relative url.
2044 - *
2045 - * @since 1.2.66
2046 - *
2047 - * @param string $url URL.
2048 - * @param bool $full_path Optional. Full Path. Default false.
2049 - * @return string
2050 - */
2051 -function uwp_get_file_relative_url( $url, $full_path = false ) {
2052 - $url = trim( $url );
2053 -
2054 - if ( !$url ) {
2055 - return $url;
2056 - }
2057 -
2058 - $relative_url = $url;
2059 - $url = trim( $url, '/\\' ); // clean slashes
2060 -
2061 - $upload_dir = wp_upload_dir();
2062 - $upload_basedir = $upload_dir['basedir'];
2063 - $upload_baseurl = $upload_dir['baseurl'];
2064 - $content_dir = untrailingslashit( WP_CONTENT_DIR );
2065 - $content_url = untrailingslashit( WP_CONTENT_URL );
2066 -
2067 - if ( strpos( $upload_baseurl, 'https://' ) === 0 ) {
2068 - $https = 'https://';
2069 - $match_upload_baseurl = str_replace( 'https://', '', $upload_baseurl );
2070 - $content_url = str_replace( 'http://', 'https://', $content_url );
2071 - } else {
2072 - $https = 'http://';
2073 - $match_upload_baseurl = str_replace( 'http://', '', $upload_baseurl );
2074 - $content_url = str_replace( 'https://', 'http://', $content_url );
2075 - }
2076 -
2077 - $match_content_url = strpos( $content_url, 'https://' ) === 0 ? str_replace( 'https://', '', $content_url ) : str_replace( 'http://', '', $content_url );
2078 - $match_url = strpos( $url, 'https://' ) === 0 ? str_replace( 'https://', '', $url ) : str_replace( 'http://', '', $url );
2079 -
2080 - // www.
2081 - $www = '';
2082 - if ( strpos( $match_upload_baseurl, 'www.' ) === 0 ) {
2083 - $www = 'www.';
2084 - $match_upload_baseurl = str_replace( 'www.', '', $match_upload_baseurl );
2085 - }
2086 - if ( strpos( $match_content_url, 'www.' ) === 0 ) {
2087 - $match_content_url = str_replace( 'www.', '', $match_content_url );
2088 - }
2089 - if ( strpos( $match_url, 'www.' ) === 0 ) {
2090 - $match_url = str_replace( 'www.', '', $match_url );
2091 - }
2092 -
2093 - if ( $full_path ) {
2094 - if ( strpos( $relative_url, 'http://' ) === 0 || strpos( $relative_url, 'https://' ) === 0 ) {
2095 - if ( strpos( $match_url, $match_upload_baseurl ) === 0 || strpos( $match_url, $match_content_url ) === 0 ) {
2096 - $relative_url = $https . $www . $match_url;
2097 - }
2098 - } else {
2099 - if ( is_file( $content_dir . '/' . $match_url ) && file_exists( $content_dir . '/' . $match_url ) ) { // url contains content url
2100 - $relative_url = $content_url . '/' . $match_url;
2101 - } elseif ( is_file( $upload_basedir . '/' . $match_url ) && file_exists( $upload_basedir . '/' . $match_url ) ) { // url contains content url
2102 - $relative_url = $upload_baseurl . '/' . $match_url;
2103 - }
2104 - }
2105 - } else {
2106 - if ( substr_count( $match_url, $match_upload_baseurl ) > 1 || substr_count( $match_url, $match_content_url ) > 1 ) {
2107 - return '';
2108 - }
2109 -
2110 - if ( strpos( $match_url, $match_upload_baseurl ) === 0 ) { // url contains uploads baseurl
2111 - $relative_url = substr( $match_url, strlen( $match_upload_baseurl ) );
2112 - } elseif ( strpos( $match_url, $match_content_url ) === 0 ) { // url contains content url
2113 - $relative_url = substr( $match_url, strlen( $match_content_url ) );
2114 - }
2115 -
2116 - $relative_url = trim( $relative_url, '/\\' );
2117 -
2118 - if ( false !== strpos( $relative_url, '..' ) ) {
2119 - return '';
2120 - }
2121 - }
2122 -
2123 - return apply_filters( 'uwp_get_file_relative_url', $relative_url, $url, $full_path );
2124 -}
1897 + return apply_filters( 'uwp_get_username', $display_name, $user_id, $user_data );
1898 +}