| @@ -44,59 +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 | - //session_write_close(); | |
| 65 | - } else { | |
| 66 | - $_SESSION[ $name ] = $value; | |
| 67 | - } | |
| 68 | - | |
| 69 | - } | |
| 70 | - /** | |
| 71 | - * Get Cookie or Session | |
| 72 | - * | |
| 73 | - * @param $name | |
| 74 | - * | |
| 75 | - * @return bool | |
| 76 | - */ | |
| 77 | - public static function getSession( $name ) { | |
| 78 | - if ( ! headers_sent() && session_status() == PHP_SESSION_NONE ) { | |
| 79 | - session_start(); | |
| 80 | - } | |
| 81 | - return $_SESSION[ $name ] ?? null; | |
| 82 | - } | |
| 83 | - /** | |
| 84 | - * Remove Session Variable | |
| 85 | - * | |
| 86 | - * @param string $name The name of the session variable to remove. | |
| 87 | - */ | |
| 88 | - public static function removeSession( $name ) { | |
| 89 | - if ( ! headers_sent() && session_status() == PHP_SESSION_NONE ) { | |
| 90 | - session_start(); | |
| 91 | - unset( $_SESSION[ $name ] ); | |
| 92 | - //session_write_close(); | |
| 93 | - } else { | |
| 94 | - unset( $_SESSION[ $name ] ); | |
| 95 | - } | |
| 96 | - } | |
| 97 | - | |
| 98 | - /** | |
| 99 | 49 | * @param $plugin_slug |
| 100 | 50 | * |
| 101 | 51 | * @return bool |
| 102 | 52 | */ |
| @@ -369,9 +319,8 @@ | ||
| 369 | 319 | $cache_key = 'rtsb_prepared_product_id'; |
| 370 | 320 | $_post_id = wp_cache_get( $cache_key ); |
| 371 | 321 | |
| 372 | 322 | if ( false === $_post_id || 'publish' !== get_post_status( $_post_id ) ) { |
| 373 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 374 | 323 | $_post_id = $wpdb->get_var( |
| 375 | 324 | $wpdb->prepare( "SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_status IN('publish', 'draft')", 'product' ) |
| 376 | 325 | ); |
| 377 | 326 | wp_cache_set( $cache_key, $_post_id, '', 12 * HOUR_IN_SECONDS ); |
| @@ -388,9 +337,9 @@ | ||
| 388 | 337 | public static function get_product() { |
| 389 | 338 | global $product; |
| 390 | 339 | |
| 391 | 340 | if ( is_singular( 'product' ) && $product instanceof WC_Product ) { |
| 392 | - // do_action( 'rtsb_before_product_template_render' );. | |
| 341 | + do_action( 'rtsb_before_product_template_render' ); | |
| 393 | 342 | return $product; |
| 394 | 343 | } |
| 395 | 344 | $cache_key = 'prepared_product_for_preview'; |
| 396 | 345 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| @@ -395,8 +344,9 @@ | ||
| 395 | 344 | $cache_key = 'prepared_product_for_preview'; |
| 396 | 345 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 397 | 346 | return self::$cache[ $cache_key ]; |
| 398 | 347 | } |
| 348 | + | |
| 399 | 349 | $product = wc_get_product( self::get_prepared_product_id() ); |
| 400 | 350 | self::$cache[ $cache_key ] = $product; |
| 401 | 351 | do_action( 'rtsb_before_product_template_render' ); |
| 402 | 352 | return $product; |
| @@ -412,9 +362,9 @@ | ||
| 412 | 362 | * @return void |
| 413 | 363 | */ |
| 414 | 364 | public static function doing_it_wrong( $function, $message, $version ) { |
| 415 | 365 | $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
| 416 | - _doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) ); | |
| 366 | + _doing_it_wrong( $function, $message, $version ); | |
| 417 | 367 | } |
| 418 | 368 | |
| 419 | 369 | /** |
| 420 | 370 | * @return array |
| @@ -545,14 +495,13 @@ | ||
| 545 | 495 | } |
| 546 | 496 | |
| 547 | 497 | if ( strlen( $page_content ) > 0 ) { |
| 548 | 498 | // Search for an existing page with the specified page content (typically a shortcode). |
| 549 | - $shortcode = str_replace( [ '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ], '', $page_content ); | |
| 550 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 499 | + $shortcode = str_replace( [ '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ], '', $page_content ); | |
| 551 | 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}%" ) ); |
| 552 | 501 | } else { |
| 553 | 502 | // Search for an existing page with the specified page slug. |
| 554 | - $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 ) ); | |
| 555 | 504 | } |
| 556 | 505 | |
| 557 | 506 | $valid_page_found = apply_filters( 'rtsb/core/create_page_id', $valid_page_found, $slug, $page_content, $options ); |
| 558 | 507 | |
| @@ -574,12 +523,12 @@ | ||
| 574 | 523 | |
| 575 | 524 | // Search for a matching valid trashed page. |
| 576 | 525 | if ( strlen( $page_content ) > 0 ) { |
| 577 | 526 | // Search for an existing page with the specified page content (typically a shortcode). |
| 578 | - $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}%" ) ); | |
| 579 | 528 | } else { |
| 580 | 529 | // Search for an existing page with the specified page slug. |
| 581 | - $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 ) ); | |
| 582 | 531 | } |
| 583 | 532 | |
| 584 | 533 | if ( $trashed_page_found ) { |
| 585 | 534 | $page_id = $trashed_page_found; |
| @@ -1081,14 +1030,9 @@ | ||
| 1081 | 1030 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 1082 | 1031 | return self::$cache[ $cache_key ]; |
| 1083 | 1032 | } |
| 1084 | 1033 | |
| 1085 | - $termList = get_terms( | |
| 1086 | - [ | |
| 1087 | - 'taxonomy' => $taxonomy, | |
| 1088 | - 'hide_empty' => false, | |
| 1089 | - ] | |
| 1090 | - ); | |
| 1034 | + $termList = get_terms( [ $taxonomy ], [ 'hide_empty' => 0 ] ); | |
| 1091 | 1035 | |
| 1092 | 1036 | if ( is_array( $termList ) && ! empty( $termList ) && empty( $termList['errors'] ) ) { |
| 1093 | 1037 | if ( $placeholder ) { |
| 1094 | 1038 | $terms = [ |
| @@ -1117,9 +1061,9 @@ | ||
| 1117 | 1061 | |
| 1118 | 1062 | if ( $attributes ) { |
| 1119 | 1063 | foreach ( $attributes as $tax ) { |
| 1120 | 1064 | if ( taxonomy_exists( wc_attribute_taxonomy_name( $tax->attribute_name ) ) ) { |
| 1121 | - $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' ); | |
| 1122 | 1066 | } |
| 1123 | 1067 | } |
| 1124 | 1068 | } |
| 1125 | 1069 | |
| @@ -1314,23 +1258,8 @@ | ||
| 1314 | 1258 | |
| 1315 | 1259 | self::print_html( $html, true ); |
| 1316 | 1260 | } |
| 1317 | 1261 | |
| 1318 | - public static function get_product_simple_rating_html() { | |
| 1319 | - global $product; | |
| 1320 | - $html = null; | |
| 1321 | - $rating_count = $product->get_rating_count(); | |
| 1322 | - $average_rating = $product->get_average_rating(); | |
| 1323 | - $html .= '<div class="product-rating">'; | |
| 1324 | - $html .= wc_get_rating_html( $average_rating, $rating_count ); | |
| 1325 | - $html .= ! empty( $html ) ? '<span class="rtsb-count">(' . $average_rating . ')</span>' : ''; | |
| 1326 | - $html .= '</div>'; | |
| 1327 | - | |
| 1328 | - self::print_html( $html, true ); | |
| 1329 | - } | |
| 1330 | - | |
| 1331 | - | |
| 1332 | - | |
| 1333 | 1262 | /** |
| 1334 | 1263 | * Text truncation. |
| 1335 | 1264 | * |
| 1336 | 1265 | * @param string $text_to_truncate Text. |
| @@ -1373,14 +1302,8 @@ | ||
| 1373 | 1302 | * |
| 1374 | 1303 | * @return void |
| 1375 | 1304 | */ |
| 1376 | 1305 | public static function get_badge_html( $text, $class = 'fill' ) { |
| 1377 | - if ( self::is_module_active( 'product_badges' ) && 'rtsb_yes' === $text ) { | |
| 1378 | - do_action( 'rtsb/modules/product_badges/frontend/display' ); | |
| 1379 | - | |
| 1380 | - return; | |
| 1381 | - } | |
| 1382 | - | |
| 1383 | 1306 | if ( empty( $text ) ) { |
| 1384 | 1307 | return; |
| 1385 | 1308 | } |
| 1386 | 1309 | ob_start(); |
| @@ -1387,9 +1310,10 @@ | ||
| 1387 | 1310 | ?> |
| 1388 | 1311 | |
| 1389 | 1312 | <ul class="rtsb-promotion-list"> |
| 1390 | 1313 | <li class="rtsb-promotion-list-item"> |
| 1391 | - <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> | |
| 1392 | 1316 | </li> |
| 1393 | 1317 | </ul> |
| 1394 | 1318 | |
| 1395 | 1319 | <?php |
| @@ -1767,12 +1691,8 @@ | ||
| 1767 | 1691 | if ( ! $product instanceof WC_Product ) { |
| 1768 | 1692 | return ''; |
| 1769 | 1693 | } |
| 1770 | 1694 | |
| 1771 | - if ( ! $product->is_on_sale() ) { | |
| 1772 | - return ''; | |
| 1773 | - } | |
| 1774 | - | |
| 1775 | 1695 | $percentage = null; |
| 1776 | 1696 | $max_percentage = ''; |
| 1777 | 1697 | |
| 1778 | 1698 | if ( $product->is_type( 'simple' ) ) { |
| @@ -1813,10 +1733,10 @@ | ||
| 1813 | 1733 | * |
| 1814 | 1734 | * @return string |
| 1815 | 1735 | */ |
| 1816 | 1736 | public static function custom_pagination( $pages = '', $range = 4, $ajax = false ) { |
| 1817 | - $html = null; | |
| 1818 | - $visible_range = apply_filters( 'rtsb/elements/pagination/visible_range', ( $range * 2 ) + 1 ); | |
| 1737 | + $html = null; | |
| 1738 | + $showitems = ( $range * 2 ) + 1; | |
| 1819 | 1739 | |
| 1820 | 1740 | global $paged; |
| 1821 | 1741 | |
| 1822 | 1742 | if ( is_front_page() ) { |
| @@ -1844,9 +1764,8 @@ | ||
| 1844 | 1764 | |
| 1845 | 1765 | if ( $ajax ) { |
| 1846 | 1766 | $ajaxClass = ' rtsb-pagination-ajax'; |
| 1847 | 1767 | $dataAttr = "data-paged='1'"; |
| 1848 | - $dataAttr .= ' data-visible-range="' . esc_attr( $visible_range ) . '"'; | |
| 1849 | 1768 | } |
| 1850 | 1769 | |
| 1851 | 1770 | if ( 1 !== $pages ) { |
| 1852 | 1771 | $html .= '<div class="rtsb-pagination' . $ajaxClass . '" ' . $dataAttr . '>'; |
| @@ -1851,29 +1770,29 @@ | ||
| 1851 | 1770 | if ( 1 !== $pages ) { |
| 1852 | 1771 | $html .= '<div class="rtsb-pagination' . $ajaxClass . '" ' . $dataAttr . '>'; |
| 1853 | 1772 | $html .= '<ul class="pagination-list">'; |
| 1854 | 1773 | |
| 1855 | - if ( $paged > 2 && $paged > $visible_range + 1 && $visible_range < $pages ) { | |
| 1774 | + if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages ) { | |
| 1856 | 1775 | $html .= "<li><a data-paged='1' href='" . get_pagenum_link( 1 ) . "' aria-label='First'>«</a></li>"; |
| 1857 | 1776 | } |
| 1858 | 1777 | |
| 1859 | - if ( $paged > 1 && $visible_range < $pages ) { | |
| 1778 | + if ( $paged > 1 && $showitems < $pages ) { | |
| 1860 | 1779 | $p = $paged - 1; |
| 1861 | 1780 | $html .= "<li><a data-paged='{$p}' href='" . get_pagenum_link( $p ) . "' aria-label='Previous'>‹</a></li>"; |
| 1862 | 1781 | } |
| 1863 | 1782 | |
| 1864 | 1783 | for ( $i = 1; $i <= $pages; $i++ ) { |
| 1865 | - 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 ) ) { | |
| 1866 | 1785 | $html .= ( $paged == $i ) ? '<li class="active"><span>' . $i . '</span></li>' : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . '</a></li>'; |
| 1867 | 1786 | } |
| 1868 | 1787 | } |
| 1869 | 1788 | |
| 1870 | - if ( $paged < $pages && $visible_range < $pages ) { | |
| 1789 | + if ( $paged < $pages && $showitems < $pages ) { | |
| 1871 | 1790 | $p = $paged + 1; |
| 1872 | 1791 | $html .= "<li><a data-paged='{$p}' href=\"" . get_pagenum_link( $paged + 1 ) . "\" aria-label='Next'>›</a></li>"; |
| 1873 | 1792 | } |
| 1874 | 1793 | |
| 1875 | - if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $visible_range < $pages ) { | |
| 1794 | + if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages ) { | |
| 1876 | 1795 | $html .= "<li><a data-paged='{$pages}' href='" . get_pagenum_link( $pages ) . "' aria-label='Last'>»</a></li>"; |
| 1877 | 1796 | } |
| 1878 | 1797 | |
| 1879 | 1798 | $html .= '</ul>'; |
| @@ -2231,8 +2150,9 @@ | ||
| 2231 | 2150 | return true; |
| 2232 | 2151 | } |
| 2233 | 2152 | } |
| 2234 | 2153 | |
| 2154 | + | |
| 2235 | 2155 | /*** |
| 2236 | 2156 | * Save Settings data |
| 2237 | 2157 | * |
| 2238 | 2158 | * @param $section_id |
| @@ -2244,9 +2164,10 @@ | ||
| 2244 | 2164 | public static function set_options( $section_id = '', $block_id = '', $rawOptions = [] ) { |
| 2245 | 2165 | $section_id = ! empty( $section_id ) ? sanitize_text_field( wp_unslash( $section_id ) ) : ''; |
| 2246 | 2166 | $block_id = ! empty( $block_id ) ? sanitize_text_field( wp_unslash( $block_id ) ) : ''; |
| 2247 | 2167 | $rawOptions = ! empty( $rawOptions ) ? $rawOptions : []; |
| 2248 | - $results = [ | |
| 2168 | + | |
| 2169 | + $results = [ | |
| 2249 | 2170 | 'status' => true, |
| 2250 | 2171 | 'message' => '', |
| 2251 | 2172 | ]; |
| 2252 | 2173 | if ( ! $section_id || ! $block_id ) { |
| @@ -2262,9 +2183,9 @@ | ||
| 2262 | 2183 | |
| 2263 | 2184 | return $results; |
| 2264 | 2185 | } |
| 2265 | 2186 | |
| 2266 | - $options = DataModel::source()->get_option( $section_id, [], false ); | |
| 2187 | + $options = DataModel::source()->get_option( $section_id, [] ); | |
| 2267 | 2188 | $changed = false; |
| 2268 | 2189 | $fields = []; |
| 2269 | 2190 | if ( isset( $sections[ $section_id ]['list'][ $block_id ]['fields'] ) && ! empty( $sections[ $section_id ]['list'][ $block_id ]['fields'] ) ) { |
| 2270 | 2191 | $fields = $sections[ $section_id ]['list'][ $block_id ]['fields']; |
| @@ -2299,16 +2220,10 @@ | ||
| 2299 | 2220 | } else { |
| 2300 | 2221 | $value = []; |
| 2301 | 2222 | } |
| 2302 | 2223 | } else { |
| 2303 | - if ( ! empty( $field['sanitize_fn'] ) ) { | |
| 2304 | - if ( is_callable( $field['sanitize_fn'] ) ) { | |
| 2305 | - $value = $field['sanitize_fn']( $raw_value ); | |
| 2306 | - } elseif ( 'pass_all' === $field['sanitize_fn'] ) { | |
| 2307 | - $value = $raw_value; | |
| 2308 | - } else { | |
| 2309 | - $value = $field['sanitize_fn']( $raw_value ); | |
| 2310 | - } | |
| 2224 | + if ( ! empty( $field['sanitize_fn'] ) && is_callable( $field['sanitize_fn'] ) ) { | |
| 2225 | + $value = $field['sanitize_fn']( $raw_value ); | |
| 2311 | 2226 | } else { |
| 2312 | 2227 | $value = sanitize_text_field( $raw_value ); |
| 2313 | 2228 | } |
| 2314 | 2229 | } |
| @@ -2354,8 +2269,9 @@ | ||
| 2354 | 2269 | * } |
| 2355 | 2270 | * return; |
| 2356 | 2271 | * } |
| 2357 | 2272 | */ |
| 2273 | + | |
| 2358 | 2274 | public static function count_products_by_taxonomies( $terms, $taxonomy = 'product_cat' ) { |
| 2359 | 2275 | if ( empty( $terms ) || ! is_array( $terms ) ) { |
| 2360 | 2276 | return; |
| 2361 | 2277 | } |
| @@ -2391,12 +2307,9 @@ | ||
| 2391 | 2307 | if ( 'page' === get_post_type() ) { |
| 2392 | 2308 | return false; |
| 2393 | 2309 | } |
| 2394 | 2310 | |
| 2395 | - $id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_type( $page ); | |
| 2396 | - if ( ! $id ) { | |
| 2397 | - return false; | |
| 2398 | - } | |
| 2311 | + $id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_type( $page ); | |
| 2399 | 2312 | $cache_key = 'product_filters_has_ajax_' . $id; |
| 2400 | 2313 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 2401 | 2314 | return self::$cache[ $cache_key ]; |
| 2402 | 2315 | } |
| @@ -2405,9 +2318,8 @@ | ||
| 2405 | 2318 | |
| 2406 | 2319 | foreach ( $elmap->get_widget_data( 'rtsb-ajax-product-filters', [], $id ) as $data ) { |
| 2407 | 2320 | $ajax[] = isset( $data['settings']['ajax_mode'] ) ? false : true; |
| 2408 | 2321 | } |
| 2409 | - | |
| 2410 | 2322 | self::$cache[ $cache_key ] = ! empty( $ajax[0] ); |
| 2411 | 2323 | return ! empty( $ajax[0] ); |
| 2412 | 2324 | } |
| 2413 | 2325 | |
| @@ -2425,11 +2337,9 @@ | ||
| 2425 | 2337 | |
| 2426 | 2338 | $id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_type( $page ); |
| 2427 | 2339 | $elmap = ElementorDataMap::instance(); |
| 2428 | 2340 | $ajax = []; |
| 2429 | - if ( ! $id ) { | |
| 2430 | - return false; | |
| 2431 | - } | |
| 2341 | + | |
| 2432 | 2342 | foreach ( $elmap->get_widget_data( 'rtsb-ajax-product-filters', [], $id ) as $data ) { |
| 2433 | 2343 | $ajax[] = ! isset( $data['settings']['active_filter'] ); |
| 2434 | 2344 | |
| 2435 | 2345 | } |
| @@ -2462,19 +2372,17 @@ | ||
| 2462 | 2372 | $sql = "SELECT t.term_id, t.name |
| 2463 | 2373 | FROM {$wpdb->terms} t |
| 2464 | 2374 | JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id |
| 2465 | 2375 | WHERE tt.taxonomy = 'product_cat'"; |
| 2466 | - | |
| 2467 | 2376 | if ( $search_query ) { |
| 2468 | 2377 | $sql .= ' AND t.name LIKE %s'; |
| 2469 | - $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 | |
| 2470 | 2379 | } else { |
| 2471 | - $prepared_sql = $sql; // No need for placeholders. | |
| 2380 | + $prepared_sql = $sql; // No need for placeholders | |
| 2472 | 2381 | } |
| 2473 | - | |
| 2474 | - $results = $wpdb->get_results( $prepared_sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared | |
| 2475 | - // Cache the results in the object cache for future use. | |
| 2476 | - wp_cache_set( $cache_key, $results ); // Adjust the expiration time as needed. | |
| 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 | |
| 2477 | 2385 | } |
| 2478 | 2386 | |
| 2479 | 2387 | $cats = []; |
| 2480 | 2388 | if ( ! is_array( $results ) && ! count( $results ) ) { |
| @@ -2489,20 +2397,20 @@ | ||
| 2489 | 2397 | 'label' => $category_title, |
| 2490 | 2398 | ]; |
| 2491 | 2399 | } |
| 2492 | 2400 | |
| 2493 | - // Cache the results in a static variable for the next call. | |
| 2401 | + // Cache the results in a static variable for the next call | |
| 2494 | 2402 | self::$cache[ $cache_key ] = $cats; |
| 2495 | 2403 | return $cats; |
| 2496 | 2404 | } |
| 2497 | 2405 | |
| 2498 | 2406 | /** |
| 2499 | - * @param string $search_query Search query. | |
| 2407 | + * @param $search_query | |
| 2500 | 2408 | * |
| 2501 | 2409 | * @return array |
| 2502 | 2410 | */ |
| 2503 | 2411 | public static function get_registered_post_types( $search_query = null ) { |
| 2504 | - // Get all registered post types. | |
| 2412 | + // Get all registered post types | |
| 2505 | 2413 | $registered_post_types = get_post_types( |
| 2506 | 2414 | [ |
| 2507 | 2415 | 'public' => true, |
| 2508 | 2416 | '_builtin' => false, |
| @@ -2515,11 +2423,11 @@ | ||
| 2515 | 2423 | unset( $registered_post_types['rtsb_builder'] ); |
| 2516 | 2424 | |
| 2517 | 2425 | $post_types = []; |
| 2518 | 2426 | |
| 2519 | - // Check if a search query is provided. | |
| 2427 | + // Check if a search query is provided | |
| 2520 | 2428 | if ( ! empty( $search_query ) ) { |
| 2521 | - // Filter post types based on the search query. | |
| 2429 | + // Filter post types based on the search query | |
| 2522 | 2430 | $registered_post_types = array_filter( |
| 2523 | 2431 | $registered_post_types, |
| 2524 | 2432 | function ( $post_type ) use ( $search_query ) { |
| 2525 | 2433 | return stripos( $post_type->labels->singular_name, $search_query ) !== false; |
| @@ -2524,9 +2432,9 @@ | ||
| 2524 | 2432 | function ( $post_type ) use ( $search_query ) { |
| 2525 | 2433 | return stripos( $post_type->labels->singular_name, $search_query ) !== false; |
| 2526 | 2434 | } |
| 2527 | 2435 | ); |
| 2528 | - // 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 | |
| 2529 | 2437 | if ( stripos( 'post', $search_query ) !== false ) { |
| 2530 | 2438 | $post_types[] = [ |
| 2531 | 2439 | 'value' => 'post', |
| 2532 | 2440 | 'label' => 'Post', |
| @@ -2538,9 +2446,9 @@ | ||
| 2538 | 2446 | 'label' => 'Post', |
| 2539 | 2447 | ]; |
| 2540 | 2448 | } |
| 2541 | 2449 | |
| 2542 | - // Convert the filtered post types to an array. | |
| 2450 | + // Convert the filtered post types to an array | |
| 2543 | 2451 | foreach ( $registered_post_types as $post_type ) { |
| 2544 | 2452 | $post_types[] = [ |
| 2545 | 2453 | 'value' => $post_type->name, |
| 2546 | 2454 | 'label' => $post_type->labels->singular_name, |
| @@ -2552,9 +2460,9 @@ | ||
| 2552 | 2460 | |
| 2553 | 2461 | /** |
| 2554 | 2462 | * Get Post Types. |
| 2555 | 2463 | * |
| 2556 | - * @param string $search_query Search query. | |
| 2464 | + * @param $search_query | |
| 2557 | 2465 | * |
| 2558 | 2466 | * @return array |
| 2559 | 2467 | */ |
| 2560 | 2468 | public static function get_post_types( $search_query = null, $args = [] ) { |
| @@ -2565,9 +2473,8 @@ | ||
| 2565 | 2473 | 'post_type' => 'any', |
| 2566 | 2474 | 'posts_per_page' => 20, |
| 2567 | 2475 | 'orderby' => 'ID', |
| 2568 | 2476 | 'order' => 'DESC', |
| 2569 | - // 'suppress_filters' => false, // WPML Support, Remove Others Languages. | |
| 2570 | 2477 | ] |
| 2571 | 2478 | ); |
| 2572 | 2479 | |
| 2573 | 2480 | if ( 'archive' !== $args['post_type'] ) { |
| @@ -2578,9 +2485,9 @@ | ||
| 2578 | 2485 | $query_results = get_posts( $args ); |
| 2579 | 2486 | foreach ( $query_results as $post ) { |
| 2580 | 2487 | $posts[] = [ |
| 2581 | 2488 | 'value' => $post->ID, |
| 2582 | - 'label' => $post->post_title . ' (' . $post->ID . ')', | |
| 2489 | + 'label' => $post->post_title, | |
| 2583 | 2490 | ]; |
| 2584 | 2491 | } |
| 2585 | 2492 | if ( $search_query ) { |
| 2586 | 2493 | if ( strpos( '-error 404', $search_query ) ) { |
| @@ -2642,48 +2549,37 @@ | ||
| 2642 | 2549 | } else { |
| 2643 | 2550 | include $view_file; |
| 2644 | 2551 | } |
| 2645 | 2552 | } |
| 2646 | - | |
| 2647 | - /** | |
| 2648 | - * Best selling product query. | |
| 2649 | - * | |
| 2650 | - * @param int $minimum_sale Minimum sale/ | |
| 2651 | - * @param int $limit Total limit. | |
| 2652 | - * | |
| 2653 | - * @return array|mixed | |
| 2654 | - */ | |
| 2655 | - public static function best_selling_products_ids( $minimum_sale = 1, $limit = 10 ) { | |
| 2656 | - $cache_key = 'rtsb_best_selling_products_' . $minimum_sale . '_' . $limit; | |
| 2657 | - // Check if the data is in the cache. | |
| 2658 | - if ( isset( self::$cache[ $cache_key ] ) ) { | |
| 2659 | - return self::$cache[ $cache_key ]; | |
| 2660 | - } | |
| 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 | |
| 2661 | 2565 | $cached_data = get_transient( $cache_key ); |
| 2662 | 2566 | if ( $cached_data ) { |
| 2663 | - self::$cache[ $cache_key ] = $cached_data; | |
| 2664 | 2567 | return $cached_data; |
| 2665 | 2568 | } |
| 2666 | - global $wpdb; | |
| 2667 | - $sql = $wpdb->prepare( | |
| 2668 | - " | |
| 2669 | - SELECT ID | |
| 2670 | - FROM {$wpdb->posts} AS p | |
| 2671 | - LEFT JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id | |
| 2672 | - WHERE p.post_type = 'product' | |
| 2673 | - AND p.post_status = 'publish' | |
| 2674 | - AND pm.meta_key = 'total_sales' | |
| 2675 | - AND pm.meta_value >= %d | |
| 2676 | - ORDER BY pm.meta_value + 0 DESC | |
| 2677 | - LIMIT %d | |
| 2678 | - ", | |
| 2679 | - $minimum_sale, | |
| 2680 | - $limit | |
| 2681 | - ); | |
| 2682 | - $best_selling = $wpdb->get_col( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared | |
| 2683 | - // 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 | |
| 2684 | 2580 | set_transient( $cache_key, $best_selling, DAY_IN_SECONDS ); |
| 2685 | - self::$cache[ $cache_key ] = $best_selling; | |
| 2581 | + | |
| 2686 | 2582 | return $best_selling; |
| 2687 | 2583 | } |
| 2688 | 2584 | |
| 2689 | 2585 | /** |
| @@ -2707,213 +2603,19 @@ | ||
| 2707 | 2603 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 2708 | 2604 | return self::$cache[ $cache_key ]; |
| 2709 | 2605 | } |
| 2710 | 2606 | |
| 2711 | - // Get the product publish date. | |
| 2607 | + // Get the product publish date | |
| 2712 | 2608 | $publish_timestamp = strtotime( $product->get_date_created()->date_i18n( 'Y-m-d H:i:s' ) ); |
| 2713 | 2609 | |
| 2714 | - // Calculate the difference in days. | |
| 2610 | + // Calculate the difference in days | |
| 2715 | 2611 | $days_difference = abs( time() - $publish_timestamp ) / ( 60 * 60 * 24 ); |
| 2716 | 2612 | |
| 2717 | - // Check if the product is considered new. | |
| 2613 | + // Check if the product is considered new | |
| 2718 | 2614 | $is_new = $days_difference <= $days_threshold; |
| 2719 | 2615 | |
| 2720 | - // Cache the result for a day. | |
| 2616 | + // Cache the result for a day | |
| 2721 | 2617 | self::$cache[ $cache_key ] = $is_new; |
| 2722 | 2618 | |
| 2723 | 2619 | return $is_new; |
| 2724 | - } | |
| 2725 | - | |
| 2726 | - /** | |
| 2727 | - * Checks if a feature is disabled for guest users based on the provided option. | |
| 2728 | - * | |
| 2729 | - * @param string $option The option to retrieve from the item. | |
| 2730 | - * @param mixed $default The default value if the option is not found. | |
| 2731 | - * | |
| 2732 | - * @return bool | |
| 2733 | - */ | |
| 2734 | - public static function is_guest_feature_disabled( $option, $default ) { | |
| 2735 | - $disabled = self::get_option( 'general', 'guest_user', $option, $default ); | |
| 2736 | - | |
| 2737 | - return ! is_user_logged_in() && $disabled; | |
| 2738 | - } | |
| 2739 | - | |
| 2740 | - /** | |
| 2741 | - * Checks if a feature is disabled for guest users based on the provided option. | |
| 2742 | - * | |
| 2743 | - * @param string $option The option to retrieve from the item. | |
| 2744 | - * @param mixed $default The default value if the option is not found. | |
| 2745 | - * | |
| 2746 | - * @return bool | |
| 2747 | - */ | |
| 2748 | - public static function woocommerce_output_all_notices() { | |
| 2749 | - if ( function_exists( 'wc_print_notices' ) ) : | |
| 2750 | - echo '<div class="rtsb-notice">'; | |
| 2751 | - woocommerce_output_all_notices(); | |
| 2752 | - echo '</div>'; | |
| 2753 | - endif; | |
| 2754 | - } | |
| 2755 | - | |
| 2756 | - /** | |
| 2757 | - * @param object $product Product. | |
| 2758 | - * @return bool | |
| 2759 | - */ | |
| 2760 | - public static function is_visible_qty_input( $product = null ) { | |
| 2761 | - $is_visible_qty = true; | |
| 2762 | - if ( $product instanceof \WC_Product ) { | |
| 2763 | - if ( $product->is_sold_individually() ) { | |
| 2764 | - $is_visible_qty = false; | |
| 2765 | - } elseif ( $product->managing_stock() ) { | |
| 2766 | - if ( in_array( $product->get_backorders(), [ 'notify' , 'yes' ], true ) ) { | |
| 2767 | - $is_visible_qty = true; | |
| 2768 | - } elseif ( $product->get_stock_quantity() < 2 ) { | |
| 2769 | - $is_visible_qty = false; | |
| 2770 | - } | |
| 2771 | - } | |
| 2772 | - } | |
| 2773 | - return $is_visible_qty; | |
| 2774 | - } | |
| 2775 | - | |
| 2776 | - /** | |
| 2777 | - * @param int $object_id Object id. | |
| 2778 | - * @param string $element_type element type. | |
| 2779 | - * @param string|null $current_lang null for current language, default for default languages. | |
| 2780 | - * @return false|mixed|null | |
| 2781 | - */ | |
| 2782 | - public static function wpml_object_id( $object_id, $element_type, $current_lang = 'default' ) { | |
| 2783 | - if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) { | |
| 2784 | - return $object_id; | |
| 2785 | - } | |
| 2786 | - if ( ! $object_id || ! $element_type ) { | |
| 2787 | - return $object_id; | |
| 2788 | - } | |
| 2789 | - if ( 'default' === $current_lang ) { | |
| 2790 | - $lang = apply_filters( 'wpml_default_language', null ); | |
| 2791 | - } else { | |
| 2792 | - $lang = null; | |
| 2793 | - } | |
| 2794 | - return apply_filters( 'wpml_object_id', $object_id, $element_type, false, $lang ); | |
| 2795 | - } | |
| 2796 | - | |
| 2797 | - /** | |
| 2798 | - * @return string | |
| 2799 | - */ | |
| 2800 | - public static function wpml_current_language() { | |
| 2801 | - $current = apply_filters( 'wpml_current_language', null ); | |
| 2802 | - $default = apply_filters( 'wpml_default_language', null ); | |
| 2803 | - return $default !== $current ? $current : null; | |
| 2804 | - } | |
| 2805 | - | |
| 2806 | - /** | |
| 2807 | - * Custom icons. | |
| 2808 | - * | |
| 2809 | - * @return string[] | |
| 2810 | - */ | |
| 2811 | - public static function get_custom_icon_names() { | |
| 2812 | - return [ | |
| 2813 | - 'heart-empty', | |
| 2814 | - 'heart', | |
| 2815 | - 'eye', | |
| 2816 | - 'exchange', | |
| 2817 | - 'plus', | |
| 2818 | - 'minus', | |
| 2819 | - 'avatar', | |
| 2820 | - 'pay', | |
| 2821 | - 'share', | |
| 2822 | - 'clock', | |
| 2823 | - 'check-alt', | |
| 2824 | - 'check', | |
| 2825 | - 'delete', | |
| 2826 | - 'marker', | |
| 2827 | - 'list', | |
| 2828 | - 'list-2', | |
| 2829 | - 'power', | |
| 2830 | - 'cart', | |
| 2831 | - 'cart-2', | |
| 2832 | - 'cart-3', | |
| 2833 | - 'downloads', | |
| 2834 | - 'zoom', | |
| 2835 | - 'user-edit', | |
| 2836 | - 'grid', | |
| 2837 | - 'filter', | |
| 2838 | - 'billing', | |
| 2839 | - 'login', | |
| 2840 | - 'payment', | |
| 2841 | - 'search', | |
| 2842 | - 'edit', | |
| 2843 | - 'coupon', | |
| 2844 | - 'arrows-cw', | |
| 2845 | - 'trash-empty', | |
| 2846 | - ]; | |
| 2847 | - } | |
| 2848 | - | |
| 2849 | - /** | |
| 2850 | - * Flushes rewrite rules. | |
| 2851 | - * | |
| 2852 | - * @return void | |
| 2853 | - */ | |
| 2854 | - public static function maybe_flush_rewrite_rules() { | |
| 2855 | - add_action( 'wp_loaded', [ __CLASS__, 'flush_rewrite_rules' ] ); | |
| 2856 | - add_action( 'shutdown', [ __CLASS__, 'flush_rewrite_rules_once_more' ] ); | |
| 2857 | - } | |
| 2858 | - | |
| 2859 | - /** | |
| 2860 | - * Flushes rewrite rules if needed. | |
| 2861 | - * | |
| 2862 | - * @return void | |
| 2863 | - */ | |
| 2864 | - public static function flush_rewrite_rules() { | |
| 2865 | - if ( get_option( 'rtsb_permalinks_need_flush' ) === 'yes' ) { | |
| 2866 | - flush_rewrite_rules(); | |
| 2867 | - } | |
| 2868 | - | |
| 2869 | - if ( get_option( 'rtsb_permalinks_flushed' ) === 'yes' ) { | |
| 2870 | - flush_rewrite_rules(); | |
| 2871 | - delete_option( 'rtsb_permalinks_flushed' ); | |
| 2872 | - } | |
| 2873 | - } | |
| 2874 | - | |
| 2875 | - /** | |
| 2876 | - * Flushes rewrite rules if needed for second time. | |
| 2877 | - * | |
| 2878 | - * @return void | |
| 2879 | - */ | |
| 2880 | - public static function flush_rewrite_rules_once_more() { | |
| 2881 | - if ( get_option( 'rtsb_permalinks_need_flush' ) === 'yes' ) { | |
| 2882 | - flush_rewrite_rules(); | |
| 2883 | - update_option( 'rtsb_permalinks_flushed', 'yes' ); | |
| 2884 | - delete_option( 'rtsb_permalinks_need_flush' ); | |
| 2885 | - } | |
| 2886 | - } | |
| 2887 | - | |
| 2888 | - /** | |
| 2889 | - * Social Share Platforms. | |
| 2890 | - * | |
| 2891 | - * @return mixed|null | |
| 2892 | - */ | |
| 2893 | - public static function set_repeater_options( $section_id, $block_id, $option_key, $compare_key, $compare_value, $values ) { | |
| 2894 | - // $options = self::get_options( $section_id, $block_id ); | |
| 2895 | - $modules = DataModel::source()->get_option( $section_id, [], false ); | |
| 2896 | - if ( empty( $modules[ $block_id ] ) ) { | |
| 2897 | - return; | |
| 2898 | - } | |
| 2899 | - $options = $modules[ $block_id ]; | |
| 2900 | - if ( empty( $options[ $option_key ] ) ) { | |
| 2901 | - return; | |
| 2902 | - } | |
| 2903 | - $repeater_options = json_decode( $options[ $option_key ], true ); | |
| 2904 | - // Check if options are not empty and are in array format. | |
| 2905 | - if ( ! is_array( $repeater_options ) ) { | |
| 2906 | - return; | |
| 2907 | - } | |
| 2908 | - // Use array_column to get an array of values from $compare_key. | |
| 2909 | - $column_values = array_column( $repeater_options, $compare_key ); | |
| 2910 | - // Use array_search to find the index of the $compare_value. | |
| 2911 | - $index = array_search( $compare_value, $column_values, true ); | |
| 2912 | - if ( false === $index ) { | |
| 2913 | - return; | |
| 2914 | - } | |
| 2915 | - $repeater_options[ $index ] = wp_parse_args( $values, $repeater_options[ $index ] ); | |
| 2916 | - $options[ $option_key ] = wp_json_encode( $repeater_options ); | |
| 2917 | - self::set_options( $section_id, $block_id, $options ); | |
| 2918 | 2620 | } |
| 2919 | 2621 | } |