From b0ba19bd76acba4bfc5b32de30d73f3c08f65955 Mon Sep 17 00:00:00 2001 From: bluefuton Date: Mon, 8 Mar 2021 16:18:16 +1300 Subject: [PATCH 1/5] Automatically select product result format for sites with WooCommerce active --- .../search/class-jetpack-instant-search.php | 20 +++++++++++++++++-- .../search/class-jetpack-search-options.php | 10 ++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/modules/search/class-jetpack-instant-search.php b/projects/plugins/jetpack/modules/search/class-jetpack-instant-search.php index 27917c031ce9d..f730b8d4407c1 100644 --- a/projects/plugins/jetpack/modules/search/class-jetpack-instant-search.php +++ b/projects/plugins/jetpack/modules/search/class-jetpack-instant-search.php @@ -170,7 +170,7 @@ protected function inject_javascript_options() { 'enableSort' => get_option( $prefix . 'enable_sort', '1' ) === '1', 'highlightColor' => get_option( $prefix . 'highlight_color', '#FFC' ), 'overlayTrigger' => get_option( $prefix . 'overlay_trigger', 'immediate' ), - 'resultFormat' => get_option( $prefix . 'result_format', 'minimal' ), + 'resultFormat' => get_option( $prefix . 'result_format', Jetpack_Search_Options::RESULT_FORMAT_MINIMAL ), 'showPoweredBy' => get_option( $prefix . 'show_powered_by', '1' ) === '1', ), @@ -448,10 +448,11 @@ public function auto_config_search() { } // Set default result format to "expanded". - update_option( Jetpack_Search_Options::OPTION_PREFIX . 'result_format', 'expanded' ); + update_option( Jetpack_Search_Options::OPTION_PREFIX . 'result_format', Jetpack_Search_Options::RESULT_FORMAT_EXPANDED ); $this->auto_config_excluded_post_types(); $this->auto_config_overlay_sidebar_widgets(); + $this->auto_config_woo_result_format(); } /** @@ -613,6 +614,7 @@ protected function get_preconfig_widget_options() { return $settings; } + /** * Automatically configure post types to exclude from one of the search widgets * @@ -644,4 +646,18 @@ public function auto_config_excluded_post_types() { update_option( Jetpack_Search_Options::OPTION_PREFIX . 'excluded_post_types', join( ',', $post_types_to_disable ) ); } } + + /** + * Automatically set result format to 'product' if WooCommerce is installed + * + * @since 9.6.0 + */ + public function auto_config_woo_result_format() { + // Check if WooCommerce plugin is active (based on https://docs.woocommerce.com/document/create-a-plugin/). + if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ), true ) ) { + return false; + } + + update_option( Jetpack_Search_Options::OPTION_PREFIX . 'result_format', Jetpack_Search_Options::RESULT_FORMAT_PRODUCT ); + } } diff --git a/projects/plugins/jetpack/modules/search/class-jetpack-search-options.php b/projects/plugins/jetpack/modules/search/class-jetpack-search-options.php index c9f87f77f4894..dee024d34b09a 100644 --- a/projects/plugins/jetpack/modules/search/class-jetpack-search-options.php +++ b/projects/plugins/jetpack/modules/search/class-jetpack-search-options.php @@ -32,6 +32,16 @@ class Jetpack_Search_Options { */ const OPTION_PREFIX = 'jetpack_search_'; + /** + * Available result formats. + * + * @since 9.6.0 + * @var string + */ + const RESULT_FORMAT_MINIMAL = 'minimal'; + const RESULT_FORMAT_EXPANDED = 'expanded'; + const RESULT_FORMAT_PRODUCT = 'product;' + /** * Returns a boolean for whether instant search is enabled. * From 7bd9e779236b2f4275e4f23654a682301eaa2f46 Mon Sep 17 00:00:00 2001 From: bluefuton Date: Mon, 8 Mar 2021 16:33:32 +1300 Subject: [PATCH 2/5] Fix typo --- .../jetpack/modules/search/class-jetpack-search-options.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/modules/search/class-jetpack-search-options.php b/projects/plugins/jetpack/modules/search/class-jetpack-search-options.php index dee024d34b09a..09215f7f4ad60 100644 --- a/projects/plugins/jetpack/modules/search/class-jetpack-search-options.php +++ b/projects/plugins/jetpack/modules/search/class-jetpack-search-options.php @@ -40,7 +40,7 @@ class Jetpack_Search_Options { */ const RESULT_FORMAT_MINIMAL = 'minimal'; const RESULT_FORMAT_EXPANDED = 'expanded'; - const RESULT_FORMAT_PRODUCT = 'product;' + const RESULT_FORMAT_PRODUCT = 'product'; /** * Returns a boolean for whether instant search is enabled. From 67cdd7dae466b52ca27da6a3753b22275c547867 Mon Sep 17 00:00:00 2001 From: bluefuton Date: Tue, 9 Mar 2021 14:56:05 +1300 Subject: [PATCH 3/5] Add Jetpack::get_active_plugins check for WP.com simple sites --- .../jetpack/modules/search/class-jetpack-instant-search.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/projects/plugins/jetpack/modules/search/class-jetpack-instant-search.php b/projects/plugins/jetpack/modules/search/class-jetpack-instant-search.php index f730b8d4407c1..a868252c3a088 100644 --- a/projects/plugins/jetpack/modules/search/class-jetpack-instant-search.php +++ b/projects/plugins/jetpack/modules/search/class-jetpack-instant-search.php @@ -653,6 +653,10 @@ public function auto_config_excluded_post_types() { * @since 9.6.0 */ public function auto_config_woo_result_format() { + if ( ! method_exists( 'Jetpack', 'get_active_plugins' ) ) { + return false; + } + // Check if WooCommerce plugin is active (based on https://docs.woocommerce.com/document/create-a-plugin/). if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ), true ) ) { return false; From ac37c744c662ecacc89c4543f717699538fecba9 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Thu, 11 Mar 2021 13:15:38 +0100 Subject: [PATCH 4/5] Add changelog --- .../jetpack/changelog/add-search-set-woo-result-format | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/add-search-set-woo-result-format diff --git a/projects/plugins/jetpack/changelog/add-search-set-woo-result-format b/projects/plugins/jetpack/changelog/add-search-set-woo-result-format new file mode 100644 index 0000000000000..9b1958039c653 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-search-set-woo-result-format @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Jetpac k Search: during setup, automatically use the product result format for sites with WooCommerce active. From 3e7ed5ee782f4535b591679cf10c8dd6f23a013e Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 12 Mar 2021 11:32:57 +1300 Subject: [PATCH 5/5] Update changelog --- .../plugins/jetpack/changelog/add-search-set-woo-result-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/changelog/add-search-set-woo-result-format b/projects/plugins/jetpack/changelog/add-search-set-woo-result-format index 9b1958039c653..03393e4659186 100644 --- a/projects/plugins/jetpack/changelog/add-search-set-woo-result-format +++ b/projects/plugins/jetpack/changelog/add-search-set-woo-result-format @@ -1,4 +1,4 @@ Significance: minor Type: enhancement -Jetpac k Search: during setup, automatically use the product result format for sites with WooCommerce active. +Jetpack Search: during setup, automatically use the product result format for sites with WooCommerce active.