| @@ -45,9 +45,9 @@ | ||
| 45 | 45 | return false; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public static function get_nonce() { |
| 49 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 49 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 50 | 50 | return isset( $_REQUEST[ rtsb()->nonceId ] ) ? sanitize_text_field( $_REQUEST[ rtsb()->nonceId ] ) : null; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
| @@ -60,8 +60,9 @@ | ||
| 60 | 60 | public static function setSession( $name, $value ) { |
| 61 | 61 | if ( ! headers_sent() && session_status() == PHP_SESSION_NONE ) { |
| 62 | 62 | session_start(); |
| 63 | 63 | $_SESSION[ $name ] = $value; |
| 64 | + // session_write_close(); | |
| 64 | 65 | } else { |
| 65 | 66 | $_SESSION[ $name ] = $value; |
| 66 | 67 | } |
| 67 | 68 | } |
| @@ -75,9 +76,9 @@ | ||
| 75 | 76 | public static function getSession( $name ) { |
| 76 | 77 | if ( ! headers_sent() && session_status() == PHP_SESSION_NONE ) { |
| 77 | 78 | session_start(); |
| 78 | 79 | } |
| 79 | - return $_SESSION[ $name ] ?? null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 80 | + return $_SESSION[ $name ] ?? null; | |
| 80 | 81 | } |
| 81 | 82 | /** |
| 82 | 83 | * Remove Session Variable |
| 83 | 84 | * |
| @@ -86,8 +87,9 @@ | ||
| 86 | 87 | public static function removeSession( $name ) { |
| 87 | 88 | if ( ! headers_sent() && session_status() == PHP_SESSION_NONE ) { |
| 88 | 89 | session_start(); |
| 89 | 90 | unset( $_SESSION[ $name ] ); |
| 91 | + // session_write_close(); | |
| 90 | 92 | } else { |
| 91 | 93 | unset( $_SESSION[ $name ] ); |
| 92 | 94 | } |
| 93 | 95 | } |
| @@ -240,19 +242,10 @@ | ||
| 240 | 242 | * |
| 241 | 243 | * @return false|string|void |
| 242 | 244 | */ |
| 243 | 245 | 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 | - } | |
| 246 | + $located = self::locate_template( $template_name, $template_path, $plugin_path ); | |
| 247 | + | |
| 255 | 248 | if ( ! file_exists( $located ) ) { |
| 256 | 249 | // translators: %s template. |
| 257 | 250 | self::doing_it_wrong( __FUNCTION__, sprintf( __( '%s does not exist.', 'shopbuilder' ), '<code>' . $located . '</code>' ), '1.0' ); |
| 258 | 251 | |
| @@ -377,9 +370,9 @@ | ||
| 377 | 370 | // Return the Builder Template id. |
| 378 | 371 | |
| 379 | 372 | if ( get_post_type( get_the_ID() ) == BuilderFns::$post_type_tb ) { |
| 380 | 373 | $product_id = get_post_meta( get_the_ID(), BuilderFns::$product_template_meta, true ); |
| 381 | - if ( $product_id && get_post_status( $product_id ) ) { | |
| 374 | + if ( $product_id ) { | |
| 382 | 375 | return $product_id; |
| 383 | 376 | } |
| 384 | 377 | } |
| 385 | 378 | |
| @@ -384,16 +377,16 @@ | ||
| 384 | 377 | } |
| 385 | 378 | |
| 386 | 379 | global $wpdb; |
| 387 | 380 | $cache_key = 'rtsb_prepared_product_id'; |
| 388 | - $_post_id = wp_cache_get( $cache_key, 'shopbuilder' ); | |
| 381 | + $_post_id = wp_cache_get( $cache_key ); | |
| 382 | + | |
| 389 | 383 | if ( false === $_post_id || 'publish' !== get_post_status( $_post_id ) ) { |
| 390 | 384 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 391 | 385 | $_post_id = $wpdb->get_var( |
| 392 | 386 | $wpdb->prepare( "SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_status IN('publish', 'draft')", 'product' ) |
| 393 | 387 | ); |
| 394 | - wp_cache_set( $cache_key, $_post_id, 'shopbuilder', 12 * HOUR_IN_SECONDS ); | |
| 395 | - Cache::set_data_cache_key( $cache_key ); | |
| 388 | + wp_cache_set( $cache_key, $_post_id, '', 12 * HOUR_IN_SECONDS ); | |
| 396 | 389 | } |
| 397 | 390 | |
| 398 | 391 | return $_post_id; |
| 399 | 392 | } |
| @@ -968,15 +961,13 @@ | ||
| 968 | 961 | return $allowed_html; |
| 969 | 962 | } |
| 970 | 963 | |
| 971 | 964 | /** |
| 972 | - * Safe get a validated HTML tag. | |
| 965 | + * Safe print a validated HTML tag. | |
| 973 | 966 | * |
| 974 | - * @param string $tag HTML tag. | |
| 975 | - * | |
| 976 | - * @return string | |
| 967 | + * @param string $tag | |
| 977 | 968 | */ |
| 978 | - public static function get_validated_html_tag( $tag ) { | |
| 969 | + public static function print_validated_html_tag( $tag ) { | |
| 979 | 970 | $allowed_html_wrapper_tags = [ |
| 980 | 971 | 'a', |
| 981 | 972 | 'article', |
| 982 | 973 | 'aside', |
| @@ -996,23 +987,12 @@ | ||
| 996 | 987 | 'section', |
| 997 | 988 | 'span', |
| 998 | 989 | ]; |
| 999 | 990 | |
| 1000 | - return in_array( strtolower( $tag ), $allowed_html_wrapper_tags, true ) ? $tag : 'div'; | |
| 991 | + self::print_html( in_array( strtolower( $tag ), $allowed_html_wrapper_tags, true ) ? $tag : 'div' ); | |
| 1001 | 992 | } |
| 1002 | 993 | |
| 1003 | 994 | /** |
| 1004 | - * Safe print a validated HTML tag. | |
| 1005 | - * | |
| 1006 | - * @param string $tag HTML tag. | |
| 1007 | - * | |
| 1008 | - * @return void | |
| 1009 | - */ | |
| 1010 | - public static function print_validated_html_tag( $tag ) { | |
| 1011 | - self::print_html( self::get_validated_html_tag( $tag ) ); | |
| 1012 | - } | |
| 1013 | - | |
| 1014 | - /** | |
| 1015 | 995 | * Insert Some array element |
| 1016 | 996 | * |
| 1017 | 997 | * @param [type] $key The elements will insert nearby this key. |
| 1018 | 998 | * @param [type] $main_array Original array. |
| @@ -2316,35 +2296,12 @@ | ||
| 2316 | 2296 | $field = $fields[ $raw_option_key ]; |
| 2317 | 2297 | if ( $field['type'] === 'switch' ) { |
| 2318 | 2298 | $value = 'on' === $raw_value ? 'on' : ''; |
| 2319 | 2299 | } elseif ( 'repeaters' === $field['type'] ) { |
| 2320 | - $the_value = []; | |
| 2321 | - $rep_title = []; | |
| 2322 | - if ( ! empty( $raw_value ) && is_array( $raw_value ) ) { | |
| 2323 | - foreach ( $raw_value as $key => $value ) { | |
| 2324 | - $the_value_decoded = json_decode( stripslashes_deep( $value ) ); | |
| 2325 | - $cr = $the_value_decoded->title ?? ''; | |
| 2326 | - if ( in_array( $cr, $rep_title, true ) ) { | |
| 2327 | - continue; | |
| 2328 | - } | |
| 2329 | - $rep_title[] = $cr; | |
| 2330 | - $the_value[] = $the_value_decoded; | |
| 2331 | - } | |
| 2332 | - } elseif ( ! empty( $raw_value ) && is_string( $raw_value ) ) { | |
| 2333 | - $the_value = $raw_value; | |
| 2334 | - } | |
| 2335 | - $value = wp_json_encode( $the_value ); | |
| 2336 | - } elseif ( 'product_addons_special_settings' === $field['type'] ) { | |
| 2337 | - $paddons_value = []; | |
| 2338 | - // error_log(print_r( $raw_value , true) . "\n\n", 3, __DIR__ . '/log.txt'); | |
| 2339 | - if ( is_array( $raw_value ) ) { | |
| 2340 | - foreach ( $raw_value as $key => $value ) { | |
| 2341 | - $paddons_value[] = json_decode( stripslashes( $value ), true ); | |
| 2342 | - } | |
| 2343 | - } | |
| 2344 | - $value = wp_json_encode( $paddons_value ); | |
| 2300 | + $value = stripslashes_deep( $raw_value ); | |
| 2345 | 2301 | } else { |
| 2346 | 2302 | if ( ! empty( $field['multiple'] ) || in_array( $field['type'], [ 'checkbox', 'search_and_multi_select' ] ) ) { |
| 2303 | + | |
| 2347 | 2304 | if ( isset( $raw_value ) && is_array( $raw_value ) ) { |
| 2348 | 2305 | if ( ! empty( $field['sanitize_fn'] ) && is_callable( $field['sanitize_fn'] ) ) { |
| 2349 | 2306 | $value = array_map( $field['sanitize_fn'], $raw_value ); |
| 2350 | 2307 | } else { |
| @@ -2425,8 +2382,9 @@ | ||
| 2425 | 2382 | $args['product_tag_id'] = $terms; |
| 2426 | 2383 | } |
| 2427 | 2384 | |
| 2428 | 2385 | $query = new WC_Product_Query( $args ); |
| 2386 | + | |
| 2429 | 2387 | return ! empty( $query->get_products() ) ? count( $query->get_products() ) : 0; |
| 2430 | 2388 | } |
| 2431 | 2389 | |
| 2432 | 2390 | /** |
| @@ -2506,9 +2464,11 @@ | ||
| 2506 | 2464 | |
| 2507 | 2465 | if ( isset( self::$cache[ $cache_key ] ) ) { |
| 2508 | 2466 | return self::$cache[ $cache_key ]; |
| 2509 | 2467 | } |
| 2510 | - $results = wp_cache_get( $cache_key, 'shopbuilder' ); | |
| 2468 | + | |
| 2469 | + $results = wp_cache_get( $cache_key ); | |
| 2470 | + | |
| 2511 | 2471 | if ( ! $results ) { |
| 2512 | 2472 | global $wpdb; |
| 2513 | 2473 | $sql = "SELECT t.term_id, t.name |
| 2514 | 2474 | FROM {$wpdb->terms} t |
| @@ -2523,10 +2483,9 @@ | ||
| 2523 | 2483 | } |
| 2524 | 2484 | |
| 2525 | 2485 | $results = $wpdb->get_results( $prepared_sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared |
| 2526 | 2486 | // Cache the results in the object cache for future use. |
| 2527 | - wp_cache_set( $cache_key, $results, 'shopbuilder' ); // Adjust the expiration time as needed. | |
| 2528 | - Cache::set_data_cache_key( $cache_key ); | |
| 2487 | + wp_cache_set( $cache_key, $results ); // Adjust the expiration time as needed. | |
| 2529 | 2488 | } |
| 2530 | 2489 | |
| 2531 | 2490 | $cats = []; |
| 2532 | 2491 | if ( ! is_array( $results ) && ! count( $results ) ) { |
| @@ -2630,12 +2589,11 @@ | ||
| 2630 | 2589 | $query_results = get_posts( $args ); |
| 2631 | 2590 | foreach ( $query_results as $post ) { |
| 2632 | 2591 | $posts[] = [ |
| 2633 | 2592 | 'value' => $post->ID, |
| 2634 | - 'label' => $post->post_title . ' ( ID ' . $post->ID . ')', | |
| 2593 | + 'label' => $post->post_title . ' (' . $post->ID . ')', | |
| 2635 | 2594 | ]; |
| 2636 | 2595 | } |
| 2637 | - | |
| 2638 | 2596 | if ( $search_query ) { |
| 2639 | 2597 | if ( strpos( '-error 404', $search_query ) ) { |
| 2640 | 2598 | $posts[] = [ |
| 2641 | 2599 | 'value' => 'error', |
| @@ -2642,14 +2600,12 @@ | ||
| 2642 | 2600 | 'label' => __( '404 Error', 'shopbuilder' ), |
| 2643 | 2601 | ]; |
| 2644 | 2602 | } |
| 2645 | 2603 | } else { |
| 2646 | - if ( 'page' === $args['post_type'] ) { | |
| 2647 | - $posts[] = [ | |
| 2648 | - 'value' => 'error', | |
| 2649 | - 'label' => __( '404 Error', 'shopbuilder' ), | |
| 2650 | - ]; | |
| 2651 | - } | |
| 2604 | + $posts[] = [ | |
| 2605 | + 'value' => 'error', | |
| 2606 | + 'label' => __( '404 Error', 'shopbuilder' ), | |
| 2607 | + ]; | |
| 2652 | 2608 | } |
| 2653 | 2609 | } else { |
| 2654 | 2610 | $posts = self::get_registered_post_types( $search_query ); |
| 2655 | 2611 | } |
| @@ -2968,10 +2924,9 @@ | ||
| 2968 | 2924 | return; |
| 2969 | 2925 | } |
| 2970 | 2926 | $repeater_options[ $index ] = wp_parse_args( $values, $repeater_options[ $index ] ); |
| 2971 | 2927 | $options[ $option_key ] = wp_json_encode( $repeater_options ); |
| 2972 | - $modules[ $block_id ] = $options; | |
| 2973 | - DataModel::source()->set_option( $section_id, $modules ); | |
| 2928 | + self::set_options( $section_id, $block_id, $options ); | |
| 2974 | 2929 | } |
| 2975 | 2930 | |
| 2976 | 2931 | |
| 2977 | 2932 | /** |