diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index 84de7c26b43..4a981717c51 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -48,7 +48,6 @@ public static function maybe_flush_rewrite_rules( $old_options, $new_options ) { sort( $new_post_types ); if ( $old_post_types !== $new_post_types ) { flush_rewrite_rules( false ); - do_action( 'rri_flush_rules' ); } } diff --git a/includes/options/views/class-amp-analytics-options-submenu-page.php b/includes/options/views/class-amp-analytics-options-submenu-page.php index f1efc645c9b..f4491361fdc 100644 --- a/includes/options/views/class-amp-analytics-options-submenu-page.php +++ b/includes/options/views/class-amp-analytics-options-submenu-page.php @@ -10,18 +10,23 @@ */ class AMP_Analytics_Options_Submenu_Page { + /** + * Render entry. + * + * @param string $id Entry ID. + * @param string $type Entry type. + * @param string $config Entry config as serialized JSON. + */ private function render_entry( $id = '', $type = '', $config = '' ) { $is_existing_entry = ! empty( $id ); if ( $is_existing_entry ) { - $entry_slug = sprintf( '%s%s', ( $type ? $type . '-' : '' ), substr( $id, -6 ) ); + $entry_slug = sprintf( '%s%s', ( $type ? $type . '-' : '' ), substr( $id, - 6 ) ); + /* translators: %s is the entry slug */ $analytics_title = sprintf( __( 'Analytics: %s', 'amp' ), $entry_slug ); } else { $analytics_title = __( 'Add new entry:', 'amp' ); - } - - if ( ! $is_existing_entry ) { - $id = '__new__'; + $id = '__new__'; } $id_base = sprintf( '%s[analytics][%s]', AMP_Options_Manager::OPTION_NAME, $id ); @@ -55,9 +60,9 @@ private function render_entry( $id = '', $type = '', $config = '' ) {
@@ -78,6 +83,9 @@ public function render_title() { post = get_post( $post ); } - $this->ID = $this->post->ID; + + // Make sure we have a post, or bail if not. + if ( is_a( $this->post, 'WP_Post' ) ) { + $this->ID = $this->post->ID; + } else { + return; + } $content_max_width = self::CONTENT_MAX_WIDTH; if ( isset( $GLOBALS['content_width'] ) && $GLOBALS['content_width'] > 0 ) { diff --git a/readme.md b/readme.md index b3fcd45f55d..62fc9cf7d0f 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ Enable Accelerated Mobile Pages (AMP) on your WordPress site. **Tags:** [amp](https://wordpress.org/plugins/tags/amp), [mobile](https://wordpress.org/plugins/tags/mobile) **Requires at least:** 4.7 **Tested up to:** 4.9 -**Stable tag:** 0.6.0 +**Stable tag:** 0.6.2 **License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) **Requires PHP:** 5.3 diff --git a/readme.txt b/readme.txt index 1f45c73947e..7d6d41a60cc 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: batmoo, joen, automattic, potatomaster, albertomedina, google, xwp Tags: amp, mobile Requires at least: 4.7 Tested up to: 4.9 -Stable tag: 0.6.0 +Stable tag: 0.6.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Requires PHP: 5.3 diff --git a/tests/test-class-amp-options-manager.php b/tests/test-class-amp-options-manager.php index d08584efdd3..564077281ac 100644 --- a/tests/test-class-amp-options-manager.php +++ b/tests/test-class-amp-options-manager.php @@ -38,7 +38,43 @@ public function test_register_settings() { $this->assertArrayHasKey( AMP_Options_Manager::OPTION_NAME, $registered_settings ); $this->assertEquals( 'array', $registered_settings[ AMP_Options_Manager::OPTION_NAME ]['type'] ); - $this->assertEquals( 10, has_action( 'update_option_' . AMP_Options_Manager::OPTION_NAME, 'flush_rewrite_rules' ) ); + $this->assertEquals( 10, has_action( 'update_option_' . AMP_Options_Manager::OPTION_NAME, array( 'AMP_Options_Manager', 'maybe_flush_rewrite_rules' ) ) ); + } + + /** + * Test maybe_flush_rewrite_rules. + * + * @covers AMP_Options_Manager::maybe_flush_rewrite_rules() + */ + public function test_maybe_flush_rewrite_rules() { + global $wp_rewrite; + $wp_rewrite->init(); + AMP_Options_Manager::register_settings(); + $dummy_rewrite_rules = array( 'previous' => true ); + + // Check change to supported_post_types. + update_option( 'rewrite_rules', $dummy_rewrite_rules ); + AMP_Options_Manager::maybe_flush_rewrite_rules( + array( 'supported_post_types' => array( 'page' ) ), + array() + ); + $this->assertEmpty( get_option( 'rewrite_rules' ) ); + + // Check update of supported_post_types but no change. + update_option( 'rewrite_rules', $dummy_rewrite_rules ); + update_option( AMP_Options_Manager::OPTION_NAME, array( + array( 'supported_post_types' => array( 'page' ) ), + array( 'supported_post_types' => array( 'page' ) ), + ) ); + $this->assertEquals( $dummy_rewrite_rules, get_option( 'rewrite_rules' ) ); + + // Check changing a different property. + update_option( 'rewrite_rules', array( 'previous' => true ) ); + update_option( AMP_Options_Manager::OPTION_NAME, array( + array( 'foo' => 'new' ), + array( 'foo' => 'old' ), + ) ); + $this->assertEquals( $dummy_rewrite_rules, get_option( 'rewrite_rules' ) ); } /**