From ecaa389b86452f554e6462504e29d8dd88292922 Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Tue, 19 Sep 2023 12:00:43 +0300 Subject: [PATCH 1/2] chore: wrap live-search deps with an action --- .../inc/plugins/class-live-search.php | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/plugins/otter-pro/inc/plugins/class-live-search.php b/plugins/otter-pro/inc/plugins/class-live-search.php index 00318fda0..cbb892570 100644 --- a/plugins/otter-pro/inc/plugins/class-live-search.php +++ b/plugins/otter-pro/inc/plugins/class-live-search.php @@ -23,6 +23,7 @@ class Live_Search { */ public function init() { add_filter( 'render_block', array( $this, 'render_blocks' ), 10, 2 ); + add_action( 'otter_load_live_search_deps', array( $this, 'load_deps' ) ); } /** @@ -39,6 +40,37 @@ public function render_blocks( $block_content, $block ) { return $block_content; } + do_action( 'otter_load_live_search_deps' ); + + $post_types_data = ''; + if ( isset( $block['attrs']['otterSearchQuery']['post_type'] ) ) { + $post_types_data = 'data-post-types=' . wp_json_encode( $block['attrs']['otterSearchQuery']['post_type'] ); + } + + // Insert hidden fields to filter core's search results. + $query_params_markup = ''; + if ( isset( $block['attrs']['otterSearchQuery'] ) && count( $block['attrs']['otterSearchQuery'] ) > 0 ) { + foreach ( $block['attrs']['otterSearchQuery'] as $param => $value ) { + $query_params_markup .= sprintf( + '', + esc_attr( $param ), + esc_attr( implode( ',', $value ) ) + ); + } + } + + $block_content = substr( $block_content, 0, strpos( $block_content, '' ) ) . $query_params_markup . substr( $block_content, strpos( $block_content, '' ) ); + return ''; + } + + /** + * Load the live search dependencies. + * + * @return void + * + * @static + */ + public static function load_deps() { $asset_file = include OTTER_BLOCKS_PATH . '/build/blocks/live-search.asset.php'; wp_enqueue_script( 'otter-live-search', @@ -64,26 +96,6 @@ public function render_blocks( $block_content, $block ) { $asset_file = include OTTER_BLOCKS_PATH . '/build/blocks/live-search-style.asset.php'; wp_enqueue_style( 'otter-live-search-style', OTTER_BLOCKS_URL . 'build/blocks/live-search-style.css', $asset_file['dependencies'], $asset_file['version'] ); - - $post_types_data = ''; - if ( isset( $block['attrs']['otterSearchQuery']['post_type'] ) ) { - $post_types_data = 'data-post-types=' . wp_json_encode( $block['attrs']['otterSearchQuery']['post_type'] ); - } - - // Insert hidden fields to filter core's search results. - $query_params_markup = ''; - if ( isset( $block['attrs']['otterSearchQuery'] ) && count( $block['attrs']['otterSearchQuery'] ) > 0 ) { - foreach ( $block['attrs']['otterSearchQuery'] as $param => $value ) { - $query_params_markup .= sprintf( - '', - esc_attr( $param ), - esc_attr( implode( ',', $value ) ) - ); - } - } - - $block_content = substr( $block_content, 0, strpos( $block_content, '' ) ) . $query_params_markup . substr( $block_content, strpos( $block_content, '' ) ); - return ''; } /** From 1c9a6b31ea74604c3a9e2c6a47a51115e2d736cf Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Tue, 19 Sep 2023 12:09:09 +0300 Subject: [PATCH 2/2] chore: licence check for live-search deps action --- plugins/otter-pro/inc/plugins/class-live-search.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/otter-pro/inc/plugins/class-live-search.php b/plugins/otter-pro/inc/plugins/class-live-search.php index cbb892570..c43c76216 100644 --- a/plugins/otter-pro/inc/plugins/class-live-search.php +++ b/plugins/otter-pro/inc/plugins/class-live-search.php @@ -71,6 +71,13 @@ public function render_blocks( $block_content, $block ) { * @static */ public static function load_deps() { + + $has_license = in_array( License::get_license_type(), array( 2, 3 ) ) || ( License::has_active_license() && isset( License::get_license_data()->otter_pro ) ); + + if ( ! $has_license ) { + return; + } + $asset_file = include OTTER_BLOCKS_PATH . '/build/blocks/live-search.asset.php'; wp_enqueue_script( 'otter-live-search',