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