PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.38
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.38
1.2.77 1.2.76 1.2.75 1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 All 177 releases
← All changes | includes/helpers/pages.php +412 -4 1.0.22 → 1.2.38 View file →
@@ -108,17 +108,17 @@
108 108 return $page->is_users_page();
109 109 }
110 110
111 111 /**
112 - * Checks whether the current page is multi register page or not.
112 + * Checks whether the current page is users list item page or not.
113 113 *
114 114 * @since 1.0.0
115 115 * @package userswp
116 116 * @return bool
117 117 */
118 -function is_uwp_multi_register_page() {
118 +function is_uwp_users_item_page() {
119 119 $page = new UsersWP_Pages();
120 - return $page->is_multi_register_page();
120 + return $page->is_user_item_page();
121 121 }
122 122
123 123 /**
124 124 * Checks whether the current page is logged in user profile page or not.
@@ -185,8 +185,416 @@
185 185 $page = new UsersWP_Pages();
186 186 $page->generate_default_pages();
187 187 }
188 188
189 -function uwp_get_page_id($type, $link) {
189 +function uwp_get_page_id($type, $link = false) {
190 190 $page = new UsersWP_Pages();
191 191 return $page->get_page_id($type, $link);
192 +}
193 +
194 +function uwp_get_user_badge($args){
195 + global $wpdb;
196 +
197 + if ( isset($args) && empty( $args['user_id'] ) ) {
198 + return;
199 + }
200 +
201 + $user = get_userdata($args['user_id']);
202 + if(!$user){
203 + return;
204 + }
205 +
206 + $defaults = array(
207 + 'user_id' => 0,
208 + 'key' => '',
209 + 'condition' => '',
210 + 'search' => 'is_equal',
211 + 'badge' => '',
212 + 'link' => '',
213 + 'new_window' => '',
214 + 'bg_color' => '#0073aa',
215 + 'txt_color' => '#ffffff',
216 + 'size' => '',
217 + 'alignment' => '',
218 + 'css_class' => '',
219 + 'onclick' => '',
220 + 'icon_class'=> '',
221 + 'extra_attributes'=> '',
222 + 'tag' => '',
223 + 'popover_title'=> '',
224 + 'popover_text'=> '',
225 + 'tooltip_text' => '',
226 + 'hover_content' => '',
227 + 'hover_icon' => '',
228 + 'type'=> '', // AUI only
229 + 'color'=> '', // AUI only
230 + 'shadow'=> '', // AUI only
231 + );
232 +
233 + $args = shortcode_atts( $defaults, $args, 'uwp_user_badge' );
234 +
235 + $output = '';
236 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
237 + $match_field = $args['key'];
238 + $badge = $args['badge'];
239 + $field = array();
240 + $user_id = $user->ID;
241 +
242 + // Check if there is a specific filter for field.
243 + if ( has_filter( 'uwp_output_badge_field_key_' . $match_field ) ) {
244 + $output = apply_filters( 'uwp_output_badge_field_key_' . $match_field, $output, $user, $args );
245 + }
246 +
247 + if ( $match_field ) {
248 + $form_id = uwp_get_register_form_id( $user->ID );
249 + $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND htmlvar_name = %s AND form_id = %d", $match_field, $form_id));
250 +
251 + if(!$fields){
252 + return $output;
253 + }
254 +
255 + $field = isset($fields[0]) ? $fields[0] : '';
256 +
257 + if ( ! empty( $field ) ) {
258 + // Check if there is a specific filter for key type.
259 + if ( has_filter( 'uwp_output_badge_key_' . $field->field_type_key ) ) {
260 + $output = apply_filters( 'uwp_output_badge_key_' . $field->field_type_key, $output, $user, $args, $field );
261 + }
262 +
263 + // Check if there is a specific filter for condition.
264 + if ( has_filter( 'uwp_output_badge_condition_' . $args['condition'] ) ) {
265 + $output = apply_filters( 'uwp_output_badge_condition_' . $args['condition'], $output, $user, $args, $field );
266 + }
267 + } else {
268 + return $output;
269 + }
270 + }
271 +
272 + // If not then we run the standard output.
273 + if ( empty( $output ) ) {
274 + $search = $args['search'];
275 + $match_found = $match_field === '' ? true : false;
276 + $is_date = ( isset( $field->field_type ) && $field->field_type == 'datepicker' ) ? true : false;
277 + $is_date = apply_filters( 'uwp_user_badge_is_date', $is_date, $match_field, $field, $args );
278 +
279 + $excluded_fields = uwp_get_excluded_fields();
280 + if(isset($field->htmlvar_name) && in_array($field->htmlvar_name, $excluded_fields)){
281 + $match_value = '';
282 + } else {
283 + $match_value = uwp_get_usermeta($user->ID, $field->htmlvar_name, "");
284 + }
285 +
286 + if ( ! $match_found ) {
287 + if ( $field->field_type == 'datepicker' && empty( $args['condition'] ) || $args['condition'] == 'is_greater_than' || $args['condition'] == 'is_less_than' ) {
288 + if( ( empty($args['condition']) || $args['condition'] == 'is_less_than' ) && strpos( $search, '-' ) === false ) {
289 + $search = str_replace('+','',$search);
290 + $search = '-' . $search;
291 + } elseif ( $args['condition'] == 'is_greater_than' && strpos( $search, '+' ) === false ) {
292 + $search = str_replace('-','',$search);
293 + $search = '+' . $search;
294 + }
295 +
296 + $the_time = strtotime(date( 'Y-m-d', $match_value ));
297 + $until_time = strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) . ' ' . $search . ' days' );
298 + $now_time = strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) );
299 +
300 +
301 + if ( ( empty( $args['condition'] ) || $args['condition'] == 'is_less_than' ) && $the_time <= $now_time && $the_time >= $until_time ) {
302 + $match_found = true;
303 + } elseif ( $args['condition'] == 'is_greater_than' && $the_time >= $now_time && $the_time <= $until_time ) {
304 + $match_found = true;
305 + }
306 + } else {
307 + switch ( $args['condition'] ) {
308 + case 'is_equal':
309 + $match_found = (bool) ( $search != '' && $match_value == $search );
310 + break;
311 + case 'is_not_equal':
312 + $match_found = (bool) ( $search != '' && $match_value != $search );
313 + break;
314 + case 'is_greater_than':
315 + $match_found = (bool) ( $search != '' && is_float( $search ) && is_float( $match_value ) && $match_value > $search );
316 + break;
317 + case 'is_less_than':
318 + $match_found = (bool) ( $search != '' && is_float( $search ) && is_float( $match_value ) && $match_value < $search );
319 + break;
320 + case 'is_empty':
321 + $match_found = (bool) ( $match_value === '' || $match_value === false || $match_value === '0' || is_null( $match_value ) );
322 + break;
323 + case 'is_not_empty':
324 + $match_found = (bool) ( $match_value !== '' && $match_value !== false && $match_value !== '0' && ! is_null( $match_value ) );
325 + break;
326 + case 'is_contains':
327 + $match_found = (bool) ( $search != '' && stripos( $match_value, $search ) !== false );
328 + break;
329 + case 'is_not_contains':
330 + $match_found = (bool) ( $search != '' && stripos( $match_value, $search ) === false );
331 + break;
332 + }
333 + }
334 + }
335 +
336 + $match_found = apply_filters( 'uwp_user_badge_check_match_found', $match_found, $args, $user );
337 +
338 + if ( $match_found ) {
339 + if ( $is_date && ! empty( $match_value ) && strpos( $match_value, '0000-00-00' ) === false ) {
340 + $args['datetime'] = mysql2date( 'c', $match_value, false );
341 + }
342 +
343 + // Option value
344 + if ( ! empty( $field->option_values ) ) {
345 + $option_values = uwp_string_values_to_options( stripslashes_deep( $field->option_values ), true );
346 +
347 + if ( ! empty( $option_values ) ) {
348 + if ( ! empty( $field->option_values ) && $field->option_values == 'multiselect' ) {
349 + $values = explode( ',', trim( $match_value, ', ' ) );
350 +
351 + if ( is_array( $values ) ) {
352 + $values = array_map( 'trim', $values );
353 + }
354 +
355 + $_match_value = array();
356 + foreach ( $option_values as $option_value ) {
357 + if ( isset( $option_value['value'] ) && in_array( $option_value['value'], $values ) ) {
358 + $_match_value[] = $option_value['label'];
359 + }
360 + }
361 +
362 + $match_value = ! empty( $_match_value ) ? implode( ', ', $_match_value ) : '';
363 + } else {
364 + foreach ( $option_values as $option_value ) {
365 + if ( isset( $option_value['value'] ) && $option_value['value'] == $match_value ) {
366 + $match_value = $option_value['label'];
367 + }
368 + }
369 + }
370 + }
371 + }
372 +
373 + $match_value = apply_filters( 'uwp_post_badge_match_value', $match_value, $match_field, $args, $user, $field );
374 +
375 + // File
376 + if ( ! empty( $badge ) && ! empty( $match_value ) && ! empty( $field->field_type ) && $field->field_type == 'file' ) {
377 + $badge = $match_value;
378 + }
379 +
380 + // badge text
381 + if ( empty( $badge ) && empty($args['icon_class']) ) {
382 + $badge = isset($field->site_title) ? $field->site_title : '';
383 + }
384 + if( !empty( $badge ) && $badge = str_replace("%%input%%", $match_value,$badge) ){
385 + // will be replace in condition check
386 + }
387 + if( !empty( $badge ) && $user_id && $badge = str_replace("%%profile_url%%", uwp_build_profile_tab_url($user_id),$badge) ){
388 + // will be replace in condition check
389 + }
390 +
391 + //link url, replace vars
392 + if( !empty( $args['link'] ) && $args['link'] = str_replace("%%input%%", $match_value,$args['link']) ){
393 + // will be replace in condition check
394 + }
395 + if( !empty( $args['link'] ) && $user_id && $args['link'] = str_replace("%%profile_url%%", uwp_build_profile_tab_url($user_id),$args['link']) ){
396 + // will be replace in condition check
397 + }
398 +
399 + // replace other post variables
400 + if(!empty($badge)){
401 + $badge = uwp_replace_variables($badge, $user_id);
402 + }
403 + if(!empty($args['popover_title'])){
404 + $args['popover_title'] = uwp_replace_variables($args['popover_title'], $user_id);
405 + }
406 + if(!empty($args['popover_text'])){
407 + $args['popover_text'] = uwp_replace_variables($args['popover_text'], $user_id);
408 + }
409 + if(!empty($args['tooltip_text'])){
410 + $args['tooltip_text'] = uwp_replace_variables($args['tooltip_text'], $user_id);
411 + }
412 + if(!empty($args['hover_content'])){
413 + $args['hover_content'] = uwp_replace_variables($args['hover_content'], $user_id);
414 + }
415 +
416 + $rel = '';
417 + if(!empty($args['link'])){
418 + $rel = strpos($args['link'], get_site_url()) !== false ? '' : 'rel="nofollow"';
419 + }
420 +
421 + $new_window = '';
422 + if ( ! empty( $args['new_window'] ) ) {
423 + $new_window = ' target="_blank" ';
424 + }
425 +
426 + $badge = ! empty( $badge ) ? __( wp_specialchars_decode( $badge, ENT_QUOTES ), 'userswp' ) : '';
427 +
428 + // phone & email link
429 + if ( ! empty( $field ) && ! empty( $field->field_type ) && ! empty( $args['link'] ) && strpos( $args['link'], 'http' ) !== 0 ) {
430 + if ( $field->field_type == 'phone' ) {
431 + $rel = 'rel="nofollow"';
432 + if ( strpos( $args['link'], 'tel:' ) !== 0 ) {
433 + $args['link'] = 'tel:' . preg_replace( '/[^0-9+]/', '', $args['link'] );
434 + }
435 + } elseif ( $field->field_type == 'email' ) {
436 + $rel = 'rel="nofollow"';
437 + if ( strpos( $args['link'], 'mailto:' ) !== 0 ) {
438 + $args['link'] = 'mailto:' . $args['link'];
439 + }
440 + }
441 + }
442 +
443 + $badge = apply_filters( 'uwp_user_badge_output_badge', $badge, $match_value, $match_field, $args, $user, $field );
444 +
445 + $btn_class = 'border-0 align-middle uwp-badge';
446 + // color
447 + $color_custom = true;
448 + if( !empty( $args['color'] ) ) {
449 + $btn_class .= ' badge-' . sanitize_html_class($args['color']);
450 + $color_custom = false;
451 + }else{
452 + $btn_class .= ' badge-primary'; // custom colors will override this anyway.
453 + }
454 +
455 + // shadow
456 + if( !empty( $args['shadow'] ) ) {
457 + if($args['shadow']=='small'){ $btn_class .= ' shadow-sm'; }
458 + elseif($args['shadow']=='medium'){ $btn_class .= ' shadow'; }
459 + elseif($args['shadow']=='large'){ $btn_class .= ' shadow-lg'; }
460 + }
461 +
462 + // type
463 + if( !empty( $args['type'] ) && $args['type']=='pill' ){
464 + $btn_class .= ' badge badge-pill';
465 + }else{
466 + $btn_class .= ' badge';
467 + }
468 +
469 + if ( ! empty( $args['css_class'] ) ) {
470 + $btn_class .= ' ' .esc_attr($args['css_class']) ;
471 + }
472 + $btn_args = array(
473 + 'class' => $btn_class,
474 + 'content' => $badge,
475 + 'style' => $color_custom ? 'background-color:' . sanitize_hex_color( $args['bg_color'] ) . ';color:' . sanitize_hex_color( $args['txt_color'] ) . ';' : '',
476 + 'data-badge' => esc_attr($match_field),
477 + 'data-badge-condition' => esc_attr($args['condition']),
478 + );
479 +
480 + // onclick
481 + if(!empty($args['onclick'])){
482 + $btn_args['onclick'] = esc_attr($args['onclick']);
483 + }
484 +
485 + // popover / tooltip
486 + $pop_link = false;
487 + if(!empty($args['popover_title']) || !empty($args['popover_text'])){
488 + $btn_args['type'] = "button";
489 + $btn_args['data-toggle'] = "popover-html";
490 + $btn_args['data-placement'] = "top";
491 + $pop_link = true;
492 + if(!empty($args['popover_title'])){
493 + $btn_args['title'] = !empty($args['link']) && $args['link']!='#' ? "<a href='".esc_url($args['link'])."' $new_window $rel>".$args['popover_title']."</a>" : $args['popover_title'];
494 + }
495 + if(!empty($args['popover_text'])){
496 + $btn_args['data-content'] = !empty($args['link']) && $args['link']!='#' ? "<a href='".esc_url($args['link'])."' $new_window $rel>".$args['popover_text']."</a>" : $args['popover_text'];
497 + }
498 + }elseif(!empty($args['tooltip_text'])){
499 + $btn_args['data-toggle'] = "tooltip";
500 + $btn_args['data-placement'] = "top";
501 + $btn_args['title'] = esc_attr($args['tooltip_text']);
502 + }
503 +
504 + // hover content
505 + if(!empty($args['hover_content'])){
506 + $btn_args['hover_content'] = $args['hover_content'];
507 + }
508 + if(!empty($args['hover_icon'])){
509 + $btn_args['hover_icon'] = $args['hover_icon'];
510 + }
511 +
512 + // style
513 + $btn_args['style'] = '';
514 + if($color_custom && !empty($args['bg_color'])){
515 + $btn_args['style'] .= 'background-color:' . sanitize_hex_color( $args['bg_color'] ) . ';border-color:' . sanitize_hex_color( $args['bg_color'] ).';';
516 + }
517 + if($color_custom && !empty($args['txt_color'])){
518 + $btn_args['style'] .= 'color:' . sanitize_hex_color( $args['txt_color'] ) . ';';
519 + }
520 +
521 + if(!empty($args['link']) && $args['link']!='#' && !$pop_link){
522 + $btn_args['href'] = $args['link'];
523 + }
524 +
525 + if(!empty($args['link']) && $new_window){
526 + $btn_args['new_window'] = true;
527 + }
528 +
529 + if(!empty($args['icon_class'])) { $btn_args['icon'] = $args['icon_class'];}
530 +
531 + $output = '<span class="bsui uwp-badge-meta">';
532 + if(!empty($args['size'])){$output .= '<span class="'.esc_attr($args['size']).'">';}
533 + $output .= aui()->badge( $btn_args );
534 + if(!empty($args['size'])){$output .= '</span>';}
535 + $output .= '</span>';
536 + }
537 + }
538 +
539 + return $output;
540 +}
541 +
542 +function uwp_aui_colors($include_branding = false){
543 + $theme_colors = array(
544 + "primary" => __('Primary', 'userswp'),
545 + "secondary" => __('Secondary', 'userswp'),
546 + "success" => __('Success', 'userswp'),
547 + "danger" => __('Danger', 'userswp'),
548 + "warning" => __('Warning', 'userswp'),
549 + "info" => __('Info', 'userswp'),
550 + "light" => __('Light', 'userswp'),
551 + "dark" => __('Dark', 'userswp'),
552 + "white" => __('White', 'userswp'),
553 + "purple" => __('Purple', 'userswp'),
554 + "salmon" => __('Salmon', 'userswp'),
555 + "cyan" => __('Cyan', 'userswp'),
556 + "gray" => __('Gray', 'userswp'),
557 + "indigo" => __('Indigo', 'userswp'),
558 + "orange" => __('Orange', 'userswp'),
559 + );
560 +
561 + if($include_branding){
562 + $theme_colors = $theme_colors + uwp_aui_branding_colors();
563 + }
564 +
565 + return $theme_colors;
566 +}
567 +
568 +function uwp_aui_branding_colors(){
569 + return array(
570 + "facebook" => __('Facebook', 'userswp'),
571 + "twitter" => __('Twitter', 'userswp'),
572 + "instagram" => __('Instagram', 'userswp'),
573 + "linkedin" => __('Linkedin', 'userswp'),
574 + "flickr" => __('Flickr', 'userswp'),
575 + "github" => __('GitHub', 'userswp'),
576 + "youtube" => __('YouTube', 'userswp'),
577 + "wordpress" => __('WordPress', 'userswp'),
578 + "google" => __('Google', 'userswp'),
579 + "yahoo" => __('Yahoo', 'userswp'),
580 + "vkontakte" => __('Vkontakte', 'userswp'),
581 + );
582 +}
583 +
584 +function uwp_replace_variables($text, $user_id = ''){
585 + // only run if we have a user ID and the start of a var
586 + if(!empty($user_id) && strpos( $text, '%%' ) !== false){
587 + $excluded_fields = uwp_get_excluded_fields();
588 + $user_data = uwp_get_usermeta_row($user_id);
589 + if(isset($user_data)){
590 + foreach($user_data as $key => $val) {
591 + if ( ! in_array( $key, $excluded_fields ) ) {
592 + $val = apply_filters( 'uwp_replace_variables_' . $key, $val, $text );
593 + $text = str_replace( '%%' . $key . '%%', $val, $text );
594 + }
595 + }
596 + }
597 + }
598 +
599 + return $text;
192 600 }