diff --git a/amp.php b/amp.php index 04d13633aa7..cad985b20d3 100644 --- a/amp.php +++ b/amp.php @@ -5,7 +5,7 @@ * Plugin URI: https://github.com/automattic/amp-wp * Author: Automattic * Author URI: https://automattic.com - * Version: 0.6.1 + * Version: 0.6.2 * Text Domain: amp * Domain Path: /languages/ * License: GPLv2 or later @@ -15,7 +15,7 @@ define( 'AMP__FILE__', __FILE__ ); define( 'AMP__DIR__', dirname( __FILE__ ) ); -define( 'AMP__VERSION', '0.6.1' ); +define( 'AMP__VERSION', '0.6.2' ); require_once AMP__DIR__ . '/includes/class-amp-autoloader.php'; AMP_Autoloader::register(); diff --git a/assets/css/amp-post-meta-box.css b/assets/css/amp-post-meta-box.css index 993df676b6a..d6164792cdb 100644 --- a/assets/css/amp-post-meta-box.css +++ b/assets/css/amp-post-meta-box.css @@ -16,16 +16,21 @@ border-top-left-radius: 0; border-bottom-left-radius: 0; text-indent: -9999px; - padding-right: 7px; - padding-left: 7px; + padding-right: 14px; + padding-left: 14px; + position: relative; } .wp-core-ui #amp-post-preview.preview::after { content: "icon"; - width: 14px; - float: left; background: no-repeat center url( '../images/amp-icon.svg' ); background-size: 14px !important; + top: 0; + right: 0; + bottom: 0; + left: 0; + display: block; + position: absolute; } .wp-core-ui #amp-post-preview.preview.disabled::after { diff --git a/composer.json b/composer.json index b06a8c5a051..25c26718396 100644 --- a/composer.json +++ b/composer.json @@ -4,5 +4,5 @@ "homepage": "https://github.com/Automattic/amp-wp", "type": "wordpress-plugin", "license": "GPL-2.0", - "version": "0.6.1" + "version": "0.6.2" } diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index f4f9f083665..690c6bf3539 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -30,7 +30,25 @@ 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(); + } } /** 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/package-lock.json b/package-lock.json index df2955e6b3e..335bc6fa433 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "amp-wp", - "version": "0.6.1", + "version": "0.6.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4775e77f748..824f728b2aa 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "git", "url": "https://github.com/Automattic/amp-wp.git" }, - "version": "0.6.1", + "version": "0.6.2", "license": "GPL-2.0+", "private": true, "devDependencies": { diff --git a/readme.md b/readme.md index 7d3c8f4e424..992aeaa5fa9 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.1 +**Stable tag:** 0.6.2 **License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) **Requires PHP:** 5.2 @@ -56,6 +56,10 @@ Follow along with or [contribute](https://github.com/Automattic/amp-wp/blob/deve ## Changelog ## +### 0.6.2 (2018-02-12) ### +- Reduce frequency of flushing rewrite rules and harden, use escaped translation functions, and make minor changes to improve logic/style. See [#953](https://github.com/Automattic/amp-wp/pull/953). Props philipjohn, westonruter. +- Fix AMP preview icon in Firefox. See [#920](https://github.com/Automattic/amp-wp/pull/920). Props zigasancin. + ### 0.6.1 (2018-02-09) ### Bump version to re-release to ensure temporarily-broken 0.6.0 ZIP build is permanently fixed, without requiring a site to re-install the plugin. diff --git a/readme.txt b/readme.txt index 12e0040c202..10f37777185 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.1 +Stable tag: 0.6.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Requires PHP: 5.2 @@ -38,6 +38,11 @@ Follow along with or [contribute](https://github.com/Automattic/amp-wp/blob/deve == Changelog == += 0.6.2 (2018-02-12) = + +- Reduce frequency of flushing rewrite rules and harden, use escaped translation functions, and make minor changes to improve logic/style. See [#953](https://github.com/Automattic/amp-wp/pull/953). Props philipjohn, westonruter. +- Fix AMP preview icon in Firefox. See [#920](https://github.com/Automattic/amp-wp/pull/920). Props zigasancin. + = 0.6.1 (2018-02-09) = Bump version to re-release to ensure temporarily-broken 0.6.0 ZIP build is permanently fixed, without requiring a site to re-install the plugin. diff --git a/tests/test-class-amp-options-manager.php b/tests/test-class-amp-options-manager.php index afe0ffc0863..b4711a69a1d 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' ) ); } /**