Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tear down WooCommerce functionalities when the plugin is not active #3688

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions includes/classes/Feature/WooCommerce/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ public function setup() {
add_action( 'pre_get_posts', [ $this, 'translate_args' ], 11, 1 );
}

/**
* Unsetup order related hooks
*
* @since 5.0.0
*/
public function tear_down() {
remove_filter( 'ep_sync_insert_permissions_bypass', [ $this, 'bypass_order_permissions_check' ] );
remove_filter( 'ep_prepare_meta_allowed_protected_keys', [ $this, 'allow_meta_keys' ] );
remove_filter( 'ep_post_sync_args_post_prepare_meta', [ $this, 'add_order_items_search' ], 20 );
remove_filter( 'ep_pc_skip_post_content_cleanup', [ $this, 'keep_order_fields' ], 20 );
remove_action( 'parse_query', [ $this, 'maybe_hook_woocommerce_search_fields' ], 1 );
remove_action( 'parse_query', [ $this, 'search_order' ], 11 );
remove_action( 'pre_get_posts', [ $this, 'translate_args' ], 11 );
}

/**
* Allow order creations on the front end to get synced
*
Expand Down
20 changes: 20 additions & 0 deletions includes/classes/Feature/WooCommerce/OrdersAutosuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ public function setup() {
add_filter( 'posts_where', [ $this, 'maybe_set_posts_where' ], 10, 2 );
}

/**
* Un-setup feature functionality.
*
* @since 5.0.0
*/
public function tear_down() {
remove_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
remove_filter( 'ep_after_update_feature', [ $this, 'after_update_feature' ] );
remove_filter( 'ep_after_sync_index', [ $this, 'epio_save_search_template' ] );
remove_filter( 'ep_saved_weighting_configuration', [ $this, 'epio_save_search_template' ] );
remove_filter( 'ep_indexable_post_status', [ $this, 'post_statuses' ] );
remove_filter( 'ep_indexable_post_types', [ $this, 'post_types' ] );
remove_action( 'rest_api_init', [ $this, 'rest_api_init' ] );
remove_filter( 'ep_post_sync_args', [ $this, 'filter_term_suggest' ] );
remove_filter( 'ep_post_mapping', [ $this, 'mapping' ] );
remove_action( 'ep_woocommerce_shop_order_search_fields', [ $this, 'set_search_fields' ] );
remove_filter( 'ep_index_posts_args', [ $this, 'maybe_query_password_protected_posts' ] );
remove_filter( 'posts_where', [ $this, 'maybe_set_posts_where' ] );
}

/**
* Get the endpoint for WooCommerce Orders search.
*
Expand Down
28 changes: 28 additions & 0 deletions includes/classes/Feature/WooCommerce/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ public function setup() {
add_filter( 'ep_is_decaying_enabled', [ $this, 'maybe_disable_decaying' ], 10, 3 );
}

/**
* Un-setup product related hooks
*
* @since 5.0.0
*/
public function tear_down() {
remove_action( 'ep_formatted_args', [ $this, 'price_filter' ] );
remove_filter( 'ep_prepare_meta_allowed_protected_keys', [ $this, 'allow_meta_keys' ] );
remove_filter( 'ep_sync_taxonomies', [ $this, 'sync_taxonomies' ] );
remove_filter( 'ep_term_suggest_post_type', [ $this, 'suggest_wc_add_post_type' ] );
remove_filter( 'ep_facet_include_taxonomies', [ $this, 'add_product_attributes' ] );
remove_filter( 'ep_weighting_fields_for_post_type', [ $this, 'add_product_attributes_to_weighting' ] );
remove_filter( 'ep_weighting_default_post_type_weights', [ $this, 'add_product_default_post_type_weights' ] );
remove_filter( 'ep_prepare_meta_data', [ $this, 'add_variations_skus_meta' ] );
remove_filter( 'request', [ $this, 'admin_product_list_request_query' ], 9 );
remove_action( 'pre_get_posts', [ $this, 'translate_args' ], 11 );
remove_filter( 'ep_facet_tax_special_slug_taxonomies', [ $this, 'add_taxonomy_attributes' ] );

// Custom product ordering
remove_action( 'ep_admin_notices', [ $this, 'maybe_display_notice_about_product_ordering' ] );
remove_action( 'woocommerce_after_product_ordering', [ $this, 'action_sync_on_woocommerce_sort_single' ] );

// Settings for Weight results by date
remove_action( 'ep_weight_settings_after_search', [ $this, 'add_weight_settings_search' ] );
remove_filter( 'ep_feature_settings_schema', [ $this, 'add_weight_settings_search_schema' ] );
remove_filter( 'ep_is_decaying_enabled', [ $this, 'maybe_disable_decaying' ] );
}

/**
* Modifies main query to allow filtering by price with WooCommerce "Filter by price" widget.
*
Expand Down
68 changes: 33 additions & 35 deletions includes/classes/Feature/WooCommerce/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,49 @@ public function setup() {
return;
}

$this->products->setup();
$this->orders->setup();
add_action( 'switch_blog', [ $this, 'setup_or_tear_down' ] );

add_filter( 'ep_integrate_search_queries', [ $this, 'disallow_coupons' ], 10, 2 );

// These hooks are deprecated and will be removed in an upcoming major version of ElasticPress
add_filter( 'woocommerce_layered_nav_query_post_ids', [ $this, 'convert_post_object_to_id' ], 10, 4 );
add_filter( 'woocommerce_unfiltered_product_ids', [ $this, 'convert_post_object_to_id' ], 10, 4 );
add_action( 'ep_wp_query_search_cached_posts', [ $this, 'disallow_duplicated_query' ], 10, 2 );
$this->products->setup();
$this->orders->setup();

// Orders Autosuggest feature.
if ( $this->is_orders_autosuggest_enabled() ) {
$this->orders_autosuggest->setup();
}
}

/**
* Setup or tear down the functionality depending on the plugin being active for the current site.
*
* @since 5.0.0
*/
public function setup_or_tear_down() {
if ( \is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
$this->setup();
} else {
$this->tear_down();
}
}

/**
* Un-setup all feature filters
*
* @since 5.0.0
*/
public function tear_down() {
remove_filter( 'ep_integrate_search_queries', [ $this, 'disallow_coupons' ] );

$this->products->tear_down();
$this->orders->tear_down();

// Orders Autosuggest feature.
if ( $this->is_orders_autosuggest_enabled() ) {
$this->orders_autosuggest->tear_down();
}
}

/**
* Given a WP_Query object, return its search term (if any)
*
Expand Down Expand Up @@ -396,19 +423,6 @@ public function whitelist_meta_keys( $meta, $post ) {
);
}

/**
* DEPRECATED. Make sure all loop shop post ins are IDS. We have to pass post objects here since we override
* the fields=>id query for the layered filter nav query
*
* @param array $posts Post object array.
* @since 2.1
* @return array
*/
public function convert_post_object_to_id( $posts ) {
_doing_it_wrong( __METHOD__, 'This filter was removed from WooCommerce and will be removed from ElasticPress in a future release.', '4.5.0' );
return $posts;
}

/**
* DEPRECATED. Index WooCommerce taxonomies
*
Expand All @@ -422,22 +436,6 @@ public function whitelist_taxonomies( $taxonomies, $post ) {
return $this->products->sync_taxonomies( $taxonomies );
}

/**
* DEPRECATED. Disallow duplicated ES queries on Orders page.
*
* @since 2.4
*
* @param array $value Original filter values.
* @param WP_Query $query WP_Query
*
* @return array
*/
public function disallow_duplicated_query( $value, $query ) {
_doing_it_wrong( __METHOD__, 'This filter was removed from WooCommerce and will be removed from ElasticPress in a future release.', '4.5.0' );

return $value;
}

/**
* DEPRECATED. Returns the WooCommerce-oriented post types in admin that EP will search
*
Expand Down
Loading