| @@ -44,56 +44,9 @@ | ||
| 44 | 44 | |
| 45 | 45 | return false; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public static function get_nonce() { | |
| 49 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 50 | - return isset( $_REQUEST[ rtsb()->nonceId ] ) ? sanitize_text_field( $_REQUEST[ rtsb()->nonceId ] ) : null; | |
| 51 | - } | |
| 52 | - | |
| 53 | - | |
| 54 | 48 | /** |
| 55 | - * Set Cookie or Session | |
| 56 | - * | |
| 57 | - * @param $name | |
| 58 | - * @param $value | |
| 59 | - */ | |
| 60 | - public static function setSession( $name, $value ) { | |
| 61 | - if ( ! headers_sent() && session_status() == PHP_SESSION_NONE ) { | |
| 62 | - session_start(); | |
| 63 | - $_SESSION[ $name ] = $value; | |
| 64 | - } else { | |
| 65 | - $_SESSION[ $name ] = $value; | |
| 66 | - } | |
| 67 | - } | |
| 68 | - /** | |
| 69 | - * Get Cookie or Session | |
| 70 | - * | |
| 71 | - * @param $name | |
| 72 | - * | |
| 73 | - * @return bool | |
| 74 | - */ | |
| 75 | - public static function getSession( $name ) { | |
| 76 | - if ( ! headers_sent() && session_status() == PHP_SESSION_NONE ) { | |
| 77 | - session_start(); | |
| 78 | - } | |
| 79 | - return $_SESSION[ $name ] ?? null; | |
| 80 | - } | |
| 81 | - /** | |
| 82 | - * Remove Session Variable | |
| 83 | - * | |
| 84 | - * @param string $name The name of the session variable to remove. | |
| 85 | - */ | |
| 86 | - public static function removeSession( $name ) { | |
| 87 | - if ( ! headers_sent() && session_status() == PHP_SESSION_NONE ) { | |
| 88 | - session_start(); | |
| 89 | - unset( $_SESSION[ $name ] ); | |
| 90 | - } else { | |
| 91 | - unset( $_SESSION[ $name ] ); | |
| 92 | - } | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | 49 | * @param $plugin_slug |
| 97 | 50 | * |
| 98 | 51 | * @return bool |
| 99 | 52 | */ |
| @@ -167,15 +120,14 @@ | ||
| 167 | 120 | |
| 168 | 121 | /** |
| 169 | 122 | * @param string $template_name Template name. |
| 170 | 123 | * @param string $template_path Template path. (default: ''). |
| 171 | - * @param string $plugin_path Plugin path. (default: ''). fallback file from plugin. | |
| 124 | + * @param string $plugin_path Plugin path. (default: ''). fallback file from plugin | |
| 172 | 125 | * |
| 173 | 126 | * @return mixed|void |
| 174 | 127 | */ |
| 175 | 128 | public static function locate_template( $template_name, $template_path = '', $plugin_path = '' ) { |
| 176 | - $template_name = self::sanitize_file_name( $template_name ) . '.php'; | |
| 177 | - | |
| 129 | + $template_name = $template_name . '.php'; | |
| 178 | 130 | if ( ! $template_path ) { |
| 179 | 131 | $template_path = rtsb()->get_template_path(); |
| 180 | 132 | } |
| 181 | 133 | if ( ! $plugin_path ) { |
| @@ -218,19 +170,8 @@ | ||
| 218 | 170 | return apply_filters( 'rtsb/core/locate_template', $located, $template_name ); |
| 219 | 171 | } |
| 220 | 172 | |
| 221 | 173 | /** |
| 222 | - * Remove any character that is not alphanumeric, /, _, or -. | |
| 223 | - * | |
| 224 | - * @param string $name Name to sanitize. | |
| 225 | - * | |
| 226 | - * @return array|string|string[]|null | |
| 227 | - */ | |
| 228 | - private static function sanitize_file_name( $name ) { | |
| 229 | - return preg_replace( '/[^a-zA-Z0-9\/_\-]/', '', $name ); | |
| 230 | - } | |
| 231 | - | |
| 232 | - /** | |
| 233 | 174 | * Template Content |
| 234 | 175 | * |
| 235 | 176 | * @param string $template_name Template name. |
| 236 | 177 | * @param array $args Arguments. (default: array). |
| @@ -240,19 +181,10 @@ | ||
| 240 | 181 | * |
| 241 | 182 | * @return false|string|void |
| 242 | 183 | */ |
| 243 | 184 | public static function load_template( $template_name, array $args = null, $return = false, $template_path = '', $plugin_path = '' ) { |
| 244 | - $cache_key = sanitize_key( implode( '-', [ 'template', $template_name, $template_path ] ) ); | |
| 245 | - $located = (string) wp_cache_get( $cache_key, 'shopbuilder' ); | |
| 246 | - if ( ! $located ) { | |
| 247 | - $located = self::locate_template( $template_name, $template_path, $plugin_path ); | |
| 248 | - // Don't cache the absolute path so that it can be shared between web servers with different paths. | |
| 249 | - $cache_path = wc_tokenize_path( $located, wc_get_path_define_tokens() ); | |
| 250 | - Cache::set_template_cache( $cache_key, $cache_path ); | |
| 251 | - } else { | |
| 252 | - // Make sure that the absolute path to the template is resolved. | |
| 253 | - $located = wc_untokenize_path( $located, wc_get_path_define_tokens() ); | |
| 254 | - } | |
| 185 | + $located = self::locate_template( $template_name, $template_path, $plugin_path ); | |
| 186 | + | |
| 255 | 187 | if ( ! file_exists( $located ) ) { |
| 256 | 188 | // translators: %s template. |
| 257 | 189 | self::doing_it_wrong( __FUNCTION__, sprintf( __( '%s does not exist.', 'shopbuilder' ), '<code>' . $located . '</code>' ), '1.0' ); |
| 258 | 190 | |
| @@ -384,16 +316,15 @@ | ||
| 384 | 316 | } |
| 385 | 317 | |
| 386 | 318 | global $wpdb; |
| 387 | 319 | $cache_key = 'rtsb_prepared_product_id'; |
| 388 | - $_post_id = wp_cache_get( $cache_key, 'shopbuilder' ); | |
| 320 | + $_post_id = wp_cache_get( $cache_key ); | |
| 321 | + | |
| 389 | 322 | if ( false === $_post_id || 'publish' !== get_post_status( $_post_id ) ) { |
| 390 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 391 | 323 | $_post_id = $wpdb->get_var( |
| 392 | 324 | $wpdb->prepare( "SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_status IN('publish', 'draft')", 'product' ) |
| 393 | 325 | ); |
| 394 | - wp_cache_set( $cache_key, $_post_id, 'shopbuilder', 12 * HOUR_IN_SECONDS ); | |
| 395 | - Cache::set_data_cache_key( $cache_key ); | |
| 326 | + wp_cache_set( $cache_key, $_post_id, '', 12 * HOUR_IN_SECONDS ); | |
| 396 | 327 | } |
| 397 | 328 | |
| 398 | 329 | return $_post_id; |
| 399 | 330 | } |
| @@ -406,9 +337,9 @@ | ||
| 406 | 337 | public static function get_product() { |
| 407 | 338 | global $product; |
| 408 | 339 | |
| 409 | 340 | if ( is_singular( 'product' ) && $product instanceof WC_Product ) { |
| 410 | - // do_action( 'rtsb_before_product_template_render' );. | |
| 341 | + do_action( 'rtsb_before_product_template_render' ); | |
| 411 | 342 | return $product; |
| 412 | 343 | } |
| 413 | 344 | $cache_key = 'prepared_product_for_preview'; |
| 414 | 345 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| @@ -413,8 +344,9 @@ | ||
| 413 | 344 | $cache_key = 'prepared_product_for_preview'; |
| 414 | 345 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 415 | 346 | return self::$cache[ $cache_key ]; |
| 416 | 347 | } |
| 348 | + | |
| 417 | 349 | $product = wc_get_product( self::get_prepared_product_id() ); |
| 418 | 350 | self::$cache[ $cache_key ] = $product; |
| 419 | 351 | do_action( 'rtsb_before_product_template_render' ); |
| 420 | 352 | return $product; |
| @@ -430,9 +362,9 @@ | ||
| 430 | 362 | * @return void |
| 431 | 363 | */ |
| 432 | 364 | public static function doing_it_wrong( $function, $message, $version ) { |
| 433 | 365 | $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
| 434 | - _doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) ); | |
| 366 | + _doing_it_wrong( $function, $message, $version ); | |
| 435 | 367 | } |
| 436 | 368 | |
| 437 | 369 | /** |
| 438 | 370 | * @return array |
| @@ -563,14 +495,13 @@ | ||
| 563 | 495 | } |
| 564 | 496 | |
| 565 | 497 | if ( strlen( $page_content ) > 0 ) { |
| 566 | 498 | // Search for an existing page with the specified page content (typically a shortcode). |
| 567 | - $shortcode = str_replace( [ '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ], '', $page_content ); | |
| 568 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 499 | + $shortcode = str_replace( [ '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ], '', $page_content ); | |
| 569 | 500 | $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$shortcode}%" ) ); |
| 570 | 501 | } else { |
| 571 | 502 | // Search for an existing page with the specified page slug. |
| 572 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 503 | + $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); | |
| 573 | 504 | } |
| 574 | 505 | |
| 575 | 506 | $valid_page_found = apply_filters( 'rtsb/core/create_page_id', $valid_page_found, $slug, $page_content, $options ); |
| 576 | 507 | |
| @@ -592,12 +523,12 @@ | ||
| 592 | 523 | |
| 593 | 524 | // Search for a matching valid trashed page. |
| 594 | 525 | if ( strlen( $page_content ) > 0 ) { |
| 595 | 526 | // Search for an existing page with the specified page content (typically a shortcode). |
| 596 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 527 | + $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); | |
| 597 | 528 | } else { |
| 598 | 529 | // Search for an existing page with the specified page slug. |
| 599 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 530 | + $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); | |
| 600 | 531 | } |
| 601 | 532 | |
| 602 | 533 | if ( $trashed_page_found ) { |
| 603 | 534 | $page_id = $trashed_page_found; |
| @@ -1099,14 +1030,9 @@ | ||
| 1099 | 1030 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 1100 | 1031 | return self::$cache[ $cache_key ]; |
| 1101 | 1032 | } |
| 1102 | 1033 | |
| 1103 | - $termList = get_terms( | |
| 1104 | - [ | |
| 1105 | - 'taxonomy' => $taxonomy, | |
| 1106 | - 'hide_empty' => false, | |
| 1107 | - ] | |
| 1108 | - ); | |
| 1034 | + $termList = get_terms( [ $taxonomy ], [ 'hide_empty' => 0 ] ); | |
| 1109 | 1035 | |
| 1110 | 1036 | if ( is_array( $termList ) && ! empty( $termList ) && empty( $termList['errors'] ) ) { |
| 1111 | 1037 | if ( $placeholder ) { |
| 1112 | 1038 | $terms = [ |
| @@ -1135,9 +1061,9 @@ | ||
| 1135 | 1061 | |
| 1136 | 1062 | if ( $attributes ) { |
| 1137 | 1063 | foreach ( $attributes as $tax ) { |
| 1138 | 1064 | if ( taxonomy_exists( wc_attribute_taxonomy_name( $tax->attribute_name ) ) ) { |
| 1139 | - $termList[ $tax->attribute_name ] = get_terms( wc_attribute_taxonomy_name( $tax->attribute_name ) ); | |
| 1065 | + $termList[ $tax->attribute_name ] = get_terms( wc_attribute_taxonomy_name( $tax->attribute_name ), 'orderby=name&hide_empty=0' ); | |
| 1140 | 1066 | } |
| 1141 | 1067 | } |
| 1142 | 1068 | } |
| 1143 | 1069 | |
| @@ -1332,23 +1258,8 @@ | ||
| 1332 | 1258 | |
| 1333 | 1259 | self::print_html( $html, true ); |
| 1334 | 1260 | } |
| 1335 | 1261 | |
| 1336 | - public static function get_product_simple_rating_html() { | |
| 1337 | - global $product; | |
| 1338 | - $html = null; | |
| 1339 | - $rating_count = $product->get_rating_count(); | |
| 1340 | - $average_rating = $product->get_average_rating(); | |
| 1341 | - $html .= '<div class="product-rating">'; | |
| 1342 | - $html .= wc_get_rating_html( $average_rating, $rating_count ); | |
| 1343 | - $html .= ! empty( $html ) ? '<span class="rtsb-count">(' . $average_rating . ')</span>' : ''; | |
| 1344 | - $html .= '</div>'; | |
| 1345 | - | |
| 1346 | - self::print_html( $html, true ); | |
| 1347 | - } | |
| 1348 | - | |
| 1349 | - | |
| 1350 | - | |
| 1351 | 1262 | /** |
| 1352 | 1263 | * Text truncation. |
| 1353 | 1264 | * |
| 1354 | 1265 | * @param string $text_to_truncate Text. |
| @@ -1391,14 +1302,8 @@ | ||
| 1391 | 1302 | * |
| 1392 | 1303 | * @return void |
| 1393 | 1304 | */ |
| 1394 | 1305 | public static function get_badge_html( $text, $class = 'fill' ) { |
| 1395 | - if ( self::is_module_active( 'product_badges' ) && 'rtsb_yes' === $text ) { | |
| 1396 | - do_action( 'rtsb/modules/product_badges/frontend/display' ); | |
| 1397 | - | |
| 1398 | - return; | |
| 1399 | - } | |
| 1400 | - | |
| 1401 | 1306 | if ( empty( $text ) ) { |
| 1402 | 1307 | return; |
| 1403 | 1308 | } |
| 1404 | 1309 | ob_start(); |
| @@ -1405,9 +1310,10 @@ | ||
| 1405 | 1310 | ?> |
| 1406 | 1311 | |
| 1407 | 1312 | <ul class="rtsb-promotion-list"> |
| 1408 | 1313 | <li class="rtsb-promotion-list-item"> |
| 1409 | - <span class="rtsb-tag-<?php echo ! empty( $class ) ? esc_attr( $class ) : ''; ?>"><?php echo esc_html( $text ); ?></span> | |
| 1314 | + <span | |
| 1315 | + class="rtsb-tag-<?php echo ! empty( $class ) ? esc_attr( $class ) : ''; ?>"><?php echo esc_html( $text ); ?></span> | |
| 1410 | 1316 | </li> |
| 1411 | 1317 | </ul> |
| 1412 | 1318 | |
| 1413 | 1319 | <?php |
| @@ -1785,12 +1691,8 @@ | ||
| 1785 | 1691 | if ( ! $product instanceof WC_Product ) { |
| 1786 | 1692 | return ''; |
| 1787 | 1693 | } |
| 1788 | 1694 | |
| 1789 | - if ( ! $product->is_on_sale() ) { | |
| 1790 | - return ''; | |
| 1791 | - } | |
| 1792 | - | |
| 1793 | 1695 | $percentage = null; |
| 1794 | 1696 | $max_percentage = ''; |
| 1795 | 1697 | |
| 1796 | 1698 | if ( $product->is_type( 'simple' ) ) { |
| @@ -1831,10 +1733,10 @@ | ||
| 1831 | 1733 | * |
| 1832 | 1734 | * @return string |
| 1833 | 1735 | */ |
| 1834 | 1736 | public static function custom_pagination( $pages = '', $range = 4, $ajax = false ) { |
| 1835 | - $html = null; | |
| 1836 | - $visible_range = apply_filters( 'rtsb/elements/pagination/visible_range', ( $range * 2 ) + 1 ); | |
| 1737 | + $html = null; | |
| 1738 | + $showitems = ( $range * 2 ) + 1; | |
| 1837 | 1739 | |
| 1838 | 1740 | global $paged; |
| 1839 | 1741 | |
| 1840 | 1742 | if ( is_front_page() ) { |
| @@ -1862,9 +1764,8 @@ | ||
| 1862 | 1764 | |
| 1863 | 1765 | if ( $ajax ) { |
| 1864 | 1766 | $ajaxClass = ' rtsb-pagination-ajax'; |
| 1865 | 1767 | $dataAttr = "data-paged='1'"; |
| 1866 | - $dataAttr .= ' data-visible-range="' . esc_attr( $visible_range ) . '"'; | |
| 1867 | 1768 | } |
| 1868 | 1769 | |
| 1869 | 1770 | if ( 1 !== $pages ) { |
| 1870 | 1771 | $html .= '<div class="rtsb-pagination' . $ajaxClass . '" ' . $dataAttr . '>'; |
| @@ -1869,29 +1770,29 @@ | ||
| 1869 | 1770 | if ( 1 !== $pages ) { |
| 1870 | 1771 | $html .= '<div class="rtsb-pagination' . $ajaxClass . '" ' . $dataAttr . '>'; |
| 1871 | 1772 | $html .= '<ul class="pagination-list">'; |
| 1872 | 1773 | |
| 1873 | - if ( $paged > 2 && $paged > $visible_range + 1 && $visible_range < $pages ) { | |
| 1774 | + if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages ) { | |
| 1874 | 1775 | $html .= "<li><a data-paged='1' href='" . get_pagenum_link( 1 ) . "' aria-label='First'>«</a></li>"; |
| 1875 | 1776 | } |
| 1876 | 1777 | |
| 1877 | - if ( $paged > 1 && $visible_range < $pages ) { | |
| 1778 | + if ( $paged > 1 && $showitems < $pages ) { | |
| 1878 | 1779 | $p = $paged - 1; |
| 1879 | 1780 | $html .= "<li><a data-paged='{$p}' href='" . get_pagenum_link( $p ) . "' aria-label='Previous'>‹</a></li>"; |
| 1880 | 1781 | } |
| 1881 | 1782 | |
| 1882 | 1783 | for ( $i = 1; $i <= $pages; $i++ ) { |
| 1883 | - if ( 1 != $pages && ( ! ( $i >= $paged + $visible_range + 1 || $i <= $paged - $visible_range - 1 ) || $pages <= $visible_range ) ) { | |
| 1784 | + if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) { | |
| 1884 | 1785 | $html .= ( $paged == $i ) ? '<li class="active"><span>' . $i . '</span></li>' : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . '</a></li>'; |
| 1885 | 1786 | } |
| 1886 | 1787 | } |
| 1887 | 1788 | |
| 1888 | - if ( $paged < $pages && $visible_range < $pages ) { | |
| 1789 | + if ( $paged < $pages && $showitems < $pages ) { | |
| 1889 | 1790 | $p = $paged + 1; |
| 1890 | 1791 | $html .= "<li><a data-paged='{$p}' href=\"" . get_pagenum_link( $paged + 1 ) . "\" aria-label='Next'>›</a></li>"; |
| 1891 | 1792 | } |
| 1892 | 1793 | |
| 1893 | - if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $visible_range < $pages ) { | |
| 1794 | + if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages ) { | |
| 1894 | 1795 | $html .= "<li><a data-paged='{$pages}' href='" . get_pagenum_link( $pages ) . "' aria-label='Last'>»</a></li>"; |
| 1895 | 1796 | } |
| 1896 | 1797 | |
| 1897 | 1798 | $html .= '</ul>'; |
| @@ -2249,8 +2150,9 @@ | ||
| 2249 | 2150 | return true; |
| 2250 | 2151 | } |
| 2251 | 2152 | } |
| 2252 | 2153 | |
| 2154 | + | |
| 2253 | 2155 | /*** |
| 2254 | 2156 | * Save Settings data |
| 2255 | 2157 | * |
| 2256 | 2158 | * @param $section_id |
| @@ -2262,9 +2164,10 @@ | ||
| 2262 | 2164 | public static function set_options( $section_id = '', $block_id = '', $rawOptions = [] ) { |
| 2263 | 2165 | $section_id = ! empty( $section_id ) ? sanitize_text_field( wp_unslash( $section_id ) ) : ''; |
| 2264 | 2166 | $block_id = ! empty( $block_id ) ? sanitize_text_field( wp_unslash( $block_id ) ) : ''; |
| 2265 | 2167 | $rawOptions = ! empty( $rawOptions ) ? $rawOptions : []; |
| 2266 | - $results = [ | |
| 2168 | + | |
| 2169 | + $results = [ | |
| 2267 | 2170 | 'status' => true, |
| 2268 | 2171 | 'message' => '', |
| 2269 | 2172 | ]; |
| 2270 | 2173 | if ( ! $section_id || ! $block_id ) { |
| @@ -2280,9 +2183,9 @@ | ||
| 2280 | 2183 | |
| 2281 | 2184 | return $results; |
| 2282 | 2185 | } |
| 2283 | 2186 | |
| 2284 | - $options = DataModel::source()->get_option( $section_id, [], false ); | |
| 2187 | + $options = DataModel::source()->get_option( $section_id, [] ); | |
| 2285 | 2188 | $changed = false; |
| 2286 | 2189 | $fields = []; |
| 2287 | 2190 | if ( isset( $sections[ $section_id ]['list'][ $block_id ]['fields'] ) && ! empty( $sections[ $section_id ]['list'][ $block_id ]['fields'] ) ) { |
| 2288 | 2191 | $fields = $sections[ $section_id ]['list'][ $block_id ]['fields']; |
| @@ -2303,26 +2206,12 @@ | ||
| 2303 | 2206 | $field = $fields[ $raw_option_key ]; |
| 2304 | 2207 | if ( $field['type'] === 'switch' ) { |
| 2305 | 2208 | $value = 'on' === $raw_value ? 'on' : ''; |
| 2306 | 2209 | } elseif ( 'repeaters' === $field['type'] ) { |
| 2307 | - $the_value = []; | |
| 2308 | - $rep_title = []; | |
| 2309 | - if ( ! empty( $raw_value ) && is_array( $raw_value ) ) { | |
| 2310 | - foreach ( $raw_value as $key => $value ) { | |
| 2311 | - $the_value_decoded = json_decode( stripslashes_deep( $value ) ); | |
| 2312 | - $cr = $the_value_decoded->title ?? ''; | |
| 2313 | - if ( in_array( $cr, $rep_title, true ) ) { | |
| 2314 | - continue; | |
| 2315 | - } | |
| 2316 | - $rep_title[] = $cr; | |
| 2317 | - $the_value[] = $the_value_decoded; | |
| 2318 | - } | |
| 2319 | - } elseif ( ! empty( $raw_value ) && is_string( $raw_value ) ) { | |
| 2320 | - $the_value = $raw_value; | |
| 2321 | - } | |
| 2322 | - $value = wp_json_encode( $the_value ); | |
| 2210 | + $value = stripslashes_deep( $raw_value ); | |
| 2323 | 2211 | } else { |
| 2324 | 2212 | if ( ! empty( $field['multiple'] ) || in_array( $field['type'], [ 'checkbox', 'search_and_multi_select' ] ) ) { |
| 2213 | + | |
| 2325 | 2214 | if ( isset( $raw_value ) && is_array( $raw_value ) ) { |
| 2326 | 2215 | if ( ! empty( $field['sanitize_fn'] ) && is_callable( $field['sanitize_fn'] ) ) { |
| 2327 | 2216 | $value = array_map( $field['sanitize_fn'], $raw_value ); |
| 2328 | 2217 | } else { |
| @@ -2331,16 +2220,10 @@ | ||
| 2331 | 2220 | } else { |
| 2332 | 2221 | $value = []; |
| 2333 | 2222 | } |
| 2334 | 2223 | } else { |
| 2335 | - if ( ! empty( $field['sanitize_fn'] ) ) { | |
| 2336 | - if ( is_callable( $field['sanitize_fn'] ) ) { | |
| 2337 | - $value = $field['sanitize_fn']( $raw_value ); | |
| 2338 | - } elseif ( 'pass_all' === $field['sanitize_fn'] ) { | |
| 2339 | - $value = $raw_value; | |
| 2340 | - } else { | |
| 2341 | - $value = $field['sanitize_fn']( $raw_value ); | |
| 2342 | - } | |
| 2224 | + if ( ! empty( $field['sanitize_fn'] ) && is_callable( $field['sanitize_fn'] ) ) { | |
| 2225 | + $value = $field['sanitize_fn']( $raw_value ); | |
| 2343 | 2226 | } else { |
| 2344 | 2227 | $value = sanitize_text_field( $raw_value ); |
| 2345 | 2228 | } |
| 2346 | 2229 | } |
| @@ -2386,8 +2269,9 @@ | ||
| 2386 | 2269 | * } |
| 2387 | 2270 | * return; |
| 2388 | 2271 | * } |
| 2389 | 2272 | */ |
| 2273 | + | |
| 2390 | 2274 | public static function count_products_by_taxonomies( $terms, $taxonomy = 'product_cat' ) { |
| 2391 | 2275 | if ( empty( $terms ) || ! is_array( $terms ) ) { |
| 2392 | 2276 | return; |
| 2393 | 2277 | } |
| @@ -2403,8 +2287,9 @@ | ||
| 2403 | 2287 | $args['product_tag_id'] = $terms; |
| 2404 | 2288 | } |
| 2405 | 2289 | |
| 2406 | 2290 | $query = new WC_Product_Query( $args ); |
| 2291 | + | |
| 2407 | 2292 | return ! empty( $query->get_products() ) ? count( $query->get_products() ) : 0; |
| 2408 | 2293 | } |
| 2409 | 2294 | |
| 2410 | 2295 | /** |
| @@ -2422,12 +2307,9 @@ | ||
| 2422 | 2307 | if ( 'page' === get_post_type() ) { |
| 2423 | 2308 | return false; |
| 2424 | 2309 | } |
| 2425 | 2310 | |
| 2426 | - $id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_type( $page ); | |
| 2427 | - if ( ! $id ) { | |
| 2428 | - return false; | |
| 2429 | - } | |
| 2311 | + $id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_type( $page ); | |
| 2430 | 2312 | $cache_key = 'product_filters_has_ajax_' . $id; |
| 2431 | 2313 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 2432 | 2314 | return self::$cache[ $cache_key ]; |
| 2433 | 2315 | } |
| @@ -2436,9 +2318,8 @@ | ||
| 2436 | 2318 | |
| 2437 | 2319 | foreach ( $elmap->get_widget_data( 'rtsb-ajax-product-filters', [], $id ) as $data ) { |
| 2438 | 2320 | $ajax[] = isset( $data['settings']['ajax_mode'] ) ? false : true; |
| 2439 | 2321 | } |
| 2440 | - | |
| 2441 | 2322 | self::$cache[ $cache_key ] = ! empty( $ajax[0] ); |
| 2442 | 2323 | return ! empty( $ajax[0] ); |
| 2443 | 2324 | } |
| 2444 | 2325 | |
| @@ -2456,11 +2337,9 @@ | ||
| 2456 | 2337 | |
| 2457 | 2338 | $id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_type( $page ); |
| 2458 | 2339 | $elmap = ElementorDataMap::instance(); |
| 2459 | 2340 | $ajax = []; |
| 2460 | - if ( ! $id ) { | |
| 2461 | - return false; | |
| 2462 | - } | |
| 2341 | + | |
| 2463 | 2342 | foreach ( $elmap->get_widget_data( 'rtsb-ajax-product-filters', [], $id ) as $data ) { |
| 2464 | 2343 | $ajax[] = ! isset( $data['settings']['active_filter'] ); |
| 2465 | 2344 | |
| 2466 | 2345 | } |
| @@ -2484,9 +2363,11 @@ | ||
| 2484 | 2363 | |
| 2485 | 2364 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 2486 | 2365 | return self::$cache[ $cache_key ]; |
| 2487 | 2366 | } |
| 2488 | - $results = wp_cache_get( $cache_key, 'shopbuilder' ); | |
| 2367 | + | |
| 2368 | + $results = wp_cache_get( $cache_key ); | |
| 2369 | + | |
| 2489 | 2370 | if ( ! $results ) { |
| 2490 | 2371 | global $wpdb; |
| 2491 | 2372 | $sql = "SELECT t.term_id, t.name |
| 2492 | 2373 | FROM {$wpdb->terms} t |
| @@ -2491,20 +2372,17 @@ | ||
| 2491 | 2372 | $sql = "SELECT t.term_id, t.name |
| 2492 | 2373 | FROM {$wpdb->terms} t |
| 2493 | 2374 | JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id |
| 2494 | 2375 | WHERE tt.taxonomy = 'product_cat'"; |
| 2495 | - | |
| 2496 | 2376 | if ( $search_query ) { |
| 2497 | 2377 | $sql .= ' AND t.name LIKE %s'; |
| 2498 | - $prepared_sql = $wpdb->prepare( $sql, '%' . $wpdb->esc_like( $search_query ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 2378 | + $prepared_sql = $wpdb->prepare( $sql, '%' . $wpdb->esc_like( $search_query ) . '%' ); // Escaping and wildcard | |
| 2499 | 2379 | } else { |
| 2500 | - $prepared_sql = $sql; // No need for placeholders. | |
| 2380 | + $prepared_sql = $sql; // No need for placeholders | |
| 2501 | 2381 | } |
| 2502 | - | |
| 2503 | - $results = $wpdb->get_results( $prepared_sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared | |
| 2504 | - // Cache the results in the object cache for future use. | |
| 2505 | - wp_cache_set( $cache_key, $results, 'shopbuilder' ); // Adjust the expiration time as needed. | |
| 2506 | - Cache::set_data_cache_key( $cache_key ); | |
| 2382 | + $results = $wpdb->get_results( $prepared_sql ); | |
| 2383 | + // Cache the results in the object cache for future use | |
| 2384 | + wp_cache_set( $cache_key, $results ); // Adjust the expiration time as needed | |
| 2507 | 2385 | } |
| 2508 | 2386 | |
| 2509 | 2387 | $cats = []; |
| 2510 | 2388 | if ( ! is_array( $results ) && ! count( $results ) ) { |
| @@ -2519,20 +2397,20 @@ | ||
| 2519 | 2397 | 'label' => $category_title, |
| 2520 | 2398 | ]; |
| 2521 | 2399 | } |
| 2522 | 2400 | |
| 2523 | - // Cache the results in a static variable for the next call. | |
| 2401 | + // Cache the results in a static variable for the next call | |
| 2524 | 2402 | self::$cache[ $cache_key ] = $cats; |
| 2525 | 2403 | return $cats; |
| 2526 | 2404 | } |
| 2527 | 2405 | |
| 2528 | 2406 | /** |
| 2529 | - * @param string $search_query Search query. | |
| 2407 | + * @param $search_query | |
| 2530 | 2408 | * |
| 2531 | 2409 | * @return array |
| 2532 | 2410 | */ |
| 2533 | 2411 | public static function get_registered_post_types( $search_query = null ) { |
| 2534 | - // Get all registered post types. | |
| 2412 | + // Get all registered post types | |
| 2535 | 2413 | $registered_post_types = get_post_types( |
| 2536 | 2414 | [ |
| 2537 | 2415 | 'public' => true, |
| 2538 | 2416 | '_builtin' => false, |
| @@ -2545,11 +2423,11 @@ | ||
| 2545 | 2423 | unset( $registered_post_types['rtsb_builder'] ); |
| 2546 | 2424 | |
| 2547 | 2425 | $post_types = []; |
| 2548 | 2426 | |
| 2549 | - // Check if a search query is provided. | |
| 2427 | + // Check if a search query is provided | |
| 2550 | 2428 | if ( ! empty( $search_query ) ) { |
| 2551 | - // Filter post types based on the search query. | |
| 2429 | + // Filter post types based on the search query | |
| 2552 | 2430 | $registered_post_types = array_filter( |
| 2553 | 2431 | $registered_post_types, |
| 2554 | 2432 | function ( $post_type ) use ( $search_query ) { |
| 2555 | 2433 | return stripos( $post_type->labels->singular_name, $search_query ) !== false; |
| @@ -2554,9 +2432,9 @@ | ||
| 2554 | 2432 | function ( $post_type ) use ( $search_query ) { |
| 2555 | 2433 | return stripos( $post_type->labels->singular_name, $search_query ) !== false; |
| 2556 | 2434 | } |
| 2557 | 2435 | ); |
| 2558 | - // Check if 'post' match the search query and include them if they do. | |
| 2436 | + // Check if 'post' match the search query and include them if they do | |
| 2559 | 2437 | if ( stripos( 'post', $search_query ) !== false ) { |
| 2560 | 2438 | $post_types[] = [ |
| 2561 | 2439 | 'value' => 'post', |
| 2562 | 2440 | 'label' => 'Post', |
| @@ -2568,9 +2446,9 @@ | ||
| 2568 | 2446 | 'label' => 'Post', |
| 2569 | 2447 | ]; |
| 2570 | 2448 | } |
| 2571 | 2449 | |
| 2572 | - // Convert the filtered post types to an array. | |
| 2450 | + // Convert the filtered post types to an array | |
| 2573 | 2451 | foreach ( $registered_post_types as $post_type ) { |
| 2574 | 2452 | $post_types[] = [ |
| 2575 | 2453 | 'value' => $post_type->name, |
| 2576 | 2454 | 'label' => $post_type->labels->singular_name, |
| @@ -2582,9 +2460,9 @@ | ||
| 2582 | 2460 | |
| 2583 | 2461 | /** |
| 2584 | 2462 | * Get Post Types. |
| 2585 | 2463 | * |
| 2586 | - * @param string $search_query Search query. | |
| 2464 | + * @param $search_query | |
| 2587 | 2465 | * |
| 2588 | 2466 | * @return array |
| 2589 | 2467 | */ |
| 2590 | 2468 | public static function get_post_types( $search_query = null, $args = [] ) { |
| @@ -2595,9 +2473,8 @@ | ||
| 2595 | 2473 | 'post_type' => 'any', |
| 2596 | 2474 | 'posts_per_page' => 20, |
| 2597 | 2475 | 'orderby' => 'ID', |
| 2598 | 2476 | 'order' => 'DESC', |
| 2599 | - // 'suppress_filters' => false, // WPML Support, Remove Others Languages. | |
| 2600 | 2477 | ] |
| 2601 | 2478 | ); |
| 2602 | 2479 | |
| 2603 | 2480 | if ( 'archive' !== $args['post_type'] ) { |
| @@ -2608,9 +2485,9 @@ | ||
| 2608 | 2485 | $query_results = get_posts( $args ); |
| 2609 | 2486 | foreach ( $query_results as $post ) { |
| 2610 | 2487 | $posts[] = [ |
| 2611 | 2488 | 'value' => $post->ID, |
| 2612 | - 'label' => $post->post_title . ' ( ID ' . $post->ID . ')', | |
| 2489 | + 'label' => $post->post_title, | |
| 2613 | 2490 | ]; |
| 2614 | 2491 | } |
| 2615 | 2492 | if ( $search_query ) { |
| 2616 | 2493 | if ( strpos( '-error 404', $search_query ) ) { |
| @@ -2672,48 +2549,37 @@ | ||
| 2672 | 2549 | } else { |
| 2673 | 2550 | include $view_file; |
| 2674 | 2551 | } |
| 2675 | 2552 | } |
| 2676 | - | |
| 2677 | - /** | |
| 2678 | - * Best selling product query. | |
| 2679 | - * | |
| 2680 | - * @param int $minimum_sale Minimum sale/ | |
| 2681 | - * @param int $limit Total limit. | |
| 2682 | - * | |
| 2683 | - * @return array|mixed | |
| 2684 | - */ | |
| 2685 | - public static function best_selling_products_ids( $minimum_sale = 1, $limit = 10 ) { | |
| 2686 | - $cache_key = 'rtsb_best_selling_products_' . $minimum_sale . '_' . $limit; | |
| 2687 | - // Check if the data is in the cache. | |
| 2688 | - if ( isset( self::$cache[ $cache_key ] ) ) { | |
| 2689 | - return self::$cache[ $cache_key ]; | |
| 2690 | - } | |
| 2553 | + /** | |
| 2554 | + * @param int $limit Best-selling Base on product Limit. | |
| 2555 | + * @param string $return_type id|Object | |
| 2556 | + * | |
| 2557 | + * @return int | |
| 2558 | + */ | |
| 2559 | + public static function best_selling_products( $limit = 10, $return_type = 'id' ) { | |
| 2560 | + $cache_key = 'best_selling_products' . $return_type . $limit; | |
| 2561 | + // if ( isset( self::$cache[ $cache_key ] ) ) { | |
| 2562 | + // return self::$cache[ $cache_key ]; | |
| 2563 | + // } | |
| 2564 | + // Check if the data is in the cache | |
| 2691 | 2565 | $cached_data = get_transient( $cache_key ); |
| 2692 | 2566 | if ( $cached_data ) { |
| 2693 | - self::$cache[ $cache_key ] = $cached_data; | |
| 2694 | 2567 | return $cached_data; |
| 2695 | 2568 | } |
| 2696 | - global $wpdb; | |
| 2697 | - $sql = $wpdb->prepare( | |
| 2698 | - " | |
| 2699 | - SELECT ID | |
| 2700 | - FROM {$wpdb->posts} AS p | |
| 2701 | - LEFT JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id | |
| 2702 | - WHERE p.post_type = 'product' | |
| 2703 | - AND p.post_status = 'publish' | |
| 2704 | - AND pm.meta_key = 'total_sales' | |
| 2705 | - AND pm.meta_value >= %d | |
| 2706 | - ORDER BY pm.meta_value + 0 DESC | |
| 2707 | - LIMIT %d | |
| 2708 | - ", | |
| 2709 | - $minimum_sale, | |
| 2710 | - $limit | |
| 2711 | - ); | |
| 2712 | - $best_selling = $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared | |
| 2713 | - // Cache the result for future use. | |
| 2569 | + | |
| 2570 | + $args = [ | |
| 2571 | + 'limit' => $limit, | |
| 2572 | + 'orderby' => 'total_sales', | |
| 2573 | + ]; | |
| 2574 | + if ( 'id' === strtolower( $return_type ) ) { | |
| 2575 | + $args['return'] = 'ids'; | |
| 2576 | + } | |
| 2577 | + $best_selling = wc_get_products( $args ); | |
| 2578 | + // self::$cache[ $cache_key ] = $best_selling; | |
| 2579 | + // Cache the result for future use | |
| 2714 | 2580 | set_transient( $cache_key, $best_selling, DAY_IN_SECONDS ); |
| 2715 | - self::$cache[ $cache_key ] = $best_selling; | |
| 2581 | + | |
| 2716 | 2582 | return $best_selling; |
| 2717 | 2583 | } |
| 2718 | 2584 | |
| 2719 | 2585 | /** |
| @@ -2737,229 +2603,19 @@ | ||
| 2737 | 2603 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 2738 | 2604 | return self::$cache[ $cache_key ]; |
| 2739 | 2605 | } |
| 2740 | 2606 | |
| 2741 | - // Get the product publish date. | |
| 2607 | + // Get the product publish date | |
| 2742 | 2608 | $publish_timestamp = strtotime( $product->get_date_created()->date_i18n( 'Y-m-d H:i:s' ) ); |
| 2743 | 2609 | |
| 2744 | - // Calculate the difference in days. | |
| 2610 | + // Calculate the difference in days | |
| 2745 | 2611 | $days_difference = abs( time() - $publish_timestamp ) / ( 60 * 60 * 24 ); |
| 2746 | 2612 | |
| 2747 | - // Check if the product is considered new. | |
| 2613 | + // Check if the product is considered new | |
| 2748 | 2614 | $is_new = $days_difference <= $days_threshold; |
| 2749 | 2615 | |
| 2750 | - // Cache the result for a day. | |
| 2616 | + // Cache the result for a day | |
| 2751 | 2617 | self::$cache[ $cache_key ] = $is_new; |
| 2752 | 2618 | |
| 2753 | 2619 | return $is_new; |
| 2754 | - } | |
| 2755 | - | |
| 2756 | - /** | |
| 2757 | - * Checks if a feature is disabled for guest users based on the provided option. | |
| 2758 | - * | |
| 2759 | - * @param string $option The option to retrieve from the item. | |
| 2760 | - * @param mixed $default The default value if the option is not found. | |
| 2761 | - * | |
| 2762 | - * @return bool | |
| 2763 | - */ | |
| 2764 | - public static function is_guest_feature_disabled( $option, $default ) { | |
| 2765 | - $disabled = self::get_option( 'general', 'guest_user', $option, $default ); | |
| 2766 | - | |
| 2767 | - return ! is_user_logged_in() && $disabled; | |
| 2768 | - } | |
| 2769 | - | |
| 2770 | - /** | |
| 2771 | - * Checks if a feature is disabled for guest users based on the provided option. | |
| 2772 | - * | |
| 2773 | - * @param string $option The option to retrieve from the item. | |
| 2774 | - * @param mixed $default The default value if the option is not found. | |
| 2775 | - * | |
| 2776 | - * @return bool | |
| 2777 | - */ | |
| 2778 | - public static function woocommerce_output_all_notices() { | |
| 2779 | - if ( function_exists( 'wc_print_notices' ) ) : | |
| 2780 | - echo '<div class="rtsb-notice">'; | |
| 2781 | - woocommerce_output_all_notices(); | |
| 2782 | - echo '</div>'; | |
| 2783 | - endif; | |
| 2784 | - } | |
| 2785 | - | |
| 2786 | - /** | |
| 2787 | - * @param object $product Product. | |
| 2788 | - * @return bool | |
| 2789 | - */ | |
| 2790 | - public static function is_visible_qty_input( $product = null ) { | |
| 2791 | - $is_visible_qty = true; | |
| 2792 | - if ( $product instanceof \WC_Product ) { | |
| 2793 | - if ( $product->is_sold_individually() ) { | |
| 2794 | - $is_visible_qty = false; | |
| 2795 | - } elseif ( $product->managing_stock() ) { | |
| 2796 | - if ( in_array( $product->get_backorders(), [ 'notify' , 'yes' ], true ) ) { | |
| 2797 | - $is_visible_qty = true; | |
| 2798 | - } elseif ( $product->get_stock_quantity() < 2 ) { | |
| 2799 | - $is_visible_qty = false; | |
| 2800 | - } | |
| 2801 | - } | |
| 2802 | - } | |
| 2803 | - return $is_visible_qty; | |
| 2804 | - } | |
| 2805 | - | |
| 2806 | - /** | |
| 2807 | - * @param int $object_id Object id. | |
| 2808 | - * @param string $element_type element type. | |
| 2809 | - * @param string|null $current_lang null for current language, default for default languages. | |
| 2810 | - * @return false|mixed|null | |
| 2811 | - */ | |
| 2812 | - public static function wpml_object_id( $object_id, $element_type, $current_lang = 'default' ) { | |
| 2813 | - if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) { | |
| 2814 | - return $object_id; | |
| 2815 | - } | |
| 2816 | - if ( ! $object_id || ! $element_type ) { | |
| 2817 | - return $object_id; | |
| 2818 | - } | |
| 2819 | - if ( 'default' === $current_lang ) { | |
| 2820 | - $lang = apply_filters( 'wpml_default_language', null ); | |
| 2821 | - } else { | |
| 2822 | - $lang = null; | |
| 2823 | - } | |
| 2824 | - return apply_filters( 'wpml_object_id', $object_id, $element_type, false, $lang ); | |
| 2825 | - } | |
| 2826 | - | |
| 2827 | - /** | |
| 2828 | - * @return string | |
| 2829 | - */ | |
| 2830 | - public static function wpml_current_language() { | |
| 2831 | - $current = apply_filters( 'wpml_current_language', null ); | |
| 2832 | - $default = apply_filters( 'wpml_default_language', null ); | |
| 2833 | - return $default !== $current ? $current : null; | |
| 2834 | - } | |
| 2835 | - | |
| 2836 | - /** | |
| 2837 | - * Custom icons. | |
| 2838 | - * | |
| 2839 | - * @return string[] | |
| 2840 | - */ | |
| 2841 | - public static function get_custom_icon_names() { | |
| 2842 | - return [ | |
| 2843 | - 'heart-empty', | |
| 2844 | - 'heart', | |
| 2845 | - 'eye', | |
| 2846 | - 'exchange', | |
| 2847 | - 'plus', | |
| 2848 | - 'minus', | |
| 2849 | - 'avatar', | |
| 2850 | - 'pay', | |
| 2851 | - 'share', | |
| 2852 | - 'clock', | |
| 2853 | - 'check-alt', | |
| 2854 | - 'check', | |
| 2855 | - 'delete', | |
| 2856 | - 'marker', | |
| 2857 | - 'list', | |
| 2858 | - 'list-2', | |
| 2859 | - 'power', | |
| 2860 | - 'cart', | |
| 2861 | - 'cart-2', | |
| 2862 | - 'cart-3', | |
| 2863 | - 'downloads', | |
| 2864 | - 'zoom', | |
| 2865 | - 'user-edit', | |
| 2866 | - 'grid', | |
| 2867 | - 'filter', | |
| 2868 | - 'billing', | |
| 2869 | - 'login', | |
| 2870 | - 'payment', | |
| 2871 | - 'search', | |
| 2872 | - 'edit', | |
| 2873 | - 'coupon', | |
| 2874 | - 'arrows-cw', | |
| 2875 | - 'trash-empty', | |
| 2876 | - ]; | |
| 2877 | - } | |
| 2878 | - | |
| 2879 | - /** | |
| 2880 | - * Flushes rewrite rules. | |
| 2881 | - * | |
| 2882 | - * @return void | |
| 2883 | - */ | |
| 2884 | - public static function maybe_flush_rewrite_rules() { | |
| 2885 | - add_action( 'wp_loaded', [ __CLASS__, 'flush_rewrite_rules' ] ); | |
| 2886 | - add_action( 'shutdown', [ __CLASS__, 'flush_rewrite_rules_once_more' ] ); | |
| 2887 | - } | |
| 2888 | - | |
| 2889 | - /** | |
| 2890 | - * Flushes rewrite rules if needed. | |
| 2891 | - * | |
| 2892 | - * @return void | |
| 2893 | - */ | |
| 2894 | - public static function flush_rewrite_rules() { | |
| 2895 | - if ( get_option( 'rtsb_permalinks_need_flush' ) === 'yes' ) { | |
| 2896 | - flush_rewrite_rules(); | |
| 2897 | - } | |
| 2898 | - | |
| 2899 | - if ( get_option( 'rtsb_permalinks_flushed' ) === 'yes' ) { | |
| 2900 | - flush_rewrite_rules(); | |
| 2901 | - delete_option( 'rtsb_permalinks_flushed' ); | |
| 2902 | - } | |
| 2903 | - } | |
| 2904 | - | |
| 2905 | - /** | |
| 2906 | - * Flushes rewrite rules if needed for second time. | |
| 2907 | - * | |
| 2908 | - * @return void | |
| 2909 | - */ | |
| 2910 | - public static function flush_rewrite_rules_once_more() { | |
| 2911 | - if ( get_option( 'rtsb_permalinks_need_flush' ) === 'yes' ) { | |
| 2912 | - flush_rewrite_rules(); | |
| 2913 | - update_option( 'rtsb_permalinks_flushed', 'yes' ); | |
| 2914 | - delete_option( 'rtsb_permalinks_need_flush' ); | |
| 2915 | - } | |
| 2916 | - } | |
| 2917 | - | |
| 2918 | - /** | |
| 2919 | - * Social Share Platforms. | |
| 2920 | - * | |
| 2921 | - * @return mixed|null | |
| 2922 | - */ | |
| 2923 | - public static function set_repeater_options( $section_id, $block_id, $option_key, $compare_key, $compare_value, $values ) { | |
| 2924 | - // $options = self::get_options( $section_id, $block_id ); | |
| 2925 | - $modules = DataModel::source()->get_option( $section_id, [], false ); | |
| 2926 | - if ( empty( $modules[ $block_id ] ) ) { | |
| 2927 | - return; | |
| 2928 | - } | |
| 2929 | - $options = $modules[ $block_id ]; | |
| 2930 | - if ( empty( $options[ $option_key ] ) ) { | |
| 2931 | - return; | |
| 2932 | - } | |
| 2933 | - $repeater_options = json_decode( $options[ $option_key ], true ); | |
| 2934 | - // Check if options are not empty and are in array format. | |
| 2935 | - if ( ! is_array( $repeater_options ) ) { | |
| 2936 | - return; | |
| 2937 | - } | |
| 2938 | - // Use array_column to get an array of values from $compare_key. | |
| 2939 | - $column_values = array_column( $repeater_options, $compare_key ); | |
| 2940 | - // Use array_search to find the index of the $compare_value. | |
| 2941 | - $index = array_search( $compare_value, $column_values, true ); | |
| 2942 | - if ( false === $index ) { | |
| 2943 | - return; | |
| 2944 | - } | |
| 2945 | - $repeater_options[ $index ] = wp_parse_args( $values, $repeater_options[ $index ] ); | |
| 2946 | - $options[ $option_key ] = wp_json_encode( $repeater_options ); | |
| 2947 | - $modules[ $block_id ] = $options; | |
| 2948 | - DataModel::source()->set_option( $section_id, $modules ); | |
| 2949 | - } | |
| 2950 | - | |
| 2951 | - | |
| 2952 | - /** | |
| 2953 | - * @param array $ids products id. | |
| 2954 | - * @return array | |
| 2955 | - */ | |
| 2956 | - public static function get_available_products_by_ids( $ids = [] ) { | |
| 2957 | - $ids = array_filter( | |
| 2958 | - $ids, | |
| 2959 | - function ( $id ) { | |
| 2960 | - return 'product' === get_post_type( $id ) && 'publish' === get_post_status( $id ); | |
| 2961 | - } | |
| 2962 | - ); | |
| 2963 | - return $ids; | |
| 2964 | 2620 | } |
| 2965 | 2621 | } |