From f4c38ee9bfe0ec381d9d41ba0bdcffaddb6317be Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Feb 2018 14:43:14 -0800 Subject: [PATCH 01/14] Bump 0.6.1 --- amp.php | 4 ++-- composer.json | 2 +- package-lock.json | 2 +- package.json | 2 +- readme.md | 5 ++++- readme.txt | 6 +++++- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/amp.php b/amp.php index a296c5c9c51..04d13633aa7 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.0 + * Version: 0.6.1 * 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.0' ); +define( 'AMP__VERSION', '0.6.1' ); require_once AMP__DIR__ . '/includes/class-amp-autoloader.php'; AMP_Autoloader::register(); diff --git a/composer.json b/composer.json index ee52ea6f241..b06a8c5a051 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.0" + "version": "0.6.1" } diff --git a/package-lock.json b/package-lock.json index b889ff52a31..df2955e6b3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "amp-wp", - "version": "0.6.0", + "version": "0.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 441e1859ff1..4775e77f748 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "git", "url": "https://github.com/Automattic/amp-wp.git" }, - "version": "0.6.0", + "version": "0.6.1", "license": "GPL-2.0+", "private": true, "devDependencies": { diff --git a/readme.md b/readme.md index 39866df99fb..7d3c8f4e424 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.1 **License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) **Requires PHP:** 5.2 @@ -56,6 +56,9 @@ Follow along with or [contribute](https://github.com/Automattic/amp-wp/blob/deve ## Changelog ## +### 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. + ### 0.6.0 (2018-01-23) ### - Add support for the "page" post type. A new `page.php` is introduced with template parts factored out (`html-start.php`, `header.php`, `footer.php`, `html-end.php`) and re-used from `single.php`. Note that AMP URLs will end in `?amp` instead of `/amp/`. See [#825](https://github.com/Automattic/amp-wp/pull/825). Props technosailor, ThierryA, westonruter. - Add AMP post preview button alongside non-AMP preview button. See [#813](https://github.com/Automattic/amp-wp/pull/813). Props ThierryA, westonruter. diff --git a/readme.txt b/readme.txt index e946d1f0871..12e0040c202 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.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Requires PHP: 5.2 @@ -38,6 +38,10 @@ Follow along with or [contribute](https://github.com/Automattic/amp-wp/blob/deve == Changelog == += 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. + = 0.6.0 (2018-01-23) = - Add support for the "page" post type. A new `page.php` is introduced with template parts factored out (`html-start.php`, `header.php`, `footer.php`, `html-end.php`) and re-used from `single.php`. Note that AMP URLs will end in `?amp` instead of `/amp/`. See [#825](https://github.com/Automattic/amp-wp/pull/825). Props technosailor, ThierryA, westonruter. From 20c394457bb6f8b68d55923191a173c15fdc4d69 Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 10 Feb 2018 19:06:35 +0000 Subject: [PATCH 02/14] Remove extraneous conditional --- .../views/class-amp-analytics-options-submenu-page.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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..a9e6ebb434a 100644 --- a/includes/options/views/class-amp-analytics-options-submenu-page.php +++ b/includes/options/views/class-amp-analytics-options-submenu-page.php @@ -18,10 +18,7 @@ private function render_entry( $id = '', $type = '', $config = '' ) { $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 ); From 4ced14cde725eba8b599d21f593f67f37c09319f Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 10 Feb 2018 19:08:38 +0000 Subject: [PATCH 03/14] Improve escaping. --- .../views/class-amp-analytics-options-submenu-page.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 a9e6ebb434a..fd4d915484d 100644 --- a/includes/options/views/class-amp-analytics-options-submenu-page.php +++ b/includes/options/views/class-amp-analytics-options-submenu-page.php @@ -52,9 +52,9 @@ private function render_entry( $id = '', $type = '', $config = '' ) {

From fc862f5c1d907cf8277eb6d23fe9f89451b979ec Mon Sep 17 00:00:00 2001 From: Philip John Date: Sat, 10 Feb 2018 19:11:59 +0000 Subject: [PATCH 04/14] Only proceed if we definitely have a valid post. --- includes/templates/class-amp-post-template.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/templates/class-amp-post-template.php b/includes/templates/class-amp-post-template.php index bd96bd53d87..9cdde3d8c7a 100644 --- a/includes/templates/class-amp-post-template.php +++ b/includes/templates/class-amp-post-template.php @@ -94,7 +94,13 @@ public function __construct( $post ) { } else { $this->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 ) { From e3ac098bdc5e5289fdfe4bb3a66ccb49b0b20250 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 11 Feb 2018 11:34:08 -0800 Subject: [PATCH 05/14] Limit flushing rewrite rules to only when supported_post_types change Also fix phpcs issues --- .../options/class-amp-options-manager.php | 20 +++++++++- ...ass-amp-analytics-options-submenu-page.php | 15 +++++++- .../templates/class-amp-post-template.php | 12 +++--- tests/test-class-amp-options-manager.php | 38 ++++++++++++++++++- 4 files changed, 75 insertions(+), 10 deletions(-) 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 fd4d915484d..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,15 +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' ); - $id = '__new__'; + $id = '__new__'; } $id_base = sprintf( '%s[analytics][%s]', AMP_Options_Manager::OPTION_NAME, $id ); @@ -75,6 +83,9 @@ public function render_title() { post = get_post( $post ); } - // Make sure we have a post, or bail if not. - if ( is_a( $this->post, 'WP_Post' ) ) { - $this->ID = $this->post->ID; - } else { - return; - } + // 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/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' ) ); } /** From 5555918fda12f9cb7df77db558fb9c6cf797cd59 Mon Sep 17 00:00:00 2001 From: Ziga Sancin Date: Tue, 30 Jan 2018 22:52:49 +0100 Subject: [PATCH 06/14] Fix AMP preview icon in Firefox The AMP preview icon isn't displaying correctly in Firefox (probably because of a different interpretation of the text-indent css rule). My proposed fix works in latest releases of Firefox, Chrome, Safari, Edge and IE. --- assets/css/amp-post-meta-box.css | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 { From 664a2a1a5c2c5fbafadb495589303433a45d88bd Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 11 Feb 2018 11:44:11 -0800 Subject: [PATCH 07/14] Bump 0.6.2 and update readme --- amp.php | 4 ++-- composer.json | 2 +- package-lock.json | 2 +- package.json | 2 +- readme.md | 6 +++++- readme.txt | 7 ++++++- 6 files changed, 16 insertions(+), 7 deletions(-) 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/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/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. From 9a6d0765e451bcd0303c17ed8cee0874dc7b516e Mon Sep 17 00:00:00 2001 From: Philip John Date: Thu, 26 Apr 2018 12:05:18 +0100 Subject: [PATCH 08/14] Remove debugging code. Gets rid of several var_dump() usages that seem to be left over from debugging. --- ...-and-attribute-sanitizer-private-methods-tests.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php b/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php index a4746c4b743..be136c16bcb 100644 --- a/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php +++ b/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php @@ -411,7 +411,6 @@ public function test_validate_attr_spec_rules( $data, $expected ) { if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $source ); - var_dump( $data ); } $this->assertEquals( $expected, $got ); @@ -568,7 +567,6 @@ public function test_is_allowed_attribute( $data, $expected ) { if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $source ); - var_dump( $data ); } $this->assertEquals( $expected, $got ); @@ -664,7 +662,6 @@ public function test_remove_node( $data, $expected ) { if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $data['source'] ); - var_dump( $data ); printf( 'got = %s' .PHP_EOL, $got ); } @@ -805,7 +802,6 @@ public function test_replace_node_with_children( $data, $expected ) { if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $data['source'] ); - var_dump( $data ); printf( 'got = %s' .PHP_EOL, $got ); } @@ -867,7 +863,6 @@ public function test_get_ancestor_with_tag_name( $data, $expected ) { if ( $ancestor_node != $got ) { printf( 'using source: %s' . PHP_EOL, $data['source'] ); - var_dump( $data ); } $this->assertEquals( $ancestor_node, $got ); @@ -1073,7 +1068,6 @@ public function test_validate_attr_spec_list_for_node( $data, $expected ) { if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $data['source'] ); - var_dump( $data ); } $this->assertEquals( $expected, $got ); @@ -1200,7 +1194,6 @@ public function test_check_attr_spec_rule_value( $data, $expected ) { if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $data['source'] ); - var_dump( $data ); } $this->assertEquals( $expected, $got ); @@ -1352,7 +1345,6 @@ public function test_check_attr_spec_rule_value_casei( $data, $expected ) { if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $data['source'] ); - var_dump( $data ); } $this->assertEquals( $expected, $got ); @@ -1446,7 +1438,6 @@ public function test_check_attr_spec_rule_blacklisted_value_regex( $data, $expec if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $data['source'] ); - var_dump( $data ); } $this->assertEquals( $expected, $got ); @@ -1581,7 +1572,6 @@ public function test_check_attr_spec_rule_allowed_protocol( $data, $expected ) { if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $data['source'] ); - var_dump( $data ); } $this->assertEquals( $expected, $got ); @@ -1730,7 +1720,6 @@ public function test_check_attr_spec_rule_disallowed_relative( $data, $expected if ( $expected != $got ) { printf( 'using source: %s' . PHP_EOL, $data['source'] ); - var_dump( $data ); } $this->assertEquals( $expected, $got ); From d250860d0c98163dd7775cc4906792d6709abfe7 Mon Sep 17 00:00:00 2001 From: Philip John Date: Thu, 26 Apr 2018 12:10:05 +0100 Subject: [PATCH 09/14] Set a limit on get_chilrdren() As `get_children()` performs a no-limit query by default we should set a posts_per_page to avoid unnecessarily expensive queries. --- includes/embeds/class-amp-gallery-embed.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/embeds/class-amp-gallery-embed.php b/includes/embeds/class-amp-gallery-embed.php index 46d44fd6951..dcdea18fd4c 100644 --- a/includes/embeds/class-amp-gallery-embed.php +++ b/includes/embeds/class-amp-gallery-embed.php @@ -62,6 +62,7 @@ public function shortcode( $attr ) { 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', + 'posts_per_page' => 100, ) ); } elseif ( ! empty( $atts['exclude'] ) ) { $attachments = get_children( array( @@ -73,6 +74,7 @@ public function shortcode( $attr ) { 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', + 'posts_per_page' => 100, ) ); } else { $attachments = get_children( array( From 302a0884b5b719684a68a713d9168b97d93ea2b3 Mon Sep 17 00:00:00 2001 From: Philip John Date: Thu, 26 Apr 2018 12:22:46 +0100 Subject: [PATCH 10/14] Only flush rewrite when necessary. Limit when we flush rewrite rules to only those times when we need to - i.e. when the relevant settings are changed. --- .../options/class-amp-options-manager.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index f4f9f083665..db64ac49850 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -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' ); + } } /** From 3a1202106bdd1e8ef8d10b959074768d79e95bc4 Mon Sep 17 00:00:00 2001 From: Philip John Date: Thu, 26 Apr 2018 12:35:25 +0100 Subject: [PATCH 11/14] Fix spacing --- includes/embeds/class-amp-gallery-embed.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/embeds/class-amp-gallery-embed.php b/includes/embeds/class-amp-gallery-embed.php index dcdea18fd4c..0e15997783c 100644 --- a/includes/embeds/class-amp-gallery-embed.php +++ b/includes/embeds/class-amp-gallery-embed.php @@ -62,7 +62,7 @@ public function shortcode( $attr ) { 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', - 'posts_per_page' => 100, + 'posts_per_page' => 100, ) ); } elseif ( ! empty( $atts['exclude'] ) ) { $attachments = get_children( array( @@ -74,7 +74,7 @@ public function shortcode( $attr ) { 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', - 'posts_per_page' => 100, + 'posts_per_page' => 100, ) ); } else { $attachments = get_children( array( From ce239b5720e6d27149fc0d91f98c48ae0f62d16d Mon Sep 17 00:00:00 2001 From: Philip John Date: Thu, 26 Apr 2018 12:37:30 +0100 Subject: [PATCH 12/14] Fix spacing --- includes/options/class-amp-options-manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index db64ac49850..72109f104a1 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -33,7 +33,7 @@ public static function register_settings() { 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 From f2e422f9a95c31ca0b380adcadd05eb0fc7a2bd7 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 26 Apr 2018 10:46:02 -0700 Subject: [PATCH 13/14] Fix OutputNotEscaped errors in tests; restore output of debug information via assertion message --- ...ribute-sanitizer-private-methods-tests.php | 68 +++---------------- 1 file changed, 11 insertions(+), 57 deletions(-) diff --git a/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php b/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php index a4286604307..eb2bd5404f5 100644 --- a/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php +++ b/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php @@ -409,11 +409,7 @@ public function test_validate_attr_spec_rules( $data, $expected ) { $got = $this->invoke_method( $sanitizer, $data['func_name'], array( $node, $data['attribute_name'], $attr_spec_rule ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $source ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $source, wp_json_encode( $data ) ) ); } public function get_is_allowed_attribute_data() { @@ -565,11 +561,7 @@ public function test_is_allowed_attribute( $data, $expected ) { $got = $this->invoke_method( $sanitizer, $data['func_name'], array( $data['attribute_name'], $attr_spec_list ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $source ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $source, wp_json_encode( $data ) ) ); } public function get_remove_node_data() { @@ -660,12 +652,7 @@ public function test_remove_node( $data, $expected ) { $got = AMP_DOM_Utils::get_content_from_dom( $dom ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - printf( 'got = %s' .PHP_EOL, $got ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } @@ -800,12 +787,7 @@ public function test_replace_node_with_children( $data, $expected ) { $got = AMP_DOM_Utils::get_content_from_dom( $dom ); $got = preg_replace( '/(?<=>)\s+(?=<)/', '', $got ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - printf( 'got = %s' .PHP_EOL, $got ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_ancestor_with_tag_name_data() { @@ -861,11 +843,7 @@ public function test_get_ancestor_with_tag_name( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'get_ancestor_with_tag_name', array( $node, $data['ancestor_tag_name'] ) ); - if ( $ancestor_node != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $ancestor_node, $got ); + $this->assertEquals( $ancestor_node, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_validate_attr_spec_list_for_node_data() { @@ -1066,11 +1044,7 @@ public function test_validate_attr_spec_list_for_node( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'validate_attr_spec_list_for_node', array( $node, $data['attr_spec_list'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_value_data() { @@ -1192,11 +1166,7 @@ public function test_check_attr_spec_rule_value( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_value', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_value_casei_data() { @@ -1343,11 +1313,7 @@ public function test_check_attr_spec_rule_value_casei( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_value_casei', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_blacklisted_value_regex() { @@ -1436,11 +1402,7 @@ public function test_check_attr_spec_rule_blacklisted_value_regex( $data, $expec $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_blacklisted_value_regex', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_allowed_protocol() { @@ -1570,11 +1532,7 @@ public function test_check_attr_spec_rule_allowed_protocol( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_allowed_protocol', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_disallowed_relative() { @@ -1718,11 +1676,7 @@ public function test_check_attr_spec_rule_disallowed_relative( $data, $expected $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_disallowed_relative', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } /** From 58b6f0ed91f1b8516d6d30281233e6a8f6aca29c Mon Sep 17 00:00:00 2001 From: Philip John Date: Fri, 27 Apr 2018 11:40:37 +0100 Subject: [PATCH 14/14] Revert: Set a limit on get_chilrdren() --- includes/embeds/class-amp-gallery-embed.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/embeds/class-amp-gallery-embed.php b/includes/embeds/class-amp-gallery-embed.php index 0e15997783c..46d44fd6951 100644 --- a/includes/embeds/class-amp-gallery-embed.php +++ b/includes/embeds/class-amp-gallery-embed.php @@ -62,7 +62,6 @@ public function shortcode( $attr ) { 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', - 'posts_per_page' => 100, ) ); } elseif ( ! empty( $atts['exclude'] ) ) { $attachments = get_children( array( @@ -74,7 +73,6 @@ public function shortcode( $attr ) { 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', - 'posts_per_page' => 100, ) ); } else { $attachments = get_children( array(