| 1 |
<?php |
| 2 |
|
| 3 |
use UltimateStoreKit\Ultimate_Store_Kit_Loader; |
| 4 |
use Elementor\Plugin; |
| 5 |
|
| 6 |
/** |
| 7 |
* You can easily add white label branding for for extended license or multi site license. |
| 8 |
* Don't try for regular license otherwise your license will be invalid. |
| 9 |
* return white label |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'BDTUSK' ) ) { |
| 13 |
define( 'BDTUSK', '' ); |
| 14 |
} |
| 15 |
|
| 16 |
//Add prefix for all widgets <span class="usk-widget-badge"></span> |
| 17 |
if ( ! defined( 'BDTUSK_CP' ) ) { |
| 18 |
define( 'BDTUSK_CP', '<span class="usk-widget-badge"></span>' ); |
| 19 |
} |
| 20 |
|
| 21 |
//Add prefix for all widgets <span class="usk-widget-badge"></span> |
| 22 |
if ( ! defined( 'BDTUSK_NC' ) ) { |
| 23 |
define( 'BDTUSK_NC', '<span class="usk-new-control"></span>' ); |
| 24 |
} |
| 25 |
|
| 26 |
// if you have any custom style |
| 27 |
if ( ! defined( 'BDTUSK_SLUG' ) ) { |
| 28 |
define( 'BDTUSK_SLUG', 'ultimate-store-kit' ); |
| 29 |
} |
| 30 |
|
| 31 |
// set your own alias |
| 32 |
if ( ! defined( 'BDTUSK_VER' ) ) { |
| 33 |
define( 'BDTUSK_VER', 'Ultimate Store Kit' ); |
| 34 |
} |
| 35 |
|
| 36 |
// Set your own name for plugin |
| 37 |
|
| 38 |
if ( ! defined( 'BDTUSK_NAME' ) ) { |
| 39 |
define( 'BDTUSK_NAME', 'Ultimate Store Kit' ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Show any alert by this function |
| 44 |
* |
| 45 |
* @param mixed $message [description] |
| 46 |
* @param class prefix $type [description] |
| 47 |
* @param boolean $close [description] |
| 48 |
* |
| 49 |
* @return helper [description] |
| 50 |
*/ |
| 51 |
|
| 52 |
|
| 53 |
function ultimate_store_kit_is_edit() { |
| 54 |
return Plugin::$instance->editor->is_edit_mode(); |
| 55 |
} |
| 56 |
|
| 57 |
function ultimate_store_kit_is_preview() { |
| 58 |
return Plugin::$instance->preview->is_preview_mode(); |
| 59 |
} |
| 60 |
|
| 61 |
function ultimate_store_kit_alert( $message, $type = 'warning', $close = true ) { |
| 62 |
?> |
| 63 |
<div class="usk-alert-<?php echo esc_attr( '$type' ); ?>" usk-alert> |
| 64 |
<?php if ( $close ) : ?> |
| 65 |
<a class="usk-alert-close" usk-close></a> |
| 66 |
<?php endif; ?> |
| 67 |
<?php echo wp_kses_post( $message ); ?> |
| 68 |
</div> |
| 69 |
<?php |
| 70 |
} |
| 71 |
|
| 72 |
function ultimate_store_kit_get_alert( $message, $type = 'warning', $close = true ) { |
| 73 |
|
| 74 |
$output = '<div class="usk-alert-' . $type . '" usk-alert>'; |
| 75 |
if ( $close ) : |
| 76 |
$output .= '<a class="usk-alert-close" usk-close></a>'; |
| 77 |
endif; |
| 78 |
$output .= wp_kses_post( $message ); |
| 79 |
$output .= '</div>'; |
| 80 |
|
| 81 |
return $output; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* all array css classes will output as proper space |
| 86 |
* |
| 87 |
* @param array $classes shortcode css class as array |
| 88 |
* |
| 89 |
* @return proper string |
| 90 |
*/ |
| 91 |
|
| 92 |
function ultimate_store_kit_get_post_types( $args = [] ) { |
| 93 |
|
| 94 |
$post_type_args = [ |
| 95 |
'show_in_nav_menus' => true, |
| 96 |
]; |
| 97 |
|
| 98 |
if ( ! empty( $args['post_type'] ) ) { |
| 99 |
$post_type_args['name'] = $args['post_type']; |
| 100 |
} |
| 101 |
|
| 102 |
$_post_types = get_post_types( $post_type_args, 'objects' ); |
| 103 |
|
| 104 |
$post_types = [ '0' => esc_html__( 'Select Type', 'ultimate-store-kit' ) ]; |
| 105 |
|
| 106 |
foreach ( $_post_types as $post_type => $object ) { |
| 107 |
$post_types[ $post_type ] = $object->label; |
| 108 |
} |
| 109 |
|
| 110 |
return $post_types; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Add REST API support to an already registered post type. |
| 115 |
*/ |
| 116 |
|
| 117 |
// function bdt_custom_post_type_rest_support() { |
| 118 |
|
| 119 |
// global $wp_post_types; |
| 120 |
|
| 121 |
// $post_types = ultimate_store_kit_get_post_types(); |
| 122 |
|
| 123 |
// foreach( $post_types as $post_type ) { |
| 124 |
|
| 125 |
// $post_type_name = $post_type; |
| 126 |
|
| 127 |
// if( isset( $wp_post_types[ $post_type_name ] ) ) { |
| 128 |
|
| 129 |
// $wp_post_types[$post_type_name]->show_in_rest = true; |
| 130 |
|
| 131 |
// $wp_post_types[$post_type_name]->rest_base = $post_type_name; |
| 132 |
|
| 133 |
// $wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller'; |
| 134 |
|
| 135 |
// } |
| 136 |
|
| 137 |
// } |
| 138 |
|
| 139 |
// } |
| 140 |
|
| 141 |
// add_action( 'init', 'bdt_custom_post_type_rest_support', 25 ); |
| 142 |
|
| 143 |
function ultimate_store_kit_allow_tags( $tag = null ) { |
| 144 |
$tag_allowed = wp_kses_allowed_html( 'post' ); |
| 145 |
|
| 146 |
$tag_allowed['input'] = [ |
| 147 |
'class' => [], |
| 148 |
'id' => [], |
| 149 |
'name' => [], |
| 150 |
'value' => [], |
| 151 |
'checked' => [], |
| 152 |
'type' => [], |
| 153 |
]; |
| 154 |
$tag_allowed['select'] = [ |
| 155 |
'class' => [], |
| 156 |
'id' => [], |
| 157 |
'name' => [], |
| 158 |
'value' => [], |
| 159 |
'multiple' => [], |
| 160 |
'type' => [], |
| 161 |
]; |
| 162 |
$tag_allowed['option'] = [ |
| 163 |
'value' => [], |
| 164 |
'selected' => [], |
| 165 |
]; |
| 166 |
|
| 167 |
$tag_allowed['title'] = [ |
| 168 |
'a' => [ |
| 169 |
'href' => [], |
| 170 |
'title' => [], |
| 171 |
'class' => [], |
| 172 |
], |
| 173 |
'br' => [], |
| 174 |
'em' => [], |
| 175 |
'strong' => [], |
| 176 |
'hr' => [], |
| 177 |
]; |
| 178 |
|
| 179 |
$tag_allowed['text'] = [ |
| 180 |
'a' => [ |
| 181 |
'href' => [], |
| 182 |
'title' => [], |
| 183 |
'class' => [], |
| 184 |
], |
| 185 |
'br' => [], |
| 186 |
'em' => [], |
| 187 |
'strong' => [], |
| 188 |
'hr' => [], |
| 189 |
'i' => [ |
| 190 |
'class' => [], |
| 191 |
], |
| 192 |
'span' => [ |
| 193 |
'class' => [], |
| 194 |
], |
| 195 |
]; |
| 196 |
|
| 197 |
$tag_allowed['svg'] = [ |
| 198 |
'svg' => [ |
| 199 |
'version' => [], |
| 200 |
'xmlns' => [], |
| 201 |
'viewbox' => [], |
| 202 |
'xml:space' => [], |
| 203 |
'xmlns:xlink' => [], |
| 204 |
'x' => [], |
| 205 |
'y' => [], |
| 206 |
'style' => [], |
| 207 |
], |
| 208 |
'g' => [], |
| 209 |
'path' => [ |
| 210 |
'class' => [], |
| 211 |
'd' => [], |
| 212 |
], |
| 213 |
'ellipse' => [ |
| 214 |
'class' => [], |
| 215 |
'cx' => [], |
| 216 |
'cy' => [], |
| 217 |
'rx' => [], |
| 218 |
'ry' => [], |
| 219 |
], |
| 220 |
'circle' => [ |
| 221 |
'class' => [], |
| 222 |
'cx' => [], |
| 223 |
'cy' => [], |
| 224 |
'r' => [], |
| 225 |
], |
| 226 |
'rect' => [ |
| 227 |
'x' => [], |
| 228 |
'y' => [], |
| 229 |
'transform' => [], |
| 230 |
'height' => [], |
| 231 |
'width' => [], |
| 232 |
'class' => [], |
| 233 |
], |
| 234 |
'line' => [ |
| 235 |
'class' => [], |
| 236 |
'x1' => [], |
| 237 |
'x2' => [], |
| 238 |
'y1' => [], |
| 239 |
'y2' => [], |
| 240 |
], |
| 241 |
'style' => [], |
| 242 |
|
| 243 |
]; |
| 244 |
|
| 245 |
if ( $tag == null ) { |
| 246 |
return $tag_allowed; |
| 247 |
} elseif ( is_array( $tag ) ) { |
| 248 |
$new_tag_allow = []; |
| 249 |
|
| 250 |
foreach ( $tag as $_tag ) { |
| 251 |
$new_tag_allow[ $_tag ] = $tag_allowed[ $_tag ]; |
| 252 |
} |
| 253 |
|
| 254 |
return $new_tag_allow; |
| 255 |
} else { |
| 256 |
return isset( $tag_allowed[ $tag ] ) ? $tag_allowed[ $tag ] : []; |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* post pagination |
| 262 |
*/ |
| 263 |
function ultimate_store_kit_post_pagination( $wp_query ) { |
| 264 |
|
| 265 |
/** Stop execution if there's only 1 page */ |
| 266 |
|
| 267 |
if ( $wp_query->max_num_pages <= 1 ) { |
| 268 |
return; |
| 269 |
} |
| 270 |
|
| 271 |
if ( is_front_page() ) { |
| 272 |
$paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1; |
| 273 |
} else { |
| 274 |
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; |
| 275 |
} |
| 276 |
|
| 277 |
$max = intval( $wp_query->max_num_pages ); |
| 278 |
|
| 279 |
/** Add current page to the array */ |
| 280 |
|
| 281 |
if ( $paged >= 1 ) { |
| 282 |
$links[] = $paged; |
| 283 |
} |
| 284 |
|
| 285 |
/** Add the pages around the current page to the array */ |
| 286 |
|
| 287 |
if ( $paged >= 3 ) { |
| 288 |
$links[] = $paged - 1; |
| 289 |
$links[] = $paged - 2; |
| 290 |
} |
| 291 |
|
| 292 |
if ( ( $paged + 2 ) <= $max ) { |
| 293 |
$links[] = $paged + 2; |
| 294 |
$links[] = $paged + 1; |
| 295 |
} |
| 296 |
|
| 297 |
echo '<ul class="usk-pagination">' . "\n"; |
| 298 |
|
| 299 |
/** Previous Post Link */ |
| 300 |
|
| 301 |
if ( get_previous_posts_link() ) { |
| 302 |
printf( '<li>%s</li>' . "\n", wp_kses_post( get_previous_posts_link( '<span class="usk-icon-arrow-left-5"></span>' ) ) ); |
| 303 |
} |
| 304 |
|
| 305 |
/** Link to first page, plus ellipses if necessary */ |
| 306 |
|
| 307 |
if ( ! in_array( 1, $links ) ) { |
| 308 |
$class = 1 == $paged ? ' class="current"' : ''; |
| 309 |
|
| 310 |
printf( '<li%s><a href="%s" target="_self">%s</a></li>' . "\n", wp_kses_post( $class ), esc_url( get_pagenum_link( 1 ) ), '1' ); |
| 311 |
|
| 312 |
if ( ! in_array( 2, $links ) ) { |
| 313 |
echo '<li class="usk-pagination-dot-dot"><span>...</span></li>'; |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
/** Link to current page, plus 2 pages in either direction if necessary */ |
| 318 |
sort( $links ); |
| 319 |
|
| 320 |
foreach ( (array) $links as $link ) { |
| 321 |
$class = $paged == $link ? ' class="usk-active"' : ''; |
| 322 |
printf( '<li%s><a href="%s" target="_self">%s</a></li>' . "\n", wp_kses_post( $class ), esc_url( get_pagenum_link( $link ) ), esc_html( $link ) ); |
| 323 |
} |
| 324 |
|
| 325 |
/** Link to last page, plus ellipses if necessary */ |
| 326 |
|
| 327 |
if ( ! in_array( $max, $links ) ) { |
| 328 |
|
| 329 |
if ( ! in_array( $max - 1, $links ) ) { |
| 330 |
echo '<li class="usk-pagination-dot-dot"><span>...</span></li>' . "\n"; |
| 331 |
} |
| 332 |
|
| 333 |
$class = $paged == $max ? ' class="usk-active"' : ''; |
| 334 |
printf( '<li%s><a href="%s" target="_self">%s</a></li>' . "\n", wp_kses_post( $class ), esc_url( get_pagenum_link( $max ) ), esc_html( $max ) ); |
| 335 |
} |
| 336 |
|
| 337 |
/** Next Post Link */ |
| 338 |
|
| 339 |
if ( get_next_posts_link() ) { |
| 340 |
printf( '<li>%s</li>' . "\n", wp_kses_post( get_next_posts_link( '<span class="usk-icon-arrow-right-1"></span>' ) ) ); |
| 341 |
} |
| 342 |
|
| 343 |
echo '</ul>' . "\n"; |
| 344 |
} |
| 345 |
function ultimate_store_kit_post_pagination__new( $wp_query ) { |
| 346 |
|
| 347 |
$page = max( 1, get_query_var( 'paged' ), get_query_var( 'page' ) ); |
| 348 |
$page = absint( empty( $_GET['product-page'] ) ? $page : $_GET['product-page'] ); |
| 349 |
$paged = absint( $page ); |
| 350 |
|
| 351 |
$current_page_url = strtok( get_pagenum_link( 1 ), '?' ); |
| 352 |
|
| 353 |
/** Stop execution if there's only 1 page */ |
| 354 |
|
| 355 |
if ( $wp_query->max_num_pages <= 1 ) { |
| 356 |
return; |
| 357 |
} |
| 358 |
|
| 359 |
$max = intval( $wp_query->max_num_pages ); |
| 360 |
|
| 361 |
/** Add current page to the array */ |
| 362 |
|
| 363 |
if ( $paged >= 1 ) { |
| 364 |
$links[] = $paged; |
| 365 |
} |
| 366 |
|
| 367 |
/** Add the pages around the current page to the array */ |
| 368 |
|
| 369 |
if ( $paged >= 3 ) { |
| 370 |
$links[] = $paged - 1; |
| 371 |
$links[] = $paged - 2; |
| 372 |
} |
| 373 |
|
| 374 |
if ( ( $paged + 2 ) <= $max ) { |
| 375 |
$links[] = $paged + 2; |
| 376 |
$links[] = $paged + 1; |
| 377 |
} |
| 378 |
|
| 379 |
echo '<ul class="usk-pagination">' . "\n"; |
| 380 |
|
| 381 |
/** Previous Post Link */ |
| 382 |
|
| 383 |
if ( get_previous_posts_link() ) { |
| 384 |
$prev_page = $paged - 1; |
| 385 |
|
| 386 |
if( $prev_page < 1 ) { |
| 387 |
return; |
| 388 |
} |
| 389 |
|
| 390 |
$class = $paged == $prev_page ? ' class="current"' : ''; |
| 391 |
|
| 392 |
printf( |
| 393 |
'<li%s><a href="%s" target="_self">%s</a></li>' . "\n", |
| 394 |
wp_kses_post( $class ), |
| 395 |
esc_url( add_query_arg( 'product-page', $prev_page, $current_page_url ) ), |
| 396 |
'<span class="usk-icon-arrow-left-5"></span>' |
| 397 |
); |
| 398 |
} |
| 399 |
|
| 400 |
/** Link to first page, plus ellipses if necessary */ |
| 401 |
|
| 402 |
if ( ! in_array( 1, $links ) ) { |
| 403 |
$class = 1 == $paged ? ' class="current"' : ''; |
| 404 |
|
| 405 |
printf( |
| 406 |
'<li%s><a href="%s" target="_self">%s</a></li>' . "\n", |
| 407 |
wp_kses_post( $class ), |
| 408 |
esc_url( add_query_arg( 'product-page', '1', $current_page_url ) ), |
| 409 |
'1' |
| 410 |
); |
| 411 |
|
| 412 |
if ( ! in_array( 2, $links ) ) { |
| 413 |
echo '<li class="usk-pagination-dot-dot"><span>...</span></li>'; |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
/** Link to current page, plus 2 pages in either direction if necessary */ |
| 418 |
sort( $links ); |
| 419 |
|
| 420 |
foreach ( (array) $links as $link ) { |
| 421 |
$class = $paged == $link ? ' class="usk-active"' : ''; |
| 422 |
printf( '<li%s><a href="%s" target="_self">%s</a></li>' . "\n", |
| 423 |
wp_kses_post( $class ), |
| 424 |
esc_url( add_query_arg( 'product-page', $link, $current_page_url ) ), |
| 425 |
esc_html( $link ) ); |
| 426 |
} |
| 427 |
|
| 428 |
/** Link to last page, plus ellipses if necessary */ |
| 429 |
|
| 430 |
if ( ! in_array( $max, $links ) ) { |
| 431 |
|
| 432 |
if ( ! in_array( $max - 1, $links ) ) { |
| 433 |
echo '<li class="usk-pagination-dot-dot"><span>...</span></li>' . "\n"; |
| 434 |
} |
| 435 |
|
| 436 |
$class = $paged == $max ? ' class="usk-active"' : ''; |
| 437 |
printf( |
| 438 |
'<li%s><a href="%s" target="_self">%s</a></li>' . "\n", |
| 439 |
wp_kses_post( $class ), |
| 440 |
esc_url( add_query_arg( 'product-page', $max, $current_page_url ) ), |
| 441 |
esc_html( $max ) ); |
| 442 |
} |
| 443 |
|
| 444 |
/** Next Post Link */ |
| 445 |
|
| 446 |
if ( get_next_posts_link() ) { |
| 447 |
$next_page = $paged + 1; |
| 448 |
|
| 449 |
if( $next_page > $max ) { |
| 450 |
return; |
| 451 |
} |
| 452 |
|
| 453 |
printf( |
| 454 |
'<li%s><a href="%s" target="_self">%s</a></li>' . "\n", |
| 455 |
wp_kses_post( $class ), |
| 456 |
esc_url( add_query_arg( 'product-page', $next_page, $current_page_url ) ), |
| 457 |
'<span class="usk-icon-arrow-right-1"></span>' |
| 458 |
); |
| 459 |
} |
| 460 |
|
| 461 |
echo '</ul>' . "\n"; |
| 462 |
} |
| 463 |
|
| 464 |
function ultimate_store_kit_template_edit_link( $template_id ) { |
| 465 |
|
| 466 |
if ( Ultimate_Store_Kit_Loader::elementor()->editor->is_edit_mode() ) { |
| 467 |
|
| 468 |
$final_url = add_query_arg( [ 'elementor' => '' ], get_permalink( $template_id ) ); |
| 469 |
|
| 470 |
$output = sprintf( '<a class="usk-elementor-template-edit-link" href="%s" title="%s" target="_blank"><i class="usk-icon-edit"></i></a>', esc_url( $final_url ), esc_html__( 'Edit Template', 'ultimate-store-kit' ) ); |
| 471 |
|
| 472 |
return $output; |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
function ultimate_store_kit_iso_time( $time ) { |
| 477 |
$current_offset = (float) get_option( 'gmt_offset' ); |
| 478 |
$timezone_string = get_option( 'timezone_string' ); |
| 479 |
|
| 480 |
// Create a UTC+- zone if no timezone string exists. |
| 481 |
|
| 482 |
//if ( empty( $timezone_string ) ) { |
| 483 |
if ( 0 === $current_offset ) { |
| 484 |
$timezone_string = '+00:00'; |
| 485 |
} elseif ( $current_offset < 0 ) { |
| 486 |
$timezone_string = $current_offset . ':00'; |
| 487 |
} else { |
| 488 |
$timezone_string = '+0' . $current_offset . ':00'; |
| 489 |
} |
| 490 |
|
| 491 |
//} |
| 492 |
|
| 493 |
$sub_time = []; |
| 494 |
$sub_time = explode( " ", $time ); |
| 495 |
$final_time = $sub_time[0] . 'T' . $sub_time[1] . ':00' . $timezone_string; |
| 496 |
|
| 497 |
return $final_time; |
| 498 |
} |
| 499 |
|
| 500 |
/** |
| 501 |
* @param $currency |
| 502 |
* @param int $precision |
| 503 |
* |
| 504 |
* @return false|string |
| 505 |
*/ |
| 506 |
function ultimate_store_kit_currency_format( $currency, $precision = 1 ) { |
| 507 |
|
| 508 |
if ( $currency > 0 ) { |
| 509 |
|
| 510 |
if ( $currency < 900 ) { |
| 511 |
// 0 - 900 |
| 512 |
$currency_format = number_format( $currency, $precision ); |
| 513 |
$suffix = ''; |
| 514 |
} else |
| 515 |
|
| 516 |
if ( $currency < 900000 ) { |
| 517 |
// 0.9k-850k |
| 518 |
$currency_format = number_format( $currency / 1000, $precision ); |
| 519 |
$suffix = 'K'; |
| 520 |
} else |
| 521 |
|
| 522 |
if ( $currency < 900000000 ) { |
| 523 |
// 0.9m-850m |
| 524 |
$currency_format = number_format( $currency / 1000000, $precision ); |
| 525 |
$suffix = 'M'; |
| 526 |
} else |
| 527 |
|
| 528 |
if ( $currency < 900000000000 ) { |
| 529 |
// 0.9b-850b |
| 530 |
$currency_format = number_format( $currency / 1000000000, $precision ); |
| 531 |
$suffix = 'B'; |
| 532 |
} else { |
| 533 |
// 0.9t+ |
| 534 |
$currency_format = number_format( $currency / 1000000000000, $precision ); |
| 535 |
$suffix = 'T'; |
| 536 |
} |
| 537 |
|
| 538 |
// Remove unecessary zeroes after decimal. "1.0" -> "1"; "1.00" -> "1" |
| 539 |
|
| 540 |
// Intentionally does not affect partials, eg "1.50" -> "1.50" |
| 541 |
if ( $precision > 0 ) { |
| 542 |
$dotzero = '.' . str_repeat( '0', $precision ); |
| 543 |
$currency_format = str_replace( $dotzero, '', $currency_format ); |
| 544 |
} |
| 545 |
|
| 546 |
return $currency_format . $suffix; |
| 547 |
} |
| 548 |
|
| 549 |
return false; |
| 550 |
} |
| 551 |
|
| 552 |
/** |
| 553 |
* @return array |
| 554 |
*/ |
| 555 |
function ultimate_store_kit_get_menu() { |
| 556 |
|
| 557 |
$menus = wp_get_nav_menus(); |
| 558 |
$items = [ 0 => esc_html__( 'Select Menu', 'ultimate-store-kit' ) ]; |
| 559 |
foreach ( $menus as $menu ) { |
| 560 |
$items[ $menu->slug ] = $menu->name; |
| 561 |
} |
| 562 |
|
| 563 |
return $items; |
| 564 |
} |
| 565 |
|
| 566 |
/** |
| 567 |
* default get_option() default value check |
| 568 |
* |
| 569 |
* @param string $option settings field name |
| 570 |
* @param string $section the section name this field belongs to |
| 571 |
* @param string $default default text if it's not found |
| 572 |
* |
| 573 |
* @return mixed |
| 574 |
*/ |
| 575 |
function ultimate_store_kit_option( $option, $section, $default = '' ) { |
| 576 |
|
| 577 |
$options = get_option( $section ); |
| 578 |
|
| 579 |
if ( isset( $options[ $option ] ) ) { |
| 580 |
return $options[ $option ]; |
| 581 |
} |
| 582 |
|
| 583 |
return $default; |
| 584 |
} |
| 585 |
|
| 586 |
/** |
| 587 |
* @return array of elementor template |
| 588 |
*/ |
| 589 |
function ultimate_store_kit_et_options() { |
| 590 |
|
| 591 |
$templates = Ultimate_Store_Kit_Loader::elementor()->templates_manager->get_source( 'local' )->get_items(); |
| 592 |
$types = []; |
| 593 |
|
| 594 |
if ( empty( $templates ) ) { |
| 595 |
$template_options = [ '0' => __( 'Template Not Found!', 'ultimate-store-kit' ) ]; |
| 596 |
} else { |
| 597 |
$template_options = [ '0' => __( 'Select Template', 'ultimate-store-kit' ) ]; |
| 598 |
|
| 599 |
foreach ( $templates as $template ) { |
| 600 |
$template_options[ $template['template_id'] ] = $template['title'] . ' (' . $template['type'] . ')'; |
| 601 |
$types[ $template['template_id'] ] = $template['type']; |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
return $template_options; |
| 606 |
} |
| 607 |
|
| 608 |
/** |
| 609 |
* @return array of wp default sidebars |
| 610 |
*/ |
| 611 |
function ultimate_store_kit_sidebar_options() { |
| 612 |
|
| 613 |
global $wp_registered_sidebars; |
| 614 |
$sidebar_options = []; |
| 615 |
|
| 616 |
if ( ! $wp_registered_sidebars ) { |
| 617 |
$sidebar_options[0] = esc_html__( 'No sidebars were found', 'ultimate-store-kit' ); |
| 618 |
} else { |
| 619 |
$sidebar_options[0] = esc_html__( 'Select Sidebar', 'ultimate-store-kit' ); |
| 620 |
|
| 621 |
foreach ( $wp_registered_sidebars as $sidebar_id => $sidebar ) { |
| 622 |
$sidebar_options[ $sidebar_id ] = $sidebar['name']; |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
return $sidebar_options; |
| 627 |
} |
| 628 |
|
| 629 |
/** |
| 630 |
* @param string category name |
| 631 |
* |
| 632 |
* @return array of category |
| 633 |
*/ |
| 634 |
function ultimate_store_kit_get_category( $taxonomy = 'product_cat' ) { |
| 635 |
|
| 636 |
$post_options = []; |
| 637 |
|
| 638 |
$post_categories = get_terms( [ |
| 639 |
'taxonomy' => $taxonomy, |
| 640 |
'hide_empty' => false, |
| 641 |
] ); |
| 642 |
|
| 643 |
if ( is_wp_error( $post_categories ) ) { |
| 644 |
return $post_options; |
| 645 |
} |
| 646 |
|
| 647 |
if ( false !== $post_categories and is_array( $post_categories ) ) { |
| 648 |
foreach ( $post_categories as $category ) { |
| 649 |
$post_options[ $category->term_id ] = $category->name; |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
return $post_options; |
| 654 |
} |
| 655 |
|
| 656 |
/** |
| 657 |
* @param string parent category name |
| 658 |
* @return array of parent category |
| 659 |
*/ |
| 660 |
function ultimate_store_kit_get_only_parent_cats( $taxonomy = 'category' ) { |
| 661 |
|
| 662 |
$parent_categories = [ 'none' => __( 'None', 'ultimate-store-kit' ) ]; |
| 663 |
$args = [ 'parent' => 0 ]; |
| 664 |
$parent_cats = get_terms( $taxonomy, $args ); |
| 665 |
|
| 666 |
foreach ( $parent_cats as $parent_cat ) { |
| 667 |
$parent_categories[ $parent_cat->term_id ] = ucfirst( $parent_cat->name ); |
| 668 |
} |
| 669 |
|
| 670 |
return $parent_categories; |
| 671 |
} |
| 672 |
|
| 673 |
/** |
| 674 |
* @param array all ajax posted array there |
| 675 |
* |
| 676 |
* @return array return all setting as array |
| 677 |
*/ |
| 678 |
function ultimate_store_kit_ajax_settings( $settings ) { |
| 679 |
|
| 680 |
$required_settings = [ |
| 681 |
'show_date' => true, |
| 682 |
'show_comment' => true, |
| 683 |
'show_link' => true, |
| 684 |
'show_meta' => true, |
| 685 |
'show_title' => true, |
| 686 |
'show_excerpt' => true, |
| 687 |
'show_lightbox' => true, |
| 688 |
'show_thumbnail' => true, |
| 689 |
'show_category' => false, |
| 690 |
'show_tags' => false, |
| 691 |
]; |
| 692 |
|
| 693 |
foreach ( $settings as $key => $value ) { |
| 694 |
if ( in_array( $key, $required_settings ) ) { |
| 695 |
$required_settings[ $key ] = $value; |
| 696 |
} |
| 697 |
} |
| 698 |
|
| 699 |
return $required_settings; |
| 700 |
} |
| 701 |
|
| 702 |
/** |
| 703 |
* @return array of all transition names |
| 704 |
*/ |
| 705 |
function ultimate_store_kit_transition_options() { |
| 706 |
|
| 707 |
$transition_options = [ |
| 708 |
'' => esc_html__( 'None', 'ultimate-store-kit' ), |
| 709 |
'fade' => esc_html__( 'Fade', 'ultimate-store-kit' ), |
| 710 |
'scale-up' => esc_html__( 'Scale Up', 'ultimate-store-kit' ), |
| 711 |
'scale-down' => esc_html__( 'Scale Down', 'ultimate-store-kit' ), |
| 712 |
'slide-top' => esc_html__( 'Slide Top', 'ultimate-store-kit' ), |
| 713 |
'slide-bottom' => esc_html__( 'Slide Bottom', 'ultimate-store-kit' ), |
| 714 |
'slide-left' => esc_html__( 'Slide Left', 'ultimate-store-kit' ), |
| 715 |
'slide-right' => esc_html__( 'Slide Right', 'ultimate-store-kit' ), |
| 716 |
'slide-top-small' => esc_html__( 'Slide Top Small', 'ultimate-store-kit' ), |
| 717 |
'slide-bottom-small' => esc_html__( 'Slide Bottom Small', 'ultimate-store-kit' ), |
| 718 |
'slide-left-small' => esc_html__( 'Slide Left Small', 'ultimate-store-kit' ), |
| 719 |
'slide-right-small' => esc_html__( 'Slide Right Small', 'ultimate-store-kit' ), |
| 720 |
'slide-top-medium' => esc_html__( 'Slide Top Medium', 'ultimate-store-kit' ), |
| 721 |
'slide-bottom-medium' => esc_html__( 'Slide Bottom Medium', 'ultimate-store-kit' ), |
| 722 |
'slide-left-medium' => esc_html__( 'Slide Left Medium', 'ultimate-store-kit' ), |
| 723 |
'slide-right-medium' => esc_html__( 'Slide Right Medium', 'ultimate-store-kit' ), |
| 724 |
]; |
| 725 |
|
| 726 |
return $transition_options; |
| 727 |
} |
| 728 |
|
| 729 |
// BDT Blend Type |
| 730 |
function ultimate_store_kit_blend_options() { |
| 731 |
$blend_options = [ |
| 732 |
'multiply' => esc_html__( 'Multiply', 'ultimate-store-kit' ), |
| 733 |
'screen' => esc_html__( 'Screen', 'ultimate-store-kit' ), |
| 734 |
'overlay' => esc_html__( 'Overlay', 'ultimate-store-kit' ), |
| 735 |
'darken' => esc_html__( 'Darken', 'ultimate-store-kit' ), |
| 736 |
'lighten' => esc_html__( 'Lighten', 'ultimate-store-kit' ), |
| 737 |
'color-dodge' => esc_html__( 'Color-Dodge', 'ultimate-store-kit' ), |
| 738 |
'color-burn' => esc_html__( 'Color-Burn', 'ultimate-store-kit' ), |
| 739 |
'hard-light' => esc_html__( 'Hard-Light', 'ultimate-store-kit' ), |
| 740 |
'soft-light' => esc_html__( 'Soft-Light', 'ultimate-store-kit' ), |
| 741 |
'difference' => esc_html__( 'Difference', 'ultimate-store-kit' ), |
| 742 |
'exclusion' => esc_html__( 'Exclusion', 'ultimate-store-kit' ), |
| 743 |
'hue' => esc_html__( 'Hue', 'ultimate-store-kit' ), |
| 744 |
'saturation' => esc_html__( 'Saturation', 'ultimate-store-kit' ), |
| 745 |
'color' => esc_html__( 'Color', 'ultimate-store-kit' ), |
| 746 |
'luminosity' => esc_html__( 'Luminosity', 'ultimate-store-kit' ), |
| 747 |
]; |
| 748 |
|
| 749 |
return $blend_options; |
| 750 |
} |
| 751 |
|
| 752 |
// BDT Position |
| 753 |
function ultimate_store_kit_position() { |
| 754 |
$position_options = [ |
| 755 |
'' => esc_html__( 'Default', 'ultimate-store-kit' ), |
| 756 |
'top-left' => esc_html__( 'Top Left', 'ultimate-store-kit' ), |
| 757 |
'top-center' => esc_html__( 'Top Center', 'ultimate-store-kit' ), |
| 758 |
'top-right' => esc_html__( 'Top Right', 'ultimate-store-kit' ), |
| 759 |
'center' => esc_html__( 'Center', 'ultimate-store-kit' ), |
| 760 |
'center-left' => esc_html__( 'Center Left', 'ultimate-store-kit' ), |
| 761 |
'center-right' => esc_html__( 'Center Right', 'ultimate-store-kit' ), |
| 762 |
'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-store-kit' ), |
| 763 |
'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-store-kit' ), |
| 764 |
'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-store-kit' ), |
| 765 |
]; |
| 766 |
|
| 767 |
return $position_options; |
| 768 |
} |
| 769 |
|
| 770 |
// BDT Thumbnavs Position |
| 771 |
function ultimate_store_kit_thumbnavs_position() { |
| 772 |
$position_options = [ |
| 773 |
'top-left' => esc_html__( 'Top Left', 'ultimate-store-kit' ), |
| 774 |
'top-center' => esc_html__( 'Top Center', 'ultimate-store-kit' ), |
| 775 |
'top-right' => esc_html__( 'Top Right', 'ultimate-store-kit' ), |
| 776 |
'center-left' => esc_html__( 'Center Left', 'ultimate-store-kit' ), |
| 777 |
'center-right' => esc_html__( 'Center Right', 'ultimate-store-kit' ), |
| 778 |
'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-store-kit' ), |
| 779 |
'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-store-kit' ), |
| 780 |
'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-store-kit' ), |
| 781 |
]; |
| 782 |
|
| 783 |
return $position_options; |
| 784 |
} |
| 785 |
|
| 786 |
function ultimate_store_kit_navigation_position() { |
| 787 |
$position_options = [ |
| 788 |
'top-left' => esc_html__( 'Top Left', 'ultimate-store-kit' ), |
| 789 |
'top-center' => esc_html__( 'Top Center', 'ultimate-store-kit' ), |
| 790 |
'top-right' => esc_html__( 'Top Right', 'ultimate-store-kit' ), |
| 791 |
'center' => esc_html__( 'Center', 'ultimate-store-kit' ), |
| 792 |
'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-store-kit' ), |
| 793 |
'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-store-kit' ), |
| 794 |
'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-store-kit' ), |
| 795 |
]; |
| 796 |
|
| 797 |
return $position_options; |
| 798 |
} |
| 799 |
|
| 800 |
function ultimate_store_kit_pagination_position() { |
| 801 |
$position_options = [ |
| 802 |
'top-left' => esc_html__( 'Top Left', 'ultimate-store-kit' ), |
| 803 |
'top-center' => esc_html__( 'Top Center', 'ultimate-store-kit' ), |
| 804 |
'top-right' => esc_html__( 'Top Right', 'ultimate-store-kit' ), |
| 805 |
'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-store-kit' ), |
| 806 |
'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-store-kit' ), |
| 807 |
'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-store-kit' ), |
| 808 |
]; |
| 809 |
|
| 810 |
return $position_options; |
| 811 |
} |
| 812 |
|
| 813 |
// BDT Drop Position |
| 814 |
function ultimate_store_kit_drop_position() { |
| 815 |
$drop_position_options = [ |
| 816 |
'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-store-kit' ), |
| 817 |
'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-store-kit' ), |
| 818 |
'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-store-kit' ), |
| 819 |
'bottom-justify' => esc_html__( 'Bottom Justify', 'ultimate-store-kit' ), |
| 820 |
'top-left' => esc_html__( 'Top Left', 'ultimate-store-kit' ), |
| 821 |
'top-center' => esc_html__( 'Top Center', 'ultimate-store-kit' ), |
| 822 |
'top-right' => esc_html__( 'Top Right', 'ultimate-store-kit' ), |
| 823 |
'top-justify' => esc_html__( 'Top Justify', 'ultimate-store-kit' ), |
| 824 |
'left-top' => esc_html__( 'Left Top', 'ultimate-store-kit' ), |
| 825 |
'left-center' => esc_html__( 'Left Center', 'ultimate-store-kit' ), |
| 826 |
'left-bottom' => esc_html__( 'Left Bottom', 'ultimate-store-kit' ), |
| 827 |
'right-top' => esc_html__( 'Right Top', 'ultimate-store-kit' ), |
| 828 |
'right-center' => esc_html__( 'Right Center', 'ultimate-store-kit' ), |
| 829 |
'right-bottom' => esc_html__( 'Right Bottom', 'ultimate-store-kit' ), |
| 830 |
]; |
| 831 |
|
| 832 |
return $drop_position_options; |
| 833 |
} |
| 834 |
|
| 835 |
// Button Size |
| 836 |
function ultimate_store_kit_button_sizes() { |
| 837 |
$button_sizes = [ |
| 838 |
'xs' => esc_html__( 'Extra Small', 'ultimate-store-kit' ), |
| 839 |
'sm' => esc_html__( 'Small', 'ultimate-store-kit' ), |
| 840 |
'md' => esc_html__( 'Medium', 'ultimate-store-kit' ), |
| 841 |
'lg' => esc_html__( 'Large', 'ultimate-store-kit' ), |
| 842 |
'xl' => esc_html__( 'Extra Large', 'ultimate-store-kit' ), |
| 843 |
]; |
| 844 |
|
| 845 |
return $button_sizes; |
| 846 |
} |
| 847 |
|
| 848 |
// Button Size |
| 849 |
function ultimate_store_kit_heading_size() { |
| 850 |
$heading_sizes = [ |
| 851 |
'h1' => 'H1', |
| 852 |
'h2' => 'H2', |
| 853 |
'h3' => 'H3', |
| 854 |
'h4' => 'H4', |
| 855 |
'h5' => 'H5', |
| 856 |
'h6' => 'H6', |
| 857 |
]; |
| 858 |
|
| 859 |
return $heading_sizes; |
| 860 |
} |
| 861 |
|
| 862 |
// Title Tags |
| 863 |
function ultimate_store_kit_title_tags() { |
| 864 |
$title_tags = [ |
| 865 |
'h1' => 'H1', |
| 866 |
'h2' => 'H2', |
| 867 |
'h3' => 'H3', |
| 868 |
'h4' => 'H4', |
| 869 |
'h5' => 'H5', |
| 870 |
'h6' => 'H6', |
| 871 |
'div' => 'div', |
| 872 |
'span' => 'span', |
| 873 |
'p' => 'p', |
| 874 |
]; |
| 875 |
|
| 876 |
return $title_tags; |
| 877 |
} |
| 878 |
|
| 879 |
function ultimate_store_kit_mask_shapes() { |
| 880 |
$path = BDTUSK_ASSETS_URL . 'images/mask/'; |
| 881 |
$shape_name = 'shape'; |
| 882 |
$extension = '.svg'; |
| 883 |
$list = [ 0 => esc_html__( 'Select Mask', 'ultimate-store-kit' ) ]; |
| 884 |
|
| 885 |
for ( $i = 1; $i <= 20; $i++ ) { |
| 886 |
$list[ $path . $shape_name . '-' . $i . $extension ] = ucwords( $shape_name . ' ' . $i ); |
| 887 |
} |
| 888 |
|
| 889 |
return $list; |
| 890 |
} |
| 891 |
|
| 892 |
/** |
| 893 |
* This is a svg file converter function which return a svg content |
| 894 |
* |
| 895 |
* @param svg file |
| 896 |
* |
| 897 |
* @return svg content |
| 898 |
*/ |
| 899 |
function ultimate_store_kit_svg_icon( $icon ) { |
| 900 |
|
| 901 |
$icon_path = BDTUSK_ASSETS_PATH . "images/svg/{$icon}.svg"; |
| 902 |
|
| 903 |
if ( ! file_exists( $icon_path ) ) { |
| 904 |
return false; |
| 905 |
} |
| 906 |
|
| 907 |
ob_start(); |
| 908 |
|
| 909 |
include $icon_path; |
| 910 |
|
| 911 |
$svg = ob_get_clean(); |
| 912 |
|
| 913 |
return $svg; |
| 914 |
} |
| 915 |
|
| 916 |
/** |
| 917 |
* @param array CSV file data |
| 918 |
* @param string $delimiter |
| 919 |
* @param false $header |
| 920 |
* |
| 921 |
* @return string |
| 922 |
*/ |
| 923 |
function ultimate_store_kit_parse_csv( $csv, $delimiter = ';', $header = true ) { |
| 924 |
|
| 925 |
if ( ! is_string( $csv ) ) { |
| 926 |
return ''; |
| 927 |
} |
| 928 |
|
| 929 |
if ( ! function_exists( 'str_getcsv' ) ) { |
| 930 |
return $csv; |
| 931 |
} |
| 932 |
|
| 933 |
$html = ''; |
| 934 |
$rows = explode( PHP_EOL, $csv ); |
| 935 |
$headRow = 1; |
| 936 |
|
| 937 |
foreach ( $rows as $row ) { |
| 938 |
|
| 939 |
if ( $headRow == 1 and $header ) { |
| 940 |
$html .= '<thead><tr>'; |
| 941 |
} else { |
| 942 |
$html .= '<tr>'; |
| 943 |
} |
| 944 |
|
| 945 |
foreach ( str_getcsv( $row, $delimiter ) as $cell ) { |
| 946 |
|
| 947 |
$cell = trim( $cell ); |
| 948 |
|
| 949 |
$html .= $header |
| 950 |
? '<th>' . $cell . '</th>' |
| 951 |
: '<td>' . $cell . '</td>'; |
| 952 |
} |
| 953 |
|
| 954 |
if ( $headRow == 1 and $header ) { |
| 955 |
$html .= '</tr></thead><tbody>'; |
| 956 |
} else { |
| 957 |
$html .= '</tr>'; |
| 958 |
} |
| 959 |
|
| 960 |
$headRow++; |
| 961 |
$header = false; |
| 962 |
} |
| 963 |
|
| 964 |
return '<table>' . $html . '</tbody></table>'; |
| 965 |
} |
| 966 |
|
| 967 |
function ultimate_store_kit_dashboard_link( $suffix = '#welcome' ) { |
| 968 |
return add_query_arg( [ 'page' => 'ultimate_store_kit_options' . $suffix ], admin_url( 'admin.php' ) ); |
| 969 |
} |
| 970 |
|
| 971 |
/** |
| 972 |
* @param int $limit default limit is 25 word |
| 973 |
* @param bool $strip_shortcode if you want to strip shortcode from excert text |
| 974 |
* @param string $trail trail string default is ... |
| 975 |
* |
| 976 |
* @return string return custom limited excerpt text |
| 977 |
*/ |
| 978 |
function ultimate_store_kit_custom_excerpt( $limit = 25, $strip_shortcode = false, $trail = '' ) { |
| 979 |
|
| 980 |
$output = get_the_content(); |
| 981 |
|
| 982 |
if ( $limit ) { |
| 983 |
$output = wp_trim_words( $output, $limit, $trail ); |
| 984 |
} |
| 985 |
|
| 986 |
if ( $strip_shortcode ) { |
| 987 |
$output = strip_shortcodes( $output ); |
| 988 |
} |
| 989 |
|
| 990 |
return wpautop( $output ); |
| 991 |
} |
| 992 |
|
| 993 |
function usk_get_order_options() { |
| 994 |
$options = [ |
| 995 |
'title' => __( 'Title', 'ultimate-store-kit' ), |
| 996 |
'ID' => __( 'ID', 'ultimate-store-kit' ), |
| 997 |
'date' => __( 'Date', 'ultimate-store-kit' ), |
| 998 |
'rand' => __( 'Random', 'ultimate-store-kit' ), |
| 999 |
'_price' => __( 'Product Price', 'ultimate-store-kit' ), |
| 1000 |
'total_sales' => __( 'Top Seller', 'ultimate-store-kit' ), |
| 1001 |
'comment_count' => __( 'Most Reviewed', 'ultimate-store-kit' ), |
| 1002 |
'_wc_average_rating' => __( 'Top Rated', 'ultimate-store-kit' ), |
| 1003 |
]; |
| 1004 |
|
| 1005 |
return apply_filters( 'usk_order_options', $options ); |
| 1006 |
} |
| 1007 |
|
| 1008 |
//wishlist |
| 1009 |
function ultimate_store_kit_get_wishlist( $user_id = 0 ) { |
| 1010 |
$_wishlist_key = '_ultimate_store_kit_wishlist'; |
| 1011 |
$_wishlist = []; |
| 1012 |
|
| 1013 |
if ( isset( $_COOKIE[ $_wishlist_key ] ) ) { |
| 1014 |
$cookie_data = stripslashes( $_COOKIE[ $_wishlist_key ] ); |
| 1015 |
$decoded_data = json_decode( $cookie_data ); |
| 1016 |
|
| 1017 |
if ( json_last_error() === JSON_ERROR_NONE && is_array( $decoded_data ) ) { |
| 1018 |
$_wishlist = $decoded_data; |
| 1019 |
} else { |
| 1020 |
// Handle JSON decoding error if necessary |
| 1021 |
$_wishlist = []; |
| 1022 |
} |
| 1023 |
} |
| 1024 |
|
| 1025 |
return apply_filters( 'ultimate_store_kit_wishlist', array_unique( $_wishlist ) ); |
| 1026 |
} |
| 1027 |
|
| 1028 |
function usk_get_taxonomies() { |
| 1029 |
$taxonomy_list = get_object_taxonomies( 'product' ); |
| 1030 |
$taxonomies = [ |
| 1031 |
'search' => 'Search', |
| 1032 |
'price' => 'Price', |
| 1033 |
'orderby' => 'Orderby', |
| 1034 |
'order' => 'Order', |
| 1035 |
]; |
| 1036 |
|
| 1037 |
foreach ( $taxonomy_list as $_taxonomy ) { |
| 1038 |
$taxonomy = get_taxonomy( $_taxonomy ); |
| 1039 |
|
| 1040 |
if ( $taxonomy->show_ui ) { |
| 1041 |
$taxonomies[ $_taxonomy ] = $taxonomy->label; |
| 1042 |
} |
| 1043 |
} |
| 1044 |
|
| 1045 |
return $taxonomies; |
| 1046 |
} |
| 1047 |
|
| 1048 |
function ultimate_store_kit_hide_on_class( $selectors ) { |
| 1049 |
$element_hide_on = ''; |
| 1050 |
|
| 1051 |
if ( ! empty( $selectors ) ) { |
| 1052 |
|
| 1053 |
foreach ( $selectors as $element ) { |
| 1054 |
|
| 1055 |
if ( $element == 'desktop' ) { |
| 1056 |
$element_hide_on .= ' usk-hide-desktop'; |
| 1057 |
} |
| 1058 |
|
| 1059 |
if ( $element == 'tablet' ) { |
| 1060 |
$element_hide_on .= ' usk-hide-tablet'; |
| 1061 |
} |
| 1062 |
|
| 1063 |
if ( $element == 'mobile' ) { |
| 1064 |
$element_hide_on .= ' usk-hide-mobile'; |
| 1065 |
} |
| 1066 |
} |
| 1067 |
} |
| 1068 |
|
| 1069 |
return $element_hide_on; |
| 1070 |
} |
| 1071 |
|
| 1072 |
function ultimate_store_kit_wc_product_quick_view_content( $product_id ) { |
| 1073 |
wp_verify_nonce( 'ajax-usk-quick-view-nonce', 'usk-quick-view-modal-sc' ); |
| 1074 |
global $woocommerce; |
| 1075 |
global $post; |
| 1076 |
|
| 1077 |
if ( intval( $product_id ) ) { |
| 1078 |
$post = get_post( $product_id ); |
| 1079 |
$next_post = get_next_post(); |
| 1080 |
$prev_post = get_previous_post(); |
| 1081 |
|
| 1082 |
wp( 'p=' . $product_id . '&post_type=product' ); |
| 1083 |
ob_start(); |
| 1084 |
?> |
| 1085 |
<div class="usk-modal-page"> |
| 1086 |
<?php |
| 1087 |
|
| 1088 |
while ( have_posts() ) : |
| 1089 |
the_post(); ?> |
| 1090 |
|
| 1091 |
<script> |
| 1092 |
var url = '<?php echo esc_url( plugins_url( 'assets/js/prettyPhoto/jquery.prettyPhoto.init.js', WC_PLUGIN_FILE ) ); ?>'; |
| 1093 |
jQuery.getScript(url); |
| 1094 |
var wc_add_to_cart_variation_params = { |
| 1095 |
"ajax_url": "\/wp-admin\/admin-ajax.php" |
| 1096 |
}; |
| 1097 |
jQuery.getScript("<?php echo esc_url( $woocommerce->plugin_url() ); ?> '/assets/js/frontend/add-to-cart-variation.min.js'"); |
| 1098 |
</script> |
| 1099 |
<div class="usk-modal-product"> |
| 1100 |
<div id="product-<?php the_ID(); ?>" <?php post_class( 'product' ); ?>> |
| 1101 |
<div class="usk-modal-image-wrapper"> |
| 1102 |
<?php do_action( 'ultimate_store_kit_quick_florence_grid_view_product_images' ); ?> |
| 1103 |
<div class="usk-onsale"> |
| 1104 |
<?php do_action( 'ultimate_store_kit_wc_product_quick_view_product_sale_flash' ); ?> |
| 1105 |
</div> |
| 1106 |
</div> |
| 1107 |
<div class="usk-modal-content-box"> |
| 1108 |
<a href="<?php echo esc_url( get_permalink() ); ?>" class="usk-product-title"> |
| 1109 |
<?php do_action( 'ultimate_store_kit_quick_view_product_title' ); ?> |
| 1110 |
</a> |
| 1111 |
<div class="usk-rating"> |
| 1112 |
<?php do_action( 'ultimate_store_kit_quick_view_product_single_rating' ); ?> |
| 1113 |
</div> |
| 1114 |
<div class="usk-product-price"> |
| 1115 |
<?php do_action( 'ultimate_store_kit_quick_view_product_single_price' ); ?> |
| 1116 |
</div> |
| 1117 |
<div class="usk-product-meta"> |
| 1118 |
<div class="usk-sku-wrapper"> |
| 1119 |
<?php do_action( 'ultimate_store_kit_quick_view_product_single_meta' ); ?> |
| 1120 |
</div> |
| 1121 |
</div> |
| 1122 |
<div class="usk-product-desc"> |
| 1123 |
<?php do_action( 'ultimate_store_kit_quick_view_product_single_excerpt' ); ?> |
| 1124 |
</div> |
| 1125 |
|
| 1126 |
<div class="usk-quick-action-wrap"> |
| 1127 |
<?php do_action( 'ultimate_store_kit_quick_view_product_single_add_to_cart' ); ?> |
| 1128 |
</div> |
| 1129 |
</div> |
| 1130 |
</div> |
| 1131 |
</div> |
| 1132 |
<?php endwhile; ?> |
| 1133 |
</div> |
| 1134 |
|
| 1135 |
<?php echo ob_get_clean(); |
| 1136 |
exit(); |
| 1137 |
} |
| 1138 |
} |
| 1139 |
|
| 1140 |
function ultimate_store_kit_quick_view_product_images() { |
| 1141 |
global $post, $product; ?> |
| 1142 |
<div class="images"> |
| 1143 |
<?php |
| 1144 |
|
| 1145 |
if ( has_post_thumbnail() ) { |
| 1146 |
$attachment_count = count( $product->get_gallery_image_ids() ); |
| 1147 |
$gallery = $attachment_count > 0 ? '[product-gallery]' : ''; |
| 1148 |
$props = wc_get_product_attachment_props( get_post_thumbnail_id(), $post ); |
| 1149 |
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), [ |
| 1150 |
'title' => $props['title'], |
| 1151 |
'alt' => $props['alt'], |
| 1152 |
] ); |
| 1153 |
echo wp_kses_post( apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="usk-product woocommerce-main-image zoom" title="%s" data-rel="prettyPhoto' . $gallery . '">%s</a>', $props['url'], $props['caption'], $image ), $post->ID ) ); |
| 1154 |
} else { |
| 1155 |
echo wp_kses_post( apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="%s" />', wc_placeholder_img_src(), esc_html__( 'Placeholder', 'ultimate-store-kit' ) ), $post->ID ) ); |
| 1156 |
} |
| 1157 |
|
| 1158 |
$attachment_ids = $product->get_gallery_image_ids(); |
| 1159 |
|
| 1160 |
if ( $attachment_ids ) : |
| 1161 |
$loop = 0; |
| 1162 |
$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 ); |
| 1163 |
?> |
| 1164 |
<div class="thumbnails columns-<?php echo esc_attr( $columns ); ?>"> |
| 1165 |
<?php |
| 1166 |
|
| 1167 |
foreach ( $attachment_ids as $attachment_id ) { |
| 1168 |
$classes = [ 'thumbnail' ]; |
| 1169 |
|
| 1170 |
if ( $loop === 0 || $loop % $columns === 0 ) { |
| 1171 |
$classes[] = 'first'; |
| 1172 |
} |
| 1173 |
|
| 1174 |
if ( ( $loop + 1 ) % $columns === 0 ) { |
| 1175 |
$classes[] = 'last'; |
| 1176 |
} |
| 1177 |
|
| 1178 |
$image_link = wp_get_attachment_url( $attachment_id ); |
| 1179 |
|
| 1180 |
if ( ! $image_link ) { |
| 1181 |
continue; |
| 1182 |
} |
| 1183 |
|
| 1184 |
$image_title = esc_attr( get_the_title( $attachment_id ) ); |
| 1185 |
$image_caption = esc_attr( get_post_field( 'post_excerpt', $attachment_id ) ); |
| 1186 |
$image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ), 0, $attr = [ |
| 1187 |
'title' => $image_title, |
| 1188 |
'alt' => $image_title, |
| 1189 |
] ); |
| 1190 |
$image_class = esc_attr( implode( ' ', $classes ) ); |
| 1191 |
echo wp_kses_post( apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '<a href="%s" class="%s" title="%s" >%s</a>', $image_link, $image_class, $image_caption, $image ), $attachment_id, $post->ID, $image_class ) ); |
| 1192 |
$loop++; |
| 1193 |
} |
| 1194 |
|
| 1195 |
?> |
| 1196 |
</div> |
| 1197 |
<?php endif; ?> |
| 1198 |
</div> |
| 1199 |
<?php |
| 1200 |
} |
| 1201 |
|
| 1202 |
|
| 1203 |
/** |
| 1204 |
* License Validation |
| 1205 |
*/ |
| 1206 |
if ( ! function_exists( 'usk_license_validation' ) ) { |
| 1207 |
function usk_license_validation() { |
| 1208 |
|
| 1209 |
if ( function_exists( '_is_usk_pro_activated' ) && false === _is_usk_pro_activated() ) { |
| 1210 |
return false; |
| 1211 |
} |
| 1212 |
|
| 1213 |
$license_key = trim( get_option( 'ultimate_post_kit_license_key' ) ); |
| 1214 |
|
| 1215 |
if ( isset( $license_key ) && ! empty( $license_key ) ) { |
| 1216 |
return true; |
| 1217 |
} else { |
| 1218 |
return false; |
| 1219 |
} |
| 1220 |
return false; |
| 1221 |
} |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
function usk_get_compare_products( $user_id = 0 ) { |
| 1227 |
$_compare_products_key = '_ultimate_store_kit_compare_products'; |
| 1228 |
$_compare_products = []; |
| 1229 |
if ( $user_id != 0 ) { |
| 1230 |
$_compare_products = get_user_meta( $user_id, $_compare_products_key, true ) ?: []; |
| 1231 |
} elseif ( isset( $_COOKIE[ $_compare_products_key ] ) ) { |
| 1232 |
//$_compare_products = unserialize(stripslashes($_COOKIE[sanitize_text_field($_compare_products_key)])); |
| 1233 |
|
| 1234 |
$cookie_value = sanitize_text_field( $_COOKIE[ $_compare_products_key ] ); |
| 1235 |
$_compare_products = json_decode( stripslashes( $cookie_value ), true ); |
| 1236 |
|
| 1237 |
// Check if JSON decoding failed |
| 1238 |
if ( ! is_array( $_compare_products ) ) { |
| 1239 |
$_compare_products = []; |
| 1240 |
} |
| 1241 |
} |
| 1242 |
|
| 1243 |
return apply_filters( 'ultimate_store_kit_compare_products', array_unique( $_compare_products ) ); |
| 1244 |
} |
| 1245 |
|
| 1246 |
function usk_get_compare_products_count() { |
| 1247 |
$count = 0; |
| 1248 |
$user_id = get_current_user_id(); |
| 1249 |
$products = usk_get_compare_products( $user_id ); |
| 1250 |
if ( is_array( $products ) ) { |
| 1251 |
$count = count( $products ); |
| 1252 |
} |
| 1253 |
return $count; |
| 1254 |
} |
| 1255 |
|
| 1256 |
//if (!function_exists('ultimate_store_kit_get_compare_product_slug')) { |
| 1257 |
// function ultimate_store_kit_compare_product_slug() { |
| 1258 |
// return 'compare-products'; |
| 1259 |
// } |
| 1260 |
//} |
| 1261 |
|
| 1262 |
if ( ! function_exists( 'ultimate_store_kit_compare_product_page' ) ) { |
| 1263 |
function ultimate_store_kit_compare_product_page() { |
| 1264 |
if ( $postId = intval( get_option( 'bdt_usk_compare_products_page_id' ) ) ) { |
| 1265 |
$post = get_post( $postId ); |
| 1266 |
if ( $post->post_status == 'publish' ) { |
| 1267 |
return $post->ID; |
| 1268 |
} |
| 1269 |
} |
| 1270 |
} |
| 1271 |
} |
| 1272 |
|
| 1273 |
if ( ! function_exists( 'ultimate_store_kit_is_compare_product_page' ) ) { |
| 1274 |
function ultimate_store_kit_is_compare_product_page() { |
| 1275 |
if ( $page = ultimate_store_kit_compare_product_page() ) { |
| 1276 |
// return is_page( $page->ID ); |
| 1277 |
return is_page( $page ); |
| 1278 |
} |
| 1279 |
} |
| 1280 |
} |
| 1281 |
|