| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | 4 | * Converts string value to options array. |
| 4 | 5 | * Used in select, multiselect and radio fields. |
| 5 | 6 | * Wraps inside optgroup if available. |
| @@ -13,55 +14,55 @@ | ||
| 13 | 14 | * @return array|null Options array. |
| 14 | 15 | */ |
| 15 | 16 | function uwp_string_values_to_options($option_values = '', $translated = false) |
| 16 | 17 | { |
| 17 | - $options = array(); | |
| 18 | - if ($option_values == '') { | |
| 19 | - return NULL; | |
| 20 | - } | |
| 18 | + $options = array(); | |
| 19 | + if ($option_values == '') { | |
| 20 | + return NULL; | |
| 21 | + } | |
| 21 | 22 | |
| 22 | - if (strpos($option_values, "{/optgroup}") !== false) { | |
| 23 | - $option_values_arr = explode("{/optgroup}", $option_values); | |
| 23 | + if (strpos($option_values, "{/optgroup}") !== false) { | |
| 24 | + $option_values_arr = explode("{/optgroup}", $option_values); | |
| 24 | 25 | |
| 25 | - foreach ($option_values_arr as $optgroup) { | |
| 26 | - if (strpos($optgroup, "{optgroup}") !== false) { | |
| 27 | - $optgroup_arr = explode("{optgroup}", $optgroup); | |
| 26 | + foreach ($option_values_arr as $optgroup) { | |
| 27 | + if (strpos($optgroup, "{optgroup}") !== false) { | |
| 28 | + $optgroup_arr = explode("{optgroup}", $optgroup); | |
| 28 | 29 | |
| 29 | - $count = 0; | |
| 30 | - foreach ($optgroup_arr as $optgroup_str) { | |
| 31 | - $count++; | |
| 32 | - $optgroup_str = trim($optgroup_str); | |
| 30 | + $count = 0; | |
| 31 | + foreach ($optgroup_arr as $optgroup_str) { | |
| 32 | + $count++; | |
| 33 | + $optgroup_str = trim($optgroup_str); | |
| 33 | 34 | |
| 34 | - $optgroup_label = ''; | |
| 35 | - if (strpos($optgroup_str, "|") !== false) { | |
| 36 | - $optgroup_str_arr = explode("|", $optgroup_str, 2); | |
| 37 | - $optgroup_label = trim($optgroup_str_arr[0]); | |
| 38 | - if ($translated && $optgroup_label != '') { | |
| 39 | - $optgroup_label = __($optgroup_label, 'userswp'); | |
| 40 | - } | |
| 41 | - $optgroup_label = ucfirst($optgroup_label); | |
| 42 | - $optgroup_str = $optgroup_str_arr[1]; | |
| 43 | - } | |
| 35 | + $optgroup_label = ''; | |
| 36 | + if (strpos($optgroup_str, "|") !== false) { | |
| 37 | + $optgroup_str_arr = explode("|", $optgroup_str, 2); | |
| 38 | + $optgroup_label = trim($optgroup_str_arr[0]); | |
| 39 | + if ($translated && $optgroup_label != '') { | |
| 40 | + $optgroup_label = __($optgroup_label, 'userswp'); | |
| 41 | + } | |
| 42 | + $optgroup_label = ucfirst($optgroup_label); | |
| 43 | + $optgroup_str = $optgroup_str_arr[1]; | |
| 44 | + } | |
| 44 | 45 | |
| 45 | - $optgroup3 = uwp_string_to_options($optgroup_str, $translated); | |
| 46 | + $optgroup3 = uwp_string_to_options($optgroup_str, $translated); | |
| 46 | 47 | |
| 47 | - if ($count > 1 && $optgroup_label != '' && !empty($optgroup3)) { | |
| 48 | - $optgroup_start = array(array('label' => $optgroup_label, 'value' => NULL, 'optgroup' => 'start')); | |
| 49 | - $optgroup_end = array(array('label' => $optgroup_label, 'value' => NULL, 'optgroup' => 'end')); | |
| 50 | - $optgroup3 = array_merge($optgroup_start, $optgroup3, $optgroup_end); | |
| 51 | - } | |
| 52 | - $options = array_merge($options, $optgroup3); | |
| 53 | - } | |
| 54 | - } else { | |
| 55 | - $optgroup1 = uwp_string_to_options($optgroup, $translated); | |
| 56 | - $options = array_merge($options, $optgroup1); | |
| 57 | - } | |
| 58 | - } | |
| 59 | - } else { | |
| 60 | - $options = uwp_string_to_options($option_values, $translated); | |
| 61 | - } | |
| 48 | + if ($count > 1 && $optgroup_label != '' && !empty($optgroup3)) { | |
| 49 | + $optgroup_start = array(array('label' => $optgroup_label, 'value' => NULL, 'optgroup' => 'start')); | |
| 50 | + $optgroup_end = array(array('label' => $optgroup_label, 'value' => NULL, 'optgroup' => 'end')); | |
| 51 | + $optgroup3 = array_merge($optgroup_start, $optgroup3, $optgroup_end); | |
| 52 | + } | |
| 53 | + $options = array_merge($options, $optgroup3); | |
| 54 | + } | |
| 55 | + } else { | |
| 56 | + $optgroup1 = uwp_string_to_options($optgroup, $translated); | |
| 57 | + $options = array_merge($options, $optgroup1); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + } else { | |
| 61 | + $options = uwp_string_to_options($option_values, $translated); | |
| 62 | + } | |
| 62 | 63 | |
| 63 | - return $options; | |
| 64 | + return $options; | |
| 64 | 65 | } |
| 65 | 66 | |
| 66 | 67 | /** |
| 67 | 68 | * Converts string value to options array. |
| @@ -76,105 +77,48 @@ | ||
| 76 | 77 | * @return array Options array. |
| 77 | 78 | */ |
| 78 | 79 | function uwp_string_to_options($input = '', $translated = false) |
| 79 | 80 | { |
| 80 | - $return = array(); | |
| 81 | - if ($input != '') { | |
| 82 | - $input = trim($input); | |
| 83 | - $input = rtrim($input, ","); | |
| 84 | - $input = ltrim($input, ","); | |
| 85 | - $input = trim($input); | |
| 86 | - } | |
| 81 | + $return = array(); | |
| 82 | + if ($input != '') { | |
| 83 | + $input = trim($input); | |
| 84 | + $input = rtrim($input, ","); | |
| 85 | + $input = ltrim($input, ","); | |
| 86 | + $input = trim($input); | |
| 87 | + } | |
| 87 | 88 | |
| 88 | - $input_arr = explode(',', $input); | |
| 89 | + $input_arr = explode(',', $input); | |
| 89 | 90 | |
| 90 | - if (!empty($input_arr)) { | |
| 91 | - foreach ($input_arr as $input_str) { | |
| 92 | - $input_str = trim($input_str); | |
| 91 | + if (!empty($input_arr)) { | |
| 92 | + foreach ($input_arr as $input_str) { | |
| 93 | + $input_str = trim(stripslashes($input_str)); | |
| 93 | 94 | |
| 94 | - if (strpos($input_str, "/") !== false) { | |
| 95 | - $input_str = explode("/", $input_str, 2); | |
| 96 | - $label = trim($input_str[0]); | |
| 97 | - if ($translated && $label != '') { | |
| 98 | - $label = __($label, 'userswp'); | |
| 99 | - } | |
| 100 | - $label = ucfirst($label); | |
| 101 | - $value = trim($input_str[1]); | |
| 102 | - } else { | |
| 103 | - if ($translated && $input_str != '') { | |
| 104 | - $input_str = __($input_str, 'userswp'); | |
| 105 | - } | |
| 106 | - $label = ucfirst($input_str); | |
| 107 | - $value = $input_str; | |
| 108 | - } | |
| 95 | + if (strpos($input_str, "/") !== false) { | |
| 96 | + $input_str = explode("/", $input_str, 2); | |
| 97 | + $label = trim($input_str[0]); | |
| 98 | + if ($translated && $label != '') { | |
| 99 | + $label = __($label, 'userswp'); | |
| 100 | + } | |
| 101 | + $label = ucfirst($label); | |
| 102 | + $value = trim($input_str[1]); | |
| 103 | + } else { | |
| 104 | + if ($translated && $input_str != '') { | |
| 105 | + $input_str = __($input_str, 'userswp'); | |
| 106 | + } | |
| 107 | + $label = ucfirst($input_str); | |
| 108 | + $value = $input_str; | |
| 109 | + } | |
| 109 | 110 | |
| 110 | - if ($label != '') { | |
| 111 | - $return[] = array('label' => $label, 'value' => $value, 'optgroup' => NULL); | |
| 112 | - } | |
| 113 | - } | |
| 114 | - } | |
| 111 | + if ($label != '') { | |
| 112 | + $return[] = array('label' => $label, 'value' => $value, 'optgroup' => NULL); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + } | |
| 115 | 116 | |
| 116 | - return $return; | |
| 117 | + return $return; | |
| 117 | 118 | } |
| 118 | 119 | |
| 119 | - | |
| 120 | 120 | /** |
| 121 | - * Resizes the image. | |
| 122 | - * | |
| 123 | - * @since 1.0.0 | |
| 124 | - * @package userswp | |
| 125 | - * | |
| 126 | - * @param string $image Reference a local file | |
| 127 | - * @param int $width Image width | |
| 128 | - * @param int $height Image height | |
| 129 | - * @param float $scale Image scale ratio. | |
| 130 | - * | |
| 131 | - * @return mixed Resized image. | |
| 132 | - */ | |
| 133 | -function uwp_resizeImage($image,$width,$height,$scale) { | |
| 134 | - /** @noinspection PhpUnusedLocalVariableInspection */ | |
| 135 | - list($imagewidth, $imageheight, $imageType) = getimagesize($image); | |
| 136 | - $imageType = image_type_to_mime_type($imageType); | |
| 137 | - $newImageWidth = ceil($width * $scale); | |
| 138 | - $newImageHeight = ceil($height * $scale); | |
| 139 | - $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight); | |
| 140 | - $source = false; | |
| 141 | - switch($imageType) { | |
| 142 | - case "image/gif": | |
| 143 | - $source=imagecreatefromgif($image); | |
| 144 | - break; | |
| 145 | - case "image/pjpeg": | |
| 146 | - case "image/jpeg": | |
| 147 | - case "image/jpg": | |
| 148 | - $source=imagecreatefromjpeg($image); | |
| 149 | - break; | |
| 150 | - case "image/png": | |
| 151 | - case "image/x-png": | |
| 152 | - $source=imagecreatefrompng($image); | |
| 153 | - break; | |
| 154 | - } | |
| 155 | - imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height); | |
| 156 | - | |
| 157 | - switch($imageType) { | |
| 158 | - case "image/gif": | |
| 159 | - imagegif($newImage,$image); | |
| 160 | - break; | |
| 161 | - case "image/pjpeg": | |
| 162 | - case "image/jpeg": | |
| 163 | - case "image/jpg": | |
| 164 | - imagejpeg($newImage,$image,90); | |
| 165 | - break; | |
| 166 | - case "image/png": | |
| 167 | - case "image/x-png": | |
| 168 | - imagepng($newImage,$image); | |
| 169 | - break; | |
| 170 | - } | |
| 171 | - | |
| 172 | - chmod($image, 0777); | |
| 173 | - return $image; | |
| 174 | -} | |
| 175 | - | |
| 176 | -/** | |
| 177 | 121 | * Resizes thumbnail image. |
| 178 | 122 | * |
| 179 | 123 | * @since 1.0.0 |
| 180 | 124 | * @package userswp |
| @@ -188,54 +132,131 @@ | ||
| 188 | 132 | * @param float $scale Image scale ratio. |
| 189 | 133 | * |
| 190 | 134 | * @return mixed Resized image. |
| 191 | 135 | */ |
| 192 | -function uwp_resizeThumbnailImage($thumb_image_name, $image, $x, $y, $src_w, $src_h, $scale){ | |
| 193 | - // ignore image createion warnings | |
| 194 | - @ini_set('gd.jpeg_ignore_warning', 1); | |
| 195 | - /** @noinspection PhpUnusedLocalVariableInspection */ | |
| 196 | - list($imagewidth, $imageheight, $imageType) = getimagesize($image); | |
| 197 | - $imageType = image_type_to_mime_type($imageType); | |
| 136 | +function uwp_resizeThumbnailImage($thumb_image_name, $image, $x, $y, $src_w, $src_h, $scale, $wp_error = false) | |
| 137 | +{ | |
| 138 | + uwp_set_php_limits(); | |
| 198 | 139 | |
| 199 | - $newImageWidth = ceil($src_w * $scale); | |
| 200 | - $newImageHeight = ceil($src_h * $scale); | |
| 201 | - $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight); | |
| 202 | - $source = false; | |
| 203 | - switch($imageType) { | |
| 204 | - case "image/gif": | |
| 205 | - $source=imagecreatefromgif($image); | |
| 206 | - break; | |
| 207 | - case "image/pjpeg": | |
| 208 | - case "image/jpeg": | |
| 209 | - case "image/jpg": | |
| 210 | - $source=imagecreatefromjpeg($image); | |
| 211 | - break; | |
| 212 | - case "image/png": | |
| 213 | - case "image/x-png": | |
| 214 | - $source=imagecreatefrompng($image); | |
| 215 | - break; | |
| 216 | - } | |
| 217 | - imagecopyresampled($newImage,$source,0,0,$x,$y,$newImageWidth, $newImageHeight, $src_w, $src_h); | |
| 218 | - switch($imageType) { | |
| 219 | - case "image/gif": | |
| 220 | - imagegif($newImage, $thumb_image_name); | |
| 221 | - break; | |
| 222 | - case "image/pjpeg": | |
| 223 | - case "image/jpeg": | |
| 224 | - case "image/jpg": | |
| 225 | - imagejpeg($newImage, $thumb_image_name, 100); | |
| 226 | - break; | |
| 227 | - case "image/png": | |
| 228 | - case "image/x-png": | |
| 229 | - imagepng($newImage, $thumb_image_name); | |
| 230 | - break; | |
| 231 | - } | |
| 140 | + // Ignore image creation warnings | |
| 141 | + @ini_set('gd.jpeg_ignore_warning', 1); | |
| 232 | 142 | |
| 233 | - chmod($thumb_image_name, 0777); | |
| 234 | - return $thumb_image_name; | |
| 143 | + $newImageWidth = ceil($src_w * $scale); | |
| 144 | + $newImageHeight = ceil($src_h * $scale); | |
| 145 | + | |
| 146 | + /** @noinspection PhpUnusedLocalVariableInspection */ | |
| 147 | + list($imagewidth, $imageheight, $imageType) = getimagesize($image); | |
| 148 | + $imageType = image_type_to_mime_type($imageType); | |
| 149 | + | |
| 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); | |
| 153 | + | |
| 154 | + if ($wp_crop) { | |
| 155 | + $cropped = wp_crop_image($image, $x, $y, $src_w, $src_h, $newImageWidth, $newImageHeight, false, $thumb_image_name); | |
| 156 | + | |
| 157 | + if ($wp_error && is_wp_error($cropped)) { | |
| 158 | + return $cropped; | |
| 159 | + } | |
| 160 | + | |
| 161 | + return $thumb_image_name; | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 165 | + $newImage = imagecreatetruecolor($newImageWidth, $newImageHeight); | |
| 166 | + $source = false; | |
| 167 | + | |
| 168 | + switch ($imageType) { | |
| 169 | + case "image/gif": | |
| 170 | + $source = imagecreatefromgif($image); | |
| 171 | + break; | |
| 172 | + case "image/pjpeg": | |
| 173 | + case "image/jpeg": | |
| 174 | + case "image/jpg": | |
| 175 | + $source = imagecreatefromjpeg($image); | |
| 176 | + break; | |
| 177 | + case "image/png": | |
| 178 | + 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); | |
| 182 | + | |
| 183 | + imagecolortransparent($newImage, $background); | |
| 184 | + imagealphablending($newImage, false); | |
| 185 | + imagesavealpha($newImage, true); | |
| 186 | + } | |
| 187 | + 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 | + } | |
| 196 | + | |
| 197 | + imagecopyresampled($newImage, $source, 0, 0, $x, $y, $newImageWidth, $newImageHeight, $src_w, $src_h); | |
| 198 | + | |
| 199 | + $quality = apply_filters('uwp_resize_thumb_quality', 100); | |
| 200 | + | |
| 201 | + switch ($imageType) { | |
| 202 | + case "image/gif": | |
| 203 | + imagegif($newImage, $thumb_image_name); | |
| 204 | + break; | |
| 205 | + case "image/pjpeg": | |
| 206 | + case "image/jpeg": | |
| 207 | + case "image/jpg": | |
| 208 | + imagejpeg($newImage, $thumb_image_name, $quality); | |
| 209 | + break; | |
| 210 | + case "image/png": | |
| 211 | + case "image/x-png": | |
| 212 | + imagepng($newImage, $thumb_image_name); | |
| 213 | + 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 | + } | |
| 222 | + | |
| 223 | + chmod($thumb_image_name, 0777); | |
| 224 | + imagedestroy($newImage); | |
| 225 | + imagedestroy($source); | |
| 226 | + | |
| 227 | + return $thumb_image_name; | |
| 235 | 228 | } |
| 236 | 229 | |
| 230 | +/** | |
| 231 | + * Try to set higher limits on the fly | |
| 232 | + */ | |
| 233 | +function uwp_set_php_limits() | |
| 234 | +{ | |
| 235 | + error_reporting(0); | |
| 237 | 236 | |
| 237 | + // 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'); | |
| 241 | + | |
| 242 | + if ($max_input_time !== 0 && $max_input_time != -1 && (! $max_input_time || $max_input_time < 3000)) { | |
| 243 | + ini_set('max_input_time', 3000); | |
| 244 | + } | |
| 245 | + | |
| 246 | + if ($max_execution_time !== 0 && (! $max_execution_time || $max_execution_time < 3000)) { | |
| 247 | + ini_set('max_execution_time', 3000); | |
| 248 | + } | |
| 249 | + | |
| 250 | + if ($memory_limit && str_replace('M', '', $memory_limit)) { | |
| 251 | + if (str_replace('M', '', $memory_limit) < 256) { | |
| 252 | + ini_set('memory_limit', '256M'); | |
| 253 | + } | |
| 254 | + } | |
| 255 | + | |
| 256 | + ini_set('auto_detect_line_endings', true); | |
| 257 | +} | |
| 258 | + | |
| 238 | 259 | /** |
| 239 | 260 | * Logs the error message. |
| 240 | 261 | * |
| 241 | 262 | * @since 1.0.0 |
| @@ -244,318 +265,383 @@ | ||
| 244 | 265 | * @param array|object|string $log Error message. |
| 245 | 266 | * |
| 246 | 267 | * @return void |
| 247 | 268 | */ |
| 248 | -function uwp_error_log($log){ | |
| 249 | - /* | |
| 250 | - * A filter to override the WP_DEBUG setting for function uwp_error_log(). | |
| 251 | - */ | |
| 252 | - $should_log = apply_filters( 'uwp_log_errors', WP_DEBUG); | |
| 253 | - if ( true === $should_log ) { | |
| 254 | - if ( is_array( $log ) || is_object( $log ) ) { | |
| 255 | - error_log( print_r( $log, true ) ); | |
| 256 | - } else { | |
| 257 | - error_log( $log ); | |
| 258 | - } | |
| 259 | - } | |
| 269 | +function uwp_error_log($log) | |
| 270 | +{ | |
| 271 | + /* | |
| 272 | + * A filter to override the debugging setting for function uwp_error_log(). | |
| 273 | + */ | |
| 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)); | |
| 278 | + } else { | |
| 279 | + error_log($log); | |
| 280 | + } | |
| 281 | + } | |
| 260 | 282 | } |
| 261 | 283 | |
| 284 | +function uwp_get_excluded_users_list() | |
| 285 | +{ | |
| 262 | 286 | |
| 287 | + $args = array( | |
| 288 | + 'fields' => 'ID', | |
| 289 | + 'meta_query' => array( | |
| 290 | + 'relation' => 'OR', | |
| 291 | + array( | |
| 292 | + 'key' => 'uwp_mod', | |
| 293 | + 'value' => 'email_unconfirmed', | |
| 294 | + 'compare' => '==' | |
| 295 | + ), | |
| 296 | + array( | |
| 297 | + 'key' => 'uwp_hide_from_listing', | |
| 298 | + 'value' => 1, | |
| 299 | + 'compare' => '==' | |
| 300 | + ) | |
| 301 | + ) | |
| 302 | + ); | |
| 303 | + | |
| 304 | + $inactive_users = new WP_User_Query($args); | |
| 305 | + $exclude_users = $inactive_users->get_results(); | |
| 306 | + | |
| 307 | + $excluded_globally = uwp_get_option('users_excluded_from_list'); | |
| 308 | + if (!empty($excluded_globally)) { | |
| 309 | + | |
| 310 | + if (is_array($excluded_globally)) { | |
| 311 | + $exclude_users = array_merge($exclude_users, $excluded_globally); | |
| 312 | + } else { | |
| 313 | + $excluded_users = str_replace(' ', '', $excluded_globally); | |
| 314 | + $users_array = explode(',', $excluded_users); | |
| 315 | + $exclude_users = array_merge($exclude_users, $users_array); | |
| 316 | + } | |
| 317 | + } | |
| 318 | + | |
| 319 | + return $exclude_users; | |
| 320 | +} | |
| 321 | + | |
| 263 | 322 | /** |
| 264 | - * Prints the users page main content. | |
| 323 | + * Retrieves a list of users with optional filtering, searching, and sorting. | |
| 265 | 324 | * |
| 266 | - * @since 1.0.0 | |
| 267 | - * @package userswp | |
| 325 | + * @since 1.0.0 | |
| 326 | + * @package userswp | |
| 268 | 327 | * |
| 269 | - * @return void | |
| 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 | + * } | |
| 270 | 335 | */ |
| 271 | -function get_uwp_users_list() { | |
| 336 | +function get_uwp_users_list( $roles = array() ) | |
| 337 | +{ | |
| 338 | + global $wpdb; | |
| 272 | 339 | |
| 273 | - global $wpdb; | |
| 340 | + // Sanitize and validate input parameters | |
| 341 | + $keyword = false; | |
| 342 | + if ( isset( $_GET['uwps'] ) && ! empty( $_GET['uwps'] ) ) { | |
| 343 | + $keyword = sanitize_text_field( wp_unslash( $_GET['uwps'] ) ); | |
| 344 | + } | |
| 274 | 345 | |
| 275 | - $keyword = false; | |
| 276 | - if (isset($_GET['uwps']) && $_GET['uwps'] != '') { | |
| 277 | - $keyword = stripslashes(strip_tags($_GET['uwps'])); | |
| 278 | - } | |
| 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; | |
| 353 | + } else { | |
| 354 | + $paged_var = get_query_var( 'paged' ); | |
| 355 | + $paged = absint( $paged_var ) > 0 ? absint( $paged_var ) : 1; | |
| 356 | + } | |
| 279 | 357 | |
| 280 | - $sort_by = false; | |
| 281 | - if (isset($_GET['uwp_sort_by']) && $_GET['uwp_sort_by'] != '') { | |
| 282 | - $sort_by = strip_tags(esc_sql($_GET['uwp_sort_by'])); | |
| 283 | - } | |
| 358 | + // Get number of items per page | |
| 359 | + $number = absint( uwp_get_option( 'users_no_of_items', 10 ) ); | |
| 360 | + $number = $number > 0 ? $number : 10; | |
| 284 | 361 | |
| 285 | - $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; | |
| 362 | + // Get search where clause from filters | |
| 363 | + $where = ''; | |
| 364 | + $where = apply_filters( 'uwp_users_search_where', $where, $keyword ); | |
| 286 | 365 | |
| 287 | - $number = uwp_get_option('profile_no_of_items', 10); | |
| 366 | + // Get excluded users list | |
| 367 | + $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(); | |
| 288 | 370 | |
| 289 | - $where = ''; | |
| 290 | - $where = apply_filters('uwp_users_search_where', $where, $keyword); | |
| 371 | + // Initialize sorting parameters | |
| 372 | + $exclude_query = ' '; | |
| 373 | + $order_by = 'uwp_meta_value'; | |
| 374 | + $order = 'ASC'; | |
| 375 | + $meta_key = ''; | |
| 291 | 376 | |
| 292 | - $arg = array( | |
| 293 | - 'fields' => 'ID', | |
| 294 | - 'meta_query' => array( | |
| 295 | - 'relation' => 'OR', | |
| 296 | - array( | |
| 297 | - 'key' => 'uwp_mod', | |
| 298 | - 'value' => 'email_unconfirmed', | |
| 299 | - 'compare' => '==' | |
| 300 | - ), | |
| 301 | - array( | |
| 302 | - 'key' => 'uwp_hide_from_listing', | |
| 303 | - 'value' => 1, | |
| 304 | - 'compare' => '==' | |
| 305 | - ) | |
| 306 | - ) | |
| 307 | - ); | |
| 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 | + } | |
| 308 | 382 | |
| 309 | - $inactive_users = new WP_User_Query($arg); | |
| 310 | - $exclude_users = $inactive_users->get_results(); | |
| 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 ); | |
| 399 | + $order = 'DESC'; | |
| 400 | + } else { | |
| 401 | + // Default to ASC if no suffix | |
| 402 | + $order_by = $sort_by; | |
| 403 | + $order = 'ASC'; | |
| 404 | + } | |
| 405 | + } | |
| 406 | + } | |
| 311 | 407 | |
| 312 | - $excluded_globally = uwp_get_option('users_excluded_from_list'); | |
| 313 | - if ( $excluded_globally ) { | |
| 314 | - $users = str_replace(' ', '', $excluded_globally ); | |
| 315 | - $users_array = explode(',', $users ); | |
| 316 | - $exclude_users = array_merge($exclude_users, $users_array); | |
| 317 | - } | |
| 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 . ')'; | |
| 412 | + } | |
| 318 | 413 | |
| 319 | - $exclude_users = apply_filters('uwp_excluded_users_from_list', $exclude_users, $where, $keyword); | |
| 414 | + $users = array(); | |
| 320 | 415 | |
| 321 | - if($exclude_users){ | |
| 322 | - $exclude_users_list = implode(',', array_unique($exclude_users)); | |
| 323 | - $exclude_query = 'AND '. $wpdb->users.'.ID NOT IN ('.$exclude_users_list.')'; | |
| 324 | - } else { | |
| 325 | - $exclude_query = ' '; | |
| 326 | - } | |
| 416 | + // Check if we have search criteria | |
| 417 | + if ( $keyword || $where ) { | |
| 327 | 418 | |
| 328 | - if ($keyword || $where) { | |
| 329 | - if (empty($where)) { | |
| 330 | - $users = $wpdb->get_results($wpdb->prepare( | |
| 331 | - "SELECT DISTINCT SQL_CALC_FOUND_ROWS $wpdb->users.* | |
| 332 | - FROM $wpdb->users | |
| 333 | - INNER JOIN $wpdb->usermeta | |
| 334 | - ON ( $wpdb->users.ID = $wpdb->usermeta.user_id ) | |
| 335 | - WHERE 1=1 | |
| 336 | - $exclude_query | |
| 337 | - AND ( | |
| 338 | - ( $wpdb->usermeta.meta_key = 'first_name' AND $wpdb->usermeta.meta_value LIKE %s ) | |
| 339 | - OR | |
| 340 | - ( $wpdb->usermeta.meta_key = 'last_name' AND $wpdb->usermeta.meta_value LIKE %s ) | |
| 341 | - OR | |
| 342 | - user_login LIKE %s | |
| 343 | - OR | |
| 344 | - user_nicename LIKE %s | |
| 345 | - OR | |
| 346 | - display_name LIKE %s | |
| 347 | - OR | |
| 348 | - user_email LIKE %s | |
| 349 | - ) | |
| 350 | - ORDER BY display_name ASC | |
| 351 | - LIMIT 0, 20", | |
| 352 | - array( | |
| 353 | - '%' . $keyword . '%', | |
| 354 | - '%' . $keyword . '%', | |
| 355 | - '%' . $keyword . '%', | |
| 356 | - '%' . $keyword . '%', | |
| 357 | - '%' . $keyword . '%', | |
| 358 | - '%' . $keyword . '%' | |
| 359 | - ) | |
| 360 | - )); | |
| 361 | - } else { | |
| 362 | - $usermeta_table = uwp_get_table_prefix() . 'uwp_usermeta'; | |
| 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 | |
| 438 | + ) | |
| 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 | + ); | |
| 447 | + } else { | |
| 448 | + // Custom where clause with uwp_usermeta table | |
| 449 | + $usermeta_table = get_usermeta_table_prefix() . 'uwp_usermeta'; | |
| 450 | + $keyword_query = ''; | |
| 363 | 451 | |
| 364 | - $users = $wpdb->get_results( | |
| 365 | - "SELECT DISTINCT SQL_CALC_FOUND_ROWS $wpdb->users.* | |
| 366 | - FROM $wpdb->users | |
| 367 | - INNER JOIN $usermeta_table | |
| 368 | - ON ( $wpdb->users.ID = $usermeta_table.user_id ) | |
| 369 | - WHERE 1=1 | |
| 370 | - $exclude_query | |
| 371 | - $where | |
| 372 | - ORDER BY display_name ASC | |
| 373 | - LIMIT 0, 20"); | |
| 374 | - } | |
| 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 | + ); | |
| 468 | + } | |
| 375 | 469 | |
| 376 | - $total_user = count($users); | |
| 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"; | |
| 476 | + } | |
| 377 | 477 | |
| 378 | - } else { | |
| 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' ); | |
| 379 | 481 | |
| 380 | - $args = array( | |
| 381 | - 'number' => (int) $number, | |
| 382 | - 'paged' => $paged, | |
| 383 | - 'exclude' => $exclude_users, | |
| 384 | - ); | |
| 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 ); | |
| 492 | + } | |
| 493 | + } | |
| 385 | 494 | |
| 495 | + // Process results if we have users | |
| 496 | + if ( ! empty( $get_users ) && is_array( $get_users ) ) { | |
| 497 | + // Prepare WP_User_Query arguments | |
| 498 | + $args = array( | |
| 499 | + 'include' => $get_users, | |
| 500 | + 'number' => $number, | |
| 501 | + 'paged' => $paged, | |
| 502 | + ); | |
| 386 | 503 | |
| 387 | - if ($sort_by) { | |
| 388 | - switch ($sort_by) { | |
| 389 | - case "newer": | |
| 390 | - $args['orderby'] = 'registered'; | |
| 391 | - $args['order'] = 'desc'; | |
| 392 | - break; | |
| 393 | - case "older": | |
| 394 | - $args['orderby'] = 'registered'; | |
| 395 | - $args['order'] = 'asc'; | |
| 396 | - break; | |
| 397 | - case "alpha_asc": | |
| 398 | - $args['orderby'] = 'display_name'; | |
| 399 | - $args['order'] = 'asc'; | |
| 400 | - break; | |
| 401 | - case "alpha_desc": | |
| 402 | - $args['orderby'] = 'display_name'; | |
| 403 | - $args['order'] = 'desc'; | |
| 404 | - break; | |
| 504 | + // Add exclude users if any | |
| 505 | + if ( ! empty( $exclude_users ) ) { | |
| 506 | + $args['exclude'] = $exclude_users; | |
| 507 | + } | |
| 405 | 508 | |
| 406 | - } | |
| 407 | - } | |
| 509 | + // Add meta_key if specified | |
| 510 | + if ( ! empty( $meta_key ) ) { | |
| 511 | + $args['meta_key'] = $meta_key; | |
| 512 | + } | |
| 408 | 513 | |
| 409 | - $users_query = new WP_User_Query($args); | |
| 410 | - $users = $users_query->get_results(); | |
| 411 | - $total_user = $users_query->get_total(); | |
| 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 | + } | |
| 524 | + } | |
| 412 | 525 | |
| 413 | - } | |
| 526 | + // Execute WP_User_Query | |
| 527 | + $uwp_users_query = new WP_User_Query( $args ); | |
| 528 | + $users['users'] = $uwp_users_query->get_results(); | |
| 529 | + $users['total_users'] = $uwp_users_query->get_total(); | |
| 414 | 530 | |
| 415 | - $total_pages=ceil($total_user/$number); | |
| 531 | + } else { | |
| 532 | + $users['users'] = array(); | |
| 533 | + $users['total_users'] = 0; | |
| 534 | + } | |
| 535 | + } else { | |
| 536 | + // No search criteria - get all users with optional role filtering | |
| 537 | + $args = array( | |
| 538 | + 'number' => $number, | |
| 539 | + 'paged' => $paged, | |
| 540 | + ); | |
| 416 | 541 | |
| 417 | - $layout_class = uwp_get_layout_class(); | |
| 418 | - ?> | |
| 419 | - <ul class="uwp-users-list-wrap <?php echo $layout_class; ?>" id="uwp_user_items_layout"> | |
| 420 | - <?php | |
| 421 | - if ($users) { | |
| 422 | - foreach ($users as $user) { | |
| 423 | - $user_obj = get_user_by('id', $user->ID); | |
| 542 | + // Add exclude users if any | |
| 543 | + if ( ! empty( $exclude_users ) ) { | |
| 544 | + $args['exclude'] = $exclude_users; | |
| 545 | + } | |
| 424 | 546 | |
| 425 | - // exclude logged in user | |
| 426 | - $exclude_loggedin_user = apply_filters('uwp_users_list_exclude_loggedin_user', false); | |
| 427 | - if ($exclude_loggedin_user) { | |
| 428 | - if ($user_obj->ID == get_current_user_id()) { | |
| 429 | - continue; | |
| 430 | - } | |
| 431 | - } | |
| 432 | - ?> | |
| 433 | - <li class="uwp-users-list-user"> | |
| 434 | - <div class="uwp-users-list-user-left"> | |
| 435 | - <?php do_action('uwp_users_profile_header', $user); ?> | |
| 436 | - </div> | |
| 437 | - <div class="uwp-users-list-user-right"> | |
| 438 | - <div class="uwp-users-list-user-name"> | |
| 439 | - <h3 class="uwp-user-title" data-user="<?php echo $user_obj->ID; ?>"> | |
| 440 | - <a href="<?php echo apply_filters('uwp_profile_link', get_author_posts_url($user_obj->ID), $user_obj->ID); ?>"> | |
| 441 | - <?php echo apply_filters('uwp_profile_display_name', $user_obj->display_name); ?> | |
| 442 | - </a> | |
| 443 | - <?php do_action('uwp_users_after_title', $user_obj->ID ); ?> | |
| 444 | - </h3> | |
| 445 | - </div> | |
| 446 | - <div class="uwp-users-list-user-btns"> | |
| 447 | - <?php do_action('uwp_profile_buttons', $user_obj ); ?> | |
| 448 | - </div> | |
| 449 | - <div class="uwp-users-list-user-social"> | |
| 450 | - <?php do_action('uwp_profile_social', $user_obj ); ?> | |
| 451 | - </div> | |
| 452 | - <div class="uwp-users-list-extra"> | |
| 453 | - <?php do_action('uwp_users_extra', $user_obj ); ?> | |
| 454 | - </div> | |
| 455 | - <div class="clfx"></div> | |
| 456 | - </div> | |
| 457 | - </li> | |
| 458 | - <?php | |
| 459 | - } | |
| 460 | - } else { | |
| 461 | - // no users found | |
| 462 | - echo '<div class="uwp-alert-error text-center">'; | |
| 463 | - echo __('No Users Found', 'userswp'); | |
| 464 | - echo '</div>'; | |
| 465 | - } | |
| 466 | - ?> | |
| 467 | - </ul> | |
| 547 | + // Filter by roles if specified | |
| 548 | + if ( ! empty( $roles ) && is_array( $roles ) ) { | |
| 549 | + $args['role__in'] = $roles; | |
| 550 | + } | |
| 468 | 551 | |
| 469 | - <?php | |
| 470 | - if ($total_pages > 1) { | |
| 471 | - do_action('uwp_profile_pagination', $total_pages); | |
| 472 | - } | |
| 473 | - ?> | |
| 474 | - <?php | |
| 475 | -} | |
| 552 | + // Add meta_key if specified | |
| 553 | + if ( ! empty( $meta_key ) ) { | |
| 554 | + $args['meta_key'] = $meta_key; | |
| 555 | + } | |
| 476 | 556 | |
| 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 | + } | |
| 567 | + } | |
| 477 | 568 | |
| 569 | + // Execute WP_User_Query | |
| 570 | + $uwp_users_query = new WP_User_Query( $args ); | |
| 571 | + $users['users'] = $uwp_users_query->get_results(); | |
| 572 | + $users['total_users'] = $uwp_users_query->get_total(); | |
| 573 | + } | |
| 478 | 574 | |
| 479 | -/** | |
| 480 | - * Loads the font-awesome css files. | |
| 481 | - * | |
| 482 | - * @since 1.0.0 | |
| 483 | - * @package userswp | |
| 484 | - * | |
| 485 | - * @return void | |
| 486 | - */ | |
| 487 | -function uwp_load_font_awesome() { | |
| 488 | - //load font awesome | |
| 489 | - global $wp_styles; | |
| 490 | - if ($wp_styles) { | |
| 491 | - $srcs = array_map('basename', (array) wp_list_pluck($wp_styles->registered, 'src') ); | |
| 492 | - if ( in_array('font-awesome.css', $srcs) || in_array('font-awesome.min.css', $srcs) ) { | |
| 493 | - /* echo 'font-awesome.css registered'; */ | |
| 494 | - } else { | |
| 495 | - wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css', array(), null); | |
| 496 | - wp_enqueue_style('font-awesome'); | |
| 497 | - } | |
| 498 | - } else { | |
| 499 | - wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css', array(), null); | |
| 500 | - wp_enqueue_style('font-awesome'); | |
| 501 | - } | |
| 575 | + return $users; | |
| 502 | 576 | } |
| 503 | 577 | |
| 504 | 578 | /** |
| 505 | - * Gets the custom field info for given key. | |
| 579 | + * Returns the Users page layout class based on the setting. | |
| 506 | 580 | * |
| 507 | 581 | * @since 1.0.0 |
| 508 | 582 | * @package userswp |
| 509 | 583 | * |
| 510 | - * @param string $htmlvar_name Custom field key. | |
| 511 | - * | |
| 512 | - * @return object Field info. | |
| 584 | + * @return string Layout class. | |
| 513 | 585 | */ |
| 514 | -function uwp_get_custom_field_info($htmlvar_name) { | |
| 515 | - global $wpdb; | |
| 516 | - $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 517 | - $field = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE htmlvar_name = %s", array($htmlvar_name))); | |
| 518 | - return $field; | |
| 519 | -} | |
| 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 { | |
| 592 | + $value = 'list'; | |
| 593 | + } | |
| 594 | + $layout = uwp_get_option('users_default_layout', $value); | |
| 595 | + } | |
| 520 | 596 | |
| 597 | + switch ($layout) { | |
| 598 | + case "list": | |
| 599 | + $class = "uwp_listview"; | |
| 600 | + $bs_class = "row-cols-md-1"; | |
| 601 | + $col_count = 1; | |
| 602 | + break; | |
| 603 | + case "2col": | |
| 604 | + $class = "uwp_gridview uwp_gridview_2col"; | |
| 605 | + $bs_class = "row-cols-md-2"; | |
| 606 | + $col_count = 2; | |
| 607 | + break; | |
| 608 | + case "3col": | |
| 609 | + $class = "uwp_gridview uwp_gridview_3col"; | |
| 610 | + $bs_class = "row-cols-md-3"; | |
| 611 | + $col_count = 3; | |
| 612 | + break; | |
| 613 | + case "4col": | |
| 614 | + $class = "uwp_gridview uwp_gridview_4col"; | |
| 615 | + $bs_class = "row-cols-md-4"; | |
| 616 | + $col_count = 4; | |
| 617 | + break; | |
| 618 | + case "5col": | |
| 619 | + $class = "uwp_gridview uwp_gridview_5col"; | |
| 620 | + $bs_class = "row-cols-md-5"; | |
| 621 | + $col_count = 5; | |
| 622 | + break; | |
| 623 | + default: | |
| 624 | + $class = "uwp_listview"; | |
| 625 | + $bs_class = "row-cols-md-3"; | |
| 626 | + $col_count = 1; | |
| 627 | + } | |
| 521 | 628 | |
| 629 | + if ($count_only) { | |
| 630 | + return $col_count; | |
| 631 | + } | |
| 522 | 632 | |
| 523 | -/** | |
| 524 | - * Returns the Users page layout class based on the setting. | |
| 525 | - * | |
| 526 | - * @since 1.0.0 | |
| 527 | - * @package userswp | |
| 528 | - * | |
| 529 | - * @return string Layout class. | |
| 530 | - */ | |
| 531 | -function uwp_get_layout_class() { | |
| 532 | - $default_layout = uwp_get_option('users_default_layout', 'list'); | |
| 533 | - switch ($default_layout) { | |
| 534 | - case "list": | |
| 535 | - $class = "uwp_listview"; | |
| 536 | - break; | |
| 537 | - case "2col": | |
| 538 | - $class = "uwp_gridview uwp_gridview_2col"; | |
| 539 | - break; | |
| 540 | - case "3col": | |
| 541 | - $class = "uwp_gridview uwp_gridview_3col"; | |
| 542 | - break; | |
| 543 | - case "4col": | |
| 544 | - $class = "uwp_gridview uwp_gridview_4col"; | |
| 545 | - break; | |
| 546 | - case "5col": | |
| 547 | - $class = "uwp_gridview uwp_gridview_5col"; | |
| 548 | - break; | |
| 549 | - default: | |
| 550 | - $class = "uwp_listview"; | |
| 551 | - } | |
| 633 | + if (uwp_get_option("design_style", 'bootstrap')) { | |
| 634 | + return $bs_class; | |
| 635 | + } | |
| 552 | 636 | |
| 553 | - return $class; | |
| 637 | + return $class; | |
| 554 | 638 | } |
| 555 | 639 | |
| 556 | -add_filter( 'get_user_option_metaboxhidden_nav-menus', 'uwp_always_nav_menu_visibility', 10, 3 ); | |
| 640 | +add_filter('uwp_users_list_ul_extra_class', 'uwp_get_layout_class', 10, 1); | |
| 557 | 641 | |
| 642 | +add_filter('get_user_option_metaboxhidden_nav-menus', 'uwp_always_nav_menu_visibility', 10, 3); | |
| 643 | + | |
| 558 | 644 | /** |
| 559 | 645 | * Filters nav menu visibility option value. |
| 560 | 646 | * |
| 561 | 647 | * @since 1.0.0 |
| @@ -566,146 +652,17 @@ | ||
| 566 | 652 | * @param WP_User $user WP_User object of the user whose option is being retrieved. |
| 567 | 653 | * |
| 568 | 654 | * @return array Filtered value. |
| 569 | 655 | */ |
| 570 | -function uwp_always_nav_menu_visibility( $result, $option, $user ) | |
| 656 | +function uwp_always_nav_menu_visibility($result, $option, $user) | |
| 571 | 657 | { |
| 572 | - if( is_array($result) && in_array( 'add-users-wp-nav-menu', $result ) ) { | |
| 573 | - $result = array_diff( $result, array( 'add-users-wp-nav-menu' ) ); | |
| 574 | - } | |
| 658 | + if (is_array($result) && in_array('add-users-wp-nav-menu', $result)) { | |
| 659 | + $result = array_diff($result, array('add-users-wp-nav-menu')); | |
| 660 | + } | |
| 575 | 661 | |
| 576 | - return $result; | |
| 662 | + return $result; | |
| 577 | 663 | } |
| 578 | 664 | |
| 579 | -add_filter('user_profile_picture_description', 'uwp_admin_user_profile_picture_description'); | |
| 580 | - | |
| 581 | -/** | |
| 582 | - * Filters the user profile picture description displayed under the Gravatar. | |
| 583 | - * | |
| 584 | - * @since 1.0.0 | |
| 585 | - * @package userswp | |
| 586 | - * | |
| 587 | - * @param string $description Profile picture description. | |
| 588 | - * | |
| 589 | - * @return string Modified description. | |
| 590 | - */ | |
| 591 | -function uwp_admin_user_profile_picture_description($description) { | |
| 592 | - if (is_admin() && IS_PROFILE_PAGE) { | |
| 593 | - $user_id = get_current_user_id(); | |
| 594 | - $avatar = uwp_get_usermeta($user_id, 'uwp_account_avatar_thumb', ''); | |
| 595 | - | |
| 596 | - if (!empty($avatar)) { | |
| 597 | - $description = sprintf( __( 'You can change your profile picture on your <a href="%s">Profile Page</a>.', 'userswp' ), | |
| 598 | - uwp_build_profile_tab_url( $user_id )); | |
| 599 | - } | |
| 600 | - | |
| 601 | - } | |
| 602 | - return $description; | |
| 603 | -} | |
| 604 | - | |
| 605 | -/** | |
| 606 | - * Adds avatar and banner fields in admin side. | |
| 607 | - * | |
| 608 | - * @since 1.0.0 | |
| 609 | - * @package userswp | |
| 610 | - * | |
| 611 | - * @param object $user User object. | |
| 612 | - * | |
| 613 | - * @return void | |
| 614 | - */ | |
| 615 | -function uwp_admin_edit_banner_fields($user) { | |
| 616 | - global $wpdb; | |
| 617 | - | |
| 618 | - $file_obj = new UsersWP_Files(); | |
| 619 | - | |
| 620 | - $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 621 | - $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE (form_type = 'avatar' OR form_type = 'banner') ORDER BY sort_order ASC"); | |
| 622 | - if ($fields) { | |
| 623 | - ?> | |
| 624 | - <div class="uwp-profile-extra uwp_page"> | |
| 625 | - <?php do_action('uwp_admin_profile_edit', $user ); ?> | |
| 626 | - <table class="uwp-profile-extra-table form-table"> | |
| 627 | - <?php | |
| 628 | - foreach ($fields as $field) { | |
| 629 | - | |
| 630 | - // Icon | |
| 631 | - $icon = uwp_get_field_icon( $field->field_icon ); | |
| 632 | - | |
| 633 | - if ($field->field_type == 'fieldset') { | |
| 634 | - ?> | |
| 635 | - <tr style="margin: 0; padding: 0"> | |
| 636 | - <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3 style="margin: 10px 0;"> | |
| 637 | - <?php echo $icon.$field->site_title; ?></h3></th> | |
| 638 | - <td></td> | |
| 639 | - </tr> | |
| 640 | - <?php | |
| 641 | - } else { ?> | |
| 642 | - <tr> | |
| 643 | - <th class="uwp-profile-extra-key"><?php echo $icon.$field->site_title; ?></th> | |
| 644 | - <td class="uwp-profile-extra-value"> | |
| 645 | - <?php | |
| 646 | - if ($field->htmlvar_name == "uwp_avatar_file") { | |
| 647 | - $value = uwp_get_usermeta($user->ID, "uwp_account_avatar_thumb", ""); | |
| 648 | - } elseif ($field->htmlvar_name == "uwp_banner_file") { | |
| 649 | - $value = uwp_get_usermeta($user->ID, "uwp_account_banner_thumb", ""); | |
| 650 | - } else { | |
| 651 | - $value = ""; | |
| 652 | - } | |
| 653 | - ?> | |
| 654 | - <?php echo $file_obj->uwp_file_upload_preview($field, $value); ?> | |
| 655 | - <?php | |
| 656 | - if ($field->htmlvar_name == "uwp_avatar_file") { | |
| 657 | - if (!empty($value)) { | |
| 658 | - ?> | |
| 659 | - <a class="uwp-profile-modal-form-trigger" data-type="avatar" href="#"> | |
| 660 | - <?php echo __("Change Avatar", "userswp"); ?> | |
| 661 | - </a> | |
| 662 | - <?php | |
| 663 | - } else { | |
| 664 | - ?> | |
| 665 | - <a class="uwp-profile-modal-form-trigger" data-type="avatar" href="#"> | |
| 666 | - <?php echo __("Upload Avatar", "userswp"); ?> | |
| 667 | - </a> | |
| 668 | - <?php | |
| 669 | - } | |
| 670 | - } elseif ($field->htmlvar_name == "uwp_banner_file") { | |
| 671 | - if (!empty($value)) { | |
| 672 | - ?> | |
| 673 | - <a class="uwp-profile-modal-form-trigger" data-type="banner" href="#"> | |
| 674 | - <?php echo __("Change Banner", "userswp"); ?> | |
| 675 | - </a> | |
| 676 | - <?php | |
| 677 | - } else { | |
| 678 | - ?> | |
| 679 | - <a class="uwp-profile-modal-form-trigger" data-type="banner" href="#"> | |
| 680 | - <?php echo __("Upload Banner", "userswp"); ?> | |
| 681 | - </a> | |
| 682 | - <?php | |
| 683 | - } | |
| 684 | - } | |
| 685 | - ?> | |
| 686 | - </td> | |
| 687 | - </tr> | |
| 688 | - <?php | |
| 689 | - } | |
| 690 | - } | |
| 691 | - ?> | |
| 692 | - </table> | |
| 693 | - </div> | |
| 694 | - <?php | |
| 695 | - } | |
| 696 | -} | |
| 697 | -add_action('show_user_profile', 'uwp_admin_edit_banner_fields'); | |
| 698 | -add_action('edit_user_profile', 'uwp_admin_edit_banner_fields'); | |
| 699 | - | |
| 700 | -add_filter('admin_body_class', 'uwp_add_admin_body_class'); | |
| 701 | -function uwp_add_admin_body_class($classes) { | |
| 702 | - $screen = get_current_screen(); | |
| 703 | - if ( 'profile' == $screen->base ) | |
| 704 | - $classes .= 'uwp_page'; | |
| 705 | - return $classes; | |
| 706 | -} | |
| 707 | - | |
| 708 | 665 | // Privacy |
| 709 | 666 | add_filter('uwp_account_page_title', 'uwp_account_privacy_page_title', 10, 2); |
| 710 | 667 | |
| 711 | 668 | /** |
| @@ -716,103 +673,26 @@ | ||
| 716 | 673 | * |
| 717 | 674 | * @param string $title Privacy title. |
| 718 | 675 | * @param string $type Tab type. |
| 719 | 676 | * |
| 720 | - * @return string|void Title. | |
| 677 | + * @return string Title. | |
| 721 | 678 | */ |
| 722 | -function uwp_account_privacy_page_title($title, $type) { | |
| 723 | - if ($type == 'privacy') { | |
| 724 | - $title = __( 'Privacy', 'userswp' ); | |
| 725 | - } | |
| 679 | +function uwp_account_privacy_page_title($title, $type) | |
| 680 | +{ | |
| 726 | 681 | |
| 727 | - return $title; | |
| 728 | -} | |
| 682 | + if ($type == 'privacy') { | |
| 683 | + $title = __('Privacy', 'userswp'); | |
| 684 | + } elseif ($type == 'notifications') { | |
| 685 | + $title = __('E-Mail Notifications', 'userswp'); | |
| 686 | + } elseif ($type == 'delete-account') { | |
| 687 | + $title = __('Delete Account', 'userswp'); | |
| 688 | + } elseif ($type == 'change-password') { | |
| 689 | + $title = __('Change Password', 'userswp'); | |
| 690 | + } elseif ($type == 'wp2fa') { | |
| 691 | + $title = __('Two-factor Authentication Settings', 'userswp'); | |
| 692 | + } | |
| 729 | 693 | |
| 730 | -add_action('uwp_account_form_display', 'uwp_account_privacy_edit_form_display'); | |
| 731 | - | |
| 732 | -/** | |
| 733 | - * Adds form html for privacy fields in account page. | |
| 734 | - * | |
| 735 | - * @since 1.0.0 | |
| 736 | - * @package userswp | |
| 737 | - * | |
| 738 | - * @param string $type Form type. | |
| 739 | - * | |
| 740 | - * @return void | |
| 741 | - */ | |
| 742 | -function uwp_account_privacy_edit_form_display($type) { | |
| 743 | - if ($type == 'privacy') { | |
| 744 | - $make_profile_private = uwp_can_make_profile_private(); | |
| 745 | - echo '<div class="uwp-account-form uwp_wc_form">'; | |
| 746 | - $extra_where = "AND is_public='2'"; | |
| 747 | - $fields = get_account_form_fields($extra_where); | |
| 748 | - $fields = apply_filters('uwp_account_privacy_fields', $fields); | |
| 749 | - $user_id = get_current_user_id(); | |
| 750 | - ?> | |
| 751 | - <div class="uwp-profile-extra"> | |
| 752 | - <div class="uwp-profile-extra-div form-table"> | |
| 753 | - <form class="uwp-account-form uwp_form" method="post"> | |
| 754 | - <?php if ($fields) { ?> | |
| 755 | - <div class="uwp-profile-extra-wrap"> | |
| 756 | - <div class="uwp-profile-extra-key" style="font-weight: bold;"> | |
| 757 | - <?php echo __("Field", "userswp") ?> | |
| 758 | - </div> | |
| 759 | - <div class="uwp-profile-extra-value" style="font-weight: bold;"> | |
| 760 | - <?php echo __("Is Public?", "userswp") ?> | |
| 761 | - </div> | |
| 762 | - </div> | |
| 763 | - <?php foreach ($fields as $field) { ?> | |
| 764 | - <div class="uwp-profile-extra-wrap"> | |
| 765 | - <div class="uwp-profile-extra-key"><?php echo $field->site_title; ?> | |
| 766 | - <span class="uwp-profile-extra-sep">:</span></div> | |
| 767 | - <div class="uwp-profile-extra-value"> | |
| 768 | - <?php | |
| 769 | - $field_name = $field->htmlvar_name . '_privacy'; | |
| 770 | - $value = uwp_get_usermeta($user_id, $field_name, false); | |
| 771 | - if ($value === false) { | |
| 772 | - $value = 'yes'; | |
| 773 | - } | |
| 774 | - ?> | |
| 775 | - <select name="<?php echo $field_name; ?>" class="uwp_privacy_field" | |
| 776 | - style="margin: 0;"> | |
| 777 | - <option value="no" <?php selected($value, "no"); ?>><?php echo __("No", "userswp") ?></option> | |
| 778 | - <option value="yes" <?php selected($value, "yes"); ?>><?php echo __("Yes", "userswp") ?></option> | |
| 779 | - </select> | |
| 780 | - </div> | |
| 781 | - </div> | |
| 782 | - <?php } | |
| 783 | - } | |
| 784 | - $value = get_user_meta($user_id, 'uwp_hide_from_listing', true); ?> | |
| 785 | - <div class="uwp-profile-extra-wrap"> | |
| 786 | - <div id="uwp_hide_from_listing" class="uwp_hide_from_listing"> | |
| 787 | - <input name="uwp_hide_from_listing" class="" <?php checked($value, "1", true); ?> type="checkbox" value="1"><?php _e('Hide profile from the users listing page.', 'userswp'); ?> | |
| 788 | - </div> | |
| 789 | - </div> | |
| 790 | - <?php | |
| 791 | - do_action('uwp_after_privacy_form_fields', $fields); | |
| 792 | - if ($make_profile_private) { | |
| 793 | - $field_name = 'uwp_make_profile_private'; | |
| 794 | - $value = get_user_meta($user_id, $field_name, true); | |
| 795 | - if ($value === false) { | |
| 796 | - $value = '0'; | |
| 797 | - } | |
| 798 | - ?> | |
| 799 | - <div id="uwp_make_profile_private" class=" uwp_make_profile_private_row"> | |
| 800 | - <input type="hidden" name="uwp_make_profile_private" value="0"> | |
| 801 | - <input name="uwp_make_profile_private" class="" <?php checked( $value, "1", true ); ?> type="checkbox" value="1"> | |
| 802 | - <?php _e( 'Make the whole profile private', 'userswp' ); ?> | |
| 803 | - </div> | |
| 804 | - <?php | |
| 805 | - } | |
| 806 | - ?> | |
| 807 | - <input type="hidden" name="uwp_privacy_nonce" value="<?php echo wp_create_nonce( 'uwp-privacy-nonce' ); ?>" /> | |
| 808 | - <input name="uwp_privacy_submit" value="<?php echo __( 'Submit', 'userswp' ); ?>" type="submit"> | |
| 809 | - </form> | |
| 810 | - </div> | |
| 811 | - </div> | |
| 812 | - <?php | |
| 813 | - echo '</div>'; | |
| 814 | - } | |
| 694 | + return $title; | |
| 815 | 695 | } |
| 816 | 696 | |
| 817 | 697 | add_action('uwp_account_menu_display', 'uwp_add_account_menu_links'); |
| 818 | 698 | |
| @@ -823,60 +703,72 @@ | ||
| 823 | 703 | * @package userswp |
| 824 | 704 | * |
| 825 | 705 | * @return void |
| 826 | 706 | */ |
| 827 | -function uwp_add_account_menu_links() { | |
| 707 | +function uwp_add_account_menu_links() | |
| 708 | +{ | |
| 709 | + global $aui_bs5; | |
| 828 | 710 | |
| 829 | - if (isset($_GET['type'])) { | |
| 830 | - $type = strip_tags(esc_sql($_GET['type'])); | |
| 831 | - } else { | |
| 832 | - $type = 'account'; | |
| 833 | - } | |
| 711 | + if (isset($_GET['type'])) { | |
| 712 | + $type = strip_tags(esc_sql($_GET['type'])); | |
| 713 | + } else { | |
| 714 | + $type = 'account'; | |
| 715 | + } | |
| 834 | 716 | |
| 835 | - $account_page = uwp_get_page_id('account_page', false); | |
| 836 | - $account_page_link = get_permalink($account_page); | |
| 717 | + $account_page = uwp_get_page_id('account_page', false); | |
| 718 | + $account_page_link = get_permalink($account_page); | |
| 837 | 719 | |
| 838 | - $account_available_tabs = uwp_account_get_available_tabs(); | |
| 720 | + $account_available_tabs = uwp_account_get_available_tabs(); | |
| 839 | 721 | |
| 840 | - if (!is_array($account_available_tabs) && count($account_available_tabs) > 0) { | |
| 841 | - return; | |
| 842 | - } | |
| 722 | + if (!is_array($account_available_tabs) && count($account_available_tabs) > 0) { | |
| 723 | + return; | |
| 724 | + } | |
| 843 | 725 | |
| 844 | - echo '<ul class="uwp_account_menu">'; | |
| 726 | + $legacy = '<ul class="uwp_account_menu">'; | |
| 727 | + 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"> | |
| 730 | + <?php | |
| 731 | + foreach ($account_available_tabs as $tab_id => $tab) { | |
| 845 | 732 | |
| 846 | - foreach( $account_available_tabs as $tab_id => $tab ) { | |
| 733 | + if ($tab_id == 'account') { | |
| 734 | + $tab_url = $account_page_link; | |
| 735 | + } else { | |
| 736 | + $tab_url = add_query_arg(array( | |
| 737 | + 'type' => $tab_id, | |
| 738 | + ), $account_page_link); | |
| 739 | + } | |
| 847 | 740 | |
| 848 | - if ($tab_id == 'account') { | |
| 849 | - $tab_url = $account_page_link; | |
| 850 | - } else { | |
| 851 | - $tab_url = add_query_arg(array( | |
| 852 | - 'type' => $tab_id, | |
| 853 | - ), $account_page_link); | |
| 854 | - } | |
| 741 | + if (isset($tab['link'])) { | |
| 742 | + $tab_url = $tab['link']; | |
| 743 | + } | |
| 855 | 744 | |
| 856 | - if (isset($tab['link'])) { | |
| 857 | - $tab_url = $tab['link']; | |
| 858 | - } | |
| 745 | + $active = $type == $tab_id ? ' active' : ''; | |
| 859 | 746 | |
| 860 | - $active = $type == $tab_id ? ' active' : ''; | |
| 861 | - ?> | |
| 862 | - <li id="uwp-account-<?php echo $tab_id; ?>"> | |
| 863 | - <a class="<?php echo $active; ?>" href="<?php echo esc_url( $tab_url ); ?>"> | |
| 864 | - <i class="<?php echo $tab['icon']; ?>"></i> <?php echo $tab['title']; ?> | |
| 865 | - </a> | |
| 866 | - </li> | |
| 867 | - <?php | |
| 868 | - } | |
| 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 | |
| 869 | 752 | |
| 870 | - $template = new UsersWP_Templates(); | |
| 871 | - $logout_url = $template->uwp_logout_url(); | |
| 872 | - echo '<li id="uwp-account-logout"><a class="uwp-account-logout-link" href="'.$logout_url.'"><i class="fa fa-sign-out"></i>'.__('Logout', 'userswp').'</a></li>'; | |
| 873 | - echo '</ul>'; | |
| 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"]); | |
| 756 | + $legacy .= '</a></li>'; | |
| 757 | + } | |
| 758 | + ?> | |
| 759 | + </ul> | |
| 760 | + <?php | |
| 761 | + $legacy .= '</ul>'; | |
| 762 | + $bs_output = ob_get_clean(); | |
| 763 | + $style = uwp_get_option('design_style', 'bootstrap'); | |
| 764 | + if (!empty($style)) { | |
| 765 | + echo $bs_output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 766 | + } else { | |
| 767 | + echo $legacy; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 768 | + } | |
| 874 | 769 | } |
| 875 | 770 | |
| 876 | - | |
| 877 | - | |
| 878 | - | |
| 879 | 771 | /** |
| 880 | 772 | * Updates extras fields sort order. |
| 881 | 773 | * |
| 882 | 774 | * @since 1.0.0 |
| @@ -883,37 +775,38 @@ | ||
| 883 | 775 | * @package userswp |
| 884 | 776 | * |
| 885 | 777 | * @param array $field_ids Form extras field ids. |
| 886 | 778 | * @param string $form_type Form type. |
| 779 | + * @param int $form_id Form ID. | |
| 887 | 780 | * |
| 888 | 781 | * @return array|bool Sorted field ids. |
| 889 | 782 | */ |
| 890 | -function uwp_form_extras_field_order($field_ids = array(), $form_type = 'register') | |
| 783 | +function uwp_form_extras_field_order($field_ids = array(), $form_type = 'register', $form_id = 1) | |
| 891 | 784 | { |
| 892 | - global $wpdb; | |
| 893 | - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; | |
| 785 | + global $wpdb; | |
| 786 | + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; | |
| 894 | 787 | |
| 895 | - $count = 0; | |
| 896 | - if (!empty($field_ids)): | |
| 897 | - foreach ($field_ids as $id) { | |
| 788 | + $count = 0; | |
| 789 | + if (!empty($field_ids)): | |
| 790 | + foreach ($field_ids as $id) { | |
| 898 | 791 | |
| 899 | - $cf = trim($id, '_'); | |
| 792 | + $cf = trim($id, '_'); | |
| 900 | 793 | |
| 901 | - $wpdb->query( | |
| 902 | - $wpdb->prepare( | |
| 903 | - "update " . $extras_table_name . " set | |
| 904 | - sort_order=%d | |
| 905 | - where id= %d", | |
| 906 | - array($count, $cf) | |
| 907 | - ) | |
| 908 | - ); | |
| 909 | - $count++; | |
| 910 | - } | |
| 794 | + $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 795 | + $extras_table_name, | |
| 796 | + array( | |
| 797 | + 'sort_order' => $count, | |
| 798 | + ), | |
| 799 | + array('id' => $cf, 'form_id' => $form_id) | |
| 800 | + ); | |
| 911 | 801 | |
| 912 | - return $field_ids; | |
| 913 | - else: | |
| 914 | - return false; | |
| 915 | - endif; | |
| 802 | + $count++; | |
| 803 | + } | |
| 804 | + | |
| 805 | + return $field_ids; | |
| 806 | + else: | |
| 807 | + return false; | |
| 808 | + endif; | |
| 916 | 809 | } |
| 917 | 810 | |
| 918 | 811 | /** |
| 919 | 812 | * Uppercase the first character of each word in a string. |
| @@ -925,14 +818,15 @@ | ||
| 925 | 818 | * @param string $charset Charset. |
| 926 | 819 | * |
| 927 | 820 | * @return string Converted string. |
| 928 | 821 | */ |
| 929 | -function uwp_ucwords($string, $charset='UTF-8') { | |
| 930 | - if (function_exists('mb_convert_case')) { | |
| 931 | - return mb_convert_case($string, MB_CASE_TITLE, $charset); | |
| 932 | - } else { | |
| 933 | - return ucwords($string); | |
| 934 | - } | |
| 822 | +function uwp_ucwords($string, $charset = 'UTF-8') | |
| 823 | +{ | |
| 824 | + if (function_exists('mb_convert_case')) { | |
| 825 | + return mb_convert_case($string, MB_CASE_TITLE, $charset); | |
| 826 | + } else { | |
| 827 | + return ucwords($string); | |
| 828 | + } | |
| 935 | 829 | } |
| 936 | 830 | |
| 937 | 831 | /** |
| 938 | 832 | * Checks whether the column exists in the table. |
| @@ -946,10 +840,10 @@ | ||
| 946 | 840 | * @return bool |
| 947 | 841 | */ |
| 948 | 842 | function uwp_column_exist($db, $column) |
| 949 | 843 | { |
| 950 | - $table = new UsersWP_Tables(); | |
| 951 | - $table->column_exists($db, $column); | |
| 844 | + $table = new UsersWP_Tables(); | |
| 845 | + return $table->column_exists($db, $column); | |
| 952 | 846 | } |
| 953 | 847 | |
| 954 | 848 | /** |
| 955 | 849 | * Adds column if not exist in the table. |
| @@ -964,11 +858,10 @@ | ||
| 964 | 858 | * @return bool|int True when success. |
| 965 | 859 | */ |
| 966 | 860 | function uwp_add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NOT NULL") |
| 967 | 861 | { |
| 968 | - $table = new UsersWP_Tables(); | |
| 969 | - $table->add_column_if_not_exist($db, $column, $column_attr); | |
| 970 | - | |
| 862 | + $table = new UsersWP_Tables(); | |
| 863 | + return $table->add_column_if_not_exist($db, $column, $column_attr); | |
| 971 | 864 | } |
| 972 | 865 | |
| 973 | 866 | /** |
| 974 | 867 | * Returns excluded custom fields. |
| @@ -977,14 +870,16 @@ | ||
| 977 | 870 | * @package userswp |
| 978 | 871 | * |
| 979 | 872 | * @return array Excluded custom fields. |
| 980 | 873 | */ |
| 981 | -function uwp_get_excluded_fields() { | |
| 982 | - $excluded = array( | |
| 983 | - 'uwp_account_password', | |
| 984 | - 'uwp_account_confirm_password', | |
| 985 | - ); | |
| 986 | - return $excluded; | |
| 874 | +function uwp_get_excluded_fields() | |
| 875 | +{ | |
| 876 | + $excluded = array( | |
| 877 | + 'password', | |
| 878 | + 'confirm_password', | |
| 879 | + 'user_privacy', | |
| 880 | + ); | |
| 881 | + return apply_filters('uwp_excluded_fields', $excluded); | |
| 987 | 882 | } |
| 988 | 883 | |
| 989 | 884 | /** |
| 990 | 885 | * Formats the currency using currency separator. |
| @@ -996,50 +891,61 @@ | ||
| 996 | 891 | * @param array|string $cf Custom field info. |
| 997 | 892 | * |
| 998 | 893 | * @return string Formatted currency. |
| 999 | 894 | */ |
| 1000 | -function uwp_currency_format_number($number='',$cf=''){ | |
| 895 | +function uwp_currency_format_number($number = '', $cf = '') | |
| 896 | +{ | |
| 1001 | 897 | |
| 1002 | - $cs = isset($cf['extra_fields']) ? maybe_unserialize($cf['extra_fields']) : ''; | |
| 898 | + $cs = isset($cf['extra_fields']) ? maybe_unserialize($cf['extra_fields']) : ''; | |
| 1003 | 899 | |
| 1004 | - $symbol = isset($cs['currency_symbol']) ? $cs['currency_symbol'] : '$'; | |
| 1005 | - $decimals = isset($cf['decimal_point']) && $cf['decimal_point'] ? $cf['decimal_point'] : 2; | |
| 1006 | - $decimal_display = isset($cf['decimal_display']) && $cf['decimal_display'] ? $cf['decimal_display'] : 'if'; | |
| 1007 | - $decimalpoint = '.'; | |
| 900 | + $symbol = isset($cs['currency_symbol']) ? $cs['currency_symbol'] : '$'; | |
| 901 | + $decimals = isset($cf['decimal_point']) && $cf['decimal_point'] ? $cf['decimal_point'] : 2; | |
| 902 | + $decimal_display = isset($cf['decimal_display']) && $cf['decimal_display'] ? $cf['decimal_display'] : 'if'; | |
| 903 | + $decimalpoint = '.'; | |
| 1008 | 904 | |
| 1009 | - if(isset($cs['decimal_separator']) && $cs['decimal_separator']=='comma'){ | |
| 1010 | - $decimalpoint = ','; | |
| 1011 | - } | |
| 905 | + if (isset($cs['decimal_separator']) && $cs['decimal_separator'] == 'comma') { | |
| 906 | + $decimalpoint = ','; | |
| 907 | + } | |
| 1012 | 908 | |
| 1013 | - $separator = ','; | |
| 909 | + $separator = ','; | |
| 1014 | 910 | |
| 1015 | - if(isset($cs['thousand_separator'])){ | |
| 1016 | - if($cs['thousand_separator']=='comma'){$separator = ',';} | |
| 1017 | - if($cs['thousand_separator']=='slash'){$separator = '\\';} | |
| 1018 | - if($cs['thousand_separator']=='period'){$separator = '.';} | |
| 1019 | - if($cs['thousand_separator']=='space'){$separator = ' ';} | |
| 1020 | - if($cs['thousand_separator']=='none'){$separator = '';} | |
| 1021 | - } | |
| 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 | + } | |
| 927 | + } | |
| 1022 | 928 | |
| 1023 | - $currency_symbol_placement = isset($cs['currency_symbol_placement']) ? $cs['currency_symbol_placement'] : 'left'; | |
| 929 | + $currency_symbol_placement = isset($cs['currency_symbol_placement']) ? $cs['currency_symbol_placement'] : 'left'; | |
| 1024 | 930 | |
| 1025 | - if($decimals>0 && $decimal_display=='if'){ | |
| 1026 | - if(is_int($number) || floor( $number ) == $number) | |
| 1027 | - $decimals = 0; | |
| 1028 | - } | |
| 931 | + if ($decimals > 0 && $decimal_display == 'if') { | |
| 932 | + if (is_int($number) || floor($number) == $number) | |
| 933 | + $decimals = 0; | |
| 934 | + } | |
| 1029 | 935 | |
| 1030 | - $number = number_format($number,$decimals,$decimalpoint,$separator); | |
| 936 | + $number = number_format($number, $decimals, $decimalpoint, $separator); | |
| 1031 | 937 | |
| 1032 | 938 | |
| 1033 | 939 | |
| 1034 | - if($currency_symbol_placement=='left'){ | |
| 1035 | - $number = $symbol . $number; | |
| 1036 | - }else{ | |
| 1037 | - $number = $number . $symbol; | |
| 1038 | - } | |
| 940 | + if ($currency_symbol_placement == 'left') { | |
| 941 | + $number = $symbol . $number; | |
| 942 | + } else { | |
| 943 | + $number = $number . $symbol; | |
| 944 | + } | |
| 1039 | 945 | |
| 1040 | 946 | |
| 1041 | - return $number; | |
| 947 | + return $number; | |
| 1042 | 948 | } |
| 1043 | 949 | |
| 1044 | 950 | |
| 1045 | 951 | /** |
| @@ -1049,217 +955,83 @@ | ||
| 1049 | 955 | * @package userswp |
| 1050 | 956 | * |
| 1051 | 957 | * @return bool |
| 1052 | 958 | */ |
| 1053 | -function uwp_can_make_profile_private() { | |
| 1054 | - $make_profile_private = apply_filters('uwp_user_can_make_profile_private', false); | |
| 1055 | - return $make_profile_private; | |
| 959 | +function uwp_can_make_profile_private() | |
| 960 | +{ | |
| 961 | + $make_profile_private = apply_filters('uwp_user_can_make_profile_private', false); | |
| 962 | + return $make_profile_private; | |
| 1056 | 963 | } |
| 1057 | 964 | |
| 1058 | 965 | /** |
| 1059 | - * Returns available registration status options. | |
| 966 | + * Returns the installation type. | |
| 1060 | 967 | * |
| 1061 | 968 | * @since 1.0.0 |
| 1062 | 969 | * @package userswp |
| 1063 | 970 | * |
| 1064 | - * @return array Registration status options. | |
| 971 | + * @return string Installation type. | |
| 1065 | 972 | */ |
| 1066 | -function uwp_registration_status_options() { | |
| 1067 | - $registration_options = array( | |
| 1068 | - 'auto_approve' => __('Auto approve', 'userswp'), | |
| 1069 | - 'auto_approve_login' => __('Auto approve + Auto Login', 'userswp'), | |
| 1070 | - 'require_email_activation' => __('Require Email Activation', 'userswp'), | |
| 1071 | - ); | |
| 973 | +function uwp_get_installation_type() | |
| 974 | +{ | |
| 975 | + // *. Single Site | |
| 976 | + if (!is_multisite()) { | |
| 977 | + return "single"; | |
| 978 | + } else { | |
| 979 | + // Multisite | |
| 980 | + if (! function_exists('is_plugin_active_for_network')) { | |
| 981 | + require_once(ABSPATH . '/wp-admin/includes/plugin.php'); | |
| 982 | + } | |
| 1072 | 983 | |
| 1073 | - $registration_options = apply_filters('uwp_registration_status_options', $registration_options); | |
| 1074 | - | |
| 1075 | - return $registration_options; | |
| 984 | + // Network active. | |
| 985 | + if (is_plugin_active_for_network('userswp/userswp.php')) { | |
| 986 | + if (defined('UWP_ROOT_PAGES')) { | |
| 987 | + if (UWP_ROOT_PAGES == 'all') { | |
| 988 | + // *. Multisite - Network Active - Pages on all sites | |
| 989 | + return "multi_na_all"; | |
| 990 | + } else { | |
| 991 | + // *. Multisite - Network Active - Pages on specific site | |
| 992 | + return "multi_na_site_id"; | |
| 993 | + } | |
| 994 | + } else { | |
| 995 | + // Multi - network active - default | |
| 996 | + // *. Multisite - Network Active - Pages on main site | |
| 997 | + return "multi_na_default"; | |
| 998 | + } | |
| 999 | + } else { | |
| 1000 | + // * Multisite - Not network active | |
| 1001 | + return "multi_not_na"; | |
| 1002 | + } | |
| 1003 | + } | |
| 1076 | 1004 | } |
| 1077 | 1005 | |
| 1078 | 1006 | /** |
| 1079 | - * Retrieves a user row based on password reset key and login | |
| 1007 | + * Returns the table prefix based on the installation type. | |
| 1080 | 1008 | * |
| 1081 | 1009 | * @since 1.0.0 |
| 1082 | 1010 | * @package userswp |
| 1083 | 1011 | * |
| 1084 | - * @param string $key Hash to validate sending user's password. | |
| 1085 | - * @param string $login The user login. | |
| 1086 | - * | |
| 1087 | - * @return WP_Error|WP_User User object. | |
| 1012 | + * @return string Table prefix | |
| 1088 | 1013 | */ |
| 1089 | -function uwp_check_activation_key( $key, $login ) { | |
| 1090 | - $user_data = check_password_reset_key( $key, $login ); | |
| 1091 | - | |
| 1092 | - return $user_data; | |
| 1014 | +function uwp_get_table_prefix() | |
| 1015 | +{ | |
| 1016 | + $tables = new UsersWP_Tables(); | |
| 1017 | + return $tables->get_table_prefix(); | |
| 1093 | 1018 | } |
| 1094 | 1019 | |
| 1095 | - | |
| 1096 | -add_action('uwp_template_fields', 'uwp_template_fields_terms_check', 100, 1); | |
| 1097 | - | |
| 1098 | 1020 | /** |
| 1099 | - * Adds "Accept terms and conditions" checkbox in register form. | |
| 1100 | - * | |
| 1101 | - * @since 1.0.0 | |
| 1102 | - * @package userswp | |
| 1103 | - * | |
| 1104 | - * @param string $form_type Form type. | |
| 1105 | - * | |
| 1106 | - * @return void | |
| 1107 | - */ | |
| 1108 | -function uwp_template_fields_terms_check($form_type) { | |
| 1109 | - if ($form_type == 'register') { | |
| 1110 | - $terms_page = false; | |
| 1111 | - $reg_terms_page_id = uwp_get_page_id('register_terms_page', false); | |
| 1112 | - $reg_terms_page_id = apply_filters('uwp_reg_terms_page_id', $reg_terms_page_id); | |
| 1113 | - if (!empty($reg_terms_page_id)) { | |
| 1114 | - $terms_page = get_permalink($reg_terms_page_id); | |
| 1115 | - } | |
| 1116 | - if ($terms_page) { | |
| 1117 | - ?> | |
| 1118 | - <div class="uwp-remember-me"> | |
| 1119 | - <label style="display: inline-block;font-weight: normal" for="agree_terms"> | |
| 1120 | - <input name="agree_terms" id="agree_terms" value="yes" type="checkbox"> | |
| 1121 | - <?php echo sprintf( __( 'I Accept <a href="%s" target="_blank">Terms and Conditions</a>.', 'userswp' ), $terms_page); ?> | |
| 1122 | - </label> | |
| 1123 | - </div> | |
| 1124 | - <?php | |
| 1125 | - } | |
| 1126 | - } | |
| 1127 | -} | |
| 1128 | - | |
| 1129 | - | |
| 1130 | - | |
| 1131 | -/** | |
| 1132 | - * Redirects the user to login page when email not confirmed. | |
| 1133 | - * | |
| 1134 | - * @since 1.0.0 | |
| 1135 | - * @package userswp | |
| 1136 | - * | |
| 1137 | - * @param string $username Username. | |
| 1138 | - * @param object $user User object. | |
| 1139 | - * | |
| 1140 | - * @return void | |
| 1141 | - */ | |
| 1142 | -function uwp_unconfirmed_login_redirect( $username, $user ) { | |
| 1143 | - if (!is_wp_error($user)) { | |
| 1144 | - $mod_value = get_user_meta( $user->ID, 'uwp_mod', true ); | |
| 1145 | - if ($mod_value == 'email_unconfirmed') { | |
| 1146 | - if ( !in_array( 'administrator', $user->roles ) ) { | |
| 1147 | - $login_page = uwp_get_page_id('login_page', false); | |
| 1148 | - if ($login_page) { | |
| 1149 | - $redirect_to = add_query_arg(array('uwp_err' => 'act_pending'), get_permalink($login_page)); | |
| 1150 | - wp_destroy_current_session(); | |
| 1151 | - wp_clear_auth_cookie(); | |
| 1152 | - wp_redirect($redirect_to); | |
| 1153 | - exit(); | |
| 1154 | - } | |
| 1155 | - } | |
| 1156 | - } | |
| 1157 | - } | |
| 1158 | -} | |
| 1159 | -add_filter( 'wp_login', 'uwp_unconfirmed_login_redirect', 10, 2 ); | |
| 1160 | - | |
| 1161 | -/** | |
| 1162 | - * Adds notification menu in admin toolbar. | |
| 1163 | - * | |
| 1164 | - * @since 1.0.0 | |
| 1165 | - * @package userswp | |
| 1166 | - * | |
| 1167 | - * @return void | |
| 1168 | - */ | |
| 1169 | -function uwp_notifications_toolbar_menu() { | |
| 1170 | - global $wp_admin_bar; | |
| 1171 | - | |
| 1172 | - if ( ! is_user_logged_in() ) { | |
| 1173 | - return; | |
| 1174 | - } | |
| 1175 | - | |
| 1176 | - $available_counts = apply_filters('uwp_notifications_available_counts', array()); | |
| 1177 | - | |
| 1178 | - if (count($available_counts) == 0) { | |
| 1179 | - return; | |
| 1180 | - } | |
| 1181 | - | |
| 1182 | - $total_count = 0; | |
| 1183 | - foreach ($available_counts as $key => $value) { | |
| 1184 | - $total_count = $total_count + $value; | |
| 1185 | - } | |
| 1186 | - | |
| 1187 | - | |
| 1188 | - $alert_class = (int) $total_count > 0 ? 'pending-count' : 'count'; | |
| 1189 | - $menu_title = '<span id="uwp-notification-count" class="' . $alert_class . '">' | |
| 1190 | - . number_format_i18n( $total_count ) . '</span>'; | |
| 1191 | - $menu_link = ''; | |
| 1192 | - | |
| 1193 | - // Add the top-level Notifications button. | |
| 1194 | - $wp_admin_bar->add_menu( array( | |
| 1195 | - 'parent' => 'top-secondary', | |
| 1196 | - 'id' => 'uwp-notifications', | |
| 1197 | - 'title' => $menu_title, | |
| 1198 | - 'href' => $menu_link, | |
| 1199 | - ) ); | |
| 1200 | - | |
| 1201 | - do_action('uwp_notifications_items', $wp_admin_bar); | |
| 1202 | - | |
| 1203 | - return; | |
| 1204 | -} | |
| 1205 | -add_action( 'admin_bar_menu', 'uwp_notifications_toolbar_menu', 90 ); | |
| 1206 | - | |
| 1207 | -/** | |
| 1208 | - * Returns the installation type. | |
| 1209 | - * | |
| 1210 | - * @since 1.0.0 | |
| 1211 | - * @package userswp | |
| 1212 | - * | |
| 1213 | - * @return string Installation type. | |
| 1214 | - */ | |
| 1215 | -function uwp_get_installation_type() { | |
| 1216 | - // *. Single Site | |
| 1217 | - if (!is_multisite()) { | |
| 1218 | - return "single"; | |
| 1219 | - } else { | |
| 1220 | - // Multisite | |
| 1221 | - if ( ! function_exists( 'is_plugin_active_for_network' ) ) { | |
| 1222 | - require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); | |
| 1223 | - } | |
| 1224 | - | |
| 1225 | - // Network active. | |
| 1226 | - if ( is_plugin_active_for_network( 'userswp/userswp.php' ) ) { | |
| 1227 | - if (defined('UWP_ROOT_PAGES')) { | |
| 1228 | - if (UWP_ROOT_PAGES == 'all') { | |
| 1229 | - // *. Multisite - Network Active - Pages on all sites | |
| 1230 | - return "multi_na_all"; | |
| 1231 | - } else { | |
| 1232 | - // *. Multisite - Network Active - Pages on specific site | |
| 1233 | - return "multi_na_site_id"; | |
| 1234 | - } | |
| 1235 | - } else { | |
| 1236 | - // Multi - network active - default | |
| 1237 | - // *. Multisite - Network Active - Pages on main site | |
| 1238 | - return "multi_na_default"; | |
| 1239 | - } | |
| 1240 | - } else { | |
| 1241 | - // * Multisite - Not network active | |
| 1242 | - return "multi_not_na"; | |
| 1243 | - } | |
| 1244 | - } | |
| 1245 | -} | |
| 1246 | - | |
| 1247 | -/** | |
| 1248 | 1021 | * Returns the table prefix based on the installation type. |
| 1249 | 1022 | * |
| 1250 | - * @since 1.0.0 | |
| 1023 | + * @since 1.0.16 | |
| 1251 | 1024 | * @package userswp |
| 1252 | 1025 | * |
| 1253 | 1026 | * @return string Table prefix |
| 1254 | 1027 | */ |
| 1255 | -function uwp_get_table_prefix() { | |
| 1256 | - $tables = new UsersWP_Tables(); | |
| 1257 | - return $tables->get_table_prefix(); | |
| 1028 | +function get_usermeta_table_prefix() | |
| 1029 | +{ | |
| 1030 | + $tables = new UsersWP_Tables(); | |
| 1031 | + return $tables->get_usermeta_table_prefix(); | |
| 1258 | 1032 | } |
| 1259 | 1033 | |
| 1260 | - | |
| 1261 | - | |
| 1262 | 1034 | /** |
| 1263 | 1035 | * Converts array to comma separated string. |
| 1264 | 1036 | * |
| 1265 | 1037 | * |
| @@ -1270,14 +1042,15 @@ | ||
| 1270 | 1042 | * @param string $value Custom field value. |
| 1271 | 1043 | * |
| 1272 | 1044 | * @return string Converted custom field value string. |
| 1273 | 1045 | */ |
| 1274 | -function uwp_maybe_serialize($key, $value) { | |
| 1275 | - $field = uwp_get_custom_field_info($key); | |
| 1276 | - if (isset($field->field_type) && $field->field_type == 'multiselect') { | |
| 1277 | - $value = implode(",", $value); | |
| 1278 | - } | |
| 1279 | - return $value; | |
| 1046 | +function uwp_maybe_serialize($key, $value) | |
| 1047 | +{ | |
| 1048 | + $field = uwp_get_custom_field_info($key); | |
| 1049 | + if (isset($field->field_type) && $field->field_type == 'multiselect' && is_array($value)) { | |
| 1050 | + $value = implode(",", $value); | |
| 1051 | + } | |
| 1052 | + return $value; | |
| 1280 | 1053 | } |
| 1281 | 1054 | |
| 1282 | 1055 | /** |
| 1283 | 1056 | * Converts comma separated string to array. |
| @@ -1289,14 +1062,15 @@ | ||
| 1289 | 1062 | * @param string $value Custom field value. |
| 1290 | 1063 | * |
| 1291 | 1064 | * @return array Converted custom field value array. |
| 1292 | 1065 | */ |
| 1293 | -function uwp_maybe_unserialize($key, $value) { | |
| 1294 | - $field = uwp_get_custom_field_info($key); | |
| 1295 | - if (isset($field->field_type) && $field->field_type == 'multiselect') { | |
| 1296 | - $value = explode(",", $value); | |
| 1297 | - } | |
| 1298 | - return $value; | |
| 1066 | +function uwp_maybe_unserialize($key, $value) | |
| 1067 | +{ | |
| 1068 | + $field = uwp_get_custom_field_info($key); | |
| 1069 | + if (isset($field->field_type) && $field->field_type == 'multiselect' && $value) { | |
| 1070 | + $value = explode(",", $value); | |
| 1071 | + } | |
| 1072 | + return $value; | |
| 1299 | 1073 | } |
| 1300 | 1074 | |
| 1301 | 1075 | /** |
| 1302 | 1076 | * Creates UsersWP related tables. |
| @@ -1307,26 +1081,13 @@ | ||
| 1307 | 1081 | * @return void |
| 1308 | 1082 | */ |
| 1309 | 1083 | function uwp_create_tables() |
| 1310 | 1084 | { |
| 1311 | - $tables = new UsersWP_Tables(); | |
| 1312 | - $tables->uwp_create_tables(); | |
| 1085 | + $tables = new UsersWP_Tables(); | |
| 1086 | + $tables->create_tables(); | |
| 1313 | 1087 | } |
| 1314 | 1088 | |
| 1315 | 1089 | /** |
| 1316 | - * Creates uwp_usermeta table which introduced in version 1.0.1 | |
| 1317 | - * | |
| 1318 | - * @since 1.0.0 | |
| 1319 | - * @package userswp | |
| 1320 | - * | |
| 1321 | - * @return void | |
| 1322 | - */ | |
| 1323 | -function uwp101_create_tables() { | |
| 1324 | - $tables = new UsersWP_Tables(); | |
| 1325 | - $tables->uwp101_create_tables(); | |
| 1326 | -} | |
| 1327 | - | |
| 1328 | -/** | |
| 1329 | 1090 | * Returns tye client IP. |
| 1330 | 1091 | * |
| 1331 | 1092 | * @since 1.0.0 |
| 1332 | 1093 | * @package userswp |
| @@ -1332,20 +1093,21 @@ | ||
| 1332 | 1093 | * @package userswp |
| 1333 | 1094 | * |
| 1334 | 1095 | * @return string IP address. |
| 1335 | 1096 | */ |
| 1336 | -function uwp_get_ip() { | |
| 1337 | - if (!empty($_SERVER['HTTP_CLIENT_IP'])) { | |
| 1338 | - //check ip from share internet | |
| 1339 | - $ip = $_SERVER['HTTP_CLIENT_IP']; | |
| 1340 | - } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
| 1341 | - //to check ip is pass from proxy | |
| 1342 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| 1343 | - } else { | |
| 1344 | - $ip = $_SERVER['REMOTE_ADDR']; | |
| 1345 | - } | |
| 1097 | +function uwp_get_ip() | |
| 1098 | +{ | |
| 1099 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { | |
| 1100 | + //check ip from share internet | |
| 1101 | + $ip = $_SERVER['HTTP_CLIENT_IP']; | |
| 1102 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
| 1103 | + //to check ip is pass from proxy | |
| 1104 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| 1105 | + } else { | |
| 1106 | + $ip = $_SERVER['REMOTE_ADDR']; | |
| 1107 | + } | |
| 1346 | 1108 | |
| 1347 | - return apply_filters('uwp_get_ip', $ip); | |
| 1109 | + return apply_filters('uwp_get_ip', $ip); | |
| 1348 | 1110 | } |
| 1349 | 1111 | |
| 1350 | 1112 | /** |
| 1351 | 1113 | * Checks whether the string starts with the given string. |
| @@ -1359,10 +1121,10 @@ | ||
| 1359 | 1121 | * @return bool True when success. False when failure. |
| 1360 | 1122 | */ |
| 1361 | 1123 | function uwp_str_starts_with($haystack, $needle) |
| 1362 | 1124 | { |
| 1363 | - $length = strlen($needle); | |
| 1364 | - return (substr($haystack, 0, $length) === $needle); | |
| 1125 | + $length = strlen($needle); | |
| 1126 | + return (substr($haystack, 0, $length) === $needle); | |
| 1365 | 1127 | } |
| 1366 | 1128 | |
| 1367 | 1129 | /** |
| 1368 | 1130 | * Checks whether the string ends with the given string. |
| @@ -1376,18 +1138,18 @@ | ||
| 1376 | 1138 | * @return bool True when success. False when failure. |
| 1377 | 1139 | */ |
| 1378 | 1140 | function uwp_str_ends_with($haystack, $needle) |
| 1379 | 1141 | { |
| 1380 | - $length = strlen($needle); | |
| 1381 | - if ($length == 0) { | |
| 1382 | - return true; | |
| 1383 | - } | |
| 1142 | + $length = strlen($needle); | |
| 1143 | + if ($length == 0) { | |
| 1144 | + return true; | |
| 1145 | + } | |
| 1384 | 1146 | |
| 1385 | - return (substr($haystack, -$length) === $needle); | |
| 1147 | + return (substr($haystack, -$length) === $needle); | |
| 1386 | 1148 | } |
| 1387 | 1149 | |
| 1388 | 1150 | /** |
| 1389 | - * Returns the font awesome icon value for field type. | |
| 1151 | + * Returns the font awesome icon value for field type. | |
| 1390 | 1152 | * Displayed in profile tabs. |
| 1391 | 1153 | * |
| 1392 | 1154 | * @since 1.0.0 |
| 1393 | 1155 | * @package userswp |
| @@ -1395,30 +1157,30 @@ | ||
| 1395 | 1157 | * @param string $type Field type. |
| 1396 | 1158 | * |
| 1397 | 1159 | * @return string Font awesome icon value. |
| 1398 | 1160 | */ |
| 1399 | -function uwp_field_type_to_fa_icon($type) { | |
| 1400 | - $field_types = array( | |
| 1401 | - 'text' => 'fa fa-minus', | |
| 1402 | - 'datepicker' => 'fa fa-calendar', | |
| 1403 | - 'textarea' => 'fa fa-bars', | |
| 1404 | - 'time' =>'fa fa-clock-o', | |
| 1405 | - 'checkbox' =>'fa fa-check-square-o', | |
| 1406 | - 'phone' =>'fa fa-phone', | |
| 1407 | - 'radio' =>'fa fa-dot-circle-o', | |
| 1408 | - 'email' =>'fa fa-envelope-o', | |
| 1409 | - 'select' =>'fa fa-caret-square-o-down', | |
| 1410 | - 'multiselect' =>'fa fa-caret-square-o-down', | |
| 1411 | - 'url' =>'fa fa-link', | |
| 1412 | - 'file' =>'fa fa-file' | |
| 1413 | - ); | |
| 1161 | +function uwp_field_type_to_fa_icon($type) | |
| 1162 | +{ | |
| 1163 | + $field_types = array( | |
| 1164 | + 'text' => 'fas fa-minus', | |
| 1165 | + 'datepicker' => 'fas fa-calendar-alt', | |
| 1166 | + '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' | |
| 1176 | + ); | |
| 1414 | 1177 | |
| 1415 | - if (isset($field_types[$type])) { | |
| 1416 | - return $field_types[$type]; | |
| 1417 | - } else { | |
| 1418 | - return ""; | |
| 1419 | - } | |
| 1420 | - | |
| 1178 | + if (isset($field_types[$type])) { | |
| 1179 | + return $field_types[$type]; | |
| 1180 | + } else { | |
| 1181 | + return ""; | |
| 1182 | + } | |
| 1421 | 1183 | } |
| 1422 | 1184 | |
| 1423 | 1185 | /** |
| 1424 | 1186 | * Check wpml active or not. |
| @@ -1426,14 +1188,15 @@ | ||
| 1426 | 1188 | * @since 1.0.7 |
| 1427 | 1189 | * |
| 1428 | 1190 | * @return True if WPML is active else False. |
| 1429 | 1191 | */ |
| 1430 | -function uwp_is_wpml() { | |
| 1431 | - if (class_exists('SitePress') && function_exists('icl_object_id')) { | |
| 1432 | - return true; | |
| 1433 | - } | |
| 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; | |
| 1196 | + } | |
| 1434 | 1197 | |
| 1435 | - return false; | |
| 1198 | + return false; | |
| 1436 | 1199 | } |
| 1437 | 1200 | |
| 1438 | 1201 | /** |
| 1439 | 1202 | * Get the element in the WPML current language. |
| @@ -1449,50 +1212,914 @@ | ||
| 1449 | 1212 | * the original if the translation is missing and $return_original_if_missing is set to TRUE. |
| 1450 | 1213 | * |
| 1451 | 1214 | * @return int|NULL |
| 1452 | 1215 | */ |
| 1453 | -function uwp_wpml_object_id( $element_id, $element_type = 'post', $return_original_if_missing = false, $ulanguage_code = null ) { | |
| 1454 | - if ( uwp_is_wpml() ) { | |
| 1455 | - if ( function_exists( 'wpml_object_id_filter' ) ) { | |
| 1456 | - return apply_filters( 'wpml_object_id', $element_id, $element_type, $return_original_if_missing, $ulanguage_code ); | |
| 1457 | - } else { | |
| 1458 | - return icl_object_id( $element_id, $element_type, $return_original_if_missing, $ulanguage_code ); | |
| 1459 | - } | |
| 1460 | - } | |
| 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); | |
| 1221 | + } else { | |
| 1222 | + return icl_object_id($element_id, $element_type, $return_original_if_missing, $ulanguage_code); | |
| 1223 | + } | |
| 1224 | + } | |
| 1461 | 1225 | |
| 1462 | - return $element_id; | |
| 1226 | + return $element_id; | |
| 1463 | 1227 | } |
| 1464 | 1228 | |
| 1465 | -function uwp_get_default_avatar_uri(){ | |
| 1466 | - $default = uwp_get_option('profile_default_profile', ''); | |
| 1467 | - if(empty($default)){ | |
| 1468 | - $default = USERSWP_PLUGIN_URL."public/assets/images/no_profile.png"; | |
| 1469 | - } else { | |
| 1470 | - $default = wp_get_attachment_url($default); | |
| 1471 | - } | |
| 1229 | +/** | |
| 1230 | + * Check if we might be on localhost. | |
| 1231 | + * | |
| 1232 | + * @return bool | |
| 1233 | + */ | |
| 1234 | +function uwp_is_localhost() | |
| 1235 | +{ | |
| 1236 | + $localhost = false; | |
| 1472 | 1237 | |
| 1473 | - return $default; | |
| 1238 | + if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'localhost') { | |
| 1239 | + $localhost = true; | |
| 1240 | + } elseif (isset($_SERVER['SERVER_ADDR']) && ($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] == '::1')) { | |
| 1241 | + $localhost = true; | |
| 1242 | + } | |
| 1243 | + | |
| 1244 | + return $localhost; | |
| 1474 | 1245 | } |
| 1475 | 1246 | |
| 1476 | -function uwp_refresh_permalinks_on_bad_404() { | |
| 1247 | +function uwp_get_default_avatar_uri() | |
| 1248 | +{ | |
| 1249 | + $default = uwp_get_option('profile_default_profile', ''); | |
| 1250 | + if (empty($default)) { | |
| 1251 | + $default = USERSWP_PLUGIN_URL . "assets/images/no_profile.png"; | |
| 1252 | + } else { | |
| 1253 | + $default = wp_get_attachment_url($default); | |
| 1254 | + } | |
| 1477 | 1255 | |
| 1478 | - global $wp; | |
| 1256 | + return apply_filters('uwp_default_avatar_uri', $default); | |
| 1257 | +} | |
| 1479 | 1258 | |
| 1480 | - if( ! is_404() ) { | |
| 1481 | - return; | |
| 1482 | - } | |
| 1259 | +function uwp_get_default_thumb_uri() | |
| 1260 | +{ | |
| 1261 | + $thumb_url = USERSWP_PLUGIN_URL . "assets/images/no_thumb.png"; | |
| 1262 | + return apply_filters('uwp_default_thumb_uri', $thumb_url); | |
| 1263 | +} | |
| 1483 | 1264 | |
| 1484 | - if( isset( $_GET['uwp-flush'] ) ) { | |
| 1485 | - return; | |
| 1486 | - } | |
| 1265 | +function uwp_get_default_banner_uri() | |
| 1266 | +{ | |
| 1267 | + $banner = uwp_get_option('profile_default_banner', ''); | |
| 1268 | + if (empty($banner)) { | |
| 1269 | + $banner_url = USERSWP_PLUGIN_URL . "assets/images/banner.png"; | |
| 1270 | + } else { | |
| 1271 | + $banner_url = wp_get_attachment_url($banner); | |
| 1272 | + } | |
| 1273 | + return apply_filters('uwp_default_banner_uri', $banner_url); | |
| 1274 | +} | |
| 1487 | 1275 | |
| 1488 | - if( false === get_transient( 'uwp_refresh_404_permalinks' ) ) { | |
| 1276 | +/** | |
| 1277 | + * Handles multisite upload dir path | |
| 1278 | + * | |
| 1279 | + * @param $uploads array upload variable array | |
| 1280 | + * | |
| 1281 | + * @return array updated upload variable array. | |
| 1282 | + */ | |
| 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'); | |
| 1287 | + } | |
| 1489 | 1288 | |
| 1490 | - flush_rewrite_rules( false ); | |
| 1289 | + // Network active. | |
| 1290 | + if (is_plugin_active_for_network('userswp/userswp.php')) { | |
| 1291 | + $main_site = get_network()->site_id; | |
| 1292 | + switch_to_blog($main_site); | |
| 1293 | + remove_filter('upload_dir', 'uwp_handle_multisite_profile_image'); | |
| 1294 | + $uploads = wp_upload_dir(); | |
| 1295 | + restore_current_blog(); | |
| 1296 | + } | |
| 1491 | 1297 | |
| 1492 | - set_transient( 'uwp_refresh_404_permalinks', 1, HOUR_IN_SECONDS * 12 ); | |
| 1298 | + return $uploads; | |
| 1299 | +} | |
| 1493 | 1300 | |
| 1494 | - wp_redirect( home_url( add_query_arg( array( 'uwp-flush' => 1 ), $wp->request ) ) ); exit; | |
| 1301 | +/** | |
| 1302 | + * let_to_num function. | |
| 1303 | + * | |
| 1304 | + * This function transforms the php.ini notation for numbers (like '2M') to an integer. | |
| 1305 | + * | |
| 1306 | + * @since 2.0.0 | |
| 1307 | + * @param $size | |
| 1308 | + * @return int | |
| 1309 | + */ | |
| 1310 | +function uwp_let_to_num($size) | |
| 1311 | +{ | |
| 1312 | + $l = substr($size, -1); | |
| 1313 | + $ret = substr($size, 0, -1); | |
| 1314 | + switch (strtoupper($l)) { | |
| 1315 | + case 'P': | |
| 1316 | + $ret *= 1024; | |
| 1317 | + case 'T': | |
| 1318 | + $ret *= 1024; | |
| 1319 | + case 'G': | |
| 1320 | + $ret *= 1024; | |
| 1321 | + case 'M': | |
| 1322 | + $ret *= 1024; | |
| 1323 | + case 'K': | |
| 1324 | + $ret *= 1024; | |
| 1325 | + } | |
| 1326 | + return $ret; | |
| 1327 | +} | |
| 1495 | 1328 | |
| 1496 | - } | |
| 1329 | +function uwp_format_decimal($number, $dp = false, $trim_zeros = false) | |
| 1330 | +{ | |
| 1331 | + $locale = localeconv(); | |
| 1332 | + $decimals = array(uwp_get_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point']); | |
| 1333 | + | |
| 1334 | + // Remove locale from string. | |
| 1335 | + if (! is_float($number)) { | |
| 1336 | + $number = str_replace($decimals, '.', $number); | |
| 1337 | + $number = preg_replace('/[^0-9\.,-]/', '', uwp_clean($number)); | |
| 1338 | + } | |
| 1339 | + | |
| 1340 | + if (false !== $dp) { | |
| 1341 | + $dp = intval('' == $dp ? uwp_get_decimal_separator() : $dp); | |
| 1342 | + $number = number_format(floatval($number), $dp, '.', ''); | |
| 1343 | + // DP is false - don't use number format, just return a string in our format | |
| 1344 | + } elseif (is_float($number)) { | |
| 1345 | + // 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)); | |
| 1347 | + // We already had a float, so trailing zeros are not needed. | |
| 1348 | + $trim_zeros = true; | |
| 1349 | + } | |
| 1350 | + | |
| 1351 | + if ($trim_zeros && strstr($number, '.')) { | |
| 1352 | + $number = rtrim(rtrim($number, '0'), '.'); | |
| 1353 | + } | |
| 1354 | + | |
| 1355 | + return $number; | |
| 1497 | 1356 | } |
| 1498 | -add_action( 'template_redirect', 'uwp_refresh_permalinks_on_bad_404' ); | |
| 1357 | + | |
| 1358 | +/** | |
| 1359 | + * Return the decimal separator. | |
| 1360 | + * @since 1.0.20 | |
| 1361 | + * @return string | |
| 1362 | + */ | |
| 1363 | +function uwp_get_decimal_separator() | |
| 1364 | +{ | |
| 1365 | + $separator = apply_filters('uwp_decimal_separator', '.'); | |
| 1366 | + return $separator ? stripslashes($separator) : '.'; | |
| 1367 | +} | |
| 1368 | + | |
| 1369 | +/** | |
| 1370 | + * Get rounding precision for internal UWP calculations. | |
| 1371 | + * Will increase the precision of uwp_get_decimal_separator by 2 decimals, unless UWP_ROUNDING_PRECISION is set to a higher number. | |
| 1372 | + * | |
| 1373 | + * @since 1.0.20 | |
| 1374 | + * @return int | |
| 1375 | + */ | |
| 1376 | +function uwp_get_rounding_precision() | |
| 1377 | +{ | |
| 1378 | + $precision = uwp_get_decimal_separator() + 2; | |
| 1379 | + if (defined(UWP_ROUNDING_PRECISION) && absint(UWP_ROUNDING_PRECISION) > $precision) { | |
| 1380 | + $precision = absint(UWP_ROUNDING_PRECISION); | |
| 1381 | + } | |
| 1382 | + return $precision; | |
| 1383 | +} | |
| 1384 | + | |
| 1385 | +/** | |
| 1386 | + * Clean variables using sanitize_text_field. Arrays are cleaned recursively. | |
| 1387 | + * Non-scalar values are ignored. | |
| 1388 | + * | |
| 1389 | + * @param string|array $var | |
| 1390 | + * | |
| 1391 | + * @return string|array | |
| 1392 | + */ | |
| 1393 | +function uwp_clean($var) | |
| 1394 | +{ | |
| 1395 | + | |
| 1396 | + if (is_array($var)) { | |
| 1397 | + return array_map('uwp_clean', $var); | |
| 1398 | + } else { | |
| 1399 | + return is_scalar($var) ? sanitize_text_field($var) : $var; | |
| 1400 | + } | |
| 1401 | +} | |
| 1402 | + | |
| 1403 | +/** | |
| 1404 | + * Define a constant if it is not already defined. | |
| 1405 | + * | |
| 1406 | + * @since 1.0.21 | |
| 1407 | + * | |
| 1408 | + * @param string $name Constant name. | |
| 1409 | + * @param string $value Value. | |
| 1410 | + */ | |
| 1411 | +function uwp_maybe_define($name, $value) | |
| 1412 | +{ | |
| 1413 | + if (! defined($name)) { | |
| 1414 | + define($name, $value); | |
| 1415 | + } | |
| 1416 | +} | |
| 1417 | + | |
| 1418 | +function uwp_insert_usermeta() | |
| 1419 | +{ | |
| 1420 | + global $wpdb; | |
| 1421 | + $sort = "user_registered"; | |
| 1422 | + | |
| 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 | + )); | |
| 1427 | + | |
| 1428 | + //we got all the IDs, now loop through them to get individual IDs | |
| 1429 | + foreach ($all_users_id as $user_id) { | |
| 1430 | + $user_data = get_userdata($user_id); | |
| 1431 | + | |
| 1432 | + $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta'; | |
| 1433 | + $user_meta = array( | |
| 1434 | + 'username' => $user_data->user_login, | |
| 1435 | + 'email' => sanitize_email($user_data->user_email), | |
| 1436 | + 'first_name' => $user_data->first_name, | |
| 1437 | + 'last_name' => $user_data->last_name, | |
| 1438 | + 'display_name' => $user_data->display_name, | |
| 1439 | + ); | |
| 1440 | + | |
| 1441 | + $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 | + | |
| 1443 | + if (!empty($users)) { | |
| 1444 | + $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 1445 | + $meta_table, | |
| 1446 | + $user_meta, | |
| 1447 | + array('user_id' => $user_id) | |
| 1448 | + ); | |
| 1449 | + } else { | |
| 1450 | + $user_meta['user_id'] = $user_id; | |
| 1451 | + $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 1452 | + $meta_table, | |
| 1453 | + $user_meta | |
| 1454 | + ); | |
| 1455 | + } | |
| 1456 | + } | |
| 1457 | +} | |
| 1458 | + | |
| 1459 | +function uwp_get_localize_data() | |
| 1460 | +{ | |
| 1461 | + $pass_msg = uwp_get_option("register_uwp_strong_pass_msg"); | |
| 1462 | + $uwp_localize_data = array( | |
| 1463 | + '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'), | |
| 1468 | + 'uwp_more_ellipses_text' => '...', | |
| 1469 | + '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"), | |
| 1475 | + 'default_banner' => uwp_get_default_banner_uri(), | |
| 1476 | + 'basicNonce' => esc_attr(wp_create_nonce('uwp_basic_nonce')), | |
| 1477 | + 'wordfence_2fa_active' => ( class_exists( '\WordfenceLS\Controller_Users' ) && class_exists( '\WordfenceLS\Controller_TOTP' ) ) ? 1 : '' | |
| 1478 | + ); | |
| 1479 | + | |
| 1480 | + return apply_filters('uwp_localize_data', $uwp_localize_data); | |
| 1481 | +} | |
| 1482 | + | |
| 1483 | +function uwp_is_page_builder() { | |
| 1484 | + if ( | |
| 1485 | + ( isset( $_GET['elementor-preview'] ) && $_GET['elementor-preview'] > 0 ) // elementor | |
| 1486 | + || isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) // divi | |
| 1487 | + || isset( $_REQUEST['fl_builder'] ) // beaver | |
| 1488 | + || ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) // siteorigin | |
| 1489 | + || ! empty( $_REQUEST['cornerstone_preview'] ) // cornerstone | |
| 1490 | + || ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) // fusion builder | |
| 1491 | + || ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) // oxygen | |
| 1492 | + || ( function_exists( 'bricks_is_builder' ) && ( bricks_is_builder() || bricks_is_builder_call() ) ) // Bricks Builder | |
| 1493 | + || ( \function_exists( 'Breakdance\\isRequestFromBuilderIframe' ) && ( \Breakdance\isRequestFromBuilderIframe() || \Breakdance\isRequestFromBuilderSsr() ) ) // Breakdance Builder | |
| 1494 | + || ( function_exists( 'znhg_kallyas_theme_config' ) && ! empty( $_REQUEST['zn_pb_edit'] ) ) // Kallyas theme Zion builder | |
| 1495 | + ) { | |
| 1496 | + return true; // builder. | |
| 1497 | + } | |
| 1498 | + | |
| 1499 | + return false; | |
| 1500 | +} | |
| 1501 | + | |
| 1502 | +/** | |
| 1503 | + * Display a help tip for settings. | |
| 1504 | + * | |
| 1505 | + * @param string $tip Help tip text | |
| 1506 | + * @param bool $allow_html Allow sanitized HTML if true or escape | |
| 1507 | + * | |
| 1508 | + * @return string | |
| 1509 | + */ | |
| 1510 | +function uwp_help_tip($tip, $allow_html = false) | |
| 1511 | +{ | |
| 1512 | + global $aui_bs5; | |
| 1513 | + if ($allow_html) { | |
| 1514 | + $tip = uwp_sanitize_tooltip($tip); | |
| 1515 | + } else { | |
| 1516 | + $tip = esc_attr($tip); | |
| 1517 | + } | |
| 1518 | + | |
| 1519 | + $ml = $aui_bs5 ? 'ms-2 float-end' : 'ml-2 float-right'; | |
| 1520 | + | |
| 1521 | + return '<span class="uwp-help-tip dashicons dashicons-editor-help text-muted ' . $ml . '" title="' . $tip . '" data-bs-toggle="tooltip" data-bs-html="true"></span>'; | |
| 1522 | +} | |
| 1523 | + | |
| 1524 | +/** | |
| 1525 | + * Sanitize a string destined to be a tooltip. | |
| 1526 | + * | |
| 1527 | + * Tooltips are encoded with htmlspecialchars to prevent XSS. Should not be used in conjunction with esc_attr() | |
| 1528 | + * | |
| 1529 | + * @param string $var | |
| 1530 | + * @return string | |
| 1531 | + */ | |
| 1532 | +function uwp_sanitize_tooltip($var) | |
| 1533 | +{ | |
| 1534 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( | |
| 1535 | + 'br' => array(), | |
| 1536 | + 'em' => array(), | |
| 1537 | + 'strong' => array(), | |
| 1538 | + 'small' => array(), | |
| 1539 | + 'span' => array(), | |
| 1540 | + 'ul' => array(), | |
| 1541 | + 'li' => array(), | |
| 1542 | + 'ol' => array(), | |
| 1543 | + 'p' => array(), | |
| 1544 | + ))); | |
| 1545 | +} | |
| 1546 | + | |
| 1547 | +function uwp_all_email_tags($inline = true, $extra_tags = array()) | |
| 1548 | +{ | |
| 1549 | + $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#]'); | |
| 1550 | + | |
| 1551 | + if (is_array($extra_tags) && count($extra_tags) > 0) { | |
| 1552 | + $tags = array_merge($extra_tags, $tags); | |
| 1553 | + } | |
| 1554 | + | |
| 1555 | + $tags = apply_filters('uwp_all_email_tags', $tags); | |
| 1556 | + | |
| 1557 | + if ($inline) { | |
| 1558 | + $tags = '<code>' . implode('</code> <code>', $tags) . '</code>'; | |
| 1559 | + } | |
| 1560 | + | |
| 1561 | + return $tags; | |
| 1562 | +} | |
| 1563 | + | |
| 1564 | +function uwp_wp_new_user_notification_tags($inline = true, $extra_tags = array()) | |
| 1565 | +{ | |
| 1566 | + $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#]',); | |
| 1567 | + | |
| 1568 | + if (is_array($extra_tags) && count($extra_tags) > 0) { | |
| 1569 | + $tags = array_merge($tags, $extra_tags); | |
| 1570 | + } | |
| 1571 | + | |
| 1572 | + $tags = apply_filters('uwp_wp_new_user_notification_email_tags', $tags); | |
| 1573 | + | |
| 1574 | + if ($inline) { | |
| 1575 | + $tags = '<code>' . implode('</code> <code>', $tags) . '</code>'; | |
| 1576 | + } | |
| 1577 | + | |
| 1578 | + return $tags; | |
| 1579 | +} | |
| 1580 | + | |
| 1581 | + | |
| 1582 | +function uwp_delete_account_email_tags($inline = true) | |
| 1583 | +{ | |
| 1584 | + $tags = array('[#site_name#]', '[#site_name_url#]', '[#from_name#]', '[#from_email#]', '[#date_time#]', '[#current_date#]', '[#login_url#]', '[#user_login#]'); | |
| 1585 | + | |
| 1586 | + $tags = apply_filters('uwp_delete_account_email_tags', $tags); | |
| 1587 | + | |
| 1588 | + if ($inline) { | |
| 1589 | + $tags = '<code>' . implode('</code> <code>', $tags) . '</code>'; | |
| 1590 | + } | |
| 1591 | + | |
| 1592 | + return $tags; | |
| 1593 | +} | |
| 1594 | + | |
| 1595 | +function uwp_authbox_tags($inline = true) | |
| 1596 | +{ | |
| 1597 | + global $wpdb; | |
| 1598 | + | |
| 1599 | + $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#]'); | |
| 1600 | + | |
| 1601 | + $tags = apply_filters('uwp_author_box_default_tags', $tags, $inline); | |
| 1602 | + | |
| 1603 | + $table_name = uwp_get_table_prefix() . 'uwp_usermeta'; | |
| 1604 | + | |
| 1605 | + $excluded = uwp_get_excluded_fields(); | |
| 1606 | + | |
| 1607 | + $columns = $wpdb->get_col("show columns from $table_name"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 1608 | + | |
| 1609 | + $extra_tags = array_diff($columns, $excluded); | |
| 1610 | + | |
| 1611 | + if (!empty($extra_tags) && '' != $extra_tags) { | |
| 1612 | + | |
| 1613 | + foreach ($extra_tags as $tag_val) { | |
| 1614 | + $tags[] = '[#' . $tag_val . '#]'; | |
| 1615 | + } | |
| 1616 | + } | |
| 1617 | + | |
| 1618 | + $tags = apply_filters('uwp_all_author_box_tags', $tags); | |
| 1619 | + | |
| 1620 | + if ($inline) { | |
| 1621 | + $tags = '<code>' . implode('</code> <code>', $tags) . '</code>'; | |
| 1622 | + } | |
| 1623 | + | |
| 1624 | + return $tags; | |
| 1625 | +} | |
| 1626 | + | |
| 1627 | +function uwp_get_posttypes() | |
| 1628 | +{ | |
| 1629 | + | |
| 1630 | + $exclude_posts = array('attachment', 'revision', 'nav_menu_item', 'custom_css', 'uwp-post'); | |
| 1631 | + $exclude_posttype = apply_filters('uwp_exclude_register_posttype', $exclude_posts); | |
| 1632 | + | |
| 1633 | + $all_posttyps = get_post_types(array('public' => true,), 'objects'); | |
| 1634 | + | |
| 1635 | + $display_posttypes = array(); | |
| 1636 | + | |
| 1637 | + if (!empty($all_posttyps) && '' != $all_posttyps) { | |
| 1638 | + foreach ($all_posttyps as $pt_keys => $pt_values) { | |
| 1639 | + | |
| 1640 | + if (!in_array($pt_values->name, $exclude_posttype)) { | |
| 1641 | + $display_posttypes[$pt_values->name] = $pt_values->label; | |
| 1642 | + } | |
| 1643 | + } | |
| 1644 | + } | |
| 1645 | + | |
| 1646 | + return $display_posttypes; | |
| 1647 | +} | |
| 1648 | + | |
| 1649 | +function uwp_get_user_by_author_slug() | |
| 1650 | +{ | |
| 1651 | + $url_type = apply_filters('uwp_profile_url_type', 'slug'); | |
| 1652 | + $author_slug = get_query_var('uwp_profile'); | |
| 1653 | + if ($url_type == 'id') { | |
| 1654 | + $user = get_user_by('id', $author_slug); | |
| 1655 | + } else { | |
| 1656 | + $user = get_user_by('slug', $author_slug); | |
| 1657 | + } | |
| 1658 | + | |
| 1659 | + return $user; | |
| 1660 | +} | |
| 1661 | + | |
| 1662 | +function uwp_get_show_in_locations() | |
| 1663 | +{ | |
| 1664 | + $show_in_locations = array( | |
| 1665 | + "[users]" => __("Users Page", 'userswp'), | |
| 1666 | + "[more_info]" => __("More info tab", 'userswp'), | |
| 1667 | + "[profile_side]" => __("Profile side (non bootstrap)", 'userswp'), | |
| 1668 | + "[fieldset]" => __("Fieldset", 'userswp'), | |
| 1669 | + ); | |
| 1670 | + | |
| 1671 | + $show_in_locations = apply_filters('uwp_show_in_locations', $show_in_locations); | |
| 1672 | + | |
| 1673 | + return $show_in_locations; | |
| 1674 | +} | |
| 1675 | + | |
| 1676 | +function uwp_get_displayed_user() | |
| 1677 | +{ | |
| 1678 | + global $uwp_user; | |
| 1679 | + $user = uwp_get_user_by_author_slug(); // for user displayed in profile | |
| 1680 | + | |
| 1681 | + if (!$user && is_user_logged_in()) { | |
| 1682 | + $user = get_userdata(get_current_user_id()); // for user currently logged in | |
| 1683 | + } | |
| 1684 | + | |
| 1685 | + if (isset($uwp_user) && !empty($uwp_user) && $uwp_user instanceof WP_User) { // for user displaying in loop | |
| 1686 | + $user = $uwp_user; | |
| 1687 | + } | |
| 1688 | + | |
| 1689 | + return apply_filters('uwp_get_displayed_user', $user); | |
| 1690 | +} | |
| 1691 | + | |
| 1692 | +function uwp_is_gdv2() | |
| 1693 | +{ | |
| 1694 | + | |
| 1695 | + if (defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION, '2.0.0.0', '>=')) { | |
| 1696 | + return true; | |
| 1697 | + } | |
| 1698 | + | |
| 1699 | + return false; | |
| 1700 | +} | |
| 1701 | + | |
| 1702 | +function uwp_get_blogname() | |
| 1703 | +{ | |
| 1704 | + $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); | |
| 1705 | + | |
| 1706 | + return apply_filters('uwp_get_blogname', $blogname); | |
| 1707 | +} | |
| 1708 | + | |
| 1709 | +/** | |
| 1710 | + * RGB from hex. | |
| 1711 | + * | |
| 1712 | + * @since 1.2.1.3 | |
| 1713 | + * | |
| 1714 | + * @param string $color Color. | |
| 1715 | + * @return array $rgb. | |
| 1716 | + */ | |
| 1717 | +function uwp_rgb_from_hex($color) | |
| 1718 | +{ | |
| 1719 | + $color = str_replace('#', '', $color); | |
| 1720 | + | |
| 1721 | + // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" | |
| 1722 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); | |
| 1723 | + if (empty($color)) { | |
| 1724 | + return NULL; | |
| 1725 | + } | |
| 1726 | + | |
| 1727 | + $color = str_split($color); | |
| 1728 | + | |
| 1729 | + $rgb = array(); | |
| 1730 | + $rgb['R'] = hexdec($color[0] . $color[1]); | |
| 1731 | + $rgb['G'] = hexdec($color[2] . $color[3]); | |
| 1732 | + $rgb['B'] = hexdec($color[4] . $color[5]); | |
| 1733 | + | |
| 1734 | + return $rgb; | |
| 1735 | +} | |
| 1736 | + | |
| 1737 | +/** | |
| 1738 | + * HEX darker. | |
| 1739 | + * | |
| 1740 | + * @since 1.2.1.3 | |
| 1741 | + * | |
| 1742 | + * @param string $color Color. | |
| 1743 | + * @param int $factor Optional. Factor. Default 30. | |
| 1744 | + * @return string $color. | |
| 1745 | + */ | |
| 1746 | +function uwp_hex_darker($color, $factor = 30) | |
| 1747 | +{ | |
| 1748 | + $base = uwp_rgb_from_hex($color); | |
| 1749 | + if (empty($base)) { | |
| 1750 | + return $color; | |
| 1751 | + } | |
| 1752 | + | |
| 1753 | + $color = '#'; | |
| 1754 | + foreach ($base as $k => $v) { | |
| 1755 | + $amount = $v / 100; | |
| 1756 | + $amount = round($amount * $factor); | |
| 1757 | + $new_decimal = $v - $amount; | |
| 1758 | + | |
| 1759 | + $new_hex_component = dechex($new_decimal); | |
| 1760 | + if (strlen($new_hex_component) < 2) { | |
| 1761 | + $new_hex_component = "0" . $new_hex_component; | |
| 1762 | + } | |
| 1763 | + $color .= $new_hex_component; | |
| 1764 | + } | |
| 1765 | + | |
| 1766 | + return $color; | |
| 1767 | +} | |
| 1768 | + | |
| 1769 | +/** | |
| 1770 | + * Hex lighter. | |
| 1771 | + * | |
| 1772 | + * @since 1.2.1.3 | |
| 1773 | + * | |
| 1774 | + * @param string $color Color. | |
| 1775 | + * @param int $factor Optional. factor. Default 30. | |
| 1776 | + * @return string $color. | |
| 1777 | + */ | |
| 1778 | +function uwp_hex_lighter($color, $factor = 30) | |
| 1779 | +{ | |
| 1780 | + $base = uwp_rgb_from_hex($color); | |
| 1781 | + if (empty($base)) { | |
| 1782 | + return $color; | |
| 1783 | + } | |
| 1784 | + | |
| 1785 | + $color = '#'; | |
| 1786 | + | |
| 1787 | + foreach ($base as $k => $v) { | |
| 1788 | + $amount = 255 - $v; | |
| 1789 | + $amount = $amount / 100; | |
| 1790 | + $amount = round($amount * $factor); | |
| 1791 | + $new_decimal = $v + $amount; | |
| 1792 | + | |
| 1793 | + $new_hex_component = dechex($new_decimal); | |
| 1794 | + if (strlen($new_hex_component) < 2) { | |
| 1795 | + $new_hex_component = "0" . $new_hex_component; | |
| 1796 | + } | |
| 1797 | + $color .= $new_hex_component; | |
| 1798 | + } | |
| 1799 | + | |
| 1800 | + return $color; | |
| 1801 | +} | |
| 1802 | + | |
| 1803 | +/** | |
| 1804 | + * Get Light or dark. | |
| 1805 | + * | |
| 1806 | + * @since 1.2.1.3 | |
| 1807 | + * | |
| 1808 | + * @param string $color color. | |
| 1809 | + * @param string $dark Optional. Dark. Default #000000. | |
| 1810 | + * @param string $light Optional. Light. Default #FFFFFF. | |
| 1811 | + * @return string | |
| 1812 | + */ | |
| 1813 | +function uwp_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') | |
| 1814 | +{ | |
| 1815 | + $hex = str_replace('#', '', $color); | |
| 1816 | + if (empty($hex)) { | |
| 1817 | + return $color; | |
| 1818 | + } | |
| 1819 | + | |
| 1820 | + $c_r = hexdec(substr($hex, 0, 2)); | |
| 1821 | + $c_g = hexdec(substr($hex, 2, 2)); | |
| 1822 | + $c_b = hexdec(substr($hex, 4, 2)); | |
| 1823 | + | |
| 1824 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; | |
| 1825 | + | |
| 1826 | + return $brightness > 155 ? $dark : $light; | |
| 1827 | +} | |
| 1828 | + | |
| 1829 | +/** | |
| 1830 | + * Format hex. | |
| 1831 | + * | |
| 1832 | + * @since 1.2.1.3 | |
| 1833 | + * | |
| 1834 | + * @param string $hex hex. | |
| 1835 | + * @return string | |
| 1836 | + */ | |
| 1837 | +function uwp_format_hex($hex) | |
| 1838 | +{ | |
| 1839 | + $hex = trim(str_replace('#', '', $hex)); | |
| 1840 | + if (empty($hex)) { | |
| 1841 | + return NULL; | |
| 1842 | + } | |
| 1843 | + | |
| 1844 | + if (strlen($hex) == 3) { | |
| 1845 | + $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; | |
| 1846 | + } | |
| 1847 | + | |
| 1848 | + return $hex ? '#' . $hex : null; | |
| 1849 | +} | |
| 1850 | + | |
| 1851 | +/** | |
| 1852 | + * Returns activation link for user. | |
| 1853 | + * | |
| 1854 | + * @since 1.2.1.3 | |
| 1855 | + * | |
| 1856 | + * @param int $user_id User ID. | |
| 1857 | + * | |
| 1858 | + * @return string $activation_link | |
| 1859 | + */ | |
| 1860 | +function uwp_get_activation_link($user_id) | |
| 1861 | +{ | |
| 1862 | + | |
| 1863 | + global $wpdb, $wp_hasher; | |
| 1864 | + | |
| 1865 | + if (!$user_id) { | |
| 1866 | + return false; | |
| 1867 | + } | |
| 1868 | + | |
| 1869 | + $user_data = get_userdata($user_id); | |
| 1870 | + | |
| 1871 | + $key = wp_generate_password(20, false); | |
| 1872 | + | |
| 1873 | + do_action('uwp_activation_key', $user_data->user_login, $key); | |
| 1874 | + | |
| 1875 | + if ( function_exists( 'wp_fast_hash' ) ) { | |
| 1876 | + $hashed = wp_fast_hash( $key ); | |
| 1877 | + } else { | |
| 1878 | + if ( empty( $wp_hasher ) ) { | |
| 1879 | + require_once ABSPATH . 'wp-includes/class-phpass.php'; | |
| 1880 | + $wp_hasher = new PasswordHash( 8, true ); | |
| 1881 | + } | |
| 1882 | + $hashed = $wp_hasher->HashPassword( $key ); | |
| 1883 | + } | |
| 1884 | + $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 | |
| 1885 | + update_user_meta($user_id, 'uwp_mod', 'email_unconfirmed'); | |
| 1886 | + | |
| 1887 | + $activation_args = array( | |
| 1888 | + 'uwp_activate' => 'yes', | |
| 1889 | + 'key' => $key, | |
| 1890 | + 'login' => rawurlencode($user_data->user_login) | |
| 1891 | + ); | |
| 1892 | + | |
| 1893 | + $activation_args = apply_filters('uwp_activation_link_args', $activation_args, $user_id, $user_data); | |
| 1894 | + | |
| 1895 | + $activation_link = add_query_arg( | |
| 1896 | + $activation_args, | |
| 1897 | + home_url('/login/') | |
| 1898 | + ); | |
| 1899 | + | |
| 1900 | + return apply_filters('uwp_activation_link', $activation_link, $user_id, $user_data, $activation_args); | |
| 1901 | +} | |
| 1902 | + | |
| 1903 | +/** | |
| 1904 | + * Checks a version number against the core version and adds a admin notice if requirements are not met. | |
| 1905 | + * | |
| 1906 | + * @param $name | |
| 1907 | + * @param $version | |
| 1908 | + * | |
| 1909 | + * @return bool | |
| 1910 | + */ | |
| 1911 | +function uwp_min_version_check($name, $version) | |
| 1912 | +{ | |
| 1913 | + if (version_compare(USERSWP_VERSION, $version, '<')) { | |
| 1914 | + add_action('admin_notices', function () use (&$name) { | |
| 1915 | + ?> | |
| 1916 | + <div class="notice notice-error is-dismissible"> | |
| 1917 | + <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> | |
| 1918 | + </div> | |
| 1919 | +<?php | |
| 1920 | + }); | |
| 1921 | + | |
| 1922 | + return false; | |
| 1923 | + } | |
| 1924 | + | |
| 1925 | + return true; | |
| 1926 | +} | |
| 1927 | + | |
| 1928 | +function uwp_get_user_roles($exclude = array()) | |
| 1929 | +{ | |
| 1930 | + $user_roles = array(); | |
| 1931 | + if (!function_exists('get_editable_roles')) { | |
| 1932 | + require_once(ABSPATH . '/wp-admin/includes/user.php'); | |
| 1933 | + } | |
| 1934 | + | |
| 1935 | + $wp_roles = get_editable_roles(); | |
| 1936 | + if (!empty($wp_roles) && is_array($wp_roles)) { | |
| 1937 | + foreach ($wp_roles as $role => $details) { | |
| 1938 | + if (in_array($role, $exclude)) { | |
| 1939 | + } else { | |
| 1940 | + $user_roles[esc_attr($role)] = !empty($details['name']) ? translate_user_role($details['name']) : $role; | |
| 1941 | + } | |
| 1942 | + } | |
| 1943 | + } | |
| 1944 | + | |
| 1945 | + return $user_roles; | |
| 1946 | +} | |
| 1947 | + | |
| 1948 | +function uwp_get_sort_by_order_list() | |
| 1949 | +{ | |
| 1950 | + | |
| 1951 | + $cache = wp_cache_get("uwp_get_sort_options"); | |
| 1952 | + if ($cache !== false) { | |
| 1953 | + return $cache; | |
| 1954 | + } | |
| 1955 | + | |
| 1956 | + global $wpdb; | |
| 1957 | + $table_name = uwp_get_table_prefix() . 'uwp_user_sorting'; | |
| 1958 | + | |
| 1959 | + $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 | |
| 1960 | + | |
| 1961 | + $sort_options = array(); | |
| 1962 | + | |
| 1963 | + if (! empty($sort_options_raw) && count($sort_options_raw) > 1) { | |
| 1964 | + foreach ($sort_options_raw as $sort) { | |
| 1965 | + $sort = stripslashes_deep($sort); | |
| 1966 | + | |
| 1967 | + $sort->site_title = __(wp_unslash($sort->site_title), 'userswp'); | |
| 1968 | + | |
| 1969 | + if ($sort->htmlvar_name == 'comment_count') { | |
| 1970 | + $sort->htmlvar_name = 'rating_count'; | |
| 1971 | + } | |
| 1972 | + | |
| 1973 | + $key = $sort->htmlvar_name; | |
| 1974 | + if (!in_array($key, array('newer', 'older'))) { | |
| 1975 | + if ($sort->sort == 'asc') { | |
| 1976 | + $key = esc_attr($sort->htmlvar_name . "_asc"); | |
| 1977 | + } elseif ($sort->sort == 'desc') { | |
| 1978 | + $key = esc_attr($sort->htmlvar_name . "_desc"); | |
| 1979 | + } | |
| 1980 | + } | |
| 1981 | + | |
| 1982 | + $sort_options[$key] = wp_unslash($sort->site_title); | |
| 1983 | + } | |
| 1984 | + } | |
| 1985 | + | |
| 1986 | + /** | |
| 1987 | + * Filter post sort options. | |
| 1988 | + * | |
| 1989 | + * @param array $sort_options Unfiltered sort field array. | |
| 1990 | + */ | |
| 1991 | + $sort_options = apply_filters('uwp_available_users_layout', $sort_options); | |
| 1992 | + | |
| 1993 | + wp_cache_set("uwp_get_sort_options", $sort_options); | |
| 1994 | + | |
| 1995 | + return $sort_options; | |
| 1996 | +} | |
| 1997 | + | |
| 1998 | +function uwp_get_default_sort() | |
| 1999 | +{ | |
| 2000 | + | |
| 2001 | + $cache = wp_cache_get("uwp_get_default_sort"); | |
| 2002 | + | |
| 2003 | + if ($cache !== false) { | |
| 2004 | + return $cache; | |
| 2005 | + } | |
| 2006 | + | |
| 2007 | + $default_sort = 'newer_asc'; | |
| 2008 | + | |
| 2009 | + global $wpdb; | |
| 2010 | + $table_name = uwp_get_table_prefix() . 'uwp_user_sorting'; | |
| 2011 | + | |
| 2012 | + $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 | |
| 2013 | + if (! empty($field)) { | |
| 2014 | + if ($field->field_type == 'random') { | |
| 2015 | + $default_sort = 'random'; | |
| 2016 | + } elseif ('newer' == $field->htmlvar_name) { | |
| 2017 | + $default_sort = 'user_registered_desc'; | |
| 2018 | + } elseif ('older' == $field->htmlvar_name) { | |
| 2019 | + $default_sort = 'user_registered_asc'; | |
| 2020 | + } else { | |
| 2021 | + $default_sort = $field->htmlvar_name . '_' . $field->sort; | |
| 2022 | + } | |
| 2023 | + } | |
| 2024 | + | |
| 2025 | + wp_cache_set("uwp_get_default_sort", $default_sort); | |
| 2026 | + | |
| 2027 | + return $default_sort; | |
| 2028 | +} | |
| 2029 | + | |
| 2030 | +function uwp_get_username($user_id) | |
| 2031 | +{ | |
| 2032 | + $user_data = get_userdata($user_id); | |
| 2033 | + | |
| 2034 | + if (! $user_data) { | |
| 2035 | + return ''; | |
| 2036 | + } | |
| 2037 | + | |
| 2038 | + $display_name = ! empty($user_data->display_name) ? $user_data->display_name : $user_data->user_login; | |
| 2039 | + | |
| 2040 | + return apply_filters('uwp_get_username', $display_name, $user_id, $user_data); | |
| 2041 | +} | |
| 2042 | + | |
| 2043 | +/** | |
| 2044 | + * File relative url. | |
| 2045 | + * | |
| 2046 | + * @since 1.2.66 | |
| 2047 | + * | |
| 2048 | + * @param string $url URL. | |
| 2049 | + * @param bool $full_path Optional. Full Path. Default false. | |
| 2050 | + * @return string | |
| 2051 | + */ | |
| 2052 | +function uwp_get_file_relative_url( $url, $full_path = false ) { | |
| 2053 | + $url = trim( $url ); | |
| 2054 | + | |
| 2055 | + if ( !$url ) { | |
| 2056 | + return $url; | |
| 2057 | + } | |
| 2058 | + | |
| 2059 | + $relative_url = $url; | |
| 2060 | + $url = trim( $url, '/\\' ); // clean slashes | |
| 2061 | + | |
| 2062 | + $upload_dir = wp_upload_dir(); | |
| 2063 | + $upload_basedir = $upload_dir['basedir']; | |
| 2064 | + $upload_baseurl = $upload_dir['baseurl']; | |
| 2065 | + $content_dir = untrailingslashit( WP_CONTENT_DIR ); | |
| 2066 | + $content_url = untrailingslashit( WP_CONTENT_URL ); | |
| 2067 | + | |
| 2068 | + if ( strpos( $upload_baseurl, 'https://' ) === 0 ) { | |
| 2069 | + $https = 'https://'; | |
| 2070 | + $match_upload_baseurl = str_replace( 'https://', '', $upload_baseurl ); | |
| 2071 | + $content_url = str_replace( 'http://', 'https://', $content_url ); | |
| 2072 | + } else { | |
| 2073 | + $https = 'http://'; | |
| 2074 | + $match_upload_baseurl = str_replace( 'http://', '', $upload_baseurl ); | |
| 2075 | + $content_url = str_replace( 'https://', 'http://', $content_url ); | |
| 2076 | + } | |
| 2077 | + | |
| 2078 | + $match_content_url = strpos( $content_url, 'https://' ) === 0 ? str_replace( 'https://', '', $content_url ) : str_replace( 'http://', '', $content_url ); | |
| 2079 | + $match_url = strpos( $url, 'https://' ) === 0 ? str_replace( 'https://', '', $url ) : str_replace( 'http://', '', $url ); | |
| 2080 | + | |
| 2081 | + // www. | |
| 2082 | + $www = ''; | |
| 2083 | + if ( strpos( $match_upload_baseurl, 'www.' ) === 0 ) { | |
| 2084 | + $www = 'www.'; | |
| 2085 | + $match_upload_baseurl = str_replace( 'www.', '', $match_upload_baseurl ); | |
| 2086 | + } | |
| 2087 | + if ( strpos( $match_content_url, 'www.' ) === 0 ) { | |
| 2088 | + $match_content_url = str_replace( 'www.', '', $match_content_url ); | |
| 2089 | + } | |
| 2090 | + if ( strpos( $match_url, 'www.' ) === 0 ) { | |
| 2091 | + $match_url = str_replace( 'www.', '', $match_url ); | |
| 2092 | + } | |
| 2093 | + | |
| 2094 | + if ( $full_path ) { | |
| 2095 | + if ( strpos( $relative_url, 'http://' ) === 0 || strpos( $relative_url, 'https://' ) === 0 ) { | |
| 2096 | + if ( strpos( $match_url, $match_upload_baseurl ) === 0 || strpos( $match_url, $match_content_url ) === 0 ) { | |
| 2097 | + $relative_url = $https . $www . $match_url; | |
| 2098 | + } | |
| 2099 | + } else { | |
| 2100 | + if ( is_file( $content_dir . '/' . $match_url ) && file_exists( $content_dir . '/' . $match_url ) ) { // url contains content url | |
| 2101 | + $relative_url = $content_url . '/' . $match_url; | |
| 2102 | + } elseif ( is_file( $upload_basedir . '/' . $match_url ) && file_exists( $upload_basedir . '/' . $match_url ) ) { // url contains content url | |
| 2103 | + $relative_url = $upload_baseurl . '/' . $match_url; | |
| 2104 | + } | |
| 2105 | + } | |
| 2106 | + } else { | |
| 2107 | + if ( substr_count( $match_url, $match_upload_baseurl ) > 1 || substr_count( $match_url, $match_content_url ) > 1 ) { | |
| 2108 | + return ''; | |
| 2109 | + } | |
| 2110 | + | |
| 2111 | + if ( strpos( $match_url, $match_upload_baseurl ) === 0 ) { // url contains uploads baseurl | |
| 2112 | + $relative_url = substr( $match_url, strlen( $match_upload_baseurl ) ); | |
| 2113 | + } elseif ( strpos( $match_url, $match_content_url ) === 0 ) { // url contains content url | |
| 2114 | + $relative_url = substr( $match_url, strlen( $match_content_url ) ); | |
| 2115 | + } | |
| 2116 | + | |
| 2117 | + $relative_url = trim( $relative_url, '/\\' ); | |
| 2118 | + | |
| 2119 | + if ( false !== strpos( $relative_url, '..' ) ) { | |
| 2120 | + return ''; | |
| 2121 | + } | |
| 2122 | + } | |
| 2123 | + | |
| 2124 | + return apply_filters( 'uwp_get_file_relative_url', $relative_url, $url, $full_path ); | |
| 2125 | +} | |