| 1 |
<?php |
| 2 |
/** |
| 3 |
* Checks whether the current page is of given page type or not. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
* @package userswp |
| 7 |
* @param string|bool $type Page type. |
| 8 |
* @return bool |
| 9 |
*/ |
| 10 |
function is_uwp_page($type = false) { |
| 11 |
$page = new UsersWP_Pages(); |
| 12 |
return $page->is_page($type); |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Checks whether the current page is register page or not. |
| 17 |
* |
| 18 |
* @since 1.0.0 |
| 19 |
* @package userswp |
| 20 |
* @return bool |
| 21 |
*/ |
| 22 |
function is_uwp_register_page() { |
| 23 |
$page = new UsersWP_Pages(); |
| 24 |
return $page->is_register_page(); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Checks whether the current page is login page or not. |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* @package userswp |
| 32 |
* @return bool |
| 33 |
*/ |
| 34 |
function is_uwp_login_page() { |
| 35 |
$page = new UsersWP_Pages(); |
| 36 |
return $page->is_login_page(); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Checks whether the current page is forgot password page or not. |
| 41 |
* |
| 42 |
* @since 1.0.0 |
| 43 |
* @package userswp |
| 44 |
* @return bool |
| 45 |
*/ |
| 46 |
function is_uwp_forgot_page() { |
| 47 |
$page = new UsersWP_Pages(); |
| 48 |
return $page->is_forgot_page(); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Checks whether the current page is change password page or not. |
| 53 |
* |
| 54 |
* @since 1.0.0 |
| 55 |
* @package userswp |
| 56 |
* @return bool |
| 57 |
*/ |
| 58 |
function is_uwp_change_page() { |
| 59 |
$page = new UsersWP_Pages(); |
| 60 |
return $page->is_change_page(); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Checks whether the current page is reset password page or not. |
| 65 |
* |
| 66 |
* @since 1.0.0 |
| 67 |
* @package userswp |
| 68 |
* @return bool |
| 69 |
*/ |
| 70 |
function is_uwp_reset_page() { |
| 71 |
$page = new UsersWP_Pages(); |
| 72 |
return $page->is_reset_page(); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Checks whether the current page is account page or not. |
| 77 |
* |
| 78 |
* @since 1.0.0 |
| 79 |
* @package userswp |
| 80 |
* @return bool |
| 81 |
*/ |
| 82 |
function is_uwp_account_page() { |
| 83 |
$page = new UsersWP_Pages(); |
| 84 |
return $page->is_account_page(); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Checks whether the current page is profile page or not. |
| 89 |
* |
| 90 |
* @since 1.0.0 |
| 91 |
* @package userswp |
| 92 |
* @return bool |
| 93 |
*/ |
| 94 |
function is_uwp_profile_page() { |
| 95 |
$page = new UsersWP_Pages(); |
| 96 |
return $page->is_profile_page(); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Checks whether the current page is users page or not. |
| 101 |
* |
| 102 |
* @since 1.0.0 |
| 103 |
* @package userswp |
| 104 |
* @return bool |
| 105 |
*/ |
| 106 |
function is_uwp_users_page() { |
| 107 |
$page = new UsersWP_Pages(); |
| 108 |
return $page->is_users_page(); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Checks whether the current page is users list item page or not. |
| 113 |
* |
| 114 |
* @since 1.0.0 |
| 115 |
* @package userswp |
| 116 |
* @return bool |
| 117 |
*/ |
| 118 |
function is_uwp_users_item_page() { |
| 119 |
$page = new UsersWP_Pages(); |
| 120 |
return $page->is_user_item_page(); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Checks whether the current page is logged in user profile page or not. |
| 125 |
* |
| 126 |
* @since 1.0.0 |
| 127 |
* @package userswp |
| 128 |
* @return bool |
| 129 |
*/ |
| 130 |
function is_uwp_current_user_profile_page() { |
| 131 |
$page = new UsersWP_Pages(); |
| 132 |
return $page->is_current_user_profile_page(); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Returns all available pages as array to use in select dropdown. |
| 137 |
* |
| 138 |
* @since 1.0.0 |
| 139 |
* @package userswp |
| 140 |
* @return array Page array. |
| 141 |
*/ |
| 142 |
function uwp_get_pages() { |
| 143 |
$page = new UsersWP_Pages(); |
| 144 |
return $page->get_pages(); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Gets the page slug using the given page type. |
| 149 |
* |
| 150 |
* @since 1.0.0 |
| 151 |
* @package userswp |
| 152 |
* @param string $page_type Page type. |
| 153 |
* @return string Page slug. |
| 154 |
*/ |
| 155 |
function uwp_get_page_slug($page_type = 'register_page') { |
| 156 |
$page = new UsersWP_Pages(); |
| 157 |
return $page->get_page_slug($page_type); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Creates UsersWP page if not exists. |
| 162 |
* |
| 163 |
* @since 1.0.0 |
| 164 |
* @package userswp |
| 165 |
* @param string $slug Page slug. |
| 166 |
* @param string $option Page setting key. |
| 167 |
* @param string $page_title The post title. Default empty. |
| 168 |
* @param mixed $page_content The post content. Default empty. |
| 169 |
* @param int $post_parent Set this for the post it belongs to, if any. Default 0. |
| 170 |
* @param string $status The post status. Default 'draft'. |
| 171 |
*/ |
| 172 |
function uwp_create_page($slug, $option, $page_title = '', $page_content = '', $post_parent = 0, $status = 'publish') { |
| 173 |
$page = new UsersWP_Pages(); |
| 174 |
$page->create_page($slug, $option, $page_title, $page_content, $post_parent, $status); |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Generates default UsersWP pages. Usually called during plugin activation. |
| 179 |
* |
| 180 |
* @since 1.0.0 |
| 181 |
* @package userswp |
| 182 |
* @return void |
| 183 |
*/ |
| 184 |
function uwp_generate_default_pages() { |
| 185 |
$page = new UsersWP_Pages(); |
| 186 |
$page->generate_default_pages(); |
| 187 |
} |
| 188 |
|
| 189 |
function uwp_get_page_id($type, $link = false) { |
| 190 |
$page = new UsersWP_Pages(); |
| 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; |
| 600 |
} |