Use an action/option rather than cron to queue rule flushing
Closes #17851
This commit is contained in:
parent
970e98db09
commit
39e86db7a7
|
@ -83,11 +83,11 @@ class WC_Admin_Settings {
|
|||
self::add_message( __( 'Your settings have been saved.', 'woocommerce' ) );
|
||||
self::check_download_folder_protection();
|
||||
|
||||
// Clear any unwanted data and flush rules
|
||||
// Clear any unwanted data and flush rules on next init.
|
||||
add_option( 'woocommerce_queue_flush_rewrite_rules', 'true' );
|
||||
delete_transient( 'woocommerce_cache_excluded_uris' );
|
||||
WC()->query->init_query_vars();
|
||||
WC()->query->add_endpoints();
|
||||
wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' );
|
||||
|
||||
do_action( 'woocommerce_settings_saved' );
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ class WC_Post_types {
|
|||
add_action( 'init', array( __CLASS__, 'register_post_status' ), 9 );
|
||||
add_action( 'init', array( __CLASS__, 'support_jetpack_omnisearch' ) );
|
||||
add_filter( 'rest_api_allowed_post_types', array( __CLASS__, 'rest_api_allowed_post_types' ) );
|
||||
add_action( 'woocommerce_after_register_post_type', array( __CLASS__, 'maybe_flush_rewrite_rules' ) );
|
||||
add_action( 'woocommerce_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) );
|
||||
}
|
||||
|
||||
|
@ -529,6 +530,18 @@ class WC_Post_types {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush rules if the event is queued.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public static function maybe_flush_rewrite_rules() {
|
||||
if ( 'true' === get_option( 'woocommerce_queue_flush_rewrite_rules' ) ) {
|
||||
delete_option( 'woocommerce_queue_flush_rewrite_rules' );
|
||||
self::flush_rewrite_rules();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush rewrite rules.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue