Skip to content

Commit 6f8a8d8

Browse files
committed
Ensure rewrite rules are flushed properly when toggling website experience
1 parent 98efeb0 commit 6f8a8d8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

amp.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function amp_deactivate() {
278278
}
279279
}
280280

281-
flush_rewrite_rules();
281+
flush_rewrite_rules( false );
282282
}
283283

284284
/*

includes/options/class-amp-options-manager.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static function register_settings() {
6868
}
6969

7070
/**
71-
* Flush rewrite rules if the supported_post_types have changed.
71+
* Flush rewrite rules if the supported_post_types or experiences have changed.
7272
*
7373
* @since 0.6.2
7474
*
@@ -80,8 +80,17 @@ public static function maybe_flush_rewrite_rules( $old_options, $new_options ) {
8080
$new_post_types = isset( $new_options['supported_post_types'] ) ? $new_options['supported_post_types'] : array();
8181
sort( $old_post_types );
8282
sort( $new_post_types );
83-
if ( $old_post_types !== $new_post_types ) {
84-
flush_rewrite_rules( false );
83+
$old_experiences = isset( $old_options['experiences'] ) ? $old_options['experiences'] : array();
84+
$new_experiences = isset( $new_options['experiences'] ) ? $new_options['experiences'] : array();
85+
sort( $old_experiences );
86+
sort( $new_experiences );
87+
if ( $old_post_types !== $new_post_types || $old_experiences !== $new_experiences ) {
88+
if ( self::is_website_experience_enabled() ) {
89+
add_rewrite_endpoint( amp_get_slug(), EP_PERMALINK );
90+
flush_rewrite_rules( false );
91+
} else {
92+
amp_deactivate();
93+
}
8594
}
8695
}
8796

0 commit comments

Comments
 (0)