Skip to content

Commit

Permalink
Only flush rewrite when necessary.
Browse files Browse the repository at this point in the history
Limit when we flush rewrite rules to only those times when we need to - i.e. when the relevant settings are changed.
  • Loading branch information
philipjohn committed Apr 26, 2018
1 parent d250860 commit 302a088
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion includes/options/class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,26 @@ public static function register_settings() {
)
);

add_action( 'update_option_' . self::OPTION_NAME, 'flush_rewrite_rules' );
add_action( 'update_option_' . self::OPTION_NAME, array( __CLASS__, 'maybe_flush_rewrite_rules' ), 10, 2 );
}

/**
* Flush rewrite rules if the supported_post_types have changed.
*
* @since 0.6.2
*
* @param array $old_options Old options.
* @param array $new_options New options.
*/
public static function maybe_flush_rewrite_rules( $old_options, $new_options ) {
$old_post_types = isset( $old_options['supported_post_types'] ) ? $old_options['supported_post_types'] : array();
$new_post_types = isset( $new_options['supported_post_types'] ) ? $new_options['supported_post_types'] : array();
sort( $old_post_types );
sort( $new_post_types );
if ( $old_post_types !== $new_post_types ) {
flush_rewrite_rules( false );
do_action( 'rri_flush_rules' );
}
}

/**
Expand Down

0 comments on commit 302a088

Please sign in to comment.