From 08f02c928ca6d6b14ecb1c2ea3aa468d2d76df24 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 11 May 2018 17:31:19 +1000 Subject: [PATCH 001/434] Proposing amp_post_template_body hook --- templates/html-start.php | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/html-start.php b/templates/html-start.php index 9ef52756ed6..2015171b87e 100644 --- a/templates/html-start.php +++ b/templates/html-start.php @@ -24,3 +24,4 @@ + From 9b7135463e5d2d4b22ba4c0f39f5ca0fd8677375 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 3 Jun 2019 13:17:57 +0200 Subject: [PATCH 002/434] Fix invalid covers annotations for functions --- tests/test-amp-analytics-options.php | 6 +-- tests/test-amp-helper-functions.php | 50 ++++++++++++------------ tests/test-amp-render-post.php | 2 +- tests/test-amp-style-sanitizer.php | 4 +- tests/test-amp.php | 2 +- tests/test-class-amp-options-manager.php | 8 ++-- tests/test-class-amp-theme-support.php | 2 +- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/tests/test-amp-analytics-options.php b/tests/test-amp-analytics-options.php index e890c15ae53..b7b2715d453 100644 --- a/tests/test-amp-analytics-options.php +++ b/tests/test-amp-analytics-options.php @@ -222,7 +222,7 @@ public function test_two_analytics_components_added() { /** * Test amp_get_analytics() * - * @covers \amp_get_analytics() + * @covers ::amp_get_analytics() */ public function test_amp_get_analytics() { $this->insert_one_option( @@ -252,7 +252,7 @@ function( $analytics ) use ( $key ) { /** * Test amp_print_analytics() * - * @covers \amp_print_analytics() + * @covers ::amp_print_analytics() */ public function test_amp_print_analytics() { $this->insert_one_option( @@ -277,7 +277,7 @@ public function test_amp_print_analytics() { * This test asserts that an issue discovered in PHP 7.1 is fixed. * * @see AMP_Theme_Support::add_hooks() Where add_action( 'wp_footer', 'amp_print_analytics' ) is done. - * @covers \amp_print_analytics() + * @covers ::amp_print_analytics() */ public function test_amp_print_analytics_when_empty() { diff --git a/tests/test-amp-helper-functions.php b/tests/test-amp-helper-functions.php index 7ba144075ab..6ee0d5058b9 100644 --- a/tests/test-amp-helper-functions.php +++ b/tests/test-amp-helper-functions.php @@ -43,7 +43,7 @@ public function return_example_url( $url, $post_id ) { /** * Test amp_get_slug(). * - * @covers \amp_get_slug() + * @covers ::amp_get_slug() */ public function test_amp_get_slug() { $this->assertSame( 'amp', amp_get_slug() ); @@ -52,7 +52,7 @@ public function test_amp_get_slug() { /** * Test amp_get_current_url(). * - * @covers \amp_get_current_url() + * @covers ::amp_get_current_url() */ public function test_amp_get_current_url() { $request_uris = array( @@ -78,7 +78,7 @@ public function test_amp_get_current_url() { /** * Test amp_get_permalink() without pretty permalinks. * - * @covers \amp_get_permalink() + * @covers ::amp_get_permalink() */ public function test_amp_get_permalink_without_pretty_permalinks() { remove_theme_support( AMP_Theme_Support::SLUG ); @@ -136,7 +136,7 @@ public function test_amp_get_permalink_without_pretty_permalinks() { /** * Test amp_get_permalink() with pretty permalinks. * - * @covers \amp_get_permalink() + * @covers ::amp_get_permalink() */ public function test_amp_get_permalink_with_pretty_permalinks() { global $wp_rewrite; @@ -205,7 +205,7 @@ public function test_amp_get_permalink_with_pretty_permalinks() { /** * Test amp_get_permalink() with theme support transitional mode. * - * @covers \amp_get_permalink() + * @covers ::amp_get_permalink() */ public function test_amp_get_permalink_with_theme_support() { global $wp_rewrite; @@ -230,7 +230,7 @@ public function test_amp_get_permalink_with_theme_support() { /** * Test amp_remove_endpoint. * - * @covers \amp_remove_endpoint() + * @covers ::amp_remove_endpoint() */ public function test_amp_remove_endpoint() { $this->assertEquals( 'https://example.com/foo/', amp_remove_endpoint( 'https://example.com/foo/?amp' ) ); @@ -243,7 +243,7 @@ public function test_amp_remove_endpoint() { /** * Test that hook is added. * - * @covers \amp_add_frontend_actions() + * @covers ::amp_add_frontend_actions() */ public function test_amp_add_frontend_actions() { $this->assertFalse( has_action( 'wp_head', 'amp_add_amphtml_link' ) ); @@ -278,7 +278,7 @@ public function get_amphtml_urls() { * Adding link when theme support is not present. * * @dataProvider get_amphtml_urls - * @covers \amp_add_amphtml_link() + * @covers ::amp_add_amphtml_link() * @param string $canonical_url Canonical URL. * @param string $amphtml_url The amphtml URL. */ @@ -332,7 +332,7 @@ public function test_amp_add_amphtml_link( $canonical_url, $amphtml_url ) { /** * Test is_amp_endpoint() function. * - * @covers \is_amp_endpoint() + * @covers ::is_amp_endpoint() */ public function test_is_amp_endpoint() { $this->go_to( get_permalink( $this->factory()->post->create() ) ); @@ -387,7 +387,7 @@ public function test_is_amp_endpoint() { /** * Test is_amp_endpoint() function for post embeds and feeds. * - * @covers \is_amp_endpoint() + * @covers ::is_amp_endpoint() * global WP_Query $wp_the_query */ public function test_is_amp_endpoint_for_post_embeds_and_feeds() { @@ -414,7 +414,7 @@ public function test_is_amp_endpoint_for_post_embeds_and_feeds() { /** * Test is_amp_endpoint() function before the parse_query action happens. * - * @covers \is_amp_endpoint() + * @covers ::is_amp_endpoint() * @expectedIncorrectUsage is_amp_endpoint */ public function test_is_amp_endpoint_before_parse_query_action() { @@ -426,7 +426,7 @@ public function test_is_amp_endpoint_before_parse_query_action() { /** * Test is_amp_endpoint() function when there is no WP_Query. * - * @covers \is_amp_endpoint() + * @covers ::is_amp_endpoint() * @expectedIncorrectUsage is_feed * @expectedIncorrectUsage is_embed * @expectedIncorrectUsage is_amp_endpoint @@ -440,7 +440,7 @@ public function test_is_amp_endpoint_when_no_wp_query() { /** * Test is_amp_endpoint() function before the wp action happens. * - * @covers \is_amp_endpoint() + * @covers ::is_amp_endpoint() * @expectedIncorrectUsage is_amp_endpoint */ public function test_is_amp_endpoint_before_wp_action() { @@ -474,7 +474,7 @@ public function capture_filter_call( $value ) { /** * Test amp_add_generator_metadata. * - * @covers \amp_add_generator_metadata() + * @covers ::amp_add_generator_metadata() */ public function test_amp_add_generator_metadata() { remove_theme_support( AMP_Theme_Support::SLUG ); @@ -502,9 +502,9 @@ public function test_amp_add_generator_metadata() { /** * Test script registering. * - * @covers \amp_register_default_scripts() - * @covers \amp_filter_script_loader_tag() - * @covers \amp_render_scripts() + * @covers ::amp_register_default_scripts() + * @covers ::amp_filter_script_loader_tag() + * @covers ::amp_render_scripts() * @global WP_Scripts $wp_scripts */ public function test_script_registering() { @@ -557,7 +557,7 @@ public function test_script_registering() { /** * Test amp_get_content_embed_handlers(). * - * @covers \amp_get_content_embed_handlers() + * @covers ::amp_get_content_embed_handlers() */ public function test_amp_get_content_embed_handlers() { $post = $this->factory()->post->create_and_get(); @@ -583,7 +583,7 @@ public function test_amp_get_content_embed_handlers() { /** * Test deprecated $post param for amp_get_content_embed_handlers(). * - * @covers \amp_get_content_embed_handlers() + * @covers ::amp_get_content_embed_handlers() */ public function test_amp_get_content_embed_handlers_deprecated_param() { $post = $this->factory()->post->create_and_get(); @@ -595,7 +595,7 @@ public function test_amp_get_content_embed_handlers_deprecated_param() { /** * Test amp_get_content_sanitizers(). * - * @covers \amp_get_content_sanitizers() + * @covers ::amp_get_content_sanitizers() */ public function test_amp_get_content_sanitizers() { $post = $this->factory()->post->create_and_get(); @@ -636,7 +636,7 @@ function( $classes ) { /** * Test deprecated $post param for amp_get_content_sanitizers(). * - * @covers \amp_get_content_sanitizers() + * @covers ::amp_get_content_sanitizers() */ public function test_amp_get_content_sanitizers_deprecated_param() { $post = $this->factory()->post->create_and_get(); @@ -648,7 +648,7 @@ public function test_amp_get_content_sanitizers_deprecated_param() { /** * Test post_supports_amp(). * - * @covers \post_supports_amp() + * @covers ::post_supports_amp() */ public function test_post_supports_amp() { add_post_type_support( 'page', AMP_Post_Type_Support::SLUG ); @@ -678,7 +678,7 @@ public function test_post_supports_amp() { /** * Test amp_get_post_image_metadata() * - * @covers \amp_get_post_image_metadata() + * @covers ::amp_get_post_image_metadata() */ public function test_amp_get_post_image_metadata() { $post_id = $this->factory()->post->create(); @@ -763,7 +763,7 @@ public function test_amp_get_post_image_metadata() { /** * Test amp_get_schemaorg_metadata(). * - * @covers \amp_get_schemaorg_metadata() + * @covers ::amp_get_schemaorg_metadata() */ public function test_amp_get_schemaorg_metadata() { update_option( 'blogname', 'Foo' ); @@ -975,7 +975,7 @@ function( $meta ) use ( $self ) { /** * Test amp_add_admin_bar_view_link() * - * @covers \amp_add_admin_bar_view_link() + * @covers ::amp_add_admin_bar_view_link() * @global \WP_Query $wp_query */ public function test_amp_add_admin_bar_item() { diff --git a/tests/test-amp-render-post.php b/tests/test-amp-render-post.php index 7771dfddd81..d89e551bcd4 100644 --- a/tests/test-amp-render-post.php +++ b/tests/test-amp-render-post.php @@ -32,7 +32,7 @@ public function test__valid_post() { /** * Test is_amp_endpoint. * - * @covers \is_amp_endpoint() + * @covers ::is_amp_endpoint() */ public function test__is_amp_endpoint() { $user_id = $this->factory()->user->create(); diff --git a/tests/test-amp-style-sanitizer.php b/tests/test-amp-style-sanitizer.php index 2c3a51b1a0e..18000f2761f 100644 --- a/tests/test-amp-style-sanitizer.php +++ b/tests/test-amp-style-sanitizer.php @@ -1847,7 +1847,7 @@ public function get_font_urls() { /** * Tests that font URLs get validated. * - * @covers \amp_filter_font_style_loader_tag_with_crossorigin_anonymous() + * @covers ::amp_filter_font_style_loader_tag_with_crossorigin_anonymous() * @dataProvider get_font_urls * @param string $url Font URL. * @param array $error_codes Error codes. @@ -1890,7 +1890,7 @@ public function test_font_urls( $url, $error_codes ) { * Test addition of crossorigin attribute to external stylesheet links. * * @covers AMP_Style_Sanitizer::process_link_element() - * @covers \amp_filter_font_style_loader_tag_with_crossorigin_anonymous() + * @covers ::amp_filter_font_style_loader_tag_with_crossorigin_anonymous() */ public function test_cors_enabled_stylesheet_url() { diff --git a/tests/test-amp.php b/tests/test-amp.php index 74fed547b7b..3e34e28cf55 100644 --- a/tests/test-amp.php +++ b/tests/test-amp.php @@ -21,7 +21,7 @@ public function tearDown() { /** * Test amp_is_canonical(). * - * @covers \amp_is_canonical() + * @covers ::amp_is_canonical() */ public function test_amp_is_canonical() { remove_theme_support( AMP_Theme_Support::SLUG ); diff --git a/tests/test-class-amp-options-manager.php b/tests/test-class-amp-options-manager.php index f79efa6103f..c4180513581 100644 --- a/tests/test-class-amp-options-manager.php +++ b/tests/test-class-amp-options-manager.php @@ -455,7 +455,7 @@ public function test_render_cache_miss_notice() { * Test handle_updated_theme_support_option for reader mode. * * @covers AMP_Options_Manager::handle_updated_theme_support_option() - * @covers \amp_admin_get_preview_permalink() + * @covers ::amp_admin_get_preview_permalink() */ public function test_handle_updated_theme_support_option_disabled() { wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); @@ -476,7 +476,7 @@ public function test_handle_updated_theme_support_option_disabled() { * Test handle_updated_theme_support_option for native when there is one auto-accepted issue. * * @covers AMP_Options_Manager::handle_updated_theme_support_option() - * @covers \amp_admin_get_preview_permalink() + * @covers ::amp_admin_get_preview_permalink() */ public function test_handle_updated_theme_support_option_native_success_but_error() { wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); @@ -524,7 +524,7 @@ public function test_handle_updated_theme_support_option_native_success_but_erro * Test handle_updated_theme_support_option for native when there is one auto-accepted issue. * * @covers AMP_Options_Manager::handle_updated_theme_support_option() - * @covers \amp_admin_get_preview_permalink() + * @covers ::amp_admin_get_preview_permalink() */ public function test_handle_updated_theme_support_option_native_validate_error() { wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); @@ -559,7 +559,7 @@ public function test_handle_updated_theme_support_option_native_validate_error() * Test handle_updated_theme_support_option for transitional mode. * * @covers AMP_Options_Manager::handle_updated_theme_support_option() - * @covers \amp_admin_get_preview_permalink() + * @covers ::amp_admin_get_preview_permalink() */ public function test_handle_updated_theme_support_option_paired() { wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 486c4aa0095..f0a4d8668a4 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -1311,7 +1311,7 @@ protected function get_etag_header_value( $headers ) { * @global WP_Scripts $wp_scripts * @covers AMP_Theme_Support::prepare_response() * @covers AMP_Theme_Support::ensure_required_markup() - * @covers \amp_render_scripts() + * @covers ::amp_render_scripts() */ public function test_prepare_response() { remove_action( 'wp_print_scripts', 'wp_print_service_workers', 9 ); From 45b1e8168b1991a84ee1db0d09c24bd8888062f5 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 3 Jun 2019 13:23:40 +0200 Subject: [PATCH 003/434] Use static access for factories Since https://core.trac.wordpress.org/changeset/35242 the factory has been a static method of `WP_UnitTestCase`. Non-static access is only there for BC. --- tests/test-amp-analytics-options.php | 6 +- tests/test-amp-helper-functions.php | 50 +++++++------- tests/test-amp-render-post.php | 8 +-- tests/test-amp-soundcloud-embed.php | 2 +- tests/test-amp-style-sanitizer.php | 2 +- tests/test-class-amp-cli.php | 24 +++---- tests/test-class-amp-core-block-handler.php | 4 +- tests/test-class-amp-gfycat-embed-handler.php | 2 +- tests/test-class-amp-http.php | 4 +- tests/test-class-amp-hulu-embed-handler.php | 2 +- tests/test-class-amp-imgur-embed-handler.php | 2 +- tests/test-class-amp-meta-box.php | 16 ++--- tests/test-class-amp-options-manager.php | 20 +++--- tests/test-class-amp-options-menu.php | 4 +- .../test-class-amp-playlist-embed-handler.php | 4 +- tests/test-class-amp-post-type-support.php | 2 +- tests/test-class-amp-service-worker.php | 2 +- tests/test-class-amp-story-post-type.php | 14 ++-- tests/test-class-amp-story-templates.php | 2 +- tests/test-class-amp-theme-support.php | 40 +++++------ ...test-class-amp-validated-url-post-type.php | 68 +++++++++---------- ...st-class-amp-validation-error-taxonomy.php | 42 ++++++------ .../test-class-amp-validation-manager.php | 36 +++++----- 23 files changed, 178 insertions(+), 178 deletions(-) diff --git a/tests/test-amp-analytics-options.php b/tests/test-amp-analytics-options.php index b7b2715d453..c5fb59b06b4 100644 --- a/tests/test-amp-analytics-options.php +++ b/tests/test-amp-analytics-options.php @@ -8,7 +8,7 @@ class AMP_Analytics_Options_Test extends WP_UnitTestCase { public function setUp() { parent::setUp(); AMP_Options_Manager::register_settings(); - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); } private $vendor = 'googleanalytics'; @@ -55,8 +55,8 @@ private function get_options() { } private function render_post() { - $user_id = $this->factory->user->create(); - $post_id = $this->factory->post->create( + $user_id = self::factory()->user->create(); + $post_id = self::factory()->post->create( array( 'post_author' => $user_id, ) diff --git a/tests/test-amp-helper-functions.php b/tests/test-amp-helper-functions.php index 6ee0d5058b9..cd0aafea193 100644 --- a/tests/test-amp-helper-functions.php +++ b/tests/test-amp-helper-functions.php @@ -85,21 +85,21 @@ public function test_amp_get_permalink_without_pretty_permalinks() { delete_option( 'permalink_structure' ); flush_rewrite_rules(); - $drafted_post = $this->factory()->post->create( + $drafted_post = self::factory()->post->create( array( 'post_name' => 'draft', 'post_status' => 'draft', 'post_type' => 'post', ) ); - $published_post = $this->factory()->post->create( + $published_post = self::factory()->post->create( array( 'post_name' => 'publish', 'post_status' => 'publish', 'post_type' => 'post', ) ); - $published_page = $this->factory()->post->create( + $published_page = self::factory()->post->create( array( 'post_name' => 'publish', 'post_status' => 'publish', @@ -149,19 +149,19 @@ public function test_amp_get_permalink_with_pretty_permalinks() { return $url . '#anchor'; }; - $drafted_post = $this->factory()->post->create( + $drafted_post = self::factory()->post->create( array( 'post_name' => 'draft', 'post_status' => 'draft', ) ); - $published_post = $this->factory()->post->create( + $published_post = self::factory()->post->create( array( 'post_name' => 'publish', 'post_status' => 'publish', ) ); - $published_page = $this->factory()->post->create( + $published_page = self::factory()->post->create( array( 'post_name' => 'publish', 'post_status' => 'publish', @@ -216,7 +216,7 @@ public function test_amp_get_permalink_with_theme_support() { $wp_rewrite->init(); $wp_rewrite->flush_rules(); - $post_id = $this->factory()->post->create(); + $post_id = self::factory()->post->create(); $this->assertEquals( get_permalink( $post_id ), amp_get_permalink( $post_id ) ); add_theme_support( @@ -257,7 +257,7 @@ public function test_amp_add_frontend_actions() { * @return array */ public function get_amphtml_urls() { - $post_id = $this->factory()->post->create(); + $post_id = self::factory()->post->create(); return array( 'home' => array( home_url( '/' ), @@ -335,7 +335,7 @@ public function test_amp_add_amphtml_link( $canonical_url, $amphtml_url ) { * @covers ::is_amp_endpoint() */ public function test_is_amp_endpoint() { - $this->go_to( get_permalink( $this->factory()->post->create() ) ); + $this->go_to( get_permalink( self::factory()->post->create() ) ); $this->assertFalse( is_amp_endpoint() ); // Legacy query var. @@ -372,7 +372,7 @@ public function test_is_amp_endpoint() { AMP_Options_Manager::update_option( 'supported_templates', array( 'is_author' ) ); // A post shouldn't be an AMP endpoint, as it was unchecked in the UI via the options above. - $this->go_to( $this->factory()->post->create() ); + $this->go_to( self::factory()->post->create() ); $this->assertFalse( is_amp_endpoint() ); // The homepage shouldn't be an AMP endpoint, as it was also unchecked in the UI. @@ -392,7 +392,7 @@ public function test_is_amp_endpoint() { */ public function test_is_amp_endpoint_for_post_embeds_and_feeds() { add_theme_support( AMP_Theme_Support::SLUG ); - $post_id = $this->factory()->post->create_and_get()->ID; + $post_id = self::factory()->post->create_and_get()->ID; $this->go_to( home_url( "?p=$post_id" ) ); $this->assertTrue( is_amp_endpoint() ); @@ -560,7 +560,7 @@ public function test_script_registering() { * @covers ::amp_get_content_embed_handlers() */ public function test_amp_get_content_embed_handlers() { - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); add_filter( 'amp_content_embed_handlers', array( $this, 'capture_filter_call' ), 10, 2 ); $this->last_filter_call = null; @@ -586,7 +586,7 @@ public function test_amp_get_content_embed_handlers() { * @covers ::amp_get_content_embed_handlers() */ public function test_amp_get_content_embed_handlers_deprecated_param() { - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); $this->setExpectedDeprecated( 'amp_get_content_embed_handlers' ); add_theme_support( AMP_Theme_Support::SLUG ); amp_get_content_embed_handlers( $post ); @@ -598,7 +598,7 @@ public function test_amp_get_content_embed_handlers_deprecated_param() { * @covers ::amp_get_content_sanitizers() */ public function test_amp_get_content_sanitizers() { - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); add_filter( 'amp_content_sanitizers', array( $this, 'capture_filter_call' ), 10, 2 ); $this->last_filter_call = null; @@ -639,7 +639,7 @@ function( $classes ) { * @covers ::amp_get_content_sanitizers() */ public function test_amp_get_content_sanitizers_deprecated_param() { - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); $this->setExpectedDeprecated( 'amp_get_content_sanitizers' ); add_theme_support( AMP_Theme_Support::SLUG ); amp_get_content_sanitizers( $post ); @@ -655,7 +655,7 @@ public function test_post_supports_amp() { // Test disabled by default for page for posts and show on front. update_option( 'show_on_front', 'page' ); - $post = $this->factory()->post->create_and_get( array( 'post_type' => 'page' ) ); + $post = self::factory()->post->create_and_get( array( 'post_type' => 'page' ) ); $this->assertTrue( post_supports_amp( $post ) ); update_option( 'show_on_front', 'page' ); $this->assertTrue( post_supports_amp( $post ) ); @@ -681,7 +681,7 @@ public function test_post_supports_amp() { * @covers ::amp_get_post_image_metadata() */ public function test_amp_get_post_image_metadata() { - $post_id = $this->factory()->post->create(); + $post_id = self::factory()->post->create(); $this->assertFalse( amp_get_post_image_metadata( $post_id ) ); $first_test_image = '/tmp/test-image.jpg'; @@ -718,7 +718,7 @@ public function test_amp_get_post_image_metadata() { $attachment_src = 'example/attachment.jpeg'; $attachment_height = 45; $attachment_width = 600; - $attachment_id = $this->factory()->attachment->create_object( + $attachment_id = self::factory()->attachment->create_object( $attachment_src, 0, array( @@ -749,7 +749,7 @@ public function test_amp_get_post_image_metadata() { // Test a video as an 'attachment' post type, which shouldn't have a schema.org image. $attachment_src = 'example/test-video.mpeg'; - $attachment_id = $this->factory()->attachment->create_object( + $attachment_id = self::factory()->attachment->create_object( $attachment_src, 0, array( @@ -774,20 +774,20 @@ public function test_amp_get_schemaorg_metadata() { 'name' => 'Foo', ); - $user_id = $this->factory()->user->create( + $user_id = self::factory()->user->create( array( 'first_name' => 'John', 'last_name' => 'Smith', ) ); - $page_id = $this->factory()->post->create( + $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Example Page', 'post_author' => $user_id, ) ); - $post_id = $this->factory()->post->create( + $post_id = self::factory()->post->create( array( 'post_type' => 'post', 'post_title' => 'Example Post', @@ -807,7 +807,7 @@ public function test_amp_get_schemaorg_metadata() { $custom_logo_src = 'example/custom-logo.jpeg'; $custom_logo_height = 45; $custom_logo_width = 600; - $custom_logo_id = $this->factory()->attachment->create_object( + $custom_logo_id = self::factory()->attachment->create_object( $custom_logo_src, 0, array( @@ -839,7 +839,7 @@ public function test_amp_get_schemaorg_metadata() { // Test the site icon as the publisher logo. $site_icon_src = 'foo/site-icon.jpeg'; - $site_icon_id = $this->factory()->attachment->create_object( + $site_icon_id = self::factory()->attachment->create_object( $site_icon_src, 0, array( @@ -981,7 +981,7 @@ function( $meta ) use ( $self ) { public function test_amp_add_admin_bar_item() { require_once ABSPATH . WPINC . '/class-wp-admin-bar.php'; - $post_id = $this->factory()->post->create(); + $post_id = self::factory()->post->create(); $this->go_to( get_permalink( $post_id ) ); global $wp_query; // Must be here after the go_to() call. diff --git a/tests/test-amp-render-post.php b/tests/test-amp-render-post.php index d89e551bcd4..65e140b6d03 100644 --- a/tests/test-amp-render-post.php +++ b/tests/test-amp-render-post.php @@ -10,8 +10,8 @@ public function test__invalid_post() { } public function test__valid_post() { - $user_id = $this->factory->user->create(); - $post_id = $this->factory->post->create( array( 'post_author' => $user_id ) ); + $user_id = self::factory()->user->create(); + $post_id = self::factory()->post->create( array( 'post_author' => $user_id ) ); // Need to use ob here since the method echos ob_start(); @@ -35,8 +35,8 @@ public function test__valid_post() { * @covers ::is_amp_endpoint() */ public function test__is_amp_endpoint() { - $user_id = $this->factory()->user->create(); - $post_id = $this->factory()->post->create( + $user_id = self::factory()->user->create(); + $post_id = self::factory()->post->create( array( 'post_author' => $user_id, ) diff --git a/tests/test-amp-soundcloud-embed.php b/tests/test-amp-soundcloud-embed.php index 389a8a4ebb0..93f4f49f11b 100644 --- a/tests/test-amp-soundcloud-embed.php +++ b/tests/test-amp-soundcloud-embed.php @@ -43,7 +43,7 @@ public function setUp() { * So on WP<4.9 we set a post global to ensure oEmbeds get processed. */ if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) { - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); } if ( function_exists( 'soundcloud_shortcode' ) ) { diff --git a/tests/test-amp-style-sanitizer.php b/tests/test-amp-style-sanitizer.php index 18000f2761f..14253eb084c 100644 --- a/tests/test-amp-style-sanitizer.php +++ b/tests/test-amp-style-sanitizer.php @@ -2330,7 +2330,7 @@ function() { add_action( 'wp_enqueue_scripts', 'twentyten_scripts_styles' ); AMP_Theme_Support::add_hooks(); wp_add_inline_style( 'admin-bar', '.admin-bar-inline-style{ color:red }' ); - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); return $render_template(); }, diff --git a/tests/test-class-amp-cli.php b/tests/test-class-amp-cli.php index bc2d67f473a..dd801e6c19f 100644 --- a/tests/test-class-amp-cli.php +++ b/tests/test-class-amp-cli.php @@ -45,11 +45,11 @@ public function test_count_urls_to_validate() { $this->assertEquals( $number_original_urls, AMP_CLI::count_urls_to_validate() ); AMP_CLI::$limit_type_validate_count = 100; - $category = $this->factory()->term->create( array( 'taxonomy' => 'category' ) ); + $category = self::factory()->term->create( array( 'taxonomy' => 'category' ) ); $number_new_posts = AMP_CLI::$limit_type_validate_count / 2; $post_ids = array(); for ( $i = 0; $i < $number_new_posts; $i++ ) { - $post_ids[] = $this->factory()->post->create( + $post_ids[] = self::factory()->post->create( array( 'tax_input' => array( 'category' => $category ), ) @@ -68,7 +68,7 @@ public function test_count_urls_to_validate() { $taxonomy = 'category'; $terms_for_current_taxonomy = array(); for ( $i = 0; $i < $number_of_new_terms; $i++ ) { - $terms_for_current_taxonomy[] = $this->factory()->term->create( + $terms_for_current_taxonomy[] = self::factory()->term->create( array( 'taxonomy' => $taxonomy, ) @@ -94,7 +94,7 @@ public function test_get_posts_that_support_amp() { $number_of_posts = 20; $ids = array(); for ( $i = 0; $i < $number_of_posts; $i++ ) { - $ids[] = $this->factory()->post->create(); + $ids[] = self::factory()->post->create(); } // This should count all of the newly-created posts as supporting AMP. @@ -239,7 +239,7 @@ public function test_get_posts_by_type() { for ( $i = 0; $i < $number_posts_each_post_type; $i++ ) { array_unshift( $expected_posts, - $this->factory()->post->create( + self::factory()->post->create( array( 'post_type' => $post_type, ) @@ -275,7 +275,7 @@ public function test_get_taxonomy_links() { $expected_links = array_map( 'get_term_link', get_terms( array( 'taxonomy' => $taxonomy ) ) ); $terms_for_current_taxonomy = array(); for ( $i = 0; $i < $number_links_each_taxonomy; $i++ ) { - $terms_for_current_taxonomy[] = $this->factory()->term->create( + $terms_for_current_taxonomy[] = self::factory()->term->create( array( 'taxonomy' => $taxonomy, ) @@ -284,7 +284,7 @@ public function test_get_taxonomy_links() { // Terms need to be associated with a post in order to be returned in get_terms(). wp_set_post_terms( - $this->factory()->post->create(), + self::factory()->post->create(), $terms_for_current_taxonomy, $taxonomy ); @@ -314,7 +314,7 @@ public function test_get_taxonomy_links() { * @covers AMP_CLI::get_author_page_urls() */ public function test_get_author_page_urls() { - $this->factory()->user->create(); + self::factory()->user->create(); $users = get_users(); $first_author = $users[0]; $first_author_url = get_author_posts_url( $first_author->ID, $first_author->user_nicename ); @@ -394,7 +394,7 @@ public function test_crawl_site() { $terms = array(); for ( $i = 0; $i < $number_of_posts; $i++ ) { - $post_id = $this->factory()->post->create(); + $post_id = self::factory()->post->create(); $posts[] = $post_id; $post_permalinks[] = get_permalink( $post_id ); } @@ -404,7 +404,7 @@ public function test_crawl_site() { $this->assertEmpty( array_diff( $post_permalinks, self::get_validated_urls() ) ); for ( $i = 0; $i < $number_of_terms; $i++ ) { - $terms[] = $this->factory()->category->create(); + $terms[] = self::factory()->category->create(); } // Terms need to be associated with a post in order to be returned in get_terms(). @@ -424,7 +424,7 @@ public function test_crawl_site() { * @covers AMP_CLI::validate_and_store_url() */ public function test_validate_and_store_url() { - $single_post_permalink = get_permalink( $this->factory()->post->create() ); + $single_post_permalink = get_permalink( self::factory()->post->create() ); AMP_CLI::validate_and_store_url( $single_post_permalink, 'post' ); $this->assertTrue( in_array( $single_post_permalink, self::get_validated_urls(), true ) ); @@ -432,7 +432,7 @@ public function test_validate_and_store_url() { $post_permalinks = array(); for ( $i = 0; $i < $number_of_posts; $i++ ) { - $permalink = get_permalink( $this->factory()->post->create() ); + $permalink = get_permalink( self::factory()->post->create() ); $post_permalinks[] = $permalink; AMP_CLI::validate_and_store_url( $permalink, 'post' ); } diff --git a/tests/test-class-amp-core-block-handler.php b/tests/test-class-amp-core-block-handler.php index 1e2d99792c9..ab7401a5134 100644 --- a/tests/test-class-amp-core-block-handler.php +++ b/tests/test-class-amp-core-block-handler.php @@ -92,9 +92,9 @@ public function test_placeholder_blocks() { * @covers \AMP_Core_Block_Handler::ampify_video_block() */ public function test_ampify_video_block() { - $attachment_id = $this->factory()->attachment->create_upload_object( DIR_TESTDATA . '/uploads/small-video.mp4' ); + $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/uploads/small-video.mp4' ); - $post_id = $this->factory()->post->create( + $post_id = self::factory()->post->create( array( 'post_title' => 'Video', 'post_content' => sprintf( diff --git a/tests/test-class-amp-gfycat-embed-handler.php b/tests/test-class-amp-gfycat-embed-handler.php index 5ba43466f14..fc20fc21c3f 100644 --- a/tests/test-class-amp-gfycat-embed-handler.php +++ b/tests/test-class-amp-gfycat-embed-handler.php @@ -39,7 +39,7 @@ function( $pre, $url ) { * So on WP<4.9 we set a post global to ensure oEmbeds get processed. */ if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) { - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); } } diff --git a/tests/test-class-amp-http.php b/tests/test-class-amp-http.php index b80e5b823d4..0c53e1e0896 100644 --- a/tests/test-class-amp-http.php +++ b/tests/test-class-amp-http.php @@ -539,8 +539,8 @@ function() { ); add_theme_support( AMP_Theme_Support::SLUG ); - $post = $this->factory()->post->create_and_get(); - $comment = $this->factory()->comment->create_and_get( + $post = self::factory()->post->create_and_get(); + $comment = self::factory()->comment->create_and_get( array( 'comment_post_ID' => $post->ID, ) diff --git a/tests/test-class-amp-hulu-embed-handler.php b/tests/test-class-amp-hulu-embed-handler.php index 8e8c4ab62ea..ed122d0e4d7 100644 --- a/tests/test-class-amp-hulu-embed-handler.php +++ b/tests/test-class-amp-hulu-embed-handler.php @@ -46,7 +46,7 @@ function( $pre, $r, $url ) { * So on WP<4.9 we set a post global to ensure oEmbeds get processed. */ if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) { - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); } } diff --git a/tests/test-class-amp-imgur-embed-handler.php b/tests/test-class-amp-imgur-embed-handler.php index b86089f9fdf..92957bbee11 100644 --- a/tests/test-class-amp-imgur-embed-handler.php +++ b/tests/test-class-amp-imgur-embed-handler.php @@ -46,7 +46,7 @@ function( $pre, $r, $url ) { * So on WP<4.9 we set a post global to ensure oEmbeds get processed. */ if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) { - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); } } diff --git a/tests/test-class-amp-meta-box.php b/tests/test-class-amp-meta-box.php index 2c1515ad7d4..d247131b206 100644 --- a/tests/test-class-amp-meta-box.php +++ b/tests/test-class-amp-meta-box.php @@ -169,9 +169,9 @@ public function test_enqueue_block_assets() { * @see AMP_Settings::render_status() */ public function test_render_status() { - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); wp_set_current_user( - $this->factory()->user->create( + self::factory()->user->create( array( 'role' => 'administrator', ) @@ -218,7 +218,7 @@ public function test_render_status() { // User doesn't have the capability to display the metabox. add_post_type_support( 'post', AMP_Post_Type_Support::SLUG ); wp_set_current_user( - $this->factory()->user->create( + self::factory()->user->create( array( 'role' => 'subscriber', ) @@ -242,7 +242,7 @@ public function test_get_status_and_errors() { ); // A post of type post shouldn't have errors, and AMP should be enabled. - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); $this->assertEquals( $expected_status_and_errors, $this->instance->get_status_and_errors( $post ) @@ -328,12 +328,12 @@ public function test_get_error_messages() { */ public function test_save_amp_status() { // Test failure. - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); $this->assertEmpty( get_post_meta( $post_id, AMP_Post_Meta_Box::STATUS_POST_META_KEY, true ) ); // Setup for success. wp_set_current_user( - $this->factory->user->create( + self::factory()->user->create( array( 'role' => 'administrator', ) @@ -343,13 +343,13 @@ public function test_save_amp_status() { $_POST[ AMP_Post_Meta_Box::STATUS_INPUT_NAME ] = 'disabled'; // Test revision bail. - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); delete_post_meta( $post_id, AMP_Post_Meta_Box::STATUS_POST_META_KEY ); wp_save_post_revision( $post_id ); $this->assertEmpty( get_post_meta( $post_id, AMP_Post_Meta_Box::STATUS_POST_META_KEY, true ) ); // Test post update success to disable. - $post_id = $this->factory->post->create(); + $post_id = self::factory()->post->create(); delete_post_meta( $post_id, AMP_Post_Meta_Box::STATUS_POST_META_KEY ); wp_update_post( array( diff --git a/tests/test-class-amp-options-manager.php b/tests/test-class-amp-options-manager.php index c4180513581..8c1c915f116 100644 --- a/tests/test-class-amp-options-manager.php +++ b/tests/test-class-amp-options-manager.php @@ -93,7 +93,7 @@ public function test_maybe_flush_rewrite_rules() { * @covers AMP_Theme_Support::reset_cache_miss_url_option() */ public function test_get_and_set_options() { - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); global $wp_settings_errors; wp_using_ext_object_cache( true ); // turn on external object cache flag. @@ -322,7 +322,7 @@ public function test_check_supported_post_type_update_errors() { */ public function test_render_welcome_notice() { // If this is not the main 'AMP Settings' page, this should not render the notice. - wp_set_current_user( $this->factory()->user->create() ); + wp_set_current_user( self::factory()->user->create() ); set_current_screen( 'edit.php' ); ob_start(); AMP_Options_Manager::render_welcome_notice(); @@ -458,10 +458,10 @@ public function test_render_cache_miss_notice() { * @covers ::amp_admin_get_preview_permalink() */ public function test_handle_updated_theme_support_option_disabled() { - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); AMP_Validation_Manager::init(); - $page_id = $this->factory()->post->create( array( 'post_type' => 'page' ) ); + $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); AMP_Options_Manager::update_option( 'supported_post_types', array( 'page' ) ); AMP_Options_Manager::update_option( 'theme_support', 'disabled' ); AMP_Options_Manager::handle_updated_theme_support_option(); @@ -479,9 +479,9 @@ public function test_handle_updated_theme_support_option_disabled() { * @covers ::amp_admin_get_preview_permalink() */ public function test_handle_updated_theme_support_option_native_success_but_error() { - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); - $post_id = $this->factory()->post->create( array( 'post_type' => 'post' ) ); + $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) ); AMP_Options_Manager::update_option( 'theme_support', 'native' ); AMP_Options_Manager::update_option( 'supported_post_types', array( 'post' ) ); @@ -527,8 +527,8 @@ public function test_handle_updated_theme_support_option_native_success_but_erro * @covers ::amp_admin_get_preview_permalink() */ public function test_handle_updated_theme_support_option_native_validate_error() { - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); - $this->factory()->post->create( array( 'post_type' => 'post' ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); + self::factory()->post->create( array( 'post_type' => 'post' ) ); AMP_Options_Manager::update_option( 'theme_support', 'native' ); AMP_Options_Manager::update_option( 'supported_post_types', array( 'post' ) ); @@ -562,9 +562,9 @@ public function test_handle_updated_theme_support_option_native_validate_error() * @covers ::amp_admin_get_preview_permalink() */ public function test_handle_updated_theme_support_option_paired() { - wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); - $post_id = $this->factory()->post->create( array( 'post_type' => 'post' ) ); + $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) ); AMP_Options_Manager::update_option( 'theme_support', 'paired' ); AMP_Options_Manager::update_option( 'supported_post_types', array( 'post' ) ); diff --git a/tests/test-class-amp-options-menu.php b/tests/test-class-amp-options-menu.php index 950e9e90733..40f519386b0 100644 --- a/tests/test-class-amp-options-menu.php +++ b/tests/test-class-amp-options-menu.php @@ -56,7 +56,7 @@ public function test_add_menu_items() { global $_parent_pages, $submenu, $wp_settings_sections, $wp_settings_fields; wp_set_current_user( - $this->factory->user->create( + self::factory()->user->create( array( 'role' => 'administrator', ) @@ -91,7 +91,7 @@ public function test_add_menu_items() { */ public function test_render_screen_for_admin_user() { wp_set_current_user( - $this->factory->user->create( + self::factory()->user->create( array( 'role' => 'administrator', ) diff --git a/tests/test-class-amp-playlist-embed-handler.php b/tests/test-class-amp-playlist-embed-handler.php index d86c4c2d289..83470c60374 100644 --- a/tests/test-class-amp-playlist-embed-handler.php +++ b/tests/test-class-amp-playlist-embed-handler.php @@ -96,7 +96,7 @@ public function test_styling() { $this->assertFalse( in_array( 'wp-mediaelement', wp_styles()->queue, true ) ); $this->assertFalse( in_array( $playlist_shortcode, wp_styles()->queue, true ) ); - $post = $this->factory()->post->create_and_get(); + $post = self::factory()->post->create_and_get(); $post->post_content = '[playlist ids="5,3"]'; $this->instance->enqueue_styles(); $style = wp_styles()->registered[ $playlist_shortcode ]; @@ -329,7 +329,7 @@ public function get_attributes( $type ) { public function get_file_ids( $files, $mime_type ) { $ids = array(); foreach ( $files as $file ) { - $ids[] = $this->factory()->attachment->create_object( + $ids[] = self::factory()->attachment->create_object( $file, 0, array( diff --git a/tests/test-class-amp-post-type-support.php b/tests/test-class-amp-post-type-support.php index 542bba357a8..e2e9f61c45a 100644 --- a/tests/test-class-amp-post-type-support.php +++ b/tests/test-class-amp-post-type-support.php @@ -99,7 +99,7 @@ public function test_get_support_error() { ); // Post type support. - $book_id = $this->factory()->post->create( array( 'post_type' => 'book' ) ); + $book_id = self::factory()->post->create( array( 'post_type' => 'book' ) ); $this->assertEquals( array( 'post-type-support' ), AMP_Post_Type_Support::get_support_errors( $book_id ) ); add_post_type_support( 'book', AMP_Post_Type_Support::SLUG ); $this->assertEmpty( AMP_Post_Type_Support::get_support_errors( $book_id ) ); diff --git a/tests/test-class-amp-service-worker.php b/tests/test-class-amp-service-worker.php index 06c5be88d21..ebe01b3d591 100644 --- a/tests/test-class-amp-service-worker.php +++ b/tests/test-class-amp-service-worker.php @@ -189,7 +189,7 @@ public function test_add_install_hooks() { remove_all_actions( 'wp_footer' ); remove_theme_support( 'amp' ); - $post_id = $this->factory()->post->create(); + $post_id = self::factory()->post->create(); $this->go_to( get_permalink( $post_id ) ); AMP_Service_Worker::add_install_hooks(); diff --git a/tests/test-class-amp-story-post-type.php b/tests/test-class-amp-story-post-type.php index e759d98998c..b19634e0ed3 100644 --- a/tests/test-class-amp-story-post-type.php +++ b/tests/test-class-amp-story-post-type.php @@ -132,7 +132,7 @@ public function test_enqueue_embed_styling() { $this->assertFalse( wp_style_is( AMP_Story_Post_Type::STORY_CARD_CSS_SLUG ) ); // Now that the conditional is satisfied, this should enqueue the stylesheet. - $amp_story_post = $this->factory()->post->create_and_get( array( 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG ) ); + $amp_story_post = self::factory()->post->create_and_get( array( 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG ) ); $this->go_to( add_query_arg( 'embed', '', get_post_permalink( $amp_story_post ) ) ); AMP_Story_Post_Type::enqueue_embed_styling(); } @@ -290,19 +290,19 @@ public function test_render_block_latest_stories() { */ public function test_remove_title_from_embed() { $initial_output = ''; - $wrong_post = $this->factory()->post->create_and_get(); + $wrong_post = self::factory()->post->create_and_get(); // The post type is not amp_story, so this should return the same $output it's passed. $this->assertEquals( $initial_output, AMP_Story_Post_Type::remove_title_from_embed( $initial_output, $wrong_post ) ); // The post type is correct, but the
does not have the expected class, so this should again return the same $output. - $correct_post = $this->factory()->post->create_and_get( array( 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG ) ); + $correct_post = self::factory()->post->create_and_get( array( 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG ) ); $block_quote_without_class = '
Example Title
'; $output_with_blockquote = $block_quote_without_class . $initial_output; $this->assertEquals( $output_with_blockquote, AMP_Story_Post_Type::remove_title_from_embed( $output_with_blockquote, $correct_post ) ); // All of the conditions are satisfied, so this should remove the
and the elements it contains. - $correct_post = $this->factory()->post->create_and_get( array( 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG ) ); + $correct_post = self::factory()->post->create_and_get( array( 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG ) ); $block_quote = '
Example Title
'; $output_with_blockquote = $block_quote . $initial_output; $this->assertEquals( $initial_output, AMP_Story_Post_Type::remove_title_from_embed( $output_with_blockquote, $correct_post ) ); @@ -316,13 +316,13 @@ public function test_remove_title_from_embed() { public function test_change_embed_iframe_attributes() { remove_theme_support( 'amp' ); $original_embed_markup = '', ' - + @@ -76,7 +76,7 @@ public function get_data() { 'iframe_with_height_only' => array( '', ' - + @@ -84,10 +84,21 @@ public function get_data() { ', ), + 'iframe_with_100_percent_width' => array( + '', + ' + + + + ', + ), + 'iframe_with_width_only' => array( '', ' - + @@ -153,7 +164,7 @@ public function get_data() { 'iframe_with_id_attribute' => array( '', ' - + @@ -164,7 +175,7 @@ public function get_data() { 'iframe_with_protocol_relative_url' => array( '', ' - + @@ -289,6 +300,48 @@ public function get_data() { 'add_placeholder' => true, ), ), + + 'iframe_relative_url' => array( + '', + '', + array( + 'add_noscript_fallback' => false, + 'add_placeholder' => false, + 'current_origin' => 'https://example.com', + ), + ), + + 'iframe_scheme_relative_url' => array( + '', + '', + array( + 'add_noscript_fallback' => false, + 'add_placeholder' => false, + 'current_origin' => 'https://example.com', + ), + ), + + 'iframe_relative_url_with_alias_origin' => array( + '', + '', + array( + 'add_noscript_fallback' => false, + 'add_placeholder' => false, + 'current_origin' => 'https://example.com', + 'alias_origin' => 'https://alt.example.org', + ), + ), + + 'iframe_absolute_url_with_alias_origin' => array( + '', + '', + array( + 'add_noscript_fallback' => false, + 'add_placeholder' => false, + 'current_origin' => 'https://example.com', + 'alias_origin' => 'https://alt.example.org', + ), + ), ); } diff --git a/tests/test-amp-script-sanitizer.php b/tests/test-amp-script-sanitizer.php index 4c056deccd7..c0f873b9a86 100644 --- a/tests/test-amp-script-sanitizer.php +++ b/tests/test-amp-script-sanitizer.php @@ -104,6 +104,6 @@ public function test_boilerplate_preservation() { $this->assertRegExp( '/\s*/', $content ); $this->assertContains( '', $content ); $this->assertContains( 'Has script? Nope!', $content ); - $this->assertContains( '', $content ); + $this->assertContains( '', $content ); } } diff --git a/tests/test-amp-video-sanitizer.php b/tests/test-amp-video-sanitizer.php index 995793c6686..ae445271371 100644 --- a/tests/test-amp-video-sanitizer.php +++ b/tests/test-amp-video-sanitizer.php @@ -44,7 +44,7 @@ public function get_data() { 'video_without_dimensions' => array( '', - 'https://example.com/file.mp4', + 'https://example.com/file.mp4', ), 'autoplay_attribute' => array( diff --git a/tests/test-class-amp-base-sanitizer.php b/tests/test-class-amp-base-sanitizer.php index cdd3fe9318b..a83d2e1b4cd 100644 --- a/tests/test-class-amp-base-sanitizer.php +++ b/tests/test-class-amp-base-sanitizer.php @@ -54,6 +54,7 @@ public function get_data() { array( 'height' => 400, 'layout' => 'fixed-height', + 'width' => 'auto', ), ), @@ -65,6 +66,7 @@ public function get_data() { array( 'height' => 400, 'layout' => 'fixed-height', + 'width' => 'auto', ), ), @@ -75,6 +77,7 @@ public function get_data() { array( 'height' => 100, 'layout' => 'fixed-height', + 'width' => 'auto', ), ), @@ -85,6 +88,7 @@ public function get_data() { array( 'height' => 400, 'layout' => 'fixed-height', + 'width' => 'auto', ), ), From bec6d2cd3bdff390044b1f3d1bdb10be8c1b8e72 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 2 Jul 2019 01:58:50 -0700 Subject: [PATCH 086/434] =?UTF-8?q?Improve=20Soundcloud=20embed:=20support?= =?UTF-8?q?=20playlists,=20preserve=20visual/he=E2=80=A6=20(#2722)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../embeds/class-amp-soundcloud-embed.php | 170 +++++++++++------- tests/test-amp-soundcloud-embed.php | 111 ++++++++---- tests/test-class-amp-theme-support.php | 2 +- 3 files changed, 191 insertions(+), 92 deletions(-) diff --git a/includes/embeds/class-amp-soundcloud-embed.php b/includes/embeds/class-amp-soundcloud-embed.php index 5ca18ee321b..438f61435ae 100644 --- a/includes/embeds/class-amp-soundcloud-embed.php +++ b/includes/embeds/class-amp-soundcloud-embed.php @@ -23,7 +23,10 @@ class AMP_SoundCloud_Embed_Handler extends AMP_Base_Embed_Handler { * Register embed. */ public function register_embed() { - add_shortcode( 'soundcloud', array( $this, 'shortcode' ) ); + if ( function_exists( 'soundcloud_shortcode' ) ) { + // @todo Move this to Jetpack. + add_shortcode( 'soundcloud', array( $this, 'shortcode' ) ); + } add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 2 ); } @@ -31,7 +34,10 @@ public function register_embed() { * Unregister embed. */ public function unregister_embed() { - remove_shortcode( 'soundcloud' ); + if ( function_exists( 'soundcloud_shortcode' ) ) { + // @todo Move this to Jetpack. + remove_shortcode( 'soundcloud' ); + } remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); } @@ -42,15 +48,14 @@ public function unregister_embed() { * * @deprecated Core's oEmbed handler is now used instead, with embed_oembed_html filter used to convert to AMP. * @param array $matches URL pattern matches. - * @param array $attr Shortcode attribues. + * @param array $attr Shortcode attributes. * @param string $url URL. * @return string Rendered oEmbed. */ public function oembed( $matches, $attr, $url ) { _deprecated_function( __METHOD__, '0.6' ); unset( $matches, $attr ); - $track_id = $this->get_track_id_from_url( $url ); - return $this->render( compact( 'track_id' ) ); + return $this->render( $this->extract_params_from_iframe_src( $url ), $url ); } /** @@ -61,31 +66,49 @@ public function oembed( $matches, $attr, $url ) { * @return string Embed. */ public function filter_embed_oembed_html( $cache, $url ) { - $parsed_url = wp_parse_url( $url ); - if ( false === strpos( $parsed_url['host'], 'soundcloud.com' ) ) { + if ( false === strpos( wp_parse_url( $url, PHP_URL_HOST ), 'soundcloud.com' ) ) { return $cache; } - return $this->parse_amp_component_from_iframe( $cache ); + return $this->parse_amp_component_from_iframe( $cache, $url ); } /** * Parse AMP component from iframe. * - * @param string $html HTML. + * @param string $html HTML. + * @param string|null $url Embed URL, for fallback purposes. * @return string AMP component or empty if unable to determine SoundCloud ID. */ - private function parse_amp_component_from_iframe( $html ) { + private function parse_amp_component_from_iframe( $html, $url ) { $embed = ''; - if ( preg_match( '#.+?)".*>#', $html, $matches ) ) { - $src = html_entity_decode( $matches['url'], ENT_QUOTES ); + + if ( preg_match( '#]*?src="(?P[^"]+)"#s', $html, $matches ) ) { + $src = html_entity_decode( $matches['src'], ENT_QUOTES ); $query = array(); parse_str( wp_parse_url( $src, PHP_URL_QUERY ), $query ); if ( ! empty( $query['url'] ) ) { - $embed = $this->render( - array( - 'track_id' => $this->get_track_id_from_url( $query['url'] ), - ) - ); + $props = $this->extract_params_from_iframe_src( $query['url'] ); + if ( isset( $query['visual'] ) ) { + $props['visual'] = $query['visual']; + } + + if ( $url && preg_match( '#]*?title="(?P[^"]+)"#s', $html, $matches ) ) { + $props['fallback'] = sprintf( + '<a fallback href="%s">%s</a>', + esc_url( $url ), + esc_html( $matches['title'] ) + ); + } + + if ( preg_match( '#<iframe[^>]*?height="(?P<height>\d+)"#s', $html, $matches ) ) { + $props['height'] = (int) $matches['height']; + } + + if ( preg_match( '#<iframe[^>]*?width="(?P<width>\d+)"#s', $html, $matches ) ) { + $props['width'] = (int) $matches['width']; + } + + $embed = $this->render( $props, $url ); } } return $embed; @@ -94,68 +117,87 @@ private function parse_amp_component_from_iframe( $html ) { /** * Render shortcode. * + * @todo Move this to Jetpack. + * * @param array $attr Shortcode attributes. * @param string $content Shortcode content. * @return string Rendered shortcode. */ public function shortcode( $attr, $content = null ) { - $output = ''; - if ( function_exists( 'soundcloud_shortcode' ) ) { - if ( empty( $attr['url'] ) && ! empty( $attr['id'] ) ) { - $attr['url'] = 'https://api.soundcloud.com/tracks/' . intval( $attr['id'] ); - } - $output = soundcloud_shortcode( $attr, $content ); - $output = $this->parse_amp_component_from_iframe( $output ); - } else { - $url = null; - if ( isset( $attr['id'] ) ) { - $url = 'https://w.soundcloud.com/player/?url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F' . intval( $attr['id'] ); - } + if ( ! function_exists( 'soundcloud_shortcode' ) ) { + return ''; + } - if ( isset( $attr['url'] ) ) { - $url = $attr['url']; - } elseif ( isset( $attr[0] ) ) { - $url = $attr[0]; - } elseif ( function_exists( 'shortcode_new_to_old_params' ) ) { - $url = shortcode_new_to_old_params( $attr ); - } + if ( isset( $attr['url'] ) ) { + $url = $attr['url']; + } elseif ( isset( $attr['id'] ) ) { + $url = 'https://api.soundcloud.com/tracks/' . $attr['id']; + } elseif ( isset( $attr[0] ) ) { + $url = is_numeric( $attr[0] ) ? 'https://api.soundcloud.com/tracks/' . $attr[0] : $attr[0]; + } elseif ( function_exists( 'shortcode_new_to_old_params' ) ) { + $url = shortcode_new_to_old_params( $attr ); + } - if ( $url ) { - $output = $this->render_embed_fallback( $url ); - } + // Defer to oEmbed if an oEmbeddable URL is provided. + if ( isset( $url ) && 'api.soundcloud.com' !== wp_parse_url( $url, PHP_URL_HOST ) ) { + global $wp_embed; + return $wp_embed->shortcode( $attr, $url ); + } + + if ( isset( $url ) && ! isset( $attr['url'] ) ) { + $attr['url'] = $url; } - return $output; + $output = soundcloud_shortcode( $attr, $content ); + + return $this->parse_amp_component_from_iframe( $output, null ); } /** * Render embed. * - * @param array $args Args. + * @param array $args Args. + * @param string $url Embed URL for fallback purposes. Optional. * @return string Rendered embed. * @global WP_Embed $wp_embed */ - public function render( $args ) { + public function render( $args, $url ) { $args = wp_parse_args( $args, array( - 'track_id' => false, - 'url' => null, + 'track_id' => false, + 'playlist_id' => false, + 'height' => null, + 'width' => null, + 'visual' => null, + 'fallback' => '', ) ); - if ( empty( $args['track_id'] ) ) { - return $this->render_embed_fallback( $args['url'] ); + $this->did_convert_elements = true; + + $attributes = array(); + if ( ! empty( $args['track_id'] ) ) { + $attributes['data-trackid'] = $args['track_id']; + } elseif ( ! empty( $args['playlist_id'] ) ) { + $attributes['data-playlistid'] = $args['playlist_id']; + } elseif ( $url ) { + return $this->render_embed_fallback( $url ); + } else { + return ''; + } + + if ( isset( $args['visual'] ) ) { + $attributes['data-visual'] = rest_sanitize_boolean( $args['visual'] ) ? 'true' : 'false'; } - $this->did_convert_elements = true; + // @todo Set width to $args['width'] and layout to responsive once amp-soundcloud supports it: <https://github.com/ampproject/amphtml/issues/23144>. + $attributes['height'] = $args['height'] ? $args['height'] : $this->args['height']; + $attributes['layout'] = 'fixed-height'; return AMP_HTML_Utils::build_tag( 'amp-soundcloud', - array( - 'data-trackid' => $args['track_id'], - 'layout' => 'fixed-height', - 'height' => $this->args['height'], - ) + $attributes, + $args['fallback'] ); } @@ -163,13 +205,13 @@ public function render( $args ) { * Render embed fallback. * * @param string $url URL. - * @returns string + * @return string Fallback link. */ private function render_embed_fallback( $url ) { return AMP_HTML_Utils::build_tag( 'a', array( - 'href' => esc_url( $url ), + 'href' => esc_url_raw( $url ), 'class' => 'amp-wp-embed-fallback', ), esc_html( $url ) @@ -177,17 +219,23 @@ private function render_embed_fallback( $url ) { } /** - * Get track_id from URL. + * Get params from Soundcloud iframe src. * * @param string $url URL. - * - * @return string Track ID or empty string if none matched. + * @return array Params extracted from URL. */ - private function get_track_id_from_url( $url ) { + private function extract_params_from_iframe_src( $url ) { $parsed_url = wp_parse_url( $url ); - if ( ! preg_match( '#tracks/(?P<track_id>[^/]+)#', $parsed_url['path'], $matches ) ) { - return ''; + if ( preg_match( '#tracks/(?P<track_id>\d+)#', $parsed_url['path'], $matches ) ) { + return array( + 'track_id' => $matches['track_id'], + ); + } + if ( preg_match( '#playlists/(?P<playlist_id>\d+)#', $parsed_url['path'], $matches ) ) { + return array( + 'playlist_id' => $matches['playlist_id'], + ); } - return $matches['track_id']; + return array(); } } diff --git a/tests/test-amp-soundcloud-embed.php b/tests/test-amp-soundcloud-embed.php index 389a8a4ebb0..aa82a9c5c18 100644 --- a/tests/test-amp-soundcloud-embed.php +++ b/tests/test-amp-soundcloud-embed.php @@ -13,19 +13,34 @@ class AMP_SoundCloud_Embed_Test extends WP_UnitTestCase { /** - * The oEmbed URL. + * Track URL. * * @var string */ - protected $oembed_url = 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor'; + protected $track_url = 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor'; /** - * Response for oEmbed request. + * Playlist URL. * - * @see AMP_SoundCloud_Embed_Test::$oembed_url * @var string */ - protected $oembed_response = '{"version":1.0,"type":"rich","provider_name":"SoundCloud","provider_url":"http://soundcloud.com","height":400,"width":500,"title":"Mozart - Requiem in D minor Complete Full by Jack Villano Villano","description":"mass in D Minor ","thumbnail_url":"http://i1.sndcdn.com/artworks-000046826426-o7i9ki-t500x500.jpg","html":"\u003Ciframe width=\"500\" height=\"400\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?visual=true\u0026url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F90097394\u0026show_artwork=true\u0026maxwidth=500\u0026maxheight=750\u0026dnt=1\"\u003E\u003C/iframe\u003E","author_name":"Jack Villano Villano","author_url":"https://soundcloud.com/jack-villano-villano"}'; + protected $playlist_url = 'https://soundcloud.com/classical-music-playlist/sets/classical-music-essential-collection'; + + /** + * Response for track oEmbed request. + * + * @see AMP_SoundCloud_Embed_Test::$track_url + * @var string + */ + protected $track_oembed_response = '{"version":1.0,"type":"rich","provider_name":"SoundCloud","provider_url":"http://soundcloud.com","height":400,"width":500,"title":"Mozart - Requiem in D minor Complete Full by Jack Villano Villano","description":"mass in D Minor ","thumbnail_url":"http://i1.sndcdn.com/artworks-000046826426-o7i9ki-t500x500.jpg","html":"\u003Ciframe width=\"500\" height=\"400\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?visual=true\u0026url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F90097394\u0026show_artwork=true\u0026maxwidth=500\u0026maxheight=750\u0026dnt=1\"\u003E\u003C/iframe\u003E","author_name":"Jack Villano Villano","author_url":"https://soundcloud.com/jack-villano-villano"}'; + + /** + * Response for playlist oEmbed request. + * + * @see AMP_SoundCloud_Embed_Test::$playlist_url + * @var string + */ + protected $playlist_oembed_response = '{"version":1.0,"type":"rich","provider_name":"SoundCloud","provider_url":"http://soundcloud.com","height":450,"width":500,"title":"Classical Music - The Essential Collection by Classical Music","description":"Classical Music - The Essential Collection features 50 of the finest Classical Masterpieces ever written. Definitely not to working to! ","thumbnail_url":"http://i1.sndcdn.com/artworks-000083473866-mno23j-t500x500.jpg","html":"\u003Ciframe width=\"500\" height=\"450\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?visual=true\u0026url=https%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F40936190\u0026show_artwork=true\u0026maxwidth=500\u0026maxheight=750\u0026dnt=1\"\u003E\u003C/iframe\u003E","author_name":"Classical Music","author_url":"https://soundcloud.com/classical-music-playlist"}'; /** * Set up. @@ -46,6 +61,7 @@ public function setUp() { $post = $this->factory()->post->create_and_get(); } + // @todo This should be moved to Jetpack. if ( function_exists( 'soundcloud_shortcode' ) ) { add_shortcode( 'soundcloud', 'soundcloud_shortcode' ); } @@ -70,20 +86,27 @@ public function tearDown() { * @return array Response data. */ public function mock_http_request( $preempt, $r, $url ) { + if ( false === strpos( $url, 'soundcloud.com' ) ) { + return $preempt; + } unset( $r ); - if ( false !== strpos( $url, 'soundcloud.com' ) ) { - return array( - 'body' => $this->oembed_response, - 'headers' => array(), - 'response' => array( - 'code' => 200, - 'message' => 'ok', - ), - 'cookies' => array(), - 'http_response' => null, - ); + + if ( false !== strpos( $url, 'sets' ) ) { + $body = $this->playlist_oembed_response; + } else { + $body = $this->track_oembed_response; } - return $preempt; + + return array( + 'body' => $body, + 'headers' => array(), + 'response' => array( + 'code' => 200, + 'message' => 'ok', + ), + 'cookies' => array(), + 'http_response' => null, + ); } /** @@ -93,35 +116,59 @@ public function mock_http_request( $preempt, $r, $url ) { */ public function get_conversion_data() { $data = array( - 'no_embed' => array( + 'no_embed' => array( '<p>Hello world.</p>', '<p>Hello world.</p>' . PHP_EOL, ), - 'url_simple' => array( - $this->oembed_url . PHP_EOL, - '<p><amp-soundcloud data-trackid="90097394" layout="fixed-height" height="200"></amp-soundcloud></p>' . PHP_EOL, + 'track_simple' => array( + $this->track_url . PHP_EOL, + '<p><amp-soundcloud data-trackid="90097394" data-visual="true" height="400" layout="fixed-height">' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? '<a fallback href="https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor">Mozart – Requiem in D minor Complete Full by Jack Villano Villano</a>' : '' ) . '</amp-soundcloud></p>' . PHP_EOL, + ), + + 'playlist_simple' => array( + $this->playlist_url . PHP_EOL, + '<p><amp-soundcloud data-playlistid="40936190" data-visual="true" height="450" layout="fixed-height">' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? '<a fallback href="https://soundcloud.com/classical-music-playlist/sets/classical-music-essential-collection">Classical Music – The Essential Collection by Classical Music</a>' : '' ) . '</amp-soundcloud></p>' . PHP_EOL, ), ); + // @todo All the following should be moved to Jetpack. if ( defined( 'JETPACK__PLUGIN_DIR' ) ) { require_once JETPACK__PLUGIN_DIR . 'modules/shortcodes/soundcloud.php'; } - if ( function_exists( 'soundcloud_shortcode' ) ) { $data = array_merge( $data, array( - // This is supported by Jetpack. - 'shortcode_unnamed_attr_as_url' => array( + 'shortcode_with_bare_track_api_url' => array( + '[soundcloud https://api.soundcloud.com/tracks/89299804]' . PHP_EOL, + '<amp-soundcloud data-trackid="89299804" data-visual="false" height="166" layout="fixed-height"></amp-soundcloud>' . PHP_EOL, + ), + + 'shortcode_with_track_api_url' => array( '[soundcloud url=https://api.soundcloud.com/tracks/89299804]' . PHP_EOL, - '<amp-soundcloud data-trackid="89299804" layout="fixed-height" height="200"></amp-soundcloud>' . PHP_EOL, + '<amp-soundcloud data-trackid="89299804" data-visual="false" height="166" layout="fixed-height"></amp-soundcloud>' . PHP_EOL, + ), + + 'shortcode_with_track_permalink' => array( + "[soundcloud url=$this->track_url]", + '<amp-soundcloud data-trackid="90097394" data-visual="true" height="400" layout="fixed-height">' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? '<a fallback href="https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor">Mozart - Requiem in D minor Complete Full by Jack Villano Villano</a>' : '' ) . '</amp-soundcloud>' . PHP_EOL, + ), + + 'shortcode_with_bare_track_permalink' => array( + "[soundcloud $this->track_url]", + '<amp-soundcloud data-trackid="90097394" data-visual="true" height="400" layout="fixed-height">' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? '<a fallback href="https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor">Mozart - Requiem in D minor Complete Full by Jack Villano Villano</a>' : '' ) . '</amp-soundcloud>' . PHP_EOL, + ), + + 'shortcode_with_playlist_permalink' => array( + "[soundcloud url=$this->playlist_url]", + '<amp-soundcloud data-playlistid="40936190" data-visual="true" height="450" layout="fixed-height">' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? '<a fallback href="https://soundcloud.com/classical-music-playlist/sets/classical-music-essential-collection">Classical Music - The Essential Collection by Classical Music</a>' : '' ) . '</amp-soundcloud>' . PHP_EOL, ), // This apparently only works on WordPress.com. - 'shortcode_with_id' => array( + 'shortcode_with_id' => array( '[soundcloud id=89299804]' . PHP_EOL, - '<amp-soundcloud data-trackid="89299804" layout="fixed-height" height="200"></amp-soundcloud>' . PHP_EOL, + '<amp-soundcloud data-trackid="89299804" data-visual="false" height="166" layout="fixed-height"></amp-soundcloud>' . PHP_EOL, ), ) ); @@ -156,12 +203,16 @@ public function test__conversion( $source, $expected ) { */ public function get_scripts_data() { return array( - 'not_converted' => array( + 'not_converted' => array( '<p>Hello World.</p>', array(), ), - 'converted' => array( - $this->oembed_url . PHP_EOL, + 'converted_track' => array( + $this->track_url . PHP_EOL, + array( 'amp-soundcloud' => true ), + ), + 'converted_playlist' => array( + $this->playlist_url . PHP_EOL, array( 'amp-soundcloud' => true ), ), ); diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index d733f939986..d7f5a15e185 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -1379,7 +1379,7 @@ protected function get_etag_header_value( $headers ) { * @covers \amp_render_scripts() */ public function test_prepare_response() { - remove_action( 'wp_print_scripts', 'wp_print_service_workers', 9 ); + add_theme_support( 'amp' ); add_filter( 'home_url', From f4aca84a7db772ff0bbe59521c74fd1393af421d Mon Sep 17 00:00:00 2001 From: Ryan Kienstra <kienstraryan@gmail.com> Date: Tue, 2 Jul 2019 04:45:18 -0500 Subject: [PATCH 087/434] Add support for portrait featured images in non-AMP Story posts (#2711) --- assets/src/block-editor/index.js | 4 +- .../featured-image-select-media-frame.js | 2 +- .../components/with-cropped-featured-image.js | 38 +++++++++++++---- assets/src/common/constants.js | 1 + assets/src/common/helpers/index.js | 41 ++++++++++++++++++- .../common/helpers/test/getAspectRatioType.js | 19 +++++++++ .../test/getMinimumFeaturedImageDimensions.js | 2 +- ...tMinimumPortraitFeaturedImageDimensions.js | 10 +++++ 8 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 assets/src/common/helpers/test/getAspectRatioType.js create mode 100644 assets/src/common/helpers/test/getMinimumPortraitFeaturedImageDimensions.js diff --git a/assets/src/block-editor/index.js b/assets/src/block-editor/index.js index b50f7b51030..4f5c429939d 100644 --- a/assets/src/block-editor/index.js +++ b/assets/src/block-editor/index.js @@ -11,7 +11,7 @@ import { select } from '@wordpress/data'; */ import { withCroppedFeaturedImage, withFeaturedImageNotice } from '../common/components'; import { addAMPAttributes, addAMPExtraProps, filterBlocksEdit, filterBlocksSave } from './helpers'; -import { getMinimumFeaturedImageDimensions } from '../common/helpers'; +import { getMinimumFeaturedImageDimensions, getMinimumPortraitFeaturedImageDimensions } from '../common/helpers'; import './store'; const { @@ -37,7 +37,7 @@ if ( isWebsiteEnabled() ) { addFilter( 'editor.BlockEdit', 'ampEditorBlocks/filterEdit', filterBlocksEdit, 20 ); addFilter( 'blocks.getSaveContent.extraProps', 'ampEditorBlocks/addExtraAttributes', addAMPExtraProps ); addFilter( 'editor.PostFeaturedImage', 'ampEditorBlocks/withFeaturedImageNotice', withFeaturedImageNotice ); - addFilter( 'editor.MediaUpload', 'ampEditorBlocks/addCroppedFeaturedImage', ( InitialMediaUpload ) => withCroppedFeaturedImage( InitialMediaUpload, getMinimumFeaturedImageDimensions() ) ); + addFilter( 'editor.MediaUpload', 'ampEditorBlocks/addCroppedFeaturedImage', ( InitialMediaUpload ) => withCroppedFeaturedImage( InitialMediaUpload, getMinimumFeaturedImageDimensions(), getMinimumPortraitFeaturedImageDimensions() ) ); } /* diff --git a/assets/src/common/components/featured-image-select-media-frame.js b/assets/src/common/components/featured-image-select-media-frame.js index 4b9c4626cf0..d96e7e38f39 100644 --- a/assets/src/common/components/featured-image-select-media-frame.js +++ b/assets/src/common/components/featured-image-select-media-frame.js @@ -72,7 +72,7 @@ const FeaturedImageToolbarSelect = wp.media.view.Toolbar.Select.extend( { const minWidth = state.collection.get( 'library' ).get( 'suggestedWidth' ); const minHeight = state.collection.get( 'library' ).get( 'suggestedHeight' ); - if ( ! attachment || ( attachment.get( 'width' ) >= minWidth && attachment.get( 'height' ) >= minHeight ) ) { + if ( ! attachment || ! attachment.get( 'width' ) || ( attachment.get( 'width' ) >= minWidth && attachment.get( 'height' ) >= minHeight ) ) { this.secondary.unset( 'select-error' ); } else { this.secondary.set( diff --git a/assets/src/common/components/with-cropped-featured-image.js b/assets/src/common/components/with-cropped-featured-image.js index caadb72803d..a24f2b594fc 100644 --- a/assets/src/common/components/with-cropped-featured-image.js +++ b/assets/src/common/components/with-cropped-featured-image.js @@ -14,6 +14,7 @@ import { dispatch } from '@wordpress/data'; */ import FeaturedImageSelectMediaFrame from './featured-image-select-media-frame'; import FeaturedImageCropper from './featured-image-cropper'; +import { getAspectRatioType } from '../helpers'; const { wp } = window; @@ -23,13 +24,19 @@ const { wp } = window; * Only applies to the MediaUpload in the Featured Image component, PostFeaturedImage. * Suggests cropping of the featured image if it's not 696 x 928. * Mostly copied from customize-controls.js. + * The optional alternateMinImageDimensions are used for the crop size when they are the same aspect ratio type as the actual image dimensions. + * For example, if the selected image has a portrait aspect ratio, and the alternateMinImageDimensions are also portrait, + * this will use the alternate dimensions as long as the selected image is big enough. + * Otherwise, this will use the minImageDimensions. * - * @param {Function} InitialMediaUpload The MediaUpload component, passed from the filter. - * @param {Object} minImageDimensions Minimum required image dimensions. + * @param {Function} InitialMediaUpload The MediaUpload component, passed from the filter. + * @param {Object} minImageDimensions Minimum required image dimensions. + * @param {Object} alternateMinImageDimensions Alternate required image dimensions, like portrait dimensions (optional). * @return {Function} The wrapped component. */ -export default ( InitialMediaUpload, minImageDimensions ) => { +export default ( InitialMediaUpload, minImageDimensions, alternateMinImageDimensions = {} ) => { const { width: EXPECTED_WIDTH, height: EXPECTED_HEIGHT } = minImageDimensions; + const { width: ALTERNATE_EXPECTED_WIDTH, height: ALTERNATE_EXPECTED_HEIGHT } = alternateMinImageDimensions; /** * Mostly copied from customize-controls.js, with slight changes. @@ -111,8 +118,20 @@ export default ( InitialMediaUpload, minImageDimensions ) => { const realWidth = attachment.get( 'width' ), realHeight = attachment.get( 'height' ); - let xInit = parseInt( EXPECTED_WIDTH, 10 ), - yInit = parseInt( EXPECTED_HEIGHT, 10 ); + /* + * Only use the alternate dimensions if the image is big enough, and if they have the same aspect ratio type. + * For example, if they are portrait dimensions, the real image must also have portrait dimensions. + * This allows having an alternative crop size, for example, a portrait crop in addition to a landscape crop. + */ + const shouldUseAlternateWidthAndHeight = ( + ALTERNATE_EXPECTED_WIDTH && + realWidth >= ALTERNATE_EXPECTED_WIDTH && + realHeight >= ALTERNATE_EXPECTED_HEIGHT && + getAspectRatioType( realWidth, realHeight ) === getAspectRatioType( ALTERNATE_EXPECTED_WIDTH, ALTERNATE_EXPECTED_HEIGHT ) + ); + + let xInit = shouldUseAlternateWidthAndHeight ? parseInt( ALTERNATE_EXPECTED_WIDTH, 10 ) : parseInt( EXPECTED_WIDTH, 10 ), + yInit = shouldUseAlternateWidthAndHeight ? parseInt( ALTERNATE_EXPECTED_HEIGHT, 10 ) : parseInt( EXPECTED_HEIGHT, 10 ); const ratio = xInit / yInit, xImg = xInit, @@ -121,10 +140,10 @@ export default ( InitialMediaUpload, minImageDimensions ) => { // Allow cropping to be skipped because the image is at least the required dimensions, so skipping crop will auto crop. controller.set( 'canSkipCrop', true ); - if ( realWidth / realHeight > ratio ) { + if ( realWidth / realHeight > ratio ) { // This is wider than the expected ratio. yInit = realHeight; xInit = yInit * ratio; - } else { + } else { // This is either the expected ratio or taller. xInit = realWidth; yInit = xInit / ratio; } @@ -157,7 +176,10 @@ export default ( InitialMediaUpload, minImageDimensions ) => { */ onSelectImage() { const attachment = this.frame.state().get( 'selection' ).first().toJSON(); - if ( EXPECTED_WIDTH === attachment.width && EXPECTED_HEIGHT === attachment.height ) { + if ( + ( EXPECTED_WIDTH === attachment.width && EXPECTED_HEIGHT === attachment.height ) || + ( ALTERNATE_EXPECTED_WIDTH && ALTERNATE_EXPECTED_WIDTH === attachment.width && ALTERNATE_EXPECTED_HEIGHT === attachment.height ) + ) { this.setImageFromURL( attachment.url, attachment.id, attachment.width, attachment.height ); this.frame.close(); } else { diff --git a/assets/src/common/constants.js b/assets/src/common/constants.js index 9373c45aff0..bb3f3e7b8ce 100644 --- a/assets/src/common/constants.js +++ b/assets/src/common/constants.js @@ -1,3 +1,4 @@ // See https://github.com/ampproject/amphtml/blob/e7a1b3ff97645ec0ec482192205134bd0735943c/extensions/amp-fit-text/0.1/amp-fit-text.js#L81-L85 export const MIN_FONT_SIZE = 6; export const MAX_FONT_SIZE = 72; +export const MINIMUM_FEATURED_IMAGE_WIDTH = 1200; diff --git a/assets/src/common/helpers/index.js b/assets/src/common/helpers/index.js index 2f1acbca5d1..b13d4a578ad 100644 --- a/assets/src/common/helpers/index.js +++ b/assets/src/common/helpers/index.js @@ -4,6 +4,11 @@ import { __, sprintf } from '@wordpress/i18n'; import { getColorObjectByAttributeValues, getColorObjectByColorValue } from '@wordpress/block-editor'; +/** + * Internal dependencies + */ +import { MINIMUM_FEATURED_IMAGE_WIDTH } from '../constants'; + /** * Determines whether whether the image has the minimum required dimensions. * @@ -46,13 +51,26 @@ export const hasMinimumDimensions = ( media, dimensions ) => { * @return {Object} Minimum dimensions including width and height. */ export const getMinimumFeaturedImageDimensions = () => { - const width = 1200; + const width = MINIMUM_FEATURED_IMAGE_WIDTH; const height = width * ( 9 / 16 ); return { width, height }; }; +/** + * Get minimum dimensions for a portrait featured image, but not for an AMP Story. + * + * @return {Object} Minimum dimensions including width and height. + */ +export const getMinimumPortraitFeaturedImageDimensions = () => { + const width = MINIMUM_FEATURED_IMAGE_WIDTH; + + const height = Math.floor( width * ( 16 / 9 ) ); + + return { width, height }; +}; + /** * Validates the an image based on requirements. * @@ -160,3 +178,24 @@ export const getBackgroundColorWithOpacity = ( colors, backgroundColor, customBa return undefined; }; + +/** + * Gets The aspect ratio type, either 'landscape', 'portrait', or 'square'. + * + * @param {number} width The image width. + * @param {number} height The image height. + * @return {string|null} The aspect ratio type: 'landscape', 'portrait', or 'square'. + */ +export const getAspectRatioType = ( width, height ) => { + if ( ! width || ! height ) { + return null; + } + + if ( width > height ) { + return 'landscape'; + } else if ( height > width ) { + return 'portrait'; + } else if ( height === width ) { + return 'square'; + } +}; diff --git a/assets/src/common/helpers/test/getAspectRatioType.js b/assets/src/common/helpers/test/getAspectRatioType.js new file mode 100644 index 00000000000..b9c66c26377 --- /dev/null +++ b/assets/src/common/helpers/test/getAspectRatioType.js @@ -0,0 +1,19 @@ +/** + * Internal dependencies + */ +import { getAspectRatioType } from '../'; + +describe( 'getAspectRatioType', () => { + it( 'should return landscape when the aspect ratio is landscape', () => { + expect( getAspectRatioType( 1400, 1000 ) ).toEqual( 'landscape' ); + } ); + it( 'should return portrait when the aspect ratio is portrait', () => { + expect( getAspectRatioType( 1400, 1800 ) ).toEqual( 'portrait' ); + } ); + it( 'should return square when the aspect ratio is square', () => { + expect( getAspectRatioType( 1200, 1200 ) ).toEqual( 'square' ); + } ); + it( 'should return null when the arguments are null', () => { + expect( getAspectRatioType( null, null ) ).toEqual( null ); + } ); +} ); diff --git a/assets/src/common/helpers/test/getMinimumFeaturedImageDimensions.js b/assets/src/common/helpers/test/getMinimumFeaturedImageDimensions.js index 84d3b9501d7..dc08233987e 100644 --- a/assets/src/common/helpers/test/getMinimumFeaturedImageDimensions.js +++ b/assets/src/common/helpers/test/getMinimumFeaturedImageDimensions.js @@ -4,7 +4,7 @@ import { getMinimumFeaturedImageDimensions } from '../'; describe( 'getMinimumFeaturedImageDimensions', () => { - it( 'should return size with correct aspect ration', () => { + it( 'should return size with correct aspect ratio', () => { expect( getMinimumFeaturedImageDimensions() ).toEqual( { width: 1200, height: 675 } ); } ); } ); diff --git a/assets/src/common/helpers/test/getMinimumPortraitFeaturedImageDimensions.js b/assets/src/common/helpers/test/getMinimumPortraitFeaturedImageDimensions.js new file mode 100644 index 00000000000..6d2c5876a5f --- /dev/null +++ b/assets/src/common/helpers/test/getMinimumPortraitFeaturedImageDimensions.js @@ -0,0 +1,10 @@ +/** + * Internal dependencies + */ +import { getMinimumPortraitFeaturedImageDimensions } from '../'; + +describe( 'getMinimumPortraitFeaturedImageDimensions', () => { + it( 'should return size with correct portrait aspect ratio', () => { + expect( getMinimumPortraitFeaturedImageDimensions() ).toEqual( { width: 1200, height: 2133 } ); + } ); +} ); From c4b95ebe03997244d48f29d842ec2bbe09e2f662 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Tue, 2 Jul 2019 12:29:25 +0200 Subject: [PATCH 088/434] Fix and consolidate some of the i18n strings (#2695) --- assets/src/block-editor/blocks/amp-brid-player/edit.js | 6 +++--- assets/src/block-editor/blocks/amp-ima-video/edit.js | 6 +++--- assets/src/block-editor/blocks/amp-jwplayer/edit.js | 2 +- .../src/block-editor/blocks/amp-latest-stories/index.js | 6 +++--- assets/src/block-editor/blocks/amp-o2-player/edit.js | 2 +- assets/src/block-editor/blocks/amp-ooyala-player/edit.js | 2 +- assets/src/block-editor/blocks/amp-reach-player/edit.js | 4 ++-- .../block-editor/blocks/amp-springboard-player/edit.js | 4 ++-- assets/src/block-editor/blocks/amp-timeago/edit.js | 2 +- assets/src/block-editor/helpers/index.js | 2 +- .../higher-order/with-validation-error-notice.js | 2 +- assets/src/stories-editor/blocks/amp-story-cta/index.js | 5 ++++- assets/src/stories-editor/blocks/amp-story-page/edit.js | 8 ++++---- .../stories-editor/blocks/amp-story-post-date/index.js | 3 --- assets/src/stories-editor/blocks/amp-story-text/index.js | 2 +- .../components/higher-order/with-amp-story-settings.js | 2 +- assets/src/stories-editor/components/inserter/index.js | 4 ++-- assets/src/stories-editor/components/inserter/menu.js | 4 ++-- includes/admin/class-amp-admin-pointers.php | 2 +- includes/class-amp-story-post-type.php | 2 +- includes/sanitizers/class-amp-form-sanitizer.php | 2 +- .../validation/class-amp-validation-error-taxonomy.php | 2 +- 22 files changed, 37 insertions(+), 37 deletions(-) diff --git a/assets/src/block-editor/blocks/amp-brid-player/edit.js b/assets/src/block-editor/blocks/amp-brid-player/edit.js index baa879dceea..00f8cfaabd5 100644 --- a/assets/src/block-editor/blocks/amp-brid-player/edit.js +++ b/assets/src/block-editor/blocks/amp-brid-player/edit.js @@ -20,7 +20,7 @@ const BlockEdit = ( props ) => { const { autoPlay, dataPartner, dataPlayer, dataVideo, dataPlaylist, dataOutstream } = attributes; const ampLayoutOptions = [ { value: 'responsive', label: __( 'Responsive', 'amp' ) }, - { value: 'fixed-height', label: __( 'Fixed height', 'amp' ) }, + { value: 'fixed-height', label: __( 'Fixed Height', 'amp' ) }, { value: 'fixed', label: __( 'Fixed', 'amp' ) }, { value: 'fill', label: __( 'Fill', 'amp' ) }, { value: 'flex-item', label: __( 'Flex-item', 'amp' ) }, @@ -36,12 +36,12 @@ const BlockEdit = ( props ) => { <InspectorControls> <PanelBody title={ __( 'Brid Player Settings', 'amp' ) }> <TextControl - label={ __( 'Brid.tv partner ID (required)', 'amp' ) } + label={ __( 'Partner ID (required)', 'amp' ) } value={ dataPartner } onChange={ ( value ) => ( setAttributes( { dataPartner: value } ) ) } /> <TextControl - label={ __( 'Brid.tv player ID (required)', 'amp' ) } + label={ __( 'Player ID (required)', 'amp' ) } value={ dataPlayer } onChange={ ( value ) => ( setAttributes( { dataPlayer: value } ) ) } /> diff --git a/assets/src/block-editor/blocks/amp-ima-video/edit.js b/assets/src/block-editor/blocks/amp-ima-video/edit.js index 084c99d7a9e..cac3211d58d 100644 --- a/assets/src/block-editor/blocks/amp-ima-video/edit.js +++ b/assets/src/block-editor/blocks/amp-ima-video/edit.js @@ -32,17 +32,17 @@ const BlockEdit = ( props ) => { <InspectorControls> <PanelBody title={ __( 'IMA Video Settings', 'amp' ) }> <TextControl - label={ __( 'Https URL for your VAST ad document (required)', 'amp' ) } + label={ __( 'HTTPS URL for your VAST ad document (required)', 'amp' ) } value={ dataTag } onChange={ ( value ) => ( setAttributes( { dataTag: value } ) ) } /> <TextControl - label={ __( 'Https URL of your video content (required)', 'amp' ) } + label={ __( 'HTTPS URL of your video content (required)', 'amp' ) } value={ dataSrc } onChange={ ( value ) => ( setAttributes( { dataSrc: value } ) ) } /> <TextControl - label={ __( 'Https URL to preview image', 'amp' ) } + label={ __( 'HTTPS URL to preview image', 'amp' ) } value={ dataPoster } onChange={ ( value ) => ( setAttributes( { dataPoster: value } ) ) } /> diff --git a/assets/src/block-editor/blocks/amp-jwplayer/edit.js b/assets/src/block-editor/blocks/amp-jwplayer/edit.js index 2ba6216c0f3..4ea46e0b4fa 100644 --- a/assets/src/block-editor/blocks/amp-jwplayer/edit.js +++ b/assets/src/block-editor/blocks/amp-jwplayer/edit.js @@ -20,7 +20,7 @@ const BlockEdit = ( props ) => { const { dataPlayerId, dataMediaId, dataPlaylistId } = attributes; const ampLayoutOptions = [ { value: 'responsive', label: __( 'Responsive', 'amp' ) }, - { value: 'fixed-height', label: __( 'Fixed height', 'amp' ) }, + { value: 'fixed-height', label: __( 'Fixed Height', 'amp' ) }, { value: 'fixed', label: __( 'Fixed', 'amp' ) }, { value: 'fill', label: __( 'Fill', 'amp' ) }, { value: 'flex-item', label: __( 'Flex-item', 'amp' ) }, diff --git a/assets/src/block-editor/blocks/amp-latest-stories/index.js b/assets/src/block-editor/blocks/amp-latest-stories/index.js index e7af99b221d..48f87e29ebd 100644 --- a/assets/src/block-editor/blocks/amp-latest-stories/index.js +++ b/assets/src/block-editor/blocks/amp-latest-stories/index.js @@ -12,12 +12,12 @@ export const name = 'amp/amp-latest-stories'; export const settings = { title: __( 'Latest Stories', 'amp' ), - description: __( 'See the latest AMP stories', 'amp' ), + description: __( 'Display your most recent stories.', 'amp' ), icon: 'list-view', category: 'widgets', keywords: [ - __( 'Recent stories', 'amp' ), - __( 'AMP stories', 'amp' ), + __( 'recent stories', 'amp' ), + __( 'AMP Stories', 'amp' ), ], supports: { diff --git a/assets/src/block-editor/blocks/amp-o2-player/edit.js b/assets/src/block-editor/blocks/amp-o2-player/edit.js index 0a395b943d3..9cd723f45b7 100644 --- a/assets/src/block-editor/blocks/amp-o2-player/edit.js +++ b/assets/src/block-editor/blocks/amp-o2-player/edit.js @@ -25,7 +25,7 @@ const BlockEdit = ( props ) => { const { autoPlay, dataPid, dataVid, dataBcid, dataBid } = attributes; const ampLayoutOptions = [ { value: 'responsive', label: __( 'Responsive', 'amp' ) }, - { value: 'fixed-height', label: __( 'Fixed height', 'amp' ) }, + { value: 'fixed-height', label: __( 'Fixed Height', 'amp' ) }, { value: 'fixed', label: __( 'Fixed', 'amp' ) }, { value: 'fill', label: __( 'Fill', 'amp' ) }, { value: 'flex-item', label: __( 'Flex-item', 'amp' ) }, diff --git a/assets/src/block-editor/blocks/amp-ooyala-player/edit.js b/assets/src/block-editor/blocks/amp-ooyala-player/edit.js index 19013f78c5c..49b2a9fe7b8 100644 --- a/assets/src/block-editor/blocks/amp-ooyala-player/edit.js +++ b/assets/src/block-editor/blocks/amp-ooyala-player/edit.js @@ -37,7 +37,7 @@ const BlockEdit = ( props ) => { return ( <> <InspectorControls> - <PanelBody title={ __( 'Ooyala settings', 'amp' ) }> + <PanelBody title={ __( 'Ooyala Settings', 'amp' ) }> <TextControl label={ __( 'Video embed code (required)', 'amp' ) } value={ dataEmbedCode } diff --git a/assets/src/block-editor/blocks/amp-reach-player/edit.js b/assets/src/block-editor/blocks/amp-reach-player/edit.js index c7a03ecd0e1..48c02f2a488 100644 --- a/assets/src/block-editor/blocks/amp-reach-player/edit.js +++ b/assets/src/block-editor/blocks/amp-reach-player/edit.js @@ -33,9 +33,9 @@ const BlockEdit = ( props ) => { return ( <> <InspectorControls> - <PanelBody title={ __( 'Reach settings', 'amp' ) }> + <PanelBody title={ __( 'Reach Settings', 'amp' ) }> <TextControl - label={ __( 'The Reach player embed id (required)', 'amp' ) } + label={ __( 'Embed ID (required)', 'amp' ) } value={ dataEmbedId } onChange={ ( value ) => ( setAttributes( { dataEmbedId: value } ) ) } /> diff --git a/assets/src/block-editor/blocks/amp-springboard-player/edit.js b/assets/src/block-editor/blocks/amp-springboard-player/edit.js index e25ef9e0e36..9f39ee4af18 100644 --- a/assets/src/block-editor/blocks/amp-springboard-player/edit.js +++ b/assets/src/block-editor/blocks/amp-springboard-player/edit.js @@ -39,12 +39,12 @@ const BlockEdit = ( props ) => { <InspectorControls> <PanelBody title={ __( 'Springboard Player Settings', 'amp' ) }> <TextControl - label={ __( 'SprintBoard site ID (required)', 'amp' ) } + label={ __( 'Site ID (required)', 'amp' ) } value={ dataSiteId } onChange={ ( value ) => ( setAttributes( { dataSiteId: value } ) ) } /> <TextControl - label={ __( 'Player content ID (required)', 'amp' ) } + label={ __( 'Content ID (required)', 'amp' ) } value={ dataContentId } onChange={ ( value ) => ( setAttributes( { dataContentId: value } ) ) } /> diff --git a/assets/src/block-editor/blocks/amp-timeago/edit.js b/assets/src/block-editor/blocks/amp-timeago/edit.js index c0ff9fa5582..bf44ef264f2 100644 --- a/assets/src/block-editor/blocks/amp-timeago/edit.js +++ b/assets/src/block-editor/blocks/amp-timeago/edit.js @@ -39,7 +39,7 @@ const BlockEdit = ( props ) => { const ampLayoutOptions = [ { value: '', label: __( 'Responsive', 'amp' ) }, { value: 'fixed', label: __( 'Fixed', 'amp' ) }, - { value: 'fixed-height', label: __( 'Fixed height', 'amp' ) }, + { value: 'fixed-height', label: __( 'Fixed Height', 'amp' ) }, ]; return ( diff --git a/assets/src/block-editor/helpers/index.js b/assets/src/block-editor/helpers/index.js index 777cd70d16b..142a9481771 100644 --- a/assets/src/block-editor/helpers/index.js +++ b/assets/src/block-editor/helpers/index.js @@ -48,7 +48,7 @@ const ampLayoutOptions = [ }, { value: 'fixed-height', - label: __( 'Fixed height', 'amp' ), + label: __( 'Fixed Height', 'amp' ), notAvailable: [], }, { diff --git a/assets/src/block-validation/components/higher-order/with-validation-error-notice.js b/assets/src/block-validation/components/higher-order/with-validation-error-notice.js index 6f96af80f0a..7be42f50691 100644 --- a/assets/src/block-validation/components/higher-order/with-validation-error-notice.js +++ b/assets/src/block-validation/components/higher-order/with-validation-error-notice.js @@ -38,7 +38,7 @@ export default createHigherOrderComponent( const actions = [ { - label: __( 'Remove Block', 'amp' ), + label: __( 'Remove Element', 'amp' ), onClick: () => onReplace( [] ), }, ]; diff --git a/assets/src/stories-editor/blocks/amp-story-cta/index.js b/assets/src/stories-editor/blocks/amp-story-cta/index.js index 0d2cae0ae78..ab75ecb0ead 100644 --- a/assets/src/stories-editor/blocks/amp-story-cta/index.js +++ b/assets/src/stories-editor/blocks/amp-story-cta/index.js @@ -49,7 +49,10 @@ export const settings = { category: 'layout', - keywords: [ __( 'call to action', 'amp' ), __( 'cta', 'amp' ), __( 'button', 'amp' ) ], + keywords: [ + __( 'cta', 'amp' ), + __( 'button', 'amp' ), + ], attributes: schema, diff --git a/assets/src/stories-editor/blocks/amp-story-page/edit.js b/assets/src/stories-editor/blocks/amp-story-page/edit.js index 84c07f6479b..c20170d8765 100644 --- a/assets/src/stories-editor/blocks/amp-story-page/edit.js +++ b/assets/src/stories-editor/blocks/amp-story-page/edit.js @@ -8,7 +8,7 @@ import { has } from 'lodash'; /** * WordPress dependencies */ -import { __, sprintf } from '@wordpress/i18n'; +import { __, _x, sprintf } from '@wordpress/i18n'; import { InnerBlocks, PanelColorSettings, @@ -338,7 +338,7 @@ class PageEdit extends Component { { !! mediaId && <MediaUploadCheck> <Button onClick={ () => setAttributes( { mediaUrl: undefined, mediaId: undefined, mediaType: undefined } ) } isLink isDestructive> - { VIDEO_BACKGROUND_TYPE === mediaType ? __( 'Remove Video', 'amp' ) : __( 'Remove image', 'amp' ) } + { _x( 'Remove', 'background media', 'amp' ) } </Button> </MediaUploadCheck> } @@ -399,7 +399,7 @@ class PageEdit extends Component { { poster && ( <Button onClick={ () => setAttributes( { poster: undefined } ) } isLink isDestructive> - { __( 'Remove Poster Image', 'amp' ) } + { __( 'Remove Image', 'amp' ) } </Button> ) } @@ -439,7 +439,7 @@ class PageEdit extends Component { onChange={ ( value ) => setAttributes( { autoAdvanceAfterDuration: value } ) } min={ Math.max( totalAnimationDuration, 1 ) } initialPosition={ totalAnimationDuration } - help={ totalAnimationDuration > 1 ? __( 'A minimum time is enforced because there are animated blocks on this page', 'amp' ) : undefined } + help={ totalAnimationDuration > 1 ? __( 'A minimum time is enforced because there are animated blocks on this page.', 'amp' ) : undefined } /> ) } </PanelBody> diff --git a/assets/src/stories-editor/blocks/amp-story-post-date/index.js b/assets/src/stories-editor/blocks/amp-story-post-date/index.js index f819dcf42a7..cdb46f8fff4 100644 --- a/assets/src/stories-editor/blocks/amp-story-post-date/index.js +++ b/assets/src/stories-editor/blocks/amp-story-post-date/index.js @@ -17,10 +17,7 @@ export const settings = { category: 'common', icon: 'clock', keywords: [ - __( 'post', 'amp' ), __( 'publish date', 'amp' ), - __( 'published date', 'amp' ), - __( 'date', 'amp' ), ], ...getMetaBlockSettings( { tagName: 'div', diff --git a/assets/src/stories-editor/blocks/amp-story-text/index.js b/assets/src/stories-editor/blocks/amp-story-text/index.js index cba6359031a..ed82fff3759 100644 --- a/assets/src/stories-editor/blocks/amp-story-text/index.js +++ b/assets/src/stories-editor/blocks/amp-story-text/index.js @@ -44,7 +44,7 @@ const schema = { export const settings = { title: __( 'Text', 'amp' ), - description: __( 'Add free-form text to your story', 'amp' ), + description: __( 'Add free-form text to your story.', 'amp' ), icon: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M11 5v7H9.5C7.6 12 6 10.4 6 8.5S7.6 5 9.5 5H11m8-2H9.5C6.5 3 4 5.5 4 8.5S6.5 14 9.5 14H11v7h2V5h2v16h2V5h2V3z" /></svg>, diff --git a/assets/src/stories-editor/components/higher-order/with-amp-story-settings.js b/assets/src/stories-editor/components/higher-order/with-amp-story-settings.js index 8564c74bf4d..8331a48092f 100644 --- a/assets/src/stories-editor/components/higher-order/with-amp-story-settings.js +++ b/assets/src/stories-editor/components/higher-order/with-amp-story-settings.js @@ -513,7 +513,7 @@ export default createHigherOrderComponent( } } /> <RangeControl - label={ __( 'Background Opacity', 'amp' ) } + label={ __( 'Opacity', 'amp' ) } value={ opacity } onChange={ ( value ) => setAttributes( { opacity: value } ) } min={ 5 } diff --git a/assets/src/stories-editor/components/inserter/index.js b/assets/src/stories-editor/components/inserter/index.js index cc3fb1529c6..9a6fa410e8f 100644 --- a/assets/src/stories-editor/components/inserter/index.js +++ b/assets/src/stories-editor/components/inserter/index.js @@ -29,7 +29,7 @@ import InserterMenu from './menu'; const defaultRenderToggle = ( { onToggle, disabled, isOpen } ) => ( <IconButton icon="insert" - label={ __( 'Add block', 'amp' ) } + label={ __( 'Add element', 'amp' ) } labelPosition="bottom" onClick={ onToggle } className="editor-inserter__toggle block-editor-inserter__toggle" @@ -112,7 +112,7 @@ class Inserter extends Component { position={ position } onToggle={ this.onToggle } expandOnMobile - headerTitle={ __( 'Add a block', 'amp' ) } + headerTitle={ __( 'Add element', 'amp' ) } renderToggle={ this.renderToggle } renderContent={ this.renderContent } /> diff --git a/assets/src/stories-editor/components/inserter/menu.js b/assets/src/stories-editor/components/inserter/menu.js index 8a561a19182..2faba81cc9c 100644 --- a/assets/src/stories-editor/components/inserter/menu.js +++ b/assets/src/stories-editor/components/inserter/menu.js @@ -280,12 +280,12 @@ export class InserterMenu extends Component { onKeyDown={ this.onKeyDown } > <label htmlFor={ `block-editor-inserter__search-${ instanceId }` } className="screen-reader-text"> - { __( 'Search for a block', 'amp' ) } + { __( 'Search for an element', 'amp' ) } </label> <input id={ `block-editor-inserter__search-${ instanceId }` } type="search" - placeholder={ __( 'Search for a block', 'amp' ) } + placeholder={ __( 'Search for an element', 'amp' ) } className="editor-inserter__search block-editor-inserter__search" autoFocus onChange={ this.onChangeSearchInput } diff --git a/includes/admin/class-amp-admin-pointers.php b/includes/admin/class-amp-admin-pointers.php index 77f2b4b1918..d04e0bf9bf4 100644 --- a/includes/admin/class-amp-admin-pointers.php +++ b/includes/admin/class-amp-admin-pointers.php @@ -96,7 +96,7 @@ private function get_pointers() { array( 'selector' => '#menu-posts-' . AMP_Story_Post_Type::POST_TYPE_SLUG, 'heading' => __( 'AMP', 'amp' ), - 'description' => __( 'Head over here to create your first AMP story.', 'amp' ), + 'description' => __( 'Head over here to create your first story.', 'amp' ), 'position' => array( 'align' => 'middle', ), diff --git a/includes/class-amp-story-post-type.php b/includes/class-amp-story-post-type.php index 3cad43787ad..6d274b3984f 100644 --- a/includes/class-amp-story-post-type.php +++ b/includes/class-amp-story-post-type.php @@ -159,7 +159,7 @@ public static function register() { 'items_list_navigation' => __( 'Stories list navigation', 'amp' ), 'items_list' => __( 'Stories list', 'amp' ), 'item_published' => __( 'Story published.', 'amp' ), - 'item_published_privately' => __( 'SStory published privately.', 'amp' ), + 'item_published_privately' => __( 'Story published privately.', 'amp' ), 'item_reverted_to_draft' => __( 'Story reverted to draft.', 'amp' ), 'item_scheduled' => __( 'Story scheduled', 'amp' ), 'item_updated' => __( 'Story updated.', 'amp' ), diff --git a/includes/sanitizers/class-amp-form-sanitizer.php b/includes/sanitizers/class-amp-form-sanitizer.php index 35968819671..44ca4b947ab 100644 --- a/includes/sanitizers/class-amp-form-sanitizer.php +++ b/includes/sanitizers/class-amp-form-sanitizer.php @@ -186,7 +186,7 @@ public function ensure_response_message_elements( $form ) { $link = $this->dom->createElement( 'a' ); $link->setAttribute( 'href', 'https://amp-wp.org/?p=5463' ); $link->setAttribute( 'target', '_blank' ); - $link->appendChild( $this->dom->createTextNode( __( 'Learn more', 'amp' ) ) ); + $link->appendChild( $this->dom->createTextNode( __( 'Learn More', 'amp' ) ) ); $small->appendChild( $link ); $p->appendChild( $small ); diff --git a/includes/validation/class-amp-validation-error-taxonomy.php b/includes/validation/class-amp-validation-error-taxonomy.php index a705c5321bc..8c0fb4c873b 100644 --- a/includes/validation/class-amp-validation-error-taxonomy.php +++ b/includes/validation/class-amp-validation-error-taxonomy.php @@ -1882,7 +1882,7 @@ public static function filter_manage_custom_columns( $content, $column_name, $te __( 'F j, Y g:i a', 'amp' ) ) ), - /* translators: %s: human readable timestamp */ + /* translators: %s: the human-readable time difference. */ esc_html( sprintf( __( '%s ago', 'amp' ), human_time_diff( $created_datetime->getTimestamp() ) ) ) ); } From bdab263673af9b73b9727cd4f75bf2d7f4e91b8c Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Tue, 2 Jul 2019 14:37:16 +0200 Subject: [PATCH 089/434] Begin with some E2E Tests (#2708) --- .eslintrc | 16 +- .travis.yml | 16 +- bin/bootstrap-env.sh | 12 - bin/local-env/docker-compose.yml | 43 ++ bin/{ => local-env}/includes.sh | 0 bin/local-env/install-composer.sh | 41 ++ bin/{ => local-env}/install-node-nvm.sh | 10 +- bin/{ => local-env}/install-wordpress.sh | 58 +-- .../launch-containers.sh} | 18 +- bin/local-env/start.sh | 65 ++++ bin/local-env/stop.sh | 26 ++ bin/reset-e2e-tests.sh | 7 - bin/setup-local-env.sh | 39 -- contributing.md | 211 ++++++++-- docker-compose.yml | 95 ----- includes/class-amp-autoloader.php | 4 +- jest-puppeteer.config.js | 7 + package.json | 12 +- tests/e2e/config/bootstrap.js | 142 +++++++ tests/e2e/jest.config.js | 22 +- tests/e2e/specs/amp-options.test.js | 134 +++++++ tests/e2e/specs/demo.test.js | 45 --- tests/e2e/specs/hello.test.js | 14 + tests/e2e/specs/stories-admin-pointer.test.js | 14 + tests/{unit => js}/jest.config.js | 2 +- tests/{unit => js}/setup-globals.js | 0 tests/{ => php}/assets/1024x768.png | Bin tests/{ => php}/assets/350x150.png | Bin tests/{ => php}/assets/wordpress-logo.png | Bin tests/{ => php}/benchmark/run-benchmark.sh | 0 tests/{ => php}/stubs.php | 0 .../{ => php}/test-amp-analytics-options.php | 0 tests/{ => php}/test-amp-audio-converter.php | 0 .../test-amp-crowdsignal-embed-handler.php | 0 .../{ => php}/test-amp-dailymotion-embed.php | 0 tests/{ => php}/test-amp-facebook-embed.php | 0 tests/{ => php}/test-amp-form-sanitizer.php | 0 tests/{ => php}/test-amp-helper-functions.php | 0 tests/{ => php}/test-amp-iframe-sanitizer.php | 0 .../test-amp-image-dimension-extractor.php | 0 tests/{ => php}/test-amp-img-sanitizer.php | 0 tests/{ => php}/test-amp-instagram-embed.php | 0 .../test-amp-o2-player-sanitizer.php | 0 tests/{ => php}/test-amp-pinterest-embed.php | 0 .../{ => php}/test-amp-playbuzz-sanitizer.php | 0 tests/{ => php}/test-amp-render-post.php | 0 tests/{ => php}/test-amp-script-sanitizer.php | 0 tests/{ => php}/test-amp-soundcloud-embed.php | 0 tests/{ => php}/test-amp-story-sanitizer.php | 0 tests/{ => php}/test-amp-style-sanitizer.php | 0 ...nd-attribute-sanitizer-private-methods.php | 0 tests/{ => php}/test-amp-twitter-embed.php | 0 tests/{ => php}/test-amp-video-sanitizer.php | 0 tests/{ => php}/test-amp-vimeo-embed.php | 0 tests/{ => php}/test-amp-vine-embed.php | 0 tests/{ => php}/test-amp-youtube-embed.php | 0 tests/{ => php}/test-amp.php | 0 .../test-class-amp-admin-pointer.php | 0 .../test-class-amp-base-sanitizer.php | 0 .../test-class-amp-block-sanitizer.php | 0 tests/{ => php}/test-class-amp-cli.php | 0 .../test-class-amp-comments-sanitizer.php | 0 .../test-class-amp-content-sanitizer.php | 0 .../test-class-amp-core-block-handler.php | 0 tests/{ => php}/test-class-amp-dom-utils.php | 0 .../test-class-amp-editor-blocks.php | 0 ...test-class-amp-gallery-block-sanitizer.php | 0 .../test-class-amp-gfycat-embed-handler.php | 0 tests/{ => php}/test-class-amp-http.php | 0 .../test-class-amp-hulu-embed-handler.php | 0 .../test-class-amp-imgur-embed-handler.php | 0 tests/{ => php}/test-class-amp-meta-box.php | 0 ...st-class-amp-nav-menu-toggle-sanitizer.php | 0 .../test-class-amp-options-manager.php | 0 .../{ => php}/test-class-amp-options-menu.php | 0 .../test-class-amp-playlist-embed-handler.php | 0 .../test-class-amp-post-type-support.php | 0 .../test-class-amp-service-worker.php | 0 .../test-class-amp-story-post-type.php | 0 .../test-class-amp-story-templates.php | 0 .../test-class-amp-theme-support.php | 0 .../test-class-amp-vimeo-embed-handler.php | 0 .../test-class-amp-widget-archives.php | 0 .../test-class-amp-widget-categories.php | 0 .../{ => php}/test-class-amp-widget-text.php | 0 .../test-class-amp-youtube-embed-handler.php | 0 .../test-tag-and-attribute-sanitizer.php | 368 +++++++++--------- ...test-class-amp-validated-url-post-type.php | 0 ...st-class-amp-validation-error-taxonomy.php | 0 .../test-class-amp-validation-manager.php | 0 90 files changed, 932 insertions(+), 489 deletions(-) delete mode 100755 bin/bootstrap-env.sh create mode 100644 bin/local-env/docker-compose.yml rename bin/{ => local-env}/includes.sh (100%) create mode 100755 bin/local-env/install-composer.sh rename bin/{ => local-env}/install-node-nvm.sh (90%) rename bin/{ => local-env}/install-wordpress.sh (71%) rename bin/{install-docker.sh => local-env/launch-containers.sh} (55%) create mode 100755 bin/local-env/start.sh create mode 100755 bin/local-env/stop.sh delete mode 100755 bin/reset-e2e-tests.sh delete mode 100755 bin/setup-local-env.sh delete mode 100644 docker-compose.yml create mode 100644 jest-puppeteer.config.js create mode 100644 tests/e2e/config/bootstrap.js create mode 100644 tests/e2e/specs/amp-options.test.js delete mode 100644 tests/e2e/specs/demo.test.js create mode 100644 tests/e2e/specs/hello.test.js create mode 100644 tests/e2e/specs/stories-admin-pointer.test.js rename tests/{unit => js}/jest.config.js (92%) rename tests/{unit => js}/setup-globals.js (100%) rename tests/{ => php}/assets/1024x768.png (100%) rename tests/{ => php}/assets/350x150.png (100%) rename tests/{ => php}/assets/wordpress-logo.png (100%) rename tests/{ => php}/benchmark/run-benchmark.sh (100%) rename tests/{ => php}/stubs.php (100%) rename tests/{ => php}/test-amp-analytics-options.php (100%) rename tests/{ => php}/test-amp-audio-converter.php (100%) rename tests/{ => php}/test-amp-crowdsignal-embed-handler.php (100%) rename tests/{ => php}/test-amp-dailymotion-embed.php (100%) rename tests/{ => php}/test-amp-facebook-embed.php (100%) rename tests/{ => php}/test-amp-form-sanitizer.php (100%) rename tests/{ => php}/test-amp-helper-functions.php (100%) rename tests/{ => php}/test-amp-iframe-sanitizer.php (100%) rename tests/{ => php}/test-amp-image-dimension-extractor.php (100%) rename tests/{ => php}/test-amp-img-sanitizer.php (100%) rename tests/{ => php}/test-amp-instagram-embed.php (100%) rename tests/{ => php}/test-amp-o2-player-sanitizer.php (100%) rename tests/{ => php}/test-amp-pinterest-embed.php (100%) rename tests/{ => php}/test-amp-playbuzz-sanitizer.php (100%) rename tests/{ => php}/test-amp-render-post.php (100%) rename tests/{ => php}/test-amp-script-sanitizer.php (100%) rename tests/{ => php}/test-amp-soundcloud-embed.php (100%) rename tests/{ => php}/test-amp-story-sanitizer.php (100%) rename tests/{ => php}/test-amp-style-sanitizer.php (100%) rename tests/{ => php}/test-amp-tag-and-attribute-sanitizer-private-methods.php (100%) rename tests/{ => php}/test-amp-twitter-embed.php (100%) rename tests/{ => php}/test-amp-video-sanitizer.php (100%) rename tests/{ => php}/test-amp-vimeo-embed.php (100%) rename tests/{ => php}/test-amp-vine-embed.php (100%) rename tests/{ => php}/test-amp-youtube-embed.php (100%) rename tests/{ => php}/test-amp.php (100%) rename tests/{ => php}/test-class-amp-admin-pointer.php (100%) rename tests/{ => php}/test-class-amp-base-sanitizer.php (100%) rename tests/{ => php}/test-class-amp-block-sanitizer.php (100%) rename tests/{ => php}/test-class-amp-cli.php (100%) rename tests/{ => php}/test-class-amp-comments-sanitizer.php (100%) rename tests/{ => php}/test-class-amp-content-sanitizer.php (100%) rename tests/{ => php}/test-class-amp-core-block-handler.php (100%) rename tests/{ => php}/test-class-amp-dom-utils.php (100%) rename tests/{ => php}/test-class-amp-editor-blocks.php (100%) rename tests/{ => php}/test-class-amp-gallery-block-sanitizer.php (100%) rename tests/{ => php}/test-class-amp-gfycat-embed-handler.php (100%) rename tests/{ => php}/test-class-amp-http.php (100%) rename tests/{ => php}/test-class-amp-hulu-embed-handler.php (100%) rename tests/{ => php}/test-class-amp-imgur-embed-handler.php (100%) rename tests/{ => php}/test-class-amp-meta-box.php (100%) rename tests/{ => php}/test-class-amp-nav-menu-toggle-sanitizer.php (100%) rename tests/{ => php}/test-class-amp-options-manager.php (100%) rename tests/{ => php}/test-class-amp-options-menu.php (100%) rename tests/{ => php}/test-class-amp-playlist-embed-handler.php (100%) rename tests/{ => php}/test-class-amp-post-type-support.php (100%) rename tests/{ => php}/test-class-amp-service-worker.php (100%) rename tests/{ => php}/test-class-amp-story-post-type.php (100%) rename tests/{ => php}/test-class-amp-story-templates.php (100%) rename tests/{ => php}/test-class-amp-theme-support.php (100%) rename tests/{ => php}/test-class-amp-vimeo-embed-handler.php (100%) rename tests/{ => php}/test-class-amp-widget-archives.php (100%) rename tests/{ => php}/test-class-amp-widget-categories.php (100%) rename tests/{ => php}/test-class-amp-widget-text.php (100%) rename tests/{ => php}/test-class-amp-youtube-embed-handler.php (100%) rename tests/{ => php}/test-tag-and-attribute-sanitizer.php (87%) rename tests/{ => php}/validation/test-class-amp-validated-url-post-type.php (100%) rename tests/{ => php}/validation/test-class-amp-validation-error-taxonomy.php (100%) rename tests/{ => php}/validation/test-class-amp-validation-manager.php (100%) diff --git a/.eslintrc b/.eslintrc index fb606190908..d469eeec916 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,11 +9,23 @@ }, "globals": { "browser": true, - "page": true, "wp": true, "Set": true }, "rules": { "react/prop-types": 2 - } + }, + "overrides": [ + { + "files": [ "tests/e2e/**/*.js" ], + "env": { + "browser": true + }, + "globals": { + "browser": true, + "page": true, + "wp": true + } + } + ] } diff --git a/.travis.yml b/.travis.yml index 7962e2b6606..f4f18d536cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ notifications: cache: directories: - $HOME/.composer/cache + - $HOME/.jest-cache - $HOME/.npm - $HOME/.nvm/.cache - $HOME/phpunit-bin @@ -76,7 +77,20 @@ jobs: env: WP_VERSION=latest DEV_LIB_SKIP=phpcs,eslint,xmllint,phpsyntax,phpunit script: - source "$DEV_LIB_PATH/travis.script.sh" - - npm run test:js -- --ci + - npm run test:js -- --ci --cacheDirectory="$HOME/.jest-cache" + + - name: E2E tests + php: "7.3" + env: WP_VERSION=latest DEV_LIB_SKIP=phpcs,eslint,xmllint,phpsyntax,phpunit PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= + install: + - nvm install + - composer install + # npm is handled by `npm run env:start` + script: + - npm run env:start + - npm run build:js # after npm dependencies have been installed + - npm run env:reset-site + - npm run test:e2e - name: PHP unit tests w/ external-http (7.3, WordPress latest) php: "7.3" diff --git a/bin/bootstrap-env.sh b/bin/bootstrap-env.sh deleted file mode 100755 index 3055a49b513..00000000000 --- a/bin/bootstrap-env.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -WP_VERSION=${WP_VERSION-latest} -WP_DEBUG=${WP_DEBUG-true} -SCRIPT_DEBUG=${SCRIPT_DEBUG-true} -DOCKER=${DOCKER-false} -DOCKER_ENV=${DOCKER_ENV-ci} -DOCKER_COMPOSE_FILE_OPTIONS="-f docker-compose.yml" - -if [ "$DOCKER_ENV" == "localwpdev" ]; then - DOCKER_COMPOSE_FILE_OPTIONS="${DOCKER_COMPOSE_FILE_OPTIONS} -f docker-compose-localdev.yml" -fi diff --git a/bin/local-env/docker-compose.yml b/bin/local-env/docker-compose.yml new file mode 100644 index 00000000000..929b5ae2eb4 --- /dev/null +++ b/bin/local-env/docker-compose.yml @@ -0,0 +1,43 @@ +version: '3.1' + +services: + wordpress: + image: wordpress + restart: always + ports: + - 8890:80 + environment: + WORDPRESS_DB_HOST: mysql + WORDPRESS_DB_PASSWORD: example + ABSPATH: /usr/src/wordpress/ + WORDPRESS_DEBUG: 1 + WORDPRESS_CONFIG_EXTRA: | + define( 'SCRIPT_DEBUG', true ); + volumes: + - wordpress_data:/var/www/html + - ../../:/var/www/html/wp-content/plugins/amp + - ../../node_modules/@wordpress/e2e-tests/plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins + - ../../node_modules/@wordpress/e2e-tests/mu-plugins:/var/www/html/wp-content/mu-plugins + depends_on: + - mysql + + cli: + image: wordpress:cli + restart: always + user: xfs + volumes: + - wordpress_data:/var/www/html + - ../../:/var/www/html/wp-content/plugins/amp + depends_on: + - mysql + - wordpress + + mysql: + image: mysql:5.7 + restart: always + environment: + MYSQL_ROOT_PASSWORD: example + MYSQL_DATABASE: wordpress_test + +volumes: + wordpress_data: diff --git a/bin/includes.sh b/bin/local-env/includes.sh similarity index 100% rename from bin/includes.sh rename to bin/local-env/includes.sh diff --git a/bin/local-env/install-composer.sh b/bin/local-env/install-composer.sh new file mode 100755 index 00000000000..f55530115a9 --- /dev/null +++ b/bin/local-env/install-composer.sh @@ -0,0 +1,41 @@ +#!/bin/bash +COMPOSER_VERSION=`curl -Ls -w %{url_effective} -o /dev/null https://github.com/composer/composer/releases/latest | rev | cut -d '/' -f 1 | rev` + +# Exit if any command fails +set -e + +# Include useful functions +. "$(dirname "$0")/includes.sh" + + +# Change to the expected directory +cd "$(dirname "$0")/../.." + +# Check if composer is installed +if [ "$TRAVIS" != "true" ] && ! command_exists "composer"; then + if ask "$(error_message "Composer isn't installed, would you like to download and install it automatically?")" Y; then + echo -en $(status_message "Installing Composer..." ) + download "https://getcomposer.org/installer" | bash >/dev/null 2>&1 + mkdir -p /usr/local/bin + mv composer.phar /usr/local/bin/composer + echo ' done!' + else + echo -e $(error_message "") + echo -e $(error_message "Please install Composer manually, then re-run the setup script to continue.") + echo -e $(error_message "Composer installation instructions can be found here: $(action_format "https://getcomposer.org/doc/00-intro.md")") + fi + + exit 1 +fi + +# Check if the current Composer version is up to date. +if [ "$TRAVIS" != "true" ] && ! [[ "$(composer --version)" == "Composer version $COMPOSER_VERSION "* ]]; then + echo -en $(status_message "Updating Composer..." ) + composer self-update + echo ' done!' +fi + + +# Install/update packages +echo -e $(status_message "Installing and updating Composer packages..." ) +composer install diff --git a/bin/install-node-nvm.sh b/bin/local-env/install-node-nvm.sh similarity index 90% rename from bin/install-node-nvm.sh rename to bin/local-env/install-node-nvm.sh index 9edc083833d..f4c29240ce5 100755 --- a/bin/install-node-nvm.sh +++ b/bin/local-env/install-node-nvm.sh @@ -1,5 +1,5 @@ #!/bin/bash -NVM_VERSION=`curl -Ls -w %{url_effective} -o /dev/null https://github.com/creationix/nvm/releases/latest | rev | cut -d '/' -f 1 | rev` +NVM_VERSION=`curl -Ls -w %{url_effective} -o /dev/null https://github.com/nvm-sh/nvm/releases/latest | rev | cut -d '/' -f 1 | rev` # Exit if any command fails set -e @@ -19,7 +19,7 @@ if [ -n "$NVM_DIR" ]; then fi # Change to the expected directory -cd "$(dirname "$0")/.." +cd "$(dirname "$0")/../.." # Check if nvm is installed if [ "$TRAVIS" != "true" ] && ! command_exists "nvm"; then @@ -30,7 +30,7 @@ if [ "$TRAVIS" != "true" ] && ! command_exists "nvm"; then fi echo -en $(status_message "Installing NVM..." ) - download "https://raw.githubusercontent.com/creationix/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 + download "https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 echo ' done!' echo -e $(warning_message "NVM was updated, please run this command to reload it:" ) @@ -39,7 +39,7 @@ if [ "$TRAVIS" != "true" ] && ! command_exists "nvm"; then else echo -e $(error_message "") echo -e $(error_message "Please install NVM manually, then re-run the setup script to continue.") - echo -e $(error_message "NVM installation instructions can be found here: $(action_format "https://github.com/creationix/nvm")") + echo -e $(error_message "NVM installation instructions can be found here: $(action_format "https://github.com/nvm-sh/nvm")") fi exit 1 @@ -48,7 +48,7 @@ fi # Check if the current nvm version is up to date. if [ "$TRAVIS" != "true" ] && [ $NVM_VERSION != "v$(nvm --version)" ]; then echo -en $(status_message "Updating NVM..." ) - download "https://raw.githubusercontent.com/creationix/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 + download "https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 echo ' done!' echo -e $(warning_message "NVM was updated, please run this command to reload it:" ) diff --git a/bin/install-wordpress.sh b/bin/local-env/install-wordpress.sh similarity index 71% rename from bin/install-wordpress.sh rename to bin/local-env/install-wordpress.sh index 5b3b8b83c0d..bb8d05efe30 100755 --- a/bin/install-wordpress.sh +++ b/bin/local-env/install-wordpress.sh @@ -3,32 +3,19 @@ # Exit if any command fails. set -e -# Gutenberg script includes. -. "$(dirname "$0")/includes.sh" +# Common variables. +DOCKER_COMPOSE_FILE_OPTIONS="-f $(dirname "$0")/docker-compose.yml" +WP_DEBUG=${WP_DEBUG-true} +SCRIPT_DEBUG=${SCRIPT_DEBUG-true} -# Set up environment variables -. "$(dirname "$0")/bootstrap-env.sh" +# Include useful functions +. "$(dirname "$0")/includes.sh" # These are the containers and values for the development site. CLI='cli' CONTAINER='wordpress' SITE_TITLE='AMP Dev' -# If we're installing/re-installing the test site, change the containers used. -if [ "$1" == '--e2e_tests' ]; then - CLI="${CLI}_e2e_tests" - CONTAINER="${CONTAINER}_e2e_tests" - SITE_TITLE='AMP Testing' - - if ! docker ps | grep -q $CONTAINER; then - echo -e $(error_message "WordPress e2e tests run in their own Docker container, but that container wasn't found.") - echo "Please restart your Docker containers by running 'docker-compose $DOCKER_COMPOSE_FILE_OPTIONS down && docker-compose $DOCKER_COMPOSE_FILE_OPTIONS up -d' or" - echo "by running './bin/setup-local-env.sh' again." - echo "" - exit 1 - fi -fi - # Get the host port for the WordPress container. HOST_PORT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS port $CONTAINER 80 | awk -F : '{printf $2}') @@ -43,7 +30,7 @@ echo '' # If this is the test site, we reset the database so no posts/comments/etc. # dirty up the tests. -if [ "$1" == '--e2e_tests' ]; then +if [ "$1" == '--reset-site' ]; then echo -e $(status_message "Resetting test database...") docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI db reset --yes --quiet fi @@ -64,13 +51,8 @@ fi # Make sure the uploads and upgrade folders exist and we have permissions to add files. echo -e $(status_message "Ensuring that files can be uploaded...") -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER chmod 767 /var/www/html/wp-content/plugins -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER chmod 767 /var/www/html/wp-config.php -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER chmod 767 /var/www/html/wp-settings.php -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER mkdir -p /var/www/html/wp-content/uploads -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER chmod -v 767 /var/www/html/wp-content/uploads -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER mkdir -p /var/www/html/wp-content/upgrade -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER chmod 767 /var/www/html/wp-content/upgrade +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER mkdir -p /var/www/html/wp-content/uploads /var/www/html/wp-content/upgrade +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER chmod 767 /var/www/html/wp-content/plugins /var/www/html/wp-config.php /var/www/html/wp-settings.php /var/www/html/wp-content/uploads /var/www/html/wp-content/upgrade CURRENT_WP_VERSION=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm $CLI core version) echo -e $(status_message "Current WordPress version: $CURRENT_WP_VERSION...") @@ -91,31 +73,31 @@ if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI option update siteurl "http://localhost:$HOST_PORT" --quiet fi +# Install a dummy favicon to avoid 404 errors. +echo -e $(status_message "Installing a dummy favicon...") +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER touch /var/www/html/favicon.ico + # Activate AMP plugin. echo -e $(status_message "Activating AMP plugin...") docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin activate amp --quiet -if [ "$POPULAR_PLUGINS" == "true" ]; then - echo -e $(status_message "Activating popular plugins...") - docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin install advanced-custom-fields --activate --quiet - docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin install jetpack --activate --quiet - docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin install wpforms-lite --activate --quiet -fi -# Install a dummy favicon to avoid 404 errors. -echo -e $(status_message "Installing a dummy favicon...") -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm $CONTAINER touch /var/www/html/favicon.ico +# Install & activate Gutenberg plugin. +echo -e $(status_message "Installing and activating Gutenberg plugin...") +# todo: Use `wp plugin install --activate` once WP-CLI is updated, see https://github.com/wp-cli/extension-command/issues/176. +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin install gutenberg --activate --quiet +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI plugin activate gutenberg --quiet # Configure site constants. echo -e $(status_message "Configuring site constants...") WP_DEBUG_CURRENT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json WP_DEBUG) -if [ $WP_DEBUG != $WP_DEBUG_CURRENT ]; then +if [ "$WP_DEBUG" != $WP_DEBUG_CURRENT ]; then docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI config set WP_DEBUG $WP_DEBUG --raw --type=constant --quiet WP_DEBUG_RESULT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json WP_DEBUG) echo -e $(status_message "WP_DEBUG: $WP_DEBUG_RESULT...") fi SCRIPT_DEBUG_CURRENT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json SCRIPT_DEBUG) -if [ $SCRIPT_DEBUG != $SCRIPT_DEBUG_CURRENT ]; then +if [ "$SCRIPT_DEBUG" != $SCRIPT_DEBUG_CURRENT ]; then docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI config set SCRIPT_DEBUG $SCRIPT_DEBUG --raw --type=constant --quiet SCRIPT_DEBUG_RESULT=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm -u 33 $CLI config get --type=constant --format=json SCRIPT_DEBUG) echo -e $(status_message "SCRIPT_DEBUG: $SCRIPT_DEBUG_RESULT...") diff --git a/bin/install-docker.sh b/bin/local-env/launch-containers.sh similarity index 55% rename from bin/install-docker.sh rename to bin/local-env/launch-containers.sh index 56bb4ad3ef1..dae82775f16 100755 --- a/bin/install-docker.sh +++ b/bin/local-env/launch-containers.sh @@ -3,14 +3,15 @@ # Exit if any command fails. set -e -. "$(dirname "$0")/bootstrap-env.sh" +# Common variables. +DOCKER_COMPOSE_FILE_OPTIONS="-f $(dirname "$0")/docker-compose.yml" # Include useful functions. . "$(dirname "$0")/includes.sh" # Check that Docker is installed. if ! command_exists "docker"; then - echo -e $(error_message "Docker doesn't seem to be installed. Please head on over to the Docker site to download it: $(action_format "https://www.docker.com/community-edition#/download")") + echo -e $(error_message "Docker doesn't seem to be installed. Please head on over to the Docker site to download it: $(action_format "https://www.docker.com/products/docker-desktop")") exit 1 fi @@ -31,16 +32,3 @@ docker-compose $DOCKER_COMPOSE_FILE_OPTIONS pull # Launch the containers. echo -e $(status_message "Starting Docker containers...") docker-compose $DOCKER_COMPOSE_FILE_OPTIONS up -d >/dev/null - -# Set up WordPress Development site. -# Note: we don't bother installing the test site right now, because that's -# done on every time `npm run test-e2e` is run. -. "$(dirname "$0")/install-wordpress.sh" - -# Install the PHPUnit test scaffolding. -echo -e $(status_message "Installing PHPUnit test scaffolding...") -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql $WP_VERSION false > /dev/null - -# Install Composer. This is only used to run WordPress Coding Standards checks. -echo -e $(status_message "Installing and updating Composer modules...") -docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm composer install diff --git a/bin/local-env/start.sh b/bin/local-env/start.sh new file mode 100755 index 00000000000..64272b8cc44 --- /dev/null +++ b/bin/local-env/start.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# Exit if any command fails +set -e + +# Include useful functions +. "$(dirname "$0")/includes.sh" + +# Change to the expected directory +cd "$(dirname "$0")/../.." + +# Check whether Node and NVM are installed +. "$(dirname "$0")/install-node-nvm.sh" + +# Check whether Composer installed +. "$(dirname "$0")/install-composer.sh" + +# Check whether Docker is installed and running +. "$(dirname "$0")/launch-containers.sh" + +# Set up WordPress Development site. +# Note: we don't bother installing the test site right now, because that's +# done on every time `npm run test-e2e` is run. +. "$(dirname "$0")/install-wordpress.sh" + +! read -d '' AMP <<"EOT" +MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMWNXK0OOkkkkOO0KXNWMMMMMMMMMMMMMMMM +MMMMMMMMMMMMWX0kdlc:::::::::::ccodk0NWMMMMMMMMMMMM +MMMMMMMMMWXOdl::::::::::::::::::::::lx0NMMMMMMMMMM +MMMMMMMWKxl::::::::::::::::::::::::::::oOXWMMMMMMM +MMMMMMXkl:::::::::::::::::col::::::::::::oONMMMMMM +MMMMW0o:::::::::::::::::ox0Xk:::::::::::::cxXWMMMM +MMMW0l:::::::::::::::::dKWWXd:::::::::::::::dXMMMM +MMW0l::::::::::::::::cxXWMM0l::::::::::::::::dXMMM +MMXd::::::::::::::::ckNMMMWkc::::::::::::::::ckWMM +MWOc:::::::::::::::lONMMMMNkooool:::::::::::::oXMM +MWk:::::::::::::::l0WMMMMMMWNWNNOc::::::::::::l0MM +MNx::::::::::::::oKWMMMMMMMMMMW0l:::::::::::::cOWM +MNx:::::::::::::oKWWWMMMMMMMMNOl::::::::::::::c0MM +MWOc::::::::::::cddddxKWMMMMNkc:::::::::::::::oKMM +MMXd:::::::::::::::::l0MMMMXdc:::::::::::::::ckWMM +MMW0l::::::::::::::::dXMWWKd:::::::::::::::::oXMMM +MMMWOl:::::::::::::::kWW0xo:::::::::::::::::oKWMMM +MMMMW0l:::::::::::::l0NOl::::::::::::::::::dKWMMMM +MMMMMWKdc:::::::::::cooc:::::::::::::::::lkNMMMMMM +MMMMMMMN0dc::::::::::::::::::::::::::::lxKWMMMMMMM +MMMMMMMMMWKxoc::::::::::::::::::::::coOXWMMMMMMMMM +MMMMMMMMMMMWNKkdoc:::::::::::::cloxOKWMMMMMMMMMMMM +MMMMMMMMMMMMMMMWNX0OkkxxxxxxkO0KXWWMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + +EOT + +CURRENT_URL=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm cli option get siteurl) + +echo -e "\nWelcome to...\n" +echo -e "\033[95m$AMP\033[0m" + +# Give the user more context to what they should do next: Build the plugin and start testing! +echo -e "\nRun $(action_format "npm run dev") to build the latest version of the AMP plugin," +echo -e "then open $(action_format "$CURRENT_URL") to get started!" + +echo -e "\n\nAccess the above install using the following credentials:" +echo -e "Default username: $(action_format "admin"), password: $(action_format "password")" diff --git a/bin/local-env/stop.sh b/bin/local-env/stop.sh new file mode 100755 index 00000000000..51c2bdc5c3b --- /dev/null +++ b/bin/local-env/stop.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Exit if any command fails. +set -e + +# Common variables. +DOCKER_COMPOSE_FILE_OPTIONS="-f $(dirname "$0")/docker-compose.yml" + +# Include useful functions. +. "$(dirname "$0")/includes.sh" + +# Check that Docker is installed. +if ! command_exists "docker"; then + echo -e $(error_message "Docker doesn't seem to be installed. Please head on over to the Docker site to download it: $(action_format "https://www.docker.com/products/docker-desktop")") + exit 1 +fi + +# Check that Docker is running. +if ! docker info >/dev/null 2>&1; then + echo -e $(error_message "Docker isn't running. Please check that you've started your Docker app, and see it in your system tray.") + exit 1 +fi + +# Stop existing containers. +echo -e $(status_message "Stopping Docker containers...") +docker-compose $DOCKER_COMPOSE_FILE_OPTIONS down --remove-orphans >/dev/null 2>&1 diff --git a/bin/reset-e2e-tests.sh b/bin/reset-e2e-tests.sh deleted file mode 100755 index fb1e080f9da..00000000000 --- a/bin/reset-e2e-tests.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -# Exit if any command fails. -set -e - -# Set up WordPress site used for end-to-end (e2e) tests. -. "$(dirname "$0")/install-wordpress.sh" --e2e_tests diff --git a/bin/setup-local-env.sh b/bin/setup-local-env.sh deleted file mode 100755 index dcc86df34a2..00000000000 --- a/bin/setup-local-env.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -# Exit if any command fails -set -e - -# Set up environment variables -. "$(dirname "$0")/bootstrap-env.sh" - -# Include useful functions -. "$(dirname "$0")/includes.sh" - -# Change to the expected directory -cd "$(dirname "$0")/.." - -# Check Node and NVM are installed -. "$(dirname "$0")/install-node-nvm.sh" - -# Check Docker is installed and running -. "$(dirname "$0")/install-docker.sh" - -! read -d '' GUTENBERG <<"EOT" -,⁻⁻⁻· . | -| ،⁓’. . |--- ,---. ,---. |---. ,---. ,---. ,---. -| | | | | |---' | | | | |---' | | | -`---' `---' `---’ `---’ ' ` `---' `---’ ` `---| - `---' -EOT - -CURRENT_URL=$(docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run -T --rm cli option get siteurl) - -echo -e "\nWelcome to...\n" -echo -e "\033[95m$GUTENBERG\033[0m" - -# Give the user more context to what they should do next: Build Gutenberg and start testing! -echo -e "\nRun $(action_format "npm run dev") to build the latest Gutenberg packages," -echo -e "then open $(action_format "$CURRENT_URL") to get started!" - -echo -e "\n\nAccess the above install using the following credentials:" -echo -e "Default username: $(action_format "admin"), password: $(action_format "password")" diff --git a/contributing.md b/contributing.md index 91954ef4b2f..2bd8fb0ace0 100644 --- a/contributing.md +++ b/contributing.md @@ -44,9 +44,96 @@ The AMP Project accepts responsible security disclosures through the [Google App In addition to the Community Guidelines, this project follows an explicit [Code of Conduct](https://github.com/ampproject/amp-wp/blob/develop/code_of_conduct.md). -## Dev Setup +## Getting Started -To start, clone this repository into your WordPress install being used for development: +### Requirements + +To contribute to this plugin, you need the following tools installed on your computer: + +* [Composer](https://getcomposer.org/) - to install PHP dependencies. +* [Node.js](https://nodejs.org/en/) - to install JavaScript dependencies. +* [WordPress](https://wordpress.org/download/) - to run the actual plugin. + +You should be running a Node version matching the [current active LTS release](https://github.com/nodejs/Release#release-schedule) or newer for this plugin to work correctly. You can check your Node.js version by typing node -v in the Terminal prompt. + +If you have an incompatible version of Node in your development environment, you can use [nvm](https://github.com/creationix/nvm) to change node versions on the command line: + +```bash +nvm install +``` + +## Local Environment + +Since you need a WordPress environment to run the plugin in, the quickest way to get up and running is to use the provided Docker setup. Install [Docker](https://www.docker.com/products/docker-desktop) and [Docker Compose](https://docs.docker.com/compose/install/) by following the instructions on their website. + +You can then clone this project somewhere on your computer: + +```bash +git clone git@github.com:ampproject/amp-wp.git amp +cd amp +``` + +After that, run a script to set up the local environment. It will automatically verify whether Docker, Composer and Node.js are configured properly and start the local WordPress instance. You may need to run this script multiple times if prompted. + +```bash +./bin/local-env/start.sh +``` + +If everything was successful, you'll see this on your screen: + +``` +Welcome to... + +MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMWNXK0OOkkkkOO0KXNWMMMMMMMMMMMMMMMM +MMMMMMMMMMMMWX0kdlc:::::::::::ccodk0NWMMMMMMMMMMMM +MMMMMMMMMWXOdl::::::::::::::::::::::lx0NMMMMMMMMMM +MMMMMMMWKxl::::::::::::::::::::::::::::oOXWMMMMMMM +MMMMMMXkl:::::::::::::::::col::::::::::::oONMMMMMM +MMMMW0o:::::::::::::::::ox0Xk:::::::::::::cxXWMMMM +MMMW0l:::::::::::::::::dKWWXd:::::::::::::::dXMMMM +MMW0l::::::::::::::::cxXWMM0l::::::::::::::::dXMMM +MMXd::::::::::::::::ckNMMMWkc::::::::::::::::ckWMM +MWOc:::::::::::::::lONMMMMNkooool:::::::::::::oXMM +MWk:::::::::::::::l0WMMMMMMWNWNNOc::::::::::::l0MM +MNx::::::::::::::oKWMMMMMMMMMMW0l:::::::::::::cOWM +MNx:::::::::::::oKWWWMMMMMMMMNOl::::::::::::::c0MM +MWOc::::::::::::cddddxKWMMMMNkc:::::::::::::::oKMM +MMXd:::::::::::::::::l0MMMMXdc:::::::::::::::ckWMM +MMW0l::::::::::::::::dXMWWKd:::::::::::::::::oXMMM +MMMWOl:::::::::::::::kWW0xo:::::::::::::::::oKWMMM +MMMMW0l:::::::::::::l0NOl::::::::::::::::::dKWMMMM +MMMMMWKdc:::::::::::cooc:::::::::::::::::lkNMMMMMM +MMMMMMMN0dc::::::::::::::::::::::::::::lxKWMMMMMMM +MMMMMMMMMWKxoc::::::::::::::::::::::coOXWMMMMMMMMM +MMMMMMMMMMMWNKkdoc:::::::::::::cloxOKWMMMMMMMMMMMM +MMMMMMMMMMMMMMMWNX0OkkxxxxxxkO0KXWWMMMMMMMMMMMMMMM +MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM +``` + +The WordPress installation should be available at http://localhost:8890 (**Username**: admin, **Password**: password). + +To later turn off the local environment, you can run: + +```bash +npm run env:stop +``` + +To bring it back later, run: + +```bash +npm run env:start +``` + +Also, if you need to reset the local environment's database, you can run: + +```bash +npm run env:reset-site +``` + +### Custom Environment + +Alternatively, you can use your own local WordPress environment and clone this repository right into your `wp-content/plugins` directory. ```bash cd wp-content/plugins && git clone git@github.com:ampproject/amp-wp.git amp @@ -62,30 +149,112 @@ npm install And lastly, do a build of the JavaScript: ```bash -npm run build +npm run build:js ``` Lastly, to get the plugin running in your WordPress install, run `composer install` and then activate the plugin via the WordPress dashboard or `wp plugin activate amp`. -To install the `pre-commit` hook, do `bash vendor/xwp/wp-dev-lib/scripts/install-pre-commit-hook.sh`. +## Developing the Plugin -Note that pull requests will be checked against [WordPress-Coding-Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) with PHPCS, and for JavaScript linting is done with ESLint and (for now) JSCS and JSHint. +Whether you use the pre-existing local environment or a custom one, any PHP code changes will be directly visible during development. -## Modifying JavaScript for Blocks +However, for JavaScript this involves a build process. To watch for any JavaScript file changes and re-build it when needed, you can run the following command: -To edit JavaScript code which is built/complied, run `npm run dev` to watch the files which Webpack will build. These complied files are excluded from version control but they are included in the release packages. +```bash +npm run dev +``` + +This way you will get a development build of the JavaScript, which makes debugging easier. + +To get a production build, run: + +```bash +npm run build:js +``` -## Creating a Plugin Build +### Creating a Plugin Build -To create a build of the plugin for installing in WordPress as a ZIP package, do: +To create a build of the plugin for installing in WordPress as a ZIP package, run: ```bash -composer install # (if you haven't done so yet) -npm install # (if you haven't done so yet) npm run build ``` -This will create an `amp.zip` in the plugin directory which you can install. The contents of this ZIP are also located in the `build` directory which you can `rsync` somewhere as well. +This will create an `amp.zip` in the plugin directory which you can install. The contents of this ZIP are also located in the `build` directory which you can `rsync` somewhere as well if needed. + +### Writing Tests + +#### PHP Unit Tests + +The AMP plugin uses the [PHPUnit](https://phpunit.de/) testing framework to write unit and integration tests for the PHP part. + +To run the full test suite, you can use the following command: + +```bash +npm run test:php +``` + +You can also just run test for a specific function or class by using something like this: + +```bash +npm run test:php -- --filter=AMP_Theme_Support +``` + +See `npm run test:php:help` to see all the possible options. + +#### JavaScript Unit Tests + +[Jest](https://jestjs.io/) is used as the JavaScript unit testing framework. + +To run the full test suite, you can use the following command: + +```bash +npm run test:js +``` + +You can also watch for any file changes and only run tests that failed or have been modified: + +```bash +npm run test:js:watch +``` + +See `npm run test:js:help` to get a list of additional options that can be passed to the test runner. + +#### End-to-End Tests + +This project leverages the local Docker-based environment to facilitate end-to-end (e2e) testing using Puppeteer. + +To run the full test suite, you can use the following command: + +```bash +npm run test:e2e +``` + +You can also watch for any file changes and only run tests that failed or have been modified: + +```bash +npm run test:e2e:watch +``` + +Not using the built-in local environment? You can also pass any other URL to run the tests against. Example: + +```bash +npm run test:e2e -- --wordpress-base-url=https://my-amp-dev-site.local +``` + +For debugging purposes, you can also run the E2E tests in non-headless mode: + +```bash +HEADLESS=false npm run test:e2e +``` + +### Coding Standards + +All contributions to this project will be checked against [WordPress-Coding-Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) with PHPCS, and for JavaScript linting is done with ESLint. + +To verify your code meets the requirements, you can run `npm run lint`. + +You can also install a `pre-commit` hook by running `bash vendor/xwp/wp-dev-lib/scripts/install-pre-commit-hook.sh`. This way, your code will be checked automatically before committing any changes. ## Updating Allowed Tags And Attributes @@ -136,24 +305,6 @@ The following script creates a post with all core Gutenberg blocks. To run it: 3. run `bash bin/create-gutenberge-test-post.sh` 4. go to the URL that is output in the command line -## PHPUnit Testing - -Please run these tests in an environment with WordPress unit tests installed, like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV). - -Run tests: - -``` bash -$ phpunit -``` - -Run tests with an HTML coverage report: - -``` bash -$ phpunit --coverage-html /tmp/report -``` - -When you push a commit to your PR, Travis CI will run the PHPUnit tests and sniffs against the WordPress Coding Standards. - ## Creating a Prerelease 1. Create changelog draft on [Wiki page](https://github.com/ampproject/amp-wp/wiki/Release-Changelog-Draft). diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 33c043e6822..00000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,95 +0,0 @@ -version: '3.1' - -services: - - wordpress: - image: wordpress - restart: always - ports: - - 8888:80 - environment: - WORDPRESS_DB_HOST: mysql - WORDPRESS_DB_PASSWORD: example - ABSPATH: /usr/src/wordpress/ - WORDPRESS_DEBUG: 1 - WORDPRESS_CONFIG_EXTRA: | - define( 'SCRIPT_DEBUG', true ); - volumes: - - wordpress_data:/var/www/html - - .:/var/www/html/wp-content/plugins/amp - - ./node_modules/@wordpress/e2e-tests/plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins - - ./node_modules/@wordpress/e2e-tests/mu-plugins:/var/www/html/wp-content/mu-plugins - depends_on: - - mysql - - cli: - image: wordpress:cli - restart: always - user: xfs - volumes: - - wordpress_data:/var/www/html - - .:/var/www/html/wp-content/plugins/amp - depends_on: - - mysql - - wordpress - - mysql: - image: mysql:5.7 - restart: always - environment: - MYSQL_ROOT_PASSWORD: example - MYSQL_DATABASE: wordpress_test - - wordpress_phpunit: - image: chriszarate/wordpress-phpunit - restart: always - environment: - PHPUNIT_DB_HOST: mysql - volumes: - - .:/app - - testsuite:/tmp - depends_on: - - mysql - - composer: - image: composer - restart: always - volumes: - - .:/app - - wordpress_e2e_tests: - image: wordpress - restart: always - ports: - - 8889:80 - environment: - WORDPRESS_DB_HOST: mysql - WORDPRESS_DB_NAME: wordpress_e2e_tests - WORDPRESS_DB_PASSWORD: example - ABSPATH: /usr/src/wordpress/ - WORDPRESS_DEBUG: 1 - WORDPRESS_CONFIG_EXTRA: | - define( 'SCRIPT_DEBUG', true ); - volumes: - - wordpress_e2e_tests_data:/var/www/html - - .:/var/www/html/wp-content/plugins/amp - - ./node_modules/@wordpress/e2e-tests/plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins - - ./node_modules/@wordpress/e2e-tests/mu-plugins:/var/www/html/wp-content/mu-plugins - depends_on: - - mysql - - cli_e2e_tests: - image: wordpress:cli - restart: always - user: xfs - volumes: - - wordpress_e2e_tests_data:/var/www/html - - .:/var/www/html/wp-content/plugins/amp - depends_on: - - mysql - - wordpress_e2e_tests - -volumes: - testsuite: - wordpress_data: - wordpress_e2e_tests_data: diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php index ee2575c5c43..dfabb4f8f16 100644 --- a/includes/class-amp-autoloader.php +++ b/includes/class-amp-autoloader.php @@ -107,8 +107,8 @@ class AMP_Autoloader { 'AMP_Widget_Archives' => 'includes/widgets/class-amp-widget-archives', 'AMP_Widget_Categories' => 'includes/widgets/class-amp-widget-categories', 'AMP_Widget_Text' => 'includes/widgets/class-amp-widget-text', - 'AMP_Test_Stub_Sanitizer' => 'tests/stubs', - 'AMP_Test_World_Sanitizer' => 'tests/stubs', + 'AMP_Test_Stub_Sanitizer' => 'tests/php/stubs', + 'AMP_Test_World_Sanitizer' => 'tests/php/stubs', ); /** diff --git a/jest-puppeteer.config.js b/jest-puppeteer.config.js new file mode 100644 index 00000000000..ce1e29f057f --- /dev/null +++ b/jest-puppeteer.config.js @@ -0,0 +1,7 @@ +module.exports = { + launch: { + dumpio: true, + headless: process.env.HEADLESS !== 'false', + }, + browserContext: 'default', +}; diff --git a/package.json b/package.json index 5b7720152e8..f760e761cda 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,9 @@ "check-licenses": "wp-scripts check-licenses --production", "deploy": "grunt deploy", "dev": "wp-scripts start", + "env:start": "./bin/local-env/start.sh", + "env:stop": "./bin/local-env/stop.sh", + "env:reset-site": "./bin/local-env/install-wordpress.sh --reset-site", "lint": "npm-run-all --parallel lint:*", "lint:css": "wp-scripts lint-style 'assets/**/*.css'", "lint:css:fix": "npm run lint:css -- --fix", @@ -111,13 +114,14 @@ "lint:pkg-json": "wp-scripts lint-pkg-json . --ignorePath .gitignore", "start": "wp-scripts start", "test": "npm-run-all --parallel test:*", - "pretest:e2e": "cross-env SCRIPT_DEBUG=false ./bin/reset-e2e-tests.sh", - "test:e2e": "wp-scripts test-e2e --config=tests/e2e/jest.config.js", + "test:e2e": "WP_BASE_URL=http://localhost:8890 wp-scripts test-e2e --config=tests/e2e/jest.config.js", + "test:e2e:help": "npm run test:e2e -- --help", "test:e2e:watch": "npm run test:e2e -- --watch", - "test:js": "wp-scripts test-unit-js --config=tests/unit/jest.config.js", + "test:js": "wp-scripts test-unit-js --config=tests/js/jest.config.js", "test:js:help": "wp-scripts test-unit-js --help", "test:js:watch": "npm run test:js -- --watch", - "test:php": "phpunit" + "test:php": "phpunit", + "test:php:help": "npm run test:php -- --help" }, "npmPackageJsonLintConfig": { "extends": "@wordpress/npm-package-json-lint-config", diff --git a/tests/e2e/config/bootstrap.js b/tests/e2e/config/bootstrap.js new file mode 100644 index 00000000000..101dd2560d9 --- /dev/null +++ b/tests/e2e/config/bootstrap.js @@ -0,0 +1,142 @@ +/** + * External dependencies + */ +import { get } from 'lodash'; + +/** + * WordPress dependencies + */ +import { + clearLocalStorage, + enablePageDialogAccept, + setBrowserViewport, +} from '@wordpress/e2e-test-utils'; + +/** + * Environment variables + */ +const { PUPPETEER_TIMEOUT } = process.env; + +/** + * Set of console logging types observed to protect against unexpected yet + * handled (i.e. not catastrophic) errors or warnings. Each key corresponds + * to the Puppeteer ConsoleMessage type, its value the corresponding function + * on the console global object. + * + * @type {Object<string,string>} + */ +const OBSERVED_CONSOLE_MESSAGE_TYPES = { + warning: 'warn', + error: 'error', +}; + +/** + * Array of page event tuples of [ eventName, handler ]. + * + * @type {Array} + */ +const pageEvents = []; + +// The Jest timeout is increased because these tests are a bit slow +jest.setTimeout( PUPPETEER_TIMEOUT || 100000 ); + +/** + * Adds an event listener to the page to handle additions of page event + * handlers, to assure that they are removed at test teardown. + */ +function capturePageEventsForTearDown() { + page.on( 'newListener', ( eventName, listener ) => { + pageEvents.push( [ eventName, listener ] ); + } ); +} + +/** + * Removes all bound page event handlers. + */ +function removePageEvents() { + pageEvents.forEach( ( [ eventName, handler ] ) => { + page.removeListener( eventName, handler ); + } ); +} + +/** + * Adds a page event handler to emit uncaught exception to process if one of + * the observed console logging types is encountered. + */ +function observeConsoleLogging() { + page.on( 'console', ( message ) => { + const type = message.type(); + if ( ! OBSERVED_CONSOLE_MESSAGE_TYPES.hasOwnProperty( type ) ) { + return; + } + + let text = message.text(); + + // An exception is made for _blanket_ deprecation warnings: Those + // which log regardless of whether a deprecated feature is in use. + if ( text.includes( 'This is a global warning' ) ) { + return; + } + + // Viewing posts on the front end can result in this error, which + // has nothing to do with Gutenberg. + if ( text.includes( 'net::ERR_UNKNOWN_URL_SCHEME' ) ) { + return; + } + + // A bug present in WordPress 5.2 will produce console warnings when + // loading the Dashicons font. These can be safely ignored, as they do + // not otherwise regress on application behavior. This logic should be + // removed once the associated ticket has been closed. + // + // See: https://core.trac.wordpress.org/ticket/47183 + if ( + text.startsWith( 'Failed to decode downloaded font:' ) || + text.startsWith( 'OTS parsing error:' ) + ) { + return; + } + + const logFunction = OBSERVED_CONSOLE_MESSAGE_TYPES[ type ]; + + // As of Puppeteer 1.6.1, `message.text()` wrongly returns an object of + // type JSHandle for error logging, instead of the expected string. + // + // See: https://github.com/GoogleChrome/puppeteer/issues/3397 + // + // The recommendation there to asynchronously resolve the error value + // upon a console event may be prone to a race condition with the test + // completion, leaving a possibility of an error not being surfaced + // correctly. Instead, the logic here synchronously inspects the + // internal object shape of the JSHandle to find the error text. If it + // cannot be found, the default text value is used instead. + text = get( message.args(), [ 0, '_remoteObject', 'description' ], text ); + + // Disable reason: We intentionally bubble up the console message + // which, unless the test explicitly anticipates the logging via + // @wordpress/jest-console matchers, will cause the intended test + // failure. + + // eslint-disable-next-line no-console + console[ logFunction ]( text ); + } ); +} + +// Before every test suite run, delete all content created by the test. This ensures +// other posts/comments/etc. aren't dirtying tests and tests don't depend on +// each other's side-effects. +beforeAll( async () => { + capturePageEventsForTearDown(); + enablePageDialogAccept(); + observeConsoleLogging(); + await setBrowserViewport( 'large' ); +} ); + +afterEach( async () => { + await clearLocalStorage(); + await setBrowserViewport( 'large' ); +} ); + +afterAll( () => { + removePageEvents(); +} ); diff --git a/tests/e2e/jest.config.js b/tests/e2e/jest.config.js index bfeca49f2ac..1ac91d4cbf0 100644 --- a/tests/e2e/jest.config.js +++ b/tests/e2e/jest.config.js @@ -1,17 +1,21 @@ module.exports = { - rootDir: '../../', ...require( '@wordpress/scripts/config/jest-e2e.config' ), + setupFilesAfterEnv: [ + '<rootDir>/config/bootstrap.js', + ], + testMatch: [ + '<rootDir>/specs/**/__tests__/**/*.js', + '<rootDir>/specs/**/?(*.)(spec|test).js', + '<rootDir>/specs/**/test/*.js', + ], transform: { - '^.+\\.[jt]sx?$': '<rootDir>/node_modules/@wordpress/scripts/config/babel-transform', + '^.+\\.[jt]sx?$': '<rootDir>/../../node_modules/@wordpress/scripts/config/babel-transform', }, - setupFilesAfterEnv: [ - '<rootDir>/node_modules/@wordpress/jest-preset-default/scripts/setup-test-framework.js', - 'expect-puppeteer', + transformIgnorePatterns: [ + 'node_modules', ], testPathIgnorePatterns: [ - '<rootDir>/.git', - '<rootDir>/node_modules', - '<rootDir>/build', - '.*/e2e/.*', + '.git', + 'node_modules', ], }; diff --git a/tests/e2e/specs/amp-options.test.js b/tests/e2e/specs/amp-options.test.js new file mode 100644 index 00000000000..94ee9ac376d --- /dev/null +++ b/tests/e2e/specs/amp-options.test.js @@ -0,0 +1,134 @@ +/** + * WordPress dependencies + */ +import { visitAdminPage, switchUserToAdmin, switchUserToTest } from '@wordpress/e2e-test-utils'; + +/** + * Deactivates an active plugin. + * + * Not using the provided deactivatePlugin() utility because it uses page.click(), + * which does not work if the element is not in the view or obscured by another element + * like an admin pointer. + * + * @param {string} slug Plugin slug. + */ +async function deactivatePlugin( slug ) { + await switchUserToAdmin(); + await visitAdminPage( 'plugins.php' ); + + await page.evaluate( ( plugin ) => { + const disableLink = document.querySelector( `tr[data-slug="${ plugin }"] .deactivate a` ); + + if ( disableLink ) { + disableLink.scrollIntoView(); + disableLink.click(); + } + }, slug ); + + await page.waitForSelector( `tr[data-slug="${ slug }"] .delete a` ); + await switchUserToTest(); +} + +/** + * Activates an installed plugin. + * + * Not using the provided activatePlugin() utility because it uses page.click(), + * which does not work if the element is not in the view or obscured by another element + * like an admin pointer. + * + * @param {string} slug Plugin slug. + */ +async function activatePlugin( slug ) { + await switchUserToAdmin(); + await visitAdminPage( 'plugins.php' ); + + const disableLink = await page.$( `tr[data-slug="${ slug }"] .deactivate a` ); + if ( disableLink ) { + return; + } + + await page.evaluate( ( plugin ) => { + const enableLink = document.querySelector( `tr[data-slug="${ plugin }"] .activate a` ); + + if ( enableLink ) { + enableLink.scrollIntoView(); + enableLink.click(); + } + }, slug ); + + await page.waitForSelector( `tr[data-slug="${ slug }"] .deactivate a` ); + await switchUserToTest(); +} + +describe( 'AMP Settings Screen', () => { + it( 'Should display a welcome notice', async () => { + await visitAdminPage( 'admin.php', 'page=amp-options' ); + const nodes = await page.$x( + '//*[contains(@class,"amp-welcome-notice")]//h1[contains(text(), "Welcome to AMP for WordPress")]' + ); + expect( nodes.length ).not.toEqual( 0 ); + } ); + + it( 'Should display a warning about missing object cache', async () => { + await visitAdminPage( 'admin.php', 'page=amp-options' ); + const nodes = await page.$x( + '//*[contains(@class,"notice-warning")]//p[contains(text(), "The AMP plugin performs at its best when persistent object cache is enabled")]' + ); + expect( nodes.length ).not.toEqual( 0 ); + } ); + + it( 'Should display a message about theme compatibility', async () => { + await visitAdminPage( 'admin.php', 'page=amp-options' ); + const nodes = await page.$x( + '//*[contains(@class,"notice-success")]//p[contains(text(), "Your active theme is known to work well in standard or transitional mode.")]' + ); + expect( nodes.length ).not.toEqual( 0 ); + } ); + + it( 'Should toggle Website Mode section', async () => { + await visitAdminPage( 'admin.php', 'page=amp-options' ); + + await page.evaluate( () => { + document.querySelector( 'tr.amp-website-mode' ).scrollIntoView(); + } ); + + const websiteModeSection = await page.$( 'tr.amp-website-mode' ); + + expect( await websiteModeSection.isIntersectingViewport() ).toBe( true ); + + await page.click( '#website_experience' ); + + expect( await websiteModeSection.isIntersectingViewport() ).toBe( false ); + } ); + + it( 'Requires at least one AMP experience to be selected', async () => { + await visitAdminPage( 'admin.php', 'page=amp-options' ); + + expect( await page.$eval( '#amp-settings', ( el ) => el.matches( `:invalid` ) ) ).toBe( false ); + + await page.click( '#website_experience' ); + + expect( await page.$eval( '#amp-settings', ( el ) => el.matches( `:invalid` ) ) ).toBe( true ); + } ); + + it( 'Should not allow AMP Stories to be enabled when Gutenberg is not active', async () => { + await deactivatePlugin( 'gutenberg' ); + + await visitAdminPage( 'admin.php', 'page=amp-options' ); + + expect( await page.$eval( '#stories_experience', ( el ) => el.matches( `:disabled` ) ) ).toBe( true ); + + const nodes = await page.$x( + '//*[contains(@class,"notice-info")]//p[contains(text(), "To use stories, you currently must have the latest version")]' + ); + expect( nodes.length ).not.toEqual( 0 ); + + await activatePlugin( 'gutenberg' ); + } ); + + it( 'Should allow AMP Stories to be enabled when Gutenberg is active', async () => { + await visitAdminPage( 'admin.php', 'page=amp-options' ); + + expect( await page.$eval( '#stories_experience', ( el ) => el.matches( `:disabled` ) ) ).toBe( false ); + } ); +} ); diff --git a/tests/e2e/specs/demo.test.js b/tests/e2e/specs/demo.test.js deleted file mode 100644 index 80d3fbfeb29..00000000000 --- a/tests/e2e/specs/demo.test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * WordPress dependencies - */ -import { visitAdminPage, createURLMatcher, setUpResponseMocking, mockOrTransform } from '@wordpress/e2e-test-utils'; - -const MOCK_VIMEO_RESPONSE = { - url: 'https://vimeo.com/22439234', - html: '<iframe width="16" height="9"></iframe>', - type: 'video', - provider_name: 'Vimeo', - provider_url: 'https://vimeo.com', - version: '1.0', -}; - -const couldNotBePreviewed = ( embedObject ) => { - return 'Embed Handler' === embedObject.provider_name; -}; - -const stripIframeFromEmbed = ( embedObject ) => { - return { ...embedObject, html: embedObject.html.replace( /src=[^\s]+/, '' ) }; -}; - -describe( 'new editor state', () => { - beforeAll( async () => { - setUpResponseMocking( [ - { - match: createURLMatcher( 'oembed%2F1.0%2Fproxy' ), - onRequestMatch: mockOrTransform( couldNotBePreviewed, MOCK_VIMEO_RESPONSE, stripIframeFromEmbed ), - }, - ] ); - await visitAdminPage( 'post-new.php', 'gutenberg-demo' ); - } ); - - it( 'content should load without making the post dirty', async () => { - const isDirty = await page.evaluate( () => { - const { select } = window.wp.data; - return select( 'core/editor' ).isEditedPostDirty(); - } ); - expect( isDirty ).toBeFalsy(); - } ); - - it( 'should be immediately saveable', async () => { - expect( await page.$( 'button.editor-post-save-draft' ) ).toBeTruthy(); - } ); -} ); diff --git a/tests/e2e/specs/hello.test.js b/tests/e2e/specs/hello.test.js new file mode 100644 index 00000000000..1ab0e02223d --- /dev/null +++ b/tests/e2e/specs/hello.test.js @@ -0,0 +1,14 @@ +/** + * WordPress dependencies + */ +import { visitAdminPage } from '@wordpress/e2e-test-utils'; + +describe( 'Hello World', () => { + it( 'Should load properly', async () => { + await visitAdminPage( '/' ); + const nodes = await page.$x( + '//h2[contains(text(), "Welcome to WordPress!")]' + ); + expect( nodes.length ).not.toEqual( 0 ); + } ); +} ); diff --git a/tests/e2e/specs/stories-admin-pointer.test.js b/tests/e2e/specs/stories-admin-pointer.test.js new file mode 100644 index 00000000000..e2ec7553145 --- /dev/null +++ b/tests/e2e/specs/stories-admin-pointer.test.js @@ -0,0 +1,14 @@ +/** + * WordPress dependencies + */ +import { visitAdminPage } from '@wordpress/e2e-test-utils'; + +describe( 'AMP Stories Admin Pointer', () => { + it( 'Should be displayed', async () => { + await visitAdminPage( '/' ); + const nodes = await page.$x( + '//*[contains(@class,"wp-amp-pointer")]//p[contains(text(), "You can now enable Stories")]' + ); + expect( nodes.length ).not.toEqual( 0 ); + } ); +} ); diff --git a/tests/unit/jest.config.js b/tests/js/jest.config.js similarity index 92% rename from tests/unit/jest.config.js rename to tests/js/jest.config.js index b4b04e5a7e6..feae25af707 100644 --- a/tests/unit/jest.config.js +++ b/tests/js/jest.config.js @@ -5,7 +5,7 @@ module.exports = { '^.+\\.[jt]sx?$': '<rootDir>/node_modules/@wordpress/scripts/config/babel-transform', }, setupFiles: [ - '<rootDir>/tests/unit/setup-globals', + '<rootDir>/tests/js/setup-globals', ], testPathIgnorePatterns: [ '<rootDir>/.git', diff --git a/tests/unit/setup-globals.js b/tests/js/setup-globals.js similarity index 100% rename from tests/unit/setup-globals.js rename to tests/js/setup-globals.js diff --git a/tests/assets/1024x768.png b/tests/php/assets/1024x768.png similarity index 100% rename from tests/assets/1024x768.png rename to tests/php/assets/1024x768.png diff --git a/tests/assets/350x150.png b/tests/php/assets/350x150.png similarity index 100% rename from tests/assets/350x150.png rename to tests/php/assets/350x150.png diff --git a/tests/assets/wordpress-logo.png b/tests/php/assets/wordpress-logo.png similarity index 100% rename from tests/assets/wordpress-logo.png rename to tests/php/assets/wordpress-logo.png diff --git a/tests/benchmark/run-benchmark.sh b/tests/php/benchmark/run-benchmark.sh similarity index 100% rename from tests/benchmark/run-benchmark.sh rename to tests/php/benchmark/run-benchmark.sh diff --git a/tests/stubs.php b/tests/php/stubs.php similarity index 100% rename from tests/stubs.php rename to tests/php/stubs.php diff --git a/tests/test-amp-analytics-options.php b/tests/php/test-amp-analytics-options.php similarity index 100% rename from tests/test-amp-analytics-options.php rename to tests/php/test-amp-analytics-options.php diff --git a/tests/test-amp-audio-converter.php b/tests/php/test-amp-audio-converter.php similarity index 100% rename from tests/test-amp-audio-converter.php rename to tests/php/test-amp-audio-converter.php diff --git a/tests/test-amp-crowdsignal-embed-handler.php b/tests/php/test-amp-crowdsignal-embed-handler.php similarity index 100% rename from tests/test-amp-crowdsignal-embed-handler.php rename to tests/php/test-amp-crowdsignal-embed-handler.php diff --git a/tests/test-amp-dailymotion-embed.php b/tests/php/test-amp-dailymotion-embed.php similarity index 100% rename from tests/test-amp-dailymotion-embed.php rename to tests/php/test-amp-dailymotion-embed.php diff --git a/tests/test-amp-facebook-embed.php b/tests/php/test-amp-facebook-embed.php similarity index 100% rename from tests/test-amp-facebook-embed.php rename to tests/php/test-amp-facebook-embed.php diff --git a/tests/test-amp-form-sanitizer.php b/tests/php/test-amp-form-sanitizer.php similarity index 100% rename from tests/test-amp-form-sanitizer.php rename to tests/php/test-amp-form-sanitizer.php diff --git a/tests/test-amp-helper-functions.php b/tests/php/test-amp-helper-functions.php similarity index 100% rename from tests/test-amp-helper-functions.php rename to tests/php/test-amp-helper-functions.php diff --git a/tests/test-amp-iframe-sanitizer.php b/tests/php/test-amp-iframe-sanitizer.php similarity index 100% rename from tests/test-amp-iframe-sanitizer.php rename to tests/php/test-amp-iframe-sanitizer.php diff --git a/tests/test-amp-image-dimension-extractor.php b/tests/php/test-amp-image-dimension-extractor.php similarity index 100% rename from tests/test-amp-image-dimension-extractor.php rename to tests/php/test-amp-image-dimension-extractor.php diff --git a/tests/test-amp-img-sanitizer.php b/tests/php/test-amp-img-sanitizer.php similarity index 100% rename from tests/test-amp-img-sanitizer.php rename to tests/php/test-amp-img-sanitizer.php diff --git a/tests/test-amp-instagram-embed.php b/tests/php/test-amp-instagram-embed.php similarity index 100% rename from tests/test-amp-instagram-embed.php rename to tests/php/test-amp-instagram-embed.php diff --git a/tests/test-amp-o2-player-sanitizer.php b/tests/php/test-amp-o2-player-sanitizer.php similarity index 100% rename from tests/test-amp-o2-player-sanitizer.php rename to tests/php/test-amp-o2-player-sanitizer.php diff --git a/tests/test-amp-pinterest-embed.php b/tests/php/test-amp-pinterest-embed.php similarity index 100% rename from tests/test-amp-pinterest-embed.php rename to tests/php/test-amp-pinterest-embed.php diff --git a/tests/test-amp-playbuzz-sanitizer.php b/tests/php/test-amp-playbuzz-sanitizer.php similarity index 100% rename from tests/test-amp-playbuzz-sanitizer.php rename to tests/php/test-amp-playbuzz-sanitizer.php diff --git a/tests/test-amp-render-post.php b/tests/php/test-amp-render-post.php similarity index 100% rename from tests/test-amp-render-post.php rename to tests/php/test-amp-render-post.php diff --git a/tests/test-amp-script-sanitizer.php b/tests/php/test-amp-script-sanitizer.php similarity index 100% rename from tests/test-amp-script-sanitizer.php rename to tests/php/test-amp-script-sanitizer.php diff --git a/tests/test-amp-soundcloud-embed.php b/tests/php/test-amp-soundcloud-embed.php similarity index 100% rename from tests/test-amp-soundcloud-embed.php rename to tests/php/test-amp-soundcloud-embed.php diff --git a/tests/test-amp-story-sanitizer.php b/tests/php/test-amp-story-sanitizer.php similarity index 100% rename from tests/test-amp-story-sanitizer.php rename to tests/php/test-amp-story-sanitizer.php diff --git a/tests/test-amp-style-sanitizer.php b/tests/php/test-amp-style-sanitizer.php similarity index 100% rename from tests/test-amp-style-sanitizer.php rename to tests/php/test-amp-style-sanitizer.php diff --git a/tests/test-amp-tag-and-attribute-sanitizer-private-methods.php b/tests/php/test-amp-tag-and-attribute-sanitizer-private-methods.php similarity index 100% rename from tests/test-amp-tag-and-attribute-sanitizer-private-methods.php rename to tests/php/test-amp-tag-and-attribute-sanitizer-private-methods.php diff --git a/tests/test-amp-twitter-embed.php b/tests/php/test-amp-twitter-embed.php similarity index 100% rename from tests/test-amp-twitter-embed.php rename to tests/php/test-amp-twitter-embed.php diff --git a/tests/test-amp-video-sanitizer.php b/tests/php/test-amp-video-sanitizer.php similarity index 100% rename from tests/test-amp-video-sanitizer.php rename to tests/php/test-amp-video-sanitizer.php diff --git a/tests/test-amp-vimeo-embed.php b/tests/php/test-amp-vimeo-embed.php similarity index 100% rename from tests/test-amp-vimeo-embed.php rename to tests/php/test-amp-vimeo-embed.php diff --git a/tests/test-amp-vine-embed.php b/tests/php/test-amp-vine-embed.php similarity index 100% rename from tests/test-amp-vine-embed.php rename to tests/php/test-amp-vine-embed.php diff --git a/tests/test-amp-youtube-embed.php b/tests/php/test-amp-youtube-embed.php similarity index 100% rename from tests/test-amp-youtube-embed.php rename to tests/php/test-amp-youtube-embed.php diff --git a/tests/test-amp.php b/tests/php/test-amp.php similarity index 100% rename from tests/test-amp.php rename to tests/php/test-amp.php diff --git a/tests/test-class-amp-admin-pointer.php b/tests/php/test-class-amp-admin-pointer.php similarity index 100% rename from tests/test-class-amp-admin-pointer.php rename to tests/php/test-class-amp-admin-pointer.php diff --git a/tests/test-class-amp-base-sanitizer.php b/tests/php/test-class-amp-base-sanitizer.php similarity index 100% rename from tests/test-class-amp-base-sanitizer.php rename to tests/php/test-class-amp-base-sanitizer.php diff --git a/tests/test-class-amp-block-sanitizer.php b/tests/php/test-class-amp-block-sanitizer.php similarity index 100% rename from tests/test-class-amp-block-sanitizer.php rename to tests/php/test-class-amp-block-sanitizer.php diff --git a/tests/test-class-amp-cli.php b/tests/php/test-class-amp-cli.php similarity index 100% rename from tests/test-class-amp-cli.php rename to tests/php/test-class-amp-cli.php diff --git a/tests/test-class-amp-comments-sanitizer.php b/tests/php/test-class-amp-comments-sanitizer.php similarity index 100% rename from tests/test-class-amp-comments-sanitizer.php rename to tests/php/test-class-amp-comments-sanitizer.php diff --git a/tests/test-class-amp-content-sanitizer.php b/tests/php/test-class-amp-content-sanitizer.php similarity index 100% rename from tests/test-class-amp-content-sanitizer.php rename to tests/php/test-class-amp-content-sanitizer.php diff --git a/tests/test-class-amp-core-block-handler.php b/tests/php/test-class-amp-core-block-handler.php similarity index 100% rename from tests/test-class-amp-core-block-handler.php rename to tests/php/test-class-amp-core-block-handler.php diff --git a/tests/test-class-amp-dom-utils.php b/tests/php/test-class-amp-dom-utils.php similarity index 100% rename from tests/test-class-amp-dom-utils.php rename to tests/php/test-class-amp-dom-utils.php diff --git a/tests/test-class-amp-editor-blocks.php b/tests/php/test-class-amp-editor-blocks.php similarity index 100% rename from tests/test-class-amp-editor-blocks.php rename to tests/php/test-class-amp-editor-blocks.php diff --git a/tests/test-class-amp-gallery-block-sanitizer.php b/tests/php/test-class-amp-gallery-block-sanitizer.php similarity index 100% rename from tests/test-class-amp-gallery-block-sanitizer.php rename to tests/php/test-class-amp-gallery-block-sanitizer.php diff --git a/tests/test-class-amp-gfycat-embed-handler.php b/tests/php/test-class-amp-gfycat-embed-handler.php similarity index 100% rename from tests/test-class-amp-gfycat-embed-handler.php rename to tests/php/test-class-amp-gfycat-embed-handler.php diff --git a/tests/test-class-amp-http.php b/tests/php/test-class-amp-http.php similarity index 100% rename from tests/test-class-amp-http.php rename to tests/php/test-class-amp-http.php diff --git a/tests/test-class-amp-hulu-embed-handler.php b/tests/php/test-class-amp-hulu-embed-handler.php similarity index 100% rename from tests/test-class-amp-hulu-embed-handler.php rename to tests/php/test-class-amp-hulu-embed-handler.php diff --git a/tests/test-class-amp-imgur-embed-handler.php b/tests/php/test-class-amp-imgur-embed-handler.php similarity index 100% rename from tests/test-class-amp-imgur-embed-handler.php rename to tests/php/test-class-amp-imgur-embed-handler.php diff --git a/tests/test-class-amp-meta-box.php b/tests/php/test-class-amp-meta-box.php similarity index 100% rename from tests/test-class-amp-meta-box.php rename to tests/php/test-class-amp-meta-box.php diff --git a/tests/test-class-amp-nav-menu-toggle-sanitizer.php b/tests/php/test-class-amp-nav-menu-toggle-sanitizer.php similarity index 100% rename from tests/test-class-amp-nav-menu-toggle-sanitizer.php rename to tests/php/test-class-amp-nav-menu-toggle-sanitizer.php diff --git a/tests/test-class-amp-options-manager.php b/tests/php/test-class-amp-options-manager.php similarity index 100% rename from tests/test-class-amp-options-manager.php rename to tests/php/test-class-amp-options-manager.php diff --git a/tests/test-class-amp-options-menu.php b/tests/php/test-class-amp-options-menu.php similarity index 100% rename from tests/test-class-amp-options-menu.php rename to tests/php/test-class-amp-options-menu.php diff --git a/tests/test-class-amp-playlist-embed-handler.php b/tests/php/test-class-amp-playlist-embed-handler.php similarity index 100% rename from tests/test-class-amp-playlist-embed-handler.php rename to tests/php/test-class-amp-playlist-embed-handler.php diff --git a/tests/test-class-amp-post-type-support.php b/tests/php/test-class-amp-post-type-support.php similarity index 100% rename from tests/test-class-amp-post-type-support.php rename to tests/php/test-class-amp-post-type-support.php diff --git a/tests/test-class-amp-service-worker.php b/tests/php/test-class-amp-service-worker.php similarity index 100% rename from tests/test-class-amp-service-worker.php rename to tests/php/test-class-amp-service-worker.php diff --git a/tests/test-class-amp-story-post-type.php b/tests/php/test-class-amp-story-post-type.php similarity index 100% rename from tests/test-class-amp-story-post-type.php rename to tests/php/test-class-amp-story-post-type.php diff --git a/tests/test-class-amp-story-templates.php b/tests/php/test-class-amp-story-templates.php similarity index 100% rename from tests/test-class-amp-story-templates.php rename to tests/php/test-class-amp-story-templates.php diff --git a/tests/test-class-amp-theme-support.php b/tests/php/test-class-amp-theme-support.php similarity index 100% rename from tests/test-class-amp-theme-support.php rename to tests/php/test-class-amp-theme-support.php diff --git a/tests/test-class-amp-vimeo-embed-handler.php b/tests/php/test-class-amp-vimeo-embed-handler.php similarity index 100% rename from tests/test-class-amp-vimeo-embed-handler.php rename to tests/php/test-class-amp-vimeo-embed-handler.php diff --git a/tests/test-class-amp-widget-archives.php b/tests/php/test-class-amp-widget-archives.php similarity index 100% rename from tests/test-class-amp-widget-archives.php rename to tests/php/test-class-amp-widget-archives.php diff --git a/tests/test-class-amp-widget-categories.php b/tests/php/test-class-amp-widget-categories.php similarity index 100% rename from tests/test-class-amp-widget-categories.php rename to tests/php/test-class-amp-widget-categories.php diff --git a/tests/test-class-amp-widget-text.php b/tests/php/test-class-amp-widget-text.php similarity index 100% rename from tests/test-class-amp-widget-text.php rename to tests/php/test-class-amp-widget-text.php diff --git a/tests/test-class-amp-youtube-embed-handler.php b/tests/php/test-class-amp-youtube-embed-handler.php similarity index 100% rename from tests/test-class-amp-youtube-embed-handler.php rename to tests/php/test-class-amp-youtube-embed-handler.php diff --git a/tests/test-tag-and-attribute-sanitizer.php b/tests/php/test-tag-and-attribute-sanitizer.php similarity index 87% rename from tests/test-tag-and-attribute-sanitizer.php rename to tests/php/test-tag-and-attribute-sanitizer.php index 9ee79d00202..3fd5ba482f0 100644 --- a/tests/test-tag-and-attribute-sanitizer.php +++ b/tests/php/test-tag-and-attribute-sanitizer.php @@ -20,82 +20,82 @@ class AMP_Tag_And_Attribute_Sanitizer_Test extends WP_UnitTestCase { */ public function get_body_data() { return array( - 'empty_doc' => array( + 'empty_doc' => array( '', '', ), - 'a-test' => array( + 'a-test' => array( '<a on="tap:see-image-lightbox" role="button" class="button button-secondary play" tabindex="0">Show Image</a>', ), - 'a4a' => array( + 'a4a' => array( '<amp-ad width="300" height="400" type="fake" data-use-a4a="true" data-vars-analytics-var="bar" src="fake_amp.json"><div placeholder=""></div><div fallback=""></div></amp-ad>', null, // No change. array( 'amp-ad' ), ), - 'ads' => array( + 'ads' => array( '<amp-ad width="300" height="250" type="a9" data-aax_size="300x250" data-aax_pubname="test123" data-aax_src="302"><div placeholder=""></div><div fallback=""></div></amp-ad>', null, // No change. array( 'amp-ad' ), ), - 'adsense' => array( + 'adsense' => array( '<amp-ad width="300" height="250" type="adsense" data-ad-client="ca-pub-2005682797531342" data-ad-slot="7046626912"><div placeholder=""></div><div fallback=""></div></amp-ad>', null, // No change. array( 'amp-ad' ), ), - 'amp-3q-player' => array( + 'amp-3q-player' => array( '<amp-3q-player data-id="c8dbe7f4-7f7f-11e6-a407-0cc47a188158" layout="responsive" width="480" height="270"></amp-3q-player>', null, array( 'amp-3q-player' ), ), - 'amp-ad' => array( + 'amp-ad' => array( '<amp-ad width="300" height="250" type="foo"></amp-ad>', null, // No change. array( 'amp-ad' ), ), - 'amp-sticky-ad' => array( + 'amp-sticky-ad' => array( '<amp-sticky-ad layout="nodisplay"><amp-ad width="320" height="50" type="doubleclick" data-slot="/35096353/amptesting/formats/sticky"></amp-ad></amp-sticky-ad>', null, array( 'amp-ad', 'amp-sticky-ad' ), ), - 'amp-sticky-ad-bad-children' => array( + 'amp-sticky-ad-bad-children' => array( '<amp-sticky-ad layout="nodisplay"><span>not allowed</span><amp-ad width="320" height="50" type="doubleclick" data-slot="/35096353/amptesting/formats/sticky"></amp-ad><i>not ok</i></amp-sticky-ad>', '', array(), ), - 'amp-animation' => array( + 'amp-animation' => array( '<amp-animation layout="nodisplay"><span>bad</span><script type="application/json">{}</script><strong>very bad</strong></amp-animation>', '<amp-animation layout="nodisplay"><script type="application/json">{}</script></amp-animation>', array( 'amp-animation' ), ), - 'amp-call-tracking' => array( + 'amp-call-tracking' => array( '<amp-call-tracking config="https://example.com/calltracking.json"><b>bad</b>--and not great: <a href="tel:123456789">+1 (23) 456-789</a><i>more bad</i>not great</amp-call-tracking>', '<amp-call-tracking config="https://example.com/calltracking.json">--and not great: <a href="tel:123456789">+1 (23) 456-789</a>not great</amp-call-tracking>', array( 'amp-call-tracking' ), ), - 'amp-call-tracking_blacklisted_config' => array( + 'amp-call-tracking_blacklisted_config' => array( '<amp-call-tracking config="__amp_source_origin"><a href="tel:123456789">+1 (23) 456-789</a></amp-call-tracking>', '', array(), // Important: This needs to be empty because the amp-call-tracking is stripped. ), - 'amp-embed' => array( + 'amp-embed' => array( '<amp-embed type="taboola" width="400" height="300" layout="responsive"></amp-embed>', null, // No change. array( 'amp-ad' ), ), - 'amp-facebook-comments' => array( + 'amp-facebook-comments' => array( '<amp-facebook-comments width="486" height="657" data-href="http://example.com/baz" layout="responsive" data-numposts="5"></amp-facebook-comments>', null, // No change. array( 'amp-facebook-comments' ), @@ -107,7 +107,7 @@ public function get_body_data() { array(), // Empty because invalid. ), - 'amp-facebook-like' => array( + 'amp-facebook-like' => array( '<amp-facebook-like width="90" height="20" data-href="http://example.com/baz" layout="fixed" data-layout="button_count"></amp-facebook-like>', null, // No change. array( 'amp-facebook-like' ), @@ -119,37 +119,37 @@ public function get_body_data() { array(), // Empty because invalid. ), - 'amp-fit-text' => array( + 'amp-fit-text' => array( '<amp-fit-text width="300" height="200" layout="responsive">Lorem ipsum</amp-fit-text>', null, // No change. array( 'amp-fit-text' ), ), - 'amp-gist' => array( + 'amp-gist' => array( '<amp-gist layout="fixed-height" data-gistid="a19" height="1613"></amp-gist>', null, // No change. array( 'amp-gist' ), ), - 'amp-gist_missing_mandatory_attribute' => array( + 'amp-gist_missing_mandatory_attribute' => array( '<amp-gist layout="fixed-height" height="1613"></amp-gist>', '', array(), ), - 'amp-iframe' => array( + 'amp-iframe' => array( '<amp-iframe width="600" height="200" sandbox="allow-scripts allow-same-origin" layout="responsive" frameborder="0" src="https://www.example.com"></amp-iframe>', null, // No change. array( 'amp-iframe' ), ), - 'amp-iframe_incorrect_protocol' => array( + 'amp-iframe_incorrect_protocol' => array( '<amp-iframe width="600" height="200" sandbox="allow-scripts allow-same-origin" layout="responsive" frameborder="0" src="masterprotocol://www.example.com"></amp-iframe>', '<amp-iframe width="600" height="200" sandbox="allow-scripts allow-same-origin" layout="responsive" frameborder="0"></amp-iframe>', array( 'amp-iframe' ), ), - 'amp-ima-video' => array( + 'amp-ima-video' => array( ' <amp-ima-video width="640" height="360" data-tag="https://example.com/foo" layout="responsive" data-src="https://example.com/bar"> <source src="https://example.com/foo.mp4" type="video/mp4"> @@ -162,86 +162,86 @@ public function get_body_data() { array( 'amp-ima-video' ), ), - 'amp-ima-video_missing_required_attribute' => array( + 'amp-ima-video_missing_required_attribute' => array( '<amp-ima-video width="640" height="360" layout="responsive" data-src="https://example.com/bar"></amp-ima-video>', '', ), - 'amp-imgur' => array( + 'amp-imgur' => array( '<amp-imgur data-imgur-id="54321" layout="responsive" width="540" height="663"></amp-imgur>', null, // No change. array( 'amp-imgur' ), ), - 'amp-install-serviceworker' => array( + 'amp-install-serviceworker' => array( '<amp-install-serviceworker src="https://www.emample.com/worker.js" data-iframe-src="https://www.example.com/serviceworker.html" layout="nodisplay"></amp-install-serviceworker>', null, // No change. array( 'amp-install-serviceworker' ), ), - 'amp-izlesene' => array( + 'amp-izlesene' => array( '<amp-izlesene data-videoid="4321" layout="responsive" width="432" height="123"></amp-izlesene>', null, // No change. array( 'amp-izlesene' ), ), - 'amp-mathml' => array( + 'amp-mathml' => array( '<amp-mathml layout="container" inline data-formula="\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]"></amp-mathml>', null, // No change. array( 'amp-mathml' ), ), - 'amp-riddle-quiz' => array( + 'amp-riddle-quiz' => array( '<amp-riddle-quiz layout="responsive" width="600" height="400" data-riddle-id="25799"></amp-riddle-quiz>', null, // No change. array( 'amp-riddle-quiz' ), ), - 'amp-wistia-player' => array( + 'amp-wistia-player' => array( '<amp-wistia-player data-media-hashed-id="u8p9wq6mq8" width="512" height="360"></amp-wistia-player>', null, // No change. array( 'amp-wistia-player' ), ), - 'amp-byside-content' => array( + 'amp-byside-content' => array( '<amp-byside-content data-webcare-id="D6604AE5D0" data-channel="" data-lang="pt" data-fid="" data-label="amp-number" layout="fixed" width="120" height="40"></amp-byside-content>', null, // No change. array( 'amp-byside-content' ), ), - 'amp-bind-macro' => array( + 'amp-bind-macro' => array( '<amp-bind-macro id="circleArea" arguments="radius" expression="3.14 * radius * radius"></amp-bind-macro>', null, // No change. array( 'amp-bind' ), ), - 'amp-nexxtv-player' => array( + 'amp-nexxtv-player' => array( '<amp-nexxtv-player data-mediaid="123ABC" data-client="4321"></amp-nexxtv-player>', null, // No change. array( 'amp-nexxtv-player' ), ), - 'amp-playbuzz' => array( + 'amp-playbuzz' => array( '<amp-playbuzz src="id-from-the-content-here" height="500" data-item-info="true" data-share-buttons="true" data-comments="true"></amp-playbuzz>', null, // No change. array( 'amp-playbuzz' ), ), - 'amp-playbuzz_no_src' => array( + 'amp-playbuzz_no_src' => array( '<amp-playbuzz height="500" data-item-info="true"></amp-playbuzz>', null, // @todo This actually should be stripped because . array( 'amp-playbuzz' ), ), // AMP-NEXT-PAGE > [separator]. - 'reference-point-amp-next-page-separator' => array( + 'reference-point-amp-next-page-separator' => array( '<amp-next-page src="https://example.com/config.json"><div separator><h1>Keep reading</h1></div></amp-next-page>', null, array( 'amp-next-page' ), ), // amp-next-page extension .json configuration. - 'reference-point-amp-next-page-json-config' => array( + 'reference-point-amp-next-page-json-config' => array( '<amp-next-page><script type="application/json">{"pages": []}</script></amp-next-page>', null, array( 'amp-next-page' ), @@ -253,25 +253,25 @@ public function get_body_data() { array( 'amp-carousel', 'amp-lightbox-gallery' ), ), - 'reference-point-lightbox-thumbnail-id' => array( + 'reference-point-lightbox-thumbnail-id' => array( '<amp-img src="/awesome.png" width="300" height="300" lightbox lightbox-thumbnail-id="a"></amp-img>', null, array( 'amp-lightbox-gallery' ), ), - 'lightbox-with-amp-carousel' => array( + 'lightbox-with-amp-carousel' => array( '<amp-carousel lightbox width="1600" height="900" layout="responsive" type="slides"><amp-img src="image1" width="200" height="100"></amp-img><amp-img src="image1" width="200" height="100"></amp-img><amp-img src="image1" width="200" height="100"></amp-img></amp-carousel>', null, array( 'amp-lightbox-gallery', 'amp-carousel' ), ), - 'reference-points-amp-live-list' => array( + 'reference-points-amp-live-list' => array( '<amp-live-list id="my-live-list" data-poll-interval="15000" data-max-items-per-page="20"><button update on="tap:my-live-list.update">You have updates!</button><div items></div><div pagination></div></amp-live-list>', null, array( 'amp-live-list' ), ), - 'reference-points-amp-story' => call_user_func( + 'reference-points-amp-story' => call_user_func( function () { $html = str_replace( array( "\n", "\t" ), @@ -331,96 +331,96 @@ function () { } ), - 'reference-points-bad' => array( + 'reference-points-bad' => array( '<div lightbox-thumbnail-id update items pagination separator option selected disabled>BAD REFERENCE POINTS</div>', '<div>BAD REFERENCE POINTS</div>', array(), ), - 'amp-position-observer' => array( + 'amp-position-observer' => array( '<amp-position-observer intersection-ratios="1"></amp-position-observer>', null, // No change. array( 'amp-position-observer' ), ), - 'amp-twitter' => array( + 'amp-twitter' => array( '<amp-twitter width="321" height="543" layout="responsive" data-tweetid="98765"></amp-twitter>', null, // No change. array( 'amp-twitter' ), ), - 'amp-user-notification' => array( + 'amp-user-notification' => array( '<amp-user-notification layout="nodisplay" id="amp-user-notification1" data-show-if-href="https://example.com/api/show?timestamp=TIMESTAMP" data-dismiss-href="https://example.com/api/echo/post">This site uses cookies to personalize content.<a class="btn" on="tap:amp-user-notification1.dismiss">I accept</a></amp-user-notification>', '<amp-user-notification layout="nodisplay" id="amp-user-notification1" data-show-if-href="https://example.com/api/show?timestamp=TIMESTAMP" data-dismiss-href="https://example.com/api/echo/post">This site uses cookies to personalize content.<a class="btn" on="tap:amp-user-notification1.dismiss">I accept</a></amp-user-notification>', array( 'amp-user-notification' ), ), - 'amp-video' => array( + 'amp-video' => array( '<amp-video width="432" height="987" src="/video/location.mp4"></amp-video>', null, // No change. array( 'amp-video' ), ), - 'amp_video_children' => array( + 'amp_video_children' => array( '<amp-video width="432" height="987"><track kind="subtitles" src="https://example.com/sampleChapters.vtt" srclang="en"><source src="foo.webm" type="video/webm"><source src="foo.ogg" type="video/ogg"><div placeholder>Placeholder</div><span fallback>Fallback</span></amp-video>', null, // No change. array( 'amp-video' ), ), - 'amp_audio_children' => array( + 'amp_audio_children' => array( '<amp-audio><track kind="subtitles" src="https://example.com/sampleChapters.vtt" srclang="en"><source src="foo.mp3" type="audio/mp3"><source src="foo.wav" type="audio/wav"><div placeholder>Placeholder</div><span fallback>Fallback</span></amp-audio>', null, // No change. array( 'amp-audio' ), ), - 'amp-vk' => array( + 'amp-vk' => array( '<amp-vk width="500" height="300" data-embedtype="post" layout="responsive"></amp-vk>', null, // No change. array( 'amp-vk' ), ), - 'amp-apester-media' => array( + 'amp-apester-media' => array( '<amp-apester-media height="444" data-apester-media-id="57a336dba187a2ca3005e826" layout="fixed-height"></amp-apester-media>', '<amp-apester-media height="444" data-apester-media-id="57a336dba187a2ca3005e826" layout="fixed-height"></amp-apester-media>', array( 'amp-apester-media' ), ), - 'button' => array( + 'button' => array( '<button on="tap:AMP.setState(foo=\'foo\', isButtonDisabled=true, textClass=\'redBackground\', imgSrc=\'https://ampbyexample.com/img/Shetland_Sheepdog.jpg\', imgSize=200, imgAlt=\'Sheepdog\', videoSrc=\'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4\')">Click me</button>', null, ), - 'brid-player' => array( + 'brid-player' => array( '<amp-brid-player data-dynamic="abc" data-partner="264" data-player="4144" data-video="13663" layout="responsive" width="480" height="270"></amp-brid-player>', null, array( 'amp-brid-player' ), ), - 'brightcove' => array( + 'brightcove' => array( '<amp-brightcove data-account="906043040001" data-video-id="1401169490001" data-player="180a5658-8be8-4f33-8eba-d562ab41b40c" layout="responsive" width="480" height="270"></amp-brightcove>', '<amp-brightcove data-account="906043040001" data-video-id="1401169490001" data-player="180a5658-8be8-4f33-8eba-d562ab41b40c" layout="responsive" width="480" height="270"></amp-brightcove>', array( 'amp-brightcove' ), ), - 'carousel_slides' => array( + 'carousel_slides' => array( '<amp-carousel width="400" height="300" layout="responsive" type="slides" controls=""><div>hello world</div><amp-img src="https://lh3.googleusercontent.com/pSECrJ82R7-AqeBCOEPGPM9iG9OEIQ_QXcbubWIOdkY=w400-h300-no-n" layout="fill"></amp-img><amp-img src="https://lh3.googleusercontent.com/5rcQ32ml8E5ONp9f9-Rf78IofLb9QjS5_0mqsY1zEFc=w400-h300-no-n" width="400" height="300" layout="responsive"></amp-img><amp-img src="https://lh3.googleusercontent.com/Z4gtm5Bkxyv21Z2PtbTf95Clb9AE4VTR6olbBKYrenM=w400-h300-no-n" width="400" height="300" layout="responsive"></amp-img><amp-soundcloud height="300" layout="fixed-height" data-trackid="243169232"></amp-soundcloud><amp-youtube data-videoid="mGENRKrdoGY" width="400" height="300"></amp-youtube><amp-anim src="https://lh3.googleusercontent.com/qNn8GDz8Jfd-s9lt3Nc4lJeLjVyEaqGJTk1vuCUWazCmAeOBVjSWDD0SMTU7x0zhVe5UzOTKR0n-kN4SXx7yElvpKYvCMaRyS_g-jydhJ_cEVYmYPiZ_j1Y9de43mlKxU6s06uK1NAlpbSkL_046amEKOdgIACICkuWfOBwlw2hUDfjPOWskeyMrcTu8XOEerCLuVqXugG31QC345hz3lUyOlkdT9fMYVUynSERGNzHba7bXMOxKRe3izS5DIWUgJs3oeKYqA-V8iqgCvneD1jj0Ff68V_ajm4BDchQubBJU0ytXVkoWh27ngeEHubpnApOS6fcGsjPxeuMjnzAUtoTsiXz2FZi1mMrxrblJ-kZoAq1DJ95cnoqoa2CYq3BTgq2E8BRe2paNxLJ5GXBCTpNdXMpVJc6eD7ceijQyn-2qanilX-iK3ChbOq0uBHMvsdoC_LsFOu5KzbbNH71vM3DPkvDGmHJmF67Vj8sQ6uBrLnzpYlCyN4-Y9frR8zugDcqX5Q=w400-h300-no" width="400" height="300"><amp-img placeholder="" src="https://lh3.googleusercontent.com/qNn8GDz8Jfd-s9lt3Nc4lJeLjVyEaqGJTk1vuCUWazCmAeOBVjSWDD0SMTU7x0zhVe5UzOTKR0n-kN4SXx7yElvpKYvCMaRyS_g-jydhJ_cEVYmYPiZ_j1Y9de43mlKxU6s06uK1NAlpbSkL_046amEKOdgIACICkuWfOBwlw2hUDfjPOWskeyMrcTu8XOEerCLuVqXugG31QC345hz3lUyOlkdT9fMYVUynSERGNzHba7bXMOxKRe3izS5DIWUgJs3oeKYqA-V8iqgCvneD1jj0Ff68V_ajm4BDchQubBJU0ytXVkoWh27ngeEHubpnApOS6fcGsjPxeuMjnzAUtoTsiXz2FZi1mMrxrblJ-kZoAq1DJ95cnoqoa2CYq3BTgq2E8BRe2paNxLJ5GXBCTpNdXMpVJc6eD7ceijQyn-2qanilX-iK3ChbOq0uBHMvsdoC_LsFOu5KzbbNH71vM3DPkvDGmHJmF67Vj8sQ6uBrLnzpYlCyN4-Y9frR8zugDcqX5Q=w400-h300-no-k" width="400" height="300"></amp-img></amp-anim><amp-audio src="https://ia801402.us.archive.org/16/items/EDIS-SRP-0197-06/EDIS-SRP-0197-06.mp3"></amp-audio><amp-brightcove data-account="906043040001" data-video-id="1401169490001" data-player="180a5658-8be8-4f33-8eba-d562ab41b40c" layout="responsive" width="480" height="270"></amp-brightcove><amp-vimeo data-videoid="27246366" width="500" height="281"></amp-vimeo><amp-dailymotion data-videoid="x3rdtfy" width="500" height="281"></amp-dailymotion><amp-vine data-vineid="MdKjXez002d" width="381" height="381" layout="responsive"></amp-vine><amp-video src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4" width="358" height="204" layout="responsive" controls=""></amp-video></amp-carousel><amp-carousel width="auto" height="300" controls=""><div>hello world</div><amp-img src="https://lh3.googleusercontent.com/pSECrJ82R7-AqeBCOEPGPM9iG9OEIQ_QXcbubWIOdkY=w400-h300-no-n" width="400" height="300"></amp-img><amp-img src="https://lh3.googleusercontent.com/5rcQ32ml8E5ONp9f9-Rf78IofLb9QjS5_0mqsY1zEFc=w400-h300-no-n" width="400" height="300"></amp-img><amp-img src="https://lh3.googleusercontent.com/Z4gtm5Bkxyv21Z2PtbTf95Clb9AE4VTR6olbBKYrenM=w400-h300-no-n" width="400" height="300"></amp-img><amp-soundcloud height="300" layout="fixed-height" data-trackid="243169232"></amp-soundcloud><amp-youtube data-videoid="mGENRKrdoGY" width="400" height="300"></amp-youtube><amp-anim src="https://lh3.googleusercontent.com/qNn8GDz8Jfd-s9lt3Nc4lJeLjVyEaqGJTk1vuCUWazCmAeOBVjSWDD0SMTU7x0zhVe5UzOTKR0n-kN4SXx7yElvpKYvCMaRyS_g-jydhJ_cEVYmYPiZ_j1Y9de43mlKxU6s06uK1NAlpbSkL_046amEKOdgIACICkuWfOBwlw2hUDfjPOWskeyMrcTu8XOEerCLuVqXugG31QC345hz3lUyOlkdT9fMYVUynSERGNzHba7bXMOxKRe3izS5DIWUgJs3oeKYqA-V8iqgCvneD1jj0Ff68V_ajm4BDchQubBJU0ytXVkoWh27ngeEHubpnApOS6fcGsjPxeuMjnzAUtoTsiXz2FZi1mMrxrblJ-kZoAq1DJ95cnoqoa2CYq3BTgq2E8BRe2paNxLJ5GXBCTpNdXMpVJc6eD7ceijQyn-2qanilX-iK3ChbOq0uBHMvsdoC_LsFOu5KzbbNH71vM3DPkvDGmHJmF67Vj8sQ6uBrLnzpYlCyN4-Y9frR8zugDcqX5Q=w400-h300-no" width="400" height="300"><amp-img placeholder="" src="https://lh3.googleusercontent.com/qNn8GDz8Jfd-s9lt3Nc4lJeLjVyEaqGJTk1vuCUWazCmAeOBVjSWDD0SMTU7x0zhVe5UzOTKR0n-kN4SXx7yElvpKYvCMaRyS_g-jydhJ_cEVYmYPiZ_j1Y9de43mlKxU6s06uK1NAlpbSkL_046amEKOdgIACICkuWfOBwlw2hUDfjPOWskeyMrcTu8XOEerCLuVqXugG31QC345hz3lUyOlkdT9fMYVUynSERGNzHba7bXMOxKRe3izS5DIWUgJs3oeKYqA-V8iqgCvneD1jj0Ff68V_ajm4BDchQubBJU0ytXVkoWh27ngeEHubpnApOS6fcGsjPxeuMjnzAUtoTsiXz2FZi1mMrxrblJ-kZoAq1DJ95cnoqoa2CYq3BTgq2E8BRe2paNxLJ5GXBCTpNdXMpVJc6eD7ceijQyn-2qanilX-iK3ChbOq0uBHMvsdoC_LsFOu5KzbbNH71vM3DPkvDGmHJmF67Vj8sQ6uBrLnzpYlCyN4-Y9frR8zugDcqX5Q=w400-h300-no-k" width="400" height="300"></amp-img></amp-anim><amp-audio src="https://ia801402.us.archive.org/16/items/EDIS-SRP-0197-06/EDIS-SRP-0197-06.mp3"></amp-audio><amp-brightcove data-account="906043040001" data-video-id="1401169490001" data-player="180a5658-8be8-4f33-8eba-d562ab41b40c" layout="responsive" width="300" height="300"></amp-brightcove><amp-vimeo data-videoid="27246366" width="300" height="300"></amp-vimeo><amp-dailymotion data-videoid="x3rdtfy" width="300" height="300"></amp-dailymotion><amp-vine data-vineid="MdKjXez002d" width="300" height="300"></amp-vine><amp-video src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4" width="300" height="300" controls=""></amp-video></amp-carousel>', '<amp-carousel width="400" height="300" layout="responsive" type="slides" controls=""><div>hello world</div><amp-img src="https://lh3.googleusercontent.com/pSECrJ82R7-AqeBCOEPGPM9iG9OEIQ_QXcbubWIOdkY=w400-h300-no-n" layout="fill"></amp-img><amp-img src="https://lh3.googleusercontent.com/5rcQ32ml8E5ONp9f9-Rf78IofLb9QjS5_0mqsY1zEFc=w400-h300-no-n" width="400" height="300" layout="responsive"></amp-img><amp-img src="https://lh3.googleusercontent.com/Z4gtm5Bkxyv21Z2PtbTf95Clb9AE4VTR6olbBKYrenM=w400-h300-no-n" width="400" height="300" layout="responsive"></amp-img><amp-soundcloud height="300" layout="fixed-height" data-trackid="243169232"></amp-soundcloud><amp-youtube data-videoid="mGENRKrdoGY" width="400" height="300"></amp-youtube><amp-anim src="https://lh3.googleusercontent.com/qNn8GDz8Jfd-s9lt3Nc4lJeLjVyEaqGJTk1vuCUWazCmAeOBVjSWDD0SMTU7x0zhVe5UzOTKR0n-kN4SXx7yElvpKYvCMaRyS_g-jydhJ_cEVYmYPiZ_j1Y9de43mlKxU6s06uK1NAlpbSkL_046amEKOdgIACICkuWfOBwlw2hUDfjPOWskeyMrcTu8XOEerCLuVqXugG31QC345hz3lUyOlkdT9fMYVUynSERGNzHba7bXMOxKRe3izS5DIWUgJs3oeKYqA-V8iqgCvneD1jj0Ff68V_ajm4BDchQubBJU0ytXVkoWh27ngeEHubpnApOS6fcGsjPxeuMjnzAUtoTsiXz2FZi1mMrxrblJ-kZoAq1DJ95cnoqoa2CYq3BTgq2E8BRe2paNxLJ5GXBCTpNdXMpVJc6eD7ceijQyn-2qanilX-iK3ChbOq0uBHMvsdoC_LsFOu5KzbbNH71vM3DPkvDGmHJmF67Vj8sQ6uBrLnzpYlCyN4-Y9frR8zugDcqX5Q=w400-h300-no" width="400" height="300"><amp-img placeholder="" src="https://lh3.googleusercontent.com/qNn8GDz8Jfd-s9lt3Nc4lJeLjVyEaqGJTk1vuCUWazCmAeOBVjSWDD0SMTU7x0zhVe5UzOTKR0n-kN4SXx7yElvpKYvCMaRyS_g-jydhJ_cEVYmYPiZ_j1Y9de43mlKxU6s06uK1NAlpbSkL_046amEKOdgIACICkuWfOBwlw2hUDfjPOWskeyMrcTu8XOEerCLuVqXugG31QC345hz3lUyOlkdT9fMYVUynSERGNzHba7bXMOxKRe3izS5DIWUgJs3oeKYqA-V8iqgCvneD1jj0Ff68V_ajm4BDchQubBJU0ytXVkoWh27ngeEHubpnApOS6fcGsjPxeuMjnzAUtoTsiXz2FZi1mMrxrblJ-kZoAq1DJ95cnoqoa2CYq3BTgq2E8BRe2paNxLJ5GXBCTpNdXMpVJc6eD7ceijQyn-2qanilX-iK3ChbOq0uBHMvsdoC_LsFOu5KzbbNH71vM3DPkvDGmHJmF67Vj8sQ6uBrLnzpYlCyN4-Y9frR8zugDcqX5Q=w400-h300-no-k" width="400" height="300"></amp-img></amp-anim><amp-audio src="https://ia801402.us.archive.org/16/items/EDIS-SRP-0197-06/EDIS-SRP-0197-06.mp3"></amp-audio><amp-brightcove data-account="906043040001" data-video-id="1401169490001" data-player="180a5658-8be8-4f33-8eba-d562ab41b40c" layout="responsive" width="480" height="270"></amp-brightcove><amp-vimeo data-videoid="27246366" width="500" height="281"></amp-vimeo><amp-dailymotion data-videoid="x3rdtfy" width="500" height="281"></amp-dailymotion><amp-vine data-vineid="MdKjXez002d" width="381" height="381" layout="responsive"></amp-vine><amp-video src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4" width="358" height="204" layout="responsive" controls=""></amp-video></amp-carousel><amp-carousel width="auto" height="300" controls=""><div>hello world</div><amp-img src="https://lh3.googleusercontent.com/pSECrJ82R7-AqeBCOEPGPM9iG9OEIQ_QXcbubWIOdkY=w400-h300-no-n" width="400" height="300"></amp-img><amp-img src="https://lh3.googleusercontent.com/5rcQ32ml8E5ONp9f9-Rf78IofLb9QjS5_0mqsY1zEFc=w400-h300-no-n" width="400" height="300"></amp-img><amp-img src="https://lh3.googleusercontent.com/Z4gtm5Bkxyv21Z2PtbTf95Clb9AE4VTR6olbBKYrenM=w400-h300-no-n" width="400" height="300"></amp-img><amp-soundcloud height="300" layout="fixed-height" data-trackid="243169232"></amp-soundcloud><amp-youtube data-videoid="mGENRKrdoGY" width="400" height="300"></amp-youtube><amp-anim src="https://lh3.googleusercontent.com/qNn8GDz8Jfd-s9lt3Nc4lJeLjVyEaqGJTk1vuCUWazCmAeOBVjSWDD0SMTU7x0zhVe5UzOTKR0n-kN4SXx7yElvpKYvCMaRyS_g-jydhJ_cEVYmYPiZ_j1Y9de43mlKxU6s06uK1NAlpbSkL_046amEKOdgIACICkuWfOBwlw2hUDfjPOWskeyMrcTu8XOEerCLuVqXugG31QC345hz3lUyOlkdT9fMYVUynSERGNzHba7bXMOxKRe3izS5DIWUgJs3oeKYqA-V8iqgCvneD1jj0Ff68V_ajm4BDchQubBJU0ytXVkoWh27ngeEHubpnApOS6fcGsjPxeuMjnzAUtoTsiXz2FZi1mMrxrblJ-kZoAq1DJ95cnoqoa2CYq3BTgq2E8BRe2paNxLJ5GXBCTpNdXMpVJc6eD7ceijQyn-2qanilX-iK3ChbOq0uBHMvsdoC_LsFOu5KzbbNH71vM3DPkvDGmHJmF67Vj8sQ6uBrLnzpYlCyN4-Y9frR8zugDcqX5Q=w400-h300-no" width="400" height="300"><amp-img placeholder="" src="https://lh3.googleusercontent.com/qNn8GDz8Jfd-s9lt3Nc4lJeLjVyEaqGJTk1vuCUWazCmAeOBVjSWDD0SMTU7x0zhVe5UzOTKR0n-kN4SXx7yElvpKYvCMaRyS_g-jydhJ_cEVYmYPiZ_j1Y9de43mlKxU6s06uK1NAlpbSkL_046amEKOdgIACICkuWfOBwlw2hUDfjPOWskeyMrcTu8XOEerCLuVqXugG31QC345hz3lUyOlkdT9fMYVUynSERGNzHba7bXMOxKRe3izS5DIWUgJs3oeKYqA-V8iqgCvneD1jj0Ff68V_ajm4BDchQubBJU0ytXVkoWh27ngeEHubpnApOS6fcGsjPxeuMjnzAUtoTsiXz2FZi1mMrxrblJ-kZoAq1DJ95cnoqoa2CYq3BTgq2E8BRe2paNxLJ5GXBCTpNdXMpVJc6eD7ceijQyn-2qanilX-iK3ChbOq0uBHMvsdoC_LsFOu5KzbbNH71vM3DPkvDGmHJmF67Vj8sQ6uBrLnzpYlCyN4-Y9frR8zugDcqX5Q=w400-h300-no-k" width="400" height="300"></amp-img></amp-anim><amp-audio src="https://ia801402.us.archive.org/16/items/EDIS-SRP-0197-06/EDIS-SRP-0197-06.mp3"></amp-audio><amp-brightcove data-account="906043040001" data-video-id="1401169490001" data-player="180a5658-8be8-4f33-8eba-d562ab41b40c" layout="responsive" width="300" height="300"></amp-brightcove><amp-vimeo data-videoid="27246366" width="300" height="300"></amp-vimeo><amp-dailymotion data-videoid="x3rdtfy" width="300" height="300"></amp-dailymotion><amp-vine data-vineid="MdKjXez002d" width="300" height="300"></amp-vine><amp-video src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4" width="300" height="300" controls=""></amp-video></amp-carousel>', array( 'amp-anim', 'amp-audio', 'amp-brightcove', 'amp-carousel', 'amp-dailymotion', 'amp-soundcloud', 'amp-video', 'amp-vimeo', 'amp-vine', 'amp-youtube' ), ), - 'carousel_simple' => array( + 'carousel_simple' => array( '<amp-carousel width="450" height="300"></amp-carousel>', null, array( 'amp-carousel' ), ), - 'carousel_lightbox' => array( + 'carousel_lightbox' => array( '<amp-carousel width="450" height="300" delay="100" arrows [slide]="foo" autoplay loop lightbox></amp-carousel>', null, array( 'amp-bind', 'amp-carousel', 'amp-lightbox-gallery' ), ), - 'base_carousel' => array( + 'base_carousel' => array( ' <amp-base-carousel width="4" height="3" auto-advance="true" layout="responsive" heights="(min-width: 600px) calc(100% * 4 * 3 / 2), calc(100% * 3 * 3 / 2)" visible-count="(min-width: 600px) 4, 3" advance-count="(min-width: 600px) 4, 3"> <div lightbox-thumbnail-id="food">first slide</div> @@ -431,75 +431,75 @@ function () { array( 'amp-base-carousel' ), ), - 'amp-dailymotion' => array( + 'amp-dailymotion' => array( '<amp-dailymotion data-videoid="x3rdtfy" width="500" height="281" dock></amp-dailymotion><h4>Default (responsive)</h4><amp-dailymotion data-videoid="x3rdtfy" width="500" height="281" layout="responsive"></amp-dailymotion><h4>Custom</h4><amp-dailymotion data-videoid="x3rdtfy" data-endscreen-enable="false" data-sharing-enable="false" data-ui-highlight="444444" data-ui-logo="false" data-info="false" width="640" height="360"></amp-dailymotion>', null, array( 'amp-dailymotion', 'amp-video-docking' ), ), // Try to test for NAME_VALUE_PARENT_DISPATCH. - 'amp_ima_video' => array( + 'amp_ima_video' => array( '<amp-ima-video width="640" height="360" layout="responsive" data-tag="ads.xml" data-poster="poster.png"><source src="foo.mp4" type="video/mp4"><source src="foo.webm" type="video/webm"><track label="English subtitles" kind="subtitles" srclang="en" src="https://example.com/subtitles.vtt"><script type="application/json">{"locale": "en", "numRedirects": 4}</script></amp-ima-video>', null, // No change. array( 'amp-ima-video' ), ), // Try to test for NAME_VALUE_DISPATCH. - 'doubleclick-1' => array( + 'doubleclick-1' => array( '<amp-ad width="480" height="75" type="doubleclick" data-slot="/4119129/mobile_ad_banner" data-multi-size="320x50" class="dashedborder"></amp-ad>', '<amp-ad width="480" height="75" type="doubleclick" data-slot="/4119129/mobile_ad_banner" data-multi-size="320x50" class="dashedborder"></amp-ad>', array( 'amp-ad' ), ), // Try to test for NAME_DISPATCH. - 'nav_dispatch_key' => array( + 'nav_dispatch_key' => array( '<nav><a href="https://example.com">Example</a></nav>', null, ), - 'json_linked_data' => array( + 'json_linked_data' => array( '<script type="application/ld+json">{"@context":"http:\/\/schema.org"}</script>', null, // No Change. ), - 'json_linked_data_with_bad_cdata' => array( + 'json_linked_data_with_bad_cdata' => array( '<script type="application/ld+json"><!-- {"@context":"http:\/\/schema.org"} --></script>', '', ), - 'facebook' => array( + 'facebook' => array( '<amp-facebook width="552" height="303" layout="responsive" data-href="https://www.facebook.com/zuck/posts/10102593740125791"></amp-facebook><h1>More Posts</h1>', '<amp-facebook width="552" height="303" layout="responsive" data-href="https://www.facebook.com/zuck/posts/10102593740125791"></amp-facebook><h1>More Posts</h1>', array( 'amp-facebook' ), ), - 'font' => array( + 'font' => array( '<amp-font layout="nodisplay" font-family="Comic AMP" timeout="2000"></amp-font><amp-font layout="nodisplay" font-family="Comic AMP Bold" timeout="3000" font-weight="bold"></amp-font>', '<amp-font layout="nodisplay" font-family="Comic AMP" timeout="2000"></amp-font><amp-font layout="nodisplay" font-family="Comic AMP Bold" timeout="3000" font-weight="bold"></amp-font>', array( 'amp-font' ), ), - 'form' => array( + 'form' => array( '<form method="get" action="/form/search-html/get" target="_blank"><fieldset><label><span>Search for</span><input type="search" placeholder="test" name="term" required></label><input type="submit" value="Search"></fieldset></form>', '<form method="get" action="/form/search-html/get" target="_blank"><fieldset><label><span>Search for</span><input type="search" placeholder="test" name="term" required></label><input type="submit" value="Search"></fieldset></form>', array( 'amp-form' ), ), - 'gfycat' => array( + 'gfycat' => array( '<amp-gfycat data-gfyid="BareSecondaryFlamingo" width="225" height="400"></amp-gfycat>', '<amp-gfycat data-gfyid="BareSecondaryFlamingo" width="225" height="400"></amp-gfycat>', array( 'amp-gfycat' ), ), - 'h2' => array( + 'h2' => array( '<h2>Example Text</h2>', ), - 'empty_element' => array( + 'empty_element' => array( '<br>', ), - 'merge_two_attr_specs' => array( + 'merge_two_attr_specs' => array( '<div submit-success>Whatever</div>', '<div>Whatever</div>', ), @@ -509,15 +509,15 @@ function () { '<a href="">Click me.</a>', ), - 'host_relative_url_allowed' => array( + 'host_relative_url_allowed' => array( '<a href="/path/to/content">Click me.</a>', ), - 'protocol_relative_url_allowed' => array( + 'protocol_relative_url_allowed' => array( '<a href="//example.com/path/to/content">Click me.</a>', ), - 'node_with_whiteilsted_protocol_http_allowed' => array( + 'node_with_whiteilsted_protocol_http_allowed' => array( '<a href="http://example.com/path/to/content">Click me.</a>', ), @@ -537,20 +537,20 @@ function () { ), ), - 'attribute_value_valid' => array( + 'attribute_value_valid' => array( '<template type="amp-mustache">Hello {{world}}! <a href="{{user_url}}" title="{{user_name}}">Homepage</a> User content: {{{some_formatting}}} A guy with Mustache: :-{). {{#returning}}Welcome back!{{/returning}} {{^returning}}Welcome for the first time!{{/returning}} </template>', null, array( 'amp-mustache' ), ), - 'attribute_value_invalid' => array( + 'attribute_value_invalid' => array( // type is mandatory, so the node is removed. '<template type="bad-type">Template Data</template>', '', array(), // No scripts because removed. ), - 'attribute_amp_accordion_value' => call_user_func( + 'attribute_amp_accordion_value' => call_user_func( function() { $html = str_replace( array( "\n", "\t" ), @@ -599,7 +599,7 @@ function() { '<a>Click me.</a>', ), - 'attribute_value_with_required_regex' => array( + 'attribute_value_with_required_regex' => array( '<a target="_blank">Click me.</a>', ), @@ -644,13 +644,13 @@ function() { array( 'amp-dailymotion' ), ), - 'attribute_bad_attr_with_no_value_removed' => array( + 'attribute_bad_attr_with_no_value_removed' => array( '<amp-ad type="adsense" bad-attr-no-value><div fallback>something here</div></amp-ad>', '<amp-ad type="adsense"><div fallback>something here</div></amp-ad>', array( 'amp-ad' ), ), - 'attribute_bad_attr_with_value_removed' => array( + 'attribute_bad_attr_with_value_removed' => array( '<amp-ad type="adsense" bad-attr="some-value">something here</amp-ad>', '<amp-ad type="adsense">something here</amp-ad>', array( 'amp-ad' ), @@ -662,22 +662,22 @@ function() { '', ), - 'remove_node_without_mandatory_attribute' => array( + 'remove_node_without_mandatory_attribute' => array( '<script>console.log()</script>', '', ), - 'remove_script_with_async_attribute' => array( + 'remove_script_with_async_attribute' => array( '<script async src="//cdn.someecards.com/assets/embed/embed-v1.07.min.js" charset="utf-8"></script>', // phpcs:ignore '', ), - 'remove_invalid_json_script' => array( + 'remove_invalid_json_script' => array( '<script type="application/json" class="wp-playlist-script">{}</script>', '', ), - 'allow_node_with_valid_mandatory_attribute' => array( + 'allow_node_with_valid_mandatory_attribute' => array( '<amp-analytics><script type="application/json"></script></amp-analytics>', null, // No change. array( 'amp-analytics' ), @@ -698,7 +698,7 @@ function() { '<div><span><span class="not-empty"></span></span></div>', ), - 'replace_non_whitelisted_node_with_children' => array( + 'replace_non_whitelisted_node_with_children' => array( '<p>This is some text <invalid_tag>with a disallowed tag</invalid_tag> in the middle of it.</p>', '<p>This is some text with a disallowed tag in the middle of it.</p>', ), @@ -714,13 +714,13 @@ function() { array( 'amp-form' ), ), - 'disallowed_empty_attr_removed' => array( + 'disallowed_empty_attr_removed' => array( '<amp-user-notification data-dismiss-href></amp-user-notification>', '<amp-user-notification></amp-user-notification>', array( 'amp-user-notification' ), ), - 'allowed_empty_attr' => array( + 'allowed_empty_attr' => array( '<a border=""></a>', ), @@ -730,7 +730,7 @@ function() { array( 'amp-sidebar' ), ), - 'amp_story_with_amp_sidebar' => array( + 'amp_story_with_amp_sidebar' => array( str_replace( array( "\n", "\t" ), '', @@ -756,7 +756,7 @@ function() { array( 'amp-sidebar', 'amp-story' ), ), - 'amp_sidebar_with_autoscroll' => array( + 'amp_sidebar_with_autoscroll' => array( str_replace( array( "\n", "\t" ), '', @@ -780,12 +780,12 @@ function() { array( 'amp-sidebar' ), ), - 'remove_node_without_mandatory_ancestor' => array( + 'remove_node_without_mandatory_ancestor' => array( '<div>All I have is this div, when all you want is a noscript tag.<audio>Sweet tunes</audio></div>', '<div>All I have is this div, when all you want is a noscript tag.</div>', ), - 'amp-img_with_good_protocols' => array( + 'amp-img_with_good_protocols' => array( '<amp-img src="https://example.com/resource1" srcset="https://example.com/resource1 320w, https://example.com/resource2 480w"></amp-img>', ), @@ -793,44 +793,44 @@ function() { '<amp-img src="/winning:yes.jpg" width="100" height="200"></amp-img>', ), - 'allowed_tag_only' => array( + 'allowed_tag_only' => array( '<p>Text</p><img src="/path/to/file.jpg">', '<p>Text</p>', ), - 'disallowed_attributes' => array( + 'disallowed_attributes' => array( '<a href="/path/to/file.jpg" style="border: 1px solid red !important;">Link</a>', '<a href="/path/to/file.jpg">Link</a>', ), - 'onclick_attribute' => array( + 'onclick_attribute' => array( '<a href="/path/to/file.jpg" onclick="alert(e);">Link</a>', '<a href="/path/to/file.jpg">Link</a>', ), - 'on_attribute' => array( + 'on_attribute' => array( '<button on="tap:my-lightbox">Tap Me</button>', ), - 'multiple_disallowed_attributes' => array( + 'multiple_disallowed_attributes' => array( '<a href="/path/to/file.jpg" style="border: 1px solid red !important;" onclick="alert(e);">Link</a>', '<a href="/path/to/file.jpg">Link</a>', ), - 'attribute_recursive' => array( + 'attribute_recursive' => array( '<div style="border: 1px solid red !important;"><a href="/path/to/file.jpg" onclick="alert(e);">Hello World</a></div>', '<div><a href="/path/to/file.jpg">Hello World</a></div>', ), - 'no_strip_amp_tags' => array( + 'no_strip_amp_tags' => array( '<amp-img src="http://example.com/path/to/file.jpg" width="300" height="300"></amp-img>', ), - 'a_with_attachment_rel' => array( + 'a_with_attachment_rel' => array( '<a href="http://example.com" rel="wp-att-1686">Link</a>', ), - 'a_with_invalid_name' => array( + 'a_with_invalid_name' => array( '<a name=shadowRoot>Shadow Root!</a>', '<a>Shadow Root!</a>', ), @@ -839,66 +839,66 @@ function() { '<a href="http://example.com" rel="attachment wp-att-1686">Link</a>', ), - 'a_with_rev' => array( + 'a_with_rev' => array( '<a href="http://example.com" rev="footnote">Link</a>', ), - 'a_with_target_blank' => array( + 'a_with_target_blank' => array( '<a href="http://example.com" target="_blank">Link</a>', ), - 'a_with_target_uppercase_blank' => array( + 'a_with_target_uppercase_blank' => array( '<a href="http://example.com" target="_BLANK">Link</a>', '<a href="http://example.com">Link</a>', ), - 'a_with_target_new' => array( + 'a_with_target_new' => array( '<a href="http://example.com" target="_new">Link</a>', '<a href="http://example.com">Link</a>', ), - 'a_with_target_self' => array( + 'a_with_target_self' => array( '<a href="http://example.com" target="_self">Link</a>', ), - 'a_with_target_invalid' => array( + 'a_with_target_invalid' => array( '<a href="http://example.com" target="boom">Link</a>', '<a href="http://example.com">Link</a>', ), - 'a_with_href_invalid' => array( + 'a_with_href_invalid' => array( '<a href="some%20random%20text">Link</a>', ), - 'a_with_href_scheme_tel' => array( + 'a_with_href_scheme_tel' => array( '<a href="tel:4166669999">Call Me, Maybe</a>', ), - 'a_with_href_scheme_sms' => array( + 'a_with_href_scheme_sms' => array( '<a href="sms:4166669999">SMS Me, Maybe</a>', ), - 'a_with_href_scheme_mailto' => array( + 'a_with_href_scheme_mailto' => array( '<a href="mailto:email@example.com">Email Me, Maybe</a>', ), - 'a_with_href_relative' => array( + 'a_with_href_relative' => array( '<a href="/home">Home</a>', ), - 'a_with_anchor' => array( + 'a_with_anchor' => array( '<a href="#section2">Home</a>', ), - 'a_is_anchor' => array( + 'a_is_anchor' => array( '<a name="section2"></a>', ), - 'a_is_achor_with_id' => array( + 'a_is_achor_with_id' => array( '<a id="section3"></a>', ), - 'a_empty' => array( + 'a_empty' => array( '<a>Hello World</a>', ), @@ -907,85 +907,85 @@ function() { '<a><span>Red</span>&<span>Orange</span></a>', ), - 'spans_with_xml_namespaced_attributes' => array( + 'spans_with_xml_namespaced_attributes' => array( '<p><span lang="es" xml:lang="es">hola</span><span xml:space="preserve">mundo</span></p>', '<p><span lang="es">hola</span><span>mundo</span></p>', ), - 'h1_with_size' => array( + 'h1_with_size' => array( '<h1 size="1">Headline</h1>', '<h1>Headline</h1>', ), - 'font_tag' => array( + 'font_tag' => array( '<font size="1">Headline</font>', 'Headline', ), - 'span_with_custom_attr' => array( + 'span_with_custom_attr' => array( '<span class="foo" custom="not-allowed">value</span>', '<span class="foo">value</span>', ), - 'a_with_custom_protocol' => array( + 'a_with_custom_protocol' => array( '<a class="foo" href="custom:bad">value</a>', '<a class="foo" href="">value</a>', ), - 'a_with_wrong_host' => array( + 'a_with_wrong_host' => array( '<a class="foo" href="http://foo bar">value</a>', '<a class="foo" href="">value</a>', ), - 'a_with_encoded_host' => array( + 'a_with_encoded_host' => array( '<a class="foo" href="http://%65%78%61%6d%70%6c%65%2e%63%6f%6d/foo/">value</a>', null, ), - 'a_with_wrong_schemeless_host' => array( + 'a_with_wrong_schemeless_host' => array( '<a class="foo" href="//bad domain with a space.com/foo">value</a>', '<a class="foo" href="">value</a>', ), - 'a_with_mail_host' => array( + 'a_with_mail_host' => array( '<a class="foo" href="mail to:foo@bar.com">value</a>', '<a class="foo" href="">value</a>', ), // font is removed so we should check that other elements are checked as well. - 'font_with_other_bad_elements' => array( + 'font_with_other_bad_elements' => array( '<font size="1">Headline</font><span style="color: blue !important">Span</span>', 'Headline<span>Span</span>', ), - 'amp_bind_attr' => array( + 'amp_bind_attr' => array( '<p [text]="\'Hello \' + foo">Hello World</p><button on="tap:AMP.setState({foo: \'amp-bind\'})">Update</button>', null, // No change. array( 'amp-bind' ), ), - 'amp_bind_with_greater_than_symbol' => array( + 'amp_bind_with_greater_than_symbol' => array( '<div class="home page-template-default page page-id-7 logged-in wp-custom-logo group-blog" [class]="minnow.bodyClasses.concat( minnow.navMenuExpanded ? \'sidebar-open\' : \'\' ).filter( className => \'\' != className )">hello</div>', '<div class="home page-template-default page page-id-7 logged-in wp-custom-logo group-blog" [class]="minnow.bodyClasses.concat( minnow.navMenuExpanded ? \'sidebar-open\' : \'\' ).filter( className => \'\' != className )">hello</div>', array( 'amp-bind' ), ), - 'amp_bad_bind_attr' => array( + 'amp_bad_bind_attr' => array( '<a [href]=\'/\' [hidden]>test</a><p [text]="\'Hello \' + name" [unrecognized] title="Foo"><button [disabled]="" [type]=\'\'>Hello World</button></p>', '<a [href]="/" [hidden]>test</a><p [text]="\'Hello \' + name" title="Foo"><button [disabled]="" [type]="">Hello World</button></p>', array( 'amp-bind' ), ), - 'amp-state' => array( + 'amp-state' => array( '<amp-state id="someNumber"><script type="application/json">4</script></amp-state>', null, array( 'amp-bind' ), ), - 'amp-state-bad' => array( + 'amp-state-bad' => array( '<amp-state id="someNumber"><i>bad</i><script type="application/json">4</script></amp-state>', '', array(), ), - 'amp-state-src' => array( + 'amp-state-src' => array( '<amp-state id="myRemoteState" src="https://data.com/articles.json"></amp-state>', null, array( 'amp-bind' ), @@ -1037,37 +1037,37 @@ function() { array( 'amp-selector', 'amp-form', 'amp-carousel' ), ), - 'amp_live_list_sort' => array( + 'amp_live_list_sort' => array( '<amp-live-list sort="ascending" data-poll-interval="15000" data-max-items-per-page="5" id="amp-live-list-insert-blog"><button update on="tap:amp-live-list-insert-blog.update" class="ampstart-btn ml1 caps">You have updates</button><div items><div id="A green landscape with trees." data-sort-time="20180317225019">Hello</div></div></amp-live-list>', null, // No change. array( 'amp-live-list' ), ), - 'amp_consent' => array( + 'amp_consent' => array( '<amp-consent media="all" noloading></amp-consent>', null, // No change. array( 'amp-consent' ), ), - 'amp_date_picker' => array( + 'amp_date_picker' => array( '<amp-date-picker id="simple-date-picker" type="single" mode="overlay" layout="container" on="select:AMP.setState({date1: event.date, dateType1: event.id})" format="Y-MM-DD" open-after-select input-selector="[name=date1]" class="mr1 ml1 flex picker"><div class="ampstart-input inline-block mt1"><input class="border-none p0" name="date1" placeholder="Pick a date"></div><button class="ampstart-btn m1 caps" on="tap: simple-date-picker.clear">Clear</button></amp-date-picker>', null, // No change. array( 'amp-date-picker' ), ), - 'amp_date_picker_range' => array( + 'amp_date_picker_range' => array( '<amp-date-picker type="range" minimum-nights="2" maximum-nights="4" mode="overlay" id="range-date-picker" on=" select: AMP.setState({ dates: event.dates, startDate: event.start, endDate: event.end })" format="YYYY-MM-DD" open-after-select min="2017-10-26" start-input-selector="#range-start" end-input-selector="#range-end" class="example-picker space-between"><div class="ampstart-input"><input class="border-none p0" id="range-start" placeholder="Start date"></div><div class="ampstart-input"><input class="border-none p0" id="range-end" placeholder="End date"></div><button class="ampstart-btn caps" on="tap:range-date-picker.clear">Clear</button><template type="amp-mustache" info-template><span [text]="(startDate && endDate ? \'You picked \' + startDate.date + \' as start date and \' + endDate.date + \' as end date.\' : \'You will see your chosen dates here.\')"> You will see your chosen dates here.</span></template></amp-date-picker>', null, // No change. array( 'amp-date-picker', 'amp-bind', 'amp-mustache' ), ), - 'amp-delight-player' => array( + 'amp-delight-player' => array( '<amp-delight-player data-content-id="-987521" layout="responsive" width="400" height="300"></amp-delight-player>', null, // No change. array( 'amp-delight-player' ), ), - 'amp-img-layout-allowed' => array( + 'amp-img-layout-allowed' => array( implode( '', array( @@ -1084,43 +1084,43 @@ function() { array(), ), - 'amp-img-layout-illegal' => array( + 'amp-img-layout-illegal' => array( '<amp-img src="/img1.png" width="50" height="50" layout="container"></amp-img>', '<amp-img src="/img1.png" width="50" height="50"></amp-img>', array(), ), - 'amp-img-layout-unknown' => array( + 'amp-img-layout-unknown' => array( '<amp-img src="/img1.png" width="50" height="50" layout="bogus-value"></amp-img>', '<amp-img src="/img1.png" width="50" height="50"></amp-img>', array(), ), - 'non-layout-span-element-attrs' => array( + 'non-layout-span-element-attrs' => array( '<span id="test" width="1" height="1" heights="(min-width:500px) 200px, 80%" sizes="(min-width: 650px) 50vw, 100vw" layout="nodisplay" [height]="1" [width]="1">Test</span>', '<span id="test">Test</span>', array(), ), - 'non-layout-col-element-attrs' => array( + 'non-layout-col-element-attrs' => array( '<table><col class="foo" width="123" style="background:red !important;"><col class="bar" style="background:green !important;" width="12%"><col class="baz" style="background:blue !important;" width="2*"><tr><td>1</td><td>2</td><td>3</td></tr></table>', '<table><col class="foo"><col class="bar"><col class="baz"><tr><td>1</td><td>2</td><td>3</td></tr></table>', array(), ), - 'amp-geo' => array( + 'amp-geo' => array( '<amp-geo layout="nodisplay"><script type="application/json">{ "AmpBind": true, "ISOCountryGroups": { "nafta": [ "ca", "mx", "us", "unknown" ], "waldo": [ "unknown" ], "anz": [ "au", "nz" ] } }</script></amp-geo>', null, array( 'amp-geo' ), ), - 'amp-geo-bad-children' => array( + 'amp-geo-bad-children' => array( '<amp-geo layout="nodisplay"><div>bad</div><script type="application/json">{ "AmpBind": true, "ISOCountryGroups": { "nafta": [ "ca", "mx", "us", "unknown" ], "waldo": [ "unknown" ], "anz": [ "au", "nz" ] } }</script></amp-geo>', '', array(), ), - 'amp-addthis-valid' => array( + 'amp-addthis-valid' => array( ' <amp-addthis width="320" @@ -1133,7 +1133,7 @@ function() { array( 'amp-addthis' ), ), - 'amp-addthis-responsive-layout' => array( + 'amp-addthis-responsive-layout' => array( ' <amp-addthis width="320" @@ -1147,7 +1147,7 @@ function() { array( 'amp-addthis' ), ), - 'amp-addthis-custom-share-attributes' => array( + 'amp-addthis-custom-share-attributes' => array( ' <amp-addthis width="320" @@ -1164,7 +1164,7 @@ function() { array( 'amp-addthis' ), ), - 'amp-addthis-wordpress-mode' => array( + 'amp-addthis-wordpress-mode' => array( ' <!-- AddThis WordPress Mode --> <amp-addthis @@ -1193,7 +1193,7 @@ function() { array( 'amp-addthis' ), ), - 'amp-addthis-inline-using-widget-id' => array( + 'amp-addthis-inline-using-widget-id' => array( ' <amp-addthis width="320" @@ -1206,7 +1206,7 @@ function() { array( 'amp-addthis' ), ), - 'amp-addthis-inline-using-product-code' => array( + 'amp-addthis-inline-using-product-code' => array( ' <amp-addthis width="320" @@ -1219,7 +1219,7 @@ function() { array( 'amp-addthis' ), ), - 'amp-addthis-floating-using-product-code' => array( + 'amp-addthis-floating-using-product-code' => array( ' <amp-addthis width="320" @@ -1233,73 +1233,73 @@ function() { array( 'amp-addthis' ), ), - 'amp-addthis-with-invalid-attribute' => array( + 'amp-addthis-with-invalid-attribute' => array( '<amp-addthis width="320" height="240" data-pub-id="ra-5adf5f2869f63c7c" data-product-code="shin" data-share-url="mailto:foo@example.com"></amp-addthis>', '<amp-addthis width="320" height="240" data-pub-id="ra-5adf5f2869f63c7c" data-product-code="shin" data-share-url=""></amp-addthis>', array( 'amp-addthis' ), ), - 'amp-3d-gltf' => array( + 'amp-3d-gltf' => array( '<amp-3d-gltf layout="responsive" width="320" height="240" alpha="true" antialiasing="true" src="path/to/model.glb"></amp-3d-gltf>', null, array( 'amp-3d-gltf' ), ), - 'amp-date-countdown' => array( + 'amp-date-countdown' => array( '<amp-date-countdown timestamp-seconds="2147483648" layout="fixed-height" height="50"><template type="amp-mustache"><p class="p1"> {{d}} days, {{h}} hours, {{m}} minutes and {{s}} seconds until <a href="https://en.wikipedia.org/wiki/Year_2038_problem">Y2K38</a>.</p></template></amp-date-countdown>', null, array( 'amp-date-countdown', 'amp-mustache' ), ), - 'amp-google-document-embed' => array( + 'amp-google-document-embed' => array( '<amp-google-document-embed src="https://www.example.com/document.pdf" width="800" height="600" layout="responsive"></amp-google-document-embed>', null, array( 'amp-google-document-embed' ), ), - 'amp-orientation-observer' => array( + 'amp-orientation-observer' => array( '<amp-orientation-observer on="beta:clockAnim1.seekTo(percent=event.percent)" layout="nodisplay"></amp-orientation-observer>', null, array( 'amp-orientation-observer' ), ), - 'amp-pan-zoom' => array( + 'amp-pan-zoom' => array( '<amp-layout layout="responsive" width="4" height="3"><amp-pan-zoom layout="fill" disable-double-tap><svg focusable="false"> ... </svg></amp-pan-zoom></amp-layout>', null, array( 'amp-pan-zoom' ), ), - 'amp-yotpo' => array( + 'amp-yotpo' => array( '<amp-yotpo width="550" height="700" layout="responsive" data-app-key="liSBkl621ZZsb88tsckAs6Bzx6jQeTJTv8CDf8y5" data-widget-type="MainWidget" data-product-id="9408616206" data-name="hockey skates" data-url="https://ranabram.myshopify.com/products/hockey-skates" data-image-url="https://ichef.bbci.co.uk/news/320/media/images/83351000/jpg/_83351965_explorer273lincolnshirewoldssouthpicturebynicholassilkstone.jpg" data-descriptipn="skates" data-yotpo-element-id="1"></amp-yotpo>', null, array( 'amp-yotpo' ), ), - 'amp-embedly' => array( + 'amp-embedly' => array( '<amp-embedly-key value="12af2e3543ee432ca35ac30a4b4f656a" layout="nodisplay"></amp-embedly-key><amp-embedly-card data-url="https://twitter.com/AMPhtml/status/986750295077040128" layout="responsive" width="150" height="80" data-card-theme="dark" data-card-controls="0"></amp-embedly-card>', null, array( 'amp-embedly-card' ), ), - 'amp-lightbox' => array( + 'amp-lightbox' => array( '<amp-lightbox id="my-lightbox" [open]="true" animate-in="fly-in-top" layout="nodisplay"><div class="lightbox" on="tap:my-lightbox.close" role="button" tabindex="0"><h1>Hello World!</h1></div></amp-lightbox>', null, array( 'amp-lightbox', 'amp-bind' ), ), - 'amp-form-messages' => array( + 'amp-form-messages' => array( '<form action-xhr="https://example.com/" method="post"><fieldset><input type="text" name="do-not-verify" no-verify><input type="text" name="firstName"></fieldset><div verify-error=""><template type="amp-mustache">There is a mistake in the form!{{#verifyErrors}}{{message}}{{/verifyErrors}}</template></div><div submitting=""><template type="amp-mustache">Form submitting... Thank you for waiting {{name}}.</template></div><div submit-success=""><template type="amp-mustache">Success! Thanks {{name}} for subscribing! Please make sure to check your email {{email}}to confirm! After that we\'ll start sending you weekly articles on {{#interests}}<b>{{name}}</b> {{/interests}}.</template></div><div submit-error><template type="amp-mustache">Oops! {{name}}, {{message}}.</template></div></form>', null, array( 'amp-form', 'amp-mustache' ), ), - 'amp-input-mask' => array( + 'amp-input-mask' => array( '<form method="post" class="p2" action-xhr="/components/amp-inputmask/postal" target="_top"><label>Postal code: <input name="code" mask="L0L_0L0" mask-trim-zeros="3" placeholder="A1A 1A1"></label><input type="submit"><div submit-success><template type="amp-mustache"><p>You submitted: {{code}}</p></template></div></form>', null, array( 'amp-form', 'amp-inputmask', 'amp-mustache' ), ), - 'amp_textarea_without_autoexpand' => array( + 'amp_textarea_without_autoexpand' => array( '<textarea name="without-autoexpand"></textarea>', null, array(), @@ -1311,43 +1311,43 @@ function() { array( 'amp-form', 'amp-bind' ), ), - 'amp-viqeo-player' => array( + 'amp-viqeo-player' => array( '<amp-viqeo-player data-profileid="184" data-videoid="b51b70cdbb06248f4438" width="640" height="360" layout="responsive"></amp-viqeo-player>', null, array( 'amp-viqeo-player' ), ), - 'amp-image-slider' => array( + 'amp-image-slider' => array( '<amp-image-slider layout="responsive" width="100" height="200"><span>Not allowed</span><amp-img src="/green-apple.jpg" alt="A green apple"></amp-img><i>forbidden</i><amp-img src="/red-apple.jpg" alt="A red apple"></amp-img><div first>This apple is green</div><strong>not allowed</strong><div second>This apple is red</div><i>not</i> <span>ok</span></amp-image-slider>', '<amp-image-slider layout="responsive" width="100" height="200"><amp-img src="/green-apple.jpg" alt="A green apple"></amp-img><amp-img src="/red-apple.jpg" alt="A red apple"></amp-img><div first>This apple is green</div><div second>This apple is red</div></amp-image-slider>', array( 'amp-image-slider' ), ), - 'amp-image-slider-bad-children' => array( + 'amp-image-slider-bad-children' => array( '<amp-image-slider layout="responsive" width="100" height="200"><amp-img src="/green-apple.jpg" alt="A green apple"></amp-img></amp-image-slider>', '', array(), ), - 'amp-fx-collection' => array( + 'amp-fx-collection' => array( '<h1 amp-fx="parallax" data-parallax-factor="1.5">A title that moves faster than other content.</h1>', null, array( 'amp-fx-collection' ), ), - 'amp-date-display' => array( + 'amp-date-display' => array( '<amp-date-display datetime="2017-08-02T15:05:05.000" layout="fixed" width="360" height="20"><template type="amp-mustache"><div>{{dayName}} {{day}} {{monthName}} {{year}} {{hourTwoDigit}}:{{minuteTwoDigit}}:{{secondTwoDigit}}</div></template></amp-date-display>', null, array( 'amp-date-display', 'amp-mustache' ), ), - 'amp-list' => array( + 'amp-list' => array( '<amp-list credentials="include" src="https://example.com/json/product.json?clientId=CLIENT_ID(myCookieId)"><template type="amp-mustache">Your personal offer: ${{price}}</template></amp-list>', null, array( 'amp-list', 'amp-mustache' ), ), - 'amp-list-load-more' => array( + 'amp-list-load-more' => array( str_replace( array( "\n", "\t" ), '', @@ -1375,38 +1375,38 @@ function() { array( 'amp-list', 'amp-mustache' ), ), - 'amp-recaptcha-input' => array( + 'amp-recaptcha-input' => array( '<form action-xhr="/" target="_top" method="post"><amp-recaptcha-input layout="nodisplay" name="reCAPTCHA_body_key" data-sitekey="reCAPTCHA_site_key" data-action="reCAPTCHA_example_action"></amp-recaptcha-input></form>', null, array( 'amp-form', 'amp-recaptcha-input' ), ), // @todo The poster should not be allowed if there is a placeholder. - 'amp-video-iframe' => array( + 'amp-video-iframe' => array( '<amp-video-iframe src="https://example.com/video/" width="500" height="500" poster="https://example.com/poster.jpg" autoplay dock implements-media-session implements-rotate-to-fullscreen referrerpolicy></amp-video-iframe>', null, array( 'amp-video-iframe', 'amp-video-docking' ), ), - 'amp-youtube' => array( + 'amp-youtube' => array( '<amp-youtube id="myLiveChannel" data-live-channelid="UCB8Kb4pxYzsDsHxzBfnid4Q" width="358" height="204" layout="responsive" dock><amp-img src="https://i.ytimg.com/vi/Wm1fWz-7nLQ/hqdefault_live.jpg" placeholder layout="fill"></amp-img></amp-youtube>', null, array( 'amp-youtube', 'amp-video-docking' ), ), - 'details' => array( + 'details' => array( '<details open [open]="foo.state"><summary>Learn more</summary><p>You are educated</p></details>', null, array( 'amp-bind' ), ), - 'amp-plain-text-script-template' => array( + 'amp-plain-text-script-template' => array( '<script type="text/plain" template="amp-mustache">Hello {{world}}!</script>', null, array( 'amp-mustache' ), ), - 'amp-action-macro' => array( + 'amp-action-macro' => array( // @todo Should calling AMP.setState() automatically cause the amp-bind extension to be added? ' <amp-action-macro id="closeNavigations" execute="AMP.setState({nav1: \'close\', nav2: \'close})"></amp-action-macro> @@ -1417,18 +1417,18 @@ function() { array( 'amp-action-macro' ), ), - 'amp-smart-links' => array( + 'amp-smart-links' => array( '<amp-smartlinks layout="nodisplay" nrtv-account-name="examplepublisher" linkmate exclusive-links link-attribute="href" link-selector="a"></amp-smartlinks>', null, array( 'amp-smartlinks' ), ), - 'amp-script-1' => array( + 'amp-script-1' => array( '<amp-script layout="container" src="https://example.com/hello-world.js"><button id="hello">Insert Hello World!</button></amp-script>', null, array( 'amp-script' ), ), - 'amp-script-2' => array( + 'amp-script-2' => array( ' <amp-script layout="container" src="https://example.com/examples/amp-script/hello-world.js"> <div class="root"> @@ -1443,7 +1443,7 @@ function() { null, array( 'amp-script' ), ), - 'amp-script-3' => array( + 'amp-script-3' => array( ' <amp-script src="https://example.com/examples/amp-script/todomvc.ssr.js" layout="container"> <div><header class="header"><h1>todos</h1><input class="new-todo" placeholder="What needs to be done?" autofocus="true"></header></div> @@ -1453,7 +1453,7 @@ function() { array( 'amp-script' ), ), - 'amp-script-4' => array( + 'amp-script-4' => array( ' <amp-script layout="container" src="https://example.com/examples/amp-script/empty.js"> <div class="root">should be empty</div> @@ -1463,26 +1463,26 @@ function() { array( 'amp-script' ), ), - 'amp_img_with_object_fit_position' => array( + 'amp_img_with_object_fit_position' => array( '<amp-img src="http://placehold.it/400x500" width="300" height="300" object-fit="none" object-position="right top" layout="intrinsic"></amp-img>', null, array(), ), - 'amp_link_rewriter' => array( + 'amp_link_rewriter' => array( '<amp-link-rewriter layout="nodisplay"><script type="application/json">{}</script></amp-link-rewriter>', null, array( 'amp-link-rewriter' ), ), - 'unique_constraint' => array( + 'unique_constraint' => array( str_repeat( '<amp-geo layout="nodisplay"><script type="application/json">{}</script></amp-geo>', 2 ), '<amp-geo layout="nodisplay"><script type="application/json">{}</script></amp-geo>', array( 'amp-geo' ), array( 'duplicate_element' ), ), - 'amp-autocomplete' => array( + 'amp-autocomplete' => array( ' <form method="post" action-xhr="/form/echo-json/post" target="_blank" on="submit-success:AMP.setState({result: event.response})"> <amp-autocomplete id="autocomplete" filter="substring" min-characters="0"> @@ -1497,13 +1497,13 @@ function() { array( 'amp-form', 'amp-autocomplete' ), ), - 'amp-connatix-player' => array( + 'amp-connatix-player' => array( '<amp-connatix-player data-player-id="03ef71d8-0941-4bff-94f2-74ca3580b497" layout="responsive" width="16" height="9"></amp-connatix-player>', null, array( 'amp-connatix-player' ), ), - 'amp-truncate-text' => array( + 'amp-truncate-text' => array( ' <amp-truncate-text layout="fixed" height="3em" width="20em"> Some text that may get truncated. @@ -1515,7 +1515,7 @@ function() { array( 'amp-truncate-text' ), ), - 'amp-user-location' => array( + 'amp-user-location' => array( ' <button on="tap: location.request()">Use my location</button> <amp-user-location id="location" on="approve:AMP.setState({located: true})" layout="nodisplay"> diff --git a/tests/validation/test-class-amp-validated-url-post-type.php b/tests/php/validation/test-class-amp-validated-url-post-type.php similarity index 100% rename from tests/validation/test-class-amp-validated-url-post-type.php rename to tests/php/validation/test-class-amp-validated-url-post-type.php diff --git a/tests/validation/test-class-amp-validation-error-taxonomy.php b/tests/php/validation/test-class-amp-validation-error-taxonomy.php similarity index 100% rename from tests/validation/test-class-amp-validation-error-taxonomy.php rename to tests/php/validation/test-class-amp-validation-error-taxonomy.php diff --git a/tests/validation/test-class-amp-validation-manager.php b/tests/php/validation/test-class-amp-validation-manager.php similarity index 100% rename from tests/validation/test-class-amp-validation-manager.php rename to tests/php/validation/test-class-amp-validation-manager.php From ad2b40875431eb42d84cf037593154196bd12ad6 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Tue, 2 Jul 2019 15:02:28 +0200 Subject: [PATCH 090/434] Increase specificity of [data-block] selector Needed after upstream change in https://github.com/WordPress/gutenberg/pull/16207. --- assets/src/stories-editor/blocks/amp-story-page/edit.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/src/stories-editor/blocks/amp-story-page/edit.css b/assets/src/stories-editor/blocks/amp-story-page/edit.css index 7a59b839928..123b24404d3 100644 --- a/assets/src/stories-editor/blocks/amp-story-page/edit.css +++ b/assets/src/stories-editor/blocks/amp-story-page/edit.css @@ -94,7 +94,7 @@ height: 553px; } -[data-block] { +.editor-styles-wrapper [data-block] { margin-top: 0; margin-bottom: 0; } From 23121d05d4c7f03ab4bc8982af53c602a3de2e45 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Tue, 2 Jul 2019 15:26:58 +0200 Subject: [PATCH 091/434] Make image placeholders draggable --- .../components/higher-order/with-amp-story-settings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/src/stories-editor/components/higher-order/with-amp-story-settings.js b/assets/src/stories-editor/components/higher-order/with-amp-story-settings.js index 8331a48092f..80c56d9c363 100644 --- a/assets/src/stories-editor/components/higher-order/with-amp-story-settings.js +++ b/assets/src/stories-editor/components/higher-order/with-amp-story-settings.js @@ -271,7 +271,7 @@ export default createHigherOrderComponent( return ( <> - { ( ! isMovableBlock || isEmptyImageBlock ) && ( <BlockEdit { ...props } /> ) } + { ( ! isMovableBlock ) && ( <BlockEdit { ...props } /> ) } { isMovableBlock && ! isEmptyImageBlock && needsResizing && ( <ResizableBox isSelected={ isSelected } @@ -318,7 +318,7 @@ export default createHigherOrderComponent( </RotatableBox> </ResizableBox> ) } - { isMovableBlock && ! needsResizing && ( + { isMovableBlock && ( ! needsResizing || isEmptyImageBlock ) && ( <RotatableBox blockElementId={ `block-${ clientId }` } initialAngle={ rotationAngle } From 8d05988cc0485f76e79fb9c669ec1af9eae93eb8 Mon Sep 17 00:00:00 2001 From: Weston Ruter <westonruter@google.com> Date: Tue, 2 Jul 2019 06:38:07 -0700 Subject: [PATCH 092/434] Exclude jest-puppeteer.config.js from build --- Gruntfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 02df5e65c0a..b15f34994a6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -88,7 +88,7 @@ module.exports = function( grunt ) { const versionAppend = new Date().toISOString().replace( /\.\d+/, '' ).replace( /-|:/g, '' ) + '-' + commitHash; const paths = lsOutput.trim().split( /\n/ ).filter( function( file ) { - return ! /^(blocks|\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|postcss\.config\.js|tests|wp-assets|readme\.md|composer\..*|patches|webpack.*|assets\/src|docker-compose\.yml|babel\.config\.js|codecov\.yml)/.test( file ); + return ! /^(blocks|\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|tests|wp-assets|readme\.md|composer\..*|patches|webpack.*|assets\/src|docker-compose\.yml|.*\.config\.js|codecov\.yml)/.test( file ); } ); paths.push( 'vendor/autoload.php' ); From 68941db7e145ed115ee91fe235481c12d681c552 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Wed, 3 Jul 2019 15:35:20 +0200 Subject: [PATCH 093/434] Try without completely removing KSES --- includes/class-amp-story-post-type.php | 39 +++++++++++++++++++++----- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/includes/class-amp-story-post-type.php b/includes/class-amp-story-post-type.php index 74dc61a0b56..d5441f03096 100644 --- a/includes/class-amp-story-post-type.php +++ b/includes/class-amp-story-post-type.php @@ -383,11 +383,10 @@ public static function filter_safe_style_css( $attr ) { /** * Filters the response before executing any REST API callbacks. * - * Temporarily removes KSES on post content for authors in order for them being able to use AMP Stories properly. + * Temporarily modifies post content during saving in a way that KSES + * does not strip actually valid CSS from post content, making block content invalid. * - * Otherwise KSES strips valid CSS from post content, making block content invalid. - * - * This is not ideal and should be removed once core has better CSS parsing. + * @todo Remove once core has better CSS parsing. * * @link https://core.trac.wordpress.org/ticket/37134 * @@ -414,9 +413,35 @@ public static function filter_rest_request_for_kses( $response, $handler, $reque return $response; } - remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); - remove_filter( 'excerpt_save_pre', 'wp_filter_post_kses' ); - remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' ); + $style_attr_values = []; + + // Replace inline styles before KSES... + add_filter( + 'pre_post_content', + static function ( $post_content ) use ( &$style_attr_values ) { + $post_content = preg_replace_callback( + '|style=\\\"([^"]*)\\\"|', // Because the post data is slashed. + static function ( $matches ) use ( &$style_attr_values ) { + $hash = md5( $matches[1] ); + $style_attr_values[ $hash ] = $matches[1]; + + return str_replace( $matches[1], $hash, $matches[0] ); + }, + $post_content + ); + + return $post_content; + } + ); + + // ...And bring it back afterwards. + add_filter( + 'content_save_pre', + static function ( $post_content ) use ( &$style_attr_values ) { + return str_replace( array_keys( $style_attr_values ), array_values( $style_attr_values ), $post_content ); + }, + 20 + ); return $response; } From 2e54b5ca00fecefca6d004afa3b9e3d618894029 Mon Sep 17 00:00:00 2001 From: Weston Ruter <westonruter@google.com> Date: Wed, 3 Jul 2019 17:06:25 -0700 Subject: [PATCH 094/434] Guard against infinite recursion when matching a theme source Fixes #2547 --- .../class-amp-validation-manager.php | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index dbb26d9f181..ac3f0565b3a 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -138,17 +138,35 @@ class AMP_Validation_Manager { /** * Cached template directory to prevent infinite recursion. * + * @see get_template_directory() * @var string */ protected static $template_directory; + /** + * Cached template slug to prevent infinite recursion. + * + * @see get_template() + * @var string + */ + protected static $template_slug; + /** * Cached stylesheet directory to prevent infinite recursion. * + * @see get_stylesheet_directory() * @var string */ protected static $stylesheet_directory; + /** + * Cached stylesheet slug to prevent infinite recursion. + * + * @see get_stylesheet() + * @var string + */ + protected static $stylesheet_slug; + /** * Add the actions. * @@ -506,8 +524,10 @@ public static function add_validation_error_sourcing() { } } - self::$template_directory = get_template_directory(); - self::$stylesheet_directory = get_stylesheet_directory(); + self::$template_directory = wp_normalize_path( get_template_directory() ); + self::$template_slug = get_template(); + self::$stylesheet_directory = wp_normalize_path( get_stylesheet_directory() ); + self::$stylesheet_slug = get_stylesheet(); add_action( 'wp', array( __CLASS__, 'wrap_widget_callbacks' ) ); @@ -1434,15 +1454,12 @@ public static function get_source( $callback ) { if ( preg_match( ':' . preg_quote( trailingslashit( wp_normalize_path( WP_PLUGIN_DIR ) ), ':' ) . $slug_pattern . ':s', $file, $matches ) ) { $source['type'] = 'plugin'; $source['name'] = $matches[1]; - } elseif ( preg_match( ':' . preg_quote( trailingslashit( wp_normalize_path( self::$template_directory ) ), ':' ) . ':s', $file ) ) { - $source['type'] = 'theme'; - $source['name'] = get_template(); - } elseif ( preg_match( ':' . preg_quote( trailingslashit( wp_normalize_path( self::$stylesheet_directory ) ), ':' ) . ':s', $file ) ) { + } elseif ( preg_match( ':' . preg_quote( trailingslashit( self::$template_directory ), ':' ) . $slug_pattern . ':s', $file ) ) { $source['type'] = 'theme'; - $source['name'] = get_stylesheet(); - } elseif ( preg_match( ':' . preg_quote( trailingslashit( wp_normalize_path( get_theme_root() ) ), ':' ) . $slug_pattern . ':s', $file, $matches ) ) { + $source['name'] = self::$template_slug; + } elseif ( preg_match( ':' . preg_quote( trailingslashit( self::$stylesheet_directory ), ':' ) . $slug_pattern . ':s', $file ) ) { $source['type'] = 'theme'; - $source['name'] = $matches[1]; + $source['name'] = self::$stylesheet_slug; } elseif ( preg_match( ':' . preg_quote( trailingslashit( wp_normalize_path( WPMU_PLUGIN_DIR ) ), ':' ) . $slug_pattern . ':s', $file, $matches ) ) { $source['type'] = 'mu-plugin'; $source['name'] = $matches[1]; From a46dc757c89f2a8cf1a21a437c90de30b6c167ba Mon Sep 17 00:00:00 2001 From: Weston Ruter <westonruter@google.com> Date: Wed, 3 Jul 2019 21:34:00 -0700 Subject: [PATCH 095/434] Preserve ability to access array callback parts after wrapping --- includes/class-amp-autoloader.php | 1 + .../class-amp-validation-callback-wrapper.php | 152 ++++++++++++++++++ .../class-amp-validation-manager.php | 58 +------ .../test-class-amp-validation-manager.php | 15 +- 4 files changed, 164 insertions(+), 62 deletions(-) create mode 100644 includes/validation/class-amp-validation-callback-wrapper.php diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php index dfabb4f8f16..f257d28f571 100644 --- a/includes/class-amp-autoloader.php +++ b/includes/class-amp-autoloader.php @@ -99,6 +99,7 @@ class AMP_Autoloader { 'AMP_HTML_Utils' => 'includes/utils/class-amp-html-utils', 'AMP_Image_Dimension_Extractor' => 'includes/utils/class-amp-image-dimension-extractor', 'AMP_Validation_Manager' => 'includes/validation/class-amp-validation-manager', + 'AMP_Validation_Callback_Wrapper' => 'includes/validation/class-amp-validation-callback-wrapper', 'AMP_Validated_URL_Post_Type' => 'includes/validation/class-amp-validated-url-post-type', 'AMP_Validation_Error_Taxonomy' => 'includes/validation/class-amp-validation-error-taxonomy', 'AMP_CLI' => 'includes/class-amp-cli', diff --git a/includes/validation/class-amp-validation-callback-wrapper.php b/includes/validation/class-amp-validation-callback-wrapper.php new file mode 100644 index 00000000000..86bfa6ec636 --- /dev/null +++ b/includes/validation/class-amp-validation-callback-wrapper.php @@ -0,0 +1,152 @@ +<?php +/** + * Class AMP_Validation_Callback_Wrapper + * + * @package AMP + */ + +/** + * Class AMP_Validation_Callback_Wrapper + * + * @since 1.2.1 + */ +class AMP_Validation_Callback_Wrapper implements ArrayAccess { + + /** + * Callback data. + * + * @var array + */ + protected $callback; + + /** + * AMP_Validation_Callback_Wrapper constructor. + * + * @param array $callback { + * The callback data. + * + * @type callable $function + * @type int $accepted_args + * @type array $source + * } + */ + public function __construct( $callback ) { + $this->callback = $callback; + } + + /** + * Invoke wrapped callback. + * + * @return mixed + */ + public function __invoke() { + global $wp_styles, $wp_scripts; + + $function = $this->callback['function']; + $accepted_args = $this->callback['accepted_args']; + $args = func_get_args(); + + $before_styles_enqueued = array(); + if ( isset( $wp_styles ) && isset( $wp_styles->queue ) ) { + $before_styles_enqueued = $wp_styles->queue; + } + $before_scripts_enqueued = array(); + if ( isset( $wp_scripts ) && isset( $wp_scripts->queue ) ) { + $before_scripts_enqueued = $wp_scripts->queue; + } + + $is_filter = isset( $callback['source']['hook'] ) && ! did_action( $this->callback['source']['hook'] ); + + // Wrap the markup output of (action) hooks in source comments. + AMP_Validation_Manager::$hook_source_stack[] = $this->callback['source']; + $has_buffer_started = false; + if ( ! $is_filter && AMP_Validation_Manager::can_output_buffer() ) { + $has_buffer_started = ob_start( array( 'AMP_Validation_Manager', 'wrap_buffer_with_source_comments' ) ); + } + $result = call_user_func_array( $function, array_slice( $args, 0, intval( $accepted_args ) ) ); + if ( $has_buffer_started ) { + ob_end_flush(); + } + array_pop( AMP_Validation_Manager::$hook_source_stack ); + + // Keep track of which source enqueued the styles. + if ( isset( $wp_styles ) && isset( $wp_styles->queue ) ) { + foreach ( array_diff( $wp_styles->queue, $before_styles_enqueued ) as $handle ) { + AMP_Validation_Manager::$enqueued_style_sources[ $handle ][] = array_merge( $this->callback['source'], compact( 'handle' ) ); + } + } + + // Keep track of which source enqueued the scripts, and immediately report validity. + if ( isset( $wp_scripts ) && isset( $wp_scripts->queue ) ) { + foreach ( array_diff( $wp_scripts->queue, $before_scripts_enqueued ) as $queued_handle ) { + $handles = array( $queued_handle ); + + // Account for case where registered script is a placeholder for a set of scripts (e.g. jquery). + if ( isset( $wp_scripts->registered[ $queued_handle ] ) && false === $wp_scripts->registered[ $queued_handle ]->src ) { + $handles = array_merge( $handles, $wp_scripts->registered[ $queued_handle ]->deps ); + } + + foreach ( $handles as $handle ) { + AMP_Validation_Manager::$enqueued_script_sources[ $handle ][] = array_merge( $this->callback['source'], compact( 'handle' ) ); + } + } + } + + return $result; + } + + /** + * Offset set. + * + * @param mixed $offset Offset. + * @param mixed $value Value. + */ + public function offsetSet( $offset, $value ) { + if ( ! is_array( $this->callback['function'] ) ) { + return; + } + if ( is_null( $offset ) ) { + $this->callback['function'][] = $value; + } else { + $this->callback['function'][ $offset ] = $value; + } + } + + /** + * Offset exists. + * + * @param mixed $offset Offset. + * @return bool Exists. + */ + public function offsetExists( $offset ) { + if ( ! is_array( $this->callback['function'] ) ) { + return false; + } + return isset( $this->callback['function'][ $offset ] ); + } + + /** + * Offset unset. + * + * @param mixed $offset Offset. + */ + public function offsetUnset( $offset ) { + if ( ! is_array( $this->callback['function'] ) ) { + return; + } + unset( $this->callback['function'][ $offset ] ); + } + + /** + * Offset get. + * + * @param mixed $offset Offset. + * @return mixed|null Value. + */ + public function offsetGet( $offset ) { + if ( is_array( $this->callback['function'] ) && isset( $this->callback['function'][ $offset ] ) ) { + return $this->callback['function'][ $offset ]; + } + return null; + } +} diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index ac3f0565b3a..7a8c09bfa1b 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -1531,64 +1531,10 @@ public static function can_output_buffer() { * @type int $accepted_args * @type array $source * } - * @return closure $wrapped_callback The callback, wrapped in comments. + * @return AMP_Validation_Callback_Wrapper $wrapped_callback The callback, wrapped in comments. */ public static function wrapped_callback( $callback ) { - return function() use ( $callback ) { - global $wp_styles, $wp_scripts; - - $function = $callback['function']; - $accepted_args = $callback['accepted_args']; - $args = func_get_args(); - - $before_styles_enqueued = array(); - if ( isset( $wp_styles ) && isset( $wp_styles->queue ) ) { - $before_styles_enqueued = $wp_styles->queue; - } - $before_scripts_enqueued = array(); - if ( isset( $wp_scripts ) && isset( $wp_scripts->queue ) ) { - $before_scripts_enqueued = $wp_scripts->queue; - } - - $is_filter = isset( $callback['source']['hook'] ) && ! did_action( $callback['source']['hook'] ); - - // Wrap the markup output of (action) hooks in source comments. - AMP_Validation_Manager::$hook_source_stack[] = $callback['source']; - $has_buffer_started = false; - if ( ! $is_filter && AMP_Validation_Manager::can_output_buffer() ) { - $has_buffer_started = ob_start( array( __CLASS__, 'wrap_buffer_with_source_comments' ) ); - } - $result = call_user_func_array( $function, array_slice( $args, 0, intval( $accepted_args ) ) ); - if ( $has_buffer_started ) { - ob_end_flush(); - } - array_pop( AMP_Validation_Manager::$hook_source_stack ); - - // Keep track of which source enqueued the styles. - if ( isset( $wp_styles ) && isset( $wp_styles->queue ) ) { - foreach ( array_diff( $wp_styles->queue, $before_styles_enqueued ) as $handle ) { - AMP_Validation_Manager::$enqueued_style_sources[ $handle ][] = array_merge( $callback['source'], compact( 'handle' ) ); - } - } - - // Keep track of which source enqueued the scripts, and immediately report validity. - if ( isset( $wp_scripts ) && isset( $wp_scripts->queue ) ) { - foreach ( array_diff( $wp_scripts->queue, $before_scripts_enqueued ) as $queued_handle ) { - $handles = array( $queued_handle ); - - // Account for case where registered script is a placeholder for a set of scripts (e.g. jquery). - if ( isset( $wp_scripts->registered[ $queued_handle ] ) && false === $wp_scripts->registered[ $queued_handle ]->src ) { - $handles = array_merge( $handles, $wp_scripts->registered[ $queued_handle ]->deps ); - } - - foreach ( $handles as $handle ) { - AMP_Validation_Manager::$enqueued_script_sources[ $handle ][] = array_merge( $callback['source'], compact( 'handle' ) ); - } - } - } - - return $result; - }; + return new AMP_Validation_Callback_Wrapper( $callback ); } /** diff --git a/tests/php/validation/test-class-amp-validation-manager.php b/tests/php/validation/test-class-amp-validation-manager.php index d601e52bf9f..34b24d4bfcf 100644 --- a/tests/php/validation/test-class-amp-validation-manager.php +++ b/tests/php/validation/test-class-amp-validation-manager.php @@ -895,9 +895,12 @@ public function test_wrap_widget_callbacks() { $this->assertArrayHasKey( $widget_id, $wp_registered_widgets ); $this->assertInternalType( 'array', $wp_registered_widgets[ $widget_id ]['callback'] ); $this->assertInstanceOf( 'WP_Widget_Search', $wp_registered_widgets[ $widget_id ]['callback'][0] ); + $this->assertSame( 'display_callback', $wp_registered_widgets[ $widget_id ]['callback'][1] ); AMP_Validation_Manager::wrap_widget_callbacks(); - $this->assertInstanceOf( 'Closure', $wp_registered_widgets[ $widget_id ]['callback'] ); + $this->assertInstanceOf( 'AMP_Validation_Callback_Wrapper', $wp_registered_widgets[ $widget_id ]['callback'] ); + $this->assertInstanceOf( 'WP_Widget', $wp_registered_widgets[ $widget_id ]['callback'][0] ); + $this->assertSame( 'display_callback', $wp_registered_widgets[ $widget_id ]['callback'][1] ); $sidebar_id = 'amp-sidebar'; register_sidebar( @@ -1150,7 +1153,7 @@ public function test_filter_wrapped_callback() { $value = 'Some Value'; apply_filters( 'foo', $value ); $wrapped_callback = AMP_Validation_Manager::wrapped_callback( $filter_callback ); - $this->assertTrue( $wrapped_callback instanceof Closure ); + $this->assertTrue( $wrapped_callback instanceof AMP_Validation_Callback_Wrapper ); AMP_Theme_Support::start_output_buffering(); $filtered_value = call_user_func( $wrapped_callback, $value ); $output = ob_get_clean(); @@ -1179,12 +1182,12 @@ public function test_action_wrapped_callback() { do_action( 'bar' ); // So that output buffering will be done. $wrapped_callback = AMP_Validation_Manager::wrapped_callback( $action_callback ); - $this->assertTrue( $wrapped_callback instanceof Closure ); + $this->assertTrue( $wrapped_callback instanceof AMP_Validation_Callback_Wrapper ); AMP_Theme_Support::start_output_buffering(); call_user_func( $wrapped_callback ); $output = ob_get_clean(); - $this->assertEquals( 'Closure', get_class( $wrapped_callback ) ); + $this->assertEquals( 'AMP_Validation_Callback_Wrapper', get_class( $wrapped_callback ) ); $this->assertContains( $test_string, $output ); $this->assertContains( '<!--amp-source-stack {"type":"plugin","name":"amp","hook":"bar"}', $output ); $this->assertContains( '<!--/amp-source-stack {"type":"plugin","name":"amp","hook":"bar"}', $output ); @@ -1200,11 +1203,11 @@ public function test_action_wrapped_callback() { ); $wrapped_callback = AMP_Validation_Manager::wrapped_callback( $action_callback ); - $this->assertTrue( $wrapped_callback instanceof Closure ); + $this->assertTrue( $wrapped_callback instanceof AMP_Validation_Callback_Wrapper ); AMP_Theme_Support::start_output_buffering(); $result = call_user_func( $wrapped_callback ); $output = ob_get_clean(); - $this->assertEquals( 'Closure', get_class( $wrapped_callback ) ); + $this->assertEquals( 'AMP_Validation_Callback_Wrapper', get_class( $wrapped_callback ) ); $this->assertEquals( '', $output ); $this->assertEquals( call_user_func( array( $this, 'get_string' ) ), $result ); unset( $post ); From 9e7346eea96af19f83a986824126a4791580f093 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:35:23 +0200 Subject: [PATCH 096/434] Simplify isset() statements --- includes/embeds/class-amp-playlist-embed-handler.php | 2 +- includes/validation/class-amp-validated-url-post-type.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/embeds/class-amp-playlist-embed-handler.php b/includes/embeds/class-amp-playlist-embed-handler.php index 15f12961c22..7e30b9db5d2 100644 --- a/includes/embeds/class-amp-playlist-embed-handler.php +++ b/includes/embeds/class-amp-playlist-embed-handler.php @@ -201,7 +201,7 @@ public function audio_playlist( $data ) { */ public function video_playlist( $data ) { global $content_width; - if ( ! isset( $data['tracks'], $data['tracks'][0]['src'] ) ) { + if ( ! isset( $data['tracks'][0]['src'] ) ) { return ''; } self::$playlist_id++; diff --git a/includes/validation/class-amp-validated-url-post-type.php b/includes/validation/class-amp-validated-url-post-type.php index f59c37c5b2a..42aff2ede25 100644 --- a/includes/validation/class-amp-validated-url-post-type.php +++ b/includes/validation/class-amp-validated-url-post-type.php @@ -664,7 +664,7 @@ public static function store_validation_errors( $validation_errors, $url, $args } $is_story = ( - isset( $args['queried_object'], $args['queried_object']['type'], $args['queried_object']['id'] ) + isset( $args['queried_object']['type'], $args['queried_object']['id'] ) && 'post' === $args['queried_object']['type'] && From 48d955b7d9adcf2ff7155346a93ba7fdb1bdfd0e Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:35:33 +0200 Subject: [PATCH 097/434] Remove unnecessary unset --- includes/validation/class-amp-validation-manager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index dbb26d9f181..a9df83cccbd 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -678,7 +678,6 @@ public static function add_rest_api_fields() { * @return array|null $validation_data Validation data if it's available, or null. */ public static function get_amp_validity_rest_field( $post_data, $field_name, $request ) { - unset( $field_name ); if ( ! current_user_can( 'edit_post', $post_data['id'] ) || ! self::has_cap() || ! self::post_supports_validation( $post_data['id'] ) ) { return null; } From 28add71829e2753370ccbd7f5634eea40b849aba Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:35:44 +0200 Subject: [PATCH 098/434] Remove unnecessary default values for class properties --- includes/admin/class-amp-admin-pointer.php | 4 ++-- includes/class-amp-theme-support.php | 4 ++-- includes/templates/class-amp-content.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/admin/class-amp-admin-pointer.php b/includes/admin/class-amp-admin-pointer.php index 53476811bfc..5087ac178ee 100644 --- a/includes/admin/class-amp-admin-pointer.php +++ b/includes/admin/class-amp-admin-pointer.php @@ -27,7 +27,7 @@ class AMP_Admin_Pointer { * @since 1.2 * @var array */ - private $args = array(); + private $args; /** * Internal storage for dismissed pointers, to prevent repeated parsing. @@ -36,7 +36,7 @@ class AMP_Admin_Pointer { * @static * @var array|null */ - private static $dismissed_pointers = null; + private static $dismissed_pointers; /** * Constructor. diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 1f6e817c369..415d1cd6197 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -149,7 +149,7 @@ class AMP_Theme_Support { * @since 1.0 * @var null|string */ - protected static $support_added_via_option = null; + protected static $support_added_via_option; /** * Theme support mode which was added via the theme. @@ -158,7 +158,7 @@ class AMP_Theme_Support { * * @var null|string */ - protected static $support_added_via_theme = null; + protected static $support_added_via_theme; /** * Initialize. diff --git a/includes/templates/class-amp-content.php b/includes/templates/class-amp-content.php index 58cf325dddf..b8a8ff68662 100644 --- a/includes/templates/class-amp-content.php +++ b/includes/templates/class-amp-content.php @@ -44,21 +44,21 @@ class AMP_Content { * * @var array */ - private $args = array(); + private $args; /** * Embed handlers. * * @var AMP_Base_Embed_Handler[] AMP_Base_Embed_Handler[] */ - private $embed_handlers = array(); + private $embed_handlers; /** * Sanitizer class names. * * @var string[] */ - private $sanitizer_classes = array(); + private $sanitizer_classes; /** * AMP_Content constructor. From 4f2403891d1360b69fd02b9bf5778d591c1f3a5f Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:37:11 +0200 Subject: [PATCH 099/434] Remove unused variable usage --- includes/sanitizers/class-amp-style-sanitizer.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 0aabf525d0d..66b38f88cf7 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -2406,17 +2406,10 @@ private function finalize_styles() { // Divide pending stylesheet between custom and keyframes, and calculate size of each (before tree shaking). foreach ( $this->pending_stylesheets as $i => $pending_stylesheet ) { - $size = 0; foreach ( $pending_stylesheet['stylesheet'] as $j => $part ) { - if ( is_string( $part ) ) { - $size += strlen( $part ); - if ( '@import' === substr( $part, 0, 7 ) ) { - $stylesheet_groups[ $pending_stylesheet['group'] ]['import_front_matter'] .= $part; - unset( $this->pending_stylesheets['stylesheet'][ $j ][ $i ] ); - } - } elseif ( is_array( $part ) ) { - $size += strlen( implode( ',', array_keys( $part[0] ) ) ); // Selectors. - $size += strlen( $part[1] ); // Declaration block. + if ( is_string( $part ) && 0 === strpos( $part, '@import' ) ) { + $stylesheet_groups[ $pending_stylesheet['group'] ]['import_front_matter'] .= $part; + unset( $this->pending_stylesheets['stylesheet'][ $j ][ $i ] ); } } From e6fba65d1cfe35ed6a02bead55cba670d8e8cbd1 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:38:15 +0200 Subject: [PATCH 100/434] Use type casts instead of intval --- includes/validation/class-amp-validation-manager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index a9df83cccbd..a3b07cc417b 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -500,7 +500,7 @@ public static function add_validation_error_sourcing() { */ foreach ( $_REQUEST[ self::VALIDATION_ERROR_TERM_STATUS_QUERY_VAR ] as $slug => $status ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $slug = sanitize_key( $slug ); - $status = intval( $status ); + $status = (int) $status; self::$validation_error_status_overrides[ $slug ] = $status; ksort( self::$validation_error_status_overrides ); } @@ -609,7 +609,7 @@ function( $post ) { if ( is_wp_error( $validity ) ) { $validation_posts[ $post->ID ] = $validity; } else { - $invalid_url_post_id = intval( get_post_meta( $post->ID, '_amp_validated_url_post_id', true ) ); + $invalid_url_post_id = (int) get_post_meta( $post->ID, '_amp_validated_url_post_id', true ); $validation_posts[ $post->ID ] = AMP_Validated_URL_Post_Type::store_validation_errors( wp_list_pluck( $validity['results'], 'error' ), @@ -919,7 +919,7 @@ public static function print_edit_form_validation_status( $post ) { printf( '<p>%s ', esc_html( $removed_set['label'] ) ); $items = array(); foreach ( $removed_set['names'] as $name => $count ) { - if ( 1 === intval( $count ) ) { + if ( 1 === (int) $count ) { $items[] = sprintf( '<code>%s</code>', esc_html( $name ) ); } else { $items[] = sprintf( '<code>%s</code> (%d)', esc_html( $name ), $count ); @@ -1540,7 +1540,7 @@ public static function wrapped_callback( $callback ) { if ( ! $is_filter && AMP_Validation_Manager::can_output_buffer() ) { $has_buffer_started = ob_start( array( __CLASS__, 'wrap_buffer_with_source_comments' ) ); } - $result = call_user_func_array( $function, array_slice( $args, 0, intval( $accepted_args ) ) ); + $result = call_user_func_array( $function, array_slice( $args, 0, (int) $accepted_args ) ); if ( $has_buffer_started ) { ob_end_flush(); } From 878f621ec788923cc7103a9669f2ee0b48c300bc Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:40:20 +0200 Subject: [PATCH 101/434] Use elvis operator where possible --- includes/embeds/class-amp-soundcloud-embed.php | 2 +- includes/validation/class-amp-validation-manager.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/embeds/class-amp-soundcloud-embed.php b/includes/embeds/class-amp-soundcloud-embed.php index e877674f586..82435cf077a 100644 --- a/includes/embeds/class-amp-soundcloud-embed.php +++ b/includes/embeds/class-amp-soundcloud-embed.php @@ -190,7 +190,7 @@ public function render( $args, $url ) { } // @todo Set width to $args['width'] and layout to responsive once amp-soundcloud supports it: <https://github.com/ampproject/amphtml/issues/23144>. - $attributes['height'] = $args['height'] ? $args['height'] : $this->args['height']; + $attributes['height'] = $args['height'] ?: $this->args['height']; $attributes['layout'] = 'fixed-height'; return AMP_HTML_Utils::build_tag( diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index a3b07cc417b..502e574816a 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -374,7 +374,7 @@ public static function add_admin_bar_menu_items( $wp_admin_bar ) { } // @todo The amp_validated_url post should probably only be accessible to users who can manage_options, or limit access to a post if the user has the cap to edit the queried object? - $validate_url = AMP_Validated_URL_Post_Type::get_recheck_url( $amp_validated_url_post ? $amp_validated_url_post : $amp_url ); + $validate_url = AMP_Validated_URL_Post_Type::get_recheck_url( $amp_validated_url_post ?: $amp_url ); // Construct the parent admin bar item. if ( is_amp_endpoint() ) { From ea4421a158e9e8d6f5c2700f038bcd20fd4603a1 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:40:33 +0200 Subject: [PATCH 102/434] Merge some isset() constructs --- includes/validation/class-amp-validation-manager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index 502e574816a..6bf012f27c3 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -1524,11 +1524,11 @@ public static function wrapped_callback( $callback ) { $args = func_get_args(); $before_styles_enqueued = array(); - if ( isset( $wp_styles ) && isset( $wp_styles->queue ) ) { + if ( isset( $wp_styles, $wp_styles->queue ) ) { $before_styles_enqueued = $wp_styles->queue; } $before_scripts_enqueued = array(); - if ( isset( $wp_scripts ) && isset( $wp_scripts->queue ) ) { + if ( isset( $wp_scripts, $wp_scripts->queue ) ) { $before_scripts_enqueued = $wp_scripts->queue; } @@ -1547,14 +1547,14 @@ public static function wrapped_callback( $callback ) { array_pop( AMP_Validation_Manager::$hook_source_stack ); // Keep track of which source enqueued the styles. - if ( isset( $wp_styles ) && isset( $wp_styles->queue ) ) { + if ( isset( $wp_styles, $wp_styles->queue ) ) { foreach ( array_diff( $wp_styles->queue, $before_styles_enqueued ) as $handle ) { AMP_Validation_Manager::$enqueued_style_sources[ $handle ][] = array_merge( $callback['source'], compact( 'handle' ) ); } } // Keep track of which source enqueued the scripts, and immediately report validity. - if ( isset( $wp_scripts ) && isset( $wp_scripts->queue ) ) { + if ( isset( $wp_scripts, $wp_scripts->queue ) ) { foreach ( array_diff( $wp_scripts->queue, $before_scripts_enqueued ) as $queued_handle ) { $handles = array( $queued_handle ); From aaf60a1c064da87b29ce82fb6576bb1b1b700d69 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:41:57 +0200 Subject: [PATCH 103/434] Avoid redundant variable declaration --- includes/embeds/class-amp-dailymotion-embed.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/embeds/class-amp-dailymotion-embed.php b/includes/embeds/class-amp-dailymotion-embed.php index 82a98de1b87..e1a8dc50560 100644 --- a/includes/embeds/class-amp-dailymotion-embed.php +++ b/includes/embeds/class-amp-dailymotion-embed.php @@ -157,8 +157,7 @@ private function get_video_id_from_url( $url ) { parse_str( $parsed_url['path'], $path ); $tok = explode( '/', $parsed_url['path'] ); $tok = explode( '_', $tok[2] ); - $video_id = $tok[0]; - return $video_id; + return $tok[0]; } } From 5f378677a35b5041f6ca7ec684f9f1c8e92f8dc9 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:47:22 +0200 Subject: [PATCH 104/434] Make string comparisons more readable --- includes/class-amp-theme-support.php | 6 +- includes/embeds/class-amp-facebook-embed.php | 2 +- .../sanitizers/class-amp-form-sanitizer.php | 4 +- .../sanitizers/class-amp-iframe-sanitizer.php | 2 +- .../sanitizers/class-amp-script-sanitizer.php | 2 +- .../sanitizers/class-amp-style-sanitizer.php | 100 +++++++++--------- .../class-amp-tag-and-attribute-sanitizer.php | 8 +- .../trait-amp-noscript-fallback.php | 2 +- .../class-amp-validated-url-post-type.php | 2 +- .../class-amp-validation-manager.php | 8 +- 10 files changed, 67 insertions(+), 69 deletions(-) diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 415d1cd6197..561409b2587 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -642,7 +642,7 @@ public static function get_template_availability( $query = null ) { } // If the callback is a method on the query, then call the method on the query itself. - if ( is_string( $callback ) && 'is_' === substr( $callback, 0, 3 ) && method_exists( $query, $callback ) ) { + if ( is_string( $callback ) && 0 === strpos( $callback, 'is_' ) && method_exists( $query, $callback ) ) { $is_match = call_user_func( array( $query, $callback ) ); } elseif ( is_callable( $callback ) ) { $is_match = $callback( $query ); @@ -1571,7 +1571,7 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles } foreach ( $head_scripts as $script ) { $src = $script->getAttribute( 'src' ); - if ( ! $src || 'https://cdn.ampproject.org/' !== substr( $src, 0, 27 ) ) { + if ( ! $src || 0 !== strpos( $src, 'https://cdn.ampproject.org/' ) ) { continue; } if ( $runtime_src === $src ) { @@ -1841,7 +1841,7 @@ public static function prepare_response( $response, $args = array() ) { } // Abort if the response was not HTML. - if ( 'text/html' !== substr( AMP_HTTP::get_response_content_type(), 0, 9 ) || '<' !== substr( ltrim( $response ), 0, 1 ) ) { + if ( 0 !== strpos( AMP_HTTP::get_response_content_type(), 'text/html' ) || 0 !== strpos( ltrim( $response ), '<' ) ) { return $response; } diff --git a/includes/embeds/class-amp-facebook-embed.php b/includes/embeds/class-amp-facebook-embed.php index 6629761c67b..8419f80b5ed 100644 --- a/includes/embeds/class-amp-facebook-embed.php +++ b/includes/embeds/class-amp-facebook-embed.php @@ -205,7 +205,7 @@ private function create_amp_facebook_and_replace_node( $dom, $node, $embed_type $node->removeAttribute( 'data-height' ); foreach ( $node->attributes as $attribute ) { - if ( 'data-' === substr( $attribute->nodeName, 0, 5 ) ) { + if ( 0 === strpos( $attribute->nodeName, 'data-' ) ) { $attributes[ $attribute->nodeName ] = $attribute->nodeValue; } } diff --git a/includes/sanitizers/class-amp-form-sanitizer.php b/includes/sanitizers/class-amp-form-sanitizer.php index 44ca4b947ab..244d0230487 100644 --- a/includes/sanitizers/class-amp-form-sanitizer.php +++ b/includes/sanitizers/class-amp-form-sanitizer.php @@ -75,7 +75,7 @@ public function sanitize() { $xhr_action = $node->getAttribute( 'action-xhr' ); // Make HTTP URLs protocol-less, since HTTPS is required for forms. - if ( 'http://' === strtolower( substr( $action_url, 0, 7 ) ) ) { + if ( 0 === stripos( $action_url, 'http://' ) ) { $action_url = substr( $action_url, 5 ); } @@ -100,7 +100,7 @@ public function sanitize() { $node->setAttribute( 'action-xhr', $action_url ); // Append success/error handlers if not found. $this->ensure_response_message_elements( $node ); - } elseif ( 'http://' === substr( $xhr_action, 0, 7 ) ) { + } elseif ( 0 === strpos( $xhr_action, 'http://' ) ) { $node->setAttribute( 'action-xhr', substr( $xhr_action, 5 ) ); } } diff --git a/includes/sanitizers/class-amp-iframe-sanitizer.php b/includes/sanitizers/class-amp-iframe-sanitizer.php index 308235a4253..3e69eb6160d 100644 --- a/includes/sanitizers/class-amp-iframe-sanitizer.php +++ b/includes/sanitizers/class-amp-iframe-sanitizer.php @@ -165,7 +165,7 @@ private function normalize_attributes( $attributes ) { switch ( $name ) { case 'src': // Make the URL absolute since relative URLs are not allowed in amp-iframe. - if ( '/' === substr( $value, 0, 1 ) && '/' !== substr( $value, 1, 1 ) ) { + if ( 0 === strpos( $value, '/' ) && '/' !== substr( $value, 1, 1 ) ) { $value = untrailingslashit( $this->args['current_origin'] ) . $value; } diff --git a/includes/sanitizers/class-amp-script-sanitizer.php b/includes/sanitizers/class-amp-script-sanitizer.php index 54596652ce4..9e054b30538 100644 --- a/includes/sanitizers/class-amp-script-sanitizer.php +++ b/includes/sanitizers/class-amp-script-sanitizer.php @@ -36,7 +36,7 @@ public function sanitize() { } // Skip noscript elements inside of amp-img or other AMP components for fallbacks. See \AMP_Img_Sanitizer::adjust_and_replace_node(). - if ( 'amp-' === substr( $noscript->parentNode->nodeName, 0, 4 ) ) { + if ( 0 === strpos( $noscript->parentNode->nodeName, 'amp-' ) ) { continue; } diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 66b38f88cf7..3c10dcbdd43 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -470,7 +470,7 @@ private function has_used_class_name( $class_names ) { foreach ( $class_names as $class_name ) { // Class names for amp-dynamic-css-classes, see <https://www.ampproject.org/docs/reference/components/amp-dynamic-css-classes>. - if ( 'amp-referrer-' === substr( $class_name, 0, 13 ) ) { + if ( 0 === strpos( $class_name, 'amp-referrer-' ) ) { continue; } @@ -487,7 +487,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-carousel, see <https://www.ampproject.org/docs/reference/components/amp-carousel#styling>. - if ( 'amp-carousel-' === substr( $class_name, 0, 13 ) ) { + if ( 0 === strpos( $class_name, 'amp-carousel-' ) ) { if ( ! $this->has_used_tag_names( array( 'amp-carousel' ) ) ) { return false; } @@ -495,7 +495,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-date-picker, see <https://www.ampproject.org/docs/reference/components/amp-date-picker>. - if ( 'amp-date-picker-' === substr( $class_name, 0, 16 ) ) { + if ( 0 === strpos( $class_name, 'amp-date-picker-' ) ) { if ( ! $this->has_used_tag_names( array( 'amp-date-picker' ) ) ) { return false; } @@ -503,7 +503,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-form, see <https://www.ampproject.org/docs/reference/components/amp-form#classes-and-css-hooks>. - if ( 'amp-form-' === substr( $class_name, 0, 9 ) || 'user-valid' === $class_name || 'user-invalid' === $class_name ) { + if ( 0 === strpos( $class_name, 'amp-form-' ) || 'user-valid' === $class_name || 'user-invalid' === $class_name ) { if ( ! $this->has_used_tag_names( array( 'form' ) ) ) { return false; } @@ -515,7 +515,7 @@ private function has_used_class_name( $class_names ) { * See <https://www.ampproject.org/docs/reference/components/amp-access>. * See <https://www.ampproject.org/docs/reference/components/amp-access-laterpay#styling> */ - if ( 'amp-access-' === substr( $class_name, 0, 11 ) ) { + if ( 0 === strpos( $class_name, 'amp-access-' ) ) { if ( ! $this->has_used_attributes( array( 'amp-access' ) ) ) { return false; } @@ -523,7 +523,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-geo, see <https://www.ampproject.org/docs/reference/components/amp-geo#generated-css-classes>. - if ( 'amp-geo-' === substr( $class_name, 0, 8 ) || 'amp-iso-country-' === substr( $class_name, 0, 16 ) ) { + if ( 0 === strpos( $class_name, 'amp-geo-' ) || 'amp-iso-country-' === substr( $class_name, 0, 16 ) ) { if ( ! $this->has_used_tag_names( array( 'amp-geo' ) ) ) { return false; } @@ -539,7 +539,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-live-list, see <https://www.ampproject.org/docs/reference/components/amp-live-list#styling>. - if ( 'amp-live-list-' === substr( $class_name, 0, 14 ) ) { + if ( 0 === strpos( $class_name, 'amp-live-list-' ) ) { if ( ! $this->has_used_tag_names( array( 'amp-live-list' ) ) ) { return false; } @@ -547,7 +547,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-sidebar, see <https://www.ampproject.org/docs/reference/components/amp-sidebar#styling-toolbar>. - if ( 'amp-sidebar-' === substr( $class_name, 0, 12 ) ) { + if ( 0 === strpos( $class_name, 'amp-sidebar-' ) ) { if ( ! $this->has_used_tag_names( array( 'amp-sidebar' ) ) ) { return false; } @@ -555,7 +555,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-sticky-ad, see <https://www.ampproject.org/docs/reference/components/amp-sticky-ad#styling>. - if ( 'amp-sticky-ad-' === substr( $class_name, 0, 14 ) ) { + if ( 0 === strpos( $class_name, 'amp-sticky-ad-' ) ) { if ( ! $this->has_used_tag_names( array( 'amp-sticky-ad' ) ) ) { return false; } @@ -563,7 +563,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-video-docking, see <https://github.com/ampproject/amphtml/blob/master/extensions/amp-video-docking/amp-video-docking.md#styling>. - if ( 'amp-docked-' === substr( $class_name, 0, 11 ) ) { + if ( 0 === strpos( $class_name, 'amp-docked-' ) ) { if ( ! $this->has_used_attributes( array( 'dock' ) ) ) { return false; } @@ -1122,7 +1122,7 @@ private function process_link_element( DOMElement $element ) { * they don't implement the resource hint. */ $needs_preconnect_link = ( - 'https://fonts.googleapis.com/' === substr( $normalized_url, 0, 29 ) + 0 === strpos( $normalized_url, 'https://fonts.googleapis.com/' ) && 0 === $this->xpath->query( '//link[ @rel = "preconnect" and @crossorigin and starts-with( @href, "https://fonts.gstatic.com" ) ]', $this->head )->length ); @@ -1903,13 +1903,13 @@ private function real_path_urls( $urls, $stylesheet_url ) { $url_string = $url->getURL()->getString(); // For data: URLs, all that is needed is to remove spaces so set and continue. - if ( 'data:' === substr( $url_string, 0, 5 ) ) { + if ( 0 === strpos( $url_string, 'data:' ) ) { continue; } // If the URL is already absolute, continue since there there is nothing left to do. $parsed_url = wp_parse_url( $url_string ); - if ( ! empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) || '/' === substr( $parsed_url['path'], 0, 1 ) ) { + if ( ! empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) || 0 === strpos( $parsed_url['path'], '/' ) ) { continue; } @@ -2104,7 +2104,7 @@ private function process_font_face_at_rule( AtRuleSet $ruleset, $options ) { foreach ( $sources as $i => $source ) { if ( $source[0] instanceof URL ) { $value = $source[0]->getURL()->getString(); - if ( 'data:' === substr( $value, 0, 5 ) ) { + if ( 0 === strpos( $value, 'data:' ) ) { $source_data_url_objects[ $i ] = $source[0]; } else { $source_file_urls[ $i ] = $value; @@ -2713,7 +2713,7 @@ private function ampify_ruleset_selectors( $ruleset ) { ? $language !== $matches['lang'] : - substr( $language, 0, strlen( $matches['lang'] ) ) !== $matches['lang'] + 0 !== strpos( $language, $matches['lang'] ) ) ); if ( $is_other_language_root ) { @@ -2741,9 +2741,9 @@ static function ( $selector_language ) { * N: en-US && en-UK */ if ( - substr( $language, 0, strlen( $selector_language ) ) === $selector_language + 0 === strpos( $language, $selector_language ) || - substr( $selector_language, 0, strlen( $language ) ) === $language + 0 === strpos( $selector_language, $language ) ) { $has_matching_language = true; break; @@ -2830,41 +2830,39 @@ private function finalize_stylesheet_group( $group, $group_config ) { $selectors = array(); foreach ( $selectors_parsed as $selector => $parsed_selector ) { $should_include = ( + // If all class names are used in the doc. ( - // If all class names are used in the doc. - ( - empty( $parsed_selector[ self::SELECTOR_EXTRACTED_CLASSES ] ) - || - $this->has_used_class_name( $parsed_selector[ self::SELECTOR_EXTRACTED_CLASSES ] ) - ) - && - // If all IDs are used in the doc. - ( - empty( $parsed_selector[ self::SELECTOR_EXTRACTED_IDS ] ) - || - 0 === count( - array_filter( - $parsed_selector[ self::SELECTOR_EXTRACTED_IDS ], - function( $id ) { - return ! $this->dom->getElementById( $id ); - } - ) + empty( $parsed_selector[ self::SELECTOR_EXTRACTED_CLASSES ] ) + || + $this->has_used_class_name( $parsed_selector[ self::SELECTOR_EXTRACTED_CLASSES ] ) + ) + && + // If all IDs are used in the doc. + ( + empty( $parsed_selector[ self::SELECTOR_EXTRACTED_IDS ] ) + || + 0 === count( + array_filter( + $parsed_selector[ self::SELECTOR_EXTRACTED_IDS ], + function( $id ) { + return ! $this->dom->getElementById( $id ); + } ) ) - && - // If tag names are present in the doc. - ( - empty( $parsed_selector[ self::SELECTOR_EXTRACTED_TAGS ] ) - || - $this->has_used_tag_names( $parsed_selector[ self::SELECTOR_EXTRACTED_TAGS ] ) - ) - && - // If all attribute names are used in the doc. - ( - empty( $parsed_selector[ self::SELECTOR_EXTRACTED_ATTRIBUTES ] ) - || - $this->has_used_attributes( $parsed_selector[ self::SELECTOR_EXTRACTED_ATTRIBUTES ] ) - ) + ) + && + // If tag names are present in the doc. + ( + empty( $parsed_selector[ self::SELECTOR_EXTRACTED_TAGS ] ) + || + $this->has_used_tag_names( $parsed_selector[ self::SELECTOR_EXTRACTED_TAGS ] ) + ) + && + // If all attribute names are used in the doc. + ( + empty( $parsed_selector[ self::SELECTOR_EXTRACTED_ATTRIBUTES ] ) + || + $this->has_used_attributes( $parsed_selector[ self::SELECTOR_EXTRACTED_ATTRIBUTES ] ) ) ); if ( $should_include ) { @@ -2882,7 +2880,7 @@ function( $id ) { $stylesheet_part_count = count( $stylesheet_parts ); for ( $i = 0; $i < $stylesheet_part_count; $i++ ) { $stylesheet_part = $stylesheet_parts[ $i ]; - if ( '@' !== substr( $stylesheet_part, 0, 1 ) ) { + if ( 0 !== strpos( $stylesheet_part, '@' ) ) { continue; } @@ -2899,7 +2897,7 @@ function( $id ) { $open_braces = 1; for ( $j = $i + 1; $j < $stylesheet_part_count; $j++ ) { $stylesheet_part = $stylesheet_parts[ $j ]; - $is_at_rule = '@' === substr( $stylesheet_part, 0, 1 ); + $is_at_rule = 0 === strpos( $stylesheet_part, '@' ); if ( empty( $stylesheet_part ) ) { continue; // There was a shaken rule. } diff --git a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php index 2bc6f208a02..479db58d9d1 100644 --- a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php +++ b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php @@ -235,7 +235,7 @@ public function get_scripts() { */ private function process_alternate_names( $attr_spec_list ) { foreach ( $attr_spec_list as $attr_name => &$attr_spec ) { - if ( '[' === $attr_name[0] ) { + if ( 0 === strpos( $attr_name, '[' ) ) { $placeholder_attr_name = $this->args['amp_bind_placeholder_prefix'] . trim( $attr_name, '[]' ); if ( ! isset( $attr_spec[ AMP_Rule_Spec::ALTERNATIVE_NAMES ] ) ) { $attr_spec[ AMP_Rule_Spec::ALTERNATIVE_NAMES ] = array(); @@ -595,7 +595,7 @@ private function process_node( $node ) { if ( $node instanceof DOMElement && ! in_array( 'amp-bind', $this->script_components, true ) ) { foreach ( $node->attributes as $name => $value ) { $is_bind_attribute = ( - '[' === $name[0] + 0 === strpos( $name, '[' ) || ( isset( $this->rev_alternate_attr_name_lookup[ $name ] ) && '[' === $this->rev_alternate_attr_name_lookup[ $name ][0] ) ); @@ -620,7 +620,7 @@ public function is_missing_mandatory_attribute( $attr_spec, $node ) { return false; } foreach ( $attr_spec as $attr_name => $attr_spec_rule_value ) { - if ( '\u' === substr( $attr_name, 0, 2 ) ) { + if ( 0 === strpos( $attr_name, '\u' ) ) { $attr_name = html_entity_decode( '&#x' . substr( $attr_name, 2 ) . ';' ); // Probably ⚡. } $is_mandatory = isset( $attr_spec_rule_value[ AMP_Rule_Spec::MANDATORY ] ) ? ( true === $attr_spec_rule_value[ AMP_Rule_Spec::MANDATORY ] ) : false; @@ -1665,7 +1665,7 @@ private function is_amp_allowed_attribute( $attr_node, $attr_spec_list ) { if ( isset( $attr_spec_list[ $attr_name ] ) || - 'data-' === substr( $attr_name, 0, 5 ) + 0 === strpos( $attr_name, 'data-' ) || // Allow the 'amp' or '⚡' attribute in <html>, like <html ⚡>. ( 'html' === $attr_node->parentNode->nodeName && in_array( $attr_node->nodeName, array( 'amp', '⚡' ), true ) ) diff --git a/includes/sanitizers/trait-amp-noscript-fallback.php b/includes/sanitizers/trait-amp-noscript-fallback.php index 3dd251d2f0a..6b8522f5a40 100644 --- a/includes/sanitizers/trait-amp-noscript-fallback.php +++ b/includes/sanitizers/trait-amp-noscript-fallback.php @@ -50,7 +50,7 @@ protected function initialize_noscript_allowed_attributes( $tag ) { * @return bool True if in an AMP noscript element, false otherwise. */ protected function is_inside_amp_noscript( \DOMNode $node ) { - return 'noscript' === $node->parentNode->nodeName && $node->parentNode->parentNode && 'amp-' === substr( $node->parentNode->parentNode->nodeName, 0, 4 ); + return 'noscript' === $node->parentNode->nodeName && $node->parentNode->parentNode && 0 === strpos( $node->parentNode->parentNode->nodeName, 'amp-' ); } /** diff --git a/includes/validation/class-amp-validated-url-post-type.php b/includes/validation/class-amp-validated-url-post-type.php index 42aff2ede25..45f1647b2a1 100644 --- a/includes/validation/class-amp-validated-url-post-type.php +++ b/includes/validation/class-amp-validated-url-post-type.php @@ -133,7 +133,7 @@ public static function register() { public static function handle_plugin_update( $old_version ) { // Update the old post type slug from amp_validated_url to amp_validated_url. - if ( '1.0-' === substr( $old_version, 0, 4 ) || version_compare( $old_version, '1.0', '<' ) ) { + if ( 0 === strpos( $old_version, '1.0-' ) || version_compare( $old_version, '1.0', '<' ) ) { global $wpdb; $post_ids = get_posts( array( diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index 6bf012f27c3..cee272065d6 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -1614,7 +1614,7 @@ public static function wrap_buffer_with_source_comments( $output ) { * @return string Nonce. */ public static function get_amp_validate_nonce() { - return substr( wp_hash( self::VALIDATE_QUERY_VAR . (string) wp_nonce_tick(), 'nonce' ), -12, 10 ); + return substr( wp_hash( self::VALIDATE_QUERY_VAR . wp_nonce_tick(), 'nonce' ), -12, 10 ); } /** @@ -1857,7 +1857,7 @@ public static function validate_url( $url ) { } // Ensure absolute URL. - if ( '/' === substr( $location_header, 0, 1 ) ) { + if ( 0 === strpos( $location_header, '/' ) ) { $location_header = preg_replace( '#(^https?://[^/]+)/.*#', '$1', home_url( '/' ) ) . $location_header; } @@ -1886,7 +1886,7 @@ public static function validate_url( $url ) { ); $response = wp_remote_retrieve_body( $r ); - if ( strlen( trim( $response ) ) === 0 ) { + if ( '' === trim( $response ) ) { $error_code = 'white_screen_of_death'; return new WP_Error( $error_code, self::get_validate_url_error_message( $error_code ) ); } @@ -1937,7 +1937,7 @@ public static function get_validate_url_error_message( $error_code ) { default: /* translators: %s is error code */ return sprintf( __( 'URL validation failed. Error code: %s.', 'amp' ), $error_code ); // Note that $error_code has been sanitized with sanitize_key(); will be escaped below as well. - }; + } } /** From 30dccc4e70ed74da5ebb9777524a34c65d06b315 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 11:48:15 +0200 Subject: [PATCH 105/434] Lint fix --- includes/embeds/class-amp-dailymotion-embed.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/embeds/class-amp-dailymotion-embed.php b/includes/embeds/class-amp-dailymotion-embed.php index e1a8dc50560..7cbbc9f6d7a 100644 --- a/includes/embeds/class-amp-dailymotion-embed.php +++ b/includes/embeds/class-amp-dailymotion-embed.php @@ -155,8 +155,8 @@ public function render( $args ) { private function get_video_id_from_url( $url ) { $parsed_url = wp_parse_url( $url ); parse_str( $parsed_url['path'], $path ); - $tok = explode( '/', $parsed_url['path'] ); - $tok = explode( '_', $tok[2] ); + $tok = explode( '/', $parsed_url['path'] ); + $tok = explode( '_', $tok[2] ); return $tok[0]; } From 9f492ccd9b9a2e27f2fddd3a2a1a92e80a18f8c5 Mon Sep 17 00:00:00 2001 From: Renovate Bot <bot@renovateapp.com> Date: Thu, 4 Jul 2019 15:09:40 +0300 Subject: [PATCH 106/434] Update dependency eslint-plugin-jest to v22.7.2 (#2743) --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 83b21db80a9..577f544a89e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5603,9 +5603,9 @@ } }, "eslint-plugin-jest": { - "version": "22.7.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-22.7.1.tgz", - "integrity": "sha512-CrT3AzA738neimv8G8iK2HCkrCwHnAJeeo7k5TEHK86VMItKl6zdJT/tHBDImfnVVAYsVs4Y6BUdBZQCCgfiyw==", + "version": "22.7.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-22.7.2.tgz", + "integrity": "sha512-Aecqe3ulBVI7amgOycVI8ZPL8o0SnGHOf3zn2/Ciu8TXyXDHcjtwD3hOs3ss/Qh/VAwlW/DMcuiXg5btgF+XMA==", "dev": true }, "eslint-plugin-jsx-a11y": { diff --git a/package.json b/package.json index f760e761cda..060a14ba8ef 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "cssnano": "4.1.10", "enzyme": "3.10.0", "eslint": "6.0.1", - "eslint-plugin-jest": "22.7.1", + "eslint-plugin-jest": "22.7.2", "eslint-plugin-react": "7.14.2", "grunt": "1.0.4", "grunt-contrib-clean": "2.0.0", From 3d5b457d225fa561528d96780e233fe026d9a77d Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 14:18:52 +0200 Subject: [PATCH 107/434] Trigger build From a89647fe75a884d29b9ee6a87e15a9378e969fc3 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 15:10:20 +0200 Subject: [PATCH 108/434] Trigger build From 1c0f9dfa4c2411b2fdd746ac81f54589e4012462 Mon Sep 17 00:00:00 2001 From: Renovate Bot <bot@renovateapp.com> Date: Thu, 4 Jul 2019 16:21:26 +0300 Subject: [PATCH 109/434] Update dependency @babel/cli to v7.5.0 (#2745) --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 577f544a89e..72dc7d134cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,9 +4,9 @@ "lockfileVersion": 1, "dependencies": { "@babel/cli": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/cli/-/cli-7.4.4.tgz", - "integrity": "sha512-XGr5YjQSjgTa6OzQZY57FAJsdeVSAKR/u/KA5exWIz66IKtv/zXtHy+fIZcMry/EgYegwuHE7vzGnrFhjdIAsQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/cli/-/cli-7.5.0.tgz", + "integrity": "sha512-qNH55fWbKrEsCwID+Qc/3JDPnsSGpIIiMDbppnR8Z6PxLAqMQCFNqBctkIkBrMH49Nx+qqVTrHRWUR+ho2k+qQ==", "dev": true, "requires": { "chokidar": "^2.0.4", diff --git a/package.json b/package.json index 060a14ba8ef..f4d7a9554df 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "prop-types": "15.7.2" }, "devDependencies": { - "@babel/cli": "7.4.4", + "@babel/cli": "7.5.0", "@babel/core": "7.4.5", "@babel/plugin-proposal-object-rest-spread": "7.4.4", "@babel/plugin-transform-react-jsx": "7.3.0", From 19ebc332000b112cace18523944c37b48878a3c3 Mon Sep 17 00:00:00 2001 From: Renovate Bot <bot@renovateapp.com> Date: Thu, 4 Jul 2019 17:09:35 +0300 Subject: [PATCH 110/434] Update dependency @babel/core to v7.5.0 (#2746) --- package-lock.json | 137 +++++++++++++++++++++++++++++++++++++++++----- package.json | 2 +- 2 files changed, 125 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 72dc7d134cf..8a678bfc747 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,18 +31,18 @@ } }, "@babel/core": { - "version": "7.4.5", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.4.5.tgz", - "integrity": "sha512-OvjIh6aqXtlsA8ujtGKfC7LYWksYSX8yQcM8Ay3LuvVeQ63lcOKgoZWVqcpFwkd29aYU9rVx7jxhfhiEDV9MZA==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.5.0.tgz", + "integrity": "sha512-6Isr4X98pwXqHvtigw71CKgmhL1etZjPs5A67jL/w0TkLM9eqmFR40YrnJvEc1WnMZFsskjsmid8bHZyxKEAnw==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.4.4", - "@babel/helpers": "^7.4.4", - "@babel/parser": "^7.4.5", + "@babel/generator": "^7.5.0", + "@babel/helpers": "^7.5.0", + "@babel/parser": "^7.5.0", "@babel/template": "^7.4.4", - "@babel/traverse": "^7.4.5", - "@babel/types": "^7.4.4", + "@babel/traverse": "^7.5.0", + "@babel/types": "^7.5.0", "convert-source-map": "^1.1.0", "debug": "^4.1.0", "json5": "^2.1.0", @@ -52,6 +52,53 @@ "source-map": "^0.5.0" }, "dependencies": { + "@babel/generator": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.5.0.tgz", + "integrity": "sha512-1TTVrt7J9rcG5PMjvO7VEG3FrEoEJNHxumRq66GemPmzboLWtIjjcJgk8rokuAS7IiRSpgVSu5Vb9lc99iJkOA==", + "dev": true, + "requires": { + "@babel/types": "^7.5.0", + "jsesc": "^2.5.1", + "lodash": "^4.17.11", + "source-map": "^0.5.0", + "trim-right": "^1.0.1" + } + }, + "@babel/parser": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.5.0.tgz", + "integrity": "sha512-I5nW8AhGpOXGCCNYGc+p7ExQIBxRFnS2fd/d862bNOKvmoEPjYPcfIjsfdy0ujagYOIYPczKgD9l3FsgTkAzKA==", + "dev": true + }, + "@babel/traverse": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.5.0.tgz", + "integrity": "sha512-SnA9aLbyOCcnnbQEGwdfBggnc142h/rbqqsXcaATj2hZcegCl903pUD/lfpsNBlBSuWow/YDfRyJuWi2EPR5cg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/generator": "^7.5.0", + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/parser": "^7.5.0", + "@babel/types": "^7.5.0", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.11" + } + }, + "@babel/types": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.5.0.tgz", + "integrity": "sha512-UFpDVqRABKsW01bvw7/wSUe56uy6RXM5+VJibVVAybDGxEW25jdwiFJEf7ASvSaC7sN7rbE/l3cLp2izav+CtQ==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.11", + "to-fast-properties": "^2.0.0" + } + }, "debug": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", @@ -285,14 +332,78 @@ } }, "@babel/helpers": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.4.4.tgz", - "integrity": "sha512-igczbR/0SeuPR8RFfC7tGrbdTbFL3QTvH6D+Z6zNxnTe//GyqmtHmDkzrqDmyZ3eSwPqB/LhyKoU5DXsp+Vp2A==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.5.0.tgz", + "integrity": "sha512-EgCUEa8cNwuMrwo87l2d7i2oShi8m2Q58H7h3t4TWtqATZalJYFwfL9DulRe02f3KdqM9xmMCw3v/7Ll+EiaWg==", "dev": true, "requires": { "@babel/template": "^7.4.4", - "@babel/traverse": "^7.4.4", - "@babel/types": "^7.4.4" + "@babel/traverse": "^7.5.0", + "@babel/types": "^7.5.0" + }, + "dependencies": { + "@babel/generator": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.5.0.tgz", + "integrity": "sha512-1TTVrt7J9rcG5PMjvO7VEG3FrEoEJNHxumRq66GemPmzboLWtIjjcJgk8rokuAS7IiRSpgVSu5Vb9lc99iJkOA==", + "dev": true, + "requires": { + "@babel/types": "^7.5.0", + "jsesc": "^2.5.1", + "lodash": "^4.17.11", + "source-map": "^0.5.0", + "trim-right": "^1.0.1" + } + }, + "@babel/parser": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.5.0.tgz", + "integrity": "sha512-I5nW8AhGpOXGCCNYGc+p7ExQIBxRFnS2fd/d862bNOKvmoEPjYPcfIjsfdy0ujagYOIYPczKgD9l3FsgTkAzKA==", + "dev": true + }, + "@babel/traverse": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.5.0.tgz", + "integrity": "sha512-SnA9aLbyOCcnnbQEGwdfBggnc142h/rbqqsXcaATj2hZcegCl903pUD/lfpsNBlBSuWow/YDfRyJuWi2EPR5cg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/generator": "^7.5.0", + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/parser": "^7.5.0", + "@babel/types": "^7.5.0", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.11" + } + }, + "@babel/types": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.5.0.tgz", + "integrity": "sha512-UFpDVqRABKsW01bvw7/wSUe56uy6RXM5+VJibVVAybDGxEW25jdwiFJEf7ASvSaC7sN7rbE/l3cLp2izav+CtQ==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.11", + "to-fast-properties": "^2.0.0" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } } }, "@babel/highlight": { diff --git a/package.json b/package.json index f4d7a9554df..d6309a43662 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "devDependencies": { "@babel/cli": "7.5.0", - "@babel/core": "7.4.5", + "@babel/core": "7.5.0", "@babel/plugin-proposal-object-rest-spread": "7.4.4", "@babel/plugin-transform-react-jsx": "7.3.0", "@wordpress/babel-preset-default": "4.3.0", From 16f8d42510d48571f023d025da22f3a8d6941f09 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 16:20:56 +0200 Subject: [PATCH 111/434] Rebuild package-lock.json --- package-lock.json | 440 +++++++++++++++++++++------------------------- 1 file changed, 196 insertions(+), 244 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8a678bfc747..8ec3ed48593 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,53 +52,6 @@ "source-map": "^0.5.0" }, "dependencies": { - "@babel/generator": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.5.0.tgz", - "integrity": "sha512-1TTVrt7J9rcG5PMjvO7VEG3FrEoEJNHxumRq66GemPmzboLWtIjjcJgk8rokuAS7IiRSpgVSu5Vb9lc99iJkOA==", - "dev": true, - "requires": { - "@babel/types": "^7.5.0", - "jsesc": "^2.5.1", - "lodash": "^4.17.11", - "source-map": "^0.5.0", - "trim-right": "^1.0.1" - } - }, - "@babel/parser": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.5.0.tgz", - "integrity": "sha512-I5nW8AhGpOXGCCNYGc+p7ExQIBxRFnS2fd/d862bNOKvmoEPjYPcfIjsfdy0ujagYOIYPczKgD9l3FsgTkAzKA==", - "dev": true - }, - "@babel/traverse": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.5.0.tgz", - "integrity": "sha512-SnA9aLbyOCcnnbQEGwdfBggnc142h/rbqqsXcaATj2hZcegCl903pUD/lfpsNBlBSuWow/YDfRyJuWi2EPR5cg==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.5.0", - "@babel/helper-function-name": "^7.1.0", - "@babel/helper-split-export-declaration": "^7.4.4", - "@babel/parser": "^7.5.0", - "@babel/types": "^7.5.0", - "debug": "^4.1.0", - "globals": "^11.1.0", - "lodash": "^4.17.11" - } - }, - "@babel/types": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.5.0.tgz", - "integrity": "sha512-UFpDVqRABKsW01bvw7/wSUe56uy6RXM5+VJibVVAybDGxEW25jdwiFJEf7ASvSaC7sN7rbE/l3cLp2izav+CtQ==", - "dev": true, - "requires": { - "esutils": "^2.0.2", - "lodash": "^4.17.11", - "to-fast-properties": "^2.0.0" - } - }, "debug": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", @@ -117,12 +70,12 @@ } }, "@babel/generator": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.4.4.tgz", - "integrity": "sha512-53UOLK6TVNqKxf7RUh8NE851EHRxOOeVXKbK2bivdb+iziMyk03Sr4eaE9OELCbyZAAafAKPDwF2TPUES5QbxQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.5.0.tgz", + "integrity": "sha512-1TTVrt7J9rcG5PMjvO7VEG3FrEoEJNHxumRq66GemPmzboLWtIjjcJgk8rokuAS7IiRSpgVSu5Vb9lc99iJkOA==", "dev": true, "requires": { - "@babel/types": "^7.4.4", + "@babel/types": "^7.5.0", "jsesc": "^2.5.1", "lodash": "^4.17.11", "source-map": "^0.5.0", @@ -340,76 +293,12 @@ "@babel/template": "^7.4.4", "@babel/traverse": "^7.5.0", "@babel/types": "^7.5.0" - }, - "dependencies": { - "@babel/generator": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.5.0.tgz", - "integrity": "sha512-1TTVrt7J9rcG5PMjvO7VEG3FrEoEJNHxumRq66GemPmzboLWtIjjcJgk8rokuAS7IiRSpgVSu5Vb9lc99iJkOA==", - "dev": true, - "requires": { - "@babel/types": "^7.5.0", - "jsesc": "^2.5.1", - "lodash": "^4.17.11", - "source-map": "^0.5.0", - "trim-right": "^1.0.1" - } - }, - "@babel/parser": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.5.0.tgz", - "integrity": "sha512-I5nW8AhGpOXGCCNYGc+p7ExQIBxRFnS2fd/d862bNOKvmoEPjYPcfIjsfdy0ujagYOIYPczKgD9l3FsgTkAzKA==", - "dev": true - }, - "@babel/traverse": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.5.0.tgz", - "integrity": "sha512-SnA9aLbyOCcnnbQEGwdfBggnc142h/rbqqsXcaATj2hZcegCl903pUD/lfpsNBlBSuWow/YDfRyJuWi2EPR5cg==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.5.0", - "@babel/helper-function-name": "^7.1.0", - "@babel/helper-split-export-declaration": "^7.4.4", - "@babel/parser": "^7.5.0", - "@babel/types": "^7.5.0", - "debug": "^4.1.0", - "globals": "^11.1.0", - "lodash": "^4.17.11" - } - }, - "@babel/types": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.5.0.tgz", - "integrity": "sha512-UFpDVqRABKsW01bvw7/wSUe56uy6RXM5+VJibVVAybDGxEW25jdwiFJEf7ASvSaC7sN7rbE/l3cLp2izav+CtQ==", - "dev": true, - "requires": { - "esutils": "^2.0.2", - "lodash": "^4.17.11", - "to-fast-properties": "^2.0.0" - } - }, - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "dev": true, - "requires": { - "ms": "^2.1.1" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - } } }, "@babel/highlight": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz", - "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.5.0.tgz", + "integrity": "sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ==", "dev": true, "requires": { "chalk": "^2.0.0", @@ -418,9 +307,9 @@ } }, "@babel/parser": { - "version": "7.4.5", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.4.5.tgz", - "integrity": "sha512-9mUqkL1FF5T7f0WDFfAoDdiMVPWsdD1gZYzSnaXsxUCUqzuch/8of9G3VUSNiZmMBoRxT3neyVsqeiL/ZPcjew==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.5.0.tgz", + "integrity": "sha512-I5nW8AhGpOXGCCNYGc+p7ExQIBxRFnS2fd/d862bNOKvmoEPjYPcfIjsfdy0ujagYOIYPczKgD9l3FsgTkAzKA==", "dev": true }, "@babel/plugin-proposal-async-generator-functions": { @@ -434,6 +323,16 @@ "@babel/plugin-syntax-async-generators": "^7.2.0" } }, + "@babel/plugin-proposal-dynamic-import": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.5.0.tgz", + "integrity": "sha512-x/iMjggsKTFHYC6g11PL7Qy58IK8H5zqfm9e6hu4z1iH2IRyAp9u9dL80zA6R76yFovETFLKz2VJIC2iIPBuFw==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-syntax-dynamic-import": "^7.2.0" + } + }, "@babel/plugin-proposal-json-strings": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-json-strings/-/plugin-proposal-json-strings-7.2.0.tgz", @@ -484,6 +383,15 @@ "@babel/helper-plugin-utils": "^7.0.0" } }, + "@babel/plugin-syntax-dynamic-import": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.2.0.tgz", + "integrity": "sha512-mVxuJ0YroI/h/tbFTPGZR8cv6ai+STMKNBq0f8hFxsxWjl94qqhsb+wXbpNMDPU3cfR1TIsVFzU3nXyZMqyK4w==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, "@babel/plugin-syntax-json-strings": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.2.0.tgz", @@ -530,9 +438,9 @@ } }, "@babel/plugin-transform-async-to-generator": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.4.4.tgz", - "integrity": "sha512-YiqW2Li8TXmzgbXw+STsSqPBPFnGviiaSp6CYOq55X8GQ2SGVLrXB6pNid8HkqkZAzOH6knbai3snhP7v0fNwA==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.5.0.tgz", + "integrity": "sha512-mqvkzwIGkq0bEF1zLRRiTdjfomZJDV33AH3oQzHVGkI2VzEmXLpKKOBvEVaFZBJdN0XTyH38s9j/Kiqr68dggg==", "dev": true, "requires": { "@babel/helper-module-imports": "^7.0.0", @@ -585,9 +493,9 @@ } }, "@babel/plugin-transform-destructuring": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.4.4.tgz", - "integrity": "sha512-/aOx+nW0w8eHiEHm+BTERB2oJn5D127iye/SUQl7NjHy0lf+j7h4MKMMSOwdazGq9OxgiNADncE+SRJkCxjZpQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.5.0.tgz", + "integrity": "sha512-YbYgbd3TryYYLGyC7ZR+Tq8H/+bCmwoaxHfJHupom5ECstzbRLTch6gOQbhEY9Z4hiCNHEURgq06ykFv9JZ/QQ==", "dev": true, "requires": { "@babel/helper-plugin-utils": "^7.0.0" @@ -605,9 +513,9 @@ } }, "@babel/plugin-transform-duplicate-keys": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.2.0.tgz", - "integrity": "sha512-q+yuxW4DsTjNceUiTzK0L+AfQ0zD9rWaTLiUqHA8p0gxx7lu1EylenfzjeIWNkPy6e/0VG/Wjw9uf9LueQwLOw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.5.0.tgz", + "integrity": "sha512-igcziksHizyQPlX9gfSjHkE2wmoCH3evvD2qR5w29/Dk0SMKE/eOI7f1HhBdNhR/zxJDqrgpoDTq5YSLH/XMsQ==", "dev": true, "requires": { "@babel/helper-plugin-utils": "^7.0.0" @@ -661,34 +569,37 @@ } }, "@babel/plugin-transform-modules-amd": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.2.0.tgz", - "integrity": "sha512-mK2A8ucqz1qhrdqjS9VMIDfIvvT2thrEsIQzbaTdc5QFzhDjQv2CkJJ5f6BXIkgbmaoax3zBr2RyvV/8zeoUZw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.5.0.tgz", + "integrity": "sha512-n20UsQMKnWrltocZZm24cRURxQnWIvsABPJlw/fvoy9c6AgHZzoelAIzajDHAQrDpuKFFPPcFGd7ChsYuIUMpg==", "dev": true, "requires": { "@babel/helper-module-transforms": "^7.1.0", - "@babel/helper-plugin-utils": "^7.0.0" + "@babel/helper-plugin-utils": "^7.0.0", + "babel-plugin-dynamic-import-node": "^2.3.0" } }, "@babel/plugin-transform-modules-commonjs": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.4.4.tgz", - "integrity": "sha512-4sfBOJt58sEo9a2BQXnZq+Q3ZTSAUXyK3E30o36BOGnJ+tvJ6YSxF0PG6kERvbeISgProodWuI9UVG3/FMY6iw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.5.0.tgz", + "integrity": "sha512-xmHq0B+ytyrWJvQTc5OWAC4ii6Dhr0s22STOoydokG51JjWhyYo5mRPXoi+ZmtHQhZZwuXNN+GG5jy5UZZJxIQ==", "dev": true, "requires": { "@babel/helper-module-transforms": "^7.4.4", "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-simple-access": "^7.1.0" + "@babel/helper-simple-access": "^7.1.0", + "babel-plugin-dynamic-import-node": "^2.3.0" } }, "@babel/plugin-transform-modules-systemjs": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.4.4.tgz", - "integrity": "sha512-MSiModfILQc3/oqnG7NrP1jHaSPryO6tA2kOMmAQApz5dayPxWiHqmq4sWH2xF5LcQK56LlbKByCd8Aah/OIkQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.5.0.tgz", + "integrity": "sha512-Q2m56tyoQWmuNGxEtUyeEkm6qJYFqs4c+XyXH5RAuYxObRNz9Zgj/1g2GMnjYp2EUyEy7YTrxliGCXzecl/vJg==", "dev": true, "requires": { "@babel/helper-hoist-variables": "^7.4.4", - "@babel/helper-plugin-utils": "^7.0.0" + "@babel/helper-plugin-utils": "^7.0.0", + "babel-plugin-dynamic-import-node": "^2.3.0" } }, "@babel/plugin-transform-modules-umd": { @@ -779,9 +690,9 @@ } }, "@babel/plugin-transform-runtime": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.4.4.tgz", - "integrity": "sha512-aMVojEjPszvau3NRg+TIH14ynZLvPewH4xhlCW1w6A3rkxTS1m4uwzRclYR9oS+rl/dr+kT+pzbfHuAWP/lc7Q==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.5.0.tgz", + "integrity": "sha512-LmPIZOAgTLl+86gR9KjLXex6P/lRz1fWEjTz6V6QZMmKie51ja3tvzdwORqhHc4RWR8TcZ5pClpRWs0mlaA2ng==", "dev": true, "requires": { "@babel/helper-module-imports": "^7.0.0", @@ -849,39 +760,41 @@ } }, "@babel/preset-env": { - "version": "7.4.5", - "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.4.5.tgz", - "integrity": "sha512-f2yNVXM+FsR5V8UwcFeIHzHWgnhXg3NpRmy0ADvALpnhB0SLbCvrCRr4BLOUYbQNLS+Z0Yer46x9dJXpXewI7w==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.5.0.tgz", + "integrity": "sha512-/5oQ7cYg+6sH9Dt9yx5IiylnLPiUdyMHl5y+K0mKVNiW2wJ7FpU5bg8jKcT8PcCbxdYzfv6OuC63jLEtMuRSmQ==", "dev": true, "requires": { "@babel/helper-module-imports": "^7.0.0", "@babel/helper-plugin-utils": "^7.0.0", "@babel/plugin-proposal-async-generator-functions": "^7.2.0", + "@babel/plugin-proposal-dynamic-import": "^7.5.0", "@babel/plugin-proposal-json-strings": "^7.2.0", - "@babel/plugin-proposal-object-rest-spread": "^7.4.4", + "@babel/plugin-proposal-object-rest-spread": "^7.5.0", "@babel/plugin-proposal-optional-catch-binding": "^7.2.0", "@babel/plugin-proposal-unicode-property-regex": "^7.4.4", "@babel/plugin-syntax-async-generators": "^7.2.0", + "@babel/plugin-syntax-dynamic-import": "^7.2.0", "@babel/plugin-syntax-json-strings": "^7.2.0", "@babel/plugin-syntax-object-rest-spread": "^7.2.0", "@babel/plugin-syntax-optional-catch-binding": "^7.2.0", "@babel/plugin-transform-arrow-functions": "^7.2.0", - "@babel/plugin-transform-async-to-generator": "^7.4.4", + "@babel/plugin-transform-async-to-generator": "^7.5.0", "@babel/plugin-transform-block-scoped-functions": "^7.2.0", "@babel/plugin-transform-block-scoping": "^7.4.4", "@babel/plugin-transform-classes": "^7.4.4", "@babel/plugin-transform-computed-properties": "^7.2.0", - "@babel/plugin-transform-destructuring": "^7.4.4", + "@babel/plugin-transform-destructuring": "^7.5.0", "@babel/plugin-transform-dotall-regex": "^7.4.4", - "@babel/plugin-transform-duplicate-keys": "^7.2.0", + "@babel/plugin-transform-duplicate-keys": "^7.5.0", "@babel/plugin-transform-exponentiation-operator": "^7.2.0", "@babel/plugin-transform-for-of": "^7.4.4", "@babel/plugin-transform-function-name": "^7.4.4", "@babel/plugin-transform-literals": "^7.2.0", "@babel/plugin-transform-member-expression-literals": "^7.2.0", - "@babel/plugin-transform-modules-amd": "^7.2.0", - "@babel/plugin-transform-modules-commonjs": "^7.4.4", - "@babel/plugin-transform-modules-systemjs": "^7.4.4", + "@babel/plugin-transform-modules-amd": "^7.5.0", + "@babel/plugin-transform-modules-commonjs": "^7.5.0", + "@babel/plugin-transform-modules-systemjs": "^7.5.0", "@babel/plugin-transform-modules-umd": "^7.2.0", "@babel/plugin-transform-named-capturing-groups-regex": "^7.4.5", "@babel/plugin-transform-new-target": "^7.4.4", @@ -896,18 +809,30 @@ "@babel/plugin-transform-template-literals": "^7.4.4", "@babel/plugin-transform-typeof-symbol": "^7.2.0", "@babel/plugin-transform-unicode-regex": "^7.4.4", - "@babel/types": "^7.4.4", + "@babel/types": "^7.5.0", "browserslist": "^4.6.0", "core-js-compat": "^3.1.1", "invariant": "^2.2.2", "js-levenshtein": "^1.1.3", "semver": "^5.5.0" + }, + "dependencies": { + "@babel/plugin-proposal-object-rest-spread": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.5.0.tgz", + "integrity": "sha512-G1qy5EdcO3vYhbxlXjRSR2SXB8GsxYv9hoRKT1Jdn3qy/NUnFqUUnqymKZ00Pbj+3FXNh06B+BUZzecrp3sxNw==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-syntax-object-rest-spread": "^7.2.0" + } + } } }, "@babel/runtime": { - "version": "7.4.5", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.4.5.tgz", - "integrity": "sha512-TuI4qpWZP6lGOGIuGWtp9sPluqYICmbk8T/1vpSysqJxRPkudh/ofFWyqdcMsDf2s7KvDL4/YHgKyvcS3g9CJQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.5.0.tgz", + "integrity": "sha512-2xsuyZ0R0RBFwjgae5NpXk8FcfH4qovj5cEM5VEeB7KXnKqzaisIu2HSV/mCEISolJJuR4wkViUGYujA8MH9tw==", "dev": true, "requires": { "regenerator-runtime": "^0.13.2" @@ -925,17 +850,17 @@ } }, "@babel/traverse": { - "version": "7.4.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.4.5.tgz", - "integrity": "sha512-Vc+qjynwkjRmIFGxy0KYoPj4FdVDxLej89kMHFsWScq999uX+pwcX4v9mWRjW0KcAYTPAuVQl2LKP1wEVLsp+A==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.5.0.tgz", + "integrity": "sha512-SnA9aLbyOCcnnbQEGwdfBggnc142h/rbqqsXcaATj2hZcegCl903pUD/lfpsNBlBSuWow/YDfRyJuWi2EPR5cg==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.4.4", + "@babel/generator": "^7.5.0", "@babel/helper-function-name": "^7.1.0", "@babel/helper-split-export-declaration": "^7.4.4", - "@babel/parser": "^7.4.5", - "@babel/types": "^7.4.4", + "@babel/parser": "^7.5.0", + "@babel/types": "^7.5.0", "debug": "^4.1.0", "globals": "^11.1.0", "lodash": "^4.17.11" @@ -959,9 +884,9 @@ } }, "@babel/types": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.4.4.tgz", - "integrity": "sha512-dOllgYdnEFOebhkKCjzSVFqw/PmmB8pH6RGOWkY4GsboQNd47b1fBThBSwlHAq9alF9vc1M3+6oqR47R50L0tQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.5.0.tgz", + "integrity": "sha512-UFpDVqRABKsW01bvw7/wSUe56uy6RXM5+VJibVVAybDGxEW25jdwiFJEf7ASvSaC7sN7rbE/l3cLp2izav+CtQ==", "dev": true, "requires": { "esutils": "^2.0.2", @@ -1337,9 +1262,9 @@ "dev": true }, "@types/node": { - "version": "12.0.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.10.tgz", - "integrity": "sha512-LcsGbPomWsad6wmMNv7nBLw7YYYyfdYcz6xryKYQhx89c3XXan+8Q6AJ43G5XDIaklaVkK3mE4fCb0SBvMiPSQ==", + "version": "12.0.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.12.tgz", + "integrity": "sha512-Uy0PN4R5vgBUXFoJrKryf5aTk3kJ8Rv3PdlHjl6UaX+Cqp1QE0yPQ68MPXGrZOfG7gZVNDIJZYyot0B9ubXUrQ==", "dev": true }, "@types/q": { @@ -2790,9 +2715,9 @@ } }, "acorn": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", - "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.2.0.tgz", + "integrity": "sha512-8oe72N3WPMjA+2zVG71Ia0nXZ8DpQH+QyyHO+p06jT8eg8FGG3FbcUIi8KziHlAfheJQZeoqbvq1mQSQHXKYLw==", "dev": true }, "acorn-dynamic-import": { @@ -2818,9 +2743,9 @@ "dev": true }, "acorn-walk": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.1.1.tgz", - "integrity": "sha512-OtUw6JUTgxA2QoqqmrmQ7F2NYqiBPi/L2jqHyFtllhOUvXYQXf0Z1CYUinIfyT4bTCGmrA7gX9FvHA81uzCoVw==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.2.0.tgz", + "integrity": "sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==", "dev": true }, "agent-base": { @@ -3260,6 +3185,15 @@ "pify": "^4.0.1" } }, + "babel-plugin-dynamic-import-node": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz", + "integrity": "sha512-o6qFkpeQEBxcqt0XYlWzAVxNCSCZdUgcR8IRlhD/8DylxjjO4foPcvTW0GGKa/cVt3rvxZ7o5ippJ+/0nvLhlQ==", + "dev": true, + "requires": { + "object.assign": "^4.1.0" + } + }, "babel-plugin-inline-react-svg": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/babel-plugin-inline-react-svg/-/babel-plugin-inline-react-svg-1.1.0.tgz", @@ -3461,15 +3395,15 @@ } }, "bfj": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/bfj/-/bfj-6.1.1.tgz", - "integrity": "sha512-+GUNvzHR4nRyGybQc2WpNJL4MJazMuvf92ueIyA0bIkPRwhhQu3IfZQ2PSoVPpCBJfmoSdOxu5rnotfFLlvYRQ==", + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/bfj/-/bfj-6.1.2.tgz", + "integrity": "sha512-BmBJa4Lip6BPRINSZ0BPEIfB1wUY/9rwbwvIHQA1KjX9om29B6id0wnWXq7m3bn5JrUVjeOTnVuhPT1FiHwPGw==", "dev": true, "requires": { - "bluebird": "^3.5.1", - "check-types": "^7.3.0", - "hoopy": "^0.1.2", - "tryer": "^1.0.0" + "bluebird": "^3.5.5", + "check-types": "^8.0.3", + "hoopy": "^0.1.4", + "tryer": "^1.0.1" } }, "big.js": { @@ -3886,9 +3820,9 @@ } }, "caniuse-lite": { - "version": "1.0.30000978", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000978.tgz", - "integrity": "sha512-H6gK6kxUzG6oAwg/Jal279z8pHw0BzrpZfwo/CA9FFm/vA0l8IhDfkZtepyJNE2Y4V6Dp3P3ubz6czby1/Mgsw==", + "version": "1.0.30000979", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000979.tgz", + "integrity": "sha512-gcu45yfq3B7Y+WB05fOMfr0EiSlq+1u+m6rPHyJli/Wy3PVQNGaU7VA4bZE5qw+AU2UVOBR/N5g1bzADUqdvFw==", "dev": true }, "capture-exit": { @@ -3977,9 +3911,9 @@ } }, "check-types": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/check-types/-/check-types-7.4.0.tgz", - "integrity": "sha512-YbulWHdfP99UfZ73NcUDlNJhEIDgm9Doq9GhpyXbF+7Aegi3CVV7qqMCKTTqJxlvEvnQBp9IA+dxsGN6xK/nSg==", + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/check-types/-/check-types-8.0.3.tgz", + "integrity": "sha512-YpeKZngUmG65rLudJ4taU7VLkOCTMhNl/u4ctNC56LQS/zJTyNH0Lrtwm1tfTsbLlwvlfsA2d1c8vCf/Kh2KwQ==", "dev": true }, "cheerio": { @@ -4017,9 +3951,9 @@ } }, "chownr": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz", - "integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.2.tgz", + "integrity": "sha512-GkfeAQh+QNy3wquu9oIZr6SS5x7wGdSgNQvD10X3r+AZr1Oys22HW8kAmDMvNg2+Dm0TeGaEuO8gFwdBXxwO8A==", "dev": true }, "chrome-trace-event": { @@ -4439,9 +4373,9 @@ }, "dependencies": { "semver": { - "version": "6.1.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.1.2.tgz", - "integrity": "sha512-z4PqiCpomGtWj8633oeAdXm1Kn1W++3T8epkZYnwiVgIYIJ0QHszhInYSJTYxebByQH7KVCEAn8R9duzZW2PhQ==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.2.0.tgz", + "integrity": "sha512-jdFC1VdUGT/2Scgbimf7FSx9iJLXoqfglSF+gJeuNWVpiE37OIbc1jywR/GJyFdz3mnkz2/id0L0J/cr0izR5A==", "dev": true } } @@ -4858,18 +4792,18 @@ } }, "cssom": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.6.tgz", - "integrity": "sha512-DtUeseGk9/GBW0hl0vVPpU22iHL6YB5BUX7ml1hB+GMpo0NX5G4voX3kdWiMSEguFtcW3Vh3djqNF4aIe6ne0A==", + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.8.tgz", + "integrity": "sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==", "dev": true }, "cssstyle": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-1.2.2.tgz", - "integrity": "sha512-43wY3kl1CVQSvL7wUY1qXkxVGkStjpkDmVjiIKX8R97uhajy8Bybay78uOtqvh7Q5GK75dNPfW0geWjE6qQQow==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-1.3.0.tgz", + "integrity": "sha512-wXsoRfsRfsLVNaVzoKdqvEmK/5PFaEXNspVT22Ots6K/cnJdpoDKuQFw+qlMiXnmaif1OgeC466X1zISgAOcGg==", "dev": true, "requires": { - "cssom": "0.3.x" + "cssom": "~0.3.6" } }, "currently-unhandled": { @@ -5354,9 +5288,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.3.176", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.176.tgz", - "integrity": "sha512-hsQ/BH6x2iCvJ7WOIbNTAlsT39vsVGIVoJJ9i6ZkGXUE2LdzWsNv0xJI2uZ5/Hkqv1oTTLxAYjbtGKVJzqYbjA==", + "version": "1.3.186", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.186.tgz", + "integrity": "sha512-lRyyEUDKenKv/EBVFgfDZDYTDdoAZhzuE+inMUP79+22NDPAA2Ox+f3AShILIjPoUIqRGwvPNbzFcyU8km8g4A==", "dev": true }, "elliptic": { @@ -5720,11 +5654,12 @@ "dev": true }, "eslint-plugin-jsx-a11y": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.2.1.tgz", - "integrity": "sha512-cjN2ObWrRz0TTw7vEcGQrx+YltMvZoOEx4hWU8eEERDnBIU00OTq7Vr+jA7DFKxiwLNv4tTh5Pq2GUNEa8b6+w==", + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.2.3.tgz", + "integrity": "sha512-CawzfGt9w83tyuVekn0GDPU9ytYtxyxyFZ3aSWROmnRRFQFT2BiPJd7jvRdzNDi6oLWaS2asMeYSNMjWTV4eNg==", "dev": true, "requires": { + "@babel/runtime": "^7.4.5", "aria-query": "^3.0.0", "array-includes": "^3.0.3", "ast-types-flow": "^0.0.7", @@ -5732,7 +5667,7 @@ "damerau-levenshtein": "^1.0.4", "emoji-regex": "^7.0.2", "has": "^1.0.3", - "jsx-ast-utils": "^2.0.1" + "jsx-ast-utils": "^2.2.1" } }, "eslint-plugin-react": { @@ -7931,9 +7866,9 @@ } }, "import-fresh": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.0.0.tgz", - "integrity": "sha512-pOnA9tfM3Uwics+SaBLCNyZZZbK+4PTu0OPZtLlMIrv17EdBoC15S9Kn8ckJ9TZTyKb3ywNE5y1yeDxxGA7nTQ==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.1.0.tgz", + "integrity": "sha512-PpuksHKGt8rXfWEr9m9EHIpgyyaltBy8+eF6GJM0QCAxMgxCfucMF3mjecK2QsJr0amJW7gTqh5/wht0z2UhEQ==", "dev": true, "requires": { "parent-module": "^1.0.0", @@ -8533,9 +8468,9 @@ }, "dependencies": { "semver": { - "version": "6.1.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.1.2.tgz", - "integrity": "sha512-z4PqiCpomGtWj8633oeAdXm1Kn1W++3T8epkZYnwiVgIYIJ0QHszhInYSJTYxebByQH7KVCEAn8R9duzZW2PhQ==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.2.0.tgz", + "integrity": "sha512-jdFC1VdUGT/2Scgbimf7FSx9iJLXoqfglSF+gJeuNWVpiE37OIbc1jywR/GJyFdz3mnkz2/id0L0J/cr0izR5A==", "dev": true } } @@ -9593,9 +9528,9 @@ } }, "jsx-ast-utils": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.2.0.tgz", - "integrity": "sha512-yAmhGSzR7TsD0OQpu1AGLz8Bx84cxMqtgoJrufomY6BlveEDlREhvu1rea21936xbe5tlUh7IPda82m5ae0H8Q==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.2.1.tgz", + "integrity": "sha512-v3FxCcAf20DayI+uxnCuw795+oOIkVu6EnJ1+kSzhqqTZHNkTZ7B66ZgLp4oLJ/gbA64cI0B7WRoHZMSRdyVRQ==", "dev": true, "requires": { "array-includes": "^3.0.3", @@ -10473,9 +10408,9 @@ } }, "node-releases": { - "version": "1.1.24", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.24.tgz", - "integrity": "sha512-wym2jptfuKowMmkZsfCSTsn8qAVo8zm+UiQA6l5dNqUcpfChZSnS/vbbpOeXczf+VdPhutxh+99lWHhdd6xKzg==", + "version": "1.1.25", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.25.tgz", + "integrity": "sha512-fI5BXuk83lKEoZDdH3gRhtsNgh05/wZacuXkgbiYkceE7+QIMXOg98n9ZV7mz27B+kFHnqHcUpscZZlGRSmTpQ==", "dev": true, "requires": { "semver": "^5.3.0" @@ -12543,9 +12478,9 @@ "dev": true }, "psl": { - "version": "1.1.33", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.33.tgz", - "integrity": "sha512-LTDP2uSrsc7XCb5lO7A8BI1qYxRe/8EqlRvMeEl6rsnYAqDOl8xHR+8lSAIVfrNaSAlTPTNOCgNjWcoUL3AZsw==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.2.0.tgz", + "integrity": "sha512-GEn74ZffufCmkDDLNcl3uuyF/aSD6exEyh1v/ZSdAomB82t6G9hzJVRx0jBmLDW+VfZqks3aScmMw9DszwUalA==", "dev": true }, "public-encrypt": { @@ -12854,9 +12789,9 @@ } }, "react-spring": { - "version": "8.0.25", - "resolved": "https://registry.npmjs.org/react-spring/-/react-spring-8.0.25.tgz", - "integrity": "sha512-KLSLI9ccpoxvxzCbtTqSOHNHhndxAeEcHsgFZoyybP3GpGh0axmtauUAH8c3XkozIW8r9gScvrCWw3F1EPIcBw==", + "version": "8.0.27", + "resolved": "https://registry.npmjs.org/react-spring/-/react-spring-8.0.27.tgz", + "integrity": "sha512-nDpWBe3ZVezukNRandTeLSPcwwTMjNVu1IDq9qA/AMiUqHuRN4BeSWvKr3eIxxg1vtiYiOLy4FqdfCP5IoP77g==", "dev": true, "requires": { "@babel/runtime": "^7.3.1", @@ -12892,15 +12827,26 @@ } }, "react-with-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/react-with-styles/-/react-with-styles-3.2.1.tgz", - "integrity": "sha512-L+x/EDgrKkqV6pTfDtLMShf7Xs+bVQ+HAT5rByX88QYX+ft9t5Gn4PWMmg36Ur21IVEBMGjjQQIJGJpBrzbsyg==", + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/react-with-styles/-/react-with-styles-3.2.3.tgz", + "integrity": "sha512-MTI1UOvMHABRLj5M4WpODfwnveHaip6X7QUMI2x6zovinJiBXxzhA9AJP7MZNaKqg1JRFtHPXZdroUC8KcXwlQ==", "dev": true, "requires": { - "deepmerge": "^1.5.2", - "hoist-non-react-statics": "^2.5.0", - "prop-types": "^15.6.1", + "hoist-non-react-statics": "^3.2.1", + "object.assign": "^4.1.0", + "prop-types": "^15.6.2", "react-with-direction": "^1.3.0" + }, + "dependencies": { + "hoist-non-react-statics": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.0.tgz", + "integrity": "sha512-0XsbTXxgiaCDYDIWFcwkmerZPSwywfUqYmwT4jzewKTQSWoE6FCMoUVOeBJWK3E/CrWbxRG3m5GzY4lnIwGRBA==", + "dev": true, + "requires": { + "react-is": "^16.7.0" + } + } } }, "react-with-styles-interface-css": { @@ -13938,9 +13884,9 @@ } }, "sisteransi": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.0.tgz", - "integrity": "sha512-N+z4pHB4AmUv0SjveWRd6q1Nj5w62m5jodv+GD8lvmbY/83T/rpbJGZOnK5T149OldDj4Db07BSv9xY4K6NTPQ==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.2.tgz", + "integrity": "sha512-ZcYcZcT69nSLAR2oLN2JwNmLkJEKGooFMCdvOkFrToUt/WfcRWqhIg4P4KwY4dmLbuyXIx4o4YmPsvMRJYJd/w==", "dev": true }, "slash": { @@ -14601,16 +14547,16 @@ } }, "stylelint-scss": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-3.8.0.tgz", - "integrity": "sha512-J55tNmxXEh/ymhz5BiscIiUcHgPmJ2Nv+0+zgnqTqdQBe1URQbrdjlAyK3xq+7i2nVpWr2wlRj25SjoonZFcHg==", + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/stylelint-scss/-/stylelint-scss-3.9.0.tgz", + "integrity": "sha512-6uB2TPfIA/HybB7gERPFaBWHDBWhoLSjKoG0rQtsQ4LNOvWzJ205Q8JA2x9zZSXOJXatonlT9aGA1tyNBJrmcg==", "dev": true, "requires": { "lodash": "^4.17.11", "postcss-media-query-parser": "^0.2.3", "postcss-resolve-nested-selector": "^0.1.1", "postcss-selector-parser": "^6.0.2", - "postcss-value-parser": "^3.3.1" + "postcss-value-parser": "^4.0.0" }, "dependencies": { "postcss-selector-parser": { @@ -14623,6 +14569,12 @@ "indexes-of": "^1.0.1", "uniq": "^1.0.1" } + }, + "postcss-value-parser": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.0.0.tgz", + "integrity": "sha512-ESPktioptiSUchCKgggAkzdmkgzKfmp0EU8jXH+5kbIUB+unr0Y4CY9SRMvibuvYUBjNh1ACLbxqYNpdTQOteQ==", + "dev": true } } }, @@ -14794,9 +14746,9 @@ "dev": true }, "terser": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/terser/-/terser-4.0.0.tgz", - "integrity": "sha512-dOapGTU0hETFl1tCo4t56FN+2jffoKyER9qBGoUFyZ6y7WLoKT0bF+lAYi6B6YsILcGF3q1C2FBh8QcKSCgkgA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-4.0.2.tgz", + "integrity": "sha512-IWLuJqTvx97KP3uTYkFVn93cXO+EtlzJu8TdJylq+H0VBDlPMIfQA9MBS5Vc5t3xTEUG1q0hIfHMpAP2R+gWTw==", "dev": true, "requires": { "commander": "^2.19.0", From fbc27b9ba525921844267ec7282d4525c4490a0e Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 16:23:24 +0200 Subject: [PATCH 112/434] Update @babel/plugin-proposal-object-rest-spread --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8ec3ed48593..4840b42ef08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -344,9 +344,9 @@ } }, "@babel/plugin-proposal-object-rest-spread": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.4.4.tgz", - "integrity": "sha512-dMBG6cSPBbHeEBdFXeQ2QLc5gUpg4Vkaz8octD4aoW/ISO+jBOcsuxYL7bsb5WSu8RLP6boxrBIALEHgoHtO9g==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.5.0.tgz", + "integrity": "sha512-G1qy5EdcO3vYhbxlXjRSR2SXB8GsxYv9hoRKT1Jdn3qy/NUnFqUUnqymKZ00Pbj+3FXNh06B+BUZzecrp3sxNw==", "dev": true, "requires": { "@babel/helper-plugin-utils": "^7.0.0", diff --git a/package.json b/package.json index d6309a43662..2701d3392ef 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "devDependencies": { "@babel/cli": "7.5.0", "@babel/core": "7.5.0", - "@babel/plugin-proposal-object-rest-spread": "7.4.4", + "@babel/plugin-proposal-object-rest-spread": "7.5.0", "@babel/plugin-transform-react-jsx": "7.3.0", "@wordpress/babel-preset-default": "4.3.0", "@wordpress/block-editor": "2.2.0", From dc035af22ea65b52d07572826e42e50795e839b6 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Thu, 4 Jul 2019 21:15:07 +0200 Subject: [PATCH 113/434] Latest Stories: Filter out stories without featured image (#2740) --- .../blocks/amp-latest-stories/edit.js | 65 +++++++++---------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/assets/src/block-editor/blocks/amp-latest-stories/edit.js b/assets/src/block-editor/blocks/amp-latest-stories/edit.js index ff108e44467..8a07cb1e36a 100644 --- a/assets/src/block-editor/blocks/amp-latest-stories/edit.js +++ b/assets/src/block-editor/blocks/amp-latest-stories/edit.js @@ -50,47 +50,45 @@ class LatestStoriesEdit extends Component { const { attributes, setAttributes, latestStories } = this.props; const { order, orderBy, storiesToShow } = attributes; - const inspectorControls = ( - <InspectorControls> - <PanelBody title={ __( 'Latest Stories Settings', 'amp' ) }> - <QueryControls - { ...{ order, orderBy } } - numberOfItems={ storiesToShow } - onOrderChange={ ( value ) => setAttributes( { order: value } ) } - onOrderByChange={ ( value ) => setAttributes( { orderBy: value } ) } - onNumberOfItemsChange={ ( value ) => setAttributes( { storiesToShow: value } ) } - /> - </PanelBody> - </InspectorControls> - ); + const isLoading = ! Array.isArray( latestStories ); + const storiesWithFeaturedImages = ( latestStories || [] ).filter( ( { featured_media: image } ) => image > 0 ); + const hasStories = storiesWithFeaturedImages.length > 0; + + const serverSideAttributes = { + ...attributes, + useCarousel: false, + }; - const hasStories = Array.isArray( latestStories ) && latestStories.length; - if ( ! hasStories ) { - return ( - <> - { inspectorControls } + return ( + <> + <InspectorControls> + <PanelBody title={ __( 'Latest Stories Settings', 'amp' ) }> + <QueryControls + { ...{ order, orderBy } } + numberOfItems={ storiesToShow } + onOrderChange={ ( value ) => setAttributes( { order: value } ) } + onOrderByChange={ ( value ) => setAttributes( { orderBy: value } ) } + onNumberOfItemsChange={ ( value ) => setAttributes( { storiesToShow: value } ) } + /> + </PanelBody> + </InspectorControls> + { ( isLoading || ! hasStories ) && ( <Placeholder icon="admin-post" label={ __( 'Latest Stories', 'amp' ) } > - { ! Array.isArray( latestStories ) ? + { isLoading ? <Spinner /> : __( 'No stories found.', 'amp' ) } </Placeholder> - </> - ); - } - - const serverSideAttributes = Object.assign( {}, attributes, { useCarousel: false } ); - - return ( - <> - { inspectorControls } - <ServerSideRender - block={ blockName } - attributes={ serverSideAttributes } - /> + ) } + { hasStories && ( + <ServerSideRender + block={ blockName } + attributes={ serverSideAttributes } + /> + ) } </> ); } @@ -103,7 +101,7 @@ LatestStoriesEdit.propTypes = { storiesToShow: PropTypes.number, } ), setAttributes: PropTypes.func.isRequired, - latestStories: PropTypes.array.isRequired, + latestStories: PropTypes.array, }; export default withSelect( ( select, props ) => { @@ -114,6 +112,7 @@ export default withSelect( ( select, props ) => { orderby: orderBy, per_page: storiesToShow, }, ( value ) => ! isUndefined( value ) ); + return { latestStories: getEntityRecords( 'postType', 'amp_story', latestStoriesQuery ), }; From 895fe24260ea2b90da032575112203035b765260 Mon Sep 17 00:00:00 2001 From: Renovate Bot <bot@renovateapp.com> Date: Thu, 4 Jul 2019 19:30:45 +0000 Subject: [PATCH 114/434] Update dependency xwp/wp-dev-lib to v1.2.2 --- composer.json | 2 +- composer.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 4875d3fdc3f..3a8f2d45c5d 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "dealerdirect/phpcodesniffer-composer-installer": "0.5.0", "phpcompatibility/php-compatibility": "9.2.0", "wp-coding-standards/wpcs": "2.1.1", - "xwp/wp-dev-lib": "1.1.2" + "xwp/wp-dev-lib": "1.2.2" }, "suggest": { "ext-intl": "Enables use of idn_to_utf8() to convert punycode domains to UTF-8 for use with an AMP Cache.", diff --git a/composer.lock b/composer.lock index a983b30f05e..d804ce9c8f6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ecd0aabb4a23550adfc45df931fad743", + "content-hash": "6941955c5bceafd045587079552381f9", "packages": [ { "name": "cweagans/composer-patches", @@ -421,16 +421,16 @@ }, { "name": "xwp/wp-dev-lib", - "version": "1.1.2", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/xwp/wp-dev-lib.git", - "reference": "d8207e7cf749eaba5de5fb45c49cf7408ba741b6" + "reference": "a40a29223deb8f44e6d61db7e6c39bd12eb37919" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/xwp/wp-dev-lib/zipball/d8207e7cf749eaba5de5fb45c49cf7408ba741b6", - "reference": "d8207e7cf749eaba5de5fb45c49cf7408ba741b6", + "url": "https://api.github.com/repos/xwp/wp-dev-lib/zipball/a40a29223deb8f44e6d61db7e6c39bd12eb37919", + "reference": "a40a29223deb8f44e6d61db7e6c39bd12eb37919", "shasum": "" }, "type": "library", @@ -455,7 +455,7 @@ "keywords": [ "wordpress" ], - "time": "2019-06-05T20:06:16+00:00" + "time": "2019-07-04T15:04:40+00:00" } ], "aliases": [], From 6cb47db919bba6cd691e8c1e0c573c0a22f74a8b Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Fri, 5 Jul 2019 00:27:07 +0200 Subject: [PATCH 115/434] Determined tag name should not influence user font size (#2742) --- .../src/stories-editor/blocks/amp-story-text/edit.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/assets/src/stories-editor/blocks/amp-story-text/edit.js b/assets/src/stories-editor/blocks/amp-story-text/edit.js index b31b9179c1e..22ef781b801 100644 --- a/assets/src/stories-editor/blocks/amp-story-text/edit.js +++ b/assets/src/stories-editor/blocks/amp-story-text/edit.js @@ -90,18 +90,10 @@ class TextBlockEdit extends Component { ampFitText, autoFontSize, height, - tagName, opacity, } = attributes; - let userFontSize = fontSize && fontSize.size ? fontSize.size + 'px' : undefined; - if ( undefined === userFontSize ) { - if ( 'h1' === tagName ) { - userFontSize = 2 + 'rem'; - } else if ( 'h2' === tagName ) { - userFontSize = 1.5 + 'rem'; - } - } + const userFontSize = fontSize && fontSize.size ? fontSize.size + 'px' : undefined; const { colors } = select( 'core/block-editor' ).getSettings(); const appliedBackgroundColor = getBackgroundColorWithOpacity( colors, backgroundColor, customBackgroundColor, opacity ); From 36f26baae9ce036e10d9df059a1ba09677e5f16b Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Fri, 5 Jul 2019 10:51:58 +0200 Subject: [PATCH 116/434] Change block dimensions when text outgrows current one (#2744) --- .../blocks/amp-story-post-author/edit.css | 2 +- .../blocks/amp-story-post-date/edit.css | 2 +- .../blocks/amp-story-post-title/edit.css | 2 +- .../blocks/amp-story-text/edit.css | 2 +- .../blocks/amp-story-text/edit.js | 9 ++- .../components/with-meta-block-edit.js | 9 ++- assets/src/stories-editor/helpers/index.js | 65 ++++++++++++++++++- 7 files changed, 78 insertions(+), 13 deletions(-) diff --git a/assets/src/stories-editor/blocks/amp-story-post-author/edit.css b/assets/src/stories-editor/blocks/amp-story-post-author/edit.css index e84246fa7f1..2c090122ca1 100644 --- a/assets/src/stories-editor/blocks/amp-story-post-author/edit.css +++ b/assets/src/stories-editor/blocks/amp-story-post-author/edit.css @@ -16,7 +16,7 @@ display: block; } -.wp-block[data-type="amp/amp-story-post-author"] .wp-block-amp-amp-story-post-author.is-amp-fit-text.is-measuring-fontsize { +.wp-block[data-type="amp/amp-story-post-author"] .wp-block-amp-amp-story-post-author.is-measuring { height: initial !important; width: initial !important; position: absolute !important; diff --git a/assets/src/stories-editor/blocks/amp-story-post-date/edit.css b/assets/src/stories-editor/blocks/amp-story-post-date/edit.css index 57c5af21b97..99debcbaa7e 100644 --- a/assets/src/stories-editor/blocks/amp-story-post-date/edit.css +++ b/assets/src/stories-editor/blocks/amp-story-post-date/edit.css @@ -16,7 +16,7 @@ display: block; } -.wp-block[data-type="amp/amp-story-post-date"] .wp-block-amp-amp-story-post-date.is-amp-fit-text.is-measuring-fontsize { +.wp-block[data-type="amp/amp-story-post-date"] .wp-block-amp-amp-story-post-date.is-measuring { height: initial !important; width: initial !important; position: absolute !important; diff --git a/assets/src/stories-editor/blocks/amp-story-post-title/edit.css b/assets/src/stories-editor/blocks/amp-story-post-title/edit.css index 5ce1ff7a68b..47e05da4ed3 100644 --- a/assets/src/stories-editor/blocks/amp-story-post-title/edit.css +++ b/assets/src/stories-editor/blocks/amp-story-post-title/edit.css @@ -17,7 +17,7 @@ display: block; } -.wp-block[data-type="amp/amp-story-post-title"] .wp-block-amp-amp-story-post-title.is-amp-fit-text.is-measuring-fontsize { +.wp-block[data-type="amp/amp-story-post-title"] .wp-block-amp-amp-story-post-title.is-measuring { height: initial !important; width: initial !important; position: absolute !important; diff --git a/assets/src/stories-editor/blocks/amp-story-text/edit.css b/assets/src/stories-editor/blocks/amp-story-text/edit.css index 1541d9afabe..52fd04d190d 100644 --- a/assets/src/stories-editor/blocks/amp-story-text/edit.css +++ b/assets/src/stories-editor/blocks/amp-story-text/edit.css @@ -59,7 +59,7 @@ div[data-type="amp/amp-story-page"] .block-editor-inner-blocks .block-editor-blo line-height: 1.15; } -.wp-block[data-type="amp/amp-story-text"] .wp-block-amp-story-text .is-amp-fit-text.is-measuring-fontsize { +.wp-block[data-type="amp/amp-story-text"] .wp-block-amp-story-text .is-amp-fit-text.is-measuring { height: initial !important; width: initial !important; position: absolute !important; diff --git a/assets/src/stories-editor/blocks/amp-story-text/edit.js b/assets/src/stories-editor/blocks/amp-story-text/edit.js index 22ef781b801..ce8cbce10c9 100644 --- a/assets/src/stories-editor/blocks/amp-story-text/edit.js +++ b/assets/src/stories-editor/blocks/amp-story-text/edit.js @@ -3,6 +3,7 @@ */ import classnames from 'classnames'; import PropTypes from 'prop-types'; +import { isEqual } from 'lodash'; /** * WordPress dependencies @@ -19,7 +20,7 @@ import { select } from '@wordpress/data'; /** * Internal dependencies */ -import { maybeUpdateFontSize } from '../../helpers'; +import { maybeUpdateFontSize, maybeUpdateBlockDimensions } from '../../helpers'; import { getBackgroundColorWithOpacity } from '../../../common/helpers'; import './edit.css'; @@ -35,7 +36,7 @@ class TextBlockEdit extends Component { } componentDidUpdate( prevProps ) { - const { attributes } = this.props; + const { attributes, fontSize } = this.props; const { height, width, @@ -45,12 +46,14 @@ class TextBlockEdit extends Component { if ( prevProps.attributes.height === height && prevProps.attributes.width === width && - prevProps.attributes.content === content + prevProps.attributes.content === content && + isEqual( prevProps.fontSize, fontSize ) ) { return; } maybeUpdateFontSize( this.props ); + maybeUpdateBlockDimensions( this.props ); } onReplace( blocks ) { diff --git a/assets/src/stories-editor/components/with-meta-block-edit.js b/assets/src/stories-editor/components/with-meta-block-edit.js index 6aca70edc03..3fe2ceaa23c 100644 --- a/assets/src/stories-editor/components/with-meta-block-edit.js +++ b/assets/src/stories-editor/components/with-meta-block-edit.js @@ -3,6 +3,7 @@ */ import classnames from 'classnames'; import PropTypes from 'prop-types'; +import { isEqual } from 'lodash'; /** * WordPress dependencies @@ -21,7 +22,7 @@ import { dateI18n, __experimentalGetSettings as getDateSettings } from '@wordpre * Internal dependencies */ import { getBackgroundColorWithOpacity } from '../../common/helpers'; -import { maybeUpdateFontSize } from '../helpers'; +import { maybeUpdateFontSize, maybeUpdateBlockDimensions } from '../helpers'; // @todo: Use minimal <RichText> when props.isEditable is true. // @todo: Allow individual blocks to add custom controls. @@ -31,7 +32,7 @@ class MetaBlockEdit extends Component { } componentDidUpdate( prevProps ) { - const { attributes, isSelected } = this.props; + const { attributes, isSelected, fontSize } = this.props; const { height, width, @@ -41,12 +42,14 @@ class MetaBlockEdit extends Component { if ( ! isSelected && prevProps.attributes.height === height && - prevProps.attributes.width === width + prevProps.attributes.width === width && + isEqual( prevProps.fontSize, fontSize ) ) { return; } maybeUpdateFontSize( this.props ); + maybeUpdateBlockDimensions( this.props ); } render() { diff --git a/assets/src/stories-editor/helpers/index.js b/assets/src/stories-editor/helpers/index.js index e12b28347ca..7d79b665bc8 100644 --- a/assets/src/stories-editor/helpers/index.js +++ b/assets/src/stories-editor/helpers/index.js @@ -768,7 +768,7 @@ export const calculateFontSize = ( measurer, expectedHeight, expectedWidth, maxF if ( ! measurer.offsetHeight || ! measurer.offsetWidth ) { return false; } - measurer.classList.toggle( 'is-measuring-fontsize' ); + measurer.classList.toggle( 'is-measuring' ); maxFontSize++; @@ -788,7 +788,7 @@ export const calculateFontSize = ( measurer, expectedHeight, expectedWidth, maxF // Let's restore the correct font size, too. measurer.style.fontSize = minFontSize + 'px'; - measurer.classList.toggle( 'is-measuring-fontsize' ); + measurer.classList.toggle( 'is-measuring' ); return minFontSize; }; @@ -1153,7 +1153,7 @@ const getBlockInnerTextElement = ( block ) => { switch ( name ) { case 'amp/amp-story-text': - return document.querySelector( `#block-${ clientId } .block-editor-rich-text__editable.is-amp-fit-text` ); + return document.querySelector( `#block-${ clientId } .block-editor-rich-text__editable` ); case 'amp/amp-story-post-title': case 'amp/amp-story-post-author': @@ -1215,6 +1215,65 @@ export const maybeUpdateFontSize = ( block ) => { } }; +/** + * Updates a block's width and height in case it doesn't use amp-fit-text and the font size has changed. + * + * @param {Object} block Block object. + * @param {string} block.clientId Block client ID. + * @param {Object} block.attributes Block attributes. + * @param {number} block.attributes.width Block width in pixels. + * @param {number} block.attributes.height Block height in pixels. + * @param {string} block.attributes.content Block inner content. + * @param {boolean} block.attributes.ampFitText Whether amp-fit-text should be used or not. + * @param {number} block.attributes.autoFontSize Automatically determined font size for amp-fit-text blocks. + */ +export const maybeUpdateBlockDimensions = ( block ) => { + const { name, clientId, attributes } = block; + const { width, height, ampFitText, content } = attributes; + + if ( ampFitText ) { + return; + } + + switch ( name ) { + case 'amp/amp-story-text': + const element = getBlockInnerTextElement( block ); + + if ( element && content.length ) { + if ( element.offsetHeight > height ) { + updateBlockAttributes( clientId, { height: element.offsetHeight } ); + } + + if ( element.offsetWidth > width ) { + updateBlockAttributes( clientId, { width: element.offsetWidth } ); + } + } + + break; + + case 'amp/amp-story-post-title': + case 'amp/amp-story-post-author': + case 'amp/amp-story-post-date': + const metaBlockElement = getBlockInnerTextElement( block ); + + if ( metaBlockElement ) { + metaBlockElement.classList.toggle( 'is-measuring' ); + + if ( metaBlockElement.offsetHeight > height ) { + updateBlockAttributes( clientId, { height: metaBlockElement.offsetHeight } ); + } + + if ( metaBlockElement.offsetWidth > width ) { + updateBlockAttributes( clientId, { width: metaBlockElement.offsetWidth } ); + } + + metaBlockElement.classList.toggle( 'is-measuring' ); + } + + break; + } +}; + /** * Sets width and height for blocks if they haven't been modified yet. * From 25b2206c2c8ef95f352568df5795a67011a9dee8 Mon Sep 17 00:00:00 2001 From: Renovate Bot <bot@renovateapp.com> Date: Fri, 5 Jul 2019 21:30:52 +0000 Subject: [PATCH 117/434] Update dependency autoprefixer to v9.6.1 --- package-lock.json | 28 +++++++++++++++++++++------- package.json | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4840b42ef08..f85321eb8f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3103,18 +3103,32 @@ "dev": true }, "autoprefixer": { - "version": "9.6.0", - "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.6.0.tgz", - "integrity": "sha512-kuip9YilBqhirhHEGHaBTZKXL//xxGnzvsD0FtBQa6z+A69qZD6s/BAX9VzDF1i9VKDquTJDQaPLSEhOnL6FvQ==", + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.6.1.tgz", + "integrity": "sha512-aVo5WxR3VyvyJxcJC3h4FKfwCQvQWb1tSI5VHNibddCVWrcD1NvlxEweg3TSgiPztMnWfjpy2FURKA2kvDE+Tw==", "dev": true, "requires": { - "browserslist": "^4.6.1", - "caniuse-lite": "^1.0.30000971", + "browserslist": "^4.6.3", + "caniuse-lite": "^1.0.30000980", "chalk": "^2.4.2", "normalize-range": "^0.1.2", "num2fraction": "^1.2.2", - "postcss": "^7.0.16", - "postcss-value-parser": "^3.3.1" + "postcss": "^7.0.17", + "postcss-value-parser": "^4.0.0" + }, + "dependencies": { + "caniuse-lite": { + "version": "1.0.30000980", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000980.tgz", + "integrity": "sha512-as0PRtWHaX3gl2gpC7qA7bX88lr+qLacMMXm1QKLLQtBCwT/Ljbgrv5EXKMNBoeEX6yFZ4vIsBb4Nh+PEwW2Rw==", + "dev": true + }, + "postcss-value-parser": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.0.0.tgz", + "integrity": "sha512-ESPktioptiSUchCKgggAkzdmkgzKfmp0EU8jXH+5kbIUB+unr0Y4CY9SRMvibuvYUBjNh1ACLbxqYNpdTQOteQ==", + "dev": true + } } }, "autosize": { diff --git a/package.json b/package.json index 2701d3392ef..04f9a966c08 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "@wordpress/server-side-render": "1.0.0", "@wordpress/url": "2.6.0", "@wordpress/wordcount": "2.4.0", - "autoprefixer": "9.6.0", + "autoprefixer": "9.6.1", "babel-eslint": "10.0.2", "babel-jest": "24.8.0", "babel-loader": "8.0.6", From d2545edba73ff9f245b59a37acb41091f0506997 Mon Sep 17 00:00:00 2001 From: Renovate Bot <bot@renovateapp.com> Date: Mon, 8 Jul 2019 11:58:43 +0300 Subject: [PATCH 118/434] =?UTF-8?q?Update=20dependency=20@babel/plugin-pro?= =?UTF-8?q?posal-object-rest-spread=20to=E2=80=A6=20(#2752)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index f85321eb8f0..29d2c9e4ff3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -344,9 +344,9 @@ } }, "@babel/plugin-proposal-object-rest-spread": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.5.0.tgz", - "integrity": "sha512-G1qy5EdcO3vYhbxlXjRSR2SXB8GsxYv9hoRKT1Jdn3qy/NUnFqUUnqymKZ00Pbj+3FXNh06B+BUZzecrp3sxNw==", + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.5.1.tgz", + "integrity": "sha512-PVGXx5LYHcT7L4MdoE+rM5uq68IKlvU9lljVQ4OXY6aUEnGvezcGbM4VNY57Ug+3R2Zg/nYHlEdiWoIBoRA0mw==", "dev": true, "requires": { "@babel/helper-plugin-utils": "^7.0.0", diff --git a/package.json b/package.json index 04f9a966c08..0aca4fd2144 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "devDependencies": { "@babel/cli": "7.5.0", "@babel/core": "7.5.0", - "@babel/plugin-proposal-object-rest-spread": "7.5.0", + "@babel/plugin-proposal-object-rest-spread": "7.5.1", "@babel/plugin-transform-react-jsx": "7.3.0", "@wordpress/babel-preset-default": "4.3.0", "@wordpress/block-editor": "2.2.0", From 5b20586a8f287a822d7e48d67d3512cf49e46273 Mon Sep 17 00:00:00 2001 From: Weston Ruter <westonruter@google.com> Date: Mon, 8 Jul 2019 02:00:42 -0700 Subject: [PATCH 119/434] Ensure AMP customizer gets initialized in Reader mode (#2754) --- includes/admin/functions.php | 2 +- includes/settings/class-amp-customizer-design-settings.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/admin/functions.php b/includes/admin/functions.php index beaa1e24bc8..072181c9261 100644 --- a/includes/admin/functions.php +++ b/includes/admin/functions.php @@ -21,7 +21,7 @@ * And this does not need to toggle between the AMP and normal display. */ function amp_init_customizer() { - if ( amp_is_canonical() || ! AMP_Options_Manager::is_website_experience_enabled() ) { + if ( ! AMP_Options_Manager::is_website_experience_enabled() || AMP_Theme_Support::READER_MODE_SLUG !== AMP_Options_Manager::get_option( 'theme_support' ) ) { return; } diff --git a/includes/settings/class-amp-customizer-design-settings.php b/includes/settings/class-amp-customizer-design-settings.php index 0708bf121bd..d8e55fcaa90 100644 --- a/includes/settings/class-amp-customizer-design-settings.php +++ b/includes/settings/class-amp-customizer-design-settings.php @@ -41,7 +41,7 @@ class AMP_Customizer_Design_Settings { */ public static function is_amp_customizer_enabled() { - if ( current_theme_supports( 'amp' ) ) { + if ( AMP_Theme_Support::READER_MODE_SLUG !== AMP_Options_Manager::get_option( 'theme_support' ) ) { return false; } From a1e66c870ff75b5b0e1023e6b6a9deacfb917df9 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 14:25:11 +0200 Subject: [PATCH 120/434] Revert "Make string comparisons more readable" This partially reverts commit 5f378677a35b5041f6ca7ec684f9f1c8e92f8dc9. --- includes/class-amp-theme-support.php | 6 +-- includes/embeds/class-amp-facebook-embed.php | 2 +- .../sanitizers/class-amp-form-sanitizer.php | 4 +- .../sanitizers/class-amp-iframe-sanitizer.php | 2 +- .../sanitizers/class-amp-script-sanitizer.php | 2 +- .../sanitizers/class-amp-style-sanitizer.php | 38 +++++++++---------- .../class-amp-tag-and-attribute-sanitizer.php | 8 ++-- .../trait-amp-noscript-fallback.php | 2 +- .../class-amp-validated-url-post-type.php | 2 +- .../class-amp-validation-manager.php | 4 +- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 561409b2587..415d1cd6197 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -642,7 +642,7 @@ public static function get_template_availability( $query = null ) { } // If the callback is a method on the query, then call the method on the query itself. - if ( is_string( $callback ) && 0 === strpos( $callback, 'is_' ) && method_exists( $query, $callback ) ) { + if ( is_string( $callback ) && 'is_' === substr( $callback, 0, 3 ) && method_exists( $query, $callback ) ) { $is_match = call_user_func( array( $query, $callback ) ); } elseif ( is_callable( $callback ) ) { $is_match = $callback( $query ); @@ -1571,7 +1571,7 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles } foreach ( $head_scripts as $script ) { $src = $script->getAttribute( 'src' ); - if ( ! $src || 0 !== strpos( $src, 'https://cdn.ampproject.org/' ) ) { + if ( ! $src || 'https://cdn.ampproject.org/' !== substr( $src, 0, 27 ) ) { continue; } if ( $runtime_src === $src ) { @@ -1841,7 +1841,7 @@ public static function prepare_response( $response, $args = array() ) { } // Abort if the response was not HTML. - if ( 0 !== strpos( AMP_HTTP::get_response_content_type(), 'text/html' ) || 0 !== strpos( ltrim( $response ), '<' ) ) { + if ( 'text/html' !== substr( AMP_HTTP::get_response_content_type(), 0, 9 ) || '<' !== substr( ltrim( $response ), 0, 1 ) ) { return $response; } diff --git a/includes/embeds/class-amp-facebook-embed.php b/includes/embeds/class-amp-facebook-embed.php index 8419f80b5ed..6629761c67b 100644 --- a/includes/embeds/class-amp-facebook-embed.php +++ b/includes/embeds/class-amp-facebook-embed.php @@ -205,7 +205,7 @@ private function create_amp_facebook_and_replace_node( $dom, $node, $embed_type $node->removeAttribute( 'data-height' ); foreach ( $node->attributes as $attribute ) { - if ( 0 === strpos( $attribute->nodeName, 'data-' ) ) { + if ( 'data-' === substr( $attribute->nodeName, 0, 5 ) ) { $attributes[ $attribute->nodeName ] = $attribute->nodeValue; } } diff --git a/includes/sanitizers/class-amp-form-sanitizer.php b/includes/sanitizers/class-amp-form-sanitizer.php index 244d0230487..44ca4b947ab 100644 --- a/includes/sanitizers/class-amp-form-sanitizer.php +++ b/includes/sanitizers/class-amp-form-sanitizer.php @@ -75,7 +75,7 @@ public function sanitize() { $xhr_action = $node->getAttribute( 'action-xhr' ); // Make HTTP URLs protocol-less, since HTTPS is required for forms. - if ( 0 === stripos( $action_url, 'http://' ) ) { + if ( 'http://' === strtolower( substr( $action_url, 0, 7 ) ) ) { $action_url = substr( $action_url, 5 ); } @@ -100,7 +100,7 @@ public function sanitize() { $node->setAttribute( 'action-xhr', $action_url ); // Append success/error handlers if not found. $this->ensure_response_message_elements( $node ); - } elseif ( 0 === strpos( $xhr_action, 'http://' ) ) { + } elseif ( 'http://' === substr( $xhr_action, 0, 7 ) ) { $node->setAttribute( 'action-xhr', substr( $xhr_action, 5 ) ); } } diff --git a/includes/sanitizers/class-amp-iframe-sanitizer.php b/includes/sanitizers/class-amp-iframe-sanitizer.php index 3e69eb6160d..308235a4253 100644 --- a/includes/sanitizers/class-amp-iframe-sanitizer.php +++ b/includes/sanitizers/class-amp-iframe-sanitizer.php @@ -165,7 +165,7 @@ private function normalize_attributes( $attributes ) { switch ( $name ) { case 'src': // Make the URL absolute since relative URLs are not allowed in amp-iframe. - if ( 0 === strpos( $value, '/' ) && '/' !== substr( $value, 1, 1 ) ) { + if ( '/' === substr( $value, 0, 1 ) && '/' !== substr( $value, 1, 1 ) ) { $value = untrailingslashit( $this->args['current_origin'] ) . $value; } diff --git a/includes/sanitizers/class-amp-script-sanitizer.php b/includes/sanitizers/class-amp-script-sanitizer.php index 9e054b30538..54596652ce4 100644 --- a/includes/sanitizers/class-amp-script-sanitizer.php +++ b/includes/sanitizers/class-amp-script-sanitizer.php @@ -36,7 +36,7 @@ public function sanitize() { } // Skip noscript elements inside of amp-img or other AMP components for fallbacks. See \AMP_Img_Sanitizer::adjust_and_replace_node(). - if ( 0 === strpos( $noscript->parentNode->nodeName, 'amp-' ) ) { + if ( 'amp-' === substr( $noscript->parentNode->nodeName, 0, 4 ) ) { continue; } diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 3c10dcbdd43..1c87d0a6552 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -470,7 +470,7 @@ private function has_used_class_name( $class_names ) { foreach ( $class_names as $class_name ) { // Class names for amp-dynamic-css-classes, see <https://www.ampproject.org/docs/reference/components/amp-dynamic-css-classes>. - if ( 0 === strpos( $class_name, 'amp-referrer-' ) ) { + if ( 'amp-referrer-' === substr( $class_name, 0, 13 ) ) { continue; } @@ -487,7 +487,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-carousel, see <https://www.ampproject.org/docs/reference/components/amp-carousel#styling>. - if ( 0 === strpos( $class_name, 'amp-carousel-' ) ) { + if ( 'amp-carousel-' === substr( $class_name, 0, 13 ) ) { if ( ! $this->has_used_tag_names( array( 'amp-carousel' ) ) ) { return false; } @@ -495,7 +495,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-date-picker, see <https://www.ampproject.org/docs/reference/components/amp-date-picker>. - if ( 0 === strpos( $class_name, 'amp-date-picker-' ) ) { + if ( 'amp-date-picker-' === substr( $class_name, 0, 16 ) ) { if ( ! $this->has_used_tag_names( array( 'amp-date-picker' ) ) ) { return false; } @@ -503,7 +503,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-form, see <https://www.ampproject.org/docs/reference/components/amp-form#classes-and-css-hooks>. - if ( 0 === strpos( $class_name, 'amp-form-' ) || 'user-valid' === $class_name || 'user-invalid' === $class_name ) { + if ( 'amp-form-' === substr( $class_name, 0, 9 ) || 'user-valid' === $class_name || 'user-invalid' === $class_name ) { if ( ! $this->has_used_tag_names( array( 'form' ) ) ) { return false; } @@ -515,7 +515,7 @@ private function has_used_class_name( $class_names ) { * See <https://www.ampproject.org/docs/reference/components/amp-access>. * See <https://www.ampproject.org/docs/reference/components/amp-access-laterpay#styling> */ - if ( 0 === strpos( $class_name, 'amp-access-' ) ) { + if ( 'amp-access-' === substr( $class_name, 0, 11 ) ) { if ( ! $this->has_used_attributes( array( 'amp-access' ) ) ) { return false; } @@ -523,7 +523,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-geo, see <https://www.ampproject.org/docs/reference/components/amp-geo#generated-css-classes>. - if ( 0 === strpos( $class_name, 'amp-geo-' ) || 'amp-iso-country-' === substr( $class_name, 0, 16 ) ) { + if ( 'amp-geo-' === substr( $class_name, 0, 8 ) || 'amp-iso-country-' === substr( $class_name, 0, 16 ) ) { if ( ! $this->has_used_tag_names( array( 'amp-geo' ) ) ) { return false; } @@ -539,7 +539,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-live-list, see <https://www.ampproject.org/docs/reference/components/amp-live-list#styling>. - if ( 0 === strpos( $class_name, 'amp-live-list-' ) ) { + if ( 'amp-live-list-' === substr( $class_name, 0, 14 ) ) { if ( ! $this->has_used_tag_names( array( 'amp-live-list' ) ) ) { return false; } @@ -547,7 +547,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-sidebar, see <https://www.ampproject.org/docs/reference/components/amp-sidebar#styling-toolbar>. - if ( 0 === strpos( $class_name, 'amp-sidebar-' ) ) { + if ( 'amp-sidebar-' === substr( $class_name, 0, 12 ) ) { if ( ! $this->has_used_tag_names( array( 'amp-sidebar' ) ) ) { return false; } @@ -555,7 +555,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-sticky-ad, see <https://www.ampproject.org/docs/reference/components/amp-sticky-ad#styling>. - if ( 0 === strpos( $class_name, 'amp-sticky-ad-' ) ) { + if ( 'amp-sticky-ad-' === substr( $class_name, 0, 14 ) ) { if ( ! $this->has_used_tag_names( array( 'amp-sticky-ad' ) ) ) { return false; } @@ -563,7 +563,7 @@ private function has_used_class_name( $class_names ) { } // Class names for amp-video-docking, see <https://github.com/ampproject/amphtml/blob/master/extensions/amp-video-docking/amp-video-docking.md#styling>. - if ( 0 === strpos( $class_name, 'amp-docked-' ) ) { + if ( 'amp-docked-' === substr( $class_name, 0, 11 ) ) { if ( ! $this->has_used_attributes( array( 'dock' ) ) ) { return false; } @@ -1122,7 +1122,7 @@ private function process_link_element( DOMElement $element ) { * they don't implement the resource hint. */ $needs_preconnect_link = ( - 0 === strpos( $normalized_url, 'https://fonts.googleapis.com/' ) + 'https://fonts.googleapis.com/' === substr( $normalized_url, 0, 29 ) && 0 === $this->xpath->query( '//link[ @rel = "preconnect" and @crossorigin and starts-with( @href, "https://fonts.gstatic.com" ) ]', $this->head )->length ); @@ -1903,13 +1903,13 @@ private function real_path_urls( $urls, $stylesheet_url ) { $url_string = $url->getURL()->getString(); // For data: URLs, all that is needed is to remove spaces so set and continue. - if ( 0 === strpos( $url_string, 'data:' ) ) { + if ( 'data:' === substr( $url_string, 0, 5 ) ) { continue; } // If the URL is already absolute, continue since there there is nothing left to do. $parsed_url = wp_parse_url( $url_string ); - if ( ! empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) || 0 === strpos( $parsed_url['path'], '/' ) ) { + if ( ! empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) || '/' === substr( $parsed_url['path'], 0, 1 ) ) { continue; } @@ -2104,7 +2104,7 @@ private function process_font_face_at_rule( AtRuleSet $ruleset, $options ) { foreach ( $sources as $i => $source ) { if ( $source[0] instanceof URL ) { $value = $source[0]->getURL()->getString(); - if ( 0 === strpos( $value, 'data:' ) ) { + if ( 'data:' === substr( $value, 0, 5 ) ) { $source_data_url_objects[ $i ] = $source[0]; } else { $source_file_urls[ $i ] = $value; @@ -2713,7 +2713,7 @@ private function ampify_ruleset_selectors( $ruleset ) { ? $language !== $matches['lang'] : - 0 !== strpos( $language, $matches['lang'] ) + substr( $language, 0, strlen( $matches['lang'] ) ) !== $matches['lang'] ) ); if ( $is_other_language_root ) { @@ -2741,9 +2741,9 @@ static function ( $selector_language ) { * N: en-US && en-UK */ if ( - 0 === strpos( $language, $selector_language ) + substr( $language, 0, strlen( $selector_language ) ) === $selector_language || - 0 === strpos( $selector_language, $language ) + substr( $selector_language, 0, strlen( $language ) ) === $language ) { $has_matching_language = true; break; @@ -2880,7 +2880,7 @@ function( $id ) { $stylesheet_part_count = count( $stylesheet_parts ); for ( $i = 0; $i < $stylesheet_part_count; $i++ ) { $stylesheet_part = $stylesheet_parts[ $i ]; - if ( 0 !== strpos( $stylesheet_part, '@' ) ) { + if ( '@' !== substr( $stylesheet_part, 0, 1 ) ) { continue; } @@ -2897,7 +2897,7 @@ function( $id ) { $open_braces = 1; for ( $j = $i + 1; $j < $stylesheet_part_count; $j++ ) { $stylesheet_part = $stylesheet_parts[ $j ]; - $is_at_rule = 0 === strpos( $stylesheet_part, '@' ); + $is_at_rule = '@' === substr( $stylesheet_part, 0, 1 ); if ( empty( $stylesheet_part ) ) { continue; // There was a shaken rule. } diff --git a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php index 479db58d9d1..2bc6f208a02 100644 --- a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php +++ b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php @@ -235,7 +235,7 @@ public function get_scripts() { */ private function process_alternate_names( $attr_spec_list ) { foreach ( $attr_spec_list as $attr_name => &$attr_spec ) { - if ( 0 === strpos( $attr_name, '[' ) ) { + if ( '[' === $attr_name[0] ) { $placeholder_attr_name = $this->args['amp_bind_placeholder_prefix'] . trim( $attr_name, '[]' ); if ( ! isset( $attr_spec[ AMP_Rule_Spec::ALTERNATIVE_NAMES ] ) ) { $attr_spec[ AMP_Rule_Spec::ALTERNATIVE_NAMES ] = array(); @@ -595,7 +595,7 @@ private function process_node( $node ) { if ( $node instanceof DOMElement && ! in_array( 'amp-bind', $this->script_components, true ) ) { foreach ( $node->attributes as $name => $value ) { $is_bind_attribute = ( - 0 === strpos( $name, '[' ) + '[' === $name[0] || ( isset( $this->rev_alternate_attr_name_lookup[ $name ] ) && '[' === $this->rev_alternate_attr_name_lookup[ $name ][0] ) ); @@ -620,7 +620,7 @@ public function is_missing_mandatory_attribute( $attr_spec, $node ) { return false; } foreach ( $attr_spec as $attr_name => $attr_spec_rule_value ) { - if ( 0 === strpos( $attr_name, '\u' ) ) { + if ( '\u' === substr( $attr_name, 0, 2 ) ) { $attr_name = html_entity_decode( '&#x' . substr( $attr_name, 2 ) . ';' ); // Probably ⚡. } $is_mandatory = isset( $attr_spec_rule_value[ AMP_Rule_Spec::MANDATORY ] ) ? ( true === $attr_spec_rule_value[ AMP_Rule_Spec::MANDATORY ] ) : false; @@ -1665,7 +1665,7 @@ private function is_amp_allowed_attribute( $attr_node, $attr_spec_list ) { if ( isset( $attr_spec_list[ $attr_name ] ) || - 0 === strpos( $attr_name, 'data-' ) + 'data-' === substr( $attr_name, 0, 5 ) || // Allow the 'amp' or '⚡' attribute in <html>, like <html ⚡>. ( 'html' === $attr_node->parentNode->nodeName && in_array( $attr_node->nodeName, array( 'amp', '⚡' ), true ) ) diff --git a/includes/sanitizers/trait-amp-noscript-fallback.php b/includes/sanitizers/trait-amp-noscript-fallback.php index 6b8522f5a40..3dd251d2f0a 100644 --- a/includes/sanitizers/trait-amp-noscript-fallback.php +++ b/includes/sanitizers/trait-amp-noscript-fallback.php @@ -50,7 +50,7 @@ protected function initialize_noscript_allowed_attributes( $tag ) { * @return bool True if in an AMP noscript element, false otherwise. */ protected function is_inside_amp_noscript( \DOMNode $node ) { - return 'noscript' === $node->parentNode->nodeName && $node->parentNode->parentNode && 0 === strpos( $node->parentNode->parentNode->nodeName, 'amp-' ); + return 'noscript' === $node->parentNode->nodeName && $node->parentNode->parentNode && 'amp-' === substr( $node->parentNode->parentNode->nodeName, 0, 4 ); } /** diff --git a/includes/validation/class-amp-validated-url-post-type.php b/includes/validation/class-amp-validated-url-post-type.php index 45f1647b2a1..42aff2ede25 100644 --- a/includes/validation/class-amp-validated-url-post-type.php +++ b/includes/validation/class-amp-validated-url-post-type.php @@ -133,7 +133,7 @@ public static function register() { public static function handle_plugin_update( $old_version ) { // Update the old post type slug from amp_validated_url to amp_validated_url. - if ( 0 === strpos( $old_version, '1.0-' ) || version_compare( $old_version, '1.0', '<' ) ) { + if ( '1.0-' === substr( $old_version, 0, 4 ) || version_compare( $old_version, '1.0', '<' ) ) { global $wpdb; $post_ids = get_posts( array( diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index 80aa8673125..d3e6bf7c2c6 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -1820,7 +1820,7 @@ public static function validate_url( $url ) { } // Ensure absolute URL. - if ( 0 === strpos( $location_header, '/' ) ) { + if ( '/' === substr( $location_header, 0, 1 ) ) { $location_header = preg_replace( '#(^https?://[^/]+)/.*#', '$1', home_url( '/' ) ) . $location_header; } @@ -1849,7 +1849,7 @@ public static function validate_url( $url ) { ); $response = wp_remote_retrieve_body( $r ); - if ( '' === trim( $response ) ) { + if ( trim( $response ) === '' ) { $error_code = 'white_screen_of_death'; return new WP_Error( $error_code, self::get_validate_url_error_message( $error_code ) ); } From 60c7ea5ebc4bc3c746c2148ab50f2a5296c83dcd Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 14:35:31 +0200 Subject: [PATCH 121/434] Extract variable for better readability --- includes/embeds/class-amp-core-block-handler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/embeds/class-amp-core-block-handler.php b/includes/embeds/class-amp-core-block-handler.php index 28cf1728cfc..75cd0df955f 100644 --- a/includes/embeds/class-amp-core-block-handler.php +++ b/includes/embeds/class-amp-core-block-handler.php @@ -49,7 +49,8 @@ public function filter_rendered_block( $block_content, $block ) { return $block_content; } if ( isset( $this->block_ampify_methods[ $block['blockName'] ] ) ) { - $block_content = $this->{$this->block_ampify_methods[ $block['blockName'] ]}( $block_content, $block ); + $method_name = $this->block_ampify_methods[ $block['blockName'] ]; + $block_content = $this->{$method_name}( $block_content, $block ); } elseif ( 'core/image' === $block['blockName'] || 'core/audio' === $block['blockName'] ) { /* * While the video block placeholder just outputs an empty video element, the placeholders for image and From e5a7a7938534374f932b258c4f5e9e24b72ef3cf Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 14:40:11 +0200 Subject: [PATCH 122/434] Update phpdoc for callable --- includes/validation/class-amp-validation-manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index d3e6bf7c2c6..f47b668293f 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -1390,7 +1390,7 @@ public static function decorate_filter_source( $value ) { /** * Gets the plugin or theme of the callback, if one exists. * - * @param string|array $callback The callback for which to get the plugin. + * @param string|array|callable $callback The callback for which to get the plugin. * @return array|null { * The source data. * From bc0088ece9bc218cbdbcc780dbf0d4255604d406 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 14:45:23 +0200 Subject: [PATCH 123/434] Remove some unnecessary qualifiers Makes code more consistent --- amp.php | 6 +++--- bin/add-test-widgets-to-sidebar.php | 2 +- bin/create-embed-test-post.php | 2 +- includes/class-amp-theme-support.php | 2 +- .../sanitizers/trait-amp-noscript-fallback.php | 18 ++++++++++-------- .../templates/class-amp-content-sanitizer.php | 2 +- includes/templates/class-amp-content.php | 2 +- includes/templates/class-amp-post-template.php | 2 +- .../class-amp-image-dimension-extractor.php | 2 +- .../class-amp-validated-url-post-type.php | 15 ++++++++------- .../class-amp-validation-error-taxonomy.php | 2 +- tests/php/test-amp-helper-functions.php | 2 +- tests/php/test-class-amp-admin-pointer.php | 2 +- tests/php/test-class-amp-cli.php | 2 +- tests/php/test-class-amp-editor-blocks.php | 2 +- tests/php/test-class-amp-service-worker.php | 2 +- .../test-class-amp-validated-url-post-type.php | 2 +- ...est-class-amp-validation-error-taxonomy.php | 2 +- .../test-class-amp-validation-manager.php | 2 +- 19 files changed, 37 insertions(+), 34 deletions(-) diff --git a/amp.php b/amp.php index 2945510f724..f0e625ab180 100644 --- a/amp.php +++ b/amp.php @@ -18,11 +18,11 @@ * * This has to be a global for the same of PHP 5.2. * - * @var \WP_Error $_amp_load_errors + * @var WP_Error $_amp_load_errors */ global $_amp_load_errors; -$_amp_load_errors = new \WP_Error(); +$_amp_load_errors = new WP_Error(); if ( version_compare( phpversion(), '5.4', '<' ) ) { $_amp_load_errors->add( @@ -160,7 +160,7 @@ * Displays an admin notice about why the plugin is unable to load. * * @since 1.1.2 - * @global \WP_Error $_amp_load_errors + * @global WP_Error $_amp_load_errors */ function _amp_show_load_errors_admin_notice() { global $_amp_load_errors; diff --git a/bin/add-test-widgets-to-sidebar.php b/bin/add-test-widgets-to-sidebar.php index b2c363af19f..153ff9a4593 100644 --- a/bin/add-test-widgets-to-sidebar.php +++ b/bin/add-test-widgets-to-sidebar.php @@ -276,7 +276,7 @@ function amp_image_widget() { * @return array|WP_CLI::error The media IDs, or an error on failure. */ function amp_media( $type, $count = 3 ) { - $query = new \WP_Query( + $query = new WP_Query( array( 'post_type' => 'attachment', 'post_mime_type' => $type, diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 36ffb96b125..6fa2925d972 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -227,7 +227,7 @@ function amp_get_test_data_entries() { * @return string|WP_CLI::error The media item ids separated by comma on success; error otherwise. */ function amp_get_media_items_ids( $type, $image_count = 3 ) { - $query = new \WP_Query( + $query = new WP_Query( array( 'post_type' => 'attachment', 'post_mime_type' => $type, diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 415d1cd6197..f30e2544209 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -1140,7 +1140,7 @@ public static function register_content_embed_handlers() { ) ); - if ( ! $embed_handler instanceof \AMP_Base_Embed_Handler ) { + if ( ! $embed_handler instanceof AMP_Base_Embed_Handler ) { _doing_it_wrong( __METHOD__, esc_html( diff --git a/includes/sanitizers/trait-amp-noscript-fallback.php b/includes/sanitizers/trait-amp-noscript-fallback.php index 3dd251d2f0a..4f3fd977a7c 100644 --- a/includes/sanitizers/trait-amp-noscript-fallback.php +++ b/includes/sanitizers/trait-amp-noscript-fallback.php @@ -44,25 +44,27 @@ protected function initialize_noscript_allowed_attributes( $tag ) { /** * Checks whether the given node is within an AMP-specific <noscript> element. * - * @since 1.1 + * @param DOMNode $node DOM node to check. * - * @param \DOMNode $node DOM node to check. * @return bool True if in an AMP noscript element, false otherwise. + *@since 1.1 + * */ - protected function is_inside_amp_noscript( \DOMNode $node ) { + protected function is_inside_amp_noscript( DOMNode $node ) { return 'noscript' === $node->parentNode->nodeName && $node->parentNode->parentNode && 'amp-' === substr( $node->parentNode->parentNode->nodeName, 0, 4 ); } /** * Appends the given old node in a <noscript> element to the new node. * - * @since 1.1 + * @param DOMNode $new_node New node to append a noscript with the old node to. + * @param DOMNode $old_node Old node to append in a noscript. + * @param DOMDocument $dom DOM document instance. + * + *@since 1.1 * - * @param \DOMNode $new_node New node to append a noscript with the old node to. - * @param \DOMNode $old_node Old node to append in a noscript. - * @param \DOMDocument $dom DOM document instance. */ - protected function append_old_node_noscript( \DOMNode $new_node, \DOMNode $old_node, \DOMDocument $dom ) { + protected function append_old_node_noscript( DOMNode $new_node, DOMNode $old_node, DOMDocument $dom ) { $noscript = $dom->createElement( 'noscript' ); $noscript->appendChild( $old_node ); $new_node->appendChild( $noscript ); diff --git a/includes/templates/class-amp-content-sanitizer.php b/includes/templates/class-amp-content-sanitizer.php index 3559712bca0..110787d1396 100644 --- a/includes/templates/class-amp-content-sanitizer.php +++ b/includes/templates/class-amp-content-sanitizer.php @@ -86,7 +86,7 @@ public static function sanitize_document( &$dom, $sanitizer_classes, $args ) { */ $sanitizer = new $sanitizer_class( $dom, array_merge( $args, $sanitizer_args ) ); - if ( ! $sanitizer instanceof \AMP_Base_Sanitizer ) { + if ( ! $sanitizer instanceof AMP_Base_Sanitizer ) { _doing_it_wrong( __METHOD__, esc_html( diff --git a/includes/templates/class-amp-content.php b/includes/templates/class-amp-content.php index b8a8ff68662..14fc86ebe04 100644 --- a/includes/templates/class-amp-content.php +++ b/includes/templates/class-amp-content.php @@ -165,7 +165,7 @@ private function register_embed_handlers( $embed_handler_classes ) { foreach ( $embed_handler_classes as $embed_handler_class => $args ) { $embed_handler = new $embed_handler_class( array_merge( $this->args, $args ) ); - if ( ! $embed_handler instanceof \AMP_Base_Embed_Handler ) { + if ( ! $embed_handler instanceof AMP_Base_Embed_Handler ) { _doing_it_wrong( __METHOD__, esc_html( diff --git a/includes/templates/class-amp-post-template.php b/includes/templates/class-amp-post-template.php index 79eda16fe40..7b53b090920 100644 --- a/includes/templates/class-amp-post-template.php +++ b/includes/templates/class-amp-post-template.php @@ -96,7 +96,7 @@ public function __construct( $post ) { } // Make sure we have a post, or bail if not. - if ( $this->post instanceof \WP_Post ) { + if ( $this->post instanceof WP_Post ) { $this->ID = $this->post->ID; } else { return; diff --git a/includes/utils/class-amp-image-dimension-extractor.php b/includes/utils/class-amp-image-dimension-extractor.php index 940aeafacfb..34d3f0983a1 100644 --- a/includes/utils/class-amp-image-dimension-extractor.php +++ b/includes/utils/class-amp-image-dimension-extractor.php @@ -156,7 +156,7 @@ public static function extract_by_downloading_images( $dimensions, $mode = false try { self::fetch_images( $urls_to_fetch, $images ); self::process_fetched_images( $urls_to_fetch, $images, $dimensions, $transient_expiration ); - } catch ( \Exception $exception ) { + } catch ( Exception $exception ) { trigger_error( esc_html( $exception->getMessage() ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error } diff --git a/includes/validation/class-amp-validated-url-post-type.php b/includes/validation/class-amp-validated-url-post-type.php index 42aff2ede25..94ea4b35af9 100644 --- a/includes/validation/class-amp-validated-url-post-type.php +++ b/includes/validation/class-amp-validated-url-post-type.php @@ -886,7 +886,7 @@ public static function add_post_columns( $columns ) { $columns['date'] = esc_html__( 'Last Checked', 'amp' ); } - if ( ! empty( $_GET[ \AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( ! empty( $_GET[ AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended unset( $columns['error_status'], $columns[ AMP_Validation_Error_Taxonomy::REMOVED_ELEMENTS ], $columns[ AMP_Validation_Error_Taxonomy::REMOVED_ATTRIBUTES ] ); $columns[ AMP_Validation_Error_Taxonomy::SOURCES_INVALID_OUTPUT ] = esc_html__( 'Sources', 'amp' ); $columns['date'] = esc_html__( 'Last Checked', 'amp' ); @@ -1290,8 +1290,8 @@ public static function print_admin_notice() { * 1. Notice with detailed error information in an expanding box. * 2. Notice with accept and reject buttons. */ - if ( ! empty( $_GET[ \AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) && isset( $_GET['post_type'] ) && self::POST_TYPE_SLUG === $_GET['post_type'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $error_id = sanitize_key( wp_unslash( $_GET[ \AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( ! empty( $_GET[ AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) && isset( $_GET['post_type'] ) && self::POST_TYPE_SLUG === $_GET['post_type'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $error_id = sanitize_key( wp_unslash( $_GET[ AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $error = AMP_Validation_Error_Taxonomy::get_term( $error_id ); if ( ! $error ) { @@ -1300,10 +1300,10 @@ public static function print_admin_notice() { // @todo Update this to use the method which will be developed in PR #1429 AMP_Validation_Error_Taxonomy::get_term_error() . $description = json_decode( $error->description, true ); - $sanitization = \AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $description ); - $status_text = \AMP_Validation_Error_Taxonomy::get_status_text_with_icon( $sanitization ); + $sanitization = AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $description ); + $status_text = AMP_Validation_Error_Taxonomy::get_status_text_with_icon( $sanitization ); $error_code = isset( $description['code'] ) ? $description['code'] : 'error'; - $error_title = \AMP_Validation_Error_Taxonomy::get_error_title_from_code( $error_code ); + $error_title = AMP_Validation_Error_Taxonomy::get_error_title_from_code( $error_code ); $validation_error = json_decode( $error->description, true ); $accept_all_url = wp_nonce_url( add_query_arg( @@ -2148,7 +2148,8 @@ public static function get_single_url_page_heading() { * Manages links for details, recheck, view, forget, and forget permanently. * * @param array $actions Row action links. - * @param \WP_Post $post Current WP post. + * @param WP_Post $post Current WP post. + * * @return array Filtered action links. */ public static function filter_post_row_actions( $actions, $post ) { diff --git a/includes/validation/class-amp-validation-error-taxonomy.php b/includes/validation/class-amp-validation-error-taxonomy.php index d55f41fdc59..4550da7045d 100644 --- a/includes/validation/class-amp-validation-error-taxonomy.php +++ b/includes/validation/class-amp-validation-error-taxonomy.php @@ -2128,7 +2128,7 @@ public static function handle_inline_edit_request() { } // If we have a post_type check that it is the correct one. - if ( isset( $_GET['post_type'] ) && \AMP_Validated_URL_Post_Type::POST_TYPE_SLUG !== $_GET['post_type'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $_GET['post_type'] ) && AMP_Validated_URL_Post_Type::POST_TYPE_SLUG !== $_GET['post_type'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } $action = sanitize_key( $_GET['action'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended diff --git a/tests/php/test-amp-helper-functions.php b/tests/php/test-amp-helper-functions.php index 90e8683c952..00614cd8f2e 100644 --- a/tests/php/test-amp-helper-functions.php +++ b/tests/php/test-amp-helper-functions.php @@ -978,7 +978,7 @@ static function( $meta ) use ( $self ) { * Test amp_add_admin_bar_view_link() * * @covers ::amp_add_admin_bar_view_link() - * @global \WP_Query $wp_query + * @global WP_Query $wp_query */ public function test_amp_add_admin_bar_item() { require_once ABSPATH . WPINC . '/class-wp-admin-bar.php'; diff --git a/tests/php/test-class-amp-admin-pointer.php b/tests/php/test-class-amp-admin-pointer.php index 6fd23742444..b1ac23a2ea3 100644 --- a/tests/php/test-class-amp-admin-pointer.php +++ b/tests/php/test-class-amp-admin-pointer.php @@ -11,7 +11,7 @@ * @covers AMP_Admin_Pointers * @since 1.0 */ -class Test_AMP_Admin_Pointers extends \WP_UnitTestCase { +class Test_AMP_Admin_Pointers extends WP_UnitTestCase { /** * The meta key of the dismissed pointers. diff --git a/tests/php/test-class-amp-cli.php b/tests/php/test-class-amp-cli.php index 7fef66c2cc4..acd9a73ef3c 100644 --- a/tests/php/test-class-amp-cli.php +++ b/tests/php/test-class-amp-cli.php @@ -10,7 +10,7 @@ * * @since 1.0 */ -class Test_AMP_CLI extends \WP_UnitTestCase { +class Test_AMP_CLI extends WP_UnitTestCase { /** * Setup. diff --git a/tests/php/test-class-amp-editor-blocks.php b/tests/php/test-class-amp-editor-blocks.php index 21adc417065..fc0e70e6591 100644 --- a/tests/php/test-class-amp-editor-blocks.php +++ b/tests/php/test-class-amp-editor-blocks.php @@ -10,7 +10,7 @@ * * @covers AMP_Editor_Blocks */ -class Test_AMP_Editor_Blocks extends \WP_UnitTestCase { +class Test_AMP_Editor_Blocks extends WP_UnitTestCase { /** * The tested instance. diff --git a/tests/php/test-class-amp-service-worker.php b/tests/php/test-class-amp-service-worker.php index 3cd43ac82db..6a0e3b8c08a 100644 --- a/tests/php/test-class-amp-service-worker.php +++ b/tests/php/test-class-amp-service-worker.php @@ -236,7 +236,7 @@ static function () { ob_start(); $exception = null; try { - $this->go_to( add_query_arg( \AMP_Service_Worker::INSTALL_SERVICE_WORKER_IFRAME_QUERY_VAR, '1', home_url() ) ); + $this->go_to( add_query_arg( AMP_Service_Worker::INSTALL_SERVICE_WORKER_IFRAME_QUERY_VAR, '1', home_url() ) ); } catch ( Exception $e ) { $exception = $e; } diff --git a/tests/php/validation/test-class-amp-validated-url-post-type.php b/tests/php/validation/test-class-amp-validated-url-post-type.php index f11b3fac635..c199483d9f1 100644 --- a/tests/php/validation/test-class-amp-validated-url-post-type.php +++ b/tests/php/validation/test-class-amp-validated-url-post-type.php @@ -12,7 +12,7 @@ * * @covers AMP_Validated_URL_Post_Type */ -class Test_AMP_Validated_URL_Post_Type extends \WP_UnitTestCase { +class Test_AMP_Validated_URL_Post_Type extends WP_UnitTestCase { const TESTED_CLASS = 'AMP_Validated_URL_Post_Type'; diff --git a/tests/php/validation/test-class-amp-validation-error-taxonomy.php b/tests/php/validation/test-class-amp-validation-error-taxonomy.php index fc616170319..9731df78374 100644 --- a/tests/php/validation/test-class-amp-validation-error-taxonomy.php +++ b/tests/php/validation/test-class-amp-validation-error-taxonomy.php @@ -10,7 +10,7 @@ * * @covers AMP_Validation_Error_Taxonomy */ -class Test_AMP_Validation_Error_Taxonomy extends \WP_UnitTestCase { +class Test_AMP_Validation_Error_Taxonomy extends WP_UnitTestCase { /** * The tested class. diff --git a/tests/php/validation/test-class-amp-validation-manager.php b/tests/php/validation/test-class-amp-validation-manager.php index 81de5385339..96aff5d0ec5 100644 --- a/tests/php/validation/test-class-amp-validation-manager.php +++ b/tests/php/validation/test-class-amp-validation-manager.php @@ -13,7 +13,7 @@ * @covers AMP_Validation_Manager * @since 0.7 */ -class Test_AMP_Validation_Manager extends \WP_UnitTestCase { +class Test_AMP_Validation_Manager extends WP_UnitTestCase { /** * The name of the tested class. From 75ff9b12aafe41dd7abc912d136bb124ba26346f Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 15:11:10 +0200 Subject: [PATCH 124/434] Lint fixes --- includes/embeds/class-amp-core-block-handler.php | 2 +- includes/sanitizers/trait-amp-noscript-fallback.php | 6 ++---- includes/validation/class-amp-validated-url-post-type.php | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/includes/embeds/class-amp-core-block-handler.php b/includes/embeds/class-amp-core-block-handler.php index 75cd0df955f..dfdb25d9a99 100644 --- a/includes/embeds/class-amp-core-block-handler.php +++ b/includes/embeds/class-amp-core-block-handler.php @@ -49,7 +49,7 @@ public function filter_rendered_block( $block_content, $block ) { return $block_content; } if ( isset( $this->block_ampify_methods[ $block['blockName'] ] ) ) { - $method_name = $this->block_ampify_methods[ $block['blockName'] ]; + $method_name = $this->block_ampify_methods[ $block['blockName'] ]; $block_content = $this->{$method_name}( $block_content, $block ); } elseif ( 'core/image' === $block['blockName'] || 'core/audio' === $block['blockName'] ) { /* diff --git a/includes/sanitizers/trait-amp-noscript-fallback.php b/includes/sanitizers/trait-amp-noscript-fallback.php index 4f3fd977a7c..a69c9d1d2fe 100644 --- a/includes/sanitizers/trait-amp-noscript-fallback.php +++ b/includes/sanitizers/trait-amp-noscript-fallback.php @@ -47,8 +47,7 @@ protected function initialize_noscript_allowed_attributes( $tag ) { * @param DOMNode $node DOM node to check. * * @return bool True if in an AMP noscript element, false otherwise. - *@since 1.1 - * + * @since 1.1 */ protected function is_inside_amp_noscript( DOMNode $node ) { return 'noscript' === $node->parentNode->nodeName && $node->parentNode->parentNode && 'amp-' === substr( $node->parentNode->parentNode->nodeName, 0, 4 ); @@ -61,8 +60,7 @@ protected function is_inside_amp_noscript( DOMNode $node ) { * @param DOMNode $old_node Old node to append in a noscript. * @param DOMDocument $dom DOM document instance. * - *@since 1.1 - * + * @since 1.1 */ protected function append_old_node_noscript( DOMNode $new_node, DOMNode $old_node, DOMDocument $dom ) { $noscript = $dom->createElement( 'noscript' ); diff --git a/includes/validation/class-amp-validated-url-post-type.php b/includes/validation/class-amp-validated-url-post-type.php index 94ea4b35af9..2a4c7a8811b 100644 --- a/includes/validation/class-amp-validated-url-post-type.php +++ b/includes/validation/class-amp-validated-url-post-type.php @@ -2147,7 +2147,7 @@ public static function get_single_url_page_heading() { * * Manages links for details, recheck, view, forget, and forget permanently. * - * @param array $actions Row action links. + * @param array $actions Row action links. * @param WP_Post $post Current WP post. * * @return array Filtered action links. From 5598393ac6fc79df4c317d7eedc0fd3e19b551e9 Mon Sep 17 00:00:00 2001 From: Renovate Bot <bot@renovateapp.com> Date: Mon, 8 Jul 2019 17:45:42 +0300 Subject: [PATCH 125/434] Update dependency webpack to v4.35.3 (#2763) --- package-lock.json | 15 ++++----------- package.json | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 29d2c9e4ff3..f403bf7b01c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2720,12 +2720,6 @@ "integrity": "sha512-8oe72N3WPMjA+2zVG71Ia0nXZ8DpQH+QyyHO+p06jT8eg8FGG3FbcUIi8KziHlAfheJQZeoqbvq1mQSQHXKYLw==", "dev": true }, - "acorn-dynamic-import": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz", - "integrity": "sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw==", - "dev": true - }, "acorn-globals": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-4.3.2.tgz", @@ -15996,17 +15990,16 @@ "dev": true }, "webpack": { - "version": "4.35.2", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.35.2.tgz", - "integrity": "sha512-TZAmorNymV4q66gAM/h90cEjG+N3627Q2MnkSgKlX/z3DlNVKUtqy57lz1WmZU2+FUZwzM+qm7cGaO95PyrX5A==", + "version": "4.35.3", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.35.3.tgz", + "integrity": "sha512-xggQPwr9ILlXzz61lHzjvgoqGU08v5+Wnut19Uv3GaTtzN4xBTcwnobodrXE142EL1tOiS5WVEButooGzcQzTA==", "dev": true, "requires": { "@webassemblyjs/ast": "1.8.5", "@webassemblyjs/helper-module-context": "1.8.5", "@webassemblyjs/wasm-edit": "1.8.5", "@webassemblyjs/wasm-parser": "1.8.5", - "acorn": "^6.0.5", - "acorn-dynamic-import": "^4.0.0", + "acorn": "^6.2.0", "ajv": "^6.1.0", "ajv-keywords": "^3.1.0", "chrome-trace-event": "^1.0.0", diff --git a/package.json b/package.json index 0aca4fd2144..ead357ca218 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "svg-inline-loader": "0.8.0", "terser-webpack-plugin": "1.3.0", "uuid": "3.3.2", - "webpack": "4.35.2", + "webpack": "4.35.3", "webpack-cli": "3.3.5" }, "scripts": { From afa8adda95b1c77dc7987d43e2e318b6c1d626a0 Mon Sep 17 00:00:00 2001 From: Renovate Bot <bot@renovateapp.com> Date: Mon, 8 Jul 2019 19:32:44 +0300 Subject: [PATCH 126/434] Update dependency browserslist to v4.6.4 (#2764) --- package-lock.json | 26 +++++++++++++++++--------- package.json | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index f403bf7b01c..a08710b8c34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3644,14 +3644,22 @@ } }, "browserslist": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.6.3.tgz", - "integrity": "sha512-CNBqTCq22RKM8wKJNowcqihHJ4SkI8CGeK7KOR9tPboXUuS5Zk5lQgzzTbs4oxD8x+6HUshZUa2OyNI9lR93bQ==", + "version": "4.6.4", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.6.4.tgz", + "integrity": "sha512-ErJT8qGfRt/VWHSr1HeqZzz50DvxHtr1fVL1m5wf20aGrG8e1ce8fpZ2EjZEfs09DDZYSvtRaDlMpWslBf8Low==", "dev": true, "requires": { - "caniuse-lite": "^1.0.30000975", - "electron-to-chromium": "^1.3.164", - "node-releases": "^1.1.23" + "caniuse-lite": "^1.0.30000981", + "electron-to-chromium": "^1.3.188", + "node-releases": "^1.1.25" + }, + "dependencies": { + "caniuse-lite": { + "version": "1.0.30000981", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000981.tgz", + "integrity": "sha512-JTByHj4DQgL2crHNMK6PibqAMrqqb/Vvh0JrsTJVSWG4VSUrT16EklkuRZofurlMjgA9e+zlCM4Y39F3kootMQ==", + "dev": true + } } }, "bser": { @@ -5296,9 +5304,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.3.186", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.186.tgz", - "integrity": "sha512-lRyyEUDKenKv/EBVFgfDZDYTDdoAZhzuE+inMUP79+22NDPAA2Ox+f3AShILIjPoUIqRGwvPNbzFcyU8km8g4A==", + "version": "1.3.188", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.188.tgz", + "integrity": "sha512-tEQcughYIMj8WDMc59EGEtNxdGgwal/oLLTDw+NEqJRJwGflQvH3aiyiexrWeZOETP4/ko78PVr6gwNhdozvuQ==", "dev": true }, "elliptic": { diff --git a/package.json b/package.json index ead357ca218..e20de8d516e 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "babel-loader": "8.0.6", "babel-plugin-inline-react-svg": "1.1.0", "babel-plugin-transform-react-remove-prop-types": "0.4.24", - "browserslist": "4.6.3", + "browserslist": "4.6.4", "core-js": "3.1.4", "cross-env": "5.2.0", "css-loader": "3.0.0", From f781b0c8133c95a5e6122113cc0f63fa34bb57ac Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 19:36:33 +0200 Subject: [PATCH 127/434] Rewrite to use custom safecss_filter_attr implementation --- includes/class-amp-story-post-type.php | 214 ++++++++++++++++--- tests/php/test-class-amp-story-post-type.php | 37 ++++ 2 files changed, 224 insertions(+), 27 deletions(-) diff --git a/includes/class-amp-story-post-type.php b/includes/class-amp-story-post-type.php index d5441f03096..1466d1d0d6f 100644 --- a/includes/class-amp-story-post-type.php +++ b/includes/class-amp-story-post-type.php @@ -206,8 +206,6 @@ public static function register() { add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'filter_kses_allowed_html' ), 10, 2 ); - add_filter( 'safe_style_css', array( __CLASS__, 'filter_safe_style_css' ), 10, 1 ); - add_filter( 'rest_request_before_callbacks', array( __CLASS__, 'filter_rest_request_for_kses' ), 100, 3 ); add_action( 'wp_default_styles', array( __CLASS__, 'register_story_card_styling' ) ); @@ -345,39 +343,198 @@ public static function remove_classic_editor_link( $actions, $post ) { } /** - * Filters allowed CSS attributes to include positioning, display, etc. + * Filters an inline style attribute and removes disallowed rules. + * + * This is equivalent to the WordPress core function of the same name, + * except that this does not remove CSS with parentheses in it. + * + * Also, it adds a few more allowed attributes. * - * @param array $attr Array of allowed CSS attributes. + * @see safecss_filter_attr() * - * @return array Filtered array of allowed CSS attributes. + * @param string $css A string of CSS rules. + * + * @return string Filtered string of CSS rules. */ - public static function filter_safe_style_css( $attr ) { - global $wp; + private static function safecss_filter_attr( $css ) { + $css = wp_kses_no_null( $css ); + $css = str_replace( array( "\n", "\r", "\t" ), '', $css ); - $route = $wp->query_vars['rest_route']; + $allowed_protocols = wp_allowed_protocols(); - if ( ! $route ) { - return $attr; - } + $css_array = explode( ';', trim( $css ) ); - $search = '\/' . self::POST_TYPE_SLUG . '\/'; + /** This filter is documented in wp-includes/kses.php */ + $allowed_attr = apply_filters( + 'safe_style_css', + array( + 'background', + 'background-color', + 'background-image', + 'background-position', + + 'border', + 'border-width', + 'border-color', + 'border-style', + 'border-right', + 'border-right-color', + 'border-right-style', + 'border-right-width', + 'border-bottom', + 'border-bottom-color', + 'border-bottom-style', + 'border-bottom-width', + 'border-left', + 'border-left-color', + 'border-left-style', + 'border-left-width', + 'border-top', + 'border-top-color', + 'border-top-style', + 'border-top-width', + + 'border-spacing', + 'border-collapse', + 'caption-side', + + 'color', + 'font', + 'font-family', + 'font-size', + 'font-style', + 'font-variant', + 'font-weight', + 'letter-spacing', + 'line-height', + 'text-align', + 'text-decoration', + 'text-indent', + 'text-transform', + + 'height', + 'min-height', + 'max-height', + + 'width', + 'min-width', + 'max-width', + + 'margin', + 'margin-right', + 'margin-bottom', + 'margin-left', + 'margin-top', + + 'padding', + 'padding-right', + 'padding-bottom', + 'padding-left', + 'padding-top', + + 'flex', + 'flex-grow', + 'flex-shrink', + 'flex-basis', + + 'clear', + 'cursor', + 'direction', + 'float', + 'overflow', + 'vertical-align', + 'list-style-type', + 'grid-template-columns', + ) + ); - // Only continue if it's a REST request for amp_story post type. - if ( ! preg_match( "/{$search}/i", $route ) ) { - return $attr; - } + // Add some more allowed attributes. + $allowed_attr[] = 'display'; + $allowed_attr[] = 'position'; + $allowed_attr[] = 'top'; + $allowed_attr[] = 'left'; + $allowed_attr[] = 'transform'; - $style_to_add = array( - 'display', - 'left', - 'position', - 'top', + /* + * CSS attributes that accept URL data types. + * + * This is in accordance to the CSS spec and unrelated to + * the sub-set of supported attributes above. + * + * See: https://developer.mozilla.org/en-US/docs/Web/CSS/url + */ + $css_url_data_types = array( + 'background', + 'background-image', + + 'cursor', + + 'list-style', + 'list-style-image', ); - foreach ( $style_to_add as $style ) { - $attr[] = $style; + if ( empty( $allowed_attr ) ) { + return $css; } - return $attr; + + $css = ''; + foreach ( $css_array as $css_item ) { + if ( $css_item === '' ) { + continue; + } + + $css_item = trim( $css_item ); + $css_test_string = $css_item; + $found = false; + $url_attr = false; + + if ( strpos( $css_item, ':' ) === false ) { + $found = true; + } else { + $parts = explode( ':', $css_item, 2 ); + $css_selector = trim( $parts[0] ); + + if ( in_array( $css_selector, $allowed_attr, true ) ) { + $found = true; + $url_attr = in_array( $css_selector, $css_url_data_types, true ); + } + } + + if ( $found && $url_attr ) { + // Simplified: matches the sequence `url(*)`. + preg_match_all( '/url\([^)]+\)/', $parts[1], $url_matches ); + + foreach ( $url_matches[0] as $url_match ) { + // Clean up the URL from each of the matches above. + preg_match( '/^url\(\s*([\'\"]?)(.*)(\g1)\s*\)$/', $url_match, $url_pieces ); + + if ( empty( $url_pieces[2] ) ) { + $found = false; + break; + } + + $url = trim( $url_pieces[2] ); + + if ( empty( $url ) || $url !== wp_kses_bad_protocol( $url, $allowed_protocols ) ) { + $found = false; + break; + } else { + // Remove the whole `url(*)` bit that was matched above from the CSS. + $css_test_string = str_replace( $url_match, '', $css_test_string ); + } + } + } + + if ( $found ) { + if ( $css !== '' ) { + $css .= ';'; + } + + $css .= $css_item; + } + } + + return $css; } /** @@ -417,27 +574,30 @@ public static function filter_rest_request_for_kses( $response, $handler, $reque // Replace inline styles before KSES... add_filter( - 'pre_post_content', + 'content_save_pre', static function ( $post_content ) use ( &$style_attr_values ) { $post_content = preg_replace_callback( '|style=\\\"([^"]*)\\\"|', // Because the post data is slashed. static function ( $matches ) use ( &$style_attr_values ) { $hash = md5( $matches[1] ); - $style_attr_values[ $hash ] = $matches[1]; + $style_attr_values[ $hash ] = self::safecss_filter_attr( $matches[1] ); + // Replaces the complete style attribute value with its hashed version. return str_replace( $matches[1], $hash, $matches[0] ); }, $post_content ); return $post_content; - } + }, + 0 ); // ...And bring it back afterwards. add_filter( 'content_save_pre', static function ( $post_content ) use ( &$style_attr_values ) { + // Replaces hashed style attribute value with the original value again. return str_replace( array_keys( $style_attr_values ), array_values( $style_attr_values ), $post_content ); }, 20 diff --git a/tests/php/test-class-amp-story-post-type.php b/tests/php/test-class-amp-story-post-type.php index 311159da7af..8d15bba5d6e 100644 --- a/tests/php/test-class-amp-story-post-type.php +++ b/tests/php/test-class-amp-story-post-type.php @@ -412,4 +412,41 @@ static function() { $this->assertStringStartsWith( '<amp-story-auto-ads', $actual ); $this->assertContains( '<script type="application/json">{"ad-attributes":{"type":"doubleclick"', $actual ); } + + /** + * Test AMP_Story_Post_Type::filter_rest_request_for_kses(). + * + * @covers AMP_Story_Post_Type::filter_rest_request_for_kses + */ + public function test_filter_rest_request_for_kses() { + AMP_Story_Post_Type::register(); + + $author_id = self::factory()->user->create( array( 'role' => 'author' ) ); + wp_set_current_user( $author_id ); + + $story = self::factory()->post->create( [ + 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG, + ] ); + + $unsanitized_content = '<!-- wp:amp/amp-story-page {"autoAdvanceAfterDuration":0,"backgroundColors":"[{\u0022color\u0022:\u0022#abb8c3\u0022},{\u0022color\u0022:null}]"} --> +<amp-story-page style="background-color:#ffffff" id="1371b14f-c7c3-4b9a-bd47-e24f2b8a1f11" class="wp-block-amp-amp-story-page"><amp-story-grid-layer template="fill" style="background-image:linear-gradient(to bottom, #abb8c3, transparent);opacity:1"></amp-story-grid-layer><!-- wp:amp/amp-story-text {"placeholder":"Write text…","tagName":"h1","customTextColor":"#ffffff","backgroundColor":"vivid-red","autoFontSize":45,"positionTop":10,"rotationAngle":-27} --> +<amp-story-grid-layer template="vertical" data-block-name="amp/amp-story-text"><div class="amp-story-block-wrapper" style="position:absolute;top:10%;left:5%;width:76.22%;height:10.85%"><h1 style="background-color:rgba(207, 46, 46, 1);color:#ffffff;display:flex;transform:rotate(-27deg)" class="wp-block-amp-amp-story-text has-text-color has-background has-vivid-red-background-color" id="ccf08639-cb18-4c65-b35d-8cf2347c700b"><amp-fit-text layout="flex-item" class="amp-text-content">Hello World</amp-fit-text></h1></div></amp-story-grid-layer> +<!-- /wp:amp/amp-story-text --></amp-story-page><!-- /wp:amp/amp-story-page -->'; + + $expected = '<!-- wp:amp/amp-story-page {"autoAdvanceAfterDuration":0,"backgroundColors":"[{\u0022color\u0022:\u0022#abb8c3\u0022},{\u0022color\u0022:null}]"} --> +<amp-story-page style="background-color:#ffffff" id="1371b14f-c7c3-4b9a-bd47-e24f2b8a1f11" class="wp-block-amp-amp-story-page"><amp-story-grid-layer template="fill" style="background-image:linear-gradient(to bottom, #abb8c3, transparent)"></amp-story-grid-layer><!-- wp:amp/amp-story-text {"placeholder":"Write text…","tagName":"h1","customTextColor":"#ffffff","backgroundColor":"vivid-red","autoFontSize":45,"positionTop":10,"rotationAngle":-27} --> +<amp-story-grid-layer template="vertical" data-block-name="amp/amp-story-text"><div class="amp-story-block-wrapper" style="position:absolute;top:10%;left:5%;width:76.22%;height:10.85%"><h1 style="background-color:rgba(207, 46, 46, 1);color:#ffffff;display:flex;transform:rotate(-27deg)" class="wp-block-amp-amp-story-text has-text-color has-background has-vivid-red-background-color" id="ccf08639-cb18-4c65-b35d-8cf2347c700b"><amp-fit-text layout="flex-item" class="amp-text-content">Hello World</amp-fit-text></h1></div></amp-story-grid-layer> +<!-- /wp:amp/amp-story-text --></amp-story-page><!-- /wp:amp/amp-story-page -->'; + + $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/%s/%d', AMP_Story_Post_Type::POST_TYPE_SLUG, $story ) ); + $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); + $request->set_body_params( [ + 'content' => $unsanitized_content, + ] ); + + $response = rest_get_server()->dispatch( $request ); + $new_data = $response->get_data(); + + $this->assertEquals( $expected, $new_data['content']['raw'] ); + } } From 1c16dcf6665ef94901a5ce0cba36ed7fbdf5286f Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 19:39:11 +0200 Subject: [PATCH 128/434] Lint fixes --- tests/php/test-class-amp-story-post-type.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/php/test-class-amp-story-post-type.php b/tests/php/test-class-amp-story-post-type.php index 8d15bba5d6e..0924f11e03c 100644 --- a/tests/php/test-class-amp-story-post-type.php +++ b/tests/php/test-class-amp-story-post-type.php @@ -424,9 +424,11 @@ public function test_filter_rest_request_for_kses() { $author_id = self::factory()->user->create( array( 'role' => 'author' ) ); wp_set_current_user( $author_id ); - $story = self::factory()->post->create( [ - 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG, - ] ); + $story = self::factory()->post->create( + [ + 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG, + ] + ); $unsanitized_content = '<!-- wp:amp/amp-story-page {"autoAdvanceAfterDuration":0,"backgroundColors":"[{\u0022color\u0022:\u0022#abb8c3\u0022},{\u0022color\u0022:null}]"} --> <amp-story-page style="background-color:#ffffff" id="1371b14f-c7c3-4b9a-bd47-e24f2b8a1f11" class="wp-block-amp-amp-story-page"><amp-story-grid-layer template="fill" style="background-image:linear-gradient(to bottom, #abb8c3, transparent);opacity:1"></amp-story-grid-layer><!-- wp:amp/amp-story-text {"placeholder":"Write text…","tagName":"h1","customTextColor":"#ffffff","backgroundColor":"vivid-red","autoFontSize":45,"positionTop":10,"rotationAngle":-27} --> @@ -440,9 +442,11 @@ public function test_filter_rest_request_for_kses() { $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/%s/%d', AMP_Story_Post_Type::POST_TYPE_SLUG, $story ) ); $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); - $request->set_body_params( [ - 'content' => $unsanitized_content, - ] ); + $request->set_body_params( + [ + 'content' => $unsanitized_content, + ] + ); $response = rest_get_server()->dispatch( $request ); $new_data = $response->get_data(); From 788617b89072ba743b7dccf8f5d45812d601b77c Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 19:42:47 +0200 Subject: [PATCH 129/434] Fix since annotations --- includes/sanitizers/trait-amp-noscript-fallback.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/sanitizers/trait-amp-noscript-fallback.php b/includes/sanitizers/trait-amp-noscript-fallback.php index a69c9d1d2fe..0b13c7f66fa 100644 --- a/includes/sanitizers/trait-amp-noscript-fallback.php +++ b/includes/sanitizers/trait-amp-noscript-fallback.php @@ -20,6 +20,7 @@ trait AMP_Noscript_Fallback { * This is used to prevent duplicated validation errors. * * @since 1.1 + * * @var array */ private $noscript_fallback_allowed_attributes = array(); @@ -44,10 +45,11 @@ protected function initialize_noscript_allowed_attributes( $tag ) { /** * Checks whether the given node is within an AMP-specific <noscript> element. * + * @since 1.1 + * * @param DOMNode $node DOM node to check. * * @return bool True if in an AMP noscript element, false otherwise. - * @since 1.1 */ protected function is_inside_amp_noscript( DOMNode $node ) { return 'noscript' === $node->parentNode->nodeName && $node->parentNode->parentNode && 'amp-' === substr( $node->parentNode->parentNode->nodeName, 0, 4 ); @@ -56,11 +58,11 @@ protected function is_inside_amp_noscript( DOMNode $node ) { /** * Appends the given old node in a <noscript> element to the new node. * + * @since 1.1 + * * @param DOMNode $new_node New node to append a noscript with the old node to. * @param DOMNode $old_node Old node to append in a noscript. * @param DOMDocument $dom DOM document instance. - * - * @since 1.1 */ protected function append_old_node_noscript( DOMNode $new_node, DOMNode $old_node, DOMDocument $dom ) { $noscript = $dom->createElement( 'noscript' ); From 953295bd8b11055101c3454a383423882415f6e4 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 19:48:33 +0200 Subject: [PATCH 130/434] Update regex as per suggestion --- includes/class-amp-story-post-type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-amp-story-post-type.php b/includes/class-amp-story-post-type.php index 1466d1d0d6f..333d50a55a4 100644 --- a/includes/class-amp-story-post-type.php +++ b/includes/class-amp-story-post-type.php @@ -577,7 +577,7 @@ public static function filter_rest_request_for_kses( $response, $handler, $reque 'content_save_pre', static function ( $post_content ) use ( &$style_attr_values ) { $post_content = preg_replace_callback( - '|style=\\\"([^"]*)\\\"|', // Because the post data is slashed. + '|<\w+(?:-\w+)*\s[^>]*?style=\\\"([^"]*)\\\"[^>]+?>|', // Because the post data is slashed. static function ( $matches ) use ( &$style_attr_values ) { $hash = md5( $matches[1] ); $style_attr_values[ $hash ] = self::safecss_filter_attr( $matches[1] ); From 5ca4b86f758f3d463caa91dfe8c2bcaa0c5016e4 Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 19:57:15 +0200 Subject: [PATCH 131/434] Use yoda conditions --- includes/class-amp-story-post-type.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-amp-story-post-type.php b/includes/class-amp-story-post-type.php index 9ac475433f9..52c30a8b371 100644 --- a/includes/class-amp-story-post-type.php +++ b/includes/class-amp-story-post-type.php @@ -479,7 +479,7 @@ private static function safecss_filter_attr( $css ) { $css = ''; foreach ( $css_array as $css_item ) { - if ( $css_item === '' ) { + if ( '' === $css_item ) { continue; } @@ -515,7 +515,7 @@ private static function safecss_filter_attr( $css ) { $url = trim( $url_pieces[2] ); - if ( empty( $url ) || $url !== wp_kses_bad_protocol( $url, $allowed_protocols ) ) { + if ( empty( $url ) || wp_kses_bad_protocol( $url, $allowed_protocols ) !== $url ) { $found = false; break; } else { @@ -526,7 +526,7 @@ private static function safecss_filter_attr( $css ) { } if ( $found ) { - if ( $css !== '' ) { + if ( '' !== $css ) { $css .= ';'; } From f61374e1ed81065473dcfdc0901dacd91e125a7c Mon Sep 17 00:00:00 2001 From: Pascal Birchler <pascalb@google.com> Date: Mon, 8 Jul 2019 20:48:19 +0200 Subject: [PATCH 132/434] Use short array syntax throughout the project This is a bit of a follow-up to #2493. The main plugin file, `amp.php`, is left untouched as it still should be parseable on PHP 5.2. Also does not change `includes/sanitizers/class-amp-allowed-tags-generated.php` as it is auto-generated. --- back-compat/templates-v0-3/meta-author.php | 4 +- back-compat/templates-v0-3/single.php | 6 +- bin/add-test-widgets-to-sidebar.php | 206 +-- bin/create-comments-on-test-post.php | 14 +- bin/create-embed-test-post.php | 216 +-- bin/create-gutenberg-test-post.php | 56 +- bin/verify-version-consistency.php | 2 +- includes/admin/class-amp-admin-pointer.php | 14 +- includes/admin/class-amp-admin-pointers.php | 30 +- includes/admin/class-amp-customizer.php | 38 +- includes/admin/class-amp-editor-blocks.php | 18 +- includes/admin/class-amp-post-meta-box.php | 52 +- includes/admin/class-amp-story-templates.php | 92 +- includes/admin/functions.php | 16 +- includes/amp-helper-functions.php | 196 +-- includes/amp-post-template-functions.php | 8 +- includes/class-amp-autoloader.php | 6 +- includes/class-amp-cli.php | 48 +- includes/class-amp-comment-walker.php | 4 +- includes/class-amp-http.php | 60 +- includes/class-amp-post-type-support.php | 18 +- includes/class-amp-service-worker.php | 76 +- includes/class-amp-story-post-type.php | 442 ++--- includes/class-amp-theme-support.php | 304 ++-- .../embeds/class-amp-base-embed-handler.php | 10 +- .../embeds/class-amp-core-block-handler.php | 8 +- .../class-amp-crowdsignal-embed-handler.php | 4 +- .../embeds/class-amp-dailymotion-embed.php | 26 +- includes/embeds/class-amp-facebook-embed.php | 18 +- includes/embeds/class-amp-gallery-embed.php | 58 +- .../embeds/class-amp-gfycat-embed-handler.php | 6 +- .../embeds/class-amp-hulu-embed-handler.php | 6 +- .../embeds/class-amp-imgur-embed-handler.php | 18 +- includes/embeds/class-amp-instagram-embed.php | 28 +- .../embeds/class-amp-issuu-embed-handler.php | 8 +- .../embeds/class-amp-meetup-embed-handler.php | 4 +- includes/embeds/class-amp-pinterest-embed.php | 12 +- .../class-amp-playlist-embed-handler.php | 20 +- .../embeds/class-amp-reddit-embed-handler.php | 12 +- .../embeds/class-amp-soundcloud-embed.php | 28 +- .../embeds/class-amp-tumblr-embed-handler.php | 8 +- includes/embeds/class-amp-twitter-embed.php | 24 +- includes/embeds/class-amp-vimeo-embed.php | 30 +- includes/embeds/class-amp-vine-embed.php | 18 +- includes/embeds/class-amp-youtube-embed.php | 30 +- .../class-amp-analytics-options-submenu.php | 4 +- .../options/class-amp-options-manager.php | 66 +- includes/options/class-amp-options-menu.php | 56 +- ...ass-amp-analytics-options-submenu-page.php | 2 +- .../sanitizers/class-amp-audio-sanitizer.php | 18 +- .../sanitizers/class-amp-base-sanitizer.php | 34 +- .../class-amp-blacklist-sanitizer.php | 26 +- .../class-amp-comments-sanitizer.php | 22 +- .../sanitizers/class-amp-embed-sanitizer.php | 4 +- .../sanitizers/class-amp-form-sanitizer.php | 6 +- .../sanitizers/class-amp-iframe-sanitizer.php | 18 +- .../class-amp-nav-menu-dropdown-sanitizer.php | 8 +- .../class-amp-o2-player-sanitizer.php | 10 +- .../class-amp-playbuzz-sanitizer.php | 8 +- includes/sanitizers/class-amp-rule-spec.php | 20 +- .../sanitizers/class-amp-style-sanitizer.php | 306 ++-- .../class-amp-tag-and-attribute-sanitizer.php | 156 +- .../sanitizers/class-amp-video-sanitizer.php | 22 +- .../class-amp-customizer-design-settings.php | 98 +- .../class-amp-customizer-settings.php | 2 +- .../templates/class-amp-content-sanitizer.php | 14 +- includes/templates/class-amp-content.php | 10 +- .../templates/class-amp-post-template.php | 42 +- includes/templates/embed-amp-story.php | 4 +- includes/templates/single-amp_story.php | 2 +- includes/utils/class-amp-dom-utils.php | 22 +- includes/utils/class-amp-html-utils.php | 4 +- .../class-amp-image-dimension-extractor.php | 28 +- includes/utils/class-amp-wp-utils.php | 4 +- .../class-amp-validated-url-post-type.php | 252 +-- .../class-amp-validation-callback-wrapper.php | 8 +- .../class-amp-validation-error-taxonomy.php | 202 +-- .../class-amp-validation-manager.php | 210 +-- .../widgets/class-amp-widget-archives.php | 8 +- .../widgets/class-amp-widget-categories.php | 6 +- templates/header.php | 2 +- templates/html-start.php | 2 +- templates/meta-author.php | 2 +- templates/page.php | 10 +- templates/single.php | 14 +- tests/php/stubs.php | 4 +- tests/php/test-amp-analytics-options.php | 20 +- tests/php/test-amp-audio-converter.php | 98 +- .../test-amp-crowdsignal-embed-handler.php | 36 +- tests/php/test-amp-dailymotion-embed.php | 40 +- tests/php/test-amp-facebook-embed.php | 92 +- tests/php/test-amp-form-sanitizer.php | 54 +- tests/php/test-amp-helper-functions.php | 202 +-- tests/php/test-amp-iframe-sanitizer.php | 154 +- .../test-amp-image-dimension-extractor.php | 120 +- tests/php/test-amp-img-sanitizer.php | 266 +-- tests/php/test-amp-instagram-embed.php | 72 +- tests/php/test-amp-o2-player-sanitizer.php | 24 +- tests/php/test-amp-pinterest-embed.php | 32 +- tests/php/test-amp-playbuzz-sanitizer.php | 42 +- tests/php/test-amp-render-post.php | 12 +- tests/php/test-amp-script-sanitizer.php | 24 +- tests/php/test-amp-soundcloud-embed.php | 82 +- tests/php/test-amp-story-sanitizer.php | 20 +- tests/php/test-amp-style-sanitizer.php | 1176 ++++++------- ...nd-attribute-sanitizer-private-methods.php | 1478 ++++++++--------- tests/php/test-amp-twitter-embed.php | 96 +- tests/php/test-amp-video-sanitizer.php | 102 +- tests/php/test-amp-vimeo-embed.php | 40 +- tests/php/test-amp-vine-embed.php | 28 +- tests/php/test-amp-youtube-embed.php | 44 +- tests/php/test-amp.php | 16 +- tests/php/test-class-amp-admin-pointer.php | 2 +- tests/php/test-class-amp-base-sanitizer.php | 222 +-- tests/php/test-class-amp-block-sanitizer.php | 24 +- tests/php/test-class-amp-cli.php | 142 +- .../php/test-class-amp-comments-sanitizer.php | 26 +- .../php/test-class-amp-content-sanitizer.php | 8 +- .../php/test-class-amp-core-block-handler.php | 4 +- tests/php/test-class-amp-dom-utils.php | 130 +- tests/php/test-class-amp-editor-blocks.php | 10 +- ...test-class-amp-gallery-block-sanitizer.php | 52 +- .../test-class-amp-gfycat-embed-handler.php | 36 +- tests/php/test-class-amp-http.php | 180 +- .../php/test-class-amp-hulu-embed-handler.php | 40 +- .../test-class-amp-imgur-embed-handler.php | 44 +- tests/php/test-class-amp-meta-box.php | 92 +- ...st-class-amp-nav-menu-toggle-sanitizer.php | 52 +- tests/php/test-class-amp-options-manager.php | 240 +-- tests/php/test-class-amp-options-menu.php | 10 +- .../test-class-amp-playlist-embed-handler.php | 86 +- .../php/test-class-amp-post-type-support.php | 34 +- tests/php/test-class-amp-service-worker.php | 54 +- tests/php/test-class-amp-story-post-type.php | 126 +- tests/php/test-class-amp-story-templates.php | 24 +- tests/php/test-class-amp-theme-support.php | 320 ++-- .../test-class-amp-vimeo-embed-handler.php | 14 +- tests/php/test-class-amp-widget-archives.php | 10 +- .../php/test-class-amp-widget-categories.php | 10 +- tests/php/test-class-amp-widget-text.php | 6 +- .../test-class-amp-youtube-embed-handler.php | 14 +- .../php/test-tag-and-attribute-sanitizer.php | 1340 +++++++-------- ...test-class-amp-validated-url-post-type.php | 606 +++---- ...st-class-amp-validation-error-taxonomy.php | 414 ++--- .../test-class-amp-validation-manager.php | 406 ++--- 145 files changed, 6593 insertions(+), 6593 deletions(-) diff --git a/back-compat/templates-v0-3/meta-author.php b/back-compat/templates-v0-3/meta-author.php index c28a77d4a1d..8497572988b 100644 --- a/back-compat/templates-v0-3/meta-author.php +++ b/back-compat/templates-v0-3/meta-author.php @@ -8,9 +8,9 @@ $post_author = $this->get( 'post_author' ); $avatar_url = get_avatar_url( $post_author->user_email, - array( + [ 'size' => 24, - ) + ] ); ?> <li class="amp-wp-byline"> diff --git a/back-compat/templates-v0-3/single.php b/back-compat/templates-v0-3/single.php index bf383f77fa6..a19858e6322 100644 --- a/back-compat/templates-v0-3/single.php +++ b/back-compat/templates-v0-3/single.php @@ -14,16 +14,16 @@ <?php do_action( 'amp_post_template_head', $this ); ?> <style amp-custom> - <?php $this->load_parts( array( 'style' ) ); ?> + <?php $this->load_parts( [ 'style' ] ); ?> <?php do_action( 'amp_post_template_css', $this ); ?> </style> </head> <body> -<?php $this->load_parts( array( 'header-bar' ) ); ?> +<?php $this->load_parts( [ 'header-bar' ] ); ?> <div class="amp-wp-content"> <h1 class="amp-wp-title"><?php echo wp_kses_data( $this->get( 'post_title' ) ); ?></h1> <ul class="amp-wp-meta"> - <?php $this->load_parts( apply_filters( 'amp_post_template_meta_parts', array( 'meta-author', 'meta-time', 'meta-taxonomy' ) ) ); ?> + <?php $this->load_parts( apply_filters( 'amp_post_template_meta_parts', [ 'meta-author', 'meta-time', 'meta-taxonomy' ] ) ); ?> </ul> <?php echo $this->get( 'post_amp_content' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> </div> diff --git a/bin/add-test-widgets-to-sidebar.php b/bin/add-test-widgets-to-sidebar.php index 153ff9a4593..68580abc2ca 100644 --- a/bin/add-test-widgets-to-sidebar.php +++ b/bin/add-test-widgets-to-sidebar.php @@ -15,7 +15,7 @@ function amp_populate_sidebar() { global $wp_registered_sidebars; $widgets = amp_get_widgets(); $sidebar = amp_get_first_sidebar(); - $created_widgets = array(); + $created_widgets = []; foreach ( $widgets as $widget ) { if ( ! amp_widget_already_in_sidebar( $widget, $sidebar ) ) { amp_create_widget( $widget ); @@ -32,89 +32,89 @@ function amp_populate_sidebar() { * @return array $widgets Data for the widgets. */ function amp_get_widgets() { - return array( - array( + return [ + [ 'widget' => 'media_audio', 'settings' => array_merge( amp_media_widget( 'audio' ), - array( + [ 'title' => 'Test Audio Widget: No Loop or Preload', - ) + ] ), - ), - array( + ], + [ 'widget' => 'media_audio', 'settings' => array_merge( amp_media_widget( 'audio' ), - array( + [ 'title' => 'Test Audio Widget: With Loop, Preload', 'loop' => true, 'preload' => 'auto', - ) + ] ), - ), - array( + ], + [ 'widget' => 'archives', - 'settings' => array( + 'settings' => [ 'title' => 'Test Archives Widget: No Dropdown or Count', - ), - ), - array( + ], + ], + [ 'widget' => 'archives', - 'settings' => array( + 'settings' => [ 'title' => 'Test Archives Widget: With Dropdown, Count', 'count' => 1, 'dropdown' => 1, - ), - ), - array( + ], + ], + [ 'widget' => 'calendar', - ), - array( + ], + [ 'widget' => 'categories', - 'settings' => array( + 'settings' => [ 'title' => 'Test Categories Widget: No Count, Dropdown, or Hierarchical', - ), - ), - array( + ], + ], + [ 'widget' => 'categories', - 'settings' => array( + 'settings' => [ 'title' => 'Test Categories Widget: With Count', 'count' => 1, - ), - ), - array( + ], + ], + [ 'widget' => 'categories', - 'settings' => array( + 'settings' => [ 'title' => 'Test Categories Widget: With Count, Dropdown, And Hierarchical', 'count' => 1, 'dropdown' => 1, 'hierarchical' => 1, - ), - ), - array( + ], + ], + [ 'widget' => 'custom_html', - 'settings' => array( + 'settings' => [ 'title' => 'Test Custom HTML Widget', 'content' => '<h2>Example Custom HTML widget</h2><article>Here is some custom HTML with a <a href="http://example.com/m">link</a></article>', - ), - ), - array( + ], + ], + [ 'widget' => 'media_gallery', 'settings' => array_merge( amp_gallery_widget(), - array( + [ 'link_type' => 'post', 'orderby_random' => false, 'size' => 'thumbnail', - ) + ] ), - ), - array( + ], + [ 'widget' => 'media_image', 'settings' => array_merge( amp_image_widget(), - array( + [ 'alt' => 'Example alt value', 'caption' => 'Example caption', 'image_classes' => 'foo bar', @@ -125,97 +125,97 @@ function amp_get_widgets() { 'link_type' => 'custom', 'link_url' => 'http://example.com/amp-test', 'size' => 'full', - ) + ] ), - ), - array( + ], + [ 'widget' => 'meta', - ), - array( + ], + [ 'widget' => 'nav_menu', - 'settings' => array( + 'settings' => [ 'nav_menu' => amp_menu(), - ), - ), - array( + ], + ], + [ 'widget' => 'pages', - ), - array( + ], + [ 'widget' => 'recent-comments', - ), - array( + ], + [ 'widget' => 'recent-posts', - 'settings' => array( + 'settings' => [ 'show_date' => true, - ), - ), - array( + ], + ], + [ 'widget' => 'rss', - 'settings' => array( + 'settings' => [ 'title' => 'Test RSS Widget: No Content, Author, or Date', 'url' => 'https://amphtml.wordpress.com/feed/', 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, - ), - ), - array( + ], + ], + [ 'widget' => 'rss', - 'settings' => array( + 'settings' => [ 'title' => 'Test RSS Widget: With Content, Author, Date', 'url' => 'https://amphtml.wordpress.com/feed/', 'show_author' => 1, 'show_date' => 1, 'show_summary' => 1, - ), - ), - array( + ], + ], + [ 'widget' => 'search', - ), - array( + ], + [ 'widget' => 'tag_cloud', - 'settings' => array( + 'settings' => [ 'title' => 'Test Tag Widget, No Count', - ), - ), - array( + ], + ], + [ 'widget' => 'tag_cloud', - 'settings' => array( + 'settings' => [ 'title' => 'Test Tag Widget, With Count', 'count' => 1, - ), - ), - array( + ], + ], + [ 'widget' => 'text', - 'settings' => array( + 'settings' => [ 'filter' => true, 'text' => '<strong>Example Headline</strong><ul><li>This is to test possible text</li><li>This should display as expected</li></ul>', 'visual' => true, - ), - ), - array( + ], + ], + [ 'widget' => 'media_video', 'settings' => array_merge( amp_media_widget( 'video' ), - array( + [ 'title' => 'Test Video Widget: No Loop or Preload', 'loop' => false, 'preload' => 'none', - ) + ] ), - ), - array( + ], + [ 'widget' => 'media_video', 'settings' => array_merge( amp_media_widget( 'video' ), - array( + [ 'title' => 'Test Video Widget: With Loop, Preload', 'loop' => true, 'preload' => 'metadata', - ) + ] ), - ), - ); + ], + ]; } /** @@ -231,10 +231,10 @@ function amp_get_widgets() { function amp_media_widget( $type ) { $all_media = amp_media( $type, 1 ); $media = reset( $all_media ); - return array( + return [ 'attachment_id' => $media->ID, 'url' => $media->guid, - ); + ]; } /** @@ -244,9 +244,9 @@ function amp_media_widget( $type ) { */ function amp_gallery_widget() { $images = amp_media( 'image', 3 ); - return array( + return [ 'ids' => wp_list_pluck( $images, 'ID' ), - ); + ]; } /** @@ -259,12 +259,12 @@ function amp_image_widget() { $image = reset( $all_images ); $metadata = wp_get_attachment_metadata( $image->ID ); $default_dimension = 100; - return array( + return [ 'attachment_id' => $image->ID, 'height' => isset( $metadata['height'] ) ? $metadata['height'] : $default_dimension, 'width' => isset( $metadata['width'] ) ? $metadata['width'] : $default_dimension, 'url' => wp_get_attachment_url( $image->ID ), - ); + ]; } /** @@ -277,12 +277,12 @@ function amp_image_widget() { */ function amp_media( $type, $count = 3 ) { $query = new WP_Query( - array( + [ 'post_type' => 'attachment', 'post_mime_type' => $type, 'post_status' => 'inherit', 'posts_per_page' => $count, - ) + ] ); if ( $query->post_count < $count ) { throw new Exception( @@ -335,7 +335,7 @@ function amp_widget_already_in_sidebar( $widget, $sidebar ) { } $id_base = $widget['widget']; - $all_widget_data = get_option( 'widget_' . $id_base, array() ); + $all_widget_data = get_option( 'widget_' . $id_base, [] ); foreach ( $sidebars[ $sidebar ] as $possible_widget ) { if ( false !== strpos( $possible_widget, $id_base ) ) { @@ -356,7 +356,7 @@ function amp_widget_already_in_sidebar( $widget, $sidebar ) { } // Find if all of the settings in $widget['settings'] are present in the widget that's already in the sidebar. - if ( array() === array_diff_assoc( array_map( 'serialize', $widget['settings'] ), array_map( 'serialize', $widget_data ) ) ) { + if ( [] === array_diff_assoc( array_map( 'serialize', $widget['settings'] ), array_map( 'serialize', $widget_data ) ) ) { return true; } } @@ -377,11 +377,11 @@ function amp_create_widget( $widget ) { $id_base = $widget['widget']; $option_key = 'widget_' . $id_base; - $widgets = get_option( $option_key, array() ); - $settings = isset( $widget['settings'] ) ? $widget['settings'] : array(); + $widgets = get_option( $option_key, [] ); + $settings = isset( $widget['settings'] ) ? $widget['settings'] : []; if ( ! isset( $settings['title'] ) ) { - $title = str_replace( array( '_', '-' ), ' ', $id_base ); + $title = str_replace( [ '_', '-' ], ' ', $id_base ); $settings['title'] = sprintf( 'Test %s Widget', ucwords( $title ) ); } @@ -421,7 +421,7 @@ function amp_get_first_sidebar() { * @return string $widget_id The ID of the widget, like 'text-2'. */ function amp_get_widget_id( $id_base ) { - $settings = get_option( "widget_{$id_base}", array() ); + $settings = get_option( "widget_{$id_base}", [] ); if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) { $settings = $settings->getArrayCopy(); } diff --git a/bin/create-comments-on-test-post.php b/bin/create-comments-on-test-post.php index 218687356be..0c26fae50ea 100644 --- a/bin/create-comments-on-test-post.php +++ b/bin/create-comments-on-test-post.php @@ -13,19 +13,19 @@ * @return int Post ID. */ function amp_create_comments_test_post() { - $q = new WP_Query( array( 'name' => 'amp-test-comments' ) ); + $q = new WP_Query( [ 'name' => 'amp-test-comments' ] ); if ( $q->have_posts() ) { $post = $q->next_post(); $post_id = $post->ID; } else { $post_id = wp_insert_post( - array( + [ 'post_name' => 'amp-test-comments', 'post_title' => 'AMP Test Comments', 'post_type' => 'post', 'post_status' => 'publish', 'post_content' => amp_get_test_random_content( 200 ), - ) + ] ); if ( ! $post_id || is_wp_error( $post_id ) ) { @@ -49,7 +49,7 @@ function amp_create_comments_test_post() { */ function amp_add_comments( $post_id ) { $data = amp_get_test_comment_entries(); - $ids = array(); + $ids = []; foreach ( $data as $comment ) { $comment['comment_post_ID'] = $post_id; $yes_no = rand( 0, 1 ); @@ -71,14 +71,14 @@ function amp_add_comments( $post_id ) { * @return array Data entries. */ function amp_get_test_comment_entries() { - $comments = array(); + $comments = []; $time = strtotime( 'now' ); for ( $i = 0; $i < 30; $i++ ) { $author = preg_replace( '/[^\w ]+/', '', amp_get_test_random_content( 2, '' ) ); $time = strtotime( '+3 minutes', $time ); // Add comment. - $comments[] = array( + $comments[] = [ 'comment_author' => ucwords( $author ), 'comment_author_email' => strtolower( implode( '@', explode( ' ', $author ) ) ) . '.com', 'comment_author_url' => strtolower( implode( '.', explode( ' ', $author ) ) ) . '.com', @@ -89,7 +89,7 @@ function amp_get_test_comment_entries() { 'comment_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', 'comment_date' => date( 'Y-m-d H:i:s', $time ), 'comment_approved' => '1', - ); + ]; } return $comments; diff --git a/bin/create-embed-test-post.php b/bin/create-embed-test-post.php index 6fa2925d972..752b0ea147f 100644 --- a/bin/create-embed-test-post.php +++ b/bin/create-embed-test-post.php @@ -14,208 +14,208 @@ */ function amp_get_test_data_entries() { list( $img_src ) = wp_get_attachment_image_src( amp_get_media_items_ids( 'image', 1 ) ); - return array( - array( + return [ + [ 'heading' => 'Media Gallery', 'content' => sprintf( '[gallery ids="%s"]', amp_get_media_items_ids( 'image' ) ), - ), - array( + ], + [ 'heading' => 'Media Image', 'content' => wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ), - ), - array( + ], + [ 'heading' => 'Media Caption', 'content' => sprintf( '[caption width=150]%sExample image caption[/caption]', wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ) ), - ), - array( + ], + [ 'heading' => 'Media Video', 'content' => sprintf( '[video poster="%s" src=https://videos.files.wordpress.com/DK5mLrbr/video-ca6dc0ab4a_hd.mp4]', $img_src ), - ), - array( + ], + [ 'heading' => 'Media Audio', 'content' => '[audio src=https://wptavern.com/wp-content/uploads/2017/11/EPISODE-296-Gutenberg-Telemetry-Calypso-and-More-With-Matt-Mullenweg.mp3]', - ), - array( + ], + [ 'heading' => 'Video Playlist', 'content' => sprintf( '[playlist type="video" ids="%s"]', amp_get_media_items_ids( 'video' ) ), - ), - array( + ], + [ 'heading' => 'Audio Playlist', 'content' => sprintf( '[playlist ids="%s"]', amp_get_media_items_ids( 'audio' ) ), - ), - array( + ], + [ 'heading' => 'WordPress Post Embed', 'content' => 'https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/', - ), - array( + ], + [ 'heading' => 'Amazon Com Smile Embed', 'content' => 'https://smile.amazon.com/dp/B00DPM7TIG', - ), - array( + ], + [ 'heading' => 'Amazon Co Smile Embed', 'content' => 'https://smile.amazon.co.uk/dp/B00DPM7TIG', - ), - array( + ], + [ 'heading' => 'Amazon Read CN Embed', 'content' => 'https://read.amazon.cn/kp/embed?asin=B00DPM7TIG', - ), - array( + ], + [ 'heading' => 'Animoto Embed', 'content' => 'https://animoto.com/play/TDfViXkPqIwYj5EjamYjnw', - ), - array( + ], + [ 'heading' => 'CloudUp Image Embed', 'content' => 'https://cloudup.com/iWn3EIpgjev', - ), - array( + ], + [ 'heading' => 'CloudUp Video Embed', 'content' => 'https://cloudup.com/ioyW8a_Tjme', - ), - array( + ], + [ 'heading' => 'CloudUp Gallery Embed', 'content' => 'https://cloudup.com/cQNdYtQLO5U', - ), - array( + ], + [ 'heading' => 'CollegeHumor Embed', 'content' => 'http://www.collegehumor.com/video/40002823/how-to-actually-finish-something-for-once', - ), - array( + ], + [ 'heading' => 'DailyMotion Embed', 'content' => 'http://www.dailymotion.com/video/x6bacgf', - ), - array( + ], + [ 'heading' => 'Facebook Post Embed', 'content' => 'https://www.facebook.com/WordPress/posts/10155651799877911', - ), - array( + ], + [ 'heading' => 'Facebook Video Embed', 'content' => 'https://www.facebook.com/WordPress/videos/10154702401472911/', - ), - array( + ], + [ 'heading' => 'Flickr Image Embed', 'content' => 'https://www.flickr.com/photos/sylvainmessier/38089894895/in/explore-2017-12-11/', - ), - array( + ], + [ 'heading' => 'Flickr Video Embed', 'content' => 'https://flic.kr/p/5TPDWa', - ), - array( + ], + [ 'heading' => 'Funny Or Die Video Embed', 'content' => 'http://www.funnyordie.com/videos/2977012a20/i-still-haven-t-found-the-droids-i-m-looking-for', - ), - array( + ], + [ 'heading' => 'Hulu Embed', 'content' => 'https://www.hulu.com/watch/807443', - ), - array( + ], + [ 'heading' => 'Instagram Embed', 'content' => 'https://www.instagram.com/p/bNd86MSFv6/', - ), - array( + ], + [ 'heading' => 'Issuu Embed', 'content' => 'https://issuu.com/ajcwfu/docs/seatatthetablefinal', - ), - array( + ], + [ 'heading' => 'Kickstarter Embed', 'content' => 'https://www.kickstarter.com/projects/iananderson/save-froots-magazine', - ), - array( + ], + [ 'heading' => 'Meetup Embed', 'content' => 'https://www.meetup.com/WordPress-Mexico', - ), - array( + ], + [ 'heading' => 'Mixcloud Embed', 'content' => 'https://www.mixcloud.com/TheWireMagazine/adventures-in-sound-and-music-hosted-by-derek-walmsley-7-december-2017/', - ), - array( + ], + [ 'heading' => 'Photobucket Embed', 'content' => 'http://i1259.photobucket.com/albums/ii543/iamnotpeterpan/EditPostlsaquoDennisDoesCricketmdashWordPress_zpsf72cc13d.png', - ), - array( + ], + [ 'heading' => 'Crowdsingal Poll Embed', 'content' => 'https://poll.fm/7012505', - ), - array( + ], + [ 'heading' => 'Polldaddy Survey Embed', 'content' => 'https://rydk.survey.fm/test-survey', - ), - array( + ], + [ 'heading' => 'Reddit Embed', 'content' => 'https://www.reddit.com/r/Android/comments/7jbkub/google_maps_will_soon_tell_you_when_its_time_to/?ref=share&ref_source=link', - ), - array( + ], + [ 'heading' => 'Reverb Nation Embed', 'content' => 'https://www.reverbnation.com/fernandotorresleiva/song/28755694-breve-amor-new-version', - ), - array( + ], + [ 'heading' => 'Screencast Embed', 'content' => 'http://www.screencast.com/t/nMCYr3N3uF', - ), - array( + ], + [ 'heading' => 'Scribd Embed', 'content' => 'http://www.scribd.com/doc/110799637/Synthesis-of-Knowledge-Effects-of-Fire-and-Thinning-Treatments-on-Understory-Vegetation-in-Dry-U-S-Forests', - ), - array( + ], + [ 'heading' => 'SlideShare Embed', 'content' => 'https://www.slideshare.net/slideshow/embed_code/key/u6WNbsR5worSzC', - ), - array( + ], + [ 'heading' => 'SmugMug Embed', 'content' => 'https://stuckincustoms.smugmug.com/Portfolio/i-GnwtS8R/A', - ), - array( + ], + [ 'heading' => 'Someecards Embed', 'content' => 'https://www.someecards.com/usercards/viewcard/mjaxmi1jmgy2y2exm2m2ngu2ntfi/?tagSlug=christmas', - ), - array( + ], + [ 'heading' => 'Someecards Short URL Embed', 'content' => 'https://some.ly/V3RZUq/', - ), - array( + ], + [ 'heading' => 'SoundCloud Embed', 'content' => 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor', - ), - array( + ], + [ 'heading' => 'Speaker Deck Embed', 'content' => 'https://speakerdeck.com/wallat/why-backbone', - ), - array( + ], + [ 'heading' => 'Spotify Embed', 'content' => 'https://open.spotify.com/track/2XULDEvijLgHttFgLzzpM5', - ), - array( + ], + [ 'heading' => 'Ted Embed', 'content' => 'https://www.ted.com/talks/derek_sivers_how_to_start_a_movement', - ), - array( + ], + [ 'heading' => 'Tumblr Post Embed', 'content' => 'http://ifpaintingscouldtext.tumblr.com/post/92003045635/grant-wood-american-gothic-1930', - ), - array( + ], + [ 'heading' => 'Twitter Embed', 'content' => 'https://twitter.com/WordPress/status/936550699336437760', - ), - array( + ], + [ 'heading' => 'VideoPress Embed', 'content' => 'https://videopress.com/v/kUJmAcSf', - ), - array( + ], + [ 'heading' => 'Vimeo Embed', 'content' => 'https://vimeo.com/59172123', - ), - array( + ], + [ 'heading' => 'WordPress Plugin Directory Embed', 'content' => 'https://wordpress.org/plugins/amp/', - ), - array( + ], + [ 'heading' => 'WordPress TV Embed', 'content' => 'https://videopress.com/v/DK5mLrbr', - ), - array( + ], + [ 'heading' => 'YouTube Embed', 'content' => 'https://www.youtube.com/watch?v=XOY3ZUO6P0k', - ), - ); + ], + ]; } /** @@ -228,13 +228,13 @@ function amp_get_test_data_entries() { */ function amp_get_media_items_ids( $type, $image_count = 3 ) { $query = new WP_Query( - array( + [ 'post_type' => 'attachment', 'post_mime_type' => $type, 'post_status' => 'inherit', 'posts_per_page' => $image_count, 'fields' => 'ids', - ) + ] ); if ( $query->post_count < $image_count ) { throw new Exception( @@ -263,11 +263,11 @@ function amp_create_embed_test_post( $data_entries ) { $page_id = $page->ID; } else { $page_id = wp_insert_post( - array( + [ 'post_name' => 'amp-test-embeds', 'post_title' => 'AMP Test Embeds', 'post_type' => 'page', - ) + ] ); if ( ! $page_id || is_wp_error( $page_id ) ) { @@ -289,10 +289,10 @@ function amp_create_embed_test_post( $data_entries ) { $update = wp_update_post( wp_slash( - array( + [ 'ID' => $page_id, 'post_content' => $content, - ) + ] ) ); diff --git a/bin/create-gutenberg-test-post.php b/bin/create-gutenberg-test-post.php index f27b7938bc3..5caa5c0a735 100644 --- a/bin/create-gutenberg-test-post.php +++ b/bin/create-gutenberg-test-post.php @@ -55,48 +55,48 @@ function get_test_block_fixtures() { * @return string $content The blocks as HTML. */ function get_test_block_permutations() { - $blocks = array( - array( + $blocks = [ + [ 'title' => '(Reusable) Block With Video', 'content' => sprintf( '<!-- wp:block {"ref":%d} /-->', create_test_reusable_block() ), - ), - array( + ], + [ 'title' => 'Categories With Dropdown', 'content' => '<!-- wp:core/categories {"showPostCounts":false,"displayAsDropdown":true,"showHierarchy":false} /-->', - ), - array( + ], + [ 'title' => 'Columns, With 2 Columns', 'content' => '<!-- wp:core/columns {"columns":2} --><div class="wp-block-columns has-2-columns"><!-- wp:core/paragraph {"layout":"column-1"} --><p class="layout-column-1">Column One, Paragraph One</p><!-- /wp:core/paragraph --><!-- wp:core/paragraph {"layout":"column-1"} --><p class="layout-column-1">Column One, Paragraph Two</p><!-- /wp:core/paragraph --><!-- wp:core/paragraph {"layout":"column-2"} --><p class="layout-column-2">Column Two, Paragraph One</p><!-- /wp:core/paragraph --></div><!-- /wp:core/columns -->', - ), - array( + ], + [ 'title' => 'Cover Image With Fixed Background', 'content' => '<!-- wp:core/cover-image {"url":"https://cldup.com/uuUqE_dXzy.jpg","dimRatio":40} --><section class="wp-block-cover-image has-background-dim-40 has-background-dim has-parallax" style="background-image:url(https://cldup.com/uuUqE_dXzy.jpg)"><h2>Guten Berg!</h2></section><!-- /wp:core/cover-image -->', - ), - array( + ], + [ 'title' => 'WordPress Embed', 'content' => '<!-- wp:core-embed/wordpress {"url":"https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/"} --><figure class="wp-block-embed-wordpress wp-block-embed">https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/<figcaption>Embedded content from WordPress</figcaption></figure><!-- /wp:core-embed/wordpress -->', - ), - array( + ], + [ 'title' => 'YouTube Embed', 'content' => '<!-- wp:core-embed/youtube {"url":"https://www.youtube.com/watch?v=GGS-tKTXw4Y"} --><figure class="wp-block-embed-youtube wp-block-embed">https://www.youtube.com/watch?v=GGS-tKTXw4Y<figcaption>Embedded content from youtube</figcaption></figure><!-- /wp:core-embed/youtube -->', - ), - array( + ], + [ 'title' => 'Twitter Embed', 'content' => '<!-- wp:core-embed/twitter {"url":"https://twitter.com/AMPhtml/status/963443140005957632"} --><figure class="wp-block-embed-twitter wp-block-embed">https://twitter.com/AMPhtml/status/963443140005957632<figcaption>We are Automattic</figcaption></figure><!-- /wp:core-embed/twitter -->', - ), - array( + ], + [ 'title' => 'Gallery With 3 Columns', 'content' => '<!-- wp:core/gallery --><ul class="wp-block-gallery alignnone columns-3 is-cropped"><li class="blocks-gallery-item"><figure><img src="https://cldup.com/uuUqE_dXzy.jpg" alt="title" /></figure></li><li class="blocks-gallery-item"><figure><img src="https://cldup.com/-3VMmmrPm9.jpg" alt="title" /></figure></li><li class="blocks-gallery-item"><figure><img src="https://cldup.com/aMbxBM0zAi.jpg" alt="title" /></figure></li></ul><!-- /wp:core/gallery -->', - ), - array( + ], + [ 'title' => 'Audio Shortcode', 'content' => '<!-- wp:core/shortcode -->[audio src=https://wptavern.com/wp-content/uploads/2017/11/EPISODE-296-Gutenberg-Telemetry-Calypso-and-More-With-Matt-Mullenweg.mp3]<!-- /wp:core/shortcode -->', - ), - array( + ], + [ 'title' => 'Caption Shortcode', 'content' => '<!-- wp:core/shortcode -->[caption width=150]This is a caption[/caption]<!-- /wp:core/shortcode -->', - ), - ); + ], + ]; $content = ''; foreach ( $blocks as $block ) { @@ -117,12 +117,12 @@ function get_test_block_permutations() { */ function create_test_reusable_block() { return wp_insert_post( - array( + [ 'post_type' => 'wp_block', 'post_title' => 'Test Reusable Block', 'post_content' => '<!-- wp:core/video --><figure class="wp-block-video"><video src="https://videos.files.wordpress.com/DK5mLrbr/video-ca6dc0ab4a_hd.mp4" controls=""></video></figure><!-- /wp:core/video -->', 'post_status' => 'publish', - ) + ] ); } @@ -142,11 +142,11 @@ function create_gutenberg_test_post( $content ) { $page_id = $page->ID; } else { $page_id = wp_insert_post( - array( + [ 'post_name' => $slug, 'post_title' => $title, 'post_type' => 'page', - ) + ] ); if ( ! $page_id || is_wp_error( $page_id ) ) { @@ -155,10 +155,10 @@ function create_gutenberg_test_post( $content ) { } $update = wp_update_post( - array( + [ 'ID' => $page_id, 'post_content' => $content, - ) + ] ); if ( ! $update ) { diff --git a/bin/verify-version-consistency.php b/bin/verify-version-consistency.php index a50bc5fe12d..a7d2837ddbc 100755 --- a/bin/verify-version-consistency.php +++ b/bin/verify-version-consistency.php @@ -12,7 +12,7 @@ exit( 1 ); } -$versions = array(); +$versions = []; $readme_txt = file_get_contents( dirname( __FILE__ ) . '/../readme.txt' ); if ( ! preg_match( '/Stable tag:\s+(?P<version>\S+)/i', $readme_txt, $matches ) ) { diff --git a/includes/admin/class-amp-admin-pointer.php b/includes/admin/class-amp-admin-pointer.php index 5087ac178ee..90cfc9a0d74 100644 --- a/includes/admin/class-amp-admin-pointer.php +++ b/includes/admin/class-amp-admin-pointer.php @@ -61,10 +61,10 @@ class AMP_Admin_Pointer { * } */ public function __construct( $slug, array $args ) { - $default_position = array( + $default_position = [ 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'bottom', - ); + ]; if ( isset( $args['position'] ) ) { $args['position'] = wp_parse_args( (array) $args['position'], $default_position ); @@ -73,7 +73,7 @@ public function __construct( $slug, array $args ) { $this->slug = $slug; $this->args = wp_parse_args( $args, - array( + [ 'selector' => '', 'description' => '', 'heading' => '', @@ -81,7 +81,7 @@ public function __construct( $slug, array $args ) { 'position' => $default_position, 'class' => '', 'active_callback' => null, - ) + ] ); } @@ -141,7 +141,7 @@ public function enqueue() { wp_enqueue_style( 'amp-validation-tooltips', amp_get_asset_url( 'css/amp-validation-tooltips.css' ), - array( 'wp-pointer' ), + [ 'wp-pointer' ], AMP__VERSION ); @@ -169,11 +169,11 @@ private function print_js() { $content = '<h3>' . wp_kses( $this->args['heading'], 'amp_admin_pointer' ) . '</h3>' . $content; } - $args = array( + $args = [ 'content' => $content, 'position' => $this->args['position'], 'pointerClass' => 'wp-pointer wp-amp-pointer' . ( ! empty( $this->args['class'] ) ? ' ' . $this->args['class'] : '' ), - ); + ]; ?> <script type="text/javascript"> diff --git a/includes/admin/class-amp-admin-pointers.php b/includes/admin/class-amp-admin-pointers.php index 2e51b14b7b7..e0b8aca838f 100644 --- a/includes/admin/class-amp-admin-pointers.php +++ b/includes/admin/class-amp-admin-pointers.php @@ -21,7 +21,7 @@ class AMP_Admin_Pointers { public function init() { add_action( 'admin_enqueue_scripts', - array( $this, 'enqueue_scripts' ) + [ $this, 'enqueue_scripts' ] ); } @@ -57,57 +57,57 @@ public function enqueue_scripts( $hook_suffix ) { * @return array List of AMP_Admin_Pointer instances. */ private function get_pointers() { - return array( + return [ new AMP_Admin_Pointer( 'amp_template_mode_pointer_10', - array( + [ 'selector' => '#toplevel_page_amp-options', 'heading' => __( 'AMP', 'amp' ), 'subheading' => __( 'New AMP Template Modes', 'amp' ), 'description' => __( 'You can now reuse your theme\'s templates and styles in AMP responses, in both “Transitional” and “Standard” modes.', 'amp' ), - 'position' => array( + 'position' => [ 'align' => 'middle', - ), + ], 'active_callback' => static function() { return version_compare( strtok( AMP__VERSION, '-' ), '1.1', '<' ); }, - ) + ] ), new AMP_Admin_Pointer( 'amp_stories_support_pointer_12', - array( + [ 'selector' => '#toplevel_page_amp-options', 'heading' => __( 'AMP', 'amp' ), 'subheading' => __( 'Stories', 'amp' ), 'description' => __( 'You can now enable Stories, a visual storytelling format for the open web which immerses your readers in fast-loading, full-screen, and visually rich experiences.', 'amp' ), - 'position' => array( + 'position' => [ 'align' => 'middle', - ), + ], 'active_callback' => static function( $hook_suffix ) { if ( 'toplevel_page_amp-options' === $hook_suffix ) { return false; } return ! AMP_Options_Manager::is_stories_experience_enabled(); }, - ) + ] ), new AMP_Admin_Pointer( 'amp_stories_menu_pointer_12', - array( + [ 'selector' => '#menu-posts-' . AMP_Story_Post_Type::POST_TYPE_SLUG, 'heading' => __( 'AMP', 'amp' ), 'description' => __( 'Head over here to create your first story.', 'amp' ), - 'position' => array( + 'position' => [ 'align' => 'middle', - ), + ], 'active_callback' => static function( $hook_suffix ) { if ( 'edit.php' === $hook_suffix && AMP_Story_Post_Type::POST_TYPE_SLUG === filter_input( INPUT_GET, 'post_type' ) ) { return false; } return AMP_Options_Manager::is_stories_experience_enabled(); }, - ) + ] ), - ); + ]; } } diff --git a/includes/admin/class-amp-customizer.php b/includes/admin/class-amp-customizer.php index 32c267ee914..61df10acc3c 100644 --- a/includes/admin/class-amp-customizer.php +++ b/includes/admin/class-amp-customizer.php @@ -59,9 +59,9 @@ public static function init( $wp_customize ) { $self->register_settings(); $self->register_ui(); - add_action( 'customize_controls_enqueue_scripts', array( $self, 'add_customizer_scripts' ) ); - add_action( 'customize_controls_print_footer_scripts', array( $self, 'print_controls_templates' ) ); - add_action( 'customize_preview_init', array( $self, 'init_preview' ) ); + add_action( 'customize_controls_enqueue_scripts', [ $self, 'add_customizer_scripts' ] ); + add_action( 'customize_controls_print_footer_scripts', [ $self, 'print_controls_templates' ] ); + add_action( 'customize_preview_init', [ $self, 'init_preview' ] ); } /** @@ -72,15 +72,15 @@ public static function init( $wp_customize ) { */ public function init_preview() { add_action( 'amp_post_template_head', 'wp_no_robots' ); - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) ); - add_action( 'amp_customizer_enqueue_preview_scripts', array( $this, 'enqueue_preview_scripts' ) ); + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_preview_scripts' ] ); + add_action( 'amp_customizer_enqueue_preview_scripts', [ $this, 'enqueue_preview_scripts' ] ); // Output scripts and styles which will break AMP validation only when preview is opened with controls for manipulation. if ( $this->wp_customize->get_messenger_channel() ) { - add_action( 'amp_post_template_head', array( $this->wp_customize, 'customize_preview_loading_style' ) ); - add_action( 'amp_post_template_css', array( $this, 'add_customize_preview_styles' ) ); - add_action( 'amp_post_template_head', array( $this->wp_customize, 'remove_frameless_preview_messenger_channel' ) ); - add_action( 'amp_post_template_footer', array( $this, 'add_preview_scripts' ) ); + add_action( 'amp_post_template_head', [ $this->wp_customize, 'customize_preview_loading_style' ] ); + add_action( 'amp_post_template_css', [ $this, 'add_customize_preview_styles' ] ); + add_action( 'amp_post_template_head', [ $this->wp_customize, 'remove_frameless_preview_messenger_channel' ] ); + add_action( 'amp_post_template_footer', [ $this, 'add_preview_scripts' ] ); } } @@ -90,12 +90,12 @@ public function init_preview() { public function register_ui() { $this->wp_customize->add_panel( self::PANEL_ID, - array( + [ 'type' => 'amp', 'title' => __( 'AMP', 'amp' ), /* translators: placeholder is URL to AMP project. */ 'description' => sprintf( __( '<a href="%s" target="_blank">The AMP Project</a> is a Google-led initiative that dramatically improves loading speeds on phones and tablets. You can use the Customizer to preview changes to your AMP template before publishing them.', 'amp' ), 'https://ampproject.org' ), - ) + ] ); /** @@ -137,7 +137,7 @@ public function add_customizer_scripts() { wp_enqueue_script( 'amp-customize-controls', amp_get_asset_url( 'js/amp-customize-controls.js' ), - array( 'jquery', 'customize-controls' ), + [ 'jquery', 'customize-controls' ], AMP__VERSION, true ); @@ -147,15 +147,15 @@ public function add_customizer_scripts() { sprintf( 'ampCustomizeControls.boot( %s );', wp_json_encode( - array( + [ 'queryVar' => amp_get_slug(), 'panelId' => self::PANEL_ID, 'ampUrl' => amp_admin_get_preview_permalink(), - 'l10n' => array( + 'l10n' => [ 'unavailableMessage' => __( 'AMP is not available for the page currently being previewed.', 'amp' ), 'unavailableLinkText' => __( 'Navigate to an AMP compatible page', 'amp' ), - ), - ) + ], + ] ) ) ); @@ -195,7 +195,7 @@ public function enqueue_preview_scripts() { wp_enqueue_script( 'amp-customize-preview', amp_get_asset_url( 'js/amp-customize-preview.js' ), - array( 'jquery', 'customize-preview' ), + [ 'jquery', 'customize-preview' ], AMP__VERSION, true ); @@ -220,10 +220,10 @@ public function enqueue_preview_scripts() { sprintf( 'ampCustomizePreview.boot( %s );', wp_json_encode( - array( + [ 'available' => $available, 'enabled' => is_amp_endpoint(), - ) + ] ) ) ); diff --git a/includes/admin/class-amp-editor-blocks.php b/includes/admin/class-amp-editor-blocks.php index dcf46489541..213b71fd752 100644 --- a/includes/admin/class-amp-editor-blocks.php +++ b/includes/admin/class-amp-editor-blocks.php @@ -16,14 +16,14 @@ class AMP_Editor_Blocks { * * @var array */ - public $content_required_amp_scripts = array(); + public $content_required_amp_scripts = []; /** * AMP components that have blocks. * * @var array */ - public $amp_blocks = array( + public $amp_blocks = [ 'amp-mathml', 'amp-timeago', 'amp-o2-player', @@ -34,14 +34,14 @@ class AMP_Editor_Blocks { 'amp-brid-player', 'amp-ima-video', 'amp-fit-text', - ); + ]; /** * Init. */ public function init() { if ( function_exists( 'register_block_type' ) ) { - add_filter( 'wp_kses_allowed_html', array( $this, 'whitelist_block_atts_in_wp_kses_allowed_html' ), 10, 2 ); + add_filter( 'wp_kses_allowed_html', [ $this, 'whitelist_block_atts_in_wp_kses_allowed_html' ], 10, 2 ); /* * Dirty AMP is required when a site is in AMP-first mode but not all templates are being served @@ -55,8 +55,8 @@ public function init() { * as much as possible. For more, see <https://github.com/ampproject/amp-wp/issues/1192>. */ if ( amp_is_canonical() ) { - add_filter( 'the_content', array( $this, 'tally_content_requiring_amp_scripts' ) ); - add_action( 'wp_print_footer_scripts', array( $this, 'print_dirty_amp_scripts' ) ); + add_filter( 'the_content', [ $this, 'tally_content_requiring_amp_scripts' ] ); + add_action( 'wp_print_footer_scripts', [ $this, 'print_dirty_amp_scripts' ] ); } } } @@ -89,18 +89,18 @@ public function whitelist_block_atts_in_wp_kses_allowed_html( $tags, $context ) foreach ( $this->amp_blocks as $amp_block ) { if ( ! isset( $tags[ $amp_block ] ) ) { - $tags[ $amp_block ] = array(); + $tags[ $amp_block ] = []; } // @todo The global attributes included here should be matched up with what is actually used by each block. $tags[ $amp_block ] = array_merge( array_fill_keys( - array( + [ 'layout', 'width', 'height', 'class', - ), + ], true ), $tags[ $amp_block ] diff --git a/includes/admin/class-amp-post-meta-box.php b/includes/admin/class-amp-post-meta-box.php index bd560805036..9c479a63fe0 100644 --- a/includes/admin/class-amp-post-meta-box.php +++ b/includes/admin/class-amp-post-meta-box.php @@ -86,20 +86,20 @@ public function init() { register_meta( 'post', self::STATUS_POST_META_KEY, - array( - 'sanitize_callback' => array( $this, 'sanitize_status' ), + [ + 'sanitize_callback' => [ $this, 'sanitize_status' ], 'type' => 'string', 'description' => __( 'AMP status.', 'amp' ), 'show_in_rest' => true, 'single' => true, - ) + ] ); - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); - add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_assets' ) ); - add_action( 'post_submitbox_misc_actions', array( $this, 'render_status' ) ); - add_action( 'save_post', array( $this, 'save_amp_status' ) ); - add_filter( 'preview_post_link', array( $this, 'preview_post_link' ) ); + add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] ); + add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_assets' ] ); + add_action( 'post_submitbox_misc_actions', [ $this, 'render_status' ] ); + add_action( 'save_post', [ $this, 'save_amp_status' ] ); + add_filter( 'preview_post_link', [ $this, 'preview_post_link' ] ); } /** @@ -110,7 +110,7 @@ public function init() { */ public function sanitize_status( $status ) { $status = strtolower( trim( $status ) ); - if ( ! in_array( $status, array( self::ENABLED_STATUS, self::DISABLED_STATUS ), true ) ) { + if ( ! in_array( $status, [ self::ENABLED_STATUS, self::DISABLED_STATUS ], true ) ) { /* * In lieu of actual validation being available, clear the status entirely * so that the underlying default status will be used instead. @@ -153,7 +153,7 @@ public function enqueue_admin_assets() { $script_deps_path = AMP__DIR__ . '/assets/js/' . self::ASSETS_HANDLE . '.deps.json'; $script_dependencies = file_exists( $script_deps_path ) ? json_decode( file_get_contents( $script_deps_path ), false ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - : array(); + : []; // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter wp_enqueue_script( @@ -176,16 +176,16 @@ public function enqueue_admin_assets() { sprintf( 'ampPostMetaBox.boot( %s );', wp_json_encode( - array( + [ 'previewLink' => esc_url_raw( add_query_arg( amp_get_slug(), '', get_preview_post_link( $post ) ) ), 'canonical' => amp_is_canonical(), 'enabled' => empty( $support_errors ), - 'canSupport' => 0 === count( array_diff( $support_errors, array( 'post-status-disabled' ) ) ), + 'canSupport' => 0 === count( array_diff( $support_errors, [ 'post-status-disabled' ] ) ), 'statusInputName' => self::STATUS_INPUT_NAME, - 'l10n' => array( + 'l10n' => [ 'ampPreviewBtnLabel' => __( 'Preview changes in AMP (opens in new window)', 'amp' ), - ), - ) + ], + ] ) ) ); @@ -205,14 +205,14 @@ public function enqueue_block_assets() { wp_enqueue_style( self::BLOCK_ASSET_HANDLE, amp_get_asset_url( 'css/' . self::BLOCK_ASSET_HANDLE . '.css' ), - array(), + [], AMP__VERSION ); $script_deps_path = AMP__DIR__ . '/assets/js/' . self::BLOCK_ASSET_HANDLE . '.deps.json'; $script_dependencies = file_exists( $script_deps_path ) ? json_decode( file_get_contents( $script_deps_path ), false ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - : array(); + : []; wp_enqueue_script( self::BLOCK_ASSET_HANDLE, @@ -226,15 +226,15 @@ public function enqueue_block_assets() { $enabled_status = $status_and_errors['status']; $error_messages = $this->get_error_messages( $status_and_errors['status'], $status_and_errors['errors'] ); - $data = array( - 'possibleStatuses' => array( self::ENABLED_STATUS, self::DISABLED_STATUS ), + $data = [ + 'possibleStatuses' => [ self::ENABLED_STATUS, self::DISABLED_STATUS ], 'defaultStatus' => $enabled_status, 'errorMessages' => $error_messages, 'isWebsiteEnabled' => AMP_Options_Manager::is_website_experience_enabled(), 'isStoriesEnabled' => AMP_Options_Manager::is_stories_experience_enabled(), 'hasThemeSupport' => current_theme_supports( AMP_Theme_Support::SLUG ), 'isStandardMode' => amp_is_canonical(), - ); + ]; wp_localize_script( self::BLOCK_ASSET_HANDLE, @@ -280,10 +280,10 @@ public function render_status( $post ) { $errors = $status_and_errors['errors']; $error_messages = $this->get_error_messages( $status, $errors ); - $labels = array( + $labels = [ 'enabled' => __( 'Enabled', 'amp' ), 'disabled' => __( 'Disabled', 'amp' ), - ); + ]; // The preceding variables are used inside the following amp-status.php template. include AMP__DIR__ . '/templates/admin/amp-status.php'; @@ -310,14 +310,14 @@ public static function get_status_and_errors( $post ) { if ( current_theme_supports( AMP_Theme_Support::SLUG ) ) { $availability = AMP_Theme_Support::get_template_availability( $post ); $status = $availability['supported'] ? self::ENABLED_STATUS : self::DISABLED_STATUS; - $errors = array_diff( $availability['errors'], array( 'post-status-disabled' ) ); // Subtract the status which the metabox will allow to be toggled. + $errors = array_diff( $availability['errors'], [ 'post-status-disabled' ] ); // Subtract the status which the metabox will allow to be toggled. if ( true === $availability['immutable'] ) { $errors[] = 'status_immutable'; } } else { $errors = AMP_Post_Type_Support::get_support_errors( $post ); $status = empty( $errors ) ? self::ENABLED_STATUS : self::DISABLED_STATUS; - $errors = array_diff( $errors, array( 'post-status-disabled' ) ); // Subtract the status which the metabox will allow to be toggled. + $errors = array_diff( $errors, [ 'post-status-disabled' ] ); // Subtract the status which the metabox will allow to be toggled. } return compact( 'status', 'errors' ); @@ -332,7 +332,7 @@ public static function get_status_and_errors( $post ) { * @return array $error_messages The error messages, as an array of strings. */ public function get_error_messages( $status, $errors ) { - $error_messages = array(); + $error_messages = []; if ( in_array( 'status_immutable', $errors, true ) ) { if ( self::ENABLED_STATUS === $status ) { $error_messages[] = __( 'Your site does not allow AMP to be disabled.', 'amp' ); @@ -360,7 +360,7 @@ public function get_error_messages( $status, $errors ) { if ( in_array( 'skip-post', $errors, true ) ) { $error_messages[] = __( 'A plugin or theme has disabled AMP support.', 'amp' ); } - if ( count( array_diff( $errors, array( 'status_immutable', 'page-on-front', 'page-for-posts', 'password-protected', 'post-type-support', 'skip-post', 'template_unsupported', 'no_matching_template' ) ) ) > 0 ) { + if ( count( array_diff( $errors, [ 'status_immutable', 'page-on-front', 'page-for-posts', 'password-protected', 'post-type-support', 'skip-post', 'template_unsupported', 'no_matching_template' ] ) ) > 0 ) { $error_messages[] = __( 'Unavailable for an unknown reason.', 'amp' ); } diff --git a/includes/admin/class-amp-story-templates.php b/includes/admin/class-amp-story-templates.php index fad1a8a7a74..335ec1d8f59 100644 --- a/includes/admin/class-amp-story-templates.php +++ b/includes/admin/class-amp-story-templates.php @@ -36,12 +36,12 @@ public function init() { return; } - add_filter( 'rest_wp_block_query', array( $this, 'filter_rest_wp_block_query' ), 10, 2 ); - add_action( 'save_post_wp_block', array( $this, 'flag_template_as_modified' ) ); + add_filter( 'rest_wp_block_query', [ $this, 'filter_rest_wp_block_query' ], 10, 2 ); + add_action( 'save_post_wp_block', [ $this, 'flag_template_as_modified' ] ); // Temporary filters for disallowing the users to edit any templates until the feature has been implemented. - add_filter( 'user_has_cap', array( $this, 'filter_user_has_cap' ), 10, 3 ); - add_filter( 'pre_get_posts', array( $this, 'filter_pre_get_posts' ) ); + add_filter( 'user_has_cap', [ $this, 'filter_user_has_cap' ], 10, 3 ); + add_filter( 'pre_get_posts', [ $this, 'filter_pre_get_posts' ] ); $this->register_taxonomy(); $this->maybe_import_story_templates(); @@ -83,15 +83,15 @@ public function filter_pre_get_posts( $query ) { $tax_query = $query->get( 'tax_query' ); if ( empty( $tax_query ) ) { - $tax_query = array(); + $tax_query = []; } - $tax_query[] = array( + $tax_query[] = [ 'taxonomy' => self::TEMPLATES_TAXONOMY, 'field' => 'slug', - 'terms' => array( self::TEMPLATES_TERM ), + 'terms' => [ self::TEMPLATES_TERM ], 'operator' => 'NOT IN', - ); + ]; $query->set( 'tax_query', $tax_query ); return $query; @@ -129,13 +129,13 @@ public function import_story_templates() { $post_id = wp_insert_post( wp_slash( - array( + [ 'post_title' => $template['title'], 'post_type' => 'wp_block', 'post_status' => 'publish', 'post_content' => $post_content, 'post_name' => $template['name'], - ) + ] ) ); if ( ! $post_id ) { @@ -160,17 +160,17 @@ protected function maybe_update_template( $template_id, $template, $content ) { return; } - remove_action( 'save_post_wp_block', array( $this, 'flag_template_as_modified' ) ); + remove_action( 'save_post_wp_block', [ $this, 'flag_template_as_modified' ] ); wp_update_post( wp_slash( - array( + [ 'ID' => $template_id, 'post_content' => $content, 'post_title' => $template['title'], - ) + ] ) ); - add_action( 'save_post_wp_block', array( $this, 'flag_template_as_modified' ) ); + add_action( 'save_post_wp_block', [ $this, 'flag_template_as_modified' ] ); } /** @@ -179,48 +179,48 @@ protected function maybe_update_template( $template_id, $template, $content ) { * @return array Story templates. */ public static function get_story_templates() { - return array( - array( + return [ + [ 'title' => __( 'Template: Travel Tip', 'amp' ), 'name' => 'travel-tip', - ), - array( + ], + [ 'title' => __( 'Template: Quote', 'amp' ), 'name' => 'quote', - ), - array( + ], + [ 'title' => __( 'Template: Travel CTA', 'amp' ), 'name' => 'travel-cta', - ), - array( + ], + [ 'title' => __( 'Template: Title Page', 'amp' ), 'name' => 'title-page', - ), - array( + ], + [ 'title' => __( 'Template: Travel Vertical', 'amp' ), 'name' => 'travel-vertical', - ), - array( + ], + [ 'title' => __( 'Template: Fandom Title', 'amp' ), 'name' => 'fandom-title', - ), - array( + ], + [ 'title' => __( 'Template: Fandom CTA', 'amp' ), 'name' => 'fandom-cta', - ), - array( + ], + [ 'title' => __( 'Template: Fandom Fact', 'amp' ), 'name' => 'fandom-fact', - ), - array( + ], + [ 'title' => __( 'Template: Fandom Fact Text', 'amp' ), 'name' => 'fandom-fact-text', - ), - array( + ], + [ 'title' => __( 'Template: Fandom Intro', 'amp' ), 'name' => 'fandom-intro', - ), - ); + ], + ]; } /** @@ -234,12 +234,12 @@ private function template_exists( $slug ) { return 0; } - $args = array( + $args = [ 'name' => $slug, 'post_type' => 'wp_block', 'post_status' => 'publish', 'posts_per_page' => 1, - ); + ]; $templates = get_posts( $args ); if ( ! empty( $templates ) ) { return $templates[0]->ID; @@ -255,7 +255,7 @@ private function register_taxonomy() { register_taxonomy( self::TEMPLATES_TAXONOMY, 'wp_block', - array( + [ 'query_var' => self::TEMPLATES_TAXONOMY, 'show_admin_column' => false, 'show_in_rest' => true, @@ -268,17 +268,17 @@ private function register_taxonomy() { 'hierarchical' => false, 'show_in_menu' => false, 'meta_box_cb' => false, - ) + ] ); if ( ! term_exists( self::TEMPLATES_TERM, self::TEMPLATES_TAXONOMY ) ) { wp_insert_term( __( 'Story Template', 'amp' ), self::TEMPLATES_TAXONOMY, - array( + [ 'description' => __( 'Story Template', 'amp' ), 'slug' => self::TEMPLATES_TERM, - ) + ] ); } } @@ -308,14 +308,14 @@ public function filter_rest_wp_block_query( $args, $request ) { $edited_post = get_post( absint( $params['post'] ) ); if ( AMP_Story_Post_Type::POST_TYPE_SLUG !== $edited_post->post_type ) { if ( ! isset( $args['tax_query'] ) ) { - $args['tax_query'] = array(); + $args['tax_query'] = []; } - $args['tax_query'][] = array( + $args['tax_query'][] = [ 'taxonomy' => self::TEMPLATES_TAXONOMY, 'field' => 'slug', - 'terms' => array( self::TEMPLATES_TERM ), + 'terms' => [ self::TEMPLATES_TERM ], 'operator' => 'NOT IN', - ); + ]; } return $args; diff --git a/includes/admin/functions.php b/includes/admin/functions.php index 072181c9261..1ab48dad096 100644 --- a/includes/admin/functions.php +++ b/includes/admin/functions.php @@ -26,10 +26,10 @@ function amp_init_customizer() { } // Fire up the AMP Customizer. - add_action( 'customize_register', array( 'AMP_Template_Customizer', 'init' ), 500 ); + add_action( 'customize_register', [ 'AMP_Template_Customizer', 'init' ], 500 ); // Add some basic design settings + controls to the Customizer. - add_action( 'amp_init', array( 'AMP_Customizer_Design_Settings', 'init' ) ); + add_action( 'amp_init', [ 'AMP_Customizer_Design_Settings', 'init' ] ); // Add a link to the Customizer. add_action( 'admin_menu', 'amp_add_customizer_link' ); @@ -51,7 +51,7 @@ function amp_admin_get_preview_permalink() { // Make sure the desired post type is actually supported, and if so, prefer it. $supported_post_types = get_post_types_by_support( AMP_Post_Type_Support::SLUG ); if ( in_array( $post_type, $supported_post_types, true ) ) { - $supported_post_types = array_unique( array_merge( array( $post_type ), $supported_post_types ) ); + $supported_post_types = array_unique( array_merge( [ $post_type ], $supported_post_types ) ); } // Bail if there are no supported post types. @@ -68,7 +68,7 @@ function amp_admin_get_preview_permalink() { } $post_ids = get_posts( - array( + [ 'no_found_rows' => true, 'suppress_filters' => false, 'post_status' => 'publish', @@ -77,7 +77,7 @@ function amp_admin_get_preview_permalink() { 'posts_per_page' => 1, 'fields' => 'ids', // @todo This should eventually do a meta_query to make sure there are none that have AMP_Post_Meta_Box::STATUS_POST_META_KEY = DISABLED_STATUS. - ) + ] ); if ( empty( $post_ids ) ) { @@ -99,11 +99,11 @@ function amp_add_customizer_link() { } $menu_slug = add_query_arg( - array( + [ 'autofocus[panel]' => AMP_Template_Customizer::PANEL_ID, 'url' => rawurlencode( amp_admin_get_preview_permalink() ), 'return' => rawurlencode( admin_url() ), - ), + ], 'customize.php' ); @@ -151,7 +151,7 @@ function amp_add_options_menu() { * @param array $analytics Analytics. * @return array Analytics. */ -function amp_add_custom_analytics( $analytics = array() ) { +function amp_add_custom_analytics( $analytics = [] ) { $analytics = amp_get_analytics( $analytics ); /** diff --git a/includes/amp-helper-functions.php b/includes/amp-helper-functions.php index b41e53c5bea..7455f84225c 100644 --- a/includes/amp-helper-functions.php +++ b/includes/amp-helper-functions.php @@ -194,7 +194,7 @@ function amp_add_amphtml_link() { // Check to see if there are known unaccepted validation errors for this URL. if ( current_theme_supports( AMP_Theme_Support::SLUG ) ) { - $validation_errors = AMP_Validated_URL_Post_Type::get_invalid_url_validation_errors( $current_url, array( 'ignore_accepted' => true ) ); + $validation_errors = AMP_Validated_URL_Post_Type::get_invalid_url_validation_errors( $current_url, [ 'ignore_accepted' => true ] ); $error_count = count( $validation_errors ); if ( $error_count > 0 ) { echo "<!--\n"; @@ -250,7 +250,7 @@ function post_supports_amp( $post ) { function is_amp_endpoint() { global $pagenow, $wp_query; - if ( is_admin() || is_embed() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || in_array( $pagenow, array( 'wp-login.php', 'wp-signup.php', 'wp-activate.php' ), true ) ) { + if ( is_admin() || is_embed() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || in_array( $pagenow, [ 'wp-login.php', 'wp-signup.php', 'wp-activate.php' ], true ) ) { return false; } @@ -400,7 +400,7 @@ function amp_register_default_scripts( $wp_scripts ) { * Polyfill dependencies that are registered in Gutenberg and WordPress 5.0. * Note that Gutenberg will override these at wp_enqueue_scripts if it is active. */ - $handles = array( 'wp-i18n', 'wp-dom-ready' ); + $handles = [ 'wp-i18n', 'wp-dom-ready' ]; foreach ( $handles as $handle ) { if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { $wp_scripts->add( $handle, amp_get_asset_url( sprintf( 'js/%s.js', $handle ) ) ); @@ -412,15 +412,15 @@ function amp_register_default_scripts( $wp_scripts ) { $wp_scripts->add( $handle, 'https://cdn.ampproject.org/v0.js', - array(), + [], null ); $wp_scripts->add_data( $handle, 'amp_script_attributes', - array( + [ 'async' => true, - ) + ] ); // Shadow AMP API. @@ -428,19 +428,19 @@ function amp_register_default_scripts( $wp_scripts ) { $wp_scripts->add( $handle, 'https://cdn.ampproject.org/shadow-v0.js', - array(), + [], null ); $wp_scripts->add_data( $handle, 'amp_script_attributes', - array( + [ 'async' => true, - ) + ] ); // Get all AMP components as defined in the spec. - $extensions = array(); + $extensions = []; foreach ( AMP_Allowed_Tags_Generated::get_allowed_tag( 'script' ) as $script_spec ) { if ( isset( $script_spec[ AMP_Rule_Spec::TAG_SPEC ]['extension_spec']['name'], $script_spec[ AMP_Rule_Spec::TAG_SPEC ]['extension_spec']['version'] ) ) { $versions = $script_spec[ AMP_Rule_Spec::TAG_SPEC ]['extension_spec']['version']; @@ -459,7 +459,7 @@ function amp_register_default_scripts( $wp_scripts ) { $wp_scripts->add( $extension, $src, - array( 'amp-runtime' ), + [ 'amp-runtime' ], null ); } @@ -533,9 +533,9 @@ function amp_filter_script_loader_tag( $tag, $handle ) { * All scripts from AMP CDN should be loaded async. * See <https://www.ampproject.org/docs/integration/pwa-amp/amp-in-pwa#include-"shadow-amp"-in-your-progressive-web-app>. */ - $attributes = array( + $attributes = [ 'async' => true, - ); + ]; // Add custom-template and custom-element attributes. All component scripts look like https://cdn.ampproject.org/v0/:name-:version.js. if ( 'v0' === strtok( substr( $src, strlen( $prefix ) ), '/' ) ) { @@ -622,8 +622,8 @@ function amp_filter_font_style_loader_tag_with_crossorigin_anonymous( $tag, $han * @param array $analytics Analytics entries. * @return array Analytics. */ -function amp_get_analytics( $analytics = array() ) { - $analytics_entries = AMP_Options_Manager::get_option( 'analytics', array() ); +function amp_get_analytics( $analytics = [] ) { + $analytics_entries = AMP_Options_Manager::get_option( 'analytics', [] ); /** * Add amp-analytics tags. @@ -642,11 +642,11 @@ function amp_get_analytics( $analytics = array() ) { } foreach ( $analytics_entries as $entry_id => $entry ) { - $analytics[ $entry_id ] = array( + $analytics[ $entry_id ] = [ 'type' => $entry['type'], - 'attributes' => array(), + 'attributes' => [], 'config_data' => json_decode( $entry['config'] ), - ); + ]; } return $analytics; @@ -661,7 +661,7 @@ function amp_get_analytics( $analytics = array() ) { */ function amp_print_analytics( $analytics ) { if ( '' === $analytics ) { - $analytics = array(); + $analytics = []; } $analytics_entries = amp_get_analytics( $analytics ); @@ -689,17 +689,17 @@ function amp_print_analytics( $analytics ) { } $script_element = AMP_HTML_Utils::build_tag( 'script', - array( + [ 'type' => 'application/json', - ), + ], wp_json_encode( $analytics_entry['config_data'] ) ); $amp_analytics_attr = array_merge( - array( + [ 'id' => $id, 'type' => $analytics_entry['type'], - ), + ], $analytics_entry['attributes'] ); @@ -741,28 +741,28 @@ function amp_get_content_embed_handlers( $post = null ) { */ return apply_filters( 'amp_content_embed_handlers', - array( - 'AMP_Core_Block_Handler' => array(), - 'AMP_Twitter_Embed_Handler' => array(), - 'AMP_YouTube_Embed_Handler' => array(), - 'AMP_Crowdsignal_Embed_Handler' => array(), - 'AMP_DailyMotion_Embed_Handler' => array(), - 'AMP_Vimeo_Embed_Handler' => array(), - 'AMP_SoundCloud_Embed_Handler' => array(), - 'AMP_Instagram_Embed_Handler' => array(), - 'AMP_Issuu_Embed_Handler' => array(), - 'AMP_Meetup_Embed_Handler' => array(), - 'AMP_Vine_Embed_Handler' => array(), - 'AMP_Facebook_Embed_Handler' => array(), - 'AMP_Pinterest_Embed_Handler' => array(), - 'AMP_Playlist_Embed_Handler' => array(), - 'AMP_Reddit_Embed_Handler' => array(), - 'AMP_Tumblr_Embed_Handler' => array(), - 'AMP_Gallery_Embed_Handler' => array(), - 'AMP_Gfycat_Embed_Handler' => array(), - 'AMP_Hulu_Embed_Handler' => array(), - 'AMP_Imgur_Embed_Handler' => array(), - ), + [ + 'AMP_Core_Block_Handler' => [], + 'AMP_Twitter_Embed_Handler' => [], + 'AMP_YouTube_Embed_Handler' => [], + 'AMP_Crowdsignal_Embed_Handler' => [], + 'AMP_DailyMotion_Embed_Handler' => [], + 'AMP_Vimeo_Embed_Handler' => [], + 'AMP_SoundCloud_Embed_Handler' => [], + 'AMP_Instagram_Embed_Handler' => [], + 'AMP_Issuu_Embed_Handler' => [], + 'AMP_Meetup_Embed_Handler' => [], + 'AMP_Vine_Embed_Handler' => [], + 'AMP_Facebook_Embed_Handler' => [], + 'AMP_Pinterest_Embed_Handler' => [], + 'AMP_Playlist_Embed_Handler' => [], + 'AMP_Reddit_Embed_Handler' => [], + 'AMP_Tumblr_Embed_Handler' => [], + 'AMP_Gallery_Embed_Handler' => [], + 'AMP_Gfycat_Embed_Handler' => [], + 'AMP_Hulu_Embed_Handler' => [], + 'AMP_Imgur_Embed_Handler' => [], + ], $post ); } @@ -799,37 +799,37 @@ function amp_get_content_sanitizers( $post = null ) { $current_origin .= ':' . $parsed_home_url['port']; } - $sanitizers = array( - 'AMP_Core_Theme_Sanitizer' => array( + $sanitizers = [ + 'AMP_Core_Theme_Sanitizer' => [ 'template' => get_template(), 'stylesheet' => get_stylesheet(), - ), - 'AMP_Img_Sanitizer' => array( + ], + 'AMP_Img_Sanitizer' => [ 'align_wide_support' => current_theme_supports( 'align-wide' ), - ), - 'AMP_Form_Sanitizer' => array(), - 'AMP_Comments_Sanitizer' => array( + ], + 'AMP_Form_Sanitizer' => [], + 'AMP_Comments_Sanitizer' => [ 'comments_live_list' => ! empty( $theme_support_args['comments_live_list'] ), - ), - 'AMP_Video_Sanitizer' => array(), - 'AMP_O2_Player_Sanitizer' => array(), - 'AMP_Audio_Sanitizer' => array(), - 'AMP_Playbuzz_Sanitizer' => array(), - 'AMP_Embed_Sanitizer' => array(), - 'AMP_Iframe_Sanitizer' => array( + ], + 'AMP_Video_Sanitizer' => [], + 'AMP_O2_Player_Sanitizer' => [], + 'AMP_Audio_Sanitizer' => [], + 'AMP_Playbuzz_Sanitizer' => [], + 'AMP_Embed_Sanitizer' => [], + 'AMP_Iframe_Sanitizer' => [ 'add_placeholder' => true, 'current_origin' => $current_origin, - ), - 'AMP_Gallery_Block_Sanitizer' => array( // Note: Gallery block sanitizer must come after image sanitizers since itś logic is using the already sanitized images. + ], + 'AMP_Gallery_Block_Sanitizer' => [ // Note: Gallery block sanitizer must come after image sanitizers since itś logic is using the already sanitized images. 'carousel_required' => ! is_array( $theme_support_args ), // For back-compat. - ), - 'AMP_Block_Sanitizer' => array(), // Note: Block sanitizer must come after embed / media sanitizers since its logic is using the already sanitized content. - 'AMP_Script_Sanitizer' => array(), - 'AMP_Style_Sanitizer' => array( + ], + 'AMP_Block_Sanitizer' => [], // Note: Block sanitizer must come after embed / media sanitizers since its logic is using the already sanitized content. + 'AMP_Script_Sanitizer' => [], + 'AMP_Style_Sanitizer' => [ 'include_manifest_comment' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'always' : 'when_excessive', - ), - 'AMP_Tag_And_Attribute_Sanitizer' => array(), // Note: This whitelist sanitizer must come at the end to clean up any remaining issues the other sanitizers didn't catch. - ); + ], + 'AMP_Tag_And_Attribute_Sanitizer' => [], // Note: This whitelist sanitizer must come at the end to clean up any remaining issues the other sanitizers didn't catch. + ]; if ( ! empty( $theme_support_args['nav_menu_toggle'] ) ) { $sanitizers['AMP_Nav_Menu_Toggle_Sanitizer'] = $theme_support_args['nav_menu_toggle']; @@ -851,7 +851,7 @@ function amp_get_content_sanitizers( $post = null ) { $sanitizers = apply_filters( 'amp_content_sanitizers', $sanitizers, $post ); // Force style sanitizer and whitelist sanitizer to be at end. - foreach ( array( 'AMP_Style_Sanitizer', 'AMP_Tag_And_Attribute_Sanitizer' ) as $class_name ) { + foreach ( [ 'AMP_Style_Sanitizer', 'AMP_Tag_And_Attribute_Sanitizer' ] as $class_name ) { if ( isset( $sanitizers[ $class_name ] ) ) { $sanitizer = $sanitizers[ $class_name ]; unset( $sanitizers[ $class_name ] ); @@ -885,7 +885,7 @@ function amp_get_post_image_metadata( $post = null ) { $post_image_id = $post->ID; } else { $attached_image_ids = get_posts( - array( + [ 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', @@ -894,7 +894,7 @@ function amp_get_post_image_metadata( $post = null ) { 'order' => 'ASC', 'fields' => 'ids', 'suppress_filters' => false, - ) + ] ); if ( ! empty( $attached_image_ids ) ) { @@ -909,12 +909,12 @@ function amp_get_post_image_metadata( $post = null ) { $post_image_src = wp_get_attachment_image_src( $post_image_id, 'full' ); if ( is_array( $post_image_src ) ) { - $post_image_meta = array( + $post_image_meta = [ '@type' => 'ImageObject', 'url' => $post_image_src[0], 'width' => $post_image_src[1], 'height' => $post_image_src[2], - ); + ]; } return $post_image_meta; @@ -929,13 +929,13 @@ function amp_get_post_image_metadata( $post = null ) { * @return array $metadata All schema.org metadata for the post. */ function amp_get_schemaorg_metadata() { - $metadata = array( + $metadata = [ '@context' => 'http://schema.org', - 'publisher' => array( + 'publisher' => [ '@type' => 'Organization', 'name' => get_bloginfo( 'name' ), - ), - ); + ], + ]; /* * "The logo should be a rectangle, not a square. The logo should fit in a 60x600px rectangle., @@ -946,17 +946,17 @@ function amp_get_schemaorg_metadata() { $max_logo_width = 600; $max_logo_height = 60; $custom_logo_id = get_theme_mod( 'custom_logo' ); - $schema_img = array(); + $schema_img = []; if ( has_custom_logo() && $custom_logo_id ) { - $custom_logo_img = wp_get_attachment_image_src( $custom_logo_id, array( $max_logo_width, $max_logo_height ), false ); + $custom_logo_img = wp_get_attachment_image_src( $custom_logo_id, [ $max_logo_width, $max_logo_height ], false ); if ( $custom_logo_img ) { // @todo Warning: The width/height returned may not actually be physically the $max_logo_width and $max_logo_height for the image returned. - $schema_img = array( + $schema_img = [ 'url' => $custom_logo_img[0], 'width' => $custom_logo_img[1], 'height' => $custom_logo_img[2], - ); + ]; } } @@ -968,11 +968,11 @@ function amp_get_schemaorg_metadata() { * to add a site_icon_image_sizes filter which appends 60 to the list of sizes, but this will only help * when adding a new site icon and it would be irrelevant when a custom logo is present, per above. */ - $schema_img = array( + $schema_img = [ 'url' => get_site_icon_url( AMP_Post_Template::SITE_ICON_SIZE ), 'width' => AMP_Post_Template::SITE_ICON_SIZE, 'height' => AMP_Post_Template::SITE_ICON_SIZE, - ); + ]; } /** @@ -993,9 +993,9 @@ function amp_get_schemaorg_metadata() { if ( ! empty( $schema_img['url'] ) ) { $metadata['publisher']['logo'] = array_merge( - array( + [ '@type' => 'ImageObject', - ), + ], $schema_img ); } @@ -1004,21 +1004,21 @@ function amp_get_schemaorg_metadata() { if ( $post instanceof WP_Post ) { $metadata = array_merge( $metadata, - array( + [ '@type' => is_page() ? 'WebPage' : 'BlogPosting', 'mainEntityOfPage' => get_permalink(), 'headline' => get_the_title(), 'datePublished' => mysql2date( 'c', $post->post_date_gmt, false ), 'dateModified' => mysql2date( 'c', $post->post_modified_gmt, false ), - ) + ] ); $post_author = get_userdata( $post->post_author ); if ( $post_author ) { - $metadata['author'] = array( + $metadata['author'] = [ '@type' => 'Person', 'name' => html_entity_decode( $post_author->display_name, ENT_QUOTES, get_bloginfo( 'charset' ) ), - ); + ]; } $image_metadata = amp_get_post_image_metadata( $post ); @@ -1081,8 +1081,8 @@ function amp_print_schemaorg_metadata() { * @return string HTML markup with tags allowed by amp-mustache. */ function amp_wp_kses_mustache( $markup ) { - $amp_mustache_allowed_html_tags = array( 'strong', 'b', 'em', 'i', 'u', 's', 'small', 'mark', 'del', 'ins', 'sup', 'sub' ); - return wp_kses( $markup, array_fill_keys( $amp_mustache_allowed_html_tags, array() ) ); + $amp_mustache_allowed_html_tags = [ 'strong', 'b', 'em', 'i', 'u', 's', 'small', 'mark', 'del', 'ins', 'sup', 'sub' ]; + return wp_kses( $markup, array_fill_keys( $amp_mustache_allowed_html_tags, [] ) ); } /** @@ -1114,7 +1114,7 @@ function amp_add_admin_bar_view_link( $wp_admin_bar ) { } // Show nothing if there are rejected validation errors for this URL. - if ( ! is_amp_endpoint() && count( AMP_Validated_URL_Post_Type::get_invalid_url_validation_errors( amp_get_current_url(), array( 'ignore_accepted' => true ) ) ) > 0 ) { + if ( ! is_amp_endpoint() && count( AMP_Validated_URL_Post_Type::get_invalid_url_validation_errors( amp_get_current_url(), [ 'ignore_accepted' => true ] ) ) > 0 ) { return; } @@ -1128,7 +1128,7 @@ function amp_add_admin_bar_view_link( $wp_admin_bar ) { $icon = '🔗'; // LINK SYMBOL. - $parent = array( + $parent = [ 'id' => 'amp', 'title' => sprintf( '<span id="amp-admin-bar-item-status-icon">%s</span> %s', @@ -1136,7 +1136,7 @@ function amp_add_admin_bar_view_link( $wp_admin_bar ) { esc_html( is_amp_endpoint() ? __( 'Non-AMP', 'amp' ) : __( 'AMP', 'amp' ) ) ), 'href' => esc_url( $href ), - ); + ]; $wp_admin_bar->add_menu( $parent ); } @@ -1155,7 +1155,7 @@ function amp_print_story_auto_ads() { * @param array $data Story ads configuration data. * @param WP_Post $post The current story's post object. */ - $data = apply_filters( 'amp_story_auto_ads_configuration', array(), get_post() ); + $data = apply_filters( 'amp_story_auto_ads_configuration', [], get_post() ); if ( empty( $data ) ) { return; @@ -1163,11 +1163,11 @@ function amp_print_story_auto_ads() { $script_element = AMP_HTML_Utils::build_tag( 'script', - array( + [ 'type' => 'application/json', - ), + ], wp_json_encode( $data ) ); - echo AMP_HTML_Utils::build_tag( 'amp-story-auto-ads', array(), $script_element ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo AMP_HTML_Utils::build_tag( 'amp-story-auto-ads', [], $script_element ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } diff --git a/includes/amp-post-template-functions.php b/includes/amp-post-template-functions.php index fcd079cc032..1f152616ec6 100644 --- a/includes/amp-post-template-functions.php +++ b/includes/amp-post-template-functions.php @@ -55,11 +55,11 @@ function amp_post_template_add_scripts( $amp_template ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo amp_render_scripts( array_merge( - array( + [ // Just in case the runtime has been overridden by amp_post_template_data filter. 'amp-runtime' => $amp_template->get( 'amp_runtime_script' ), - ), - $amp_template->get( 'amp_component_scripts', array() ) + ], + $amp_template->get( 'amp_component_scripts', [] ) ) ); } @@ -70,7 +70,7 @@ function amp_post_template_add_scripts( $amp_template ) { * @param AMP_Post_Template $amp_template Template. */ function amp_post_template_add_fonts( $amp_template ) { - $font_urls = $amp_template->get( 'font_urls', array() ); + $font_urls = $amp_template->get( 'font_urls', [] ); foreach ( $font_urls as $slug => $url ) { printf( '<link rel="stylesheet" href="%s">', esc_url( esc_url( $url ) ) ); // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet } diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php index f257d28f571..f81cfad1f88 100644 --- a/includes/class-amp-autoloader.php +++ b/includes/class-amp-autoloader.php @@ -28,7 +28,7 @@ class AMP_Autoloader { * * @var string[] */ - private static $classmap = array( + private static $classmap = [ 'AMP_Editor_Blocks' => 'includes/admin/class-amp-editor-blocks', 'AMP_Theme_Support' => 'includes/class-amp-theme-support', 'AMP_Story_Post_Type' => 'includes/class-amp-story-post-type', @@ -110,7 +110,7 @@ class AMP_Autoloader { 'AMP_Widget_Text' => 'includes/widgets/class-amp-widget-text', 'AMP_Test_Stub_Sanitizer' => 'tests/php/stubs', 'AMP_Test_World_Sanitizer' => 'tests/php/stubs', - ); + ]; /** * Is registered. @@ -149,7 +149,7 @@ public static function register() { } if ( ! self::$is_registered ) { - spl_autoload_register( array( __CLASS__, 'autoload' ) ); + spl_autoload_register( [ __CLASS__, 'autoload' ] ); self::$is_registered = true; } } diff --git a/includes/class-amp-cli.php b/includes/class-amp-cli.php index 587a0498284..f92a5271df3 100644 --- a/includes/class-amp-cli.php +++ b/includes/class-amp-cli.php @@ -100,7 +100,7 @@ class AMP_CLI { * * @var array */ - public static $include_conditionals = array(); + public static $include_conditionals = []; /** * The maximum number of URLs to validate for each type. @@ -123,7 +123,7 @@ class AMP_CLI { * @type int $total The total number of URLs for this type, valid or invalid. * } */ - public static $validity_by_type = array(); + public static $validity_by_type = []; /** * Crawl the entire site to get AMP validation results. @@ -152,7 +152,7 @@ class AMP_CLI { * @throws Exception If an error happens. */ public function validate_site( $args, $assoc_args ) { - self::$include_conditionals = array(); + self::$include_conditionals = []; self::$force_crawl_urls = false; self::$limit_type_validate_count = (int) $assoc_args[ self::LIMIT_URLS_ARGUMENT ]; @@ -218,13 +218,13 @@ public function validate_site( $args, $assoc_args ) { $key_url_count = 'URL Count'; $key_validity_rate = 'Validity Rate'; - $table_validation_by_type = array(); + $table_validation_by_type = []; foreach ( self::$validity_by_type as $type_name => $validity ) { - $table_validation_by_type[] = array( + $table_validation_by_type[] = [ $key_template_type => $type_name, $key_url_count => $validity['total'], $key_validity_rate => sprintf( '%d%%', 100.0 * ( $validity['valid'] / $validity['total'] ) ), - ); + ]; } if ( empty( $table_validation_by_type ) ) { @@ -245,7 +245,7 @@ public function validate_site( $args, $assoc_args ) { WP_CLI\Utils\format_items( 'table', $table_validation_by_type, - array( $key_template_type, $key_url_count, $key_validity_rate ) + [ $key_template_type, $key_url_count, $key_validity_rate ] ); $url_more_details = add_query_arg( @@ -334,18 +334,18 @@ public static function count_urls_to_validate() { $total_count = 'posts' === get_option( 'show_on_front' ) && self::is_template_supported( 'is_home' ) ? 1 : 0; $amp_enabled_taxonomies = array_filter( - get_taxonomies( array( 'public' => true ) ), - array( 'AMP_CLI', 'does_taxonomy_support_amp' ) + get_taxonomies( [ 'public' => true ] ), + [ 'AMP_CLI', 'does_taxonomy_support_amp' ] ); // Count all public taxonomy terms. foreach ( $amp_enabled_taxonomies as $taxonomy ) { $term_query = new WP_Term_Query( - array( + [ 'taxonomy' => $taxonomy, 'fields' => 'ids', 'number' => self::$limit_type_validate_count, - ) + ] ); // If $term_query->terms is an empty array, passing it to count() will throw an error. @@ -353,7 +353,7 @@ public static function count_urls_to_validate() { } // Count posts by type, like post, page, attachment, etc. - $public_post_types = get_post_types( array( 'public' => true ), 'names' ); + $public_post_types = get_post_types( [ 'public' => true ], 'names' ); foreach ( $public_post_types as $post_type ) { $posts = self::get_posts_that_support_amp( self::get_posts_by_type( $post_type ) ); $total_count += ! empty( $posts ) ? count( $posts ) : 0; @@ -388,7 +388,7 @@ public static function count_urls_to_validate() { */ public static function get_posts_that_support_amp( $ids ) { if ( ! self::is_template_supported( 'is_singular' ) ) { - return array(); + return []; } if ( self::$force_crawl_urls ) { @@ -456,14 +456,14 @@ public static function is_template_supported( $template ) { * @return int[] $post_ids The post IDs in an array. */ public static function get_posts_by_type( $post_type, $offset = null, $number = null ) { - $args = array( + $args = [ 'post_type' => $post_type, 'posts_per_page' => is_int( $number ) ? $number : self::$limit_type_validate_count, 'post_status' => 'publish', 'orderby' => 'ID', 'order' => 'DESC', 'fields' => 'ids', - ); + ]; if ( is_int( $offset ) ) { $args['offset'] = $offset; } @@ -492,9 +492,9 @@ public static function get_taxonomy_links( $taxonomy, $offset = '', $number = 1 get_terms( array_merge( compact( 'taxonomy', 'offset', 'number' ), - array( + [ 'orderby' => 'id', - ) + ] ) ) ); @@ -511,7 +511,7 @@ public static function get_taxonomy_links( $taxonomy, $offset = '', $number = 1 * @return array The author page URLs, or an empty array. */ public static function get_author_page_urls( $offset = '', $number = '' ) { - $author_page_urls = array(); + $author_page_urls = []; if ( ! self::is_template_supported( 'is_author' ) ) { return $author_page_urls; } @@ -567,10 +567,10 @@ public static function crawl_site() { } $amp_enabled_taxonomies = array_filter( - get_taxonomies( array( 'public' => true ) ), - array( 'AMP_CLI', 'does_taxonomy_support_amp' ) + get_taxonomies( [ 'public' => true ] ), + [ 'AMP_CLI', 'does_taxonomy_support_amp' ] ); - $public_post_types = get_post_types( array( 'public' => true ), 'names' ); + $public_post_types = get_post_types( [ 'public' => true ], 'names' ); // Validate one URL of each template/content type, then another URL of each type on the next iteration. for ( $i = 0; $i < self::$limit_type_validate_count; $i++ ) { @@ -632,7 +632,7 @@ public static function validate_and_store_url( $url, $type ) { AMP_Validated_URL_Post_Type::store_validation_errors( $validation_errors, $validity['url'], - wp_array_slice_assoc( $validity, array( 'queried_object' ) ) + wp_array_slice_assoc( $validity, [ 'queried_object' ] ) ); $unaccepted_error_count = count( array_filter( @@ -658,10 +658,10 @@ static function( $error ) { self::$number_crawled++; if ( ! isset( self::$validity_by_type[ $type ] ) ) { - self::$validity_by_type[ $type ] = array( + self::$validity_by_type[ $type ] = [ 'valid' => 0, 'total' => 0, - ); + ]; } self::$validity_by_type[ $type ]['total']++; if ( 0 === $unaccepted_error_count ) { diff --git a/includes/class-amp-comment-walker.php b/includes/class-amp-comment-walker.php index 811b98b7e91..9a221b78433 100644 --- a/includes/class-amp-comment-walker.php +++ b/includes/class-amp-comment-walker.php @@ -32,7 +32,7 @@ class AMP_Comment_Walker extends Walker_Comment { * @since 0.7 * @var array */ - private $comment_thread_age = array(); + private $comment_thread_age = []; /** * Starts the element output. @@ -50,7 +50,7 @@ class AMP_Comment_Walker extends Walker_Comment { * @param array $args Optional. An array of arguments. Default empty array. * @param int $id Optional. ID of the current comment. Default 0 (unused). */ - public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) { + public function start_el( &$output, $comment, $depth = 0, $args = [], $id = 0 ) { $new_out = ''; parent::start_el( $new_out, $comment, $depth, $args, $id ); diff --git a/includes/class-amp-http.php b/includes/class-amp-http.php index 10e5d5a784f..57b3d41bff0 100644 --- a/includes/class-amp-http.php +++ b/includes/class-amp-http.php @@ -28,7 +28,7 @@ class AMP_HTTP { * @see AMP_HTTP::send_header() * @var array[] */ - public static $headers_sent = array(); + public static $headers_sent = []; /** * Whether Server-Timing headers are sent. @@ -53,7 +53,7 @@ class AMP_HTTP { * @see AMP_HTTP::purge_amp_query_vars() * @var string[] */ - public static $purged_amp_query_vars = array(); + public static $purged_amp_query_vars = []; /** * Send an HTTP response header. @@ -73,12 +73,12 @@ class AMP_HTTP { * } * @return bool Whether the header was sent. */ - public static function send_header( $name, $value, $args = array() ) { + public static function send_header( $name, $value, $args = [] ) { $args = array_merge( - array( + [ 'replace' => true, 'status_code' => null, - ), + ], $args ); @@ -113,7 +113,7 @@ public static function send_server_timing( $name, $duration = null, $description } $value = $name; if ( isset( $description ) ) { - $value .= sprintf( ';desc="%s"', str_replace( array( '\\', '"' ), '', substr( $description, 0, 100 ) ) ); + $value .= sprintf( ';desc="%s"', str_replace( [ '\\', '"' ], '', substr( $description, 0, 100 ) ) ); } if ( isset( $duration ) ) { if ( $duration < 0 ) { @@ -121,7 +121,7 @@ public static function send_server_timing( $name, $duration = null, $description } $value .= sprintf( ';dur=%f', $duration * 1000 ); } - return self::send_header( 'Server-Timing', $value, array( 'replace' => false ) ); + return self::send_header( 'Server-Timing', $value, [ 'replace' => false ] ); } /** @@ -138,12 +138,12 @@ public static function send_server_timing( $name, $duration = null, $description * @since 1.0 Moved to AMP_HTTP class. */ public static function purge_amp_query_vars() { - $query_vars = array( + $query_vars = [ '__amp_source_origin', self::ACTION_XHR_CONVERTED_QUERY_VAR, 'amp_latest_update_time', 'amp_last_check_time', - ); + ]; // Scrub input vars. foreach ( $query_vars as $query_var ) { @@ -158,7 +158,7 @@ public static function purge_amp_query_vars() { if ( isset( $scrubbed ) ) { $build_query = static function ( $query ) use ( $query_vars ) { $pattern = '/^(' . implode( '|', $query_vars ) . ')(?==|$)/'; - $pairs = array(); + $pairs = []; foreach ( explode( '&', $query ) as $pair ) { if ( ! preg_match( $pattern, $pair ) ) { $pairs[] = $pair; @@ -207,17 +207,17 @@ public static function filter_allowed_redirect_hosts( $allowed_hosts ) { * @return array AMP cache hosts. */ public static function get_amp_cache_hosts() { - $hosts = array(); + $hosts = []; // Google AMP Cache (legacy). $hosts[] = 'cdn.ampproject.org'; // From the publisher’s own origins. $domains = array_unique( - array( + [ wp_parse_url( site_url(), PHP_URL_HOST ), wp_parse_url( home_url(), PHP_URL_HOST ), - ) + ] ); /* @@ -232,7 +232,7 @@ public static function get_amp_cache_hosts() { // phpcs:ignore PHPCompatibility.Constants.RemovedConstants.intl_idna_variant_2003Deprecated $domain = idn_to_utf8( $domain, IDNA_DEFAULT, defined( 'INTL_IDNA_VARIANT_UTS46' ) ? INTL_IDNA_VARIANT_UTS46 : INTL_IDNA_VARIANT_2003 ); } - $subdomain = str_replace( array( '-', '.' ), array( '--', '-' ), $domain ); + $subdomain = str_replace( [ '-', '.' ], [ '--', '-' ], $domain ); // Google AMP Cache subdomain. $hosts[] = sprintf( '%s.cdn.ampproject.org', $subdomain ); @@ -293,13 +293,13 @@ public static function send_cors_headers() { } if ( $origin ) { - self::send_header( 'Access-Control-Allow-Origin', $origin, array( 'replace' => false ) ); + self::send_header( 'Access-Control-Allow-Origin', $origin, [ 'replace' => false ] ); self::send_header( 'Access-Control-Allow-Credentials', 'true' ); - self::send_header( 'Vary', 'Origin', array( 'replace' => false ) ); + self::send_header( 'Vary', 'Origin', [ 'replace' => false ] ); } if ( $source_origin ) { self::send_header( 'AMP-Access-Control-Allow-Source-Origin', $source_origin ); - self::send_header( 'Access-Control-Expose-Headers', 'AMP-Access-Control-Allow-Source-Origin', array( 'replace' => false ) ); + self::send_header( 'Access-Control-Expose-Headers', 'AMP-Access-Control-Allow-Source-Origin', [ 'replace' => false ] ); } } @@ -320,14 +320,14 @@ public static function handle_xhr_request() { } // Intercept POST requests which redirect. - add_filter( 'wp_redirect', array( __CLASS__, 'intercept_post_request_redirect' ), PHP_INT_MAX ); + add_filter( 'wp_redirect', [ __CLASS__, 'intercept_post_request_redirect' ], PHP_INT_MAX ); // Add special handling for redirecting after comment submission. - add_filter( 'comment_post_redirect', array( __CLASS__, 'filter_comment_post_redirect' ), PHP_INT_MAX, 2 ); + add_filter( 'comment_post_redirect', [ __CLASS__, 'filter_comment_post_redirect' ], PHP_INT_MAX, 2 ); // Add die handler for AMP error display, most likely due to problem with comment. $handle_wp_die = static function () { - return array( __CLASS__, 'handle_wp_die' ); + return [ __CLASS__, 'handle_wp_die' ]; }; add_filter( 'wp_die_json_handler', $handle_wp_die ); add_filter( 'wp_die_handler', $handle_wp_die ); // Needed for WP<5.1. @@ -346,11 +346,11 @@ public static function intercept_post_request_redirect( $location ) { // Make sure relative redirects get made absolute. $parsed_location = array_merge( - array( + [ 'scheme' => 'https', 'host' => wp_parse_url( home_url(), PHP_URL_HOST ), 'path' => isset( $_SERVER['REQUEST_URI'] ) ? strtok( wp_unslash( $_SERVER['REQUEST_URI'] ), '?' ) : '/', - ), + ], wp_parse_url( $location ) ); @@ -371,13 +371,13 @@ public static function intercept_post_request_redirect( $location ) { } self::send_header( 'AMP-Redirect-To', $absolute_location ); - self::send_header( 'Access-Control-Expose-Headers', 'AMP-Redirect-To', array( 'replace' => false ) ); + self::send_header( 'Access-Control-Expose-Headers', 'AMP-Redirect-To', [ 'replace' => false ] ); wp_send_json( - array( + [ 'message' => __( 'Redirecting…', 'amp' ), 'redirecting' => true, // Make sure that the submit-success doesn't get styled as success since redirection _could_ be to error page. - ), + ], 200 ); } @@ -402,7 +402,7 @@ public static function intercept_post_request_redirect( $location ) { * } * @global string $pagenow */ - public static function handle_wp_die( $error, $title = '', $args = array() ) { + public static function handle_wp_die( $error, $title = '', $args = [] ) { global $pagenow; if ( is_int( $title ) ) { $status_code = $title; @@ -434,9 +434,9 @@ public static function handle_wp_die( $error, $title = '', $args = array() ) { // Message will be shown in template defined by AMP_Theme_Support::amend_comment_form(). wp_send_json( - array( + [ 'message' => amp_wp_kses_mustache( $error ), - ), + ], $status_code ); } @@ -483,9 +483,9 @@ public static function filter_comment_post_redirect( $url, $comment ) { // Message will be shown in template defined by AMP_Theme_Support::amend_comment_form(). wp_send_json( - array( + [ 'message' => amp_wp_kses_mustache( $message ), - ), + ], 200 ); diff --git a/includes/class-amp-post-type-support.php b/includes/class-amp-post-type-support.php index b486a7d66f0..5c77b0b2acb 100644 --- a/includes/class-amp-post-type-support.php +++ b/includes/class-amp-post-type-support.php @@ -26,7 +26,7 @@ class AMP_Post_Type_Support { */ public static function get_builtin_supported_post_types() { _deprecated_function( __METHOD__, '1.0' ); - return array_filter( array( 'post' ), 'post_type_exists' ); + return array_filter( [ 'post' ], 'post_type_exists' ); } /** @@ -39,15 +39,15 @@ public static function get_eligible_post_types() { return array_diff( array_values( get_post_types( - array( + [ 'public' => true, - ), + ], 'names' ) ), - array( + [ AMP_Story_Post_Type::POST_TYPE_SLUG, - ) + ] ); } @@ -63,7 +63,7 @@ public static function add_post_type_support() { if ( current_theme_supports( AMP_Theme_Support::SLUG ) && AMP_Options_Manager::get_option( 'all_templates_supported' ) ) { $post_types = self::get_eligible_post_types(); } else { - $post_types = AMP_Options_Manager::get_option( 'supported_post_types', array() ); + $post_types = AMP_Options_Manager::get_option( 'supported_post_types', [] ); } foreach ( $post_types as $post_type ) { add_post_type_support( $post_type, self::SLUG ); @@ -82,7 +82,7 @@ public static function get_support_errors( $post ) { if ( ! ( $post instanceof WP_Post ) ) { $post = get_post( $post ); } - $errors = array(); + $errors = []; if ( ! post_type_supports( $post->post_type, self::SLUG ) ) { $errors[] = 'post-type-support'; @@ -128,10 +128,10 @@ public static function get_support_errors( $post ) { && in_array( (int) $post->ID, - array( + [ (int) get_option( 'page_on_front' ), (int) get_option( 'page_for_posts' ), - ), + ], true ) ) diff --git a/includes/class-amp-service-worker.php b/includes/class-amp-service-worker.php index 02aea1723e6..6709a9a8929 100644 --- a/includes/class-amp-service-worker.php +++ b/includes/class-amp-service-worker.php @@ -27,9 +27,9 @@ public static function init() { } // Shim support for service worker installation from PWA feature plugin. - add_filter( 'query_vars', array( __CLASS__, 'add_query_var' ) ); - add_action( 'parse_request', array( __CLASS__, 'handle_service_worker_iframe_install' ) ); - add_action( 'wp', array( __CLASS__, 'add_install_hooks' ) ); + add_filter( 'query_vars', [ __CLASS__, 'add_query_var' ] ); + add_action( 'parse_request', [ __CLASS__, 'handle_service_worker_iframe_install' ] ); + add_action( 'wp', [ __CLASS__, 'add_install_hooks' ] ); $theme_support = AMP_Theme_Support::get_theme_support_args(); if ( isset( $theme_support['service_worker'] ) && false === $theme_support['service_worker'] ) { @@ -40,11 +40,11 @@ public static function init() { * The default-enabled options reflect which features are not commented-out in the AMP-by-Example service worker. * See <https://github.com/ampproject/amp-by-example/blob/e093edb401b1617859b5365e80b639d81b06f058/boilerplate-generator/templates/files/serviceworkerJs.js>. */ - $enabled_options = array( + $enabled_options = [ 'cdn_script_caching' => true, 'image_caching' => false, 'google_fonts_caching' => false, - ); + ]; if ( isset( $theme_support['service_worker'] ) && is_array( $theme_support['service_worker'] ) ) { $enabled_options = array_merge( $enabled_options, @@ -53,13 +53,13 @@ public static function init() { } if ( $enabled_options['cdn_script_caching'] ) { - add_action( 'wp_front_service_worker', array( __CLASS__, 'add_cdn_script_caching' ) ); + add_action( 'wp_front_service_worker', [ __CLASS__, 'add_cdn_script_caching' ] ); } if ( $enabled_options['image_caching'] ) { - add_action( 'wp_front_service_worker', array( __CLASS__, 'add_image_caching' ) ); + add_action( 'wp_front_service_worker', [ __CLASS__, 'add_image_caching' ] ); } if ( $enabled_options['google_fonts_caching'] ) { - add_action( 'wp_front_service_worker', array( __CLASS__, 'add_google_fonts_caching' ) ); + add_action( 'wp_front_service_worker', [ __CLASS__, 'add_google_fonts_caching' ] ); } } @@ -111,9 +111,9 @@ static function() { // Serve the AMP Runtime from cache and check for an updated version in the background. See <https://github.com/ampproject/amp-by-example/blob/4593af61609898043302a101826ddafe7206bfd9/boilerplate-generator/templates/files/serviceworkerJs.js#L54-L58>. $service_workers->caching_routes()->register( '^https:\/\/cdn\.ampproject\.org\/.*', - array( + [ 'strategy' => WP_Service_Worker_Caching_Routes::STRATEGY_STALE_WHILE_REVALIDATE, - ) + ] ); } @@ -132,19 +132,19 @@ public static function add_image_caching( $service_workers ) { $service_workers->caching_routes()->register( '^' . preg_quote( set_url_scheme( content_url( '/' ), 'https' ), '/' ) . '[^\?]+?\.(?:png|gif|jpg|jpeg|svg|webp)(\?.*)?$', - array( + [ 'strategy' => WP_Service_Worker_Caching_Routes::STRATEGY_CACHE_FIRST, 'cacheName' => 'images', - 'plugins' => array( - 'cacheableResponse' => array( - 'statuses' => array( 0, 200 ), - ), - 'expiration' => array( + 'plugins' => [ + 'cacheableResponse' => [ + 'statuses' => [ 0, 200 ], + ], + 'expiration' => [ 'maxEntries' => 60, 'maxAgeSeconds' => MONTH_IN_SECONDS, - ), - ), - ) + ], + ], + ] ); } @@ -171,28 +171,28 @@ public static function add_google_fonts_caching( $service_workers ) { // Cache the Google Fonts stylesheets with a stale while revalidate strategy. $service_workers->caching_routes()->register( '^https:\/\/fonts\.googleapis\.com', - array( + [ 'strategy' => WP_Service_Worker_Caching_Routes::STRATEGY_STALE_WHILE_REVALIDATE, 'cacheName' => 'google-fonts-stylesheets', - ) + ] ); // Cache the Google Fonts webfont files with a cache first strategy for 1 year. $service_workers->caching_routes()->register( '^https:\/\/fonts\.gstatic\.com', - array( + [ 'strategy' => WP_Service_Worker_Caching_Routes::STRATEGY_CACHE_FIRST, 'cacheName' => 'google-fonts-webfonts', - 'plugins' => array( - 'cacheableResponse' => array( - 'statuses' => array( 0, 200 ), - ), - 'expiration' => array( + 'plugins' => [ + 'cacheableResponse' => [ + 'statuses' => [ 0, 200 ], + ], + 'expiration' => [ 'maxAgeSeconds' => YEAR_IN_SECONDS, 'maxEntries' => 30, - ), - ), - ) + ], + ], + ] ); } @@ -211,12 +211,12 @@ public static function add_google_fonts_caching( $service_workers ) { public static function get_precached_script_cdn_urls() { // List of AMP scripts that we know will be used in WordPress always. - $precached_handles = array( + $precached_handles = [ 'amp-runtime', 'amp-bind', // Used by comments. 'amp-form', // Used by comments. 'amp-install-serviceworker', - ); + ]; $theme_support = AMP_Theme_Support::get_theme_support_args(); if ( ! empty( $theme_support['comments_live_list'] ) ) { @@ -227,7 +227,7 @@ public static function get_precached_script_cdn_urls() { $precached_handles[] = 'amp-analytics'; } - $urls = array(); + $urls = []; foreach ( $precached_handles as $handle ) { if ( wp_script_is( $handle, 'registered' ) ) { $urls[] = wp_scripts()->registered[ $handle ]->src; @@ -242,10 +242,10 @@ public static function get_precached_script_cdn_urls() { */ public static function add_install_hooks() { if ( current_theme_supports( 'amp' ) && is_amp_endpoint() ) { - add_action( 'wp_footer', array( __CLASS__, 'install_service_worker' ) ); + add_action( 'wp_footer', [ __CLASS__, 'install_service_worker' ] ); // Prevent validation error due to the script that installs the service worker on non-AMP pages. - foreach ( array( 'wp_print_scripts', 'wp_print_footer_scripts' ) as $action ) { + foreach ( [ 'wp_print_scripts', 'wp_print_footer_scripts' ] as $action ) { $priority = has_action( $action, 'wp_print_service_workers' ); if ( false !== $priority ) { remove_action( $action, 'wp_print_service_workers', $priority ); @@ -254,7 +254,7 @@ public static function add_install_hooks() { } // Reader mode integration. - add_action( 'amp_post_template_footer', array( __CLASS__, 'install_service_worker' ) ); + add_action( 'amp_post_template_footer', [ __CLASS__, 'install_service_worker' ] ); add_filter( 'amp_post_template_data', static function ( $data ) { @@ -308,7 +308,7 @@ public static function handle_service_worker_iframe_install() { wp_die( esc_html__( 'No service workers registered for the requested scope.', 'amp' ), esc_html__( 'Service Worker Installation', 'amp' ), - array( 'response' => 404 ) + [ 'response' => 404 ] ); } @@ -327,7 +327,7 @@ public static function handle_service_worker_iframe_install() { printf( '<script>navigator.serviceWorker.register( %s, %s );</script>', wp_json_encode( wp_get_service_worker_url( $scope ) ), - wp_json_encode( array( 'scope' => $front_scope ) ) + wp_json_encode( [ 'scope' => $front_scope ] ) ); ?> </body> diff --git a/includes/class-amp-story-post-type.php b/includes/class-amp-story-post-type.php index 1bf7b32e5b4..982933c6759 100644 --- a/includes/class-amp-story-post-type.php +++ b/includes/class-amp-story-post-type.php @@ -133,8 +133,8 @@ public static function register() { register_post_type( self::POST_TYPE_SLUG, - array( - 'labels' => array( + [ + 'labels' => [ 'name' => _x( 'Stories', 'post type general name', 'amp' ), 'singular_name' => _x( 'Story', 'post type singular name', 'amp' ), 'add_new' => _x( 'New', 'story', 'amp' ), @@ -165,59 +165,59 @@ public static function register() { 'item_updated' => __( 'Story updated.', 'amp' ), 'menu_name' => _x( 'Stories', 'admin menu', 'amp' ), 'name_admin_bar' => _x( 'Story', 'add new on admin bar', 'amp' ), - ), + ], 'menu_icon' => 'dashicons-book', - 'taxonomies' => array( + 'taxonomies' => [ 'post_tag', 'category', - ), - 'supports' => array( + ], + 'supports' => [ 'title', // Used for amp-story[title]. 'author', // Used for the amp/amp-story-post-author block. 'editor', 'thumbnail', // Used for poster images. 'amp', 'revisions', // Without this, the REST API will return 404 for an autosave request. - ), - 'rewrite' => array( + ], + 'rewrite' => [ 'slug' => self::REWRITE_SLUG, - ), + ], 'public' => true, 'show_ui' => true, 'show_in_rest' => true, - 'template' => array( - array( + 'template' => [ + [ 'amp/amp-story-page', - array(), - array( - array( + [], + [ + [ 'amp/amp-story-text', - array( + [ 'placeholder' => __( 'Write text…', 'amp' ), - ), - ), - ), - ), - ), - ) + ], + ], + ], + ], + ], + ] ); - add_filter( 'post_row_actions', array( __CLASS__, 'remove_classic_editor_link' ), 11, 2 ); + add_filter( 'post_row_actions', [ __CLASS__, 'remove_classic_editor_link' ], 11, 2 ); - add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'filter_kses_allowed_html' ), 10, 2 ); + add_filter( 'wp_kses_allowed_html', [ __CLASS__, 'filter_kses_allowed_html' ], 10, 2 ); - add_action( 'wp_default_styles', array( __CLASS__, 'register_story_card_styling' ) ); + add_action( 'wp_default_styles', [ __CLASS__, 'register_story_card_styling' ] ); - add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_styles' ) ); + add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'enqueue_block_editor_styles' ] ); - add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ) ); + add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'enqueue_block_editor_scripts' ] ); - add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'export_latest_stories_block_editor_data' ), 100 ); + add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'export_latest_stories_block_editor_data' ], 100 ); - add_action( 'wp_enqueue_scripts', array( __CLASS__, 'add_custom_stories_styles' ) ); + add_action( 'wp_enqueue_scripts', [ __CLASS__, 'add_custom_stories_styles' ] ); // Remove unnecessary settings. - add_filter( 'block_editor_settings', array( __CLASS__, 'filter_block_editor_settings' ), 10, 2 ); + add_filter( 'block_editor_settings', [ __CLASS__, 'filter_block_editor_settings' ], 10, 2 ); // Used for amp-story[publisher-logo-src]: The publisher's logo in square format (1x1 aspect ratio). This will be supplied by the custom logo or else site icon. add_image_size( 'amp-publisher-logo', 100, 100, true ); @@ -235,72 +235,72 @@ public static function register() { add_image_size( self::MAX_IMAGE_SIZE_SLUG, 99999, 1440 ); // In case there is no featured image for the poster-portrait-src, add a fallback image. - add_filter( 'wp_get_attachment_image_src', array( __CLASS__, 'poster_portrait_fallback' ), 10, 3 ); + add_filter( 'wp_get_attachment_image_src', [ __CLASS__, 'poster_portrait_fallback' ], 10, 3 ); // If the image is for a poster-square-src or poster-landscape-src, this ensures that it's not too small. - add_filter( 'wp_get_attachment_image_src', array( __CLASS__, 'ensure_correct_poster_size' ), 10, 3 ); + add_filter( 'wp_get_attachment_image_src', [ __CLASS__, 'ensure_correct_poster_size' ], 10, 3 ); // Limit the styles that are printed in a story. - add_filter( 'print_styles_array', array( __CLASS__, 'filter_frontend_print_styles_array' ) ); - add_filter( 'print_styles_array', array( __CLASS__, 'filter_editor_print_styles_array' ) ); + add_filter( 'print_styles_array', [ __CLASS__, 'filter_frontend_print_styles_array' ] ); + add_filter( 'print_styles_array', [ __CLASS__, 'filter_editor_print_styles_array' ] ); // Select the single-amp_story.php template for AMP Stories. - add_filter( 'template_include', array( __CLASS__, 'filter_template_include' ) ); + add_filter( 'template_include', [ __CLASS__, 'filter_template_include' ] ); // Get an embed template for this post type. - add_filter( 'embed_template', array( __CLASS__, 'get_embed_template' ), 10, 3 ); + add_filter( 'embed_template', [ __CLASS__, 'get_embed_template' ], 10, 3 ); // Enqueue the styling for the /embed endpoint. - add_action( 'embed_footer', array( __CLASS__, 'enqueue_embed_styling' ) ); + add_action( 'embed_footer', [ __CLASS__, 'enqueue_embed_styling' ] ); // In the block editor, remove the title from above the AMP Stories embed. - add_filter( 'embed_html', array( __CLASS__, 'remove_title_from_embed' ), 10, 2 ); + add_filter( 'embed_html', [ __CLASS__, 'remove_title_from_embed' ], 10, 2 ); // Change some attributes for the AMP story embed. - add_filter( 'embed_html', array( __CLASS__, 'change_embed_iframe_attributes' ), 10, 2 ); + add_filter( 'embed_html', [ __CLASS__, 'change_embed_iframe_attributes' ], 10, 2 ); // Override the render_callback for AMP story embeds. - add_filter( 'pre_render_block', array( __CLASS__, 'override_story_embed_callback' ), 10, 2 ); + add_filter( 'pre_render_block', [ __CLASS__, 'override_story_embed_callback' ], 10, 2 ); // The AJAX handler for when an image is cropped and sent via POST. - add_action( 'wp_ajax_custom-header-crop', array( __CLASS__, 'crop_featured_image' ) ); + add_action( 'wp_ajax_custom-header-crop', [ __CLASS__, 'crop_featured_image' ] ); // Register render callback for just-in-time inclusion of dependent Google Font styles. - add_filter( 'render_block', array( __CLASS__, 'render_block_with_google_fonts' ), 10, 2 ); + add_filter( 'render_block', [ __CLASS__, 'render_block_with_google_fonts' ], 10, 2 ); - add_filter( 'use_block_editor_for_post_type', array( __CLASS__, 'use_block_editor_for_story_post_type' ), PHP_INT_MAX, 2 ); - add_filter( 'classic_editor_enabled_editors_for_post_type', array( __CLASS__, 'filter_enabled_editors_for_story_post_type' ), PHP_INT_MAX, 2 ); + add_filter( 'use_block_editor_for_post_type', [ __CLASS__, 'use_block_editor_for_story_post_type' ], PHP_INT_MAX, 2 ); + add_filter( 'classic_editor_enabled_editors_for_post_type', [ __CLASS__, 'filter_enabled_editors_for_story_post_type' ], PHP_INT_MAX, 2 ); - add_filter( 'image_size_names_choose', array( __CLASS__, 'add_new_max_image_size' ) ); + add_filter( 'image_size_names_choose', [ __CLASS__, 'add_new_max_image_size' ] ); self::register_block_latest_stories(); register_block_type( 'amp/amp-story-post-author', - array( - 'render_callback' => array( __CLASS__, 'render_post_author_block' ), - ) + [ + 'render_callback' => [ __CLASS__, 'render_post_author_block' ], + ] ); register_block_type( 'amp/amp-story-post-date', - array( - 'render_callback' => array( __CLASS__, 'render_post_date_block' ), - ) + [ + 'render_callback' => [ __CLASS__, 'render_post_date_block' ], + ] ); register_block_type( 'amp/amp-story-post-title', - array( - 'render_callback' => array( __CLASS__, 'render_post_title_block' ), - ) + [ + 'render_callback' => [ __CLASS__, 'render_post_title_block' ], + ] ); add_filter( 'amp_content_sanitizers', static function( $sanitizers ) { if ( is_singular( self::POST_TYPE_SLUG ) ) { - $sanitizers['AMP_Story_Sanitizer'] = array(); + $sanitizers['AMP_Story_Sanitizer'] = []; // Disable noscript fallbacks since not allowed in AMP Stories. $sanitizers['AMP_Img_Sanitizer']['add_noscript_fallback'] = false; @@ -323,7 +323,7 @@ static function( $sanitizers ) { } ); - add_action( 'wp_head', array( __CLASS__, 'print_feed_link' ) ); + add_action( 'wp_head', [ __CLASS__, 'print_feed_link' ] ); } /** @@ -347,11 +347,11 @@ public static function remove_classic_editor_link( $actions, $post ) { * @return array Allowed tags. */ public static function filter_kses_allowed_html( $allowed_tags ) { - $story_components = array( + $story_components = [ 'amp-story-page', 'amp-story-grid-layer', 'amp-story-cta-layer', - ); + ]; foreach ( $story_components as $story_component ) { $attributes = array_fill_keys( array_keys( AMP_Allowed_Tags_Generated::get_allowed_attributes() ), true ); $rule_specs = AMP_Allowed_Tags_Generated::get_allowed_tag( $story_component ); @@ -458,14 +458,14 @@ public static function enqueue_block_editor_styles() { wp_enqueue_style( self::AMP_STORIES_EDITOR_STYLE_HANDLE, amp_get_asset_url( 'css/amp-stories-editor.css' ), - array( 'wp-edit-blocks' ), + [ 'wp-edit-blocks' ], AMP__VERSION ); wp_enqueue_style( self::AMP_STORIES_EDITOR_STYLE_HANDLE . '-compiled', amp_get_asset_url( 'css/amp-stories-editor-compiled.css' ), - array( 'wp-edit-blocks', 'amp-stories' ), + [ 'wp-edit-blocks', 'amp-stories' ], AMP__VERSION ); @@ -482,7 +482,7 @@ public static function enqueue_general_styles() { wp_enqueue_style( self::AMP_STORIES_STYLE_HANDLE, amp_get_asset_url( 'css/amp-stories.css' ), - array(), + [], AMP__VERSION ); @@ -560,11 +560,11 @@ public static function is_theme_stylesheet( $url ) { */ public static function poster_portrait_fallback( $image, $attachment_id, $size ) { if ( ! $image && self::STORY_CARD_IMAGE_SIZE === $size ) { - return array( + return [ amp_get_asset_url( 'images/story-fallback-poster.jpg' ), self::STORY_LARGE_IMAGE_DIMENSION, self::STORY_SMALL_IMAGE_DIMENSION, - ); + ]; } return $image; @@ -607,7 +607,7 @@ public static function register_story_card_styling( WP_Styles $wp_styles ) { $wp_styles->add( self::STORY_CARD_CSS_SLUG, amp_get_asset_url( '/css/' . self::STORY_CARD_CSS_SLUG . '.css' ), - array(), + [], AMP__VERSION ); } @@ -634,9 +634,9 @@ public static function export_latest_stories_block_editor_data() { sprintf( 'var ampLatestStoriesBlockData = %s;', wp_json_encode( - array( + [ 'storyCardStyleURL' => $url, - ) + ] ) ), 'before' @@ -654,7 +654,7 @@ public static function enqueue_block_editor_scripts() { $script_deps_path = AMP__DIR__ . '/assets/js/' . self::AMP_STORIES_SCRIPT_HANDLE . '.deps.json'; $script_dependencies = file_exists( $script_deps_path ) ? json_decode( file_get_contents( $script_deps_path ), false ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - : array(); + : []; wp_enqueue_script( self::AMP_STORIES_SCRIPT_HANDLE, @@ -729,7 +729,7 @@ public static function add_custom_stories_styles() { wp_enqueue_style( 'amp-stories-frontend', amp_get_asset_url( 'css/amp-stories-frontend.css' ), - array( self::AMP_STORIES_STYLE_HANDLE ), + [ self::AMP_STORIES_STYLE_HANDLE ], AMP__VERSION, false ); @@ -751,187 +751,187 @@ public static function get_fonts() { return $fonts; } - $fonts = array( - array( + $fonts = [ + [ 'name' => 'Arial', - 'fallbacks' => array( 'Helvetica Neue', 'Helvetica', 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'Helvetica Neue', 'Helvetica', 'sans-serif' ], + ], + [ 'name' => 'Arial Black', - 'fallbacks' => array( 'Arial Black', 'Arial Bold', 'Gadget', 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'Arial Black', 'Arial Bold', 'Gadget', 'sans-serif' ], + ], + [ 'name' => 'Arial Narrow', - 'fallbacks' => array( 'Arial', 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'Arial', 'sans-serif' ], + ], + [ 'name' => 'Arimo', 'gfont' => 'Arimo:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Baskerville', - 'fallbacks' => array( 'Baskerville Old Face', 'Hoefler Text', 'Garamond', 'Times New Roman', 'serif' ), - ), - array( + 'fallbacks' => [ 'Baskerville Old Face', 'Hoefler Text', 'Garamond', 'Times New Roman', 'serif' ], + ], + [ 'name' => 'Brush Script MT', - 'fallbacks' => array( 'cursive' ), - ), - array( + 'fallbacks' => [ 'cursive' ], + ], + [ 'name' => 'Copperplate', - 'fallbacks' => array( 'Copperplate Gothic Light', 'fantasy' ), - ), - array( + 'fallbacks' => [ 'Copperplate Gothic Light', 'fantasy' ], + ], + [ 'name' => 'Courier New', - 'fallbacks' => array( 'Courier', 'Lucida Sans Typewriter', 'Lucida Typewriter', 'monospace' ), - ), - array( + 'fallbacks' => [ 'Courier', 'Lucida Sans Typewriter', 'Lucida Typewriter', 'monospace' ], + ], + [ 'name' => 'Century Gothic', - 'fallbacks' => array( 'CenturyGothic', 'AppleGothic', 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'CenturyGothic', 'AppleGothic', 'sans-serif' ], + ], + [ 'name' => 'Garamond', - 'fallbacks' => array( 'Baskerville', 'Baskerville Old Face', 'Hoefler Text', 'Times New Roman', 'serif' ), - ), - array( + 'fallbacks' => [ 'Baskerville', 'Baskerville Old Face', 'Hoefler Text', 'Times New Roman', 'serif' ], + ], + [ 'name' => 'Georgia', - 'fallbacks' => array( 'Times', 'Times New Roman', 'serif' ), - ), - array( + 'fallbacks' => [ 'Times', 'Times New Roman', 'serif' ], + ], + [ 'name' => 'Gill Sans', - 'fallbacks' => array( 'Gill Sans MT', 'Calibri', 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'Gill Sans MT', 'Calibri', 'sans-serif' ], + ], + [ 'name' => 'Lato', 'gfont' => 'Lato:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Lora', 'gfont' => 'Lora:400,700', - 'fallbacks' => array( 'serif' ), - ), - array( + 'fallbacks' => [ 'serif' ], + ], + [ 'name' => 'Lucida Bright', - 'fallbacks' => array( 'Georgia', 'serif' ), - ), - array( + 'fallbacks' => [ 'Georgia', 'serif' ], + ], + [ 'name' => 'Lucida Sans Typewriter', - 'fallbacks' => array( 'Lucida Console', 'monaco', 'Bitstream Vera Sans Mono', 'monospace' ), - ), - array( + 'fallbacks' => [ 'Lucida Console', 'monaco', 'Bitstream Vera Sans Mono', 'monospace' ], + ], + [ 'name' => 'Merriweather', 'gfont' => 'Merriweather:400,700', - 'fallbacks' => array( 'serif' ), - ), - array( + 'fallbacks' => [ 'serif' ], + ], + [ 'name' => 'Montserrat', 'gfont' => 'Montserrat:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Noto Sans', 'gfont' => 'Noto Sans:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Open Sans', 'gfont' => 'Open Sans:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Open Sans Condensed', 'gfont' => 'Open Sans Condensed:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Oswald', 'gfont' => 'Oswald:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Palatino', - 'fallbacks' => array( 'Palatino Linotype', 'Palatino LT STD', 'Book Antiqua', 'Georgia', 'serif' ), - ), - array( + 'fallbacks' => [ 'Palatino Linotype', 'Palatino LT STD', 'Book Antiqua', 'Georgia', 'serif' ], + ], + [ 'name' => 'Papyrus', - 'fallbacks' => array( 'fantasy' ), - ), - array( + 'fallbacks' => [ 'fantasy' ], + ], + [ 'name' => 'Playfair Display', 'gfont' => 'Playfair Display:400,700', - 'fallbacks' => array( 'serif' ), - ), - array( + 'fallbacks' => [ 'serif' ], + ], + [ 'name' => 'PT Sans', 'gfont' => 'PT Sans:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'PT Sans Narrow', 'gfont' => 'PT Sans Narrow:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'PT Serif', 'gfont' => 'PT Serif:400,700', - 'fallbacks' => array( 'serif' ), - ), - array( + 'fallbacks' => [ 'serif' ], + ], + [ 'name' => 'Raleway', 'gfont' => 'Raleway:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Roboto', 'gfont' => 'Roboto:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Roboto Condensed', 'gfont' => 'Roboto Condensed:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Roboto Slab', 'gfont' => 'Roboto Slab:400,700', - 'fallbacks' => array( 'serif' ), - ), - array( + 'fallbacks' => [ 'serif' ], + ], + [ 'name' => 'Slabo 27px', 'gfont' => 'Slabo 27px:400,700', - 'fallbacks' => array( 'serif' ), - ), - array( + 'fallbacks' => [ 'serif' ], + ], + [ 'name' => 'Source Sans Pro', 'gfont' => 'Source Sans Pro:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Tahoma', - 'fallbacks' => array( 'Verdana', 'Segoe', 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'Verdana', 'Segoe', 'sans-serif' ], + ], + [ 'name' => 'Times New Roman', - 'fallbacks' => array( 'Times New Roman', 'Times', 'Baskerville', 'Georgia', 'serif' ), - ), - array( + 'fallbacks' => [ 'Times New Roman', 'Times', 'Baskerville', 'Georgia', 'serif' ], + ], + [ 'name' => 'Trebuchet MS', - 'fallbacks' => array( 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', 'Tahoma', 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', 'Tahoma', 'sans-serif' ], + ], + [ 'name' => 'Ubuntu', 'gfont' => 'Ubuntu:400,700', - 'fallbacks' => array( 'sans-serif' ), - ), - array( + 'fallbacks' => [ 'sans-serif' ], + ], + [ 'name' => 'Verdana', - 'fallbacks' => array( 'Geneva', 'sans-serif' ), - ), - ); + 'fallbacks' => [ 'Geneva', 'sans-serif' ], + ], + ]; $fonts_url = 'https://fonts.googleapis.com/css'; - $subsets = array( 'latin', 'latin-ext' ); + $subsets = [ 'latin', 'latin-ext' ]; /* * Translators: To add an additional character subset specific to your language, @@ -958,10 +958,10 @@ static function ( $font ) use ( $fonts_url, $subsets ) { if ( isset( $font['gfont'] ) ) { $font['handle'] = sprintf( '%s-font', $font['slug'] ); $font['src'] = add_query_arg( - array( + [ 'family' => rawurlencode( $font['gfont'] ), 'subset' => rawurlencode( implode( ',', $subsets ) ), - ), + ], $fonts_url ); } @@ -1047,7 +1047,7 @@ public static function render_block_with_google_fonts( $block_content, $block ) } if ( ! wp_style_is( $font['handle'], 'registered' ) ) { - wp_register_style( $font['handle'], $font['src'], array(), null, 'all' ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion + wp_register_style( $font['handle'], $font['src'], [], null, 'all' ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion } wp_enqueue_style( $font['handle'] ); @@ -1132,11 +1132,11 @@ public static function get_embed_template( $template, $type, $templates ) { public static function the_single_story_card( $args ) { $args = wp_parse_args( $args, - array( + [ 'post' => null, 'size' => 'full', 'disable_link' => false, - ) + ] ); $post = get_post( $args['post'] ); @@ -1157,9 +1157,9 @@ public static function the_single_story_card( $args ) { 24, '', '', - array( + [ 'class' => 'latest-stories__avatar', - ) + ] ); if ( ! $args['disable_link'] ) { $href = sprintf( @@ -1219,7 +1219,7 @@ public static function enqueue_embed_styling() { * @return string|null $rendered_markup The rendered markup, or null to not override the existing render_callback. */ public static function override_story_embed_callback( $pre_render, $block ) { - if ( ! isset( $block['attrs']['url'], $block['blockName'] ) || ! in_array( $block['blockName'], array( 'core-embed/wordpress', 'core/embed' ), true ) ) { + if ( ! isset( $block['attrs']['url'], $block['blockName'] ) || ! in_array( $block['blockName'], [ 'core-embed/wordpress', 'core/embed' ], true ) ) { return $pre_render; } @@ -1251,10 +1251,10 @@ public static function override_story_embed_callback( $pre_render, $block ) { <div class="amp-story-embed"> <?php self::the_single_story_card( - array( + [ 'post' => $post, 'size' => self::STORY_CARD_IMAGE_SIZE, - ) + ] ); ?> </div> @@ -1271,30 +1271,30 @@ public static function override_story_embed_callback( $pre_render, $block ) { public static function register_block_latest_stories() { register_block_type( 'amp/amp-latest-stories', - array( - 'attributes' => array( - 'className' => array( + [ + 'attributes' => [ + 'className' => [ 'type' => 'string', - ), - 'storiesToShow' => array( + ], + 'storiesToShow' => [ 'type' => 'number', 'default' => 5, - ), - 'order' => array( + ], + 'order' => [ 'type' => 'string', 'default' => 'desc', - ), - 'orderBy' => array( + ], + 'orderBy' => [ 'type' => 'string', 'default' => 'date', - ), - 'useCarousel' => array( + ], + 'useCarousel' => [ 'type' => 'boolean', 'default' => ! is_admin(), - ), - ), - 'render_callback' => array( __CLASS__, 'render_block_latest_stories' ), - ) + ], + ], + 'render_callback' => [ __CLASS__, 'render_block_latest_stories' ], + ] ); } @@ -1308,7 +1308,7 @@ public static function register_block_latest_stories() { */ public static function render_block_latest_stories( $attributes ) { $is_amp_carousel = ! empty( $attributes['useCarousel'] ); - $args = array( + $args = [ 'post_type' => self::POST_TYPE_SLUG, 'posts_per_page' => $attributes['storiesToShow'], 'post_status' => 'publish', @@ -1316,7 +1316,7 @@ public static function render_block_latest_stories( $attributes ) { 'orderby' => $attributes['orderBy'], 'suppress_filters' => false, 'meta_key' => '_thumbnail_id', - ); + ]; $story_query = new WP_Query( $args ); $class = 'amp-block-latest-stories'; if ( isset( $attributes['className'] ) ) { @@ -1338,11 +1338,11 @@ public static function render_block_latest_stories( $attributes ) { <<?php echo $is_amp_carousel ? 'div' : 'li'; ?> class="slide latest-stories__slide"> <?php self::the_single_story_card( - array( + [ 'post' => $post, 'size' => $size, 'disable_link' => ! $is_amp_carousel, - ) + ] ); ?> </<?php echo $is_amp_carousel ? 'div' : 'li'; ?>> @@ -1395,10 +1395,10 @@ public static function crop_featured_image() { $crop_details = $_POST['cropDetails']; - $dimensions = array( + $dimensions = [ 'dst_width' => self::STORY_SMALL_IMAGE_DIMENSION, 'dst_height' => self::STORY_LARGE_IMAGE_DIMENSION, - ); + ]; $attachment_id = absint( $_POST['id'] ); @@ -1413,7 +1413,7 @@ public static function crop_featured_image() { ); if ( ! $cropped || is_wp_error( $cropped ) ) { - wp_send_json_error( array( 'message' => __( 'Image could not be processed. Please go back and try again.', 'default' ) ) ); + wp_send_json_error( [ 'message' => __( 'Image could not be processed. Please go back and try again.', 'default' ) ] ); } /** This filter is documented in wp-admin/custom-header.php */ @@ -1450,14 +1450,14 @@ public static function create_attachment_object( $cropped, $parent_attachment_id } $image_type = $size ? $size['mime'] : 'image/jpeg'; - $object = array( + $object = [ 'ID' => $parent_attachment_id, 'post_title' => basename( $cropped ), 'post_mime_type' => $image_type, 'guid' => $url, 'context' => 'amp-story-poster', 'post_parent' => $parent_attachment_id, - ); + ]; return $object; } diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index f30e2544209..197d45e23a7 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -91,21 +91,21 @@ class AMP_Theme_Support { * * @var array */ - protected static $sanitizer_classes = array(); + protected static $sanitizer_classes = []; /** * Embed handlers. * * @var AMP_Base_Embed_Handler[] */ - protected static $embed_handlers = array(); + protected static $embed_handlers = []; /** * Template types. * * @var array */ - protected static $template_types = array( + protected static $template_types = [ 'paged', // Deprecated. 'index', '404', @@ -123,7 +123,7 @@ class AMP_Theme_Support { 'embed', 'singular', 'attachment', - ); + ]; /** * Start time when init was called. @@ -176,14 +176,14 @@ public static function init() { require_once AMP__DIR__ . '/includes/amp-post-template-functions.php'; - add_action( 'widgets_init', array( __CLASS__, 'register_widgets' ) ); + add_action( 'widgets_init', [ __CLASS__, 'register_widgets' ] ); /* * Note that wp action is use instead of template_redirect because some themes/plugins output * the response at this action and then short-circuit with exit. So this is why the the preceding * action to template_redirect--the wp action--is used instead. */ - add_action( 'wp', array( __CLASS__, 'finish_init' ), PHP_INT_MAX ); + add_action( 'wp', [ __CLASS__, 'finish_init' ], PHP_INT_MAX ); } elseif ( AMP_Options_Manager::is_stories_experience_enabled() ) { add_action( 'wp', @@ -279,7 +279,7 @@ public static function read_theme_support() { $args = self::get_theme_support_args(); // Validate theme support usage. - $keys = array( 'template_dir', 'comments_live_list', self::PAIRED_FLAG, 'templates_supported', 'available_callback', 'service_worker', 'nav_menu_toggle', 'nav_menu_dropdown' ); + $keys = [ 'template_dir', 'comments_live_list', self::PAIRED_FLAG, 'templates_supported', 'available_callback', 'service_worker', 'nav_menu_toggle', 'nav_menu_dropdown' ]; if ( count( array_diff( array_keys( $args ), $keys ) ) !== 0 ) { _doing_it_wrong( @@ -328,9 +328,9 @@ public static function read_theme_support() { $is_paired = ( self::TRANSITIONAL_MODE_SLUG === $theme_support_option ); add_theme_support( self::SLUG, - array( + [ self::PAIRED_FLAG => $is_paired, - ) + ] ); self::$support_added_via_option = $is_paired ? self::TRANSITIONAL_MODE_SLUG : self::STANDARD_MODE_SLUG; } elseif ( AMP_Validation_Manager::is_theme_support_forced() ) { @@ -354,12 +354,12 @@ public static function get_theme_support_args() { } $support = get_theme_support( self::SLUG ); if ( true === $support ) { - return array( + return [ self::PAIRED_FLAG => false, - ); + ]; } if ( ! isset( $support[0] ) || ! is_array( $support[0] ) ) { - return array(); + return []; } return $support[0]; } @@ -400,7 +400,7 @@ public static function finish_init() { foreach ( self::$sanitizer_classes as $sanitizer_class => $args ) { if ( method_exists( $sanitizer_class, 'add_buffering_hooks' ) ) { - call_user_func( array( $sanitizer_class, 'add_buffering_hooks' ), $args ); + call_user_func( [ $sanitizer_class, 'add_buffering_hooks' ], $args ); } } } @@ -525,7 +525,7 @@ public static function add_amp_template_filters() { // See get_query_template(). $template_type = preg_replace( '|[^a-z0-9-]+|', '', $template_type ); - add_filter( "{$template_type}_template_hierarchy", array( __CLASS__, 'filter_amp_template_hierarchy' ) ); + add_filter( "{$template_type}_template_hierarchy", [ __CLASS__, 'filter_amp_template_hierarchy' ] ); } } @@ -565,18 +565,18 @@ public static function get_template_availability( $query = null ) { $query->parse_query_vars(); } - $default_response = array( - 'errors' => array(), + $default_response = [ + 'errors' => [], 'supported' => false, 'immutable' => null, 'template' => null, - ); + ]; if ( ! ( $query instanceof WP_Query ) ) { _doing_it_wrong( __METHOD__, esc_html__( 'No WP_Query available.', 'amp' ), '1.0' ); return array_merge( $default_response, - array( 'errors' => array( 'no_query_available' ) ) + [ 'errors' => [ 'no_query_available' ] ] ); } @@ -584,7 +584,7 @@ public static function get_template_availability( $query = null ) { if ( false === $theme_support_args ) { return array_merge( $default_response, - array( 'errors' => array( 'no_theme_support' ) ) + [ 'errors' => [ 'no_theme_support' ] ] ); } @@ -599,20 +599,20 @@ public static function get_template_availability( $query = null ) { if ( ( is_singular() || $query->is_posts_page ) && ! post_supports_amp( $queried_object ) ) { return array_merge( $default_response, - array( - 'errors' => array( 'no-post-support' ), + [ + 'errors' => [ 'no-post-support' ], 'supported' => false, 'immutable' => true, - ) + ] ); } $response = array_merge( $default_response, - array( + [ 'supported' => call_user_func( $theme_support_args['available_callback'] ), 'immutable' => true, - ) + ] ); if ( ! $response['supported'] ) { $response['errors'][] = 'available_callback'; @@ -632,7 +632,7 @@ public static function get_template_availability( $query = null ) { $prev_query = $wp_query; $wp_query = $query; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited - $matching_templates = array(); + $matching_templates = []; $supportable_templates = self::get_supportable_templates(); foreach ( $supportable_templates as $id => $supportable_template ) { if ( empty( $supportable_template['callback'] ) ) { @@ -643,7 +643,7 @@ public static function get_template_availability( $query = null ) { // If the callback is a method on the query, then call the method on the query itself. if ( is_string( $callback ) && 'is_' === substr( $callback, 0, 3 ) && method_exists( $query, $callback ) ) { - $is_match = call_user_func( array( $query, $callback ) ); + $is_match = call_user_func( [ $query, $callback ] ); } elseif ( is_callable( $callback ) ) { $is_match = $callback( $query ); } else { @@ -653,11 +653,11 @@ public static function get_template_availability( $query = null ) { } if ( $is_match ) { - $matching_templates[ $id ] = array( + $matching_templates[ $id ] = [ 'template' => $id, 'supported' => ! empty( $supportable_template['supported'] ), 'immutable' => ! empty( $supportable_template['immutable'] ), - ); + ]; } } @@ -704,7 +704,7 @@ public static function get_template_availability( $query = null ) { * See <https://github.com/WordPress/wordpress-develop/blob/5.1.0/src/wp-includes/template-loader.php#L49-L68>. */ if ( count( $matching_templates ) > 1 ) { - $template_conditional_priority_order = array( + $template_conditional_priority_order = [ 'is_embed', 'is_404', 'is_search', @@ -721,10 +721,10 @@ public static function get_template_availability( $query = null ) { 'is_author', 'is_date', 'is_archive', - ); + ]; // Obtain the template conditionals for each matching template ID (e.g. 'is_post_type_archive[product]' => 'is_post_type_archive'). - $template_conditional_id_mapping = array(); + $template_conditional_id_mapping = []; foreach ( array_keys( $matching_templates ) as $template_id ) { $template_conditional_id_mapping[ strtok( $template_id, '[' ) ] = $template_id; } @@ -747,9 +747,9 @@ public static function get_template_availability( $query = null ) { foreach ( $template_conditional_priority_order as $template_conditional ) { if ( isset( $template_conditional_id_mapping[ $template_conditional ] ) ) { $template_id = $template_conditional_id_mapping[ $template_conditional ]; - $matching_templates = array( + $matching_templates = [ $template_id => $matching_templates[ $template_id ], - ); + ]; break; } } @@ -781,15 +781,15 @@ public static function get_template_availability( $query = null ) { if ( $all_templates_supported ) { return array_merge( $default_response, - array( + [ 'supported' => true, - ) + ] ); } return array_merge( $default_response, - array( 'errors' => array( 'no_matching_template' ) ) + [ 'errors' => [ 'no_matching_template' ] ] ); } $matching_template = array_merge( $default_response, $matching_template ); @@ -825,98 +825,98 @@ public static function get_template_availability( $query = null ) { * @return array Supportable templates. */ public static function get_supportable_templates() { - $templates = array( - 'is_singular' => array( + $templates = [ + 'is_singular' => [ 'label' => __( 'Singular', 'amp' ), 'description' => __( 'Required for the above content types.', 'amp' ), - ), - ); + ], + ]; if ( 'page' === get_option( 'show_on_front' ) ) { - $templates['is_front_page'] = array( + $templates['is_front_page'] = [ 'label' => __( 'Homepage', 'amp' ), 'parent' => 'is_singular', - ); + ]; if ( AMP_Post_Meta_Box::DISABLED_STATUS === get_post_meta( get_option( 'page_on_front' ), AMP_Post_Meta_Box::STATUS_POST_META_KEY, true ) ) { /* translators: %s: the URL to the edit post screen. */ $templates['is_front_page']['description'] = sprintf( __( 'Currently disabled at the <a href="%s">page level</a>.', 'amp' ), esc_url( get_edit_post_link( get_option( 'page_on_front' ) ) ) ); } // In other words, same as is_posts_page, *but* it not is_singular. - $templates['is_home'] = array( + $templates['is_home'] = [ 'label' => __( 'Blog', 'amp' ), - ); + ]; if ( AMP_Post_Meta_Box::DISABLED_STATUS === get_post_meta( get_option( 'page_for_posts' ), AMP_Post_Meta_Box::STATUS_POST_META_KEY, true ) ) { /* translators: %s: the URL to the edit post screen. */ $templates['is_home']['description'] = sprintf( __( 'Currently disabled at the <a href="%s">page level</a>.', 'amp' ), esc_url( get_edit_post_link( get_option( 'page_for_posts' ) ) ) ); } } else { - $templates['is_home'] = array( + $templates['is_home'] = [ 'label' => __( 'Homepage', 'amp' ), - ); + ]; } $templates = array_merge( $templates, - array( - 'is_archive' => array( + [ + 'is_archive' => [ 'label' => __( 'Archives', 'amp' ), - ), - 'is_author' => array( + ], + 'is_author' => [ 'label' => __( 'Author', 'amp' ), 'parent' => 'is_archive', - ), - 'is_date' => array( + ], + 'is_date' => [ 'label' => __( 'Date', 'amp' ), 'parent' => 'is_archive', - ), - 'is_search' => array( + ], + 'is_search' => [ 'label' => __( 'Search', 'amp' ), - ), - 'is_404' => array( + ], + 'is_404' => [ 'label' => __( 'Not Found (404)', 'amp' ), - ), - ) + ], + ] ); if ( taxonomy_exists( 'category' ) ) { - $templates['is_category'] = array( + $templates['is_category'] = [ 'label' => get_taxonomy( 'category' )->labels->name, 'parent' => 'is_archive', - ); + ]; } if ( taxonomy_exists( 'post_tag' ) ) { - $templates['is_tag'] = array( + $templates['is_tag'] = [ 'label' => get_taxonomy( 'post_tag' )->labels->name, 'parent' => 'is_archive', - ); + ]; } - $taxonomy_args = array( + $taxonomy_args = [ '_builtin' => false, 'publicly_queryable' => true, - ); + ]; foreach ( get_taxonomies( $taxonomy_args, 'objects' ) as $taxonomy ) { - $templates[ sprintf( 'is_tax[%s]', $taxonomy->name ) ] = array( + $templates[ sprintf( 'is_tax[%s]', $taxonomy->name ) ] = [ 'label' => $taxonomy->labels->name, 'parent' => 'is_archive', 'callback' => static function ( WP_Query $query ) use ( $taxonomy ) { return $query->is_tax( $taxonomy->name ); }, - ); + ]; } - $post_type_args = array( + $post_type_args = [ 'has_archive' => true, 'publicly_queryable' => true, - ); + ]; foreach ( get_post_types( $post_type_args, 'objects' ) as $post_type ) { - $templates[ sprintf( 'is_post_type_archive[%s]', $post_type->name ) ] = array( + $templates[ sprintf( 'is_post_type_archive[%s]', $post_type->name ) ] = [ 'label' => $post_type->labels->archives, 'parent' => 'is_archive', 'callback' => static function ( WP_Query $query ) use ( $post_type ) { return $query->is_post_type_archive( $post_type->name ); }, - ); + ]; } /** @@ -939,7 +939,7 @@ public static function get_supportable_templates() { $templates = apply_filters( 'amp_supportable_templates', $templates ); $theme_support_args = self::get_theme_support_args(); - $theme_supported_templates = array(); + $theme_supported_templates = []; if ( isset( $theme_support_args['templates_supported'] ) ) { $theme_supported_templates = $theme_support_args['templates_supported']; } @@ -987,7 +987,7 @@ public static function add_hooks() { if ( has_action( 'wp_head', 'print_emoji_detection_script' ) ) { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); - add_action( 'wp_print_styles', array( __CLASS__, 'print_emoji_styles' ) ); + add_action( 'wp_print_styles', [ __CLASS__, 'print_emoji_styles' ] ); add_filter( 'the_title', 'wp_staticize_emoji' ); add_filter( 'the_excerpt', 'wp_staticize_emoji' ); add_filter( 'the_content', 'wp_staticize_emoji' ); @@ -1047,11 +1047,11 @@ static function() { PHP_INT_MAX ); - add_action( 'admin_bar_init', array( __CLASS__, 'init_admin_bar' ) ); + add_action( 'admin_bar_init', [ __CLASS__, 'init_admin_bar' ] ); add_action( 'wp_head', 'amp_add_generator_metadata', 20 ); - add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ), 0 ); // Enqueue before theme's styles. - add_action( 'wp_enqueue_scripts', array( __CLASS__, 'dequeue_customize_preview_scripts' ), 1000 ); - add_filter( 'customize_partial_render', array( __CLASS__, 'filter_customize_partial_render' ) ); + add_action( 'wp_enqueue_scripts', [ __CLASS__, 'enqueue_assets' ], 0 ); // Enqueue before theme's styles. + add_action( 'wp_enqueue_scripts', [ __CLASS__, 'dequeue_customize_preview_scripts' ], 1000 ); + add_filter( 'customize_partial_render', [ __CLASS__, 'filter_customize_partial_render' ] ); add_action( 'wp_footer', 'amp_print_analytics' ); @@ -1060,16 +1060,16 @@ static function() { * instead of template_include. */ $priority = defined( 'PHP_INT_MIN' ) ? PHP_INT_MIN : ~PHP_INT_MAX; // phpcs:ignore PHPCompatibility.Constants.NewConstants.php_int_minFound - add_action( 'template_redirect', array( __CLASS__, 'start_output_buffering' ), $priority ); + add_action( 'template_redirect', [ __CLASS__, 'start_output_buffering' ], $priority ); // Commenting hooks. - add_filter( 'comment_form_defaults', array( __CLASS__, 'filter_comment_form_defaults' ) ); - add_filter( 'comment_reply_link', array( __CLASS__, 'filter_comment_reply_link' ), 10, 4 ); - add_filter( 'cancel_comment_reply_link', array( __CLASS__, 'filter_cancel_comment_reply_link' ), 10, 3 ); - add_action( 'comment_form', array( __CLASS__, 'amend_comment_form' ), 100 ); + add_filter( 'comment_form_defaults', [ __CLASS__, 'filter_comment_form_defaults' ] ); + add_filter( 'comment_reply_link', [ __CLASS__, 'filter_comment_reply_link' ], 10, 4 ); + add_filter( 'cancel_comment_reply_link', [ __CLASS__, 'filter_cancel_comment_reply_link' ], 10, 3 ); + add_action( 'comment_form', [ __CLASS__, 'amend_comment_form' ], 100 ); remove_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); - add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'whitelist_layout_in_wp_kses_allowed_html' ), 10 ); - add_filter( 'get_header_image_tag', array( __CLASS__, 'amend_header_image_with_video_header' ), PHP_INT_MAX ); + add_filter( 'wp_kses_allowed_html', [ __CLASS__, 'whitelist_layout_in_wp_kses_allowed_html' ], 10 ); + add_filter( 'get_header_image_tag', [ __CLASS__, 'amend_header_image_with_video_header' ], PHP_INT_MAX ); add_action( 'wp_print_footer_scripts', static function() { @@ -1123,7 +1123,7 @@ public static function register_widgets() { public static function register_content_embed_handlers() { global $content_width; - $embed_handlers = array(); + $embed_handlers = []; foreach ( amp_get_content_embed_handlers() as $embed_handler_class => $args ) { /** @@ -1133,9 +1133,9 @@ public static function register_content_embed_handlers() { */ $embed_handler = new $embed_handler_class( array_merge( - array( + [ 'content_max_width' => ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH, // Back-compat. - ), + ], $args ) ); @@ -1198,7 +1198,7 @@ public static function amend_comment_form() { public static function filter_amp_template_hierarchy( $templates ) { $args = self::get_theme_support_args(); if ( isset( $args['template_dir'] ) ) { - $amp_templates = array(); + $amp_templates = []; foreach ( $templates as $template ) { $amp_templates[] = $args['template_dir'] . '/' . $template; // Let template_dir have precedence. $amp_templates[] = $template; @@ -1314,14 +1314,14 @@ public static function filter_comment_reply_link( $link, $args, $comment ) { } $state_id = self::get_comment_form_state_id( get_the_ID() ); - $tap_state = array( - $state_id => array( + $tap_state = [ + $state_id => [ 'replyToName' => $comment->comment_author, - 'values' => array( + 'values' => [ 'comment_parent' => (string) $comment->comment_ID, - ), - ), - ); + ], + ], + ]; // @todo Figure out how to support add_below. Instead of moving the form, what about letting the form get a fixed position? $link = sprintf( @@ -1351,14 +1351,14 @@ public static function filter_cancel_comment_reply_link( $formatted_link, $link, } $state_id = self::get_comment_form_state_id( get_the_ID() ); - $tap_state = array( - $state_id => array( + $tap_state = [ + $state_id => [ 'replyToName' => '', - 'values' => array( + 'values' => [ 'comment_parent' => '0', - ), - ), - ); + ], + ], + ]; $respond_id = 'respond'; // Hard-coded in comment_form() and default value in get_comment_reply_link(). return sprintf( @@ -1417,9 +1417,9 @@ static function( $body_classes ) { return array_merge( array_diff( $body_classes, - array( 'no-customize-support' ) + [ 'no-customize-support' ] ), - array( 'customize-support' ) + [ 'customize-support' ] ); } ); @@ -1440,7 +1440,7 @@ static function( $body_classes ) { * @param DOMDocument $dom Document. * @param string[] $script_handles AMP script handles for components identified during output buffering. */ - public static function ensure_required_markup( DOMDocument $dom, $script_handles = array() ) { + public static function ensure_required_markup( DOMDocument $dom, $script_handles = [] ) { /** * Elements. * @@ -1469,7 +1469,7 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles } // Ensure rel=canonical link. - $links = array(); + $links = []; $link_elements = $head->getElementsByTagName( 'link' ); $rel_canonical = null; foreach ( $link_elements as $link ) { @@ -1481,10 +1481,10 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles $rel_canonical = AMP_DOM_Utils::create_node( $dom, 'link', - array( + [ 'rel' => 'canonical', 'href' => self::get_current_canonical_url(), - ) + ] ); $head->appendChild( $rel_canonical ); } @@ -1502,7 +1502,7 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles */ $meta_charset = null; $meta_viewport = null; - $meta_elements = array(); + $meta_elements = []; foreach ( $head->getElementsByTagName( 'meta' ) as $meta ) { if ( $meta->hasAttribute( 'charset' ) ) { // There will not be a meta[http-equiv] because the sanitizer removed it. $meta_charset = $meta; @@ -1517,9 +1517,9 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles $meta_charset = AMP_DOM_Utils::create_node( $dom, 'meta', - array( + [ 'charset' => 'utf-8', - ) + ] ); } else { $head->removeChild( $meta_charset ); // So we can move it. @@ -1530,10 +1530,10 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles $meta_viewport = AMP_DOM_Utils::create_node( $dom, 'meta', - array( + [ 'name' => 'viewport', 'content' => 'width=device-width', - ) + ] ); } else { $head->removeChild( $meta_viewport ); // So we can move it. @@ -1555,16 +1555,16 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles } // @see https://github.com/ampproject/amphtml/blob/2fd30ca984bceac05905bd5b17f9e0010629d719/src/render-delaying-services.js#L39-L43 AMPHTML Render Delaying Services SERVICES definition. - $render_delaying_extensions = array( + $render_delaying_extensions = [ 'amp-experiment', 'amp-dynamic-css-classes', 'amp-story', - ); + ]; // Obtain the existing AMP scripts. - $amp_scripts = array(); - $ordered_scripts = array(); - $head_scripts = array(); + $amp_scripts = []; + $ordered_scripts = []; + $head_scripts = []; $runtime_src = wp_scripts()->registered['amp-runtime']->src; foreach ( $head->getElementsByTagName( 'script' ) as $script ) { // Note that prepare_response() already moved body scripts to head. $head_scripts[] = $script; @@ -1591,10 +1591,10 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles if ( ! wp_script_is( $missing_script_handle, 'registered' ) ) { continue; } - $attrs = array( + $attrs = [ 'src' => wp_scripts()->registered[ $missing_script_handle ]->src, 'async' => '', - ); + ]; if ( 'amp-mustache' === $missing_script_handle ) { $attrs['custom-template'] = $missing_script_handle; } else { @@ -1611,19 +1611,19 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles * until the AMP runtime has loaded. Preloading the AMP runtime tells the browser to download the script with a higher priority." * {@link https://docs.google.com/document/d/169XUxtSSEJb16NfkrCr9y5lqhUR7vxXEAsNxBzg07fM/edit#heading=h.2ha259c3ffos Optimize the AMP Runtime loading} */ - $prioritized_preloads = array(); + $prioritized_preloads = []; if ( ! isset( $links['preload'] ) ) { - $links['preload'] = array(); + $links['preload'] = []; } $prioritized_preloads[] = AMP_DOM_Utils::create_node( $dom, 'link', - array( + [ 'rel' => 'preload', 'as' => 'script', 'href' => $runtime_src, - ) + ] ); $amp_script_handles = array_keys( $amp_scripts ); @@ -1634,16 +1634,16 @@ public static function ensure_required_markup( DOMDocument $dom, $script_handles $prioritized_preloads[] = AMP_DOM_Utils::create_node( $dom, 'link', - array( + [ 'rel' => 'preload', 'as' => 'script', 'href' => $amp_scripts[ $script_handle ]->getAttribute( 'src' ), - ) + ] ); } $links['preload'] = array_merge( $prioritized_preloads, $links['preload'] ); - $link_relations = array( 'preconnect', 'dns-prefetch', 'preload', 'prerender', 'prefetch' ); + $link_relations = [ 'preconnect', 'dns-prefetch', 'preload', 'prerender', 'prefetch' ]; foreach ( $link_relations as $rel ) { if ( ! isset( $links[ $rel ] ) ) { continue; @@ -1734,7 +1734,7 @@ public static function start_output_buffering() { newrelic_disable_autorum(); } - ob_start( array( __CLASS__, 'finish_output_buffering' ) ); + ob_start( [ __CLASS__, 'finish_output_buffering' ] ); self::$is_output_buffering = true; } @@ -1778,12 +1778,12 @@ public static function filter_customize_partial_render( $partial ) { global $content_width; if ( is_string( $partial ) && preg_match( '/<\w/', $partial ) ) { $dom = AMP_DOM_Utils::get_dom_from_content( $partial ); - $args = array( + $args = [ 'content_max_width' => ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH, // Back-compat. 'use_document_element' => false, 'allow_dirty_styles' => true, 'allow_dirty_scripts' => false, - ); + ]; AMP_Content_Sanitizer::sanitize_document( $dom, self::$sanitizer_classes, $args ); // @todo Include script assets in response? $partial = AMP_DOM_Utils::get_content_from_dom( $dom ); } @@ -1800,7 +1800,7 @@ public static function filter_customize_partial_render( $partial ) { * @return string AMP document response. * @global int $content_width */ - public static function prepare_response( $response, $args = array() ) { + public static function prepare_response( $response, $args = [] ) { global $content_width; $prepare_response_start = microtime( true ); @@ -1833,10 +1833,10 @@ public static function prepare_response( $response, $args = array() ) { $status_code = 200; // Not a web server environment. } return wp_json_encode( - array( + [ 'status_code' => $status_code, 'status_text' => get_status_header_desc( $status_code ), - ) + ] ); } @@ -1882,14 +1882,14 @@ public static function prepare_response( $response, $args = array() ) { } $args = array_merge( - array( + [ 'content_max_width' => ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH, // Back-compat. 'use_document_element' => true, 'allow_dirty_styles' => self::is_customize_preview_iframe(), // Dirty styles only needed when editing (e.g. for edit shortcodes). 'allow_dirty_scripts' => is_customize_preview(), // Scripts are always needed to inject changeset UUID. 'user_can_validate' => AMP_Validation_Manager::has_cap(), 'stream_fragment' => $stream_fragment, - ), + ], $args, compact( 'enable_response_caching' ) ); @@ -1903,13 +1903,13 @@ public static function prepare_response( $response, $args = array() ) { */ $response_cache_key = md5( wp_json_encode( - array( + [ $args, $response, self::$sanitizer_classes, self::$embed_handlers, AMP__VERSION, - ) + ] ) ); @@ -1979,7 +1979,7 @@ public static function prepare_response( $response, $args = array() ) { if ( in_array( $header, AMP_HTTP::$headers_sent, true ) ) { continue; // Skip sending headers that were already sent prior to post-processing. } - AMP_HTTP::send_header( $header['name'], $header['value'], wp_array_slice_assoc( $header, array( 'replace', 'status_code' ) ) ); + AMP_HTTP::send_header( $header['name'], $header['value'], wp_array_slice_assoc( $header, [ 'replace', 'status_code' ] ) ); } } @@ -2011,11 +2011,11 @@ public static function prepare_response( $response, $args = array() ) { return wp_cache_set( $response_cache_key, - array( + [ 'headers' => AMP_HTTP::$headers_sent, 'body' => $body, 'validation_results' => $validation_results, - ), + ], AMP_Theme_Support::RESPONSE_CACHE_GROUP, MONTH_IN_SECONDS ); @@ -2093,7 +2093,7 @@ public static function prepare_response( $response, $args = array() ) { // Determine what the validation errors are. $blocking_error_count = 0; - $validation_results = array(); + $validation_results = []; foreach ( AMP_Validation_Manager::$validation_results as $validation_result ) { if ( ! $validation_result['sanitized'] ) { $blocking_error_count++; @@ -2172,9 +2172,9 @@ public static function prepare_response( $response, $args = array() ) { AMP_Validation_Manager::finalize_validation( $dom, - array( + [ 'remove_source_comments' => ! isset( $_GET['amp_preserve_source_comments'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended - ) + ] ); // For service worker streaming, restore the script that was removed above and obtain the script that should be added to the body fragment. @@ -2238,12 +2238,12 @@ public static function prepare_response( $response, $args = array() ) { private static function check_for_cache_misses() { // If the cache miss threshold is exceeded, return true. if ( self::exceeded_cache_miss_threshold() ) { - return array( true, null ); + return [ true, null ]; } // Get the cache miss URLs. $cache_miss_urls = wp_cache_get( self::POST_PROCESSOR_CACHE_EFFECTIVENESS_KEY, self::POST_PROCESSOR_CACHE_EFFECTIVENESS_GROUP ); - $cache_miss_urls = is_array( $cache_miss_urls ) ? $cache_miss_urls : array(); + $cache_miss_urls = is_array( $cache_miss_urls ) ? $cache_miss_urls : []; $exceeded_threshold = ( ! empty( $cache_miss_urls ) @@ -2252,13 +2252,13 @@ private static function check_for_cache_misses() { ); if ( ! $exceeded_threshold ) { - return array( $exceeded_threshold, $cache_miss_urls ); + return [ $exceeded_threshold, $cache_miss_urls ]; } // When the threshold is exceeded, store the URL for cache miss and turn off response caching. update_option( self::CACHE_MISS_URL_OPTION, amp_get_current_url() ); AMP_Options_Manager::update_option( 'enable_response_caching', false ); - return array( true, null ); + return [ true, null ]; } /** @@ -2311,7 +2311,7 @@ public static function enqueue_assets() { wp_enqueue_script( 'amp-runtime' ); // Enqueue default styles expected by sanitizer. - wp_enqueue_style( 'amp-default', amp_get_asset_url( 'css/amp-default.css' ), array(), AMP__VERSION ); + wp_enqueue_style( 'amp-default', amp_get_asset_url( 'css/amp-default.css' ), [], AMP__VERSION ); } /** @@ -2368,15 +2368,15 @@ public static function amend_header_image_with_video_header( $image_markup ) { $video_settings = get_header_video_settings(); $parsed_url = wp_parse_url( $video_settings['videoUrl'] ); - $query = isset( $parsed_url['query'] ) ? wp_parse_args( $parsed_url['query'] ) : array(); - $video_attributes = array( + $query = isset( $parsed_url['query'] ) ? wp_parse_args( $parsed_url['query'] ) : []; + $video_attributes = [ 'media' => '(min-width: ' . $video_settings['minWidth'] . 'px)', 'width' => $video_settings['width'], 'height' => $video_settings['height'], 'layout' => 'responsive', 'autoplay' => '', 'id' => 'wp-custom-header-video', - ); + ]; $youtube_id = null; if ( isset( $parsed_url['host'] ) && preg_match( '/(^|\.)(youtube\.com|youtu\.be)$/', $parsed_url['host'] ) ) { @@ -2393,12 +2393,12 @@ public static function amend_header_image_with_video_header( $image_markup ) { 'amp-youtube', array_merge( $video_attributes, - array( + [ 'data-videoid' => $youtube_id, 'data-param-rel' => '0', // Don't show related videos. 'data-param-showinfo' => '0', // Don't show video title at the top. 'data-param-controls' => '0', // Don't show video controls. - ) + ] ) ); } else { @@ -2406,9 +2406,9 @@ public static function amend_header_image_with_video_header( $image_markup ) { 'amp-video', array_merge( $video_attributes, - array( + [ 'src' => $video_settings['videoUrl'], - ) + ] ) ); } diff --git a/includes/embeds/class-amp-base-embed-handler.php b/includes/embeds/class-amp-base-embed-handler.php index d2dac7e17fb..d1c20389621 100644 --- a/includes/embeds/class-amp-base-embed-handler.php +++ b/includes/embeds/class-amp-base-embed-handler.php @@ -30,7 +30,7 @@ abstract class AMP_Base_Embed_Handler { * * @var array */ - protected $args = array(); + protected $args = []; /** * Whether or not conversion was completed. @@ -54,13 +54,13 @@ abstract public function unregister_embed(); * * @param array $args Height and width for embed. */ - public function __construct( $args = array() ) { + public function __construct( $args = [] ) { $this->args = wp_parse_args( $args, - array( + [ 'width' => $this->DEFAULT_WIDTH, 'height' => $this->DEFAULT_HEIGHT, - ) + ] ); } @@ -75,6 +75,6 @@ public function __construct( $args = array() ) { * @return array Scripts. */ public function get_scripts() { - return array(); + return []; } } diff --git a/includes/embeds/class-amp-core-block-handler.php b/includes/embeds/class-amp-core-block-handler.php index dfdb25d9a99..493d862ecbe 100644 --- a/includes/embeds/class-amp-core-block-handler.php +++ b/includes/embeds/class-amp-core-block-handler.php @@ -17,24 +17,24 @@ class AMP_Core_Block_Handler extends AMP_Base_Embed_Handler { * * @var array */ - protected $block_ampify_methods = array( + protected $block_ampify_methods = [ 'core/categories' => 'ampify_categories_block', 'core/archives' => 'ampify_archives_block', 'core/video' => 'ampify_video_block', - ); + ]; /** * Register embed. */ public function register_embed() { - add_filter( 'render_block', array( $this, 'filter_rendered_block' ), 0, 2 ); + add_filter( 'render_block', [ $this, 'filter_rendered_block' ], 0, 2 ); } /** * Unregister embed. */ public function unregister_embed() { - remove_filter( 'render_block', array( $this, 'filter_rendered_block' ), 0 ); + remove_filter( 'render_block', [ $this, 'filter_rendered_block' ], 0 ); } /** diff --git a/includes/embeds/class-amp-crowdsignal-embed-handler.php b/includes/embeds/class-amp-crowdsignal-embed-handler.php index 2c07b69c5ad..f243bed4625 100644 --- a/includes/embeds/class-amp-crowdsignal-embed-handler.php +++ b/includes/embeds/class-amp-crowdsignal-embed-handler.php @@ -17,14 +17,14 @@ class AMP_Crowdsignal_Embed_Handler extends AMP_Base_Embed_Handler { * Register embed. */ public function register_embed() { - add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 3 ); + add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 3 ); } /** * Unregister embed. */ public function unregister_embed() { - remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); + remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 ); } /** diff --git a/includes/embeds/class-amp-dailymotion-embed.php b/includes/embeds/class-amp-dailymotion-embed.php index 7cbbc9f6d7a..0eac0970567 100644 --- a/includes/embeds/class-amp-dailymotion-embed.php +++ b/includes/embeds/class-amp-dailymotion-embed.php @@ -34,7 +34,7 @@ class AMP_DailyMotion_Embed_Handler extends AMP_Base_Embed_Handler { * * @param array $args Height, width and maximum width for embed. */ - public function __construct( $args = array() ) { + public function __construct( $args = [] ) { parent::__construct( $args ); if ( isset( $this->args['content_max_width'] ) ) { @@ -48,8 +48,8 @@ public function __construct( $args = array() ) { * Register embed. */ public function register_embed() { - wp_embed_register_handler( 'amp-dailymotion', self::URL_PATTERN, array( $this, 'oembed' ), -1 ); - add_shortcode( 'dailymotion', array( $this, 'shortcode' ) ); + wp_embed_register_handler( 'amp-dailymotion', self::URL_PATTERN, [ $this, 'oembed' ], -1 ); + add_shortcode( 'dailymotion', [ $this, 'shortcode' ] ); } /** @@ -82,9 +82,9 @@ public function shortcode( $attr ) { } return $this->render( - array( + [ 'video_id' => $video_id, - ) + ] ); } @@ -102,9 +102,9 @@ public function shortcode( $attr ) { public function oembed( $matches, $attr, $url, $rawattr ) { $video_id = $this->get_video_id_from_url( $url ); return $this->render( - array( + [ 'video_id' => $video_id, - ) + ] ); } @@ -117,18 +117,18 @@ public function oembed( $matches, $attr, $url, $rawattr ) { public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'video_id' => false, - ) + ] ); if ( empty( $args['video_id'] ) ) { return AMP_HTML_Utils::build_tag( 'a', - array( + [ 'href' => esc_url( $args['url'] ), 'class' => 'amp-wp-embed-fallback', - ), + ], esc_html( $args['url'] ) ); } @@ -137,12 +137,12 @@ public function render( $args ) { return AMP_HTML_Utils::build_tag( 'amp-dailymotion', - array( + [ 'data-videoid' => $args['video_id'], 'layout' => 'responsive', 'width' => $this->args['width'], 'height' => $this->args['height'], - ) + ] ); } diff --git a/includes/embeds/class-amp-facebook-embed.php b/includes/embeds/class-amp-facebook-embed.php index 6629761c67b..8efd7b2af63 100644 --- a/includes/embeds/class-amp-facebook-embed.php +++ b/includes/embeds/class-amp-facebook-embed.php @@ -43,7 +43,7 @@ class AMP_Facebook_Embed_Handler extends AMP_Base_Embed_Handler { * Registers embed. */ public function register_embed() { - wp_embed_register_handler( $this->amp_tag, self::URL_PATTERN, array( $this, 'oembed' ), -1 ); + wp_embed_register_handler( $this->amp_tag, self::URL_PATTERN, [ $this, 'oembed' ], -1 ); } /** @@ -63,7 +63,7 @@ public function unregister_embed() { * @return string HTML markup for rendered embed. */ public function oembed( $matches, $attr, $url, $rawattr ) { - return $this->render( array( 'url' => $url ) ); + return $this->render( [ 'url' => $url ] ); } /** @@ -75,9 +75,9 @@ public function oembed( $matches, $attr, $url, $rawattr ) { public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'url' => false, - ) + ] ); if ( empty( $args['url'] ) ) { @@ -88,12 +88,12 @@ public function render( $args ) { return AMP_HTML_Utils::build_tag( $this->amp_tag, - array( + [ 'data-href' => $args['url'], 'layout' => 'responsive', 'width' => $this->args['width'], 'height' => $this->args['height'], - ) + ] ); } @@ -136,7 +136,7 @@ public function sanitize_raw_embeds( $dom ) { $fb_root = $dom->getElementById( 'fb-root' ); if ( $fb_root ) { $xpath = new DOMXPath( $dom ); - $scripts = array(); + $scripts = []; foreach ( $xpath->query( '//script[ starts-with( @src, "https://connect.facebook.net" ) and contains( @src, "sdk.js" ) ]' ) as $script ) { $scripts[] = $script; } @@ -195,11 +195,11 @@ private function get_embed_type( $node ) { */ private function create_amp_facebook_and_replace_node( $dom, $node, $embed_type ) { - $attributes = array( + $attributes = [ 'layout' => 'responsive', 'width' => $node->hasAttribute( 'data-width' ) ? $node->getAttribute( 'data-width' ) : $this->DEFAULT_WIDTH, 'height' => $node->hasAttribute( 'data-height' ) ? $node->getAttribute( 'data-height' ) : $this->DEFAULT_HEIGHT, - ); + ]; $node->removeAttribute( 'data-width' ); $node->removeAttribute( 'data-height' ); diff --git a/includes/embeds/class-amp-gallery-embed.php b/includes/embeds/class-amp-gallery-embed.php index b5c26d167d0..835b1e8fc74 100644 --- a/includes/embeds/class-amp-gallery-embed.php +++ b/includes/embeds/class-amp-gallery-embed.php @@ -16,8 +16,8 @@ class AMP_Gallery_Embed_Handler extends AMP_Base_Embed_Handler { * Register embed. */ public function register_embed() { - add_filter( 'post_gallery', array( $this, 'maybe_override_gallery' ), 10, 2 ); - add_action( 'wp_print_styles', array( $this, 'print_styles' ) ); + add_filter( 'post_gallery', [ $this, 'maybe_override_gallery' ], 10, 2 ); + add_action( 'wp_print_styles', [ $this, 'print_styles' ] ); } /** @@ -43,15 +43,15 @@ public function shortcode( $attr ) { } $atts = shortcode_atts( - array( + [ 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'include' => '', 'exclude' => '', - 'size' => array( $this->args['width'], $this->args['height'] ), + 'size' => [ $this->args['width'], $this->args['height'] ], 'link' => 'none', - ), + ], $attr, 'gallery' ); @@ -64,7 +64,7 @@ public function shortcode( $attr ) { if ( ! empty( $atts['include'] ) ) { $attachments = get_posts( - array( + [ 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', @@ -72,11 +72,11 @@ public function shortcode( $attr ) { 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', - ) + ] ); } elseif ( ! empty( $atts['exclude'] ) ) { $attachments = get_children( - array( + [ 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', @@ -85,11 +85,11 @@ public function shortcode( $attr ) { 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', - ) + ] ); } else { $attachments = get_children( - array( + [ 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', @@ -97,7 +97,7 @@ public function shortcode( $attr ) { 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', - ) + ] ); } @@ -105,7 +105,7 @@ public function shortcode( $attr ) { return ''; } - $urls = array(); + $urls = []; foreach ( $attachments as $attachment_id ) { list( $url, $width, $height ) = wp_get_attachment_image_src( $attachment_id, $atts['size'], true ); @@ -122,26 +122,26 @@ public function shortcode( $attr ) { } } - $urls[] = array( + $urls[] = [ 'href' => $href, 'url' => $url, 'width' => $width, 'height' => $height, - ); + ]; } - $args = array( + $args = [ 'images' => $urls, - ); + ]; if ( ! empty( $atts['lightbox'] ) ) { $args['lightbox'] = true; $lightbox_tag = AMP_HTML_Utils::build_tag( 'amp-image-lightbox', - array( + [ 'id' => AMP_Base_Sanitizer::AMP_IMAGE_LIGHTBOX_ID, 'layout' => 'nodisplay', 'data-close-button-aria-label' => __( 'Close', 'amp' ), - ) + ] ); /* We need to add lightbox tag, too. @todo Could there be a better alternative for this? */ return $this->render( $args ) . $lightbox_tag; @@ -164,10 +164,10 @@ public function maybe_override_gallery( $html, $attributes ) { $is_lightbox = isset( $attributes['amp-lightbox'] ) && true === filter_var( $attributes['amp-lightbox'], FILTER_VALIDATE_BOOLEAN ); if ( isset( $attributes['amp-carousel'] ) && false === filter_var( $attributes['amp-carousel'], FILTER_VALIDATE_BOOLEAN ) ) { if ( true === $is_lightbox ) { - remove_filter( 'post_gallery', array( $this, 'maybe_override_gallery' ), 10 ); + remove_filter( 'post_gallery', [ $this, 'maybe_override_gallery' ], 10 ); $attributes['link'] = 'none'; $html = '<ul class="amp-lightbox">' . gallery_shortcode( $attributes ) . '</ul>'; - add_filter( 'post_gallery', array( $this, 'maybe_override_gallery' ), 10, 2 ); + add_filter( 'post_gallery', [ $this, 'maybe_override_gallery' ], 10, 2 ); } return $html; @@ -198,9 +198,9 @@ public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'images' => false, - ) + ] ); if ( empty( $args['images'] ) ) { @@ -210,14 +210,14 @@ public function render( $args ) { $max_width = 0; $max_height = 0; - $images = array(); + $images = []; foreach ( $args['images'] as $props ) { - $image_atts = array( + $image_atts = [ 'src' => $props['url'], 'width' => $props['width'], 'height' => $props['height'], 'layout' => 'responsive', - ); + ]; $max_width = max( $max_width, $props['width'] ); $max_height = max( $max_height, $props['height'] ); if ( ! empty( $args['lightbox'] ) ) { @@ -234,9 +234,9 @@ public function render( $args ) { if ( ! empty( $props['href'] ) ) { $image = AMP_HTML_Utils::build_tag( 'a', - array( + [ 'href' => $props['href'], - ), + ], $image ); } @@ -246,12 +246,12 @@ public function render( $args ) { return AMP_HTML_Utils::build_tag( 'amp-carousel', - array( + [ 'width' => $max_width, 'height' => $max_height, 'type' => 'slides', 'layout' => 'responsive', - ), + ], implode( PHP_EOL, $images ) ); } diff --git a/includes/embeds/class-amp-gfycat-embed-handler.php b/includes/embeds/class-amp-gfycat-embed-handler.php index 7948d7a1d0f..ba016eec378 100644 --- a/includes/embeds/class-amp-gfycat-embed-handler.php +++ b/includes/embeds/class-amp-gfycat-embed-handler.php @@ -21,14 +21,14 @@ class AMP_Gfycat_Embed_Handler extends AMP_Base_Embed_Handler { * Register embed. */ public function register_embed() { - add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 3 ); + add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 3 ); } /** * Unregister embed. */ public function unregister_embed() { - remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); + remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 ); } /** @@ -53,7 +53,7 @@ public function filter_embed_oembed_html( $return, $url, $attr ) { return $return; } - $attributes = wp_array_slice_assoc( $attr, array( 'width', 'height' ) ); + $attributes = wp_array_slice_assoc( $attr, [ 'width', 'height' ] ); if ( empty( $attr['width'] ) ) { $attributes['layout'] = 'fixed-height'; diff --git a/includes/embeds/class-amp-hulu-embed-handler.php b/includes/embeds/class-amp-hulu-embed-handler.php index c15212b03b2..c5a00d1204f 100644 --- a/includes/embeds/class-amp-hulu-embed-handler.php +++ b/includes/embeds/class-amp-hulu-embed-handler.php @@ -28,14 +28,14 @@ class AMP_Hulu_Embed_Handler extends AMP_Base_Embed_Handler { * Register embed. */ public function register_embed() { - add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 3 ); + add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 3 ); } /** * Unregister embed. */ public function unregister_embed() { - remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); + remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 ); } /** @@ -60,7 +60,7 @@ public function filter_embed_oembed_html( $return, $url, $attr ) { return $return; } - $attributes = wp_array_slice_assoc( $attr, array( 'width', 'height' ) ); + $attributes = wp_array_slice_assoc( $attr, [ 'width', 'height' ] ); if ( empty( $attr['width'] ) ) { $attributes['layout'] = 'fixed-height'; diff --git a/includes/embeds/class-amp-imgur-embed-handler.php b/includes/embeds/class-amp-imgur-embed-handler.php index b1669c560a9..8fcbb871524 100644 --- a/includes/embeds/class-amp-imgur-embed-handler.php +++ b/includes/embeds/class-amp-imgur-embed-handler.php @@ -24,9 +24,9 @@ public function register_embed() { if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) { // Before 4.9 the embedding Imgur is not working properly, register embed for that case. - wp_embed_register_handler( 'amp-imgur', self::URL_PATTERN, array( $this, 'oembed' ), -1 ); + wp_embed_register_handler( 'amp-imgur', self::URL_PATTERN, [ $this, 'oembed' ], -1 ); } else { - add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 3 ); + add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 3 ); } } @@ -37,7 +37,7 @@ public function unregister_embed() { if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) { wp_embed_unregister_handler( 'amp-imgur', -1 ); } else { - remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); + remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 ); } } @@ -51,7 +51,7 @@ public function unregister_embed() { * @return string Embed. */ public function oembed( $matches, $attr, $url, $rawattr ) { - return $this->render( array( 'url' => $url ) ); + return $this->render( [ 'url' => $url ] ); } /** @@ -63,9 +63,9 @@ public function oembed( $matches, $attr, $url, $rawattr ) { public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'url' => false, - ) + ] ); if ( empty( $args['url'] ) ) { @@ -80,11 +80,11 @@ public function render( $args ) { } return AMP_HTML_Utils::build_tag( 'amp-imgur', - array( + [ 'width' => $this->args['width'], 'height' => $this->args['height'], 'data-imgur-id' => $id, - ) + ] ); } @@ -110,7 +110,7 @@ public function filter_embed_oembed_html( $return, $url, $attr ) { return $return; } - $attributes = wp_array_slice_assoc( $attr, array( 'width', 'height' ) ); + $attributes = wp_array_slice_assoc( $attr, [ 'width', 'height' ] ); if ( empty( $attr['width'] ) ) { $attributes['layout'] = 'fixed-height'; diff --git a/includes/embeds/class-amp-instagram-embed.php b/includes/embeds/class-amp-instagram-embed.php index 8183c794ec5..c54cd2e52b1 100644 --- a/includes/embeds/class-amp-instagram-embed.php +++ b/includes/embeds/class-amp-instagram-embed.php @@ -46,8 +46,8 @@ class AMP_Instagram_Embed_Handler extends AMP_Base_Embed_Handler { * Registers embed. */ public function register_embed() { - wp_embed_register_handler( $this->amp_tag, self::URL_PATTERN, array( $this, 'oembed' ), -1 ); - add_shortcode( 'instagram', array( $this, 'shortcode' ) ); + wp_embed_register_handler( $this->amp_tag, self::URL_PATTERN, [ $this, 'oembed' ], -1 ); + add_shortcode( 'instagram', [ $this, 'shortcode' ] ); } /** @@ -78,10 +78,10 @@ public function shortcode( $attr ) { $instagram_id = $this->get_instagram_id_from_url( $url ); return $this->render( - array( + [ 'url' => $url, 'instagram_id' => $instagram_id, - ) + ] ); } @@ -96,10 +96,10 @@ public function shortcode( $attr ) { */ public function oembed( $matches, $attr, $url, $rawattr ) { return $this->render( - array( + [ 'url' => $url, 'instagram_id' => end( $matches ), - ) + ] ); } @@ -112,19 +112,19 @@ public function oembed( $matches, $attr, $url, $rawattr ) { public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'url' => false, 'instagram_id' => false, - ) + ] ); if ( empty( $args['instagram_id'] ) ) { return AMP_HTML_Utils::build_tag( 'a', - array( + [ 'href' => esc_url( $args['url'] ), 'class' => 'amp-wp-embed-fallback', - ), + ], esc_html( $args['url'] ) ); } @@ -133,13 +133,13 @@ public function render( $args ) { return AMP_HTML_Utils::build_tag( $this->amp_tag, - array( + [ 'data-shortcode' => $args['instagram_id'], 'data-captioned' => '', 'layout' => 'responsive', 'width' => $this->args['width'], 'height' => $this->args['height'], - ) + ] ); } @@ -198,12 +198,12 @@ public function sanitize_raw_embeds( $dom ) { private function create_amp_instagram_and_replace_node( $dom, $node ) { $instagram_id = $this->get_instagram_id_from_url( $node->getAttribute( 'data-instgrm-permalink' ) ); - $node_args = array( + $node_args = [ 'data-shortcode' => $instagram_id, 'layout' => 'responsive', 'width' => $this->DEFAULT_WIDTH, 'height' => $this->DEFAULT_HEIGHT, - ); + ]; if ( true === $node->hasAttribute( 'data-instgrm-captioned' ) ) { $node_args['data-captioned'] = ''; diff --git a/includes/embeds/class-amp-issuu-embed-handler.php b/includes/embeds/class-amp-issuu-embed-handler.php index 6ffb38197ab..247a5e3ef3b 100644 --- a/includes/embeds/class-amp-issuu-embed-handler.php +++ b/includes/embeds/class-amp-issuu-embed-handler.php @@ -21,14 +21,14 @@ class AMP_Issuu_Embed_Handler extends AMP_Base_Embed_Handler { * Register embed. */ public function register_embed() { - add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 3 ); + add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 3 ); } /** * Unregister embed. */ public function unregister_embed() { - remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); + remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 ); } /** @@ -51,12 +51,12 @@ public function filter_embed_oembed_html( $return, $url, $attr ) { $return = AMP_HTML_Utils::build_tag( 'amp-iframe', - array( + [ 'width' => $attr['width'], 'height' => $attr['height'], 'src' => $url, 'sandbox' => 'allow-scripts allow-same-origin', - ) + ] ); } return $return; diff --git a/includes/embeds/class-amp-meetup-embed-handler.php b/includes/embeds/class-amp-meetup-embed-handler.php index 2957850fd08..6f39aa01dbe 100644 --- a/includes/embeds/class-amp-meetup-embed-handler.php +++ b/includes/embeds/class-amp-meetup-embed-handler.php @@ -15,14 +15,14 @@ class AMP_Meetup_Embed_Handler extends AMP_Base_Embed_Handler { * Register embed. */ public function register_embed() { - add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 2 ); + add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 2 ); } /** * Unregister embed. */ public function unregister_embed() { - remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); + remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 ); } /** diff --git a/includes/embeds/class-amp-pinterest-embed.php b/includes/embeds/class-amp-pinterest-embed.php index 183165d5c22..ab99396d3eb 100644 --- a/includes/embeds/class-amp-pinterest-embed.php +++ b/includes/embeds/class-amp-pinterest-embed.php @@ -33,7 +33,7 @@ public function register_embed() { wp_embed_register_handler( 'amp-pinterest', self::URL_PATTERN, - array( $this, 'oembed' ), + [ $this, 'oembed' ], -1 ); } @@ -55,7 +55,7 @@ public function unregister_embed() { * @return string HTML markup for rendered embed. */ public function oembed( $matches, $attr, $url, $rawattr ) { - return $this->render( array( 'url' => $url ) ); + return $this->render( [ 'url' => $url ] ); } /** @@ -67,9 +67,9 @@ public function oembed( $matches, $attr, $url, $rawattr ) { public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'url' => false, - ) + ] ); if ( empty( $args['url'] ) ) { @@ -80,12 +80,12 @@ public function render( $args ) { return AMP_HTML_Utils::build_tag( 'amp-pinterest', - array( + [ 'width' => $this->args['width'], 'height' => $this->args['height'], 'data-do' => 'embedPin', 'data-url' => $args['url'], - ) + ] ); } } diff --git a/includes/embeds/class-amp-playlist-embed-handler.php b/includes/embeds/class-amp-playlist-embed-handler.php index 7e30b9db5d2..20e2ddc4b41 100644 --- a/includes/embeds/class-amp-playlist-embed-handler.php +++ b/includes/embeds/class-amp-playlist-embed-handler.php @@ -85,7 +85,7 @@ public function register_embed() { if ( shortcode_exists( self::SHORTCODE ) ) { $this->removed_shortcode_callback = $shortcode_tags[ self::SHORTCODE ]; } - add_shortcode( self::SHORTCODE, array( $this, 'shortcode' ) ); + add_shortcode( self::SHORTCODE, [ $this, 'shortcode' ] ); remove_action( 'wp_playlist_scripts', 'wp_playlist_scripts' ); } @@ -111,7 +111,7 @@ public function enqueue_styles() { wp_enqueue_style( 'amp-playlist-shortcode', amp_get_asset_url( 'css/amp-playlist-shortcode.css' ), - array( 'wp-mediaelement' ), + [ 'wp-mediaelement' ], AMP__VERSION ); } @@ -152,9 +152,9 @@ public function audio_playlist( $data ) { self::$playlist_id++; $container_id = 'wpPlaylist' . self::$playlist_id . 'Carousel'; $state_id = 'wpPlaylist' . self::$playlist_id; - $amp_state = array( + $amp_state = [ 'selectedIndex' => 0, - ); + ]; $this->enqueue_styles(); ob_start(); @@ -206,14 +206,14 @@ public function video_playlist( $data ) { } self::$playlist_id++; $state_id = 'wpPlaylist' . self::$playlist_id; - $amp_state = array( + $amp_state = [ 'selectedIndex' => 0, - ); + ]; foreach ( $data['tracks'] as $index => $track ) { - $amp_state[ $index ] = array( + $amp_state[ $index ] = [ 'videoUrl' => $track['src'], 'thumb' => isset( $track['thumb']['src'] ) ? $track['thumb']['src'] : '', - ); + ]; } $dimensions = isset( $data['tracks'][0]['dimensions']['resized'] ) ? $data['tracks'][0]['dimensions']['resized'] : null; @@ -278,7 +278,7 @@ public function print_tracks( $state_id, $tracks ) { <div class="wp-playlist-tracks"> <?php foreach ( $tracks as $index => $track ) : ?> <?php - $on = 'tap:AMP.setState(' . wp_json_encode( array( $state_id => array( 'selectedIndex' => $index ) ) ) . ')'; + $on = 'tap:AMP.setState(' . wp_json_encode( [ $state_id => [ 'selectedIndex' => $index ] ] ) . ')'; $initial_class = 0 === $index ? 'wp-playlist-item wp-playlist-playing' : 'wp-playlist-item'; $bound_class = sprintf( '%d == %s.selectedIndex ? "wp-playlist-item wp-playlist-playing" : "wp-playlist-item"', $index, $state_id ); ?> @@ -306,7 +306,7 @@ public function get_data( $attr ) { $markup = wp_playlist_shortcode( $attr ); preg_match( self::PLAYLIST_REGEX, $markup, $matches ); if ( empty( $matches[1] ) ) { - return array(); + return []; } return json_decode( $matches[1], true ); } diff --git a/includes/embeds/class-amp-reddit-embed-handler.php b/includes/embeds/class-amp-reddit-embed-handler.php index b3a91fa94a1..8199dde0910 100644 --- a/includes/embeds/class-amp-reddit-embed-handler.php +++ b/includes/embeds/class-amp-reddit-embed-handler.php @@ -21,7 +21,7 @@ class AMP_Reddit_Embed_Handler extends AMP_Base_Embed_Handler { * Register embed. */ public function register_embed() { - wp_embed_register_handler( 'amp-reddit', self::URL_PATTERN, array( $this, 'oembed' ), -1 ); + wp_embed_register_handler( 'amp-reddit', self::URL_PATTERN, [ $this, 'oembed' ], -1 ); } /** @@ -40,7 +40,7 @@ public function unregister_embed() { * @return string Embed. */ public function oembed( $matches, $attr, $url ) { - return $this->render( array( 'url' => $url ) ); + return $this->render( [ 'url' => $url ] ); } /** @@ -52,9 +52,9 @@ public function oembed( $matches, $attr, $url ) { public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'url' => false, - ) + ] ); if ( empty( $args['url'] ) ) { @@ -63,12 +63,12 @@ public function render( $args ) { return AMP_HTML_Utils::build_tag( 'amp-embedly-card', - array( + [ 'layout' => 'responsive', 'width' => '100', 'height' => '100', 'data-url' => $args['url'], - ) + ] ); } } diff --git a/includes/embeds/class-amp-soundcloud-embed.php b/includes/embeds/class-amp-soundcloud-embed.php index 82435cf077a..23ef47f7c5f 100644 --- a/includes/embeds/class-amp-soundcloud-embed.php +++ b/includes/embeds/class-amp-soundcloud-embed.php @@ -25,9 +25,9 @@ class AMP_SoundCloud_Embed_Handler extends AMP_Base_Embed_Handler { public function register_embed() { if ( function_exists( 'soundcloud_shortcode' ) ) { // @todo Move this to Jetpack. - add_shortcode( 'soundcloud', array( $this, 'shortcode' ) ); + add_shortcode( 'soundcloud', [ $this, 'shortcode' ] ); } - add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 2 ); + add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 2 ); } /** @@ -38,7 +38,7 @@ public function unregister_embed() { // @todo Move this to Jetpack. remove_shortcode( 'soundcloud' ); } - remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); + remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 ); } /** @@ -83,7 +83,7 @@ private function parse_amp_component_from_iframe( $html, $url ) { if ( preg_match( '#<iframe[^>]*?src="(?P<src>[^"]+)"#s', $html, $matches ) ) { $src = html_entity_decode( $matches['src'], ENT_QUOTES ); - $query = array(); + $query = []; parse_str( wp_parse_url( $src, PHP_URL_QUERY ), $query ); if ( ! empty( $query['url'] ) ) { $props = $this->extract_params_from_iframe_src( $query['url'] ); @@ -162,19 +162,19 @@ public function shortcode( $attr, $content = null ) { public function render( $args, $url ) { $args = wp_parse_args( $args, - array( + [ 'track_id' => false, 'playlist_id' => false, 'height' => null, 'width' => null, 'visual' => null, 'fallback' => '', - ) + ] ); $this->did_convert_elements = true; - $attributes = array(); + $attributes = []; if ( ! empty( $args['track_id'] ) ) { $attributes['data-trackid'] = $args['track_id']; } elseif ( ! empty( $args['playlist_id'] ) ) { @@ -209,10 +209,10 @@ public function render( $args, $url ) { private function render_embed_fallback( $url ) { return AMP_HTML_Utils::build_tag( 'a', - array( + [ 'href' => esc_url_raw( $url ), 'class' => 'amp-wp-embed-fallback', - ), + ], esc_html( $url ) ); } @@ -226,15 +226,15 @@ private function render_embed_fallback( $url ) { private function extract_params_from_iframe_src( $url ) { $parsed_url = wp_parse_url( $url ); if ( preg_match( '#tracks/(?P<track_id>\d+)#', $parsed_url['path'], $matches ) ) { - return array( + return [ 'track_id' => $matches['track_id'], - ); + ]; } if ( preg_match( '#playlists/(?P<playlist_id>\d+)#', $parsed_url['path'], $matches ) ) { - return array( + return [ 'playlist_id' => $matches['playlist_id'], - ); + ]; } - return array(); + return []; } } diff --git a/includes/embeds/class-amp-tumblr-embed-handler.php b/includes/embeds/class-amp-tumblr-embed-handler.php index 75650849c9a..fe59c68952c 100644 --- a/includes/embeds/class-amp-tumblr-embed-handler.php +++ b/includes/embeds/class-amp-tumblr-embed-handler.php @@ -15,14 +15,14 @@ class AMP_Tumblr_Embed_Handler extends AMP_Base_Embed_Handler { * Register embed. */ public function register_embed() { - add_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10, 2 ); + add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 2 ); } /** * Unregister embed. */ public function unregister_embed() { - remove_filter( 'embed_oembed_html', array( $this, 'filter_embed_oembed_html' ), 10 ); + remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 ); } /** @@ -42,13 +42,13 @@ public function filter_embed_oembed_html( $cache, $url ) { if ( preg_match( '#data-href="(?P<href>https://embed.tumblr.com/embed/post/\w+/\w+)"#', $cache, $matches ) ) { $cache = AMP_HTML_Utils::build_tag( 'amp-iframe', - array( + [ 'width' => $this->args['width'], 'height' => $this->args['height'], 'layout' => 'responsive', 'sandbox' => 'allow-scripts allow-popups', // The allow-scripts is needed to allow the iframe to render; allow-popups needed to allow clicking. 'src' => $matches['href'], - ), + ], sprintf( '<a placeholder href="%s">Tumblr</a>', $url ) ); } diff --git a/includes/embeds/class-amp-twitter-embed.php b/includes/embeds/class-amp-twitter-embed.php index 5b2e04bb1e6..c6410ff1fa0 100644 --- a/includes/embeds/class-amp-twitter-embed.php +++ b/includes/embeds/class-amp-twitter-embed.php @@ -46,9 +46,9 @@ class AMP_Twitter_Embed_Handler extends AMP_Base_Embed_Handler { * Registers embed. */ public function register_embed() { - add_shortcode( 'tweet', array( $this, 'shortcode' ) ); // Note: This is a Jetpack shortcode. - wp_embed_register_handler( 'amp-twitter', self::URL_PATTERN, array( $this, 'oembed' ), -1 ); - wp_embed_register_handler( 'amp-twitter-timeline', self::URL_PATTERN_TIMELINE, array( $this, 'oembed_timeline' ), -1 ); + add_shortcode( 'tweet', [ $this, 'shortcode' ] ); // Note: This is a Jetpack shortcode. + wp_embed_register_handler( 'amp-twitter', self::URL_PATTERN, [ $this, 'oembed' ], -1 ); + wp_embed_register_handler( 'amp-twitter-timeline', self::URL_PATTERN_TIMELINE, [ $this, 'oembed_timeline' ], -1 ); } /** @@ -71,9 +71,9 @@ public function unregister_embed() { public function shortcode( $attr ) { $attr = wp_parse_args( $attr, - array( + [ 'tweet' => false, - ) + ] ); if ( empty( $attr['tweet'] ) && ! empty( $attr[0] ) ) { @@ -98,12 +98,12 @@ public function shortcode( $attr ) { return AMP_HTML_Utils::build_tag( $this->amp_tag, - array( + [ 'data-tweetid' => $id, 'layout' => 'responsive', 'width' => $this->args['width'], 'height' => $this->args['height'], - ) + ] ); } @@ -126,7 +126,7 @@ public function oembed( $matches ) { return ''; } - return $this->shortcode( array( 'tweet' => $id ) ); + return $this->shortcode( [ 'tweet' => $id ] ); } /** @@ -142,10 +142,10 @@ public function oembed_timeline( $matches ) { return ''; } - $attributes = array( + $attributes = [ 'data-timeline-source-type' => 'profile', 'data-timeline-screen-name' => $matches['username'], - ); + ]; if ( isset( $matches['type'] ) ) { switch ( $matches['type'] ) { @@ -232,12 +232,12 @@ private function create_amp_twitter_and_replace_node( $dom, $node ) { $new_node = AMP_DOM_Utils::create_node( $dom, $this->amp_tag, - array( + [ 'width' => $this->DEFAULT_WIDTH, 'height' => $this->DEFAULT_HEIGHT, 'layout' => 'responsive', 'data-tweetid' => $tweet_id, - ) + ] ); $this->sanitize_embed_script( $node ); diff --git a/includes/embeds/class-amp-vimeo-embed.php b/includes/embeds/class-amp-vimeo-embed.php index bea3aca8626..9dcf3468e7b 100644 --- a/includes/embeds/class-amp-vimeo-embed.php +++ b/includes/embeds/class-amp-vimeo-embed.php @@ -35,7 +35,7 @@ class AMP_Vimeo_Embed_Handler extends AMP_Base_Embed_Handler { * * @param array $args Height, width and maximum width for embed. */ - public function __construct( $args = array() ) { + public function __construct( $args = [] ) { parent::__construct( $args ); if ( isset( $this->args['content_max_width'] ) ) { @@ -49,9 +49,9 @@ public function __construct( $args = array() ) { * Register embed. */ public function register_embed() { - wp_embed_register_handler( 'amp-vimeo', self::URL_PATTERN, array( $this, 'oembed' ), -1 ); - add_shortcode( 'vimeo', array( $this, 'shortcode' ) ); - add_filter( 'wp_video_shortcode_override', array( $this, 'video_override' ), 10, 2 ); + wp_embed_register_handler( 'amp-vimeo', self::URL_PATTERN, [ $this, 'oembed' ], -1 ); + add_shortcode( 'vimeo', [ $this, 'shortcode' ] ); + add_filter( 'wp_video_shortcode_override', [ $this, 'video_override' ], 10, 2 ); } /** @@ -86,9 +86,9 @@ public function shortcode( $attr ) { } return $this->render( - array( + [ 'video_id' => $video_id, - ) + ] ); } @@ -107,10 +107,10 @@ public function oembed( $matches, $attr, $url, $rawattr ) { $video_id = $this->get_video_id_from_url( $url ); return $this->render( - array( + [ 'url' => $url, 'video_id' => $video_id, - ) + ] ); } @@ -123,18 +123,18 @@ public function oembed( $matches, $attr, $url, $rawattr ) { public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'video_id' => false, - ) + ] ); if ( empty( $args['video_id'] ) ) { return AMP_HTML_Utils::build_tag( 'a', - array( + [ 'href' => esc_url( $args['url'] ), 'class' => 'amp-wp-embed-fallback', - ), + ], esc_html( $args['url'] ) ); } @@ -143,12 +143,12 @@ public function render( $args ) { return AMP_HTML_Utils::build_tag( 'amp-vimeo', - array( + [ 'data-videoid' => $args['video_id'], 'layout' => 'responsive', 'width' => $this->args['width'], 'height' => $this->args['height'], - ) + ] ); } @@ -188,7 +188,7 @@ public function video_override( $html, $attr ) { $src = $attr['src']; $vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#'; if ( 1 === preg_match( $vimeo_pattern, $src ) ) { - return $this->shortcode( array( $src ) ); + return $this->shortcode( [ $src ] ); } return $html; } diff --git a/includes/embeds/class-amp-vine-embed.php b/includes/embeds/class-amp-vine-embed.php index 5d4b42002e4..f2b05041651 100644 --- a/includes/embeds/class-amp-vine-embed.php +++ b/includes/embeds/class-amp-vine-embed.php @@ -29,7 +29,7 @@ class AMP_Vine_Embed_Handler extends AMP_Base_Embed_Handler { * Registers embed. */ public function register_embed() { - wp_embed_register_handler( 'amp-vine', self::URL_PATTERN, array( $this, 'oembed' ), -1 ); + wp_embed_register_handler( 'amp-vine', self::URL_PATTERN, [ $this, 'oembed' ], -1 ); } /** @@ -50,10 +50,10 @@ public function unregister_embed() { */ public function oembed( $matches, $attr, $url, $rawattr ) { return $this->render( - array( + [ 'url' => $url, 'vine_id' => end( $matches ), - ) + ] ); } @@ -66,19 +66,19 @@ public function oembed( $matches, $attr, $url, $rawattr ) { public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'url' => false, 'vine_id' => false, - ) + ] ); if ( empty( $args['vine_id'] ) ) { return AMP_HTML_Utils::build_tag( 'a', - array( + [ 'href' => esc_url( $args['url'] ), 'class' => 'amp-wp-embed-fallback', - ), + ], esc_html( $args['url'] ) ); } @@ -87,12 +87,12 @@ public function render( $args ) { return AMP_HTML_Utils::build_tag( 'amp-vine', - array( + [ 'data-vineid' => $args['vine_id'], 'layout' => 'responsive', 'width' => $this->args['width'], 'height' => $this->args['height'], - ) + ] ); } } diff --git a/includes/embeds/class-amp-youtube-embed.php b/includes/embeds/class-amp-youtube-embed.php index 5bf829952ad..824bfb65231 100644 --- a/includes/embeds/class-amp-youtube-embed.php +++ b/includes/embeds/class-amp-youtube-embed.php @@ -35,7 +35,7 @@ class AMP_YouTube_Embed_Handler extends AMP_Base_Embed_Handler { * * @param array $args Height, width and maximum width for embed. */ - public function __construct( $args = array() ) { + public function __construct( $args = [] ) { parent::__construct( $args ); if ( isset( $this->args['content_max_width'] ) ) { @@ -49,9 +49,9 @@ public function __construct( $args = array() ) { * Register embed. */ public function register_embed() { - wp_embed_register_handler( 'amp-youtube', self::URL_PATTERN, array( $this, 'oembed' ), -1 ); - add_shortcode( 'youtube', array( $this, 'shortcode' ) ); - add_filter( 'wp_video_shortcode_override', array( $this, 'video_override' ), 10, 2 ); + wp_embed_register_handler( 'amp-youtube', self::URL_PATTERN, [ $this, 'oembed' ], -1 ); + add_shortcode( 'youtube', [ $this, 'shortcode' ] ); + add_filter( 'wp_video_shortcode_override', [ $this, 'video_override' ], 10, 2 ); } /** @@ -84,10 +84,10 @@ public function shortcode( $attr ) { $video_id = $this->get_video_id_from_url( $url ); return $this->render( - array( + [ 'url' => $url, 'video_id' => $video_id, - ) + ] ); } @@ -103,7 +103,7 @@ public function shortcode( $attr ) { * @return string Rendered oEmbed. */ public function oembed( $matches, $attr, $url, $rawattr ) { - return $this->shortcode( array( $url ) ); + return $this->shortcode( [ $url ] ); } /** @@ -115,18 +115,18 @@ public function oembed( $matches, $attr, $url, $rawattr ) { public function render( $args ) { $args = wp_parse_args( $args, - array( + [ 'video_id' => false, - ) + ] ); if ( empty( $args['video_id'] ) ) { return AMP_HTML_Utils::build_tag( 'a', - array( + [ 'href' => esc_url( $args['url'] ), 'class' => 'amp-wp-embed-fallback', - ), + ], esc_html( $args['url'] ) ); } @@ -135,12 +135,12 @@ public function render( $args ) { return AMP_HTML_Utils::build_tag( 'amp-youtube', - array( + [ 'data-videoid' => $args['video_id'], 'layout' => 'responsive', 'width' => $this->args['width'], 'height' => $this->args['height'], - ) + ] ); } @@ -174,7 +174,7 @@ private function get_video_id_from_url( $url ) { /* The path looks like /(v|e|embed)/{id} */ $parts = explode( '/', $parsed_url['path'] ); - if ( in_array( $parts[1], array( 'v', 'e', 'embed' ), true ) ) { + if ( in_array( $parts[1], [ 'v', 'e', 'embed' ], true ) ) { $video_id = $parts[2]; } } @@ -214,7 +214,7 @@ public function video_override( $html, $attr ) { $src = $attr['src']; $youtube_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#'; if ( 1 === preg_match( $youtube_pattern, $src ) ) { - return $this->shortcode( array( $src ) ); + return $this->shortcode( [ $src ] ); } return $html; } diff --git a/includes/options/class-amp-analytics-options-submenu.php b/includes/options/class-amp-analytics-options-submenu.php index f994767f05b..60e0a2a8a72 100644 --- a/includes/options/class-amp-analytics-options-submenu.php +++ b/includes/options/class-amp-analytics-options-submenu.php @@ -50,7 +50,7 @@ public function init() { add_action( 'admin_print_styles-amp_page_' . $this->menu_slug, - array( $this, 'amp_options_styles' ) + [ $this, 'amp_options_styles' ] ); } @@ -64,7 +64,7 @@ private function add_submenu() { __( 'Analytics', 'amp' ), 'manage_options', $this->menu_slug, - array( $this->menu_page, 'render' ) + [ $this->menu_page, 'render' ] ); } diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index c005fb0bc7e..b0c5b187e4b 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -34,18 +34,18 @@ class AMP_Options_Manager { * * @var array */ - protected static $defaults = array( - 'experiences' => array( self::WEBSITE_EXPERIENCE ), + protected static $defaults = [ + 'experiences' => [ self::WEBSITE_EXPERIENCE ], 'theme_support' => AMP_Theme_Support::READER_MODE_SLUG, - 'supported_post_types' => array( 'post' ), - 'analytics' => array(), + 'supported_post_types' => [ 'post' ], + 'analytics' => [], 'auto_accept_sanitization' => true, 'all_templates_supported' => true, - 'supported_templates' => array( 'is_singular' ), + 'supported_templates' => [ 'is_singular' ], 'enable_response_caching' => true, 'version' => AMP__VERSION, 'story_templates_version' => false, - ); + ]; /** * Register settings. @@ -54,17 +54,17 @@ public static function register_settings() { register_setting( self::OPTION_NAME, self::OPTION_NAME, - array( + [ 'type' => 'array', - 'sanitize_callback' => array( __CLASS__, 'validate_options' ), - ) + 'sanitize_callback' => [ __CLASS__, 'validate_options' ], + ] ); - add_action( 'update_option_' . self::OPTION_NAME, array( __CLASS__, 'maybe_flush_rewrite_rules' ), 10, 2 ); - add_action( 'admin_notices', array( __CLASS__, 'render_welcome_notice' ) ); - add_action( 'admin_notices', array( __CLASS__, 'persistent_object_caching_notice' ) ); - add_action( 'admin_notices', array( __CLASS__, 'render_cache_miss_notice' ) ); - add_action( 'admin_notices', array( __CLASS__, 'render_php_css_parser_conflict_notice' ) ); + add_action( 'update_option_' . self::OPTION_NAME, [ __CLASS__, 'maybe_flush_rewrite_rules' ], 10, 2 ); + add_action( 'admin_notices', [ __CLASS__, 'render_welcome_notice' ] ); + add_action( 'admin_notices', [ __CLASS__, 'persistent_object_caching_notice' ] ); + add_action( 'admin_notices', [ __CLASS__, 'render_cache_miss_notice' ] ); + add_action( 'admin_notices', [ __CLASS__, 'render_php_css_parser_conflict_notice' ] ); } /** @@ -76,12 +76,12 @@ public static function register_settings() { * @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(); + $old_post_types = isset( $old_options['supported_post_types'] ) ? $old_options['supported_post_types'] : []; + $new_post_types = isset( $new_options['supported_post_types'] ) ? $new_options['supported_post_types'] : []; sort( $old_post_types ); sort( $new_post_types ); - $old_experiences = isset( $old_options['experiences'] ) ? $old_options['experiences'] : array(); - $new_experiences = isset( $new_options['experiences'] ) ? $new_options['experiences'] : array(); + $old_experiences = isset( $old_options['experiences'] ) ? $old_options['experiences'] : []; + $new_experiences = isset( $new_options['experiences'] ) ? $new_options['experiences'] : []; sort( $old_experiences ); sort( $new_experiences ); if ( $old_post_types !== $new_post_types || $old_experiences !== $new_experiences ) { @@ -111,9 +111,9 @@ public static function maybe_flush_rewrite_rules( $old_options, $new_options ) { * @return array Options. */ public static function get_options() { - $options = get_option( self::OPTION_NAME, array() ); + $options = get_option( self::OPTION_NAME, [] ); if ( empty( $options ) ) { - $options = array(); // Ensure empty string becomes array. + $options = []; // Ensure empty string becomes array. } $defaults = self::$defaults; @@ -219,30 +219,30 @@ public static function validate_options( $new_options ) { // Validate the selected experiences. $options['experiences'] = array_intersect( $new_options['experiences'], - array( + [ self::WEBSITE_EXPERIENCE, self::STORIES_EXPERIENCE, - ) + ] ); // At least one experience must be selected. if ( empty( $options['experiences'] ) ) { - $options['experiences'] = array( self::WEBSITE_EXPERIENCE ); + $options['experiences'] = [ self::WEBSITE_EXPERIENCE ]; } } // Theme support. - $recognized_theme_supports = array( + $recognized_theme_supports = [ AMP_Theme_Support::READER_MODE_SLUG, AMP_Theme_Support::TRANSITIONAL_MODE_SLUG, AMP_Theme_Support::STANDARD_MODE_SLUG, - ); + ]; if ( isset( $new_options['theme_support'] ) && in_array( $new_options['theme_support'], $recognized_theme_supports, true ) ) { $options['theme_support'] = $new_options['theme_support']; // If this option was changed, display a notice with the new template mode. if ( self::get_option( 'theme_support' ) !== $new_options['theme_support'] ) { - add_action( 'update_option_' . self::OPTION_NAME, array( __CLASS__, 'handle_updated_theme_support_option' ) ); + add_action( 'update_option_' . self::OPTION_NAME, [ __CLASS__, 'handle_updated_theme_support_option' ] ); } } @@ -250,7 +250,7 @@ public static function validate_options( $new_options ) { // Validate post type support. if ( in_array( self::WEBSITE_EXPERIENCE, $options['experiences'], true ) || isset( $new_options['supported_post_types'] ) ) { - $options['supported_post_types'] = array(); + $options['supported_post_types'] = []; if ( isset( $new_options['supported_post_types'] ) ) { foreach ( $new_options['supported_post_types'] as $post_type ) { if ( ! post_type_exists( $post_type ) ) { @@ -269,7 +269,7 @@ public static function validate_options( $new_options ) { $options['all_templates_supported'] = ! empty( $new_options['all_templates_supported'] ); // Validate supported templates. - $options['supported_templates'] = array(); + $options['supported_templates'] = []; if ( isset( $new_options['supported_templates'] ) ) { $options['supported_templates'] = array_intersect( $new_options['supported_templates'], @@ -315,10 +315,10 @@ public static function validate_options( $new_options ) { if ( isset( $data['delete'] ) ) { unset( $options['analytics'][ $entry_id ] ); } else { - $options['analytics'][ $entry_id ] = array( + $options['analytics'][ $entry_id ] = [ 'type' => $entry_vendor_type, 'config' => $entry_config, - ); + ]; } } } @@ -355,7 +355,7 @@ public static function check_supported_post_type_update_errors() { return; } - $supported_types = self::get_option( 'supported_post_types', array() ); + $supported_types = self::get_option( 'supported_post_types', [] ); foreach ( AMP_Post_Type_Support::get_eligible_post_types() as $name ) { $post_type = get_post_type_object( $name ); if ( empty( $post_type ) ) { @@ -636,7 +636,7 @@ public static function handle_updated_theme_support_option() { if ( $has_theme_support ) { $theme_support = current_theme_supports( AMP_Theme_Support::SLUG ); if ( ! is_array( $theme_support ) ) { - $theme_support = array(); + $theme_support = []; } $theme_support['paired'] = AMP_Theme_Support::TRANSITIONAL_MODE_SLUG === $template_mode; add_theme_support( AMP_Theme_Support::SLUG, $theme_support ); @@ -647,7 +647,7 @@ public static function handle_updated_theme_support_option() { $url = amp_admin_get_preview_permalink(); $notice_type = 'updated'; - $review_messages = array(); + $review_messages = []; if ( $url && $has_theme_support ) { $validation = AMP_Validation_Manager::validate_url( $url ); diff --git a/includes/options/class-amp-options-menu.php b/includes/options/class-amp-options-menu.php index 787f01c7742..7fbaaddc791 100644 --- a/includes/options/class-amp-options-menu.php +++ b/includes/options/class-amp-options-menu.php @@ -22,10 +22,10 @@ class AMP_Options_Menu { */ public function init() { add_action( 'admin_post_amp_analytics_options', 'AMP_Options_Manager::handle_analytics_submit' ); - add_action( 'admin_menu', array( $this, 'add_menu_items' ), 9 ); + add_action( 'admin_menu', [ $this, 'add_menu_items' ], 9 ); $plugin_file = preg_replace( '#.+/(?=.+?/.+?)#', '', AMP__FILE__ ); - add_filter( "plugin_action_links_{$plugin_file}", array( $this, 'add_plugin_action_links' ) ); + add_filter( "plugin_action_links_{$plugin_file}", [ $this, 'add_plugin_action_links' ] ); } /** @@ -36,13 +36,13 @@ public function init() { */ public function add_plugin_action_links( $links ) { return array_merge( - array( + [ 'settings' => sprintf( '<a href="%1$s">%2$s</a>', esc_url( add_query_arg( 'page', AMP_Options_Manager::OPTION_NAME, admin_url( 'admin.php' ) ) ), __( 'Settings', 'amp' ) ), - ), + ], $links ); } @@ -57,7 +57,7 @@ public function add_menu_items() { __( 'AMP', 'amp' ), 'edit_posts', AMP_Options_Manager::OPTION_NAME, - array( $this, 'render_screen' ), + [ $this, 'render_screen' ], self::ICON_BASE64_SVG ); @@ -79,45 +79,45 @@ public function add_menu_items() { add_settings_field( 'experiences', __( 'Experiences', 'amp' ), - array( $this, 'render_experiences' ), + [ $this, 'render_experiences' ], AMP_Options_Manager::OPTION_NAME, 'general', - array( + [ 'class' => 'experiences', - ) + ] ); add_settings_field( 'theme_support', __( 'Website Mode', 'amp' ), - array( $this, 'render_theme_support' ), + [ $this, 'render_theme_support' ], AMP_Options_Manager::OPTION_NAME, 'general', - array( + [ 'class' => 'amp-website-mode', - ) + ] ); add_settings_field( 'validation', __( 'Validation Handling', 'amp' ), - array( $this, 'render_validation_handling' ), + [ $this, 'render_validation_handling' ], AMP_Options_Manager::OPTION_NAME, 'general', - array( + [ 'class' => 'amp-validation-field', - ) + ] ); add_settings_field( 'supported_templates', __( 'Supported Templates', 'amp' ), - array( $this, 'render_supported_templates' ), + [ $this, 'render_supported_templates' ], AMP_Options_Manager::OPTION_NAME, 'general', - array( + [ 'class' => 'amp-template-support-field', - ) + ] ); add_action( @@ -139,18 +139,18 @@ function() { add_settings_field( 'caching', __( 'Caching', 'amp' ), - array( $this, 'render_caching' ), + [ $this, 'render_caching' ], AMP_Options_Manager::OPTION_NAME, 'general', - array( + [ 'class' => 'amp-caching-field', - ) + ] ); } - $submenus = array( + $submenus = [ new AMP_Analytics_Options_Submenu( AMP_Options_Manager::OPTION_NAME ), - ); + ]; // Create submenu items and calls on the Submenu Page object to render the actual contents of the page. foreach ( $submenus as $submenu ) { @@ -354,10 +354,10 @@ public function render_theme_support() { '<a href="%s">%s</a>', esc_url( add_query_arg( - array( + [ 'taxonomy' => AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, 'post_type' => AMP_Validated_URL_Post_Type::POST_TYPE_SLUG, - ), + ], admin_url( 'edit-tags.php' ) ) ), @@ -393,9 +393,9 @@ public function render_validation_handling() { <fieldset <?php disabled( ! current_user_can( 'manage_options' ) ); ?>> <?php $auto_sanitization = AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( - array( + [ 'code' => 'non_existent', - ) + ] ); $forced_sanitization = 'with_filter' === $auto_sanitization['forced']; @@ -426,10 +426,10 @@ public function render_validation_handling() { __( 'Existing validation errors which you have already rejected will not be modified (you may want to consider <a href="%s">bulk-accepting them</a>).', 'amp' ), esc_url( add_query_arg( - array( + [ 'taxonomy' => AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, 'post_type' => AMP_Validated_URL_Post_Type::POST_TYPE_SLUG, - ), + ], admin_url( 'edit-tags.php' ) ) ) 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 68c0ef3e27e..17eb250eb27 100644 --- a/includes/options/views/class-amp-analytics-options-submenu-page.php +++ b/includes/options/views/class-amp-analytics-options-submenu-page.php @@ -186,7 +186,7 @@ protected function render_scripts() { public function render() { $this->render_styles(); - $analytics_entries = AMP_Options_Manager::get_option( 'analytics', array() ); + $analytics_entries = AMP_Options_Manager::get_option( 'analytics', [] ); $this->render_title( ! empty( $analytics_entries ) ); diff --git a/includes/sanitizers/class-amp-audio-sanitizer.php b/includes/sanitizers/class-amp-audio-sanitizer.php index 16ac60307ee..2a369a94159 100644 --- a/includes/sanitizers/class-amp-audio-sanitizer.php +++ b/includes/sanitizers/class-amp-audio-sanitizer.php @@ -26,9 +26,9 @@ class AMP_Audio_Sanitizer extends AMP_Base_Sanitizer { * * @var array */ - protected $DEFAULT_ARGS = array( + protected $DEFAULT_ARGS = [ 'add_noscript_fallback' => true, - ); + ]; /** * Get mapping of HTML selectors to the AMP component selectors which they may be converted into. @@ -36,9 +36,9 @@ class AMP_Audio_Sanitizer extends AMP_Base_Sanitizer { * @return array Mapping. */ public function get_selector_conversion_mapping() { - return array( - 'audio' => array( 'amp-audio' ), - ); + return [ + 'audio' => [ 'amp-audio' ], + ]; } /** @@ -68,7 +68,7 @@ public function sanitize() { $old_attributes = AMP_DOM_Utils::get_node_attributes_as_assoc_array( $node ); // For amp-audio, the default width and height are inferred from browser. - $sources = array(); + $sources = []; $new_attributes = $this->filter_attributes( $old_attributes ); if ( ! empty( $new_attributes['src'] ) ) { $sources[] = $new_attributes['src']; @@ -83,7 +83,7 @@ public function sanitize() { // Gather all child nodes and supply empty video dimensions from sources. $fallback = null; - $child_nodes = array(); + $child_nodes = []; while ( $node->firstChild ) { $child_node = $node->removeChild( $node->firstChild ); if ( $child_node instanceof DOMElement && 'source' === $child_node->nodeName && $child_node->hasAttribute( 'src' ) ) { @@ -133,7 +133,7 @@ public function sanitize() { } // Make sure the updated src and poster are applied to the original. - foreach ( array( 'src', 'poster', 'artwork' ) as $attr_name ) { + foreach ( [ 'src', 'poster', 'artwork' ] as $attr_name ) { if ( $new_node->hasAttribute( $attr_name ) ) { $old_node->setAttribute( $attr_name, $new_node->getAttribute( $attr_name ) ); } @@ -180,7 +180,7 @@ public function sanitize() { * @return array Returns HTML attributes; removes any not specifically declared above from input. */ private function filter_attributes( $attributes ) { - $out = array(); + $out = []; foreach ( $attributes as $name => $value ) { switch ( $name ) { diff --git a/includes/sanitizers/class-amp-base-sanitizer.php b/includes/sanitizers/class-amp-base-sanitizer.php index 9dd41993b44..62b915512d2 100644 --- a/includes/sanitizers/class-amp-base-sanitizer.php +++ b/includes/sanitizers/class-amp-base-sanitizer.php @@ -35,7 +35,7 @@ abstract class AMP_Base_Sanitizer { * * @var array */ - protected $DEFAULT_ARGS = array(); + protected $DEFAULT_ARGS = []; /** * DOM. @@ -91,7 +91,7 @@ abstract class AMP_Base_Sanitizer { * * @var array */ - private $should_not_removed_nodes = array(); + private $should_not_removed_nodes = []; /** * AMP_Base_Sanitizer constructor. @@ -110,7 +110,7 @@ abstract class AMP_Base_Sanitizer { * @type string[] $amp_layout_allowed_attributes * } */ - public function __construct( $dom, $args = array() ) { + public function __construct( $dom, $args = [] ) { $this->dom = $dom; $this->args = array_merge( $this->DEFAULT_ARGS, $args ); @@ -135,7 +135,7 @@ public function __construct( $dom, $args = array() ) { * * @param array $args Args. */ - public static function add_buffering_hooks( $args = array() ) {} + public static function add_buffering_hooks( $args = [] ) {} /** * Get mapping of HTML selectors to the AMP component selectors which they may be converted into. @@ -143,7 +143,7 @@ public static function add_buffering_hooks( $args = array() ) {} * @return array Mapping. */ public function get_selector_conversion_mapping() { - return array(); + return []; } /** @@ -174,7 +174,7 @@ abstract public function sanitize(); * or if it did not find any HTML elements to convert to AMP equivalents. */ public function get_scripts() { - return array(); + return []; } /** @@ -186,7 +186,7 @@ public function get_scripts() { * @return array[][] Mapping of CSS selectors to arrays of properties. */ public function get_styles() { - return array(); + return []; } /** @@ -196,7 +196,7 @@ public function get_styles() { * @return array Values are the CSS stylesheets. Keys are MD5 hashes of the stylesheets. */ public function get_stylesheets() { - $stylesheets = array(); + $stylesheets = []; foreach ( $this->get_styles() as $selector => $properties ) { $stylesheet = sprintf( '%s { %s }', $selector, implode( '; ', $properties ) . ';' ); @@ -350,7 +350,7 @@ public function maybe_enforce_https_src( $src, $force_https = false ) { * @param array $validation_error Validation error details. * @return bool Whether the node should have been removed, that is, that the node was sanitized for validity. */ - public function remove_invalid_child( $node, $validation_error = array() ) { + public function remove_invalid_child( $node, $validation_error = [] ) { // Prevent double-reporting nodes that are rejected for sanitization. if ( isset( $this->should_not_removed_nodes[ $node->nodeName ] ) && in_array( $node, $this->should_not_removed_nodes[ $node->nodeName ], true ) ) { @@ -379,7 +379,7 @@ public function remove_invalid_child( $node, $validation_error = array() ) { * @param array $validation_error Validation error details. * @return bool Whether the node should have been removed, that is, that the node was sanitized for validity. */ - public function remove_invalid_attribute( $element, $attribute, $validation_error = array() ) { + public function remove_invalid_attribute( $element, $attribute, $validation_error = [] ) { if ( is_string( $attribute ) ) { $node = $element->getAttributeNode( $attribute ); } else { @@ -401,7 +401,7 @@ public function remove_invalid_attribute( $element, $attribute, $validation_erro * @param array $data Data including the node. * @return bool Whether to sanitize. */ - public function should_sanitize_validation_error( $validation_error, $data = array() ) { + public function should_sanitize_validation_error( $validation_error, $data = [] ) { if ( empty( $this->args['validation_error_callback'] ) || ! is_callable( $this->args['validation_error_callback'] ) ) { return true; } @@ -424,7 +424,7 @@ public function should_sanitize_validation_error( $validation_error, $data = arr * } * @return array Error. */ - public function prepare_validation_error( array $error = array(), array $data = array() ) { + public function prepare_validation_error( array $error = [], array $data = [] ) { $node = null; $matches = null; @@ -447,7 +447,7 @@ public function prepare_validation_error( array $error = array(), array $data = } if ( ! isset( $error['node_attributes'] ) ) { - $error['node_attributes'] = array(); + $error['node_attributes'] = []; foreach ( $node->attributes as $attribute ) { $error['node_attributes'][ $attribute->nodeName ] = $attribute->nodeValue; } @@ -473,7 +473,7 @@ public function prepare_validation_error( array $error = array(), array $data = $error['type'] = preg_match( '/^on\w+/', $node->nodeName ) ? AMP_Validation_Error_Taxonomy::JS_ERROR_TYPE : AMP_Validation_Error_Taxonomy::HTML_ATTRIBUTE_ERROR_TYPE; } if ( ! isset( $error['element_attributes'] ) ) { - $error['element_attributes'] = array(); + $error['element_attributes'] = []; if ( $node->parentNode && $node->parentNode->hasAttributes() ) { foreach ( $node->parentNode->attributes as $attribute ) { $error['element_attributes'][ $attribute->nodeName ] = $attribute->nodeValue; @@ -492,7 +492,7 @@ public function prepare_validation_error( array $error = array(), array $data = * @return array AMP data array. */ public function get_data_amp_attributes( $node ) { - $attributes = array(); + $attributes = []; // Editor blocks add 'figure' as the parent node for images. If this node has data-amp-layout then we should add this as the layout attribute. $parent_node = $node->parentNode; @@ -580,11 +580,11 @@ public function maybe_add_amp_image_lightbox_node() { $amp_image_lightbox = AMP_DOM_Utils::create_node( $this->dom, 'amp-image-lightbox', - array( + [ 'id' => self::AMP_IMAGE_LIGHTBOX_ID, 'layout' => 'nodisplay', 'data-close-button-aria-label' => __( 'Close', 'amp' ), - ) + ] ); $body_node->appendChild( $amp_image_lightbox ); } diff --git a/includes/sanitizers/class-amp-blacklist-sanitizer.php b/includes/sanitizers/class-amp-blacklist-sanitizer.php index 332f6acce9c..d9915eb25d2 100644 --- a/includes/sanitizers/class-amp-blacklist-sanitizer.php +++ b/includes/sanitizers/class-amp-blacklist-sanitizer.php @@ -22,11 +22,11 @@ class AMP_Blacklist_Sanitizer extends AMP_Base_Sanitizer { * * @var array */ - protected $DEFAULT_ARGS = array( - 'add_blacklisted_protocols' => array(), - 'add_blacklisted_tags' => array(), - 'add_blacklisted_attributes' => array(), - ); + protected $DEFAULT_ARGS = [ + 'add_blacklisted_protocols' => [], + 'add_blacklisted_tags' => [], + 'add_blacklisted_attributes' => [], + ]; /** * Sanitize. @@ -187,8 +187,8 @@ private function validate_a_node( $node ) { $href = untrailingslashit( get_home_url() ) . $href; } - $valid_protocols = array( 'http', 'https', 'mailto', 'sms', 'tel', 'viber', 'whatsapp' ); - $special_protocols = array( 'tel', 'sms' ); // These ones don't valid with `filter_var+FILTER_VALIDATE_URL`. + $valid_protocols = [ 'http', 'https', 'mailto', 'sms', 'tel', 'viber', 'whatsapp' ]; + $special_protocols = [ 'tel', 'sms' ]; // These ones don't valid with `filter_var+FILTER_VALIDATE_URL`. $protocol = strtok( $href, ':' ); if ( false === filter_var( $href, FILTER_VALIDATE_URL ) @@ -252,9 +252,9 @@ private function merge_defaults_with_args( $key, $values ) { private function get_blacklisted_protocols() { return $this->merge_defaults_with_args( 'add_blacklisted_protocols', - array( + [ 'javascript', - ) + ] ); } @@ -266,7 +266,7 @@ private function get_blacklisted_protocols() { private function get_blacklisted_tags() { return $this->merge_defaults_with_args( 'add_blacklisted_tags', - array( + [ 'script', 'noscript', 'style', @@ -290,7 +290,7 @@ private function get_blacklisted_tags() { // Other weird ones. 'comments-count', - ) + ] ); } @@ -302,13 +302,13 @@ private function get_blacklisted_tags() { private function get_blacklisted_attributes() { return $this->merge_defaults_with_args( 'add_blacklisted_attributes', - array( + [ 'style', 'size', 'clear', 'align', 'valign', - ) + ] ); } } diff --git a/includes/sanitizers/class-amp-comments-sanitizer.php b/includes/sanitizers/class-amp-comments-sanitizer.php index f2176140476..662b558255a 100644 --- a/includes/sanitizers/class-amp-comments-sanitizer.php +++ b/includes/sanitizers/class-amp-comments-sanitizer.php @@ -19,9 +19,9 @@ class AMP_Comments_Sanitizer extends AMP_Base_Sanitizer { * * @var array */ - protected $DEFAULT_ARGS = array( + protected $DEFAULT_ARGS = [ 'comment_live_list' => false, - ); + ]; /** * Pre-process the comment form and comment list for AMP. @@ -74,7 +74,7 @@ protected function process_comment_form( $comment_form ) { * * @var DOMElement[][] $form_fields */ - $form_fields = array(); + $form_fields = []; foreach ( $comment_form->getElementsByTagName( 'input' ) as $element ) { $name = $element->getAttribute( 'name' ); if ( $name ) { @@ -94,11 +94,11 @@ protected function process_comment_form( $comment_form ) { $post_id = (int) $form_fields['comment_post_ID'][0]->getAttribute( 'value' ); $state_id = AMP_Theme_Support::get_comment_form_state_id( $post_id ); - $form_state = array( - 'values' => array(), + $form_state = [ + 'values' => [], 'submitting' => false, 'replyToName' => '', - ); + ]; if ( ! empty( $form_fields['comment_parent'] ) ) { $comment_id = (int) $form_fields['comment_parent'][0]->getAttribute( 'value' ); @@ -115,7 +115,7 @@ protected function process_comment_form( $comment_form ) { foreach ( $form_field as $element ) { // @todo Radio and checkbox inputs are not supported yet. - if ( in_array( strtolower( $element->getAttribute( 'type' ) ), array( 'checkbox', 'radio' ), true ) ) { + if ( in_array( strtolower( $element->getAttribute( 'type' ) ), [ 'checkbox', 'radio' ], true ) ) { continue; } @@ -157,7 +157,7 @@ protected function process_comment_form( $comment_form ) { $form_reset_state['values']['email'], $form_reset_state['values']['url'] ); - $on = array( + $on = [ // Disable the form when submitting. sprintf( 'submit:AMP.setState( { %s: { submitting: true } } )', @@ -174,7 +174,7 @@ protected function process_comment_form( $comment_form ) { $state_id, wp_json_encode( $form_reset_state, JSON_UNESCAPED_UNICODE ) ), - ); + ]; $comment_form->setAttribute( 'on', implode( ';', $on ) ); } @@ -203,11 +203,11 @@ protected function add_amp_live_list_comment_attributes( $comment_element ) { // Ensure the top-level data-update-time reflects the max time of the comments in the thread. $children = $comment_object->get_children( - array( + [ 'format' => 'flat', 'hierarchical' => 'flat', 'orderby' => 'none', - ) + ] ); foreach ( $children as $child_comment ) { $update_time = max( strtotime( $child_comment->comment_date ), $update_time ); diff --git a/includes/sanitizers/class-amp-embed-sanitizer.php b/includes/sanitizers/class-amp-embed-sanitizer.php index 6d32afd5b18..d9f9690d6b2 100644 --- a/includes/sanitizers/class-amp-embed-sanitizer.php +++ b/includes/sanitizers/class-amp-embed-sanitizer.php @@ -17,7 +17,7 @@ class AMP_Embed_Sanitizer extends AMP_Base_Sanitizer { * * @var AMP_Base_Embed_Handler[] AMP_Base_Embed_Handler[] */ - private $embed_handlers = array(); + private $embed_handlers = []; /** * AMP_Embed_Sanitizer constructor. @@ -25,7 +25,7 @@ class AMP_Embed_Sanitizer extends AMP_Base_Sanitizer { * @param DOMDocument $dom DOM. * @param array $args Args. */ - public function __construct( $dom, $args = array() ) { + public function __construct( $dom, $args = [] ) { parent::__construct( $dom, $args ); if ( ! empty( $this->args['embed_handlers'] ) ) { diff --git a/includes/sanitizers/class-amp-form-sanitizer.php b/includes/sanitizers/class-amp-form-sanitizer.php index 44ca4b947ab..7387061694b 100644 --- a/includes/sanitizers/class-amp-form-sanitizer.php +++ b/includes/sanitizers/class-amp-form-sanitizer.php @@ -112,7 +112,7 @@ public function sanitize() { */ $target = $node->getAttribute( 'target' ); if ( '_top' !== $target ) { - if ( ! $target || in_array( $target, array( '_self', '_parent' ), true ) ) { + if ( ! $target || in_array( $target, [ '_self', '_parent' ], true ) ) { $node->setAttribute( 'target', '_top' ); } elseif ( '_blank' !== $target ) { $node->setAttribute( 'target', '_blank' ); @@ -135,11 +135,11 @@ public function ensure_response_message_elements( $form ) { * * @var DOMElement $parent */ - $elements = array( + $elements = [ 'submit-error' => null, 'submit-success' => null, 'submitting' => null, - ); + ]; $templates = $form->getElementsByTagName( 'template' ); for ( $i = $templates->length - 1; $i >= 0; $i-- ) { diff --git a/includes/sanitizers/class-amp-iframe-sanitizer.php b/includes/sanitizers/class-amp-iframe-sanitizer.php index 308235a4253..70d1376cfbc 100644 --- a/includes/sanitizers/class-amp-iframe-sanitizer.php +++ b/includes/sanitizers/class-amp-iframe-sanitizer.php @@ -43,12 +43,12 @@ class AMP_Iframe_Sanitizer extends AMP_Base_Sanitizer { * @type string $alias_origin An alternative origin which can be supplied which is used when encountering same-origin iframes. * } */ - protected $DEFAULT_ARGS = array( + protected $DEFAULT_ARGS = [ 'add_placeholder' => false, 'add_noscript_fallback' => true, 'current_origin' => null, 'alias_origin' => null, - ); + ]; /** * Get mapping of HTML selectors to the AMP component selectors which they may be converted into. @@ -56,11 +56,11 @@ class AMP_Iframe_Sanitizer extends AMP_Base_Sanitizer { * @return array Mapping. */ public function get_selector_conversion_mapping() { - return array( - 'iframe' => array( + return [ + 'iframe' => [ 'amp-iframe', - ), - ); + ], + ]; } /** @@ -158,7 +158,7 @@ public function sanitize() { * @return array Returns HTML attributes; normalizes src, dimensions, frameborder, sandox, allowtransparency and allowfullscreen */ private function normalize_attributes( $attributes ) { - $out = array(); + $out = []; $remove_allow_same_origin = false; foreach ( $attributes as $name => $value ) { @@ -262,10 +262,10 @@ private function build_placeholder( $parent_attributes ) { $placeholder_node = AMP_DOM_Utils::create_node( $this->dom, 'span', - array( + [ 'placeholder' => '', 'class' => 'amp-wp-iframe-placeholder', - ) + ] ); return $placeholder_node; diff --git a/includes/sanitizers/class-amp-nav-menu-dropdown-sanitizer.php b/includes/sanitizers/class-amp-nav-menu-dropdown-sanitizer.php index 110951117d9..e686951c65f 100644 --- a/includes/sanitizers/class-amp-nav-menu-dropdown-sanitizer.php +++ b/includes/sanitizers/class-amp-nav-menu-dropdown-sanitizer.php @@ -20,14 +20,14 @@ class AMP_Nav_Menu_Dropdown_Sanitizer extends AMP_Base_Sanitizer { * @since 1.1.0 * @var array */ - protected $DEFAULT_ARGS = array( + protected $DEFAULT_ARGS = [ 'sub_menu_button_class' => '', 'sub_menu_button_toggle_class' => '', 'expand_text' => '', 'collapse_text' => '', 'icon' => null, // Optional. 'sub_menu_item_state_id' => 'navMenuItemExpanded', - ); + ]; /** * AMP_Nav_Menu_Dropdown_Sanitizer constructor. @@ -37,7 +37,7 @@ class AMP_Nav_Menu_Dropdown_Sanitizer extends AMP_Base_Sanitizer { * @param DOMDocument $dom DOM. * @param array $args Args. */ - public function __construct( $dom, $args = array() ) { + public function __construct( $dom, $args = [] ) { parent::__construct( $dom, $args ); $this->args = self::ensure_defaults( $this->args ); @@ -50,7 +50,7 @@ public function __construct( $dom, $args = array() ) { * * @param array $args Args. */ - public static function add_buffering_hooks( $args = array() ) { + public static function add_buffering_hooks( $args = [] ) { if ( empty( $args['sub_menu_button_class'] ) || empty( $args['sub_menu_button_toggle_class'] ) ) { return; } diff --git a/includes/sanitizers/class-amp-o2-player-sanitizer.php b/includes/sanitizers/class-amp-o2-player-sanitizer.php index ddb115a6853..f21b8ff1cfd 100644 --- a/includes/sanitizers/class-amp-o2-player-sanitizer.php +++ b/includes/sanitizers/class-amp-o2-player-sanitizer.php @@ -99,12 +99,12 @@ private function create_amp_o2_player( $dom, $node ) { if ( ! empty( $o2_attributes ) ) { $component_attributes = array_merge( $o2_attributes, - array( + [ 'data-macros' => 'm.playback=click', 'layout' => 'responsive', 'width' => self::$width, 'height' => self::$height, - ) + ] ); $amp_o2_player = AMP_DOM_Utils::create_node( $dom, self::$amp_tag, $component_attributes ); @@ -129,13 +129,13 @@ private function create_amp_o2_player( $dom, $node ) { private function get_o2_player_attributes( $src ) { $found = preg_match( self::URL_PATTERN, $src, $matches ); if ( $found ) { - return array( + return [ 'data-pid' => $matches['data_pid'], 'data-vid' => $matches['data_vid'], 'data-bcid' => $matches['data_bcid'], - ); + ]; } - return array(); + return []; } } diff --git a/includes/sanitizers/class-amp-playbuzz-sanitizer.php b/includes/sanitizers/class-amp-playbuzz-sanitizer.php index 3ec07e5f8b9..ecf3c419a48 100644 --- a/includes/sanitizers/class-amp-playbuzz-sanitizer.php +++ b/includes/sanitizers/class-amp-playbuzz-sanitizer.php @@ -46,9 +46,9 @@ class AMP_Playbuzz_Sanitizer extends AMP_Base_Sanitizer { * @return array Mapping. */ public function get_selector_conversion_mapping() { - return array( - 'div.pb_feed' => array( 'amp-playbuzz.pb_feed' ), - ); + return [ + 'div.pb_feed' => [ 'amp-playbuzz.pb_feed' ], + ]; } /** @@ -108,7 +108,7 @@ public function sanitize() { * @return array Returns HTML attributes; removes any not specifically declared above from input. */ private function filter_attributes( $attributes ) { - $out = array(); + $out = []; foreach ( $attributes as $name => $value ) { switch ( $name ) { diff --git a/includes/sanitizers/class-amp-rule-spec.php b/includes/sanitizers/class-amp-rule-spec.php index 02993d35d06..f6d5a848f7e 100644 --- a/includes/sanitizers/class-amp-rule-spec.php +++ b/includes/sanitizers/class-amp-rule-spec.php @@ -60,7 +60,7 @@ abstract class AMP_Rule_Spec { * @since 1.0 * @var array */ - public static $layout_enum = array( + public static $layout_enum = [ 1 => 'nodisplay', 2 => 'fixed', 3 => 'fixed-height', @@ -70,7 +70,7 @@ abstract class AMP_Rule_Spec { 7 => 'flex-item', 8 => 'fluid', 9 => 'intrinsic', - ); + ]; /** * List of boolean attributes. @@ -78,7 +78,7 @@ abstract class AMP_Rule_Spec { * @since 0.7 * @var array */ - public static $boolean_attributes = array( + public static $boolean_attributes = [ 'allowfullscreen', 'async', 'autofocus', @@ -123,19 +123,19 @@ abstract class AMP_Rule_Spec { 'truespeed', 'typemustmatch', 'visible', - ); + ]; /** * Additional allowed tags. * * @var array */ - public static $additional_allowed_tags = array( + public static $additional_allowed_tags = [ // An experimental tag with no protoascii. - 'amp-share-tracking' => array( - 'attr_spec_list' => array(), - 'tag_spec' => array(), - ), - ); + 'amp-share-tracking' => [ + 'attr_spec_list' => [], + 'tag_spec' => [], + ], + ]; } diff --git a/includes/sanitizers/class-amp-style-sanitizer.php b/includes/sanitizers/class-amp-style-sanitizer.php index 1c87d0a6552..80fd6803be1 100644 --- a/includes/sanitizers/class-amp-style-sanitizer.php +++ b/includes/sanitizers/class-amp-style-sanitizer.php @@ -97,17 +97,17 @@ class AMP_Style_Sanitizer extends AMP_Base_Sanitizer { * * @var array */ - protected $DEFAULT_ARGS = array( - 'dynamic_element_selectors' => array( + protected $DEFAULT_ARGS = [ + 'dynamic_element_selectors' => [ 'amp-list', 'amp-live-list', '[submit-error]', '[submit-success]', - ), + ], 'should_locate_sources' => false, 'parsed_cache_variant' => null, 'include_manifest_comment' => 'always', - ); + ]; /** * List of stylesheet parts prior to selector/rule removal (tree shaking). @@ -122,7 +122,7 @@ class AMP_Style_Sanitizer extends AMP_Base_Sanitizer { * @type bool $keyframes Whether an amp-keyframes. * } */ - private $pending_stylesheets = array(); + private $pending_stylesheets = []; /** * Spec for style[amp-custom] cdata. @@ -190,7 +190,7 @@ class AMP_Style_Sanitizer extends AMP_Base_Sanitizer { * @since 1.1 * @var array */ - private $used_attributes = array( + private $used_attributes = [ 'autofocus' => true, 'checked' => true, 'controls' => true, @@ -202,7 +202,7 @@ class AMP_Style_Sanitizer extends AMP_Base_Sanitizer { 'readonly' => true, 'required' => true, 'selected' => true, - ); + ]; /** * Tag names used in document. @@ -254,7 +254,7 @@ class AMP_Style_Sanitizer extends AMP_Base_Sanitizer { * * @var array */ - private $processed_imported_stylesheet_urls = array(); + private $processed_imported_stylesheet_urls = []; /** * List of font stylesheets that were @import'ed which should have been <link>'ed to instead. @@ -263,14 +263,14 @@ class AMP_Style_Sanitizer extends AMP_Base_Sanitizer { * * @var array */ - private $imported_font_urls = array(); + private $imported_font_urls = []; /** * Mapping of HTML element selectors to AMP selector elements. * * @var array */ - private $selector_mappings = array(); + private $selector_mappings = []; /** * Get error codes that can be raised during parsing of CSS. @@ -281,7 +281,7 @@ class AMP_Style_Sanitizer extends AMP_Base_Sanitizer { * @return array */ public static function get_css_parser_validation_error_codes() { - return array( + return [ 'css_parse_error', 'excessive_css', self::ILLEGAL_AT_RULE_ERROR_CODE, @@ -290,7 +290,7 @@ public static function get_css_parser_validation_error_codes() { 'unrecognized_css', 'disallowed_file_extension', 'file_path_not_found', - ); + ]; } /** @@ -338,7 +338,7 @@ public static function has_required_php_css_parser() { * @param DOMDocument $dom Represents the HTML document to sanitize. * @param array $args Args. */ - public function __construct( DOMDocument $dom, array $args = array() ) { + public function __construct( DOMDocument $dom, array $args = [] ) { parent::__construct( $dom, $args ); foreach ( AMP_Allowed_Tags_Generated::get_allowed_tag( 'style' ) as $spec_rule ) { @@ -378,7 +378,7 @@ public function __construct( DOMDocument $dom, array $args = array() ) { * @return array[] Mapping CSS selectors to array of properties, or mapping of keys starting with 'stylesheet:' with value being the stylesheet. */ public function get_styles() { - return array(); + return []; } /** @@ -410,14 +410,14 @@ private function get_used_class_names() { return $this->used_class_names; } - $dynamic_class_names = array( + $dynamic_class_names = [ /* * See <https://www.ampproject.org/docs/reference/components/amp-dynamic-css-classes>. * Note that amp-referrer-* class names are handled in has_used_class_name() below. */ 'amp-viewer', - ); + ]; $classes = ' '; foreach ( $this->xpath->query( '//*/@class' ) as $class_attribute ) { @@ -480,7 +480,7 @@ private function has_used_class_name( $class_names ) { * See <https://www.ampproject.org/docs/reference/components/amp-live-list#styling>. */ if ( 'amp-active' === $class_name || 'amp-hidden' === $class_name ) { - if ( ! $this->has_used_tag_names( array( 'amp-live-list' ) ) && ! $this->has_used_tag_names( array( 'amp-user-notification' ) ) ) { + if ( ! $this->has_used_tag_names( [ 'amp-live-list' ] ) && ! $this->has_used_tag_names( [ 'amp-user-notification' ] ) ) { return false; } continue; @@ -488,7 +488,7 @@ private function has_used_class_name( $class_names ) { // Class names for amp-carousel, see <https://www.ampproject.org/docs/reference/components/amp-carousel#styling>. if ( 'amp-carousel-' === substr( $class_name, 0, 13 ) ) { - if ( ! $this->has_used_tag_names( array( 'amp-carousel' ) ) ) { + if ( ! $this->has_used_tag_names( [ 'amp-carousel' ] ) ) { return false; } continue; @@ -496,7 +496,7 @@ private function has_used_class_name( $class_names ) { // Class names for amp-date-picker, see <https://www.ampproject.org/docs/reference/components/amp-date-picker>. if ( 'amp-date-picker-' === substr( $class_name, 0, 16 ) ) { - if ( ! $this->has_used_tag_names( array( 'amp-date-picker' ) ) ) { + if ( ! $this->has_used_tag_names( [ 'amp-date-picker' ] ) ) { return false; } continue; @@ -504,7 +504,7 @@ private function has_used_class_name( $class_names ) { // Class names for amp-form, see <https://www.ampproject.org/docs/reference/components/amp-form#classes-and-css-hooks>. if ( 'amp-form-' === substr( $class_name, 0, 9 ) || 'user-valid' === $class_name || 'user-invalid' === $class_name ) { - if ( ! $this->has_used_tag_names( array( 'form' ) ) ) { + if ( ! $this->has_used_tag_names( [ 'form' ] ) ) { return false; } continue; @@ -516,7 +516,7 @@ private function has_used_class_name( $class_names ) { * See <https://www.ampproject.org/docs/reference/components/amp-access-laterpay#styling> */ if ( 'amp-access-' === substr( $class_name, 0, 11 ) ) { - if ( ! $this->has_used_attributes( array( 'amp-access' ) ) ) { + if ( ! $this->has_used_attributes( [ 'amp-access' ] ) ) { return false; } continue; @@ -524,7 +524,7 @@ private function has_used_class_name( $class_names ) { // Class names for amp-geo, see <https://www.ampproject.org/docs/reference/components/amp-geo#generated-css-classes>. if ( 'amp-geo-' === substr( $class_name, 0, 8 ) || 'amp-iso-country-' === substr( $class_name, 0, 16 ) ) { - if ( ! $this->has_used_tag_names( array( 'amp-geo' ) ) ) { + if ( ! $this->has_used_tag_names( [ 'amp-geo' ] ) ) { return false; } continue; @@ -532,7 +532,7 @@ private function has_used_class_name( $class_names ) { // Class names for amp-image-lightbox, see <https://www.ampproject.org/docs/reference/components/amp-image-lightbox#styling>. if ( 'amp-image-lightbox-caption' === $class_name ) { - if ( ! $this->has_used_tag_names( array( 'amp-image-lightbox' ) ) ) { + if ( ! $this->has_used_tag_names( [ 'amp-image-lightbox' ] ) ) { return false; } continue; @@ -540,7 +540,7 @@ private function has_used_class_name( $class_names ) { // Class names for amp-live-list, see <https://www.ampproject.org/docs/reference/components/amp-live-list#styling>. if ( 'amp-live-list-' === substr( $class_name, 0, 14 ) ) { - if ( ! $this->has_used_tag_names( array( 'amp-live-list' ) ) ) { + if ( ! $this->has_used_tag_names( [ 'amp-live-list' ] ) ) { return false; } continue; @@ -548,7 +548,7 @@ private function has_used_class_name( $class_names ) { // Class names for amp-sidebar, see <https://www.ampproject.org/docs/reference/components/amp-sidebar#styling-toolbar>. if ( 'amp-sidebar-' === substr( $class_name, 0, 12 ) ) { - if ( ! $this->has_used_tag_names( array( 'amp-sidebar' ) ) ) { + if ( ! $this->has_used_tag_names( [ 'amp-sidebar' ] ) ) { return false; } continue; @@ -556,7 +556,7 @@ private function has_used_class_name( $class_names ) { // Class names for amp-sticky-ad, see <https://www.ampproject.org/docs/reference/components/amp-sticky-ad#styling>. if ( 'amp-sticky-ad-' === substr( $class_name, 0, 14 ) ) { - if ( ! $this->has_used_tag_names( array( 'amp-sticky-ad' ) ) ) { + if ( ! $this->has_used_tag_names( [ 'amp-sticky-ad' ] ) ) { return false; } continue; @@ -564,7 +564,7 @@ private function has_used_class_name( $class_names ) { // Class names for amp-video-docking, see <https://github.com/ampproject/amphtml/blob/master/extensions/amp-video-docking/amp-video-docking.md#styling>. if ( 'amp-docked-' === substr( $class_name, 0, 11 ) ) { - if ( ! $this->has_used_attributes( array( 'dock' ) ) ) { + if ( ! $this->has_used_attributes( [ 'dock' ] ) ) { return false; } continue; @@ -586,7 +586,7 @@ private function has_used_class_name( $class_names ) { */ private function get_used_tag_names() { if ( ! isset( $this->used_tag_names ) ) { - $this->used_tag_names = array(); + $this->used_tag_names = []; foreach ( $this->dom->getElementsByTagName( '*' ) as $el ) { $this->used_tag_names[ $el->tagName ] = true; } @@ -673,7 +673,7 @@ public function init( $sanitizers ) { * @since 0.4 */ public function sanitize() { - $elements = array(); + $elements = []; // Do nothing if inline styles are allowed. if ( ! empty( $this->args['allow_dirty_styles'] ) ) { @@ -695,10 +695,10 @@ public function sanitize() { $xpath = $this->xpath; $lower_case = 'translate( %s, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz" )'; // In XPath 2.0 this is lower-case(). - $predicates = array( + $predicates = [ sprintf( '( self::style and not( @amp-boilerplate ) and ( not( @type ) or %s = "text/css" ) )', sprintf( $lower_case, '@type' ) ), sprintf( '( self::link and @href and %s = "stylesheet" )', sprintf( $lower_case, '@rel' ) ), - ); + ]; foreach ( $xpath->query( '//*[ ' . implode( ' or ', $predicates ) . ' ]' ) as $element ) { $elements[] = $element; @@ -745,7 +745,7 @@ public function sanitize() { } } - $elements = array(); + $elements = []; foreach ( $xpath->query( '//*[ @style ]' ) as $element ) { $elements[] = $element; } @@ -796,15 +796,15 @@ private function get_stylesheet_priority( DOMNode $node ) { $style_handle = $matches[1]; } - $core_frontend_handles = array( + $core_frontend_handles = [ 'wp-block-library', 'wp-block-library-theme', - ); - $non_amp_handles = array( + ]; + $non_amp_handles = [ 'mediaelement', 'wp-mediaelement', 'thickbox', - ); + ]; if ( in_array( $style_handle, $non_amp_handles, true ) ) { // Styles are for non-AMP JS only so not be used in AMP at all. @@ -939,7 +939,7 @@ private function reconstruct_url( $parsed_url ) { * @param string[] $allowed_extensions Allowed file extensions for local files. * @return string|WP_Error Style's absolute validated filesystem path, or WP_Error when error. */ - public function get_validated_url_file_path( $url, $allowed_extensions = array() ) { + public function get_validated_url_file_path( $url, $allowed_extensions = [] ) { if ( ! is_string( $url ) ) { return new WP_Error( 'url_not_string' ); } @@ -981,11 +981,11 @@ public function get_validated_url_file_path( $url, $allowed_extensions = array() $admin_url = $remove_url_scheme( get_admin_url( null, '/' ) ); $site_url = $remove_url_scheme( site_url( '/' ) ); - $allowed_hosts = array( + $allowed_hosts = [ wp_parse_url( $includes_url, PHP_URL_HOST ), wp_parse_url( $content_url, PHP_URL_HOST ), wp_parse_url( $admin_url, PHP_URL_HOST ), - ); + ]; // Validate file extensions. if ( ! empty( $allowed_extensions ) ) { @@ -1071,21 +1071,21 @@ private function process_style_element( DOMElement $element ) { $processed = $this->process_stylesheet( $stylesheet, - array( + [ 'allowed_at_rules' => $cdata_spec['css_spec']['allowed_at_rules'], 'property_whitelist' => $cdata_spec['css_spec']['declaration'], 'validate_keyframes' => $cdata_spec['css_spec']['validate_keyframes'], - ) + ] ); $this->pending_stylesheets[] = array_merge( - array( + [ 'group' => $is_keyframes ? 'keyframes' : 'custom', 'node' => $element, 'sources' => $this->current_sources, 'priority' => $this->get_stylesheet_priority( $element ), - ), - wp_array_slice_assoc( $processed, array( 'stylesheet', 'imported_font_urls' ) ) + ], + wp_array_slice_assoc( $processed, [ 'stylesheet', 'imported_font_urls' ] ) ); if ( $element->hasAttribute( 'amp-custom' ) && ! $this->amp_custom_style_element ) { @@ -1130,18 +1130,18 @@ private function process_link_element( DOMElement $element ) { $link = AMP_DOM_Utils::create_node( $this->dom, 'link', - array( + [ 'rel' => 'preconnect', 'href' => 'https://fonts.gstatic.com/', 'crossorigin' => '', - ) + ] ); $this->head->insertBefore( $link ); // Note that \AMP_Theme_Support::ensure_required_markup() will put this in the optimal order. } return; } - $css_file_path = $this->get_validated_url_file_path( $href, array( 'css', 'less', 'scss', 'sass' ) ); + $css_file_path = $this->get_validated_url_file_path( $href, [ 'css', 'less', 'scss', 'sass' ] ); if ( ! is_wp_error( $css_file_path ) ) { $stylesheet = file_get_contents( $css_file_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request. } else { @@ -1152,11 +1152,11 @@ private function process_link_element( DOMElement $element ) { } else { $this->remove_invalid_child( $element, - array( + [ 'code' => $contents->get_error_code(), 'message' => $contents->get_error_message(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ) + ] ); return; } @@ -1165,10 +1165,10 @@ private function process_link_element( DOMElement $element ) { if ( false === $stylesheet ) { $this->remove_invalid_child( $element, - array( + [ 'code' => 'stylesheet_file_missing', 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ) + ] ); return; } @@ -1183,22 +1183,22 @@ private function process_link_element( DOMElement $element ) { $processed = $this->process_stylesheet( $stylesheet, - array( + [ 'allowed_at_rules' => $this->style_custom_cdata_spec['css_spec']['allowed_at_rules'], 'property_whitelist' => $this->style_custom_cdata_spec['css_spec']['declaration'], 'stylesheet_url' => $href, 'stylesheet_path' => $css_file_path, - ) + ] ); $this->pending_stylesheets[] = array_merge( - array( + [ 'group' => 'custom', 'node' => $element, 'sources' => $this->current_sources, // Needed because node is removed below. 'priority' => $this->get_stylesheet_priority( $element ), - ), - wp_array_slice_assoc( $processed, array( 'stylesheet', 'imported_font_urls' ) ) + ], + wp_array_slice_assoc( $processed, [ 'stylesheet', 'imported_font_urls' ] ) ); // Remove now that styles have been processed. @@ -1274,7 +1274,7 @@ private function fetch_external_stylesheet( $url ) { * @type int $priority The priority of the stylesheet. * } */ - private function process_stylesheet( $stylesheet, $options = array() ) { + private function process_stylesheet( $stylesheet, $options = [] ) { $parsed = null; $cache_key = null; $cache_group = 'amp-parsed-stylesheet-v18'; // This should be bumped whenever the PHP-CSS-Parser is updated or parsed format is updated. @@ -1282,15 +1282,15 @@ private function process_stylesheet( $stylesheet, $options = array() ) { $cache_impacting_options = array_merge( wp_array_slice_assoc( $options, - array( 'property_whitelist', 'property_blacklist', 'stylesheet_url', 'allowed_at_rules' ) + [ 'property_whitelist', 'property_blacklist', 'stylesheet_url', 'allowed_at_rules' ] ), wp_array_slice_assoc( $this->args, - array( 'should_locate_sources', 'parsed_cache_variant' ) + [ 'should_locate_sources', 'parsed_cache_variant' ] ), - array( + [ 'language' => get_bloginfo( 'language' ), // Used to tree-shake html[lang] selectors. - ) + ] ); $cache_key = md5( $stylesheet . wp_json_encode( $cache_impacting_options ) ); @@ -1347,13 +1347,13 @@ private function process_stylesheet( $stylesheet, $options = array() ) { * @return array Validation results. */ private function parse_import_stylesheet( Import $item, CSSList $css_list, $options ) { - $results = array(); + $results = []; $at_rule_args = $item->atRuleArgs(); $location = array_shift( $at_rule_args ); $media_query = array_shift( $at_rule_args ); if ( isset( $options['stylesheet_url'] ) ) { - $this->real_path_urls( array( $location ), $options['stylesheet_url'] ); + $this->real_path_urls( [ $location ], $options['stylesheet_url'] ); } $import_stylesheet_url = $location->getURL()->getString(); @@ -1361,7 +1361,7 @@ private function parse_import_stylesheet( Import $item, CSSList $css_list, $opti // Prevent importing something that has already been imported, and avoid infinite recursion. if ( isset( $this->processed_imported_stylesheet_urls[ $import_stylesheet_url ] ) ) { $css_list->remove( $item ); - return array(); + return []; } $this->processed_imported_stylesheet_urls[ $import_stylesheet_url ] = true; @@ -1383,20 +1383,20 @@ private function parse_import_stylesheet( Import $item, CSSList $css_list, $opti ), '1.0' ); - return array(); + return []; } - $css_file_path = $this->get_validated_url_file_path( $import_stylesheet_url, array( 'css', 'less', 'scss', 'sass' ) ); + $css_file_path = $this->get_validated_url_file_path( $import_stylesheet_url, [ 'css', 'less', 'scss', 'sass' ] ); if ( is_wp_error( $css_file_path ) && ( 'disallowed_file_extension' === $css_file_path->get_error_code() || 'external_file_url' === $css_file_path->get_error_code() ) ) { $contents = $this->fetch_external_stylesheet( $import_stylesheet_url ); if ( is_wp_error( $contents ) ) { - $error = array( + $error = [ 'code' => $contents->get_error_code(), 'message' => $contents->get_error_message(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, 'url' => $import_stylesheet_url, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); if ( $sanitized ) { $css_list->remove( $item ); @@ -1407,12 +1407,12 @@ private function parse_import_stylesheet( Import $item, CSSList $css_list, $opti $stylesheet = $contents; } elseif ( is_wp_error( $css_file_path ) ) { - $error = array( + $error = [ 'code' => $css_file_path->get_error_code(), 'message' => $css_file_path->get_error_message(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, 'url' => $import_stylesheet_url, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); if ( $sanitized ) { $css_list->remove( $item ); @@ -1471,10 +1471,10 @@ private function parse_import_stylesheet( Import $item, CSSList $css_list, $opti * } */ private function parse_stylesheet( $stylesheet_string, $options ) { - $validation_results = array(); + $validation_results = []; $css_document = null; - $this->imported_font_urls = array(); + $this->imported_font_urls = []; try { // Remove spaces from data URLs, which cause errors and PHP-CSS-Parser can't handle them. $stylesheet_string = $this->remove_spaces_from_data_urls( $stylesheet_string ); @@ -1500,11 +1500,11 @@ static function ( $value ) { $this->process_css_list( $css_document, $options ) ); } catch ( Exception $exception ) { - $error = array( + $error = [ 'code' => 'css_parse_error', 'message' => $exception->getMessage(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; /* * This is not a recoverable error, so sanitized here is just used to give user control @@ -1516,9 +1516,9 @@ static function ( $value ) { } return array_merge( compact( 'validation_results', 'css_document' ), - array( + [ 'imported_font_urls' => $this->imported_font_urls, - ) + ] ); } @@ -1537,22 +1537,22 @@ static function ( $value ) { * @type array $imported_font_urls Imported font stylesheet URLs. * } */ - private function prepare_stylesheet( $stylesheet_string, $options = array() ) { + private function prepare_stylesheet( $stylesheet_string, $options = [] ) { $start_time = microtime( true ); $options = array_merge( - array( - 'allowed_at_rules' => array(), - 'property_blacklist' => array( + [ + 'allowed_at_rules' => [], + 'property_blacklist' => [ // See <https://www.ampproject.org/docs/design/responsive/style_pages#disallowed-styles>. 'behavior', '-moz-binding', - ), - 'property_whitelist' => array(), + ], + 'property_whitelist' => [], 'validate_keyframes' => false, 'stylesheet_url' => null, 'stylesheet_path' => null, - ), + ], $options ); @@ -1565,7 +1565,7 @@ private function prepare_stylesheet( $stylesheet_string, $options = array() ) { $stylesheet_string = preg_replace( '#\]\]>\s*$#', '', $stylesheet_string ); $stylesheet_string = preg_replace( '#-->\s*$#', '', $stylesheet_string ); - $stylesheet = array(); + $stylesheet = []; $parsed_stylesheet = $this->parse_stylesheet( $stylesheet_string, $options ); $validation_results = $parsed_stylesheet['validation_results']; if ( ! empty( $parsed_stylesheet['css_document'] ) ) { @@ -1633,9 +1633,9 @@ static function( $selector ) { $declaration = $split_stylesheet[ ++$i ]; // @todo The following logic could be made much more robust if PHP-CSS-Parser did parsing of selectors. See <https://github.com/sabberworm/PHP-CSS-Parser/pull/138#issuecomment-418193262> and <https://github.com/ampproject/amp-wp/issues/2102>. - $selectors_parsed = array(); + $selectors_parsed = []; foreach ( $selectors as $selector ) { - $selectors_parsed[ $selector ] = array(); + $selectors_parsed[ $selector ] = []; // Remove :not() and pseudo selectors to eliminate false negatives, such as with `body:not(.title-tagline-hidden) .site-branding-text` (but not after escape character). $reduced_selector = preg_replace( '/(?<!\\\\)::?[a-zA-Z0-9_-]+(\(.+?\))?/', '', $selector ); @@ -1692,10 +1692,10 @@ static function( $matches ) use ( $selector, &$selectors_parsed ) { unset( $reduced_selector ); } - $stylesheet[] = array( + $stylesheet[] = [ $selectors_parsed, $declaration, - ); + ]; } else { $stylesheet[] = $split_stylesheet[ $i ]; } @@ -1706,9 +1706,9 @@ static function( $matches ) use ( $selector, &$selectors_parsed ) { return array_merge( compact( 'stylesheet', 'validation_results' ), - array( + [ 'imported_font_urls' => $parsed_stylesheet['imported_font_urls'], - ) + ] ); } @@ -1721,7 +1721,7 @@ static function( $matches ) use ( $selector, &$selectors_parsed ) { * @see AMP_Style_Sanitizer::should_sanitize_validation_error() * @var array */ - protected $previous_should_sanitize_validation_error_results = array(); + protected $previous_should_sanitize_validation_error_results = []; /** * Check whether or not sanitization should occur in response to validation error. @@ -1734,7 +1734,7 @@ static function( $matches ) use ( $selector, &$selectors_parsed ) { * @param array $data Data including the node. * @return bool Whether to sanitize. */ - public function should_sanitize_validation_error( $validation_error, $data = array() ) { + public function should_sanitize_validation_error( $validation_error, $data = [] ) { if ( ! isset( $data['node'] ) ) { $data['node'] = $this->current_node; } @@ -1787,7 +1787,7 @@ static function( $matches ) { * @return array Validation errors. */ private function process_css_list( CSSList $css_list, $options ) { - $results = array(); + $results = []; foreach ( $css_list->getContents() as $css_item ) { $sanitized = false; @@ -1798,11 +1798,11 @@ private function process_css_list( CSSList $css_list, $options ) { ); } elseif ( $css_item instanceof AtRuleBlockList ) { if ( ! in_array( $css_item->atRuleName(), $options['allowed_at_rules'], true ) ) { - $error = array( + $error = [ 'code' => self::ILLEGAL_AT_RULE_ERROR_CODE, 'at_rule' => $css_item->atRuleName(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); $results[] = compact( 'error', 'sanitized' ); } @@ -1819,11 +1819,11 @@ private function process_css_list( CSSList $css_list, $options ) { ); } elseif ( $css_item instanceof AtRuleSet ) { if ( ! in_array( $css_item->atRuleName(), $options['allowed_at_rules'], true ) ) { - $error = array( + $error = [ 'code' => self::ILLEGAL_AT_RULE_ERROR_CODE, 'at_rule' => $css_item->atRuleName(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); $results[] = compact( 'error', 'sanitized' ); } @@ -1836,11 +1836,11 @@ private function process_css_list( CSSList $css_list, $options ) { } } elseif ( $css_item instanceof KeyFrame ) { if ( ! in_array( 'keyframes', $options['allowed_at_rules'], true ) ) { - $error = array( + $error = [ 'code' => self::ILLEGAL_AT_RULE_ERROR_CODE, 'at_rule' => $css_item->atRuleName(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); $results[] = compact( 'error', 'sanitized' ); } @@ -1861,20 +1861,20 @@ private function process_css_list( CSSList $css_list, $options ) { */ $sanitized = true; } else { - $error = array( + $error = [ 'code' => self::ILLEGAL_AT_RULE_ERROR_CODE, 'at_rule' => $css_item->atRuleName(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); $results[] = compact( 'error', 'sanitized' ); } } else { - $error = array( + $error = [ 'code' => 'unrecognized_css', 'item' => get_class( $css_item ), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); $results[] = compact( 'error', 'sanitized' ); } @@ -1942,7 +1942,7 @@ private function real_path_urls( $urls, $stylesheet_url ) { * @return array Validation results. */ private function process_css_declaration_block( RuleSet $ruleset, CSSList $css_list, $options ) { - $results = array(); + $results = []; if ( $ruleset instanceof DeclarationBlock ) { $this->ampify_ruleset_selectors( $ruleset ); @@ -1958,12 +1958,12 @@ private function process_css_declaration_block( RuleSet $ruleset, CSSList $css_l foreach ( $properties as $property ) { $vendorless_property_name = preg_replace( '/^-\w+-/', '', $property->getRule() ); if ( ! in_array( $vendorless_property_name, $options['property_whitelist'], true ) ) { - $error = array( + $error = [ 'code' => 'illegal_css_property', 'property_name' => $property->getRule(), 'property_value' => $property->getValue(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); if ( $sanitized ) { $ruleset->removeRule( $property->getRule() ); @@ -1975,12 +1975,12 @@ private function process_css_declaration_block( RuleSet $ruleset, CSSList $css_l foreach ( $options['property_blacklist'] as $illegal_property_name ) { $properties = $ruleset->getRules( $illegal_property_name ); foreach ( $properties as $property ) { - $error = array( + $error = [ 'code' => 'illegal_css_property', 'property_name' => $property->getRule(), 'property_value' => (string) $property->getValue(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); if ( $sanitized ) { $ruleset->removeRule( $property->getRule() ); @@ -2071,23 +2071,23 @@ private function process_font_face_at_rule( AtRuleSet $ruleset, $options ) { * * Clearly the components here are not logically grouped. So the first step is to fix the order. */ - $sources = array(); + $sources = []; foreach ( $value->getListComponents() as $component ) { if ( $component instanceof RuleValueList ) { $subcomponents = $component->getListComponents(); $subcomponent = array_shift( $subcomponents ); if ( $subcomponent ) { if ( empty( $sources ) ) { - $sources[] = array( $subcomponent ); + $sources[] = [ $subcomponent ]; } else { $sources[ count( $sources ) - 1 ][] = $subcomponent; } } foreach ( $subcomponents as $subcomponent ) { - $sources[] = array( $subcomponent ); + $sources[] = [ $subcomponent ]; } } elseif ( empty( $sources ) ) { - $sources[] = array( $component ); + $sources[] = [ $component ]; } else { $sources[ count( $sources ) - 1 ][] = $component; } @@ -2099,8 +2099,8 @@ private function process_font_face_at_rule( AtRuleSet $ruleset, $options ) { * @var string[] $source_file_urls * @var URL[] $source_data_url_objects */ - $source_file_urls = array(); - $source_data_url_objects = array(); + $source_file_urls = []; + $source_data_url_objects = []; foreach ( $sources as $i => $source ) { if ( $source[0] instanceof URL ) { $value = $source[0]->getURL()->getString(); @@ -2120,7 +2120,7 @@ private function process_font_face_at_rule( AtRuleSet $ruleset, $options ) { } $extension = preg_replace( ':.+/(.+-)?:', '', $mime_type ); - $guessed_urls = array(); + $guessed_urls = []; // Guess URLs based on any other font sources that are not using data: URLs (e.g. truetype fallback for inline woff2). foreach ( $source_file_urls as $source_file_url ) { @@ -2147,7 +2147,7 @@ private function process_font_face_at_rule( AtRuleSet $ruleset, $options ) { // Find the font file that exists, and then replace the data: URL with the external URL for the font. foreach ( $guessed_urls as $guessed_url ) { - $path = $this->get_validated_url_file_path( $guessed_url, array( 'woff', 'woff2', 'ttf', 'otf', 'svg' ) ); + $path = $this->get_validated_url_file_path( $guessed_url, [ 'woff', 'woff2', 'ttf', 'otf', 'svg' ] ); if ( ! is_wp_error( $path ) ) { $data_url->getURL()->setString( $guessed_url ); $converted_count++; @@ -2183,15 +2183,15 @@ private function process_font_face_at_rule( AtRuleSet $ruleset, $options ) { * @return array Validation results. */ private function process_css_keyframes( KeyFrame $css_list, $options ) { - $results = array(); + $results = []; if ( ! empty( $options['property_whitelist'] ) ) { foreach ( $css_list->getContents() as $rules ) { if ( ! ( $rules instanceof DeclarationBlock ) ) { - $error = array( + $error = [ 'code' => 'unrecognized_css', 'item' => get_class( $rules ), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); if ( $sanitized ) { $css_list->remove( $rules ); @@ -2209,12 +2209,12 @@ private function process_css_keyframes( KeyFrame $css_list, $options ) { foreach ( $properties as $property ) { $vendorless_property_name = preg_replace( '/^-\w+-/', '', $property->getRule() ); if ( ! in_array( $vendorless_property_name, $options['property_whitelist'], true ) ) { - $error = array( + $error = [ 'code' => 'illegal_css_property', 'property_name' => $property->getRule(), 'property_value' => (string) $property->getValue(), 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); if ( $sanitized ) { $rules->removeRule( $property->getRule() ); @@ -2239,7 +2239,7 @@ private function process_css_keyframes( KeyFrame $css_list, $options ) { * @return array Validation results. */ private function transform_important_qualifiers( RuleSet $ruleset, CSSList $css_list ) { - $results = array(); + $results = []; // An !important only makes sense for rulesets that have selectors. $allow_transformation = ( @@ -2249,7 +2249,7 @@ private function transform_important_qualifiers( RuleSet $ruleset, CSSList $css_ ); $properties = $ruleset->getRules(); - $importants = array(); + $importants = []; foreach ( $properties as $property ) { if ( $property->getIsImportant() ) { if ( $allow_transformation ) { @@ -2257,10 +2257,10 @@ private function transform_important_qualifiers( RuleSet $ruleset, CSSList $css_ $property->setIsImportant( false ); $ruleset->removeRule( $property->getRule() ); } else { - $error = array( + $error = [ 'code' => 'illegal_css_important', 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; $sanitized = $this->should_sanitize_validation_error( $error ); if ( $sanitized ) { $property->setIsImportant( false ); @@ -2312,7 +2312,7 @@ static function( Selector $old_selector ) { $i = array_search( $ruleset, $css_list->getContents(), true ); if ( false !== $i && method_exists( $css_list, 'splice' ) ) { - $css_list->splice( $i + 1, 0, array( $important_ruleset ) ); + $css_list->splice( $i + 1, 0, [ $important_ruleset ] ); } else { $css_list->append( $important_ruleset ); } @@ -2348,22 +2348,22 @@ private function collect_inline_styles( $element ) { $processed = $this->process_stylesheet( $rule, - array( - 'allowed_at_rules' => array(), + [ + 'allowed_at_rules' => [], 'property_whitelist' => $this->style_custom_cdata_spec['css_spec']['declaration'], - ) + ] ); $element->removeAttribute( 'style' ); if ( $processed['stylesheet'] ) { - $this->pending_stylesheets[] = array( + $this->pending_stylesheets[] = [ 'group' => 'custom', 'stylesheet' => $processed['stylesheet'], 'node' => $element, 'sources' => $this->current_sources, 'priority' => $this->get_stylesheet_priority( $style_attribute ), - ); + ]; if ( $element->hasAttribute( 'class' ) ) { $element->setAttribute( 'class', $element->getAttribute( 'class' ) . ' ' . $class ); @@ -2385,24 +2385,24 @@ private function collect_inline_styles( $element ) { * @see https://www.ampproject.org/docs/fundamentals/spec#keyframes-stylesheet */ private function finalize_styles() { - $stylesheet_groups = array( - 'custom' => array( + $stylesheet_groups = [ + 'custom' => [ 'source_map_comment' => "\n\n/*# sourceURL=amp-custom.css */", 'cdata_spec' => $this->style_custom_cdata_spec, - 'pending_stylesheets' => array(), + 'pending_stylesheets' => [], 'included_count' => 0, 'import_front_matter' => '', // Extra @import statements that are prepended when fetch fails and validation error is rejected. - ), - 'keyframes' => array( + ], + 'keyframes' => [ 'source_map_comment' => "\n\n/*# sourceURL=amp-keyframes.css */", 'cdata_spec' => $this->style_keyframes_cdata_spec, - 'pending_stylesheets' => array(), + 'pending_stylesheets' => [], 'included_count' => 0, 'import_front_matter' => '', - ), - ); + ], + ]; - $imported_font_urls = array(); + $imported_font_urls = []; // Divide pending stylesheet between custom and keyframes, and calculate size of each (before tree shaking). foreach ( $this->pending_stylesheets as $i => $pending_stylesheet ) { @@ -2462,7 +2462,7 @@ private function finalize_styles() { $included_original_size = 0; $excluded_size = 0; $excluded_original_size = 0; - $included_sources = array(); + $included_sources = []; foreach ( $this->pending_stylesheets as $j => $pending_stylesheet ) { if ( 'custom' !== $pending_stylesheet['group'] || ! ( $pending_stylesheet['node'] instanceof DOMElement ) || ! empty( $pending_stylesheet['duplicate'] ) ) { continue; @@ -2597,10 +2597,10 @@ private function finalize_styles() { $body = $this->dom->getElementsByTagName( 'body' )->item( 0 ); if ( ! $body ) { $this->should_sanitize_validation_error( - array( + [ 'code' => 'missing_body_element', 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ) + ] ); } else { $css = $stylesheet_groups['keyframes']['import_front_matter']; @@ -2692,7 +2692,7 @@ private function remove_admin_bar_if_css_excluded() { * @param DeclarationBlock $ruleset Ruleset. */ private function ampify_ruleset_selectors( $ruleset ) { - $selectors = array(); + $selectors = []; $changes = 0; $language = strtolower( get_bloginfo( 'language' ) ); foreach ( $ruleset->getSelectors() as $old_selector ) { @@ -2759,7 +2759,7 @@ static function ( $selector_language ) { $before_type_selector_pattern = '(?<=^|\(|\s|>|\+|~|,|})'; $after_type_selector_pattern = '(?=$|[^a-zA-Z0-9_-])'; - $edited_selectors = array( $selector ); + $edited_selectors = [ $selector ]; foreach ( $this->selector_mappings as $html_selector => $amp_selectors ) { // Note: The $selector_mappings array contains ~6 items. $html_pattern = '/' . $before_type_selector_pattern . preg_quote( $html_selector, '/' ) . $after_type_selector_pattern . '/i'; foreach ( $edited_selectors as &$edited_selector ) { // Note: The $edited_selectors array contains only item in the normal case. @@ -2804,8 +2804,8 @@ private function finalize_stylesheet_group( $group, $group_config ) { $included_count = 0; $max_bytes = $group_config['cdata_spec']['max_bytes'] - strlen( $group_config['source_map_comment'] ); - $previously_seen_stylesheet_index = array(); - $indices_by_stylesheet_element_id = array(); + $previously_seen_stylesheet_index = []; + $indices_by_stylesheet_element_id = []; foreach ( $this->pending_stylesheets as $pending_stylesheet_index => &$pending_stylesheet ) { if ( $group !== $pending_stylesheet['group'] ) { continue; @@ -2816,7 +2816,7 @@ private function finalize_stylesheet_group( $group, $group_config ) { $indices_by_stylesheet_element_id[ $pending_stylesheet['node']->getAttribute( 'id' ) ] = $pending_stylesheet_index; } - $stylesheet_parts = array(); + $stylesheet_parts = []; $original_size = 0; foreach ( $pending_stylesheet['stylesheet'] as $stylesheet_part ) { if ( is_string( $stylesheet_part ) ) { @@ -2827,7 +2827,7 @@ private function finalize_stylesheet_group( $group, $group_config ) { list( $selectors_parsed, $declaration_block ) = $stylesheet_part; - $selectors = array(); + $selectors = []; foreach ( $selectors_parsed as $selector => $parsed_selector ) { $should_include = ( // If all class names are used in the doc. @@ -2963,15 +2963,15 @@ function( $a, $b ) { // Report validation error if size is now too big. if ( $current_concatenated_size + $this->pending_stylesheets[ $i ]['size'] > $max_bytes ) { - $validation_error = array( + $validation_error = [ 'code' => 'excessive_css', 'type' => AMP_Validation_Error_Taxonomy::CSS_ERROR_TYPE, - ); + ]; if ( isset( $this->pending_stylesheets[ $i ]['sources'] ) ) { $validation_error['sources'] = $this->pending_stylesheets[ $i ]['sources']; } - if ( $this->should_sanitize_validation_error( $validation_error, wp_array_slice_assoc( $this->pending_stylesheets[ $i ], array( 'node' ) ) ) ) { + if ( $this->should_sanitize_validation_error( $validation_error, wp_array_slice_assoc( $this->pending_stylesheets[ $i ], [ 'node' ] ) ) ) { $this->pending_stylesheets[ $i ]['included'] = false; continue; // Skip to the next stylesheet. } @@ -2998,7 +2998,7 @@ function( $a, $b ) { private function exclude_all_admin_bar_css_if_excessive( $indices_by_stylesheet_element_id ) { $excluded_count = 0; - $admin_bar_style_element_ids = array( 'admin-bar-css', 'admin-bar-inline-css' ); + $admin_bar_style_element_ids = [ 'admin-bar-css', 'admin-bar-inline-css' ]; $should_exclude_admin_bar_inline_css = false; foreach ( $admin_bar_style_element_ids as $admin_bar_style_element_id ) { if ( ! isset( $indices_by_stylesheet_element_id[ $admin_bar_style_element_id ] ) ) { diff --git a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php index 2bc6f208a02..ada07196abb 100644 --- a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php +++ b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php @@ -58,14 +58,14 @@ class AMP_Tag_And_Attribute_Sanitizer extends AMP_Base_Sanitizer { * @since 0.7 * @var array */ - protected $rev_alternate_attr_name_lookup = array(); + protected $rev_alternate_attr_name_lookup = []; /** * Mapping of JSON-serialized tag spec to the number of instances encountered in the document. * * @var array */ - protected $visited_unique_tag_specs = array(); + protected $visited_unique_tag_specs = []; /** * Stack. @@ -74,7 +74,7 @@ class AMP_Tag_And_Attribute_Sanitizer extends AMP_Base_Sanitizer { * * @var DOMElement[] */ - private $stack = array(); + private $stack = []; /** * Default args. @@ -83,21 +83,21 @@ class AMP_Tag_And_Attribute_Sanitizer extends AMP_Base_Sanitizer { * * @var array */ - protected $DEFAULT_ARGS = array(); + protected $DEFAULT_ARGS = []; /** * AMP script components that are discovered being required through sanitization. * * @var string[] */ - protected $script_components = array(); + protected $script_components = []; /** * Keep track of nodes that should not be replaced to prevent duplicated validation errors since sanitization is rejected. * * @var array */ - protected $should_not_replace_nodes = array(); + protected $should_not_replace_nodes = []; /** * AMP_Tag_And_Attribute_Sanitizer constructor. @@ -107,73 +107,73 @@ class AMP_Tag_And_Attribute_Sanitizer extends AMP_Base_Sanitizer { * @param DOMDocument $dom DOM. * @param array $args Args. */ - public function __construct( $dom, $args = array() ) { - $this->DEFAULT_ARGS = array( + public function __construct( $dom, $args = [] ) { + $this->DEFAULT_ARGS = [ 'amp_allowed_tags' => AMP_Allowed_Tags_Generated::get_allowed_tags(), 'amp_globally_allowed_attributes' => AMP_Allowed_Tags_Generated::get_allowed_attributes(), 'amp_layout_allowed_attributes' => AMP_Allowed_Tags_Generated::get_layout_attributes(), 'amp_bind_placeholder_prefix' => AMP_DOM_Utils::get_amp_bind_placeholder_prefix(), - ); + ]; parent::__construct( $dom, $args ); if ( ! empty( $this->args['allow_dirty_styles'] ) ) { // Allow style attribute on all elements. - $this->args['amp_globally_allowed_attributes']['style'] = array(); + $this->args['amp_globally_allowed_attributes']['style'] = []; // Allow style elements. - $this->args['amp_allowed_tags']['style'][] = array( - 'attr_spec_list' => array( - 'type' => array( + $this->args['amp_allowed_tags']['style'][] = [ + 'attr_spec_list' => [ + 'type' => [ 'value_casei' => 'text/css', - ), - ), - 'cdata' => array(), - 'tag_spec' => array( + ], + ], + 'cdata' => [], + 'tag_spec' => [ 'spec_name' => 'style for Customizer preview', - ), - ); + ], + ]; // Allow stylesheet links. - $this->args['amp_allowed_tags']['link'][] = array( - 'attr_spec_list' => array( - 'async' => array(), - 'crossorigin' => array(), - 'href' => array( + $this->args['amp_allowed_tags']['link'][] = [ + 'attr_spec_list' => [ + 'async' => [], + 'crossorigin' => [], + 'href' => [ 'mandatory' => true, - ), - 'integrity' => array(), - 'media' => array(), - 'rel' => array( + ], + 'integrity' => [], + 'media' => [], + 'rel' => [ 'dispatch_key' => 2, 'mandatory' => true, 'value_casei' => 'stylesheet', - ), - 'type' => array( + ], + 'type' => [ 'value_casei' => 'text/css', - ), - ), - 'tag_spec' => array( + ], + ], + 'tag_spec' => [ 'spec_name' => 'link rel=stylesheet for Customizer preview', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet - ), - ); + ], + ]; } // Allow scripts if requested. if ( ! empty( $this->args['allow_dirty_scripts'] ) ) { - $this->args['amp_allowed_tags']['script'][] = array( - 'attr_spec_list' => array( - 'type' => array(), - 'src' => array(), - 'async' => array(), - 'defer' => array(), - ), - 'cdata' => array(), - 'tag_spec' => array( + $this->args['amp_allowed_tags']['script'][] = [ + 'attr_spec_list' => [ + 'type' => [], + 'src' => [], + 'async' => [], + 'defer' => [], + ], + 'cdata' => [], + 'tag_spec' => [ 'spec_name' => 'scripts for Customizer preview', - ), - ); + ], + ]; } // Prepare whitelists. @@ -238,7 +238,7 @@ private function process_alternate_names( $attr_spec_list ) { if ( '[' === $attr_name[0] ) { $placeholder_attr_name = $this->args['amp_bind_placeholder_prefix'] . trim( $attr_name, '[]' ); if ( ! isset( $attr_spec[ AMP_Rule_Spec::ALTERNATIVE_NAMES ] ) ) { - $attr_spec[ AMP_Rule_Spec::ALTERNATIVE_NAMES ] = array(); + $attr_spec[ AMP_Rule_Spec::ALTERNATIVE_NAMES ] = []; } $attr_spec[ AMP_Rule_Spec::ALTERNATIVE_NAMES ][] = $placeholder_attr_name; } @@ -306,29 +306,29 @@ private function get_rule_spec_list_to_validate( $node, $rule_spec ) { $extension_spec = $rule_spec[ AMP_Rule_Spec::TAG_SPEC ]['extension_spec']; $custom_attr = 'amp-mustache' === $extension_spec['name'] ? 'custom-template' : 'custom-element'; - $rule_spec[ AMP_Rule_Spec::ATTR_SPEC_LIST ][ $custom_attr ] = array( + $rule_spec[ AMP_Rule_Spec::ATTR_SPEC_LIST ][ $custom_attr ] = [ AMP_Rule_Spec::VALUE => $extension_spec['name'], AMP_Rule_Spec::MANDATORY => true, - ); + ]; $versions = array_unique( array_merge( - isset( $extension_spec['allowed_versions'] ) ? $extension_spec['allowed_versions'] : array(), - isset( $extension_spec['version'] ) ? $extension_spec['version'] : array() + isset( $extension_spec['allowed_versions'] ) ? $extension_spec['allowed_versions'] : [], + isset( $extension_spec['version'] ) ? $extension_spec['version'] : [] ) ); - $rule_spec[ AMP_Rule_Spec::ATTR_SPEC_LIST ]['src'] = array( + $rule_spec[ AMP_Rule_Spec::ATTR_SPEC_LIST ]['src'] = [ AMP_Rule_Spec::VALUE_REGEX => implode( '', - array( + [ '^', preg_quote( 'https://cdn.ampproject.org/v0/' . $extension_spec['name'] . '-' ), // phpcs:ignore WordPress.PHP.PregQuoteDelimiter.Missing '(' . implode( '|', $versions ) . ')', '\.js$', - ) + ] ), - ); + ]; } // Augment the attribute list according to the parent's reference points, if it has them. @@ -403,8 +403,8 @@ private function process_node( $node ) { * Compile a list of rule_specs to validate for this node * based on tag name of the node. */ - $rule_spec_list_to_validate = array(); - $rule_spec_list = array(); + $rule_spec_list_to_validate = []; + $rule_spec_list = []; if ( isset( $this->allowed_tags[ $node->nodeName ] ) ) { $rule_spec_list = $this->allowed_tags[ $node->nodeName ]; } @@ -421,9 +421,9 @@ private function process_node( $node ) { } // The remaining validations all have to do with attributes. - $attr_spec_list = array(); - $tag_spec = array(); - $cdata = array(); + $attr_spec_list = []; + $tag_spec = []; + $cdata = []; /* * If we have exactly one rule_spec, use it's attr_spec_list @@ -447,7 +447,7 @@ private function process_node( $node ) { * Get a score from each attr_spec_list by seeing how many * attributes and values match the node. */ - $attr_spec_scores = array(); + $attr_spec_scores = []; foreach ( $rule_spec_list_to_validate as $spec_id => $rule_spec ) { $attr_spec_scores[ $spec_id ] = $this->validate_attr_spec_list_for_node( $node, $rule_spec[ AMP_Rule_Spec::ATTR_SPEC_LIST ] ); } @@ -532,7 +532,7 @@ private function process_node( $node ) { if ( ! empty( $this->visited_unique_tag_specs[ $node->nodeName ][ $tag_spec_key ] ) ) { $removed = $this->remove_invalid_child( $node, - array( 'code' => 'duplicate_element' ) + [ 'code' => 'duplicate_element' ] ); } $this->visited_unique_tag_specs[ $node->nodeName ][ $tag_spec_key ] = true; @@ -559,9 +559,9 @@ private function process_node( $node ) { * Capture all element attributes up front so that differing validation errors result when * one invalid attribute is accepted but the others are still rejected. */ - $validation_error = array( - 'element_attributes' => array(), - ); + $validation_error = [ + 'element_attributes' => [], + ]; foreach ( $node->attributes as $attribute ) { $validation_error['element_attributes'][ $attribute->nodeName ] = $attribute->nodeValue; } @@ -956,7 +956,7 @@ private function get_disallowed_attributes_in_node( $node, $attr_spec_list ) { * If $node is only a DOMNode and not a DOMElement we can't * remove an attribute from it anyway. So bail out now. */ - return array(); + return []; } /* @@ -964,7 +964,7 @@ private function get_disallowed_attributes_in_node( $node, $attr_spec_list ) { * breaking the iteration. So we keep track of the attributes to * remove in the first loop, then remove them in the second loop. */ - $attrs_to_remove = array(); + $attrs_to_remove = []; foreach ( $node->attributes as $attr_name => $attr_node ) { if ( ! $this->is_amp_allowed_attribute( $attr_node, $attr_spec_list ) ) { $attrs_to_remove[] = $attr_node; @@ -1015,7 +1015,7 @@ private function sanitize_disallowed_attribute_values_in_node( $node, $attr_spec * @return DOMAttr[]|false Attributes to remove, or false if the element itself should be removed. */ private function delegated_sanitize_disallowed_attribute_values_in_node( $node, $attr_spec_list, $attributes_pending_removal ) { - $attrs_to_remove = array(); + $attrs_to_remove = []; foreach ( $attr_spec_list as $attr_name => $attr_val ) { if ( isset( $attr_spec_list[ $attr_name ][ AMP_Rule_Spec::ALTERNATIVE_NAMES ] ) ) { @@ -1440,7 +1440,7 @@ static function ( $srcset_part ) { ); } - return array( $attribute_node->nodeValue ); + return [ $attribute_node->nodeValue ]; } /** @@ -1607,7 +1607,7 @@ private function check_attr_spec_rule_blacklisted_value_regex( $node, $attr_name */ private function check_attr_spec_rule_value_properties( $node, $attr_name, $attr_spec_rule ) { if ( isset( $attr_spec_rule[ AMP_Rule_Spec::VALUE_PROPERTIES ] ) && $node->hasAttribute( $attr_name ) ) { - $properties = array(); + $properties = []; foreach ( explode( ',', $node->getAttribute( $attr_name ) ) as $pair ) { $pair_parts = explode( '=', $pair, 2 ); if ( 2 !== count( $pair_parts ) ) { @@ -1668,7 +1668,7 @@ private function is_amp_allowed_attribute( $attr_node, $attr_spec_list ) { 'data-' === substr( $attr_name, 0, 5 ) || // Allow the 'amp' or '⚡' attribute in <html>, like <html ⚡>. - ( 'html' === $attr_node->parentNode->nodeName && in_array( $attr_node->nodeName, array( 'amp', '⚡' ), true ) ) + ( 'html' === $attr_node->parentNode->nodeName && in_array( $attr_node->nodeName, [ 'amp', '⚡' ], true ) ) ) { return true; } @@ -1686,10 +1686,10 @@ private function is_amp_allowed_attribute( $attr_node, $attr_spec_list ) { * unique reference point, see: * https://github.com/ampproject/amphtml/blob/1526498116488/extensions/amp-selector/validator-amp-selector.protoascii#L81-L91 */ - $descendant_reference_points = array( + $descendant_reference_points = [ 'amp-selector' => AMP_Allowed_Tags_Generated::get_reference_point_spec( 'AMP-SELECTOR option' ), 'amp-story-grid-layer' => AMP_Allowed_Tags_Generated::get_reference_point_spec( 'AMP-STORY-GRID-LAYER default' ), // @todo Consider the more restrictive 'AMP-STORY-GRID-LAYER animate-in'. - ); + ]; foreach ( $descendant_reference_points as $ancestor_name => $reference_point_spec ) { if ( isset( $reference_point_spec[ AMP_Rule_Spec::ATTR_SPEC_LIST ][ $attr_name ] ) ) { $parent = $attr_node->parentNode; @@ -1786,12 +1786,12 @@ private function has_ancestor( $node, $ancestor_tag_name ) { * @return array Tag name and attributes. */ private function parse_tag_and_attributes_from_spec_name( $spec_name ) { - static $parsed_specs = array(); + static $parsed_specs = []; if ( isset( $parsed_specs[ $spec_name ] ) ) { return $parsed_specs[ $spec_name ]; } - $attributes = array(); + $attributes = []; /* * This matches spec names like: @@ -1832,7 +1832,7 @@ private function remove_disallowed_descendants( $node, $allowed_descendants ) { return; } - $child_elements = array(); + $child_elements = []; for ( $i = 0; $i < $node->childNodes->length; $i++ ) { $child = $node->childNodes->item( $i ); if ( $child instanceof DOMElement ) { @@ -1864,7 +1864,7 @@ private function remove_disallowed_descendants( $node, $allowed_descendants ) { * @return bool Whether the element satisfies the requirements, or else it should be removed. */ private function check_valid_children( $node, $child_tags ) { - $child_elements = array(); + $child_elements = []; for ( $i = 0; $i < $node->childNodes->length; $i++ ) { $child = $node->childNodes->item( $i ); if ( $child instanceof DOMElement ) { @@ -1977,7 +1977,7 @@ private function replace_node_with_children( $node ) { } // Replace node with fragment. - $should_replace = $this->should_sanitize_validation_error( array(), compact( 'node' ) ); + $should_replace = $this->should_sanitize_validation_error( [], compact( 'node' ) ); if ( $should_replace ) { $node->parentNode->replaceChild( $fragment, $node ); } else { diff --git a/includes/sanitizers/class-amp-video-sanitizer.php b/includes/sanitizers/class-amp-video-sanitizer.php index 60aaabe629c..6e334885596 100644 --- a/includes/sanitizers/class-amp-video-sanitizer.php +++ b/includes/sanitizers/class-amp-video-sanitizer.php @@ -29,9 +29,9 @@ class AMP_Video_Sanitizer extends AMP_Base_Sanitizer { * * @var array */ - protected $DEFAULT_ARGS = array( + protected $DEFAULT_ARGS = [ 'add_noscript_fallback' => true, - ); + ]; /** * Get mapping of HTML selectors to the AMP component selectors which they may be converted into. @@ -39,9 +39,9 @@ class AMP_Video_Sanitizer extends AMP_Base_Sanitizer { * @return array Mapping. */ public function get_selector_conversion_mapping() { - return array( - 'video' => array( 'amp-video', 'amp-youtube' ), - ); + return [ + 'video' => [ 'amp-video', 'amp-youtube' ], + ]; } /** @@ -78,7 +78,7 @@ public function sanitize() { $old_attributes = AMP_DOM_Utils::get_node_attributes_as_assoc_array( $node ); $old_attributes = $this->filter_data_amp_attributes( $old_attributes, $amp_data ); - $sources = array(); + $sources = []; $new_attributes = $this->filter_attributes( $old_attributes ); $layout = isset( $amp_data['layout'] ) ? $amp_data['layout'] : false; if ( isset( $new_attributes['src'] ) ) { @@ -97,7 +97,7 @@ public function sanitize() { // Gather all child nodes and supply empty video dimensions from sources. $fallback = null; - $child_nodes = array(); + $child_nodes = []; while ( $node->firstChild ) { $child_node = $node->removeChild( $node->firstChild ); if ( $child_node instanceof DOMElement && 'source' === $child_node->nodeName && $child_node->hasAttribute( 'src' ) ) { @@ -147,7 +147,7 @@ public function sanitize() { } // Make sure the updated src and poster are applied to the original. - foreach ( array( 'src', 'poster', 'artwork' ) as $attr_name ) { + foreach ( [ 'src', 'poster', 'artwork' ] as $attr_name ) { if ( $new_node->hasAttribute( $attr_name ) ) { $old_node->setAttribute( $attr_name, $new_node->getAttribute( $attr_name ) ); } @@ -194,12 +194,12 @@ protected function filter_video_dimensions( $new_attributes, $src ) { $path = wp_parse_url( $src, PHP_URL_PATH ); $ext = pathinfo( $path, PATHINFO_EXTENSION ); $name = sanitize_title( wp_basename( $path, ".$ext" ) ); - $args = array( + $args = [ 'name' => $name, 'post_type' => 'attachment', 'post_status' => 'inherit', 'numberposts' => 1, - ); + ]; $attachment = get_posts( $args ); @@ -239,7 +239,7 @@ protected function filter_video_dimensions( $new_attributes, $src ) { * @return array Returns HTML attributes; removes any not specifically declared above from input. */ private function filter_attributes( $attributes ) { - $out = array(); + $out = []; foreach ( $attributes as $name => $value ) { switch ( $name ) { diff --git a/includes/settings/class-amp-customizer-design-settings.php b/includes/settings/class-amp-customizer-design-settings.php index d8e55fcaa90..154f732fe08 100644 --- a/includes/settings/class-amp-customizer-design-settings.php +++ b/includes/settings/class-amp-customizer-design-settings.php @@ -59,10 +59,10 @@ public static function is_amp_customizer_enabled() { * Init. */ public static function init() { - add_action( 'amp_customizer_init', array( __CLASS__, 'init_customizer' ) ); + add_action( 'amp_customizer_init', [ __CLASS__, 'init_customizer' ] ); if ( self::is_amp_customizer_enabled() ) { - add_filter( 'amp_customizer_get_settings', array( __CLASS__, 'append_settings' ) ); + add_filter( 'amp_customizer_get_settings', [ __CLASS__, 'append_settings' ] ); } } @@ -71,9 +71,9 @@ public static function init() { */ public static function init_customizer() { if ( self::is_amp_customizer_enabled() ) { - add_action( 'amp_customizer_register_settings', array( __CLASS__, 'register_customizer_settings' ) ); - add_action( 'amp_customizer_register_ui', array( __CLASS__, 'register_customizer_ui' ) ); - add_action( 'amp_customizer_enqueue_preview_scripts', array( __CLASS__, 'enqueue_customizer_preview_scripts' ) ); + add_action( 'amp_customizer_register_settings', [ __CLASS__, 'register_customizer_settings' ] ); + add_action( 'amp_customizer_register_ui', [ __CLASS__, 'register_customizer_ui' ] ); + add_action( 'amp_customizer_enqueue_preview_scripts', [ __CLASS__, 'enqueue_customizer_preview_scripts' ] ); } } @@ -87,45 +87,45 @@ public static function register_customizer_settings( $wp_customize ) { // Header text color setting. $wp_customize->add_setting( 'amp_customizer[header_color]', - array( + [ 'type' => 'option', 'default' => self::DEFAULT_HEADER_COLOR, 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', - ) + ] ); // Header background color. $wp_customize->add_setting( 'amp_customizer[header_background_color]', - array( + [ 'type' => 'option', 'default' => self::DEFAULT_HEADER_BACKGROUND_COLOR, 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', - ) + ] ); // Background color scheme. $wp_customize->add_setting( 'amp_customizer[color_scheme]', - array( + [ 'type' => 'option', 'default' => self::DEFAULT_COLOR_SCHEME, - 'sanitize_callback' => array( __CLASS__, 'sanitize_color_scheme' ), + 'sanitize_callback' => [ __CLASS__, 'sanitize_color_scheme' ], 'transport' => 'postMessage', - ) + ] ); // Display exit link. $wp_customize->add_setting( 'amp_customizer[display_exit_link]', - array( + [ 'type' => 'option', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean', 'transport' => 'postMessage', - ) + ] ); } @@ -137,10 +137,10 @@ public static function register_customizer_settings( $wp_customize ) { public static function register_customizer_ui( $wp_customize ) { $wp_customize->add_section( 'amp_design', - array( + [ 'title' => __( 'Design', 'amp' ), 'panel' => AMP_Template_Customizer::PANEL_ID, - ) + ] ); // Header text color control. @@ -148,12 +148,12 @@ public static function register_customizer_ui( $wp_customize ) { new WP_Customize_Color_Control( $wp_customize, 'amp_header_color', - array( + [ 'settings' => 'amp_customizer[header_color]', 'label' => __( 'Header Text Color', 'amp' ), 'section' => 'amp_design', 'priority' => 10, - ) + ] ) ); @@ -162,61 +162,61 @@ public static function register_customizer_ui( $wp_customize ) { new WP_Customize_Color_Control( $wp_customize, 'amp_header_background_color', - array( + [ 'settings' => 'amp_customizer[header_background_color]', 'label' => __( 'Header Background & Link Color', 'amp' ), 'section' => 'amp_design', 'priority' => 20, - ) + ] ) ); // Background color scheme. $wp_customize->add_control( 'amp_color_scheme', - array( + [ 'settings' => 'amp_customizer[color_scheme]', 'label' => __( 'Color Scheme', 'amp' ), 'section' => 'amp_design', 'type' => 'radio', 'priority' => 30, 'choices' => self::get_color_scheme_names(), - ) + ] ); // Display exit link. $wp_customize->add_control( 'amp_display_exit_link', - array( + [ 'settings' => 'amp_customizer[display_exit_link]', 'label' => __( 'Display link to exit reader mode?', 'amp' ), 'section' => 'amp_design', 'type' => 'checkbox', 'priority' => 40, - ) + ] ); // Header. $wp_customize->selective_refresh->add_partial( 'amp-wp-header', - array( + [ 'selector' => '.amp-wp-header', - 'settings' => array( 'blogname', 'amp_customizer[display_exit_link]' ), // @todo Site Icon. - 'render_callback' => array( __CLASS__, 'render_header_bar' ), + 'settings' => [ 'blogname', 'amp_customizer[display_exit_link]' ], // @todo Site Icon. + 'render_callback' => [ __CLASS__, 'render_header_bar' ], 'fallback_refresh' => false, - ) + ] ); // Header. $wp_customize->selective_refresh->add_partial( 'amp-wp-footer', - array( + [ 'selector' => '.amp-wp-footer', - 'settings' => array( 'blogname' ), - 'render_callback' => array( __CLASS__, 'render_footer' ), + 'settings' => [ 'blogname' ], + 'render_callback' => [ __CLASS__, 'render_footer' ], 'fallback_refresh' => false, 'container_inclusive' => true, - ) + ] ); } @@ -226,7 +226,7 @@ public static function register_customizer_ui( $wp_customize ) { public static function render_header_bar() { if ( is_singular() ) { $post_template = new AMP_Post_Template( get_post() ); - $post_template->load_parts( array( 'header-bar' ) ); + $post_template->load_parts( [ 'header-bar' ] ); } } @@ -236,7 +236,7 @@ public static function render_header_bar() { public static function render_footer() { if ( is_singular() ) { $post_template = new AMP_Post_Template( get_post() ); - $post_template->load_parts( array( 'footer' ) ); + $post_template->load_parts( [ 'footer' ] ); } } @@ -252,16 +252,16 @@ public static function enqueue_customizer_preview_scripts() { wp_enqueue_script( 'amp-customizer-design-preview', amp_get_asset_url( 'js/amp-customizer-design-preview.js' ), - array( 'amp-customize-preview' ), + [ 'amp-customize-preview' ], false, true ); wp_localize_script( 'amp-customizer-design-preview', 'amp_customizer_design', - array( + [ 'color_schemes' => self::get_color_schemes(), - ) + ] ); // Prevent a theme's registered blogname partial from causing full page refreshes. @@ -282,12 +282,12 @@ public static function enqueue_customizer_preview_scripts() { public static function append_settings( $settings ) { $settings = wp_parse_args( $settings, - array( + [ 'header_color' => self::DEFAULT_HEADER_COLOR, 'header_background_color' => self::DEFAULT_HEADER_BACKGROUND_COLOR, 'color_scheme' => self::DEFAULT_COLOR_SCHEME, 'display_exit_link' => false, - ) + ] ); $theme_colors = self::get_colors_for_color_scheme( $settings['color_scheme'] ); @@ -295,9 +295,9 @@ public static function append_settings( $settings ) { return array_merge( $settings, $theme_colors, - array( + [ 'link_color' => $settings['header_background_color'], - ) + ] ); } @@ -307,10 +307,10 @@ public static function append_settings( $settings ) { * @return array Color scheme names. */ protected static function get_color_scheme_names() { - return array( + return [ 'light' => __( 'Light', 'amp' ), 'dark' => __( 'Dark', 'amp' ), - ); + ]; } /** @@ -319,22 +319,22 @@ protected static function get_color_scheme_names() { * @return array Color schemes. */ protected static function get_color_schemes() { - return array( - 'light' => array( + return [ + 'light' => [ // Convert colors to greyscale for light theme color; see <http://goo.gl/2gDLsp>. 'theme_color' => '#fff', 'text_color' => '#353535', 'muted_text_color' => '#696969', 'border_color' => '#c2c2c2', - ), - 'dark' => array( + ], + 'dark' => [ // Convert and invert colors to greyscale for dark theme color; see <http://goo.gl/uVB2cO>. 'theme_color' => '#0a0a0a', 'text_color' => '#dedede', 'muted_text_color' => '#b1b1b1', 'border_color' => '#707070', - ), - ); + ], + ]; } /** diff --git a/includes/settings/class-amp-customizer-settings.php b/includes/settings/class-amp-customizer-settings.php index d075e78efb5..7fada7625bc 100644 --- a/includes/settings/class-amp-customizer-settings.php +++ b/includes/settings/class-amp-customizer-settings.php @@ -18,7 +18,7 @@ class AMP_Customizer_Settings { * @return array Associative array of $setting => $value pairs. */ private static function get_stored_options() { - return get_option( 'amp_customizer', array() ); + return get_option( 'amp_customizer', [] ); } /** diff --git a/includes/templates/class-amp-content-sanitizer.php b/includes/templates/class-amp-content-sanitizer.php index 110787d1396..6fca3c5e5a2 100644 --- a/includes/templates/class-amp-content-sanitizer.php +++ b/includes/templates/class-amp-content-sanitizer.php @@ -24,7 +24,7 @@ class AMP_Content_Sanitizer { * @param array $global_args Global args. * @return array Tuple containing sanitized HTML, scripts array, and styles array (or stylesheets, if return_styles=false is passed in $global_args). */ - public static function sanitize( $content, array $sanitizer_classes, $global_args = array() ) { + public static function sanitize( $content, array $sanitizer_classes, $global_args = [] ) { $dom = AMP_DOM_Utils::get_dom_from_content( $content ); // For back-compat. @@ -33,11 +33,11 @@ public static function sanitize( $content, array $sanitizer_classes, $global_arg } $results = self::sanitize_document( $dom, $sanitizer_classes, $global_args ); - return array( + return [ AMP_DOM_Utils::get_content_from_dom( $dom ), $results['scripts'], empty( $global_args['return_styles'] ) ? $results['stylesheets'] : $results['styles'], - ); + ]; } /** @@ -57,9 +57,9 @@ public static function sanitize( $content, array $sanitizer_classes, $global_arg * } */ public static function sanitize_document( &$dom, $sanitizer_classes, $args ) { - $scripts = array(); - $stylesheets = array(); - $styles = array(); + $scripts = []; + $stylesheets = []; + $styles = []; $return_styles = ! empty( $args['return_styles'] ); unset( $args['return_styles'] ); @@ -69,7 +69,7 @@ public static function sanitize_document( &$dom, $sanitizer_classes, $args ) { * * @var AMP_Base_Sanitizer[] $sanitizers */ - $sanitizers = array(); + $sanitizers = []; // Instantiate the sanitizers. foreach ( $sanitizer_classes as $sanitizer_class => $sanitizer_args ) { diff --git a/includes/templates/class-amp-content.php b/includes/templates/class-amp-content.php index 14fc86ebe04..70d3f30df3d 100644 --- a/includes/templates/class-amp-content.php +++ b/includes/templates/class-amp-content.php @@ -29,7 +29,7 @@ class AMP_Content { * * @var array */ - private $amp_scripts = array(); + private $amp_scripts = []; /** * AMP stylesheets. @@ -37,7 +37,7 @@ class AMP_Content { * @since 1.0 * @var array */ - private $amp_stylesheets = array(); + private $amp_stylesheets = []; /** * Args. @@ -68,7 +68,7 @@ class AMP_Content { * @param string[] $sanitizer_classes Sanitizer class names. * @param array $args Args. */ - public function __construct( $content, $embed_handler_classes, $sanitizer_classes, $args = array() ) { + public function __construct( $content, $embed_handler_classes, $sanitizer_classes, $args = [] ) { $this->content = $content; $this->args = $args; $this->embed_handlers = $this->register_embed_handlers( $embed_handler_classes ); @@ -105,7 +105,7 @@ public function get_amp_scripts() { */ public function get_amp_styles() { _deprecated_function( __METHOD__, '1.0', __CLASS__ . '::get_amp_stylesheets' ); - return array(); + return []; } /** @@ -160,7 +160,7 @@ private function add_stylesheets( $stylesheets ) { * @return array */ private function register_embed_handlers( $embed_handler_classes ) { - $embed_handlers = array(); + $embed_handlers = []; foreach ( $embed_handler_classes as $embed_handler_class => $args ) { $embed_handler = new $embed_handler_class( array_merge( $this->args, $args ) ); diff --git a/includes/templates/class-amp-post-template.php b/includes/templates/class-amp-post-template.php index 7b53b090920..8c34801c626 100644 --- a/includes/templates/class-amp-post-template.php +++ b/includes/templates/class-amp-post-template.php @@ -108,7 +108,7 @@ public function __construct( $post ) { } $content_max_width = apply_filters( 'amp_content_max_width', $content_max_width ); - $this->data = array( + $this->data = [ 'content_max_width' => $content_max_width, 'document_title' => function_exists( 'wp_get_document_title' ) ? wp_get_document_title() : wp_title( '', false ), // Back-compat with 4.3. @@ -116,7 +116,7 @@ public function __construct( $post ) { 'home_url' => home_url( '/' ), 'blog_name' => get_bloginfo( 'name' ), - 'html_tag_attributes' => array(), + 'html_tag_attributes' => [], 'body_class' => '', 'site_icon_url' => apply_filters( 'amp_site_icon_url', function_exists( 'get_site_icon_url' ) ? get_site_icon_url( self::SITE_ICON_SIZE ) : '' ), @@ -127,17 +127,17 @@ public function __construct( $post ) { 'comments_link_text' => false, 'amp_runtime_script' => 'https://cdn.ampproject.org/v0.js', - 'amp_component_scripts' => array(), + 'amp_component_scripts' => [], - 'customizer_settings' => array(), + 'customizer_settings' => [], - 'font_urls' => array(), + 'font_urls' => [], - 'post_amp_stylesheets' => array(), - 'post_amp_styles' => array(), // Deprecated. + 'post_amp_stylesheets' => [], + 'post_amp_styles' => [], // Deprecated. 'amp_analytics' => amp_add_custom_analytics(), - ); + ]; $this->build_post_content(); $this->build_post_data(); @@ -196,7 +196,7 @@ public function get_customizer_setting( $name, $default = null ) { public function load() { global $wp_query; $template = is_page() || $wp_query->is_posts_page ? 'page' : 'single'; - $this->load_parts( array( $template ) ); + $this->load_parts( [ $template ] ); } /** @@ -265,7 +265,7 @@ private function build_post_data() { $post_modified_timestamp = get_post_modified_time( 'U', false, $this->post ); $post_author = get_userdata( $this->post->post_author ); - $data = array( + $data = [ 'post' => $this->post, 'post_id' => $this->ID, 'post_title' => $post_title, @@ -274,7 +274,7 @@ private function build_post_data() { 'post_author' => $post_author, 'post_canonical_link_url' => '', 'post_canonical_link_text' => '', - ); + ]; $customizer_settings = AMP_Customizer_Settings::get_settings(); if ( ! empty( $customizer_settings['display_exit_link'] ) ) { @@ -310,10 +310,10 @@ private function build_post_comments_data() { : __( 'View Comments', 'amp' ); $this->add_data( - array( + [ 'comments_link_url' => $comments_link_url, 'comments_link_text' => $comments_link_text, - ) + ] ); } @@ -325,9 +325,9 @@ private function build_post_content() { $this->post->post_content, amp_get_content_embed_handlers( $this->post ), amp_get_content_sanitizers( $this->post ), - array( + [ 'content_max_width' => $this->get( 'content_max_width' ), - ) + ] ); $this->add_data_by_key( 'post_amp_content', $amp_content->get_amp_content() ); @@ -364,19 +364,19 @@ private function build_post_featured_image() { $assets = AMP_Content_Sanitizer::sanitize_document( $dom, amp_get_content_sanitizers( $this->post ), - array( + [ 'content_max_width' => $this->get( 'content_max_width' ), - ) + ] ); $sanitized_html = AMP_DOM_Utils::get_content_from_dom( $dom ); $this->add_data_by_key( 'featured_image', - array( + [ 'amp_html' => $sanitized_html, 'caption' => $featured_image->post_excerpt, - ) + ] ); if ( $assets['scripts'] ) { @@ -415,7 +415,7 @@ private function build_customizer_settings() { * Build HTML tag attributes. */ private function build_html_tag_attributes() { - $attributes = array(); + $attributes = []; if ( function_exists( 'is_rtl' ) && is_rtl() ) { $attributes['dir'] = 'rtl'; @@ -460,7 +460,7 @@ private function verify_and_include( $file, $template_type ) { */ private function locate_template( $file ) { $search_file = sprintf( 'amp/%s', basename( $file ) ); - return locate_template( array( $search_file ), false ); + return locate_template( [ $search_file ], false ); } /** diff --git a/includes/templates/embed-amp-story.php b/includes/templates/embed-amp-story.php index 7a8101f236b..d471e406d5e 100644 --- a/includes/templates/embed-amp-story.php +++ b/includes/templates/embed-amp-story.php @@ -16,10 +16,10 @@ <div class="amp-story-embed"> <?php AMP_Story_Post_Type::the_single_story_card( - array( + [ 'post' => get_post(), 'size' => AMP_Story_Post_Type::STORY_CARD_IMAGE_SIZE, - ) + ] ); ?> </div> diff --git a/includes/templates/single-amp_story.php b/includes/templates/single-amp_story.php index f1d68d316a4..f47180fe5e0 100644 --- a/includes/templates/single-amp_story.php +++ b/includes/templates/single-amp_story.php @@ -15,7 +15,7 @@ <title><?php echo esc_html( wp_get_document_title() ); ?> do_items( array( 'amp-runtime' ) ); // @todo Duplicate with AMP_Theme_Support::enqueue_assets(). + wp_scripts()->do_items( [ 'amp-runtime' ] ); // @todo Duplicate with AMP_Theme_Support::enqueue_assets(). wp_styles()->do_items(); ?> diff --git a/includes/utils/class-amp-dom-utils.php b/includes/utils/class-amp-dom-utils.php index 1ee42c739ab..03047a6a53f 100644 --- a/includes/utils/class-amp-dom-utils.php +++ b/includes/utils/class-amp-dom-utils.php @@ -21,7 +21,7 @@ class AMP_DOM_Utils { * @link https://www.w3.org/TR/html5/syntax.html#serializing-html-fragments * @var array */ - private static $self_closing_tags = array( + private static $self_closing_tags = [ 'area', 'base', 'basefont', @@ -40,7 +40,7 @@ class AMP_DOM_Utils { 'source', 'track', 'wbr', - ); + ]; /** * List of elements allowed in head. @@ -49,7 +49,7 @@ class AMP_DOM_Utils { * @link https://www.w3.org/TR/html5/document-metadata.html * @var array */ - private static $elements_allowed_in_head = array( + private static $elements_allowed_in_head = [ 'title', 'base', 'link', @@ -57,7 +57,7 @@ class AMP_DOM_Utils { 'style', 'noscript', 'script', - ); + ]; /** * Stored noscript/comment replacements for libxml<2.8. @@ -65,7 +65,7 @@ class AMP_DOM_Utils { * @since 0.7 * @var array */ - public static $noscript_placeholder_comments = array(); + public static $noscript_placeholder_comments = []; /** * Return a valid DOMDocument representing HTML document passed as a parameter. @@ -249,7 +249,7 @@ private static function get_mustache_tag_placeholders() { $salt = wp_rand(); // Note: The order of these tokens is important, as it determines the order of the order of the replacements. - $tokens = array( + $tokens = [ '{{{', '}}}', '{{#', @@ -258,8 +258,8 @@ private static function get_mustache_tag_placeholders() { '{{/', '{{', '}}', - ); - $placeholders = array(); + ]; + $placeholders = []; foreach ( $tokens as $token ) { $placeholders[ $token ] = '_amp_mustache_' . md5( $salt . $token ); } @@ -322,7 +322,7 @@ public static function convert_amp_bind_attributes( $html ) { // Match all start tags that contain a binding attribute. $pattern = implode( '', - array( + [ '#<', '(?P[a-zA-Z0-9_\-]+)', // Tag name. '(?P\s', // Attributes. @@ -330,7 +330,7 @@ public static function convert_amp_bind_attributes( $html ) { '\[[a-zA-Z0-9_\-]+\]', // One binding attribute key. '(?:[^>"\']+|"[^"]*+"|\'[^\']*+\')*+', // Any attribute tokens, including binding ones. ')>#s', - ) + ] ); $converted = preg_replace_callback( $pattern, @@ -596,7 +596,7 @@ public static function create_node( $dom, $tag, $attributes ) { * empty array if it has no attributes. */ public static function get_node_attributes_as_assoc_array( $node ) { - $attributes = array(); + $attributes = []; if ( ! $node->hasAttributes() ) { return $attributes; } diff --git a/includes/utils/class-amp-html-utils.php b/includes/utils/class-amp-html-utils.php index 39f5ce38473..34402ee25f1 100644 --- a/includes/utils/class-amp-html-utils.php +++ b/includes/utils/class-amp-html-utils.php @@ -18,7 +18,7 @@ class AMP_HTML_Utils { * @param string $content Inner content for the generated node. * @return string HTML markup. */ - public static function build_tag( $tag_name, $attributes = array(), $content = '' ) { + public static function build_tag( $tag_name, $attributes = [], $content = '' ) { $attr_string = self::build_attributes_string( $attributes ); return sprintf( '<%1$s %2$s>%3$s', sanitize_key( $tag_name ), $attr_string, $content ); } @@ -30,7 +30,7 @@ public static function build_tag( $tag_name, $attributes = array(), $content = ' * @return string HTML attributes string. */ public static function build_attributes_string( $attributes ) { - $string = array(); + $string = []; foreach ( $attributes as $name => $value ) { if ( '' === $value ) { $string[] = sprintf( '%s', sanitize_key( $name ) ); diff --git a/includes/utils/class-amp-image-dimension-extractor.php b/includes/utils/class-amp-image-dimension-extractor.php index 34d3f0983a1..1ff304c4e6c 100644 --- a/includes/utils/class-amp-image-dimension-extractor.php +++ b/includes/utils/class-amp-image-dimension-extractor.php @@ -33,17 +33,17 @@ public static function extract( $urls ) { self::register_callbacks(); } - $return_dimensions = array(); + $return_dimensions = []; // Back-compat for users calling this method directly. $is_single = is_string( $urls ); if ( $is_single ) { - $urls = array( $urls ); + $urls = [ $urls ]; } // Normalize URLs and also track a map of normalized-to-original as we'll need it to reformat things when returning the data. - $url_map = array(); - $normalized_urls = array(); + $url_map = []; + $normalized_urls = []; foreach ( $urls as $original_url ) { $normalized_url = self::normalize_url( $original_url ); if ( false !== $normalized_url ) { @@ -130,7 +130,7 @@ public static function normalize_url( $url ) { private static function register_callbacks() { self::$callbacks_registered = true; - add_filter( 'amp_extract_image_dimensions_batch', array( __CLASS__, 'extract_by_downloading_images' ), 999, 1 ); + add_filter( 'amp_extract_image_dimensions_batch', [ __CLASS__, 'extract_by_downloading_images' ], 999, 1 ); do_action( 'amp_extract_image_dimensions_batch_callbacks_registered' ); } @@ -149,8 +149,8 @@ public static function extract_by_downloading_images( $dimensions, $mode = false $transient_expiration = 30 * DAY_IN_SECONDS; - $urls_to_fetch = array(); - $images = array(); + $urls_to_fetch = []; + $images = []; self::determine_which_images_to_fetch( $dimensions, $urls_to_fetch ); try { @@ -185,10 +185,10 @@ private static function determine_which_images_to_fetch( &$dimensions, &$urls_to // If we're able to retrieve the dimensions from a transient, set them and move on. if ( is_array( $cached_dimensions ) ) { - $dimensions[ $url ] = array( + $dimensions[ $url ] = [ 'width' => $cached_dimensions[0], 'height' => $cached_dimensions[1], - ); + ]; continue; } @@ -207,7 +207,7 @@ private static function determine_which_images_to_fetch( &$dimensions, &$urls_to } // Include the image as a url to fetch. - $urls_to_fetch[ $url ] = array(); + $urls_to_fetch[ $url ] = []; $urls_to_fetch[ $url ]['url'] = $url; $urls_to_fetch[ $url ]['transient_name'] = $transient_name; $urls_to_fetch[ $url ]['transient_lock_name'] = $transient_lock_name; @@ -256,16 +256,16 @@ private static function process_fetched_images( $urls_to_fetch, $images, &$dimen $dimensions[ $url_data['url'] ] = false; set_transient( $url_data['transient_name'], self::STATUS_FAILED_LAST_ATTEMPT, $transient_expiration ); } else { - $dimensions[ $url_data['url'] ] = array( + $dimensions[ $url_data['url'] ] = [ 'width' => $image_data['size'][0], 'height' => $image_data['size'][1], - ); + ]; set_transient( $url_data['transient_name'], - array( + [ $image_data['size'][0], $image_data['size'][1], - ), + ], $transient_expiration ); } diff --git a/includes/utils/class-amp-wp-utils.php b/includes/utils/class-amp-wp-utils.php index d7b26c2a5ff..2d6661bd125 100644 --- a/includes/utils/class-amp-wp-utils.php +++ b/includes/utils/class-amp-wp-utils.php @@ -82,7 +82,7 @@ protected static function _get_component_from_parsed_url_array( $url_parts, $com * @deprecated 0.7 */ protected static function _wp_translate_php_url_constant_to_key( $constant ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore - $translation = array( + $translation = [ PHP_URL_SCHEME => 'scheme', PHP_URL_HOST => 'host', PHP_URL_PORT => 'port', @@ -91,7 +91,7 @@ protected static function _wp_translate_php_url_constant_to_key( $constant ) { / PHP_URL_PATH => 'path', PHP_URL_QUERY => 'query', PHP_URL_FRAGMENT => 'fragment', - ); + ]; if ( isset( $translation[ $constant ] ) ) { return $translation[ $constant ]; diff --git a/includes/validation/class-amp-validated-url-post-type.php b/includes/validation/class-amp-validated-url-post-type.php index 2a4c7a8811b..be9f6701e4a 100644 --- a/includes/validation/class-amp-validated-url-post-type.php +++ b/includes/validation/class-amp-validated-url-post-type.php @@ -95,12 +95,12 @@ class AMP_Validated_URL_Post_Type { * @return void */ public static function register() { - add_action( 'amp_plugin_update', array( __CLASS__, 'handle_plugin_update' ) ); + add_action( 'amp_plugin_update', [ __CLASS__, 'handle_plugin_update' ] ); $post_type = register_post_type( self::POST_TYPE_SLUG, - array( - 'labels' => array( + [ + 'labels' => [ 'name' => _x( 'AMP Validated URLs', 'post type general name', 'amp' ), 'menu_name' => __( 'Validated URLs', 'amp' ), 'singular_name' => __( 'Validated URL', 'amp' ), @@ -108,13 +108,13 @@ public static function register() { 'not_found_in_trash' => __( 'No forgotten validated URLs', 'amp' ), 'search_items' => __( 'Search validated URLs', 'amp' ), 'edit_item' => '', // Overwritten in JS, so this prevents the page header from appearing and changing. - ), + ], 'supports' => false, 'public' => false, 'show_ui' => true, 'show_in_menu' => ( self::should_show_in_menu() || AMP_Validation_Error_Taxonomy::should_show_in_menu() ) ? AMP_Options_Manager::OPTION_NAME : false, // @todo Show in rest. - ) + ] ); // Hide the add new post link. @@ -136,17 +136,17 @@ public static function handle_plugin_update( $old_version ) { if ( '1.0-' === substr( $old_version, 0, 4 ) || version_compare( $old_version, '1.0', '<' ) ) { global $wpdb; $post_ids = get_posts( - array( + [ 'post_type' => 'amp_invalid_url', 'fields' => 'ids', 'posts_per_page' => -1, - ) + ] ); foreach ( $post_ids as $post_id ) { $wpdb->update( $wpdb->posts, - array( 'post_type' => self::POST_TYPE_SLUG ), - array( 'ID' => $post_id ) + [ 'post_type' => self::POST_TYPE_SLUG ], + [ 'ID' => $post_id ] ); clean_post_cache( $post_id ); } @@ -170,26 +170,26 @@ public static function should_show_in_menu() { * Add admin hooks. */ public static function add_admin_hooks() { - add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_post_list_screen_scripts' ) ); + add_action( 'admin_enqueue_scripts', [ __CLASS__, 'enqueue_post_list_screen_scripts' ] ); if ( AMP_Options_Manager::is_website_experience_enabled() ) { - add_filter( 'dashboard_glance_items', array( __CLASS__, 'filter_dashboard_glance_items' ) ); - add_action( 'rightnow_end', array( __CLASS__, 'print_dashboard_glance_styles' ) ); + add_filter( 'dashboard_glance_items', [ __CLASS__, 'filter_dashboard_glance_items' ] ); + add_action( 'rightnow_end', [ __CLASS__, 'print_dashboard_glance_styles' ] ); } // Edit post screen hooks. - add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_edit_post_screen_scripts' ) ); - add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) ); - add_action( 'edit_form_after_title', array( __CLASS__, 'render_single_url_list_table' ) ); - add_filter( 'edit_' . AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG . '_per_page', array( __CLASS__, 'get_terms_per_page' ) ); - add_action( 'admin_init', array( __CLASS__, 'add_taxonomy' ) ); - add_action( 'edit_form_top', array( __CLASS__, 'print_url_as_title' ) ); + add_action( 'admin_enqueue_scripts', [ __CLASS__, 'enqueue_edit_post_screen_scripts' ] ); + add_action( 'add_meta_boxes', [ __CLASS__, 'add_meta_boxes' ] ); + add_action( 'edit_form_after_title', [ __CLASS__, 'render_single_url_list_table' ] ); + add_filter( 'edit_' . AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG . '_per_page', [ __CLASS__, 'get_terms_per_page' ] ); + add_action( 'admin_init', [ __CLASS__, 'add_taxonomy' ] ); + add_action( 'edit_form_top', [ __CLASS__, 'print_url_as_title' ] ); // Post list screen hooks. add_filter( 'view_mode_post_types', static function( $post_types ) { - return array_diff( $post_types, array( AMP_Validated_URL_Post_Type::POST_TYPE_SLUG ) ); + return array_diff( $post_types, [ AMP_Validated_URL_Post_Type::POST_TYPE_SLUG ] ); } ); add_action( @@ -207,23 +207,23 @@ static function() { ); } ); - add_action( 'admin_notices', array( __CLASS__, 'render_link_to_error_index_screen' ) ); - add_filter( 'the_title', array( __CLASS__, 'filter_the_title_in_post_list_table' ), 10, 2 ); - add_action( 'restrict_manage_posts', array( __CLASS__, 'render_post_filters' ), 10, 2 ); - add_filter( 'manage_' . self::POST_TYPE_SLUG . '_posts_columns', array( __CLASS__, 'add_post_columns' ) ); - add_filter( 'manage_' . self::POST_TYPE_SLUG . '_columns', array( __CLASS__, 'add_single_post_columns' ) ); - add_action( 'manage_posts_custom_column', array( __CLASS__, 'output_custom_column' ), 10, 2 ); - add_filter( 'bulk_actions-edit-' . self::POST_TYPE_SLUG, array( __CLASS__, 'filter_bulk_actions' ), 10, 2 ); + add_action( 'admin_notices', [ __CLASS__, 'render_link_to_error_index_screen' ] ); + add_filter( 'the_title', [ __CLASS__, 'filter_the_title_in_post_list_table' ], 10, 2 ); + add_action( 'restrict_manage_posts', [ __CLASS__, 'render_post_filters' ], 10, 2 ); + add_filter( 'manage_' . self::POST_TYPE_SLUG . '_posts_columns', [ __CLASS__, 'add_post_columns' ] ); + add_filter( 'manage_' . self::POST_TYPE_SLUG . '_columns', [ __CLASS__, 'add_single_post_columns' ] ); + add_action( 'manage_posts_custom_column', [ __CLASS__, 'output_custom_column' ], 10, 2 ); + add_filter( 'bulk_actions-edit-' . self::POST_TYPE_SLUG, [ __CLASS__, 'filter_bulk_actions' ], 10, 2 ); add_filter( 'bulk_actions-' . self::POST_TYPE_SLUG, '__return_false' ); - add_filter( 'handle_bulk_actions-edit-' . self::POST_TYPE_SLUG, array( __CLASS__, 'handle_bulk_action' ), 10, 3 ); - add_action( 'admin_notices', array( __CLASS__, 'print_admin_notice' ) ); - add_action( 'admin_action_' . self::VALIDATE_ACTION, array( __CLASS__, 'handle_validate_request' ) ); - add_action( 'post_action_' . self::UPDATE_POST_TERM_STATUS_ACTION, array( __CLASS__, 'handle_validation_error_status_update' ) ); - add_action( 'admin_menu', array( __CLASS__, 'add_admin_menu_new_invalid_url_count' ) ); - add_filter( 'post_row_actions', array( __CLASS__, 'filter_post_row_actions' ), 10, 2 ); - add_filter( sprintf( 'views_edit-%s', self::POST_TYPE_SLUG ), array( __CLASS__, 'filter_table_views' ) ); - add_filter( 'bulk_post_updated_messages', array( __CLASS__, 'filter_bulk_post_updated_messages' ), 10, 2 ); - add_filter( 'admin_title', array( __CLASS__, 'filter_admin_title' ) ); + add_filter( 'handle_bulk_actions-edit-' . self::POST_TYPE_SLUG, [ __CLASS__, 'handle_bulk_action' ], 10, 3 ); + add_action( 'admin_notices', [ __CLASS__, 'print_admin_notice' ] ); + add_action( 'admin_action_' . self::VALIDATE_ACTION, [ __CLASS__, 'handle_validate_request' ] ); + add_action( 'post_action_' . self::UPDATE_POST_TERM_STATUS_ACTION, [ __CLASS__, 'handle_validation_error_status_update' ] ); + add_action( 'admin_menu', [ __CLASS__, 'add_admin_menu_new_invalid_url_count' ] ); + add_filter( 'post_row_actions', [ __CLASS__, 'filter_post_row_actions' ], 10, 2 ); + add_filter( sprintf( 'views_edit-%s', self::POST_TYPE_SLUG ), [ __CLASS__, 'filter_table_views' ] ); + add_filter( 'bulk_post_updated_messages', [ __CLASS__, 'filter_bulk_post_updated_messages' ], 10, 2 ); + add_filter( 'admin_title', [ __CLASS__, 'filter_admin_title' ] ); // Hide irrelevant "published" label in the AMP Validated URLs post list. add_filter( @@ -263,7 +263,7 @@ public static function enqueue_post_list_screen_scripts() { $script_deps_path = AMP__DIR__ . '/assets/js/amp-validated-urls-index.deps.json'; $script_dependencies = file_exists( $script_deps_path ) ? json_decode( file_get_contents( $script_deps_path ), false ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - : array(); + : []; wp_enqueue_script( 'amp-validated-urls-index', @@ -291,19 +291,19 @@ public static function enqueue_post_list_screen_scripts() { wp_register_style( 'amp-validation-tooltips', amp_get_asset_url( 'css/amp-validation-tooltips.css' ), - array( 'wp-pointer' ), + [ 'wp-pointer' ], AMP__VERSION ); $script_deps_path = AMP__DIR__ . '/assets/js/amp-validation-tooltips.deps.json'; $script_dependencies = file_exists( $script_deps_path ) ? json_decode( file_get_contents( $script_deps_path ), false ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - : array(); + : []; wp_register_script( 'amp-validation-tooltips', amp_get_asset_url( 'js/amp-validation-tooltips.js' ), - array_merge( $script_dependencies, array( 'wp-pointer' ) ), + array_merge( $script_dependencies, [ 'wp-pointer' ] ), AMP__VERSION, true ); @@ -311,14 +311,14 @@ public static function enqueue_post_list_screen_scripts() { wp_enqueue_style( 'amp-validation-error-taxonomy', amp_get_asset_url( 'css/amp-validation-error-taxonomy.css' ), - array( 'common', 'amp-validation-tooltips' ), + [ 'common', 'amp-validation-tooltips' ], AMP__VERSION ); wp_enqueue_script( 'amp-validation-detail-toggle', amp_get_asset_url( 'js/amp-validation-detail-toggle.js' ), - array( 'wp-dom-ready', 'wp-i18n', 'amp-validation-tooltips' ), + [ 'wp-dom-ready', 'wp-i18n', 'amp-validation-tooltips' ], AMP__VERSION, true ); @@ -368,15 +368,15 @@ public static function add_admin_menu_new_invalid_url_count() { } $query = new WP_Query( - array( + [ 'post_type' => self::POST_TYPE_SLUG, - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => array( + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => [ AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, - ), + ], 'update_post_meta_cache' => false, 'update_post_term_cache' => false, - ) + ] ); if ( 0 === $query->found_posts ) { @@ -401,11 +401,11 @@ public static function add_admin_menu_new_invalid_url_count() { * } * @return array List of errors, with keys for term, data, status, and (sanitization) forced. */ - public static function get_invalid_url_validation_errors( $url, $args = array() ) { + public static function get_invalid_url_validation_errors( $url, $args = [] ) { $args = array_merge( - array( + [ 'ignore_accepted' => false, - ), + ], $args ); @@ -416,16 +416,16 @@ public static function get_invalid_url_validation_errors( $url, $args = array() $post = get_post( $url ); } if ( ! $post || self::POST_TYPE_SLUG !== $post->post_type ) { - return array(); + return []; } // Skip when parse error. $stored_validation_errors = json_decode( $post->post_content, true ); if ( ! is_array( $stored_validation_errors ) ) { - return array(); + return []; } - $errors = array(); + $errors = []; foreach ( $stored_validation_errors as $stored_validation_error ) { if ( ! isset( $stored_validation_error['term_slug'] ) ) { continue; @@ -442,10 +442,10 @@ public static function get_invalid_url_validation_errors( $url, $args = array() } $errors[] = array_merge( - array( + [ 'term' => $term, 'data' => $stored_validation_error['data'], - ), + ], $sanitization ); } @@ -462,17 +462,17 @@ public static function get_invalid_url_validation_errors( $url, $args = array() * @type bool $display_enabled_status Whether to display the status of whether AMP is enabled on the URL. * } */ - public static function display_invalid_url_validation_error_counts_summary( $post, $args = array() ) { + public static function display_invalid_url_validation_error_counts_summary( $post, $args = [] ) { $args = array_merge( - array( + [ 'display_enabled_status' => false, - ), + ], $args ); $validation_errors = self::get_invalid_url_validation_errors( $post ); $counts = self::count_invalid_url_validation_errors( $validation_errors ); - $result = array(); + $result = []; if ( $counts['new_rejected'] ) { $result[] = sprintf( /* translators: 1: status. 2: count. */ @@ -536,11 +536,11 @@ public static function display_invalid_url_validation_error_counts_summary( $pos * } * @return WP_Post|null The post of the existing custom post, or null. */ - public static function get_invalid_url_post( $url, $options = array() ) { - $default = array( + public static function get_invalid_url_post( $url, $options = [] ) { + $default = [ 'normalize' => true, 'include_trashed' => false, - ); + ]; $options = wp_parse_args( $options, $default ); if ( $options['normalize'] ) { @@ -646,7 +646,7 @@ protected static function normalize_url_for_storage( $url ) { * @return int|WP_Error $post_id The post ID of the custom post type used, or WP_Error on failure. * @global WP $wp */ - public static function store_validation_errors( $validation_errors, $url, $args = array() ) { + public static function store_validation_errors( $validation_errors, $url, $args = [] ) { $url = self::normalize_url_for_storage( $url ); $slug = md5( $url ); $post = null; @@ -656,10 +656,10 @@ public static function store_validation_errors( $validation_errors, $url, $args if ( ! $post ) { $post = self::get_invalid_url_post( $url, - array( + [ 'include_trashed' => true, 'normalize' => false, // Since already normalized. - ) + ] ); } @@ -676,20 +676,20 @@ public static function store_validation_errors( $validation_errors, $url, $args * The post content just contains the slugs for these terms and the sources for the given instance of * the validation error. */ - $stored_validation_errors = array(); + $stored_validation_errors = []; // Prevent Kses from corrupting JSON in description. - $pre_term_description_filters = array( + $pre_term_description_filters = [ 'wp_filter_kses' => has_filter( 'pre_term_description', 'wp_filter_kses' ), 'wp_targeted_link_rel' => has_filter( 'pre_term_description', 'wp_targeted_link_rel' ), - ); + ]; foreach ( $pre_term_description_filters as $callback => $priority ) { if ( false !== $priority ) { remove_filter( 'pre_term_description', $callback, $priority ); } } - $terms = array(); + $terms = []; foreach ( $validation_errors as $data ) { $term_data = AMP_Validation_Error_Taxonomy::prepare_validation_error_taxonomy_term( $data ); $term_slug = $term_data['slug']; @@ -720,18 +720,18 @@ public static function store_validation_errors( $validation_errors, $url, $args wp_update_term( $term_id, AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, - array( + [ 'term_group' => $sanitization['status'], - ) + ] ); } elseif ( AMP_Validation_Manager::is_sanitization_auto_accepted() || $is_story ) { $term_data['term_group'] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS; wp_update_term( $term_id, AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, - array( + [ 'term_group' => $term_data['term_group'], - ) + ] ); } @@ -772,14 +772,14 @@ public static function store_validation_errors( $validation_errors, $url, $args // Create a new invalid AMP URL post, or update the existing one. $r = wp_insert_post( wp_slash( - array( + [ 'ID' => $post ? $post->ID : null, 'post_type' => self::POST_TYPE_SLUG, 'post_title' => $url, 'post_name' => $slug, 'post_content' => $placeholder, // Content is provided via wp_insert_post_data filter above to guard against Kses-corruption. 'post_status' => 'publish', - ) + ] ), true ); @@ -804,10 +804,10 @@ public static function store_validation_errors( $validation_errors, $url, $args * @return array Environment. */ public static function get_validated_environment() { - return array( + return [ 'theme' => get_stylesheet(), - 'plugins' => get_option( 'active_plugins', array() ), - ); + 'plugins' => get_option( 'active_plugins', [] ), + ]; } /** @@ -825,13 +825,13 @@ public static function get_validated_environment() { public static function get_post_staleness( $post ) { $post = get_post( $post ); if ( empty( $post ) || self::POST_TYPE_SLUG !== $post->post_type ) { - return array(); + return []; } $old_validated_environment = get_post_meta( $post->ID, '_amp_validated_environment', true ); $new_validated_environment = self::get_validated_environment(); - $staleness = array(); + $staleness = []; if ( isset( $old_validated_environment['theme'] ) && $new_validated_environment['theme'] !== $old_validated_environment['theme'] ) { $staleness['theme'] = $old_validated_environment['theme']; } @@ -859,7 +859,7 @@ public static function get_post_staleness( $post ) { public static function add_post_columns( $columns ) { $columns = array_merge( $columns, - array( + [ AMP_Validation_Error_Taxonomy::ERROR_STATUS => sprintf( '%s', esc_html__( 'Status', 'amp' ), @@ -873,7 +873,7 @@ public static function add_post_columns( $columns ) { ), AMP_Validation_Error_Taxonomy::FOUND_ELEMENTS_AND_ATTRIBUTES => esc_html__( 'Invalid', 'amp' ), AMP_Validation_Error_Taxonomy::SOURCES_INVALID_OUTPUT => esc_html__( 'Sources', 'amp' ), - ) + ] ); if ( isset( $columns['title'] ) ) { @@ -902,7 +902,7 @@ public static function add_post_columns( $columns ) { * @return array The filtered post columns. */ public static function add_single_post_columns() { - return array( + return [ 'cb' => '', 'error' => __( 'Error', 'amp' ), 'status' => sprintf( @@ -929,7 +929,7 @@ public static function add_single_post_columns() { ), 'sources_with_invalid_output' => __( 'Sources', 'amp' ), 'error_type' => __( 'Type', 'amp' ), - ); + ]; } /** @@ -957,7 +957,7 @@ public static function output_custom_column( $column_name, $post_id ) { self::display_invalid_url_validation_error_counts_summary( $post_id ); break; case AMP_Validation_Error_Taxonomy::FOUND_ELEMENTS_AND_ATTRIBUTES: - $items = array(); + $items = []; if ( ! empty( $error_summary[ AMP_Validation_Error_Taxonomy::REMOVED_ELEMENTS ] ) ) { foreach ( $error_summary[ AMP_Validation_Error_Taxonomy::REMOVED_ELEMENTS ] as $name => $count ) { if ( 1 === (int) $count ) { @@ -1013,10 +1013,10 @@ public static function render_sources_column( $error_summary, $post_id ) { } $sources = $error_summary[ AMP_Validation_Error_Taxonomy::SOURCES_INVALID_OUTPUT ]; - $output = array(); + $output = []; $plugins = get_plugins(); - foreach ( wp_array_slice_assoc( $sources, array( 'plugin', 'mu-plugin' ) ) as $type => $slugs ) { - $plugin_names = array(); + foreach ( wp_array_slice_assoc( $sources, [ 'plugin', 'mu-plugin' ] ) as $type => $slugs ) { + $plugin_names = []; $plugin_slugs = array_unique( $slugs ); foreach ( $plugin_slugs as $plugin_slug ) { if ( 'mu-plugin' === $type ) { @@ -1135,9 +1135,9 @@ public static function handle_bulk_action( $redirect, $action, $items ) { if ( self::BULK_VALIDATE_ACTION !== $action ) { return $redirect; } - $remaining_invalid_urls = array(); + $remaining_invalid_urls = []; - $errors = array(); + $errors = []; foreach ( $items as $item ) { $post = get_post( $item ); @@ -1160,7 +1160,7 @@ public static function handle_bulk_action( $redirect, $action, $items ) { self::store_validation_errors( $validation_errors, $validity['url'], - wp_array_slice_assoc( $validity, array( 'queried_object' ) ) + wp_array_slice_assoc( $validity, [ 'queried_object' ] ) ); $unaccepted_error_count = count( array_filter( @@ -1176,9 +1176,9 @@ static function( $error ) { } // Get the URLs that still have errors after rechecking. - $args = array( + $args = [ self::URLS_TESTED => count( $items ), - ); + ]; if ( ! empty( $errors ) ) { $args['amp_validate_error'] = $errors; } else { @@ -1307,19 +1307,19 @@ public static function print_admin_notice() { $validation_error = json_decode( $error->description, true ); $accept_all_url = wp_nonce_url( add_query_arg( - array( + [ 'action' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPT_ACTION, 'term_id' => $error->term_id, - ) + ] ), AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPT_ACTION ); $reject_all_url = wp_nonce_url( add_query_arg( - array( + [ 'action' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECT_ACTION, 'term_id' => $error->term_id, - ) + ] ), AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECT_ACTION ); @@ -1446,10 +1446,10 @@ public static function handle_validate_request() { $errors, $validity['url'], array_merge( - array( + [ 'invalid_url_post' => $post, - ), - wp_array_slice_assoc( $validity, array( 'queried_object' ) ) + ], + wp_array_slice_assoc( $validity, [ 'queried_object' ] ) ) ); if ( is_wp_error( $stored ) ) { @@ -1477,7 +1477,7 @@ static function ( $error ) { } else { $redirect = admin_url( add_query_arg( - array( 'post_type' => self::POST_TYPE_SLUG ), + [ 'post_type' => self::POST_TYPE_SLUG ], 'edit.php' ) ); @@ -1513,15 +1513,15 @@ public static function recheck_post( $post ) { } $validation_errors = wp_list_pluck( $validity['results'], 'error' ); - $validation_results = array(); + $validation_results = []; self::store_validation_errors( $validation_errors, $validity['url'], array_merge( - array( + [ 'invalid_url_post' => $post, - ), - wp_array_slice_assoc( $validity, array( 'queried_object' ) ) + ], + wp_array_slice_assoc( $validity, [ 'queried_object' ] ) ) ); foreach ( $validation_errors as $error ) { @@ -1580,9 +1580,9 @@ public static function handle_validation_error_status_update() { add_filter( 'pre_term_description', 'wp_filter_kses', $has_pre_term_description_filter ); } - $args = array( + $args = [ 'amp_taxonomy_terms_updated' => $updated_count, - ); + ]; /* * Re-check the post after the validation status change. This is particularly important for validation errors like @@ -1629,7 +1629,7 @@ public static function enqueue_edit_post_screen_scripts() { $script_deps_path = AMP__DIR__ . '/assets/js/' . self::EDIT_POST_SCRIPT_HANDLE . '.deps.json'; $script_dependencies = file_exists( $script_deps_path ) ? json_decode( file_get_contents( $script_deps_path ), false ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - : array(); + : []; wp_enqueue_script( self::EDIT_POST_SCRIPT_HANDLE, @@ -1642,10 +1642,10 @@ public static function enqueue_edit_post_screen_scripts() { $current_screen = get_current_screen(); if ( $current_screen && 'post' === $current_screen->base && self::POST_TYPE_SLUG === $current_screen->post_type ) { $post = get_post(); - $data = array( + $data = [ 'page_heading' => self::get_single_url_page_heading(), 'amp_enabled' => self::is_amp_enabled_on_post( $post ), - ); + ]; wp_localize_script( self::EDIT_POST_SCRIPT_HANDLE, @@ -1679,11 +1679,11 @@ public static function add_meta_boxes() { add_meta_box( self::STATUS_META_BOX, __( 'Status', 'amp' ), - array( __CLASS__, 'print_status_meta_box' ), + [ __CLASS__, 'print_status_meta_box' ], self::POST_TYPE_SLUG, 'side', 'default', - array( '__back_compat_meta_box' => true ) + [ '__back_compat_meta_box' => true ] ); } @@ -1758,7 +1758,7 @@ public static function print_status_meta_box( $post ) { echo '

'; } ?> - true ) ); ?> + true ] ); ?>
@@ -1862,10 +1862,10 @@ public static function render_single_url_list_table( $post ) { $wp_list_table = _get_list_table( 'WP_Terms_List_Table' ); get_current_screen()->set_screen_reader_content( - array( + [ 'heading_pagination' => $taxonomy_object->labels->items_list_navigation, 'heading_list' => $taxonomy_object->labels->items_list, - ) + ] ); $wp_list_table->prepare_items(); @@ -1998,9 +1998,9 @@ public static function render_post_filters( $post_type, $which ) { * @return string The URL to recheck the post. */ public static function get_recheck_url( $url_or_post ) { - $args = array( + $args = [ 'action' => self::VALIDATE_ACTION, - ); + ]; if ( is_string( $url_or_post ) ) { $args['url'] = $url_or_post; } elseif ( $url_or_post instanceof WP_Post && self::POST_TYPE_SLUG === $url_or_post->post_type ) { @@ -2022,15 +2022,15 @@ public static function get_recheck_url( $url_or_post ) { public static function filter_dashboard_glance_items( $items ) { $query = new WP_Query( - array( + [ 'post_type' => self::POST_TYPE_SLUG, - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => array( + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => [ AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, - ), + ], 'update_post_meta_cache' => false, 'update_post_term_cache' => false, - ) + ] ); if ( 0 !== $query->found_posts ) { @@ -2039,13 +2039,13 @@ public static function filter_dashboard_glance_items( $items ) { esc_url( admin_url( add_query_arg( - array( + [ 'post_type' => self::POST_TYPE_SLUG, - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => array( + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => [ AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, - ), - ), + ], + ], 'edit.php' ) ) @@ -2235,7 +2235,7 @@ public static function filter_bulk_post_updated_messages( $messages, $bulk_count if ( get_current_screen()->id === sprintf( 'edit-%s', self::POST_TYPE_SLUG ) ) { $messages['post'] = array_merge( $messages['post'], - array( + [ /* translators: %s is the number of posts forgotten */ 'deleted' => _n( '%s validated URL forgotten.', @@ -2257,7 +2257,7 @@ public static function filter_bulk_post_updated_messages( $messages, $bulk_count $bulk_counts['untrashed'], 'amp' ), - ) + ] ); } @@ -2291,7 +2291,7 @@ public static function is_amp_enabled_on_post( $post ) { */ protected static function count_invalid_url_validation_errors( $validation_errors ) { $counts = array_fill_keys( - array( 'new_accepted', 'ack_accepted', 'new_rejected', 'ack_rejected' ), + [ 'new_accepted', 'ack_accepted', 'new_rejected', 'ack_rejected' ], 0 ); foreach ( $validation_errors as $error ) { diff --git a/includes/validation/class-amp-validation-callback-wrapper.php b/includes/validation/class-amp-validation-callback-wrapper.php index a9c03c162dd..e18b20f6d71 100644 --- a/includes/validation/class-amp-validation-callback-wrapper.php +++ b/includes/validation/class-amp-validation-callback-wrapper.php @@ -46,11 +46,11 @@ public function __invoke() { $accepted_args = $this->callback['accepted_args']; $args = func_get_args(); - $before_styles_enqueued = array(); + $before_styles_enqueued = []; if ( isset( $wp_styles, $wp_styles->queue ) ) { $before_styles_enqueued = $wp_styles->queue; } - $before_scripts_enqueued = array(); + $before_scripts_enqueued = []; if ( isset( $wp_scripts, $wp_scripts->queue ) ) { $before_scripts_enqueued = $wp_scripts->queue; } @@ -61,7 +61,7 @@ public function __invoke() { AMP_Validation_Manager::$hook_source_stack[] = $this->callback['source']; $has_buffer_started = false; if ( ! $is_filter && AMP_Validation_Manager::can_output_buffer() ) { - $has_buffer_started = ob_start( array( 'AMP_Validation_Manager', 'wrap_buffer_with_source_comments' ) ); + $has_buffer_started = ob_start( [ 'AMP_Validation_Manager', 'wrap_buffer_with_source_comments' ] ); } $result = call_user_func_array( $function, array_slice( $args, 0, (int) $accepted_args ) ); if ( $has_buffer_started ) { @@ -79,7 +79,7 @@ public function __invoke() { // Keep track of which source enqueued the scripts, and immediately report validity. if ( isset( $wp_scripts, $wp_scripts->queue ) ) { foreach ( array_diff( $wp_scripts->queue, $before_scripts_enqueued ) as $queued_handle ) { - $handles = array( $queued_handle ); + $handles = [ $queued_handle ]; // Account for case where registered script is a placeholder for a set of scripts (e.g. jquery). if ( isset( $wp_scripts->registered[ $queued_handle ] ) && false === $wp_scripts->registered[ $queued_handle ]->src ) { diff --git a/includes/validation/class-amp-validation-error-taxonomy.php b/includes/validation/class-amp-validation-error-taxonomy.php index 4550da7045d..cb0a98bcea8 100644 --- a/includes/validation/class-amp-validation-error-taxonomy.php +++ b/includes/validation/class-amp-validation-error-taxonomy.php @@ -233,8 +233,8 @@ public static function register() { register_taxonomy( self::TAXONOMY_SLUG, AMP_Validated_URL_Post_Type::POST_TYPE_SLUG, - array( - 'labels' => array( + [ + 'labels' => [ 'name' => _x( 'AMP Validation Error Index', 'taxonomy general name', 'amp' ), 'singular_name' => _x( 'AMP Validation Error', 'taxonomy singular name', 'amp' ), 'search_items' => __( 'Search AMP Validation Errors', 'amp' ), @@ -253,7 +253,7 @@ public static function register() { 'items_list' => __( 'Validation errors list', 'amp' ), /* translators: Tab heading when selecting from the most used terms */ 'most_used' => __( 'Most Used Validation Errors', 'amp' ), - ), + ], 'public' => false, 'show_ui' => true, // @todo False because we need a custom UI. 'show_tagcloud' => false, @@ -261,12 +261,12 @@ public static function register() { 'hierarchical' => false, // Or true? Code could be the parent term? 'show_in_menu' => self::should_show_in_menu() || AMP_Validated_URL_Post_Type::should_show_in_menu(), 'meta_box_cb' => false, - 'capabilities' => array( + 'capabilities' => [ // Note that delete_terms is needed so the checkbox (cb) table column will work. 'assign_terms' => 'do_not_allow', 'edit_terms' => 'do_not_allow', - ), - ) + ], + ] ); if ( is_admin() ) { @@ -361,12 +361,12 @@ public static function delete_empty_terms() { * } * @return int|int[]|null Returns an integer unless the multiple option is passed. Null if invalid. */ - public static function sanitize_term_status( $status, $options = array() ) { + public static function sanitize_term_status( $status, $options = [] ) { $multiple = ! empty( $options['multiple'] ); // Catch case where an empty string is supplied. Prevent casting to 0. if ( ! is_numeric( $status ) && empty( $status ) ) { - return $multiple ? array() : null; + return $multiple ? [] : null; } if ( is_string( $status ) ) { @@ -376,12 +376,12 @@ public static function sanitize_term_status( $status, $options = array() ) { } $statuses = array_intersect( - array( + [ self::VALIDATION_ERROR_NEW_REJECTED_STATUS, self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, self::VALIDATION_ERROR_ACK_REJECTED_STATUS, - ), + ], $statuses ); $statuses = array_values( array_unique( $statuses ) ); @@ -418,11 +418,11 @@ public static function prepare_validation_error_taxonomy_term( $error ) { ksort( $error ); $description = wp_json_encode( $error ); $term_slug = md5( $description ); - return array( + return [ 'slug' => $term_slug, 'name' => $term_slug, 'description' => $description, - ); + ]; } /** @@ -457,12 +457,12 @@ public static function is_validation_error_sanitized( $error ) { public static function get_validation_error_sanitization( $error ) { $term_data = self::prepare_validation_error_taxonomy_term( $error ); $term = self::get_term( $term_data['slug'] ); - $statuses = array( + $statuses = [ self::VALIDATION_ERROR_NEW_REJECTED_STATUS, self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, self::VALIDATION_ERROR_ACK_REJECTED_STATUS, - ); + ]; if ( ! empty( $term ) && in_array( $term->term_group, $statuses, true ) ) { $term_status = $term->term_group; } else { @@ -576,17 +576,17 @@ public static function is_array_subset( $superset, $subset ) { * } * @return int Term count. */ - public static function get_validation_error_count( $args = array() ) { + public static function get_validation_error_count( $args = [] ) { $args = array_merge( - array( + [ 'group' => null, - ), + ], $args ); $groups = null; if ( isset( $args['group'] ) ) { - $groups = self::sanitize_term_status( $args['group'], array( 'multiple' => true ) ); + $groups = self::sanitize_term_status( $args['group'], [ 'multiple' => true ] ); } $filter = static function( $clauses ) use ( $groups ) { @@ -625,9 +625,9 @@ public static function filter_posts_where_for_validation_error_status( $where, W return $where; } - $error_statuses = array(); + $error_statuses = []; if ( false !== $query->get( self::VALIDATION_ERROR_STATUS_QUERY_VAR, false ) ) { - $error_statuses = self::sanitize_term_status( $query->get( self::VALIDATION_ERROR_STATUS_QUERY_VAR ), array( 'multiple' => true ) ); + $error_statuses = self::sanitize_term_status( $query->get( self::VALIDATION_ERROR_STATUS_QUERY_VAR ), [ 'multiple' => true ] ); } $error_type = sanitize_key( $query->get( self::VALIDATION_ERROR_TYPE_QUERY_VAR ) ); @@ -683,10 +683,10 @@ public static function filter_posts_where_for_validation_error_status( $where, W * @return array The AMP validity of the markup. */ public static function summarize_validation_errors( $validation_errors ) { - $results = array(); - $removed_elements = array(); - $removed_attributes = array(); - $invalid_sources = array(); + $results = []; + $removed_elements = []; + $removed_attributes = []; + $invalid_sources = []; foreach ( $validation_errors as $validation_error ) { $code = isset( $validation_error['code'] ) ? $validation_error['code'] : null; @@ -723,9 +723,9 @@ public static function summarize_validation_errors( $validation_errors ) { } $results = array_merge( - array( + [ self::SOURCES_INVALID_OUTPUT => $invalid_sources, - ), + ], compact( 'removed_elements', 'removed_attributes' @@ -740,36 +740,36 @@ public static function summarize_validation_errors( $validation_errors ) { * Add admin hooks. */ public static function add_admin_hooks() { - add_filter( 'redirect_term_location', array( __CLASS__, 'add_term_filter_query_var' ), 10, 2 ); - add_action( 'load-edit-tags.php', array( __CLASS__, 'add_group_terms_clauses_filter' ) ); - add_action( 'load-edit-tags.php', array( __CLASS__, 'add_error_type_clauses_filter' ) ); - add_action( 'load-post.php', array( __CLASS__, 'add_error_type_clauses_filter' ) ); - add_action( 'load-edit-tags.php', array( __CLASS__, 'add_order_clauses_from_description_json' ) ); - add_action( 'load-post.php', array( __CLASS__, 'add_order_clauses_from_description_json' ) ); - add_action( sprintf( 'after-%s-table', self::TAXONOMY_SLUG ), array( __CLASS__, 'render_taxonomy_filters' ) ); - add_action( sprintf( 'after-%s-table', self::TAXONOMY_SLUG ), array( __CLASS__, 'render_link_to_invalid_urls_screen' ) ); + add_filter( 'redirect_term_location', [ __CLASS__, 'add_term_filter_query_var' ], 10, 2 ); + add_action( 'load-edit-tags.php', [ __CLASS__, 'add_group_terms_clauses_filter' ] ); + add_action( 'load-edit-tags.php', [ __CLASS__, 'add_error_type_clauses_filter' ] ); + add_action( 'load-post.php', [ __CLASS__, 'add_error_type_clauses_filter' ] ); + add_action( 'load-edit-tags.php', [ __CLASS__, 'add_order_clauses_from_description_json' ] ); + add_action( 'load-post.php', [ __CLASS__, 'add_order_clauses_from_description_json' ] ); + add_action( sprintf( 'after-%s-table', self::TAXONOMY_SLUG ), [ __CLASS__, 'render_taxonomy_filters' ] ); + add_action( sprintf( 'after-%s-table', self::TAXONOMY_SLUG ), [ __CLASS__, 'render_link_to_invalid_urls_screen' ] ); add_action( 'load-edit-tags.php', static function() { - add_filter( 'user_has_cap', array( __CLASS__, 'filter_user_has_cap_for_hiding_term_list_table_checkbox' ), 10, 3 ); + add_filter( 'user_has_cap', [ __CLASS__, 'filter_user_has_cap_for_hiding_term_list_table_checkbox' ], 10, 3 ); } ); - add_filter( 'terms_clauses', array( __CLASS__, 'filter_terms_clauses_for_description_search' ), 10, 3 ); - add_action( 'admin_notices', array( __CLASS__, 'add_admin_notices' ) ); - add_filter( 'tag_row_actions', array( __CLASS__, 'filter_tag_row_actions' ), 10, 2 ); + add_filter( 'terms_clauses', [ __CLASS__, 'filter_terms_clauses_for_description_search' ], 10, 3 ); + add_action( 'admin_notices', [ __CLASS__, 'add_admin_notices' ] ); + add_filter( 'tag_row_actions', [ __CLASS__, 'filter_tag_row_actions' ], 10, 2 ); if ( get_taxonomy( self::TAXONOMY_SLUG )->show_in_menu ) { - add_action( 'admin_menu', array( __CLASS__, 'add_admin_menu_validation_error_item' ) ); - } - add_action( 'parse_term_query', array( __CLASS__, 'parse_post_php_term_query' ) ); - add_filter( 'manage_' . self::TAXONOMY_SLUG . '_custom_column', array( __CLASS__, 'filter_manage_custom_columns' ), 10, 3 ); - add_filter( 'manage_' . AMP_Validated_URL_Post_Type::POST_TYPE_SLUG . '_sortable_columns', array( __CLASS__, 'add_single_post_sortable_columns' ) ); - add_filter( 'posts_where', array( __CLASS__, 'filter_posts_where_for_validation_error_status' ), 10, 2 ); - add_filter( 'post_action_' . self::VALIDATION_ERROR_REJECT_ACTION, array( __CLASS__, 'handle_single_url_page_bulk_and_inline_actions' ) ); - add_filter( 'post_action_' . self::VALIDATION_ERROR_ACCEPT_ACTION, array( __CLASS__, 'handle_single_url_page_bulk_and_inline_actions' ) ); - add_filter( 'handle_bulk_actions-edit-' . self::TAXONOMY_SLUG, array( __CLASS__, 'handle_validation_error_update' ), 10, 3 ); - add_action( 'load-edit-tags.php', array( __CLASS__, 'handle_inline_edit_request' ) ); - add_action( 'load-edit-tags.php', array( __CLASS__, 'handle_clear_empty_terms_request' ) ); - add_action( 'load-edit.php', array( __CLASS__, 'handle_inline_edit_request' ) ); + add_action( 'admin_menu', [ __CLASS__, 'add_admin_menu_validation_error_item' ] ); + } + add_action( 'parse_term_query', [ __CLASS__, 'parse_post_php_term_query' ] ); + add_filter( 'manage_' . self::TAXONOMY_SLUG . '_custom_column', [ __CLASS__, 'filter_manage_custom_columns' ], 10, 3 ); + add_filter( 'manage_' . AMP_Validated_URL_Post_Type::POST_TYPE_SLUG . '_sortable_columns', [ __CLASS__, 'add_single_post_sortable_columns' ] ); + add_filter( 'posts_where', [ __CLASS__, 'filter_posts_where_for_validation_error_status' ], 10, 2 ); + add_filter( 'post_action_' . self::VALIDATION_ERROR_REJECT_ACTION, [ __CLASS__, 'handle_single_url_page_bulk_and_inline_actions' ] ); + add_filter( 'post_action_' . self::VALIDATION_ERROR_ACCEPT_ACTION, [ __CLASS__, 'handle_single_url_page_bulk_and_inline_actions' ] ); + add_filter( 'handle_bulk_actions-edit-' . self::TAXONOMY_SLUG, [ __CLASS__, 'handle_validation_error_update' ], 10, 3 ); + add_action( 'load-edit-tags.php', [ __CLASS__, 'handle_inline_edit_request' ] ); + add_action( 'load-edit-tags.php', [ __CLASS__, 'handle_clear_empty_terms_request' ] ); + add_action( 'load-edit.php', [ __CLASS__, 'handle_inline_edit_request' ] ); // Prevent query vars from persisting after redirect. add_filter( @@ -797,7 +797,7 @@ static function( $query_vars ) { add_filter( 'get_terms_defaults', static function( $args, $taxonomies ) { - if ( array( AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ) === $taxonomies ) { + if ( [ AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] === $taxonomies ) { $args['orderby'] = 'term_id'; $args['order'] = 'DESC'; } @@ -823,7 +823,7 @@ static function( $bulk_actions ) { 'manage_edit-' . self::TAXONOMY_SLUG . '_columns', static function( $old_columns ) { - return array( + return [ 'cb' => $old_columns['cb'], 'error' => esc_html__( 'Error', 'amp' ), 'status' => sprintf( @@ -851,7 +851,7 @@ static function( $old_columns ) { 'error_type' => esc_html__( 'Type', 'amp' ), 'created_date_gmt' => esc_html__( 'Last Seen', 'amp' ), 'posts' => esc_html__( 'Found URLs', 'amp' ), - ); + ]; } ); @@ -892,19 +892,19 @@ static function() { wp_register_style( 'amp-validation-tooltips', amp_get_asset_url( 'css/amp-validation-tooltips.css' ), - array( 'wp-pointer' ), + [ 'wp-pointer' ], AMP__VERSION ); $script_deps_path = AMP__DIR__ . '/assets/js/amp-validation-tooltips.deps.json'; $script_dependencies = file_exists( $script_deps_path ) ? json_decode( file_get_contents( $script_deps_path ), false ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - : array(); + : []; wp_register_script( 'amp-validation-tooltips', amp_get_asset_url( 'js/amp-validation-tooltips.js' ), - array_merge( $script_dependencies, array( 'wp-pointer' ) ), + array_merge( $script_dependencies, [ 'wp-pointer' ] ), AMP__VERSION, true ); @@ -912,14 +912,14 @@ static function() { wp_enqueue_style( 'amp-validation-error-taxonomy', amp_get_asset_url( 'css/amp-validation-error-taxonomy.css' ), - array( 'common', 'amp-validation-tooltips' ), + [ 'common', 'amp-validation-tooltips' ], AMP__VERSION ); wp_enqueue_script( 'amp-validation-detail-toggle', amp_get_asset_url( 'js/amp-validation-detail-toggle.js' ), - array( 'wp-dom-ready', 'wp-i18n', 'amp-validation-tooltips' ), + [ 'wp-dom-ready', 'wp-i18n', 'amp-validation-tooltips' ], AMP__VERSION, true ); @@ -929,14 +929,14 @@ static function() { wp_enqueue_style( 'amp-validation-single-error-url', amp_get_asset_url( 'css/amp-validation-single-error-url.css' ), - array( 'common' ), + [ 'common' ], AMP__VERSION ); $script_deps_path = AMP__DIR__ . '/assets/js/amp-validation-single-error-url-details.deps.json'; $script_dependencies = file_exists( $script_deps_path ) ? json_decode( file_get_contents( $script_deps_path ), false ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - : array(); + : []; wp_enqueue_script( 'amp-validation-single-error-url-details', @@ -1007,7 +1007,7 @@ public static function add_term_filter_query_var( $url, $tax ) { && in_array( $_POST[ self::VALIDATION_ERROR_TYPE_QUERY_VAR ], // phpcs:ignore WordPress.Security.NonceVerification.Missing - array_merge( self::get_error_types(), array( (string) self::NO_FILTER_VALUE ) ), + array_merge( self::get_error_types(), [ (string) self::NO_FILTER_VALUE ] ), true ) ) { @@ -1019,13 +1019,13 @@ public static function add_term_filter_query_var( $url, $tax ) { } // If the error status query var is valid, pass it along in the redirect $url. - $groups = array(); + $groups = []; if ( isset( $_POST[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing - $groups = self::sanitize_term_status( wp_unslash( $_POST[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ] ), array( 'multiple' => true ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing + $groups = self::sanitize_term_status( wp_unslash( $_POST[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ] ), [ 'multiple' => true ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing } if ( ! empty( $groups ) ) { $url = add_query_arg( - array( self::VALIDATION_ERROR_STATUS_QUERY_VAR => $groups ), + [ self::VALIDATION_ERROR_STATUS_QUERY_VAR => $groups ], $url ); } else { @@ -1043,7 +1043,7 @@ public static function add_group_terms_clauses_filter() { return; } self::$should_filter_terms_clauses_for_error_validation_status = true; - $groups = self::sanitize_term_status( wp_unslash( $_GET[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ] ), array( 'multiple' => true ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $groups = self::sanitize_term_status( wp_unslash( $_GET[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ] ), [ 'multiple' => true ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( empty( $groups ) ) { return; } @@ -1103,10 +1103,10 @@ public static function add_order_clauses_from_description_json() { return; } - $sortable_column_vars = array( + $sortable_column_vars = [ self::VALIDATION_ERROR_TYPE_QUERY_VAR, self::VALIDATION_DETAILS_ERROR_CODE_QUERY_VAR, - ); + ]; if ( ! isset( $_GET['orderby'] ) || ! in_array( $_GET['orderby'], $sortable_column_vars, true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; @@ -1167,7 +1167,7 @@ public static function render_taxonomy_filters( $taxonomy_name ) { 'doaction' ) ); + submit_button( __( 'Apply Filter', 'amp' ), '', 'filter_action', false, [ 'id' => 'doaction' ] ); self::render_clear_empty_button(); ?>
@@ -1241,16 +1241,16 @@ public static function render_error_status_filter() { if ( 'edit-tags' === $screen_base ) { $total_term_count = self::get_validation_error_count(); - $ack_rejected_term_count = self::get_validation_error_count( array( 'group' => array( self::VALIDATION_ERROR_ACK_REJECTED_STATUS ) ) ); - $ack_accepted_term_count = self::get_validation_error_count( array( 'group' => array( self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS ) ) ); + $ack_rejected_term_count = self::get_validation_error_count( [ 'group' => [ self::VALIDATION_ERROR_ACK_REJECTED_STATUS ] ] ); + $ack_accepted_term_count = self::get_validation_error_count( [ 'group' => [ self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS ] ] ); $new_term_count = $total_term_count - $ack_rejected_term_count - $ack_accepted_term_count; } elseif ( 'edit' === $screen_base ) { - $args = array( + $args = [ 'post_type' => AMP_Validated_URL_Post_Type::POST_TYPE_SLUG, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, - ); + ]; $error_type = sanitize_key( $wp_query->get( self::VALIDATION_ERROR_TYPE_QUERY_VAR ) ); if ( $error_type && in_array( $error_type, self::get_error_types(), true ) ) { @@ -1260,12 +1260,12 @@ public static function render_error_status_filter() { $with_new_query = new WP_Query( array_merge( $args, - array( - self::VALIDATION_ERROR_STATUS_QUERY_VAR => array( + [ + self::VALIDATION_ERROR_STATUS_QUERY_VAR => [ self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, self::VALIDATION_ERROR_NEW_REJECTED_STATUS, - ), - ) + ], + ] ) ); $new_term_count = $with_new_query->found_posts; @@ -1273,7 +1273,7 @@ public static function render_error_status_filter() { $with_rejected_query = new WP_Query( array_merge( $args, - array( self::VALIDATION_ERROR_STATUS_QUERY_VAR => self::VALIDATION_ERROR_ACK_REJECTED_STATUS ) + [ self::VALIDATION_ERROR_STATUS_QUERY_VAR => self::VALIDATION_ERROR_ACK_REJECTED_STATUS ] ) ); $ack_rejected_term_count = $with_rejected_query->found_posts; @@ -1281,7 +1281,7 @@ public static function render_error_status_filter() { $with_accepted_query = new WP_Query( array_merge( $args, - array( self::VALIDATION_ERROR_STATUS_QUERY_VAR => self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS ) + [ self::VALIDATION_ERROR_STATUS_QUERY_VAR => self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS ] ) ); $ack_accepted_term_count = $with_accepted_query->found_posts; @@ -1289,9 +1289,9 @@ public static function render_error_status_filter() { return; } - $selected_groups = array(); + $selected_groups = []; if ( isset( $_GET[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $selected_groups = self::sanitize_term_status( $_GET[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ], array( 'multiple' => true ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $selected_groups = self::sanitize_term_status( $_GET[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ], [ 'multiple' => true ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } if ( ! empty( $selected_groups ) ) { sort( $selected_groups ); @@ -1401,7 +1401,7 @@ public static function render_error_status_filter() { * @return array Error types. */ public static function get_error_types() { - return array( self::HTML_ELEMENT_ERROR_TYPE, self::HTML_ATTRIBUTE_ERROR_TYPE, self::JS_ERROR_TYPE, self::CSS_ERROR_TYPE ); + return [ self::HTML_ELEMENT_ERROR_TYPE, self::HTML_ATTRIBUTE_ERROR_TYPE, self::JS_ERROR_TYPE, self::CSS_ERROR_TYPE ]; } /** @@ -1608,10 +1608,10 @@ public static function filter_tag_row_actions( $actions, WP_Term $tag ) { '%s', admin_url( add_query_arg( - array( + [ self::TAXONOMY_SLUG => $term->name, 'post_type' => AMP_Validated_URL_Post_Type::POST_TYPE_SLUG, - ), + ], 'edit.php' ) ), @@ -1626,7 +1626,7 @@ public static function filter_tag_row_actions( $actions, WP_Term $tag ) { $actions[ self::VALIDATION_ERROR_REJECT_ACTION ] = sprintf( '%s', wp_nonce_url( - add_query_arg( array_merge( array( 'action' => self::VALIDATION_ERROR_REJECT_ACTION ), compact( 'term_id' ) ) ), + add_query_arg( array_merge( [ 'action' => self::VALIDATION_ERROR_REJECT_ACTION ], compact( 'term_id' ) ) ), self::VALIDATION_ERROR_REJECT_ACTION ), esc_html__( 'Reject', 'amp' ) @@ -1636,7 +1636,7 @@ public static function filter_tag_row_actions( $actions, WP_Term $tag ) { $actions[ self::VALIDATION_ERROR_ACCEPT_ACTION ] = sprintf( '%s', wp_nonce_url( - add_query_arg( array_merge( array( 'action' => self::VALIDATION_ERROR_ACCEPT_ACTION ), compact( 'term_id' ) ) ), + add_query_arg( array_merge( [ 'action' => self::VALIDATION_ERROR_ACCEPT_ACTION ], compact( 'term_id' ) ) ), self::VALIDATION_ERROR_ACCEPT_ACTION ), esc_html__( 'Accept', 'amp' ) @@ -1652,9 +1652,9 @@ public static function filter_tag_row_actions( $actions, WP_Term $tag ) { public static function add_admin_menu_validation_error_item() { $menu_item_label = esc_html__( 'Error Index', 'amp' ); $new_error_count = self::get_validation_error_count( - array( - 'group' => array( self::VALIDATION_ERROR_NEW_REJECTED_STATUS, self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS ), - ) + [ + 'group' => [ self::VALIDATION_ERROR_NEW_REJECTED_STATUS, self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS ], + ] ); if ( $new_error_count ) { $menu_item_label .= ' ' . esc_html( number_format_i18n( $new_error_count ) ) . ''; @@ -1768,10 +1768,10 @@ public static function filter_manage_custom_columns( $content, $column_name, $te '%s', admin_url( add_query_arg( - array( + [ self::TAXONOMY_SLUG => $term->name, 'post_type' => AMP_Validated_URL_Post_Type::POST_TYPE_SLUG, - ), + ], 'edit.php' ) ), @@ -1906,7 +1906,7 @@ public static function filter_manage_custom_columns( $content, $column_name, $te unset( $validation_error['error_type'], $validation_error['parent_name'] ); - $attributes = array(); + $attributes = []; $attributes_heading = ''; if ( ! empty( $validation_error['node_attributes'] ) ) { $attributes_heading = sprintf( '
%s
', esc_html__( 'Element attributes:', 'amp' ) ); @@ -1986,10 +1986,10 @@ static function( $error ) use ( $term ) { public static function add_single_post_sortable_columns( $sortable_columns ) { return array_merge( $sortable_columns, - array( + [ 'error' => self::VALIDATION_DETAILS_ERROR_CODE_QUERY_VAR, 'error_type' => self::VALIDATION_ERROR_TYPE_QUERY_VAR, - ) + ] ); } @@ -2099,12 +2099,12 @@ public static function get_translated_type_name( $validation_error ) { return null; } - $translated_names = array( + $translated_names = [ self::HTML_ELEMENT_ERROR_TYPE => __( 'HTML Element', 'amp' ), self::HTML_ATTRIBUTE_ERROR_TYPE => __( 'HTML Attribute', 'amp' ), self::JS_ERROR_TYPE => __( 'JavaScript', 'amp' ), self::CSS_ERROR_TYPE => __( 'CSS', 'amp' ), - ); + ]; if ( isset( $translated_names[ $validation_error['type'] ] ) ) { return $translated_names[ $validation_error['type'] ]; @@ -2140,7 +2140,7 @@ public static function handle_inline_edit_request() { $referer = wp_get_referer(); $term_id = (int) $_GET['term_id']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $redirect = self::handle_validation_error_update( $referer, $action, array( $term_id ) ); + $redirect = self::handle_validation_error_update( $referer, $action, [ $term_id ] ); if ( $redirect !== $referer ) { wp_safe_redirect( $redirect ); @@ -2165,10 +2165,10 @@ public static function handle_single_url_page_bulk_and_inline_actions( $post_id $action = sanitize_key( $_REQUEST['action'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $term_ids = isset( $_POST['delete_tags'] ) ? array_map( 'sanitize_key', $_POST['delete_tags'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing $single_term_id = isset( $_GET['term_id'] ) ? sanitize_key( $_GET['term_id'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $redirect_query_args = array( + $redirect_query_args = [ 'action' => 'edit', 'amp_actioned' => $action, - ); + ]; if ( $term_ids ) { // If this is a bulk action. @@ -2176,7 +2176,7 @@ public static function handle_single_url_page_bulk_and_inline_actions( $post_id $redirect_query_args['amp_actioned_count'] = count( $term_ids ); } elseif ( $single_term_id ) { // If this is an inline action, like 'Reject' or 'Accept'. - self::handle_validation_error_update( null, $action, array( $single_term_id ) ); + self::handle_validation_error_update( null, $action, [ $single_term_id ] ); $redirect_query_args['amp_actioned_count'] = 1; } @@ -2219,10 +2219,10 @@ public static function handle_validation_error_update( $redirect_to, $action, $t add_filter( 'pre_term_description', 'wp_filter_kses', $has_pre_term_description_filter ); } $redirect_to = add_query_arg( - array( + [ 'amp_actioned' => $action, 'amp_actioned_count' => count( $term_ids ), - ), + ], $redirect_to ); } diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index f47b668293f..0d243baf667 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -63,21 +63,21 @@ class AMP_Validation_Manager { * @type string $slug Hash of the error. * } */ - public static $validation_results = array(); + public static $validation_results = []; /** * Sources that enqueue each script. * * @var array */ - public static $enqueued_script_sources = array(); + public static $enqueued_script_sources = []; /** * Sources that enqueue each style. * * @var array */ - public static $enqueued_style_sources = array(); + public static $enqueued_style_sources = []; /** * Post IDs for posts that have been updated which need to be re-validated. @@ -86,7 +86,7 @@ class AMP_Validation_Manager { * * @var bool[] */ - public static $posts_pending_frontend_validation = array(); + public static $posts_pending_frontend_validation = []; /** * Current sources gathered for a given hook currently being run. @@ -95,7 +95,7 @@ class AMP_Validation_Manager { * @see AMP_Validation_Manager::decorate_filter_source() * @var array[] */ - protected static $current_hook_source_stack = array(); + protected static $current_hook_source_stack = []; /** * Index for where block appears in a post's content. @@ -112,7 +112,7 @@ class AMP_Validation_Manager { * @since 0.7 * @var array[] */ - public static $hook_source_stack = array(); + public static $hook_source_stack = []; /** * Whether validation error sources should be located. @@ -126,7 +126,7 @@ class AMP_Validation_Manager { * * @var array */ - public static $validation_error_status_overrides = array(); + public static $validation_error_status_overrides = []; /** * Whether the admin bar item was added for AMP. @@ -177,11 +177,11 @@ class AMP_Validation_Manager { * } * @return void */ - public static function init( $args = array() ) { + public static function init( $args = [] ) { $args = array_merge( - array( + [ 'should_locate_sources' => self::should_validate_response(), - ), + ], $args ); @@ -195,10 +195,10 @@ public static function init( $args = array() ) { return; } - add_action( 'save_post', array( __CLASS__, 'handle_save_post_prompting_validation' ) ); - add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_validation' ) ); - add_action( 'edit_form_top', array( __CLASS__, 'print_edit_form_validation_status' ), 10, 2 ); - add_action( 'rest_api_init', array( __CLASS__, 'add_rest_api_fields' ) ); + add_action( 'save_post', [ __CLASS__, 'handle_save_post_prompting_validation' ] ); + add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'enqueue_block_validation' ] ); + add_action( 'edit_form_top', [ __CLASS__, 'print_edit_form_validation_status' ], 10, 2 ); + add_action( 'rest_api_init', [ __CLASS__, 'add_rest_api_fields' ] ); // Add actions for checking theme support is present to determine plugin compatibility and show validation links in the admin bar. if ( AMP_Options_Manager::is_website_experience_enabled() && current_theme_supports( AMP_Theme_Support::SLUG ) ) { @@ -206,8 +206,8 @@ public static function init( $args = array() ) { add_action( 'activate_plugin', function() { - if ( ! has_action( 'shutdown', array( __CLASS__, 'validate_after_plugin_activation' ) ) ) { - add_action( 'shutdown', array( __CLASS__, 'validate_after_plugin_activation' ) ); // Shutdown so all plugins will have been activated. + if ( ! has_action( 'shutdown', [ __CLASS__, 'validate_after_plugin_activation' ] ) ) { + add_action( 'shutdown', [ __CLASS__, 'validate_after_plugin_activation' ] ); // Shutdown so all plugins will have been activated. } } ); @@ -221,9 +221,9 @@ function( $query_vars ) { } ); - add_action( 'all_admin_notices', array( __CLASS__, 'print_plugin_notice' ) ); + add_action( 'all_admin_notices', [ __CLASS__, 'print_plugin_notice' ] ); - add_action( 'admin_bar_menu', array( __CLASS__, 'add_admin_bar_menu_items' ), 101 ); + add_action( 'admin_bar_menu', [ __CLASS__, 'add_admin_bar_menu_items' ], 101 ); } if ( self::$should_locate_sources ) { @@ -350,10 +350,10 @@ public static function add_admin_bar_menu_items( $wp_admin_bar ) { $amp_url = remove_query_arg( array_merge( wp_removable_query_args(), - array( + [ self::VALIDATE_QUERY_VAR, 'amp_preserve_source_comments', - ) + ] ), $current_url ); @@ -405,7 +405,7 @@ public static function add_admin_bar_menu_items( $wp_admin_bar ) { $icon = '🔗'; // LINK SYMBOL. $href = $amp_url; } - $parent = array( + $parent = [ 'id' => 'amp', 'title' => sprintf( '%s %s', @@ -413,14 +413,14 @@ public static function add_admin_bar_menu_items( $wp_admin_bar ) { esc_html__( 'AMP', 'amp' ) ), 'href' => esc_url( $href ), - ); + ]; // Construct admin bar item for validation. - $validate_item = array( + $validate_item = [ 'parent' => 'amp', 'id' => 'amp-validity', 'href' => esc_url( $validate_url ), - ); + ]; if ( $error_count <= 0 ) { $validate_item['title'] = esc_html__( 'Re-validate', 'amp' ); } else { @@ -439,12 +439,12 @@ public static function add_admin_bar_menu_items( $wp_admin_bar ) { } // Construct admin bar item to link to AMP version or non-AMP version. - $link_item = array( + $link_item = [ 'parent' => 'amp', 'id' => 'amp-view', 'title' => esc_html( is_amp_endpoint() ? __( 'View non-AMP version', 'amp' ) : __( 'View AMP version', 'amp' ) ), 'href' => esc_url( is_amp_endpoint() ? $non_amp_url : $amp_url ), - ); + ]; // Add admin bar item to switch between AMP and non-AMP if parent node is also an AMP link. $is_single_version_available = ( @@ -529,16 +529,16 @@ public static function add_validation_error_sourcing() { self::$stylesheet_directory = wp_normalize_path( get_stylesheet_directory() ); self::$stylesheet_slug = get_stylesheet(); - add_action( 'wp', array( __CLASS__, 'wrap_widget_callbacks' ) ); + add_action( 'wp', [ __CLASS__, 'wrap_widget_callbacks' ] ); - add_action( 'all', array( __CLASS__, 'wrap_hook_callbacks' ) ); - $wrapped_filters = array( 'the_content', 'the_excerpt' ); + add_action( 'all', [ __CLASS__, 'wrap_hook_callbacks' ] ); + $wrapped_filters = [ 'the_content', 'the_excerpt' ]; foreach ( $wrapped_filters as $wrapped_filter ) { - add_filter( $wrapped_filter, array( __CLASS__, 'decorate_filter_source' ), PHP_INT_MAX ); + add_filter( $wrapped_filter, [ __CLASS__, 'decorate_filter_source' ], PHP_INT_MAX ); } - add_filter( 'do_shortcode_tag', array( __CLASS__, 'decorate_shortcode_source' ), PHP_INT_MAX, 2 ); - add_filter( 'embed_oembed_html', array( __CLASS__, 'decorate_embed_source' ), PHP_INT_MAX, 3 ); + add_filter( 'do_shortcode_tag', [ __CLASS__, 'decorate_shortcode_source' ], PHP_INT_MAX, 2 ); + add_filter( 'embed_oembed_html', [ __CLASS__, 'decorate_embed_source' ], PHP_INT_MAX, 3 ); $do_blocks_priority = has_filter( 'the_content', 'do_blocks' ); $is_gutenberg_active = ( @@ -547,7 +547,7 @@ public static function add_validation_error_sourcing() { class_exists( 'WP_Block_Type_Registry' ) ); if ( $is_gutenberg_active ) { - add_filter( 'the_content', array( __CLASS__, 'add_block_source_comments' ), $do_blocks_priority - 1 ); + add_filter( 'the_content', [ __CLASS__, 'add_block_source_comments' ], $do_blocks_priority - 1 ); } } @@ -588,8 +588,8 @@ public static function handle_save_post_prompting_validation( $post_id ) { self::$posts_pending_frontend_validation[ $post_id ] = true; // The reason for shutdown is to ensure that all postmeta changes have been saved, including whether AMP is enabled. - if ( ! has_action( 'shutdown', array( __CLASS__, 'validate_queued_posts_on_frontend' ) ) ) { - add_action( 'shutdown', array( __CLASS__, 'validate_queued_posts_on_frontend' ) ); + if ( ! has_action( 'shutdown', [ __CLASS__, 'validate_queued_posts_on_frontend' ] ) ) { + add_action( 'shutdown', [ __CLASS__, 'validate_queued_posts_on_frontend' ] ); } } } @@ -609,7 +609,7 @@ function( $post ) { } ); - $validation_posts = array(); + $validation_posts = []; /* * It is unlikely that there will be more than one post in the array. @@ -635,10 +635,10 @@ function( $post ) { wp_list_pluck( $validity['results'], 'error' ), $validity['url'], array_merge( - array( + [ 'invalid_url_post' => $invalid_url_post_id, - ), - wp_array_slice_assoc( $validity, array( 'queried_object' ) ) + ], + wp_array_slice_assoc( $validity, [ 'queried_object' ] ) ) ); @@ -659,16 +659,16 @@ function( $post ) { */ public static function add_rest_api_fields() { if ( ! current_theme_supports( AMP_Theme_Support::SLUG ) ) { - $object_types = array( AMP_Story_Post_Type::POST_TYPE_SLUG ); // Eventually validation should be done in Reader mode as well, but for now, limit to stories. + $object_types = [ AMP_Story_Post_Type::POST_TYPE_SLUG ]; // Eventually validation should be done in Reader mode as well, but for now, limit to stories. } elseif ( amp_is_canonical() ) { $object_types = get_post_types_by_support( 'editor' ); // @todo Shouldn't this actually only be those with 'amp' support, or if if all_templates_supported? } else { $object_types = array_intersect( get_post_types_by_support( 'amp' ), get_post_types( - array( + [ 'show_in_rest' => true, - ) + ] ) ); } @@ -676,13 +676,13 @@ public static function add_rest_api_fields() { register_rest_field( $object_types, self::VALIDITY_REST_FIELD_NAME, - array( - 'get_callback' => array( __CLASS__, 'get_amp_validity_rest_field' ), - 'schema' => array( + [ + 'get_callback' => [ __CLASS__, 'get_amp_validity_rest_field' ], + 'schema' => [ 'description' => __( 'AMP validity status', 'amp' ), 'type' => 'object', - ), - ) + ], + ] ); } @@ -704,7 +704,7 @@ public static function get_amp_validity_rest_field( $post_data, $field_name, $re $post = get_post( $post_data['id'] ); $validation_status_post = null; - if ( in_array( $request->get_method(), array( 'PUT', 'POST' ), true ) ) { + if ( in_array( $request->get_method(), [ 'PUT', 'POST' ], true ) ) { if ( ! isset( self::$posts_pending_frontend_validation[ $post->ID ] ) ) { self::$posts_pending_frontend_validation[ $post->ID ] = true; } @@ -718,21 +718,21 @@ public static function get_amp_validity_rest_field( $post_data, $field_name, $re $validation_status_post = AMP_Validated_URL_Post_Type::get_invalid_url_post( amp_get_permalink( $post->ID ) ); } - $field = array( - 'results' => array(), + $field = [ + 'results' => [], 'review_link' => null, - ); + ]; if ( $validation_status_post ) { $field['review_link'] = get_edit_post_link( $validation_status_post->ID, 'raw' ); foreach ( AMP_Validated_URL_Post_Type::get_invalid_url_validation_errors( $validation_status_post ) as $result ) { - $field['results'][] = array( + $field['results'][] = [ 'sanitized' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $result['status'], 'error' => $result['data'], 'status' => $result['status'], 'term_status' => $result['term_status'], 'forced' => $result['forced'], - ); + ]; } } @@ -758,7 +758,7 @@ public static function has_cap() { * * @return bool Whether the validation error should result in sanitization. */ - public static function add_validation_error( array $error, array $data = array() ) { + public static function add_validation_error( array $error, array $data = [] ) { $node = null; $matches = null; $sources = null; @@ -838,9 +838,9 @@ public static function add_validation_error( array $error, array $data = array() * @return void */ public static function reset_validation_results() { - self::$validation_results = array(); - self::$enqueued_style_sources = array(); - self::$enqueued_script_sources = array(); + self::$validation_results = []; + self::$enqueued_style_sources = []; + self::$enqueued_script_sources = []; } /** @@ -864,7 +864,7 @@ public static function print_edit_form_validation_status( $post ) { } // Show all validation errors which have not been explicitly acknowledged as accepted. - $validation_errors = array(); + $validation_errors = []; $has_rejected_error = false; foreach ( AMP_Validated_URL_Post_Type::get_invalid_url_validation_errors( $invalid_url_post ) as $error ) { $needs_moderation = ( @@ -921,23 +921,23 @@ public static function print_edit_form_validation_status( $post ) { echo '

'; $results = AMP_Validation_Error_Taxonomy::summarize_validation_errors( array_unique( $validation_errors, SORT_REGULAR ) ); - $removed_sets = array(); + $removed_sets = []; if ( ! empty( $results[ AMP_Validation_Error_Taxonomy::REMOVED_ELEMENTS ] ) && is_array( $results[ AMP_Validation_Error_Taxonomy::REMOVED_ELEMENTS ] ) ) { - $removed_sets[] = array( + $removed_sets[] = [ 'label' => __( 'Invalid elements:', 'amp' ), 'names' => array_map( 'sanitize_key', $results[ AMP_Validation_Error_Taxonomy::REMOVED_ELEMENTS ] ), - ); + ]; } if ( ! empty( $results[ AMP_Validation_Error_Taxonomy::REMOVED_ATTRIBUTES ] ) && is_array( $results[ AMP_Validation_Error_Taxonomy::REMOVED_ATTRIBUTES ] ) ) { - $removed_sets[] = array( + $removed_sets[] = [ 'label' => __( 'Invalid attributes:', 'amp' ), 'names' => array_map( 'sanitize_key', $results[ AMP_Validation_Error_Taxonomy::REMOVED_ATTRIBUTES ] ), - ); + ]; } // @todo There are other kinds of errors other than REMOVED_ELEMENTS and REMOVED_ATTRIBUTES. foreach ( $removed_sets as $removed_set ) { printf( '

%s ', esc_html( $removed_set['label'] ) ); - $items = array(); + $items = []; foreach ( $removed_set['names'] as $name => $count ) { if ( 1 === (int) $count ) { $items[] = sprintf( '%s', esc_html( $name ) ); @@ -1001,8 +1001,8 @@ public static function parse_source_comment( DOMComment $comment ) { public static function locate_sources( DOMNode $node ) { $xpath = new DOMXPath( $node->ownerDocument ); $comments = $xpath->query( 'preceding::comment()[ starts-with( ., "amp-source-stack" ) or starts-with( ., "/amp-source-stack" ) ]', $node ); - $sources = array(); - $matches = array(); + $sources = []; + $matches = []; foreach ( $comments as $comment ) { $parsed_comment = self::parse_source_comment( $comment ); @@ -1102,7 +1102,7 @@ public static function locate_sources( DOMNode $node ) { */ public static function remove_source_comments( $dom ) { $xpath = new DOMXPath( $dom ); - $comments = array(); + $comments = []; foreach ( $xpath->query( '//comment()[ starts-with( ., "amp-source-stack" ) or starts-with( ., "/amp-source-stack" ) ]' ) as $comment ) { if ( self::parse_source_comment( $comment ) ) { $comments[] = $comment; @@ -1124,19 +1124,19 @@ public static function add_block_source_comments( $content ) { $start_block_pattern = implode( '', - array( + [ '##s', - ) + ] ); return preg_replace_callback( $start_block_pattern, - array( __CLASS__, 'handle_block_source_comment_replacement' ), + [ __CLASS__, 'handle_block_source_comment_replacement' ], $content ); } @@ -1154,10 +1154,10 @@ protected static function handle_block_source_comment_replacement( $matches ) { $replaced = $matches[0]; // Obtain source information for block. - $source = array( + $source = [ 'block_name' => $matches['name'], 'post_id' => get_the_ID(), - ); + ]; if ( empty( $matches['closing'] ) ) { $source['block_content_index'] = self::$block_content_index; @@ -1235,7 +1235,7 @@ public static function wrap_hook_callbacks( $hook ) { return; } - self::$current_hook_source_stack[ $hook ] = array(); + self::$current_hook_source_stack[ $hook ] = []; foreach ( $wp_filter[ $hook ]->callbacks as $priority => &$callbacks ) { foreach ( $callbacks as &$callback ) { $source = self::get_source( $callback['function'] ); @@ -1315,11 +1315,11 @@ public static function decorate_shortcode_source( $output, $tag ) { $output = implode( '', - array( + [ self::get_source_comment( $source, true ), $output, self::get_source_comment( $source, false ), - ) + ] ); return $output; } @@ -1335,17 +1335,17 @@ public static function decorate_shortcode_source( $output, $tag ) { * @return string Output. */ public static function decorate_embed_source( $output, $url, $attr ) { - $source = array( + $source = [ 'embed' => $url, 'attr' => $attr, - ); + ]; return implode( '', - array( + [ self::get_source_comment( $source, true ), trim( $output ), self::get_source_comment( $source, false ), - ) + ] ); } @@ -1364,10 +1364,10 @@ public static function decorate_filter_source( $value ) { } $post = get_post(); - $source = array( + $source = [ 'hook' => current_filter(), 'filter' => true, - ); + ]; if ( $post ) { $source['post_id'] = $post->ID; $source['post_type'] = $post->post_type; @@ -1379,11 +1379,11 @@ public static function decorate_filter_source( $value ) { } return implode( '', - array( + [ self::get_source_comment( $source, true ), $value, self::get_source_comment( $source, false ), - ) + ] ); } @@ -1497,7 +1497,7 @@ public static function can_output_buffer() { } // Check if any functions in call stack are output buffering display handlers. - $called_functions = array(); + $called_functions = []; if ( defined( 'DEBUG_BACKTRACE_IGNORE_ARGS' ) ) { $arg = DEBUG_BACKTRACE_IGNORE_ARGS; // phpcs:ignore PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound } else { @@ -1559,11 +1559,11 @@ public static function wrap_buffer_with_source_comments( $output ) { if ( ! empty( $output ) && preg_match( '/<.+?>/s', $output ) ) { $output = implode( '', - array( + [ self::get_source_comment( $source, true ), $output, self::get_source_comment( $source, false ), - ) + ] ); } return $output; @@ -1609,12 +1609,12 @@ public static function should_validate_response() { * @type bool $append_validation_status_comment Whether the validation errors should be appended as an HTML comment. Defaults to true. * } */ - public static function finalize_validation( DOMDocument $dom, $args = array() ) { + public static function finalize_validation( DOMDocument $dom, $args = [] ) { $args = array_merge( - array( + [ 'remove_source_comments' => true, 'append_validation_status_comment' => true, - ), + ], $args ); @@ -1667,11 +1667,11 @@ public static function finalize_validation( DOMDocument $dom, $args = array() ) } if ( $args['append_validation_status_comment'] ) { - $data = array( + $data = [ 'results' => self::$validation_results, - ); + ]; if ( get_queried_object() ) { - $data['queried_object'] = array(); + $data['queried_object'] = []; if ( get_queried_object_id() ) { $data['queried_object']['id'] = get_queried_object_id(); } @@ -1708,7 +1708,7 @@ public static function filter_sanitizer_args( $sanitizers ) { if ( isset( $sanitizers['AMP_Style_Sanitizer'] ) ) { $sanitizers['AMP_Style_Sanitizer']['should_locate_sources'] = self::$should_locate_sources; - $css_validation_errors = array(); + $css_validation_errors = []; foreach ( self::$validation_error_status_overrides as $slug => $status ) { $term = AMP_Validation_Error_Taxonomy::get_term( $slug ); if ( ! $term ) { @@ -1754,7 +1754,7 @@ public static function validate_after_plugin_activation() { AMP_Validated_URL_Post_Type::store_validation_errors( $validation_errors, $validity['url'], - wp_array_slice_assoc( $validity, array( 'queried_object_id', 'queried_object_type' ) ) + wp_array_slice_assoc( $validity, [ 'queried_object_id', 'queried_object_type' ] ) ); set_transient( self::PLUGIN_ACTIVATION_VALIDATION_ERRORS_TRANSIENT_KEY, $validation_errors, 60 ); } else { @@ -1781,10 +1781,10 @@ public static function validate_after_plugin_activation() { */ public static function validate_url( $url ) { - $added_query_vars = array( + $added_query_vars = [ self::VALIDATE_QUERY_VAR => self::get_amp_validate_nonce(), self::CACHE_BUST_QUERY_VAR => wp_rand(), - ); + ]; $validation_url = add_query_arg( $added_query_vars, $url ); $r = null; @@ -1794,15 +1794,15 @@ public static function validate_url( $url ) { for ( $redirect_count = 0; $redirect_count < $allowed_redirects; $redirect_count++ ) { $r = wp_remote_get( $validation_url, - array( + [ 'cookies' => wp_unslash( $_COOKIE ), // Pass along cookies so private pages and drafts can be accessed. 'timeout' => 15, // Increase from default of 5 to give extra time for the plugin to identify the sources for any given validation errors; also, response caching is disabled when validating. 'sslverify' => false, 'redirection' => 0, // Because we're in a loop for redirection. - 'headers' => array( + 'headers' => [ 'Cache-Control' => 'no-cache', - ), - ) + ], + ] ); // If the response is not a redirect, then break since $r is all we need. @@ -1919,7 +1919,7 @@ public static function print_plugin_notice() { $errors = AMP_Validation_Error_Taxonomy::summarize_validation_errors( $validation_errors ); $invalid_plugins = isset( $errors[ AMP_Validation_Error_Taxonomy::SOURCES_INVALID_OUTPUT ]['plugin'] ) ? array_unique( $errors[ AMP_Validation_Error_Taxonomy::SOURCES_INVALID_OUTPUT ]['plugin'] ) : null; if ( isset( $invalid_plugins ) ) { - $reported_plugins = array(); + $reported_plugins = []; foreach ( $invalid_plugins as $plugin ) { $reported_plugins[] = sprintf( '%s', esc_html( $plugin ) ); } @@ -1977,7 +1977,7 @@ public static function enqueue_block_validation() { $script_deps_path = AMP__DIR__ . '/assets/js/' . $slug . '.deps.json'; $script_dependencies = file_exists( $script_deps_path ) ? json_decode( file_get_contents( $script_deps_path ), false ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - : array(); + : []; wp_enqueue_script( $slug, @@ -1990,11 +1990,11 @@ public static function enqueue_block_validation() { $status_and_errors = AMP_Post_Meta_Box::get_status_and_errors( get_post() ); $enabled_status = $status_and_errors['status']; - $data = array( + $data = [ 'isSanitizationAutoAccepted' => self::is_sanitization_auto_accepted() || AMP_Story_Post_Type::POST_TYPE_SLUG === get_post_type(), - 'possibleStatuses' => array( AMP_Post_Meta_Box::ENABLED_STATUS, AMP_Post_Meta_Box::DISABLED_STATUS ), + 'possibleStatuses' => [ AMP_Post_Meta_Box::ENABLED_STATUS, AMP_Post_Meta_Box::DISABLED_STATUS ], 'defaultStatus' => $enabled_status, - ); + ]; wp_localize_script( $slug, diff --git a/includes/widgets/class-amp-widget-archives.php b/includes/widgets/class-amp-widget-archives.php index 108898d0544..84cefb3ff3b 100644 --- a/includes/widgets/class-amp-widget-archives.php +++ b/includes/widgets/class-amp-widget-archives.php @@ -58,11 +58,11 @@ public function widget( $args, $instance ) { /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ $dropdown_args = apply_filters( 'widget_archives_dropdown_args', - array( + [ 'type' => 'monthly', 'format' => 'option', 'show_post_count' => $c, - ) + ] ); switch ( $dropdown_args['type'] ) { @@ -95,10 +95,10 @@ public function widget( $args, $instance ) { wp_get_archives( apply_filters( 'widget_archives_args', - array( + [ 'type' => 'monthly', 'show_post_count' => $c, - ) + ] ) ); ?> diff --git a/includes/widgets/class-amp-widget-categories.php b/includes/widgets/class-amp-widget-categories.php index dda32668cb9..0fb88546d7c 100644 --- a/includes/widgets/class-amp-widget-categories.php +++ b/includes/widgets/class-amp-widget-categories.php @@ -46,11 +46,11 @@ public function widget( $args, $instance ) { if ( $title ) { echo wp_kses_post( $args['before_title'] . $title . $args['after_title'] ); } - $cat_args = array( + $cat_args = [ 'orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, - ); + ]; if ( $d ) : $form_id = sprintf( 'widget-categories-dropdown-%d', $this->number ); printf( '

', esc_url( home_url() ), esc_attr( $form_id ) ); @@ -64,7 +64,7 @@ public function widget( $args, $instance ) { array_merge( /** This filter is documented in wp-includes/widgets/class-wp-widget-categories.php */ apply_filters( 'widget_categories_dropdown_args', $cat_args, $instance ), - array( 'echo' => false ) + [ 'echo' => false ] ) ); $dropdown = preg_replace( diff --git a/templates/header.php b/templates/header.php index 17e6de102a2..a4fd9704283 100644 --- a/templates/header.php +++ b/templates/header.php @@ -11,4 +11,4 @@ * @var AMP_Post_Template $this */ -$this->load_parts( array( 'header-bar' ) ); +$this->load_parts( [ 'header-bar' ] ); diff --git a/templates/html-start.php b/templates/html-start.php index 1a14fde32d6..ee28cd8f4cc 100644 --- a/templates/html-start.php +++ b/templates/html-start.php @@ -25,7 +25,7 @@ diff --git a/templates/meta-author.php b/templates/meta-author.php index 238ea77a925..089f1692d3b 100644 --- a/templates/meta-author.php +++ b/templates/meta-author.php @@ -17,7 +17,7 @@ diff --git a/templates/page.php b/templates/page.php index c3779f9fd47..e631fab9a1b 100644 --- a/templates/page.php +++ b/templates/page.php @@ -18,24 +18,24 @@ * @var AMP_Post_Template $this */ -$this->load_parts( array( 'html-start' ) ); +$this->load_parts( [ 'html-start' ] ); ?> -load_parts( array( 'header' ) ); ?> +load_parts( [ 'header' ] ); ?>

get( 'post_title' ) ); ?>

- load_parts( array( 'featured-image' ) ); ?> + load_parts( [ 'featured-image' ] ); ?>
get( 'post_amp_content' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
-load_parts( array( 'footer' ) ); ?> +load_parts( [ 'footer' ] ); ?> load_parts( array( 'html-end' ) ); +$this->load_parts( [ 'html-end' ] ); diff --git a/templates/single.php b/templates/single.php index db63ea1e982..a56aff770e4 100644 --- a/templates/single.php +++ b/templates/single.php @@ -18,29 +18,29 @@ * @var AMP_Post_Template $this */ -$this->load_parts( array( 'html-start' ) ); +$this->load_parts( [ 'html-start' ] ); ?> -load_parts( array( 'header' ) ); ?> +load_parts( [ 'header' ] ); ?>

get( 'post_title' ) ); ?>

- load_parts( apply_filters( 'amp_post_article_header_meta', array( 'meta-author', 'meta-time' ) ) ); ?> + load_parts( apply_filters( 'amp_post_article_header_meta', [ 'meta-author', 'meta-time' ] ) ); ?>
- load_parts( array( 'featured-image' ) ); ?> + load_parts( [ 'featured-image' ] ); ?>
get( 'post_amp_content' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
- load_parts( apply_filters( 'amp_post_article_footer_meta', array( 'meta-taxonomy', 'meta-comments-link' ) ) ); ?> + load_parts( apply_filters( 'amp_post_article_footer_meta', [ 'meta-taxonomy', 'meta-comments-link' ] ) ); ?>
-load_parts( array( 'footer' ) ); ?> +load_parts( [ 'footer' ] ); ?> load_parts( array( 'html-end' ) ); +$this->load_parts( [ 'html-end' ] ); diff --git a/tests/php/stubs.php b/tests/php/stubs.php index 4347da62a97..04b6dcc2cb0 100644 --- a/tests/php/stubs.php +++ b/tests/php/stubs.php @@ -17,10 +17,10 @@ public function sanitize() { } public function get_scripts() { - return array( 'scripts' ); + return [ 'scripts' ]; } public function get_styles() { - return array( 'styles' ); + return [ 'styles' ]; } } diff --git a/tests/php/test-amp-analytics-options.php b/tests/php/test-amp-analytics-options.php index af595ef347e..36dfd3d367e 100644 --- a/tests/php/test-amp-analytics-options.php +++ b/tests/php/test-amp-analytics-options.php @@ -8,7 +8,7 @@ class AMP_Analytics_Options_Test extends WP_UnitTestCase { public function setUp() { parent::setUp(); AMP_Options_Manager::register_settings(); - wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) ); } private $vendor = 'googleanalytics'; @@ -51,18 +51,18 @@ public function setUp() { }'; private function get_options() { - return AMP_Options_Manager::get_option( 'analytics', array() ); + return AMP_Options_Manager::get_option( 'analytics', [] ); } private function render_post() { $user_id = self::factory()->user->create(); $post_id = self::factory()->post->create( - array( + [ 'post_author' => $user_id, - ) + ] ); - return get_echo( 'amp_render_post', array( $post_id ) ); + return get_echo( 'amp_render_post', [ $post_id ] ); } /** @@ -74,9 +74,9 @@ private function render_post() { private function insert_one_option( $type, $config ) { AMP_Options_Manager::update_option( 'analytics', - array( + [ '__new__' => compact( 'type', 'config' ), - ) + ] ); } @@ -261,7 +261,7 @@ public function test_amp_print_analytics() { $analytics = amp_get_analytics(); - $output = get_echo( 'amp_print_analytics', array( $analytics ) ); + $output = get_echo( 'amp_print_analytics', [ $analytics ] ); $this->assertStringStartsWith( 'assertContains( 'type="googleanalytics">', // phpcs:ignore - ); - $survey_response = array( + ]; + $survey_response = [ 'type' => 'rich', 'version' => '1.0', 'provider_name' => 'Crowdsignal', 'provider_url' => 'https://crowdsignal.com', 'html' => '
', - ); + ]; - $data = array( - 'poll.fm' => array( + $data = [ + 'poll.fm' => [ 'https://poll.fm/7012505', '

Which design do you prefer?

', $poll_response, - ), + ], - 'polldaddy_poll' => array( + 'polldaddy_poll' => [ 'https://polldaddy.com/poll/7012505/', '

Which design do you prefer?

', $poll_response, - ), + ], - 'polldaddy_survey' => array( + 'polldaddy_survey' => [ 'https://rydk.polldaddy.com/s/test-survey', '

View Survey

', $survey_response, - ), - ); + ], + ]; /* * There is a bug with WordPress's oEmbed handling for Crowdsignal surveys. * See . */ if ( version_compare( get_bloginfo( 'version' ), '5.2.0', '>=' ) ) { - $data['survey.fm'] = array( + $data['survey.fm'] = [ 'https://rydk.survey.fm/test-survey', '

View Survey

', $survey_response, - ); + ]; } return $data; @@ -86,13 +86,13 @@ static function ( $pre, $r, $request_url ) use ( $oembed_response ) { return $pre; } - return array( + return [ 'body' => wp_json_encode( $oembed_response ), - 'response' => array( + 'response' => [ 'code' => 200, 'message' => 'OK', - ), - ); + ], + ]; }, 10, 3 diff --git a/tests/php/test-amp-dailymotion-embed.php b/tests/php/test-amp-dailymotion-embed.php index 46955984267..4cd3ca9fccb 100644 --- a/tests/php/test-amp-dailymotion-embed.php +++ b/tests/php/test-amp-dailymotion-embed.php @@ -2,33 +2,33 @@ class AMP_DailyMotion_Embed_Test extends WP_UnitTestCase { public function get_conversion_data() { - return array( - 'no_embed' => array( + return [ + 'no_embed' => [ '

Hello world.

', '

Hello world.

' . PHP_EOL, - ), + ], - 'url_simple' => array( + 'url_simple' => [ 'https://www.dailymotion.com/video/x5awwth' . PHP_EOL, '

' . PHP_EOL, - ), + ], - 'url_with_title' => array( + 'url_with_title' => [ 'http://www.dailymotion.com/video/x5awwth_snatched-official-trailer-2-hd_shortfilms' . PHP_EOL, '

' . PHP_EOL, - ), + ], - 'shortcode_unnamed_attr_as_id' => array( + 'shortcode_unnamed_attr_as_id' => [ '[dailymotion x5awwth]' . PHP_EOL, '' . PHP_EOL, - ), + ], - 'shortcode_named_attr_as_id' => array( + 'shortcode_named_attr_as_id' => [ '[dailymotion id=x5awwth]' . PHP_EOL, '' . PHP_EOL, - ), + ], - ); + ]; } /** @@ -43,16 +43,16 @@ public function test__conversion( $source, $expected ) { } public function get_scripts_data() { - return array( - 'not_converted' => array( + return [ + 'not_converted' => [ '

Hello World.

', - array(), - ), - 'converted' => array( + [], + ], + 'converted' => [ 'https://www.dailymotion.com/video/x5awwth' . PHP_EOL, - array( 'amp-dailymotion' => true ), - ), - ); + [ 'amp-dailymotion' => true ], + ], + ]; } /** diff --git a/tests/php/test-amp-facebook-embed.php b/tests/php/test-amp-facebook-embed.php index a04b7299f6a..6d42ad72749 100644 --- a/tests/php/test-amp-facebook-embed.php +++ b/tests/php/test-amp-facebook-embed.php @@ -18,37 +18,37 @@ class AMP_Facebook_Embed_Test extends WP_UnitTestCase { * @return array Data. */ public function get_conversion_data() { - return array( - 'no_embed' => array( + return [ + 'no_embed' => [ '

Hello world.

', '

Hello world.

' . PHP_EOL, - ), - 'simple_url_https' => array( + ], + 'simple_url_https' => [ 'https://www.facebook.com/zuck/posts/10102593740125791' . PHP_EOL, '

' . PHP_EOL, - ), - 'simple_url_http' => array( + ], + 'simple_url_http' => [ 'http://www.facebook.com/zuck/posts/10102593740125791' . PHP_EOL, '

' . PHP_EOL, - ), - 'no_dubdubdub' => array( + ], + 'no_dubdubdub' => [ 'https://facebook.com/zuck/posts/10102593740125791' . PHP_EOL, '

' . PHP_EOL, - ), - 'notes_url' => array( + ], + 'notes_url' => [ 'https://www.facebook.com/notes/facebook-engineering/under-the-hood-the-javascript-sdk-truly-asynchronous-loading/10151176218703920/' . PHP_EOL, '

' . PHP_EOL, - ), - 'photo_url' => array( + ], + 'photo_url' => [ 'https://www.facebook.com/photo.php?fbid=10102533316889441&set=a.529237706231.2034669.4&type=3&theater' . PHP_EOL, '

' . PHP_EOL, - ), - 'notes_url2' => array( + ], + 'notes_url2' => [ 'https://www.facebook.com/zuck/videos/10102509264909801/' . PHP_EOL, '

' . PHP_EOL, - ), + ], - ); + ]; } /** @@ -72,16 +72,16 @@ public function test__conversion( $source, $expected ) { * @return array Scripts. */ public function get_scripts_data() { - return array( - 'not_converted' => array( + return [ + 'not_converted' => [ '

Hello World.

', - array(), - ), - 'converted' => array( + [], + ], + 'converted' => [ 'https://www.facebook.com/zuck/posts/10102593740125791' . PHP_EOL, - array( 'amp-facebook' => true ), - ), - ); + [ 'amp-facebook' => true ], + ], + ]; } /** @@ -113,22 +113,22 @@ public function test__get_scripts( $source, $expected ) { * @return array */ public function get_raw_embed_dataset() { - return array( - 'no_embed_blockquote' => array( + return [ + 'no_embed_blockquote' => [ '

Hello world.

', '

Hello world.

', - ), - 'div_without_instagram' => array( + ], + 'div_without_instagram' => [ '
lorem ipsum
', '
lorem ipsum
', - ), + ], - 'post_embed' => array( + 'post_embed' => [ '
', '', - ), + ], - 'post_with_fallbacks' => array( + 'post_with_fallbacks' => [ '
@@ -143,14 +143,14 @@ public function get_raw_embed_dataset() {
', - ), + ], - 'video_embed' => array( + 'video_embed' => [ '
', '', - ), + ], - 'page_embed' => array( + 'page_embed' => [ '
@@ -165,9 +165,9 @@ public function get_raw_embed_dataset() {
', - ), + ], - 'like' => array( + 'like' => [ '
', @@ -175,27 +175,27 @@ public function get_raw_embed_dataset() { ', - ), + ], - 'comments' => array( + 'comments' => [ '
', '', - ), + ], - 'comment_embed' => array( + 'comment_embed' => [ '
', '', - ), + ], - 'remove_fb_root' => array( + 'remove_fb_root' => [ '
', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript '', - ), - ); + ], + ]; } /** diff --git a/tests/php/test-amp-form-sanitizer.php b/tests/php/test-amp-form-sanitizer.php index b29577955cf..9ab1dc36a6e 100644 --- a/tests/php/test-amp-form-sanitizer.php +++ b/tests/php/test-amp-form-sanitizer.php @@ -35,56 +35,56 @@ public function get_data() { preg_quote( '
' ); - return array( - 'no_form' => array( + return [ + 'no_form' => [ '

Lorem Ipsum Demet Delorit.

', null, // Same. - ), - 'form_with_get_method_http_action_and_no_target' => array( + ], + 'form_with_get_method_http_action_and_no_target' => [ '', '
', - ), - 'form_with_implicit_method_http_action_and_no_action_or_target' => array( + ], + 'form_with_implicit_method_http_action_and_no_action_or_target' => [ '
', sprintf( '
', preg_replace( '#^https?:#', '', home_url( '/current-page/' ) ) ), - ), - 'form_with_empty_method_http_action_and_no_action_or_target' => array( + ], + 'form_with_empty_method_http_action_and_no_action_or_target' => [ '
', '
', - ), - 'form_with_post_method_http_action_and_no_target' => array( + ], + 'form_with_post_method_http_action_and_no_target' => [ '
', '#' . preg_quote( '
', '#' ) . $form_template_pattern . '
#s', - ), - 'form_with_post_method_http_action_and_blank_target' => array( + ], + 'form_with_post_method_http_action_and_blank_target' => [ '
', '
', - ), - 'form_with_post_method_http_action_and_self_target' => array( + ], + 'form_with_post_method_http_action_and_self_target' => [ '
', '
', - ), - 'form_with_post_method_https_action_and_custom_target' => array( + ], + 'form_with_post_method_https_action_and_custom_target' => [ '
', '#' . preg_quote( '
', '#' ) . $form_template_pattern . '
#s', - ), - 'jetpack_contact_form' => array( + ], + 'jetpack_contact_form' => [ '
hello

', '#' . preg_quote( '
hello

', '#' ) . $form_template_pattern . '
#s', - ), - 'form_with_upload' => array( + ], + 'form_with_upload' => [ '
', '#' . preg_quote( '
', '#' ) . $form_template_pattern . '
#s', - ), - 'form_with_password' => array( + ], + 'form_with_password' => [ '
', '#' . preg_quote( '
', '#' ) . $form_template_pattern . '
#s', - ), - 'form_with_relative_action_url' => array( + ], + 'form_with_relative_action_url' => [ '
', '#' . preg_quote( '
', '#' ) . $form_template_pattern . '
#s', - ), - ); + ], + ]; } /** @@ -120,7 +120,7 @@ public function test_converter( $source, $expected = null ) { */ public function test_scripts() { $source = '
'; - $expected = array( 'amp-form' => true ); + $expected = [ 'amp-form' => true ]; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $whitelist_sanitizer = new AMP_Tag_And_Attribute_Sanitizer( $dom ); diff --git a/tests/php/test-amp-helper-functions.php b/tests/php/test-amp-helper-functions.php index 00614cd8f2e..e20900ae497 100644 --- a/tests/php/test-amp-helper-functions.php +++ b/tests/php/test-amp-helper-functions.php @@ -55,11 +55,11 @@ public function test_amp_get_slug() { * @covers ::amp_get_current_url() */ public function test_amp_get_current_url() { - $request_uris = array( + $request_uris = [ '/foo', '/bar?baz', null, - ); + ]; foreach ( $request_uris as $request_uri ) { if ( $request_uri ) { @@ -86,50 +86,50 @@ public function test_amp_get_permalink_without_pretty_permalinks() { flush_rewrite_rules(); $drafted_post = self::factory()->post->create( - array( + [ 'post_name' => 'draft', 'post_status' => 'draft', 'post_type' => 'post', - ) + ] ); $published_post = self::factory()->post->create( - array( + [ 'post_name' => 'publish', 'post_status' => 'publish', 'post_type' => 'post', - ) + ] ); $published_page = self::factory()->post->create( - array( + [ 'post_name' => 'publish', 'post_status' => 'publish', 'post_type' => 'page', - ) + ] ); $this->assertStringEndsWith( '&', amp_get_permalink( $published_post ) ); $this->assertStringEndsWith( '&', amp_get_permalink( $drafted_post ) ); $this->assertStringEndsWith( '&', amp_get_permalink( $published_page ) ); - add_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); - add_filter( 'amp_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); + add_filter( 'amp_pre_get_permalink', [ $this, 'return_example_url' ], 10, 2 ); + add_filter( 'amp_get_permalink', [ $this, 'return_example_url' ], 10, 2 ); $url = amp_get_permalink( $published_post ); $this->assertContains( 'current_filter=amp_pre_get_permalink', $url ); $this->assertContains( 'url=0', $url ); - remove_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10 ); + remove_filter( 'amp_pre_get_permalink', [ $this, 'return_example_url' ], 10 ); $url = amp_get_permalink( $published_post ); $this->assertContains( 'current_filter=amp_get_permalink', $url ); - remove_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ) ); + remove_filter( 'amp_pre_get_permalink', [ $this, 'return_example_url' ] ); // Now check with theme support added (in transitional mode). - add_theme_support( AMP_Theme_Support::SLUG, array( 'template_dir' => './' ) ); + add_theme_support( AMP_Theme_Support::SLUG, [ 'template_dir' => './' ] ); $this->assertStringEndsWith( '&', amp_get_permalink( $published_post ) ); $this->assertStringEndsWith( '&', amp_get_permalink( $drafted_post ) ); $this->assertStringEndsWith( '&', amp_get_permalink( $published_page ) ); - add_filter( 'amp_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); + add_filter( 'amp_get_permalink', [ $this, 'return_example_url' ], 10, 2 ); $this->assertNotContains( 'current_filter=amp_get_permalink', amp_get_permalink( $published_post ) ); // Filter does not apply. - add_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); + add_filter( 'amp_pre_get_permalink', [ $this, 'return_example_url' ], 10, 2 ); $this->assertNotContains( 'current_filter=amp_pre_get_permalink', amp_get_permalink( $published_post ) ); // Filter does not apply. } @@ -150,23 +150,23 @@ public function test_amp_get_permalink_with_pretty_permalinks() { }; $drafted_post = self::factory()->post->create( - array( + [ 'post_name' => 'draft', 'post_status' => 'draft', - ) + ] ); $published_post = self::factory()->post->create( - array( + [ 'post_name' => 'publish', 'post_status' => 'publish', - ) + ] ); $published_page = self::factory()->post->create( - array( + [ 'post_name' => 'publish', 'post_status' => 'publish', 'post_type' => 'page', - ) + ] ); $this->assertStringEndsWith( '&', amp_get_permalink( $drafted_post ) ); $this->assertStringEndsWith( '/amp/', amp_get_permalink( $published_post ) ); @@ -176,25 +176,25 @@ public function test_amp_get_permalink_with_pretty_permalinks() { $this->assertStringEndsWith( '/amp/#anchor', amp_get_permalink( $published_post ) ); remove_filter( 'post_link', $add_anchor_fragment ); - add_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); - add_filter( 'amp_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); + add_filter( 'amp_pre_get_permalink', [ $this, 'return_example_url' ], 10, 2 ); + add_filter( 'amp_get_permalink', [ $this, 'return_example_url' ], 10, 2 ); $url = amp_get_permalink( $published_post ); $this->assertContains( 'current_filter=amp_pre_get_permalink', $url ); $this->assertContains( 'url=0', $url ); - remove_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10 ); + remove_filter( 'amp_pre_get_permalink', [ $this, 'return_example_url' ], 10 ); $url = amp_get_permalink( $published_post ); $this->assertContains( 'current_filter=amp_get_permalink', $url ); - remove_filter( 'amp_get_permalink', array( $this, 'return_example_url' ), 10 ); + remove_filter( 'amp_get_permalink', [ $this, 'return_example_url' ], 10 ); // Now check with theme support added (in transitional mode). - add_theme_support( AMP_Theme_Support::SLUG, array( 'template_dir' => './' ) ); + add_theme_support( AMP_Theme_Support::SLUG, [ 'template_dir' => './' ] ); $this->assertStringEndsWith( '&', amp_get_permalink( $drafted_post ) ); $this->assertStringEndsWith( '?amp', amp_get_permalink( $published_post ) ); $this->assertStringEndsWith( '?amp', amp_get_permalink( $published_page ) ); - add_filter( 'amp_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); + add_filter( 'amp_get_permalink', [ $this, 'return_example_url' ], 10, 2 ); $this->assertNotContains( 'current_filter=amp_get_permalink', amp_get_permalink( $published_post ) ); // Filter does not apply. - add_filter( 'amp_pre_get_permalink', array( $this, 'return_example_url' ), 10, 2 ); + add_filter( 'amp_pre_get_permalink', [ $this, 'return_example_url' ], 10, 2 ); $this->assertNotContains( 'current_filter=amp_pre_get_permalink', amp_get_permalink( $published_post ) ); // Filter does not apply. // Make sure that if permalink has anchor that it is persists. @@ -221,9 +221,9 @@ public function test_amp_get_permalink_with_theme_support() { add_theme_support( AMP_Theme_Support::SLUG, - array( + [ 'template_dir' => 'amp', - ) + ] ); } @@ -258,20 +258,20 @@ public function test_amp_add_frontend_actions() { */ public function get_amphtml_urls() { $post_id = self::factory()->post->create(); - return array( - 'home' => array( + return [ + 'home' => [ home_url( '/' ), add_query_arg( amp_get_slug(), '', home_url( '/' ) ), - ), - '404' => array( + ], + '404' => [ home_url( '/no-existe/' ), add_query_arg( amp_get_slug(), '', home_url( '/no-existe/' ) ), - ), - 'post' => array( + ], + 'post' => [ get_permalink( $post_id ), amp_get_permalink( $post_id ), - ), - ); + ], + ]; } /** @@ -308,17 +308,17 @@ public function test_amp_add_amphtml_link( $canonical_url, $amphtml_url ) { // Make sure that the link is not provided when there are validation errors associated with the URL. add_theme_support( AMP_Theme_Support::SLUG, - array( + [ 'template_dir' => './', - ) + ] ); AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::STANDARD_MODE_SLUG ); AMP_Theme_Support::read_theme_support(); AMP_Theme_Support::init(); $invalid_url_post_id = AMP_Validated_URL_Post_Type::store_validation_errors( - array( - array( 'code' => 'foo' ), - ), + [ + [ 'code' => 'foo' ], + ], $canonical_url ); $this->assertNotInstanceOf( 'WP_Error', $invalid_url_post_id ); @@ -345,7 +345,7 @@ public function test_is_amp_endpoint() { $this->assertFalse( is_amp_endpoint() ); // Transitional theme support. - add_theme_support( AMP_Theme_Support::SLUG, array( 'template_dir' => './' ) ); + add_theme_support( AMP_Theme_Support::SLUG, [ 'template_dir' => './' ] ); $_GET['amp'] = ''; $this->assertTrue( is_amp_endpoint() ); unset( $_GET['amp'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended @@ -357,7 +357,7 @@ public function test_is_amp_endpoint() { $this->assertTrue( is_amp_endpoint() ); // Special core pages. - $pages = array( 'wp-login.php', 'wp-signup.php', 'wp-activate.php' ); + $pages = [ 'wp-login.php', 'wp-signup.php', 'wp-activate.php' ]; foreach ( $pages as $page ) { $GLOBALS['pagenow'] = $page; $this->assertFalse( is_amp_endpoint() ); @@ -369,7 +369,7 @@ public function test_is_amp_endpoint() { * The user has chosen not to show them as AMP, so most URLs should not be AMP endpoints. */ AMP_Options_Manager::update_option( 'all_templates_supported', false ); - AMP_Options_Manager::update_option( 'supported_templates', array( 'is_author' ) ); + AMP_Options_Manager::update_option( 'supported_templates', [ 'is_author' ] ); // A post shouldn't be an AMP endpoint, as it was unchecked in the UI via the options above. $this->go_to( self::factory()->post->create() ); @@ -464,10 +464,10 @@ public function test_is_amp_endpoint_before_wp_action() { * @return mixed Value. */ public function capture_filter_call( $value ) { - $this->last_filter_call = array( + $this->last_filter_call = [ 'current_filter' => current_filter(), 'args' => func_get_args(), - ); + ]; return $value; } @@ -488,22 +488,22 @@ public function test_amp_add_generator_metadata() { $this->assertContains( 'v' . AMP__VERSION, $output ); $this->assertContains( 'experiences=website', $output ); - add_theme_support( AMP_Theme_Support::SLUG, array( AMP_Theme_Support::PAIRED_FLAG => true ) ); + add_theme_support( AMP_Theme_Support::SLUG, [ AMP_Theme_Support::PAIRED_FLAG => true ] ); $output = $get_generator_tag(); $this->assertContains( 'mode=transitional', $output ); $this->assertContains( 'v' . AMP__VERSION, $output ); - add_theme_support( AMP_Theme_Support::SLUG, array( AMP_Theme_Support::PAIRED_FLAG => false ) ); + add_theme_support( AMP_Theme_Support::SLUG, [ AMP_Theme_Support::PAIRED_FLAG => false ] ); $output = $get_generator_tag(); $this->assertContains( 'mode=standard', $output ); $this->assertContains( 'v' . AMP__VERSION, $output ); - AMP_Options_Manager::update_option( 'experiences', array( AMP_Options_Manager::STORIES_EXPERIENCE ) ); + AMP_Options_Manager::update_option( 'experiences', [ AMP_Options_Manager::STORIES_EXPERIENCE ] ); $output = $get_generator_tag(); $this->assertContains( 'mode=none', $output ); $this->assertContains( 'experiences=stories', $output ); - AMP_Options_Manager::update_option( 'experiences', array( AMP_Options_Manager::WEBSITE_EXPERIENCE, AMP_Options_Manager::STORIES_EXPERIENCE ) ); + AMP_Options_Manager::update_option( 'experiences', [ AMP_Options_Manager::WEBSITE_EXPERIENCE, AMP_Options_Manager::STORIES_EXPERIENCE ] ); $output = $get_generator_tag(); $this->assertContains( 'mode=standard', $output ); $this->assertContains( 'experiences=website,stories', $output ); @@ -544,19 +544,19 @@ public function test_script_registering() { // Try rendering via amp_render_scripts() instead of amp_render_scripts(), which is how component scripts get added normally. $output = amp_render_scripts( - array( + [ 'amp-mathml' => true, // But already printed above. 'amp-carousel' => 'https://cdn.ampproject.org/v0/amp-mustache-2.0.js', 'amp-accordion' => true, - ) + ] ); $this->assertNotContains( 'amp-mathml', $output, 'The amp-mathml component was already printed above.' ); $this->assertContains( '', $output ); // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript $this->assertContains( '', $output ); // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript // Try some experimental component to ensure expected script attributes are added. - wp_register_script( 'amp-foo', 'https://cdn.ampproject.org/v0/amp-foo-0.1.js', array( 'amp-runtime' ), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter, WordPress.WP.EnqueuedResourceParameters.MissingVersion - $output = get_echo( 'wp_print_scripts', array( 'amp-foo' ) ); + wp_register_script( 'amp-foo', 'https://cdn.ampproject.org/v0/amp-foo-0.1.js', [ 'amp-runtime' ], null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter, WordPress.WP.EnqueuedResourceParameters.MissingVersion + $output = get_echo( 'wp_print_scripts', [ 'amp-foo' ] ); $this->assertContains( '', $output ); // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript } @@ -567,7 +567,7 @@ public function test_script_registering() { */ public function test_amp_get_content_embed_handlers() { $post = self::factory()->post->create_and_get(); - add_filter( 'amp_content_embed_handlers', array( $this, 'capture_filter_call' ), 10, 2 ); + add_filter( 'amp_content_embed_handlers', [ $this, 'capture_filter_call' ], 10, 2 ); $this->last_filter_call = null; add_theme_support( AMP_Theme_Support::SLUG ); @@ -605,7 +605,7 @@ public function test_amp_get_content_embed_handlers_deprecated_param() { */ public function test_amp_get_content_sanitizers() { $post = self::factory()->post->create_and_get(); - add_filter( 'amp_content_sanitizers', array( $this, 'capture_filter_call' ), 10, 2 ); + add_filter( 'amp_content_sanitizers', [ $this, 'capture_filter_call' ], 10, 2 ); $this->last_filter_call = null; add_theme_support( AMP_Theme_Support::SLUG ); @@ -629,7 +629,7 @@ public function test_amp_get_content_sanitizers() { add_filter( 'amp_content_sanitizers', static function( $classes ) { - $classes['Even_After_Whitelist_Sanitizer'] = array(); + $classes['Even_After_Whitelist_Sanitizer'] = []; return $classes; } ); @@ -661,7 +661,7 @@ public function test_post_supports_amp() { // Test disabled by default for page for posts and show on front. update_option( 'show_on_front', 'page' ); - $post = self::factory()->post->create_and_get( array( 'post_type' => 'page' ) ); + $post = self::factory()->post->create_and_get( [ 'post_type' => 'page' ] ); $this->assertTrue( post_supports_amp( $post ) ); update_option( 'show_on_front', 'page' ); $this->assertTrue( post_supports_amp( $post ) ); @@ -693,12 +693,12 @@ public function test_amp_get_post_image_metadata() { $first_test_image = '/tmp/test-image.jpg'; copy( DIR_TESTDATA . '/images/test-image.jpg', $first_test_image ); $attachment_id = self::factory()->attachment->create_object( - array( + [ 'file' => $first_test_image, 'post_parent' => 0, 'post_mime_type' => 'image/jpeg', 'post_title' => 'Test Image', - ) + ] ); wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $first_test_image ) ); @@ -712,10 +712,10 @@ public function test_amp_get_post_image_metadata() { delete_post_thumbnail( $post_id ); $this->assertFalse( amp_get_post_image_metadata( $post_id ) ); wp_update_post( - array( + [ 'ID' => $attachment_id, 'post_parent' => $post_id, - ) + ] ); $metadata = amp_get_post_image_metadata( $post_id ); $this->assertStringEndsWith( 'test-image.jpg', $metadata['url'] ); @@ -725,40 +725,40 @@ public function test_amp_get_post_image_metadata() { $attachment_height = 45; $attachment_width = 600; $attachment_id = self::factory()->attachment->create_object( - array( + [ 'file' => $attachment_src, 'post_mime_type' => 'image/jpeg', - ) + ] ); $expected_attachment_img = wp_get_attachment_image_src( $attachment_id, 'full', false ); update_post_meta( $attachment_id, '_wp_attachment_metadata', - array( + [ 'height' => $attachment_height, 'width' => $attachment_width, - ) + ] ); $this->go_to( get_permalink( $attachment_id ) ); $this->assertEquals( - array( + [ '@type' => 'ImageObject', 'height' => $attachment_height, 'url' => $expected_attachment_img[0], 'width' => $attachment_width, - ), + ], amp_get_post_image_metadata( $attachment_id ) ); // Test a video as an 'attachment' post type, which shouldn't have a schema.org image. $attachment_src = 'example/test-video.mpeg'; $attachment_id = self::factory()->attachment->create_object( - array( + [ 'file' => $attachment_src, 'post_mime_type' => 'video/mpeg', - ) + ] ); $this->go_to( get_permalink( $attachment_id ) ); $this->assertFalse( amp_get_post_image_metadata( $attachment_id ) ); @@ -773,30 +773,30 @@ public function test_amp_get_schemaorg_metadata() { update_option( 'blogname', 'Foo' ); $publisher_type = 'Organization'; $logo_type = 'ImageObject'; - $expected_publisher = array( + $expected_publisher = [ '@type' => $publisher_type, 'name' => 'Foo', - ); + ]; $user_id = self::factory()->user->create( - array( + [ 'first_name' => 'John', 'last_name' => 'Smith', - ) + ] ); $page_id = self::factory()->post->create( - array( + [ 'post_type' => 'page', 'post_title' => 'Example Page', 'post_author' => $user_id, - ) + ] ); $post_id = self::factory()->post->create( - array( + [ 'post_type' => 'post', 'post_title' => 'Example Post', 'post_author' => $user_id, - ) + ] ); // Test non-singular, with no publisher logo. @@ -812,30 +812,30 @@ public function test_amp_get_schemaorg_metadata() { $custom_logo_height = 45; $custom_logo_width = 600; $custom_logo_id = self::factory()->attachment->create_object( - array( + [ 'file' => $custom_logo_src, 'post_mime_type' => 'image/jpeg', - ) + ] ); $expected_logo_img = wp_get_attachment_image_src( $custom_logo_id, 'full', false ); update_post_meta( $custom_logo_id, '_wp_attachment_metadata', - array( + [ 'width' => $custom_logo_width, 'height' => $custom_logo_height, - ) + ] ); set_theme_mod( 'custom_logo', $custom_logo_id ); $metadata = amp_get_schemaorg_metadata(); $this->assertEquals( - array( + [ '@type' => $logo_type, 'height' => $custom_logo_height, 'url' => $expected_logo_img[0], 'width' => $custom_logo_width, - ), + ], $metadata['publisher']['logo'] ); set_theme_mod( 'custom_logo', null ); @@ -843,20 +843,20 @@ public function test_amp_get_schemaorg_metadata() { // Test the site icon as the publisher logo. $site_icon_src = 'foo/site-icon.jpeg'; $site_icon_id = self::factory()->attachment->create_object( - array( + [ 'file' => $site_icon_src, 'post_mime_type' => 'image/jpeg', - ) + ] ); $expected_site_icon_img = wp_get_attachment_image_src( $site_icon_id, 'full', false ); update_option( 'site_icon', $site_icon_id ); - $expected_schema_site_icon = array( + $expected_schema_site_icon = [ '@type' => $logo_type, 'height' => 32, 'url' => $expected_site_icon_img[0], 'width' => 32, - ); + ]; $metadata = amp_get_schemaorg_metadata(); $this->assertEquals( $expected_schema_site_icon, $metadata['publisher']['logo'] ); update_option( 'site_icon', null ); @@ -872,22 +872,22 @@ public function test_amp_get_schemaorg_metadata() { update_post_meta( $custom_logo_id, '_wp_attachment_metadata', - array( + [ 'width' => $custom_logo_width, 'height' => $custom_logo_excessive_height, - ) + ] ); set_theme_mod( 'custom_logo', $custom_logo_id ); update_option( 'site_icon', $site_icon_id ); $metadata = amp_get_schemaorg_metadata(); $max_height = 60; $this->assertEquals( - array( + [ '@type' => $logo_type, 'height' => $max_height, 'url' => $expected_logo_img[0], 'width' => $custom_logo_width * $max_height / $custom_logo_excessive_height, // Proportional to downsized height. - ), + ], $metadata['publisher']['logo'] ); set_theme_mod( 'custom_logo', null ); @@ -902,16 +902,16 @@ public function test_amp_get_schemaorg_metadata() { update_post_meta( $custom_logo_id, '_wp_attachment_metadata', - array( + [ 'width' => $custom_logo_width, 'height' => $custom_logo_height, - ) + ] ); set_theme_mod( 'custom_logo', $custom_logo_id ); - add_filter( 'amp_site_icon_url', array( __CLASS__, 'mock_site_icon' ) ); + add_filter( 'amp_site_icon_url', [ __CLASS__, 'mock_site_icon' ] ); $metadata = amp_get_schemaorg_metadata(); $this->assertEquals( self::MOCK_SITE_ICON, $metadata['publisher']['logo']['url'] ); - remove_filter( 'amp_site_icon_url', array( __CLASS__, 'mock_site_icon' ) ); + remove_filter( 'amp_site_icon_url', [ __CLASS__, 'mock_site_icon' ] ); set_theme_mod( 'custom_logo', null ); // Test page. @@ -937,10 +937,10 @@ public function test_amp_get_schemaorg_metadata() { $this->assertArrayHasKey( 'datePublished', $metadata ); $this->assertArrayHasKey( 'dateModified', $metadata ); $this->assertEquals( - array( + [ '@type' => 'Person', 'name' => 'John Smith', - ), + ], $metadata['author'] ); @@ -994,7 +994,7 @@ public function test_amp_add_admin_bar_item() { $this->assertNull( $admin_bar->get_node( 'amp' ) ); // Check that paired mode does add link. - add_theme_support( 'amp', array( AMP_Theme_Support::PAIRED_FLAG => true ) ); + add_theme_support( 'amp', [ AMP_Theme_Support::PAIRED_FLAG => true ] ); $admin_bar = new WP_Admin_Bar(); amp_add_admin_bar_view_link( $admin_bar ); $item = $admin_bar->get_node( 'amp' ); diff --git a/tests/php/test-amp-iframe-sanitizer.php b/tests/php/test-amp-iframe-sanitizer.php index 96186c9cb0e..61aea858745 100644 --- a/tests/php/test-amp-iframe-sanitizer.php +++ b/tests/php/test-amp-iframe-sanitizer.php @@ -20,13 +20,13 @@ class AMP_Iframe_Converter_Test extends WP_UnitTestCase { * @return array Data. */ public function get_data() { - return array( - 'no_iframes' => array( + return [ + 'no_iframes' => [ '

Lorem Ipsum Demet Delorit.

', '

Lorem Ipsum Demet Delorit.

', - ), + ], - 'simple_iframe' => array( + 'simple_iframe' => [ '', ' @@ -36,22 +36,22 @@ public function get_data() { ', - array( + [ 'add_noscript_fallback' => true, 'add_placeholder' => true, - ), - ), + ], + ], - 'simple_iframe_without_noscript_or_placeholder' => array( + 'simple_iframe_without_noscript_or_placeholder' => [ '', '', - array( + [ 'add_noscript_fallback' => false, 'add_placeholder' => false, - ), - ), + ], + ], - 'force_https' => array( + 'force_https' => [ '', ' @@ -60,9 +60,9 @@ public function get_data() { ', - ), + ], - 'iframe_without_dimensions' => array( + 'iframe_without_dimensions' => [ '', ' @@ -71,9 +71,9 @@ public function get_data() { ', - ), + ], - 'iframe_with_height_only' => array( + 'iframe_with_height_only' => [ '', ' @@ -82,9 +82,9 @@ public function get_data() { ', - ), + ], - 'iframe_with_100_percent_width' => array( + 'iframe_with_100_percent_width' => [ '', ' @@ -93,9 +93,9 @@ public function get_data() { ', - ), + ], - 'iframe_with_width_only' => array( + 'iframe_with_width_only' => [ '', ' @@ -104,9 +104,9 @@ public function get_data() { ', - ), + ], - 'iframe_with_invalid_frameborder' => array( + 'iframe_with_invalid_frameborder' => [ '', ' @@ -115,9 +115,9 @@ public function get_data() { ', - ), + ], - 'iframe_with_1_frameborder' => array( + 'iframe_with_1_frameborder' => [ '', ' @@ -126,9 +126,9 @@ public function get_data() { ', - ), + ], - 'simple_iframe_with_sandbox' => array( + 'simple_iframe_with_sandbox' => [ '', ' @@ -137,9 +137,9 @@ public function get_data() { ', - ), + ], - 'iframe_with_blacklisted_attribute' => array( + 'iframe_with_blacklisted_attribute' => [ '', ' @@ -148,9 +148,9 @@ public function get_data() { ', - ), + ], - 'iframe_with_sizes_attribute_is_overridden' => array( + 'iframe_with_sizes_attribute_is_overridden' => [ '', ' @@ -159,9 +159,9 @@ public function get_data() { ', - ), + ], - 'iframe_with_id_attribute' => array( + 'iframe_with_id_attribute' => [ '', ' @@ -170,9 +170,9 @@ public function get_data() { ', - ), + ], - 'iframe_with_protocol_relative_url' => array( + 'iframe_with_protocol_relative_url' => [ '', ' @@ -181,9 +181,9 @@ public function get_data() { ', - ), + ], - 'multiple_same_iframe' => array( + 'multiple_same_iframe' => [ ' @@ -199,9 +199,9 @@ public function get_data() { ', 3 ), - ), + ], - 'multiple_different_iframes' => array( + 'multiple_different_iframes' => [ ' @@ -224,8 +224,8 @@ public function get_data() { ', - ), - 'iframe_in_p_tag' => array( + ], + 'iframe_in_p_tag' => [ '

', '

@@ -236,8 +236,8 @@ public function get_data() {

', - ), - 'multiple_iframes_in_p_tag' => array( + ], + 'multiple_iframes_in_p_tag' => [ '

', '

@@ -252,8 +252,8 @@ public function get_data() {

', - ), - 'multiple_iframes_and_contents_in_p_tag' => array( + ], + 'multiple_iframes_and_contents_in_p_tag' => [ '

contents

', '

contents @@ -268,8 +268,8 @@ public function get_data() {

', - ), - 'iframe_src_with_commas_and_colons' => array( + ], + 'iframe_src_with_commas_and_colons' => [ '', ' @@ -278,14 +278,14 @@ public function get_data() { ', - ), + ], - 'amp_iframe_with_fallback' => array( + 'amp_iframe_with_fallback' => [ '', null, - ), + ], - 'attributes_removed_from_noscript_iframe' => array( + 'attributes_removed_from_noscript_iframe' => [ '', ' @@ -295,54 +295,54 @@ public function get_data() { ', - array( + [ 'add_noscript_fallback' => true, 'add_placeholder' => true, - ), - ), + ], + ], - 'iframe_relative_url' => array( + 'iframe_relative_url' => [ '', '', - array( + [ 'add_noscript_fallback' => false, 'add_placeholder' => false, 'current_origin' => 'https://example.com', - ), - ), + ], + ], - 'iframe_scheme_relative_url' => array( + 'iframe_scheme_relative_url' => [ '', '', - array( + [ 'add_noscript_fallback' => false, 'add_placeholder' => false, 'current_origin' => 'https://example.com', - ), - ), + ], + ], - 'iframe_relative_url_with_alias_origin' => array( + 'iframe_relative_url_with_alias_origin' => [ '', '', - array( + [ 'add_noscript_fallback' => false, 'add_placeholder' => false, 'current_origin' => 'https://example.com', 'alias_origin' => 'https://alt.example.org', - ), - ), + ], + ], - 'iframe_absolute_url_with_alias_origin' => array( + 'iframe_absolute_url_with_alias_origin' => [ '', '', - array( + [ 'add_noscript_fallback' => false, 'add_placeholder' => false, 'current_origin' => 'https://example.com', 'alias_origin' => 'https://alt.example.org', - ), - ), - ); + ], + ], + ]; } /** @@ -354,7 +354,7 @@ public function get_data() { * @param string $expected Expected. * @param array $args Sanitizer args. */ - public function test_converter( $source, $expected = null, $args = array() ) { + public function test_converter( $source, $expected = null, $args = [] ) { if ( ! $expected ) { $expected = $source; } @@ -379,10 +379,10 @@ public function test__https_required() { $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_Iframe_Sanitizer( $dom, - array( + [ 'add_placeholder' => true, 'require_https_src' => true, - ) + ] ); $sanitizer->sanitize(); @@ -395,7 +395,7 @@ public function test__https_required() { */ public function test_get_scripts__didnt_convert() { $source = '

Hello World

'; - $expected = array(); + $expected = []; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_Iframe_Sanitizer( $dom ); @@ -416,7 +416,7 @@ public function test_get_scripts__didnt_convert() { */ public function test_get_scripts__did_convert() { $source = ''; - $expected = array( 'amp-iframe' => true ); + $expected = [ 'amp-iframe' => true ]; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_Iframe_Sanitizer( $dom ); @@ -442,9 +442,9 @@ public function test__args__placeholder() { $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_Iframe_Sanitizer( $dom, - array( + [ 'add_placeholder' => true, - ) + ] ); $sanitizer->sanitize(); $content = AMP_DOM_Utils::get_content_from_dom( $dom ); diff --git a/tests/php/test-amp-image-dimension-extractor.php b/tests/php/test-amp-image-dimension-extractor.php index 30010c2178b..0ece0b15cf7 100644 --- a/tests/php/test-amp-image-dimension-extractor.php +++ b/tests/php/test-amp-image-dimension-extractor.php @@ -26,7 +26,7 @@ public function setUp() { parent::setUp(); // We don't want to actually download the images; just testing the extract method. - add_action( 'amp_extract_image_dimensions_batch_callbacks_registered', array( $this, 'disable_downloads' ) ); + add_action( 'amp_extract_image_dimensions_batch_callbacks_registered', [ $this, 'disable_downloads' ] ); } /** @@ -44,7 +44,7 @@ public function disable_downloads() { public function test__single_url() { $source_url = 'https://example.com/image.png'; $cdn_url = 'https://cdn.example.com/image.png'; - $expected = array( 100, 101 ); + $expected = [ 100, 101 ]; add_action( 'amp_extract_image_dimensions_batch_callbacks_registered', @@ -52,12 +52,12 @@ static function() use ( $cdn_url ) { add_filter( 'amp_extract_image_dimensions_batch', static function() use ( $cdn_url ) { - return array( - $cdn_url => array( + return [ + $cdn_url => [ 100, 101, - ), - ); + ], + ]; } ); }, @@ -87,16 +87,16 @@ function ( $url, $original_url ) use ( $source_url, $cdn_url, &$ran_filter_count * Test should return both urls */ public function test__should_return_both_urls() { - $source_urls = array( + $source_urls = [ home_url( '/wp-content/uploads/2018/06/IMG_0183-300x300.jpg' ), site_url( '/wp-content/uploads/2018/06/IMG_0183-300x300.jpg' ), '/wp-content/uploads/2018/06/IMG_0183-300x300.jpg', - ); - $expected = array( + ]; + $expected = [ home_url( '/wp-content/uploads/2018/06/IMG_0183-300x300.jpg' ) => false, site_url( '/wp-content/uploads/2018/06/IMG_0183-300x300.jpg' ) => false, '/wp-content/uploads/2018/06/IMG_0183-300x300.jpg' => false, - ); + ]; $actual = AMP_Image_Dimension_Extractor::extract( $source_urls ); @@ -107,18 +107,18 @@ public function test__should_return_both_urls() { * Test where processed URLs should match originals. */ public function test__should_return_original_urls() { - $source_urls = array( + $source_urls = [ 'https://example.com', '//example.com/no-protocol', '/absolute-url/no-host', 'data:image/gif;base64,R0lGODl...', // can't normalize. - ); - $expected = array( + ]; + $expected = [ 'https://example.com' => false, '//example.com/no-protocol' => false, '/absolute-url/no-host' => false, 'data:image/gif;base64,R0lGODl...' => false, - ); + ]; $actual = AMP_Image_Dimension_Extractor::extract( $source_urls ); @@ -133,36 +133,36 @@ public function test__should_return_original_urls() { public function get_data() { $home_url = home_url(); - return array( - 'empty_url' => array( + return [ + 'empty_url' => [ '', false, - ), - 'data_url' => array( + ], + 'data_url' => [ 'data:image/gif;base64,R0lGODl...', false, - ), - 'protocol-less_url' => array( + ], + 'protocol-less_url' => [ '//example.com/file.jpg', 'http://example.com/file.jpg', - ), - 'path_only' => array( + ], + 'path_only' => [ '/path/to/file.png', $home_url . '/path/to/file.png', - ), - 'query_only' => array( + ], + 'query_only' => [ '?file=file.png', $home_url . '?file=file.png', - ), - 'path_and_query' => array( + ], + 'path_and_query' => [ '/path/file.jpg?query=1', $home_url . '/path/file.jpg?query=1', - ), - 'normal_url' => array( + ], + 'normal_url' => [ 'https://example.com/path/to/file.jpg', 'https://example.com/path/to/file.jpg', - ), - ); + ], + ]; } /** @@ -188,15 +188,15 @@ public function test__normalize_url( $source_url, $expected_url ) { * @group external-http */ public function test__valid_image_file() { - $sources = array( + $sources = [ IMG_350 => false, - ); - $expected = array( - IMG_350 => array( + ]; + $expected = [ + IMG_350 => [ 'width' => 350, 'height' => 150, - ), - ); + ], + ]; $dimensions = AMP_Image_Dimension_Extractor::extract_by_downloading_images( $sources ); @@ -209,30 +209,30 @@ public function test__valid_image_file() { * @group external-http */ public function test__multiple_valid_image_files() { - $sources = array( + $sources = [ IMG_350 => false, IMG_1024 => false, IMG_SVG => false, IMG_SVG_VIEWPORT => false, - ); - $expected = array( - IMG_350 => array( + ]; + $expected = [ + IMG_350 => [ 'width' => 350, 'height' => 150, - ), - IMG_1024 => array( + ], + IMG_1024 => [ 'width' => 1024, 'height' => 768, - ), - IMG_SVG => array( + ], + IMG_SVG => [ 'width' => 175, 'height' => 60, - ), - IMG_SVG_VIEWPORT => array( + ], + IMG_SVG_VIEWPORT => [ 'width' => 251, 'height' => 80, - ), - ); + ], + ]; $dimensions = AMP_Image_Dimension_Extractor::extract_by_downloading_images( $sources ); @@ -245,12 +245,12 @@ public function test__multiple_valid_image_files() { * @group external-http */ public function test__invalid_image_file() { - $sources = array( + $sources = [ AMP_IMG_DIMENSION_TEST_INVALID_FILE => false, - ); - $expected = array( + ]; + $expected = [ AMP_IMG_DIMENSION_TEST_INVALID_FILE => false, - ); + ]; $dimensions = AMP_Image_Dimension_Extractor::extract_by_downloading_images( $sources ); @@ -263,22 +263,22 @@ public function test__invalid_image_file() { * @group external-http */ public function test__mix_of_valid_and_invalid_image_file() { - $sources = array( + $sources = [ IMG_350 => false, AMP_IMG_DIMENSION_TEST_INVALID_FILE => false, IMG_1024 => false, - ); - $expected = array( - IMG_350 => array( + ]; + $expected = [ + IMG_350 => [ 'width' => 350, 'height' => 150, - ), + ], AMP_IMG_DIMENSION_TEST_INVALID_FILE => false, - IMG_1024 => array( + IMG_1024 => [ 'width' => 1024, 'height' => 768, - ), - ); + ], + ]; $dimensions = AMP_Image_Dimension_Extractor::extract_by_downloading_images( $sources ); diff --git a/tests/php/test-amp-img-sanitizer.php b/tests/php/test-amp-img-sanitizer.php index 47d6c8a719d..ef558f6433d 100644 --- a/tests/php/test-amp-img-sanitizer.php +++ b/tests/php/test-amp-img-sanitizer.php @@ -20,10 +20,10 @@ public function setUp() { add_filter( 'amp_extract_image_dimensions_batch', static function( $urls ) { - $dimensions = array(); + $dimensions = []; foreach ( array_keys( $urls ) as $url ) { if ( preg_match( '#/(?P\d+)x(?P\d+)$#', $url, $matches ) ) { - $dimensions[ $url ] = array_map( 'intval', wp_array_slice_assoc( $matches, array( 'width', 'height' ) ) ); + $dimensions[ $url ] = array_map( 'intval', wp_array_slice_assoc( $matches, [ 'width', 'height' ] ) ); } else { $dimensions[ $url ] = false; } @@ -39,284 +39,284 @@ static function( $urls ) { * @return array */ public function get_data() { - return array( - 'no_images' => array( + return [ + 'no_images' => [ '

Lorem Ipsum Demet Delorit.

', '

Lorem Ipsum Demet Delorit.

', - ), + ], - 'simple_image' => array( + 'simple_image' => [ '

', '

', - array( + [ 'add_noscript_fallback' => true, - ), - ), + ], + ], - 'simple_image_without_noscript' => array( + 'simple_image_without_noscript' => [ '

', '

', - array( + [ 'add_noscript_fallback' => false, - ), - ), + ], + ], - 'image_without_src' => array( + 'image_without_src' => [ '

', '

', - array(), - array( 'invalid_element' ), - ), + [], + [ 'invalid_element' ], + ], - 'image_with_empty_src' => array( + 'image_with_empty_src' => [ '

', '

', - array(), - array( 'invalid_element' ), - ), + [], + [ 'invalid_element' ], + ], - 'image_with_layout' => array( + 'image_with_layout' => [ '', '', - ), + ], - 'image_with_noloading' => array( + 'image_with_noloading' => [ '', '', - ), + ], - 'image_with_layout_from_editor' => array( + 'image_with_layout_from_editor' => [ '
', '
', - ), + ], - 'image_with_noloading_from_editor' => array( + 'image_with_noloading_from_editor' => [ '
', '
', - ), + ], - 'image_with_spaces_only_src' => array( + 'image_with_spaces_only_src' => [ '

', '

', - array(), - array( 'invalid_element' ), - ), + [], + [ 'invalid_element' ], + ], - 'image_with_empty_width_and_height' => array( + 'image_with_empty_width_and_height' => [ '

', '

', - ), + ], - 'image_with_undefined_width_and_height' => array( + 'image_with_undefined_width_and_height' => [ '

', '

', - ), + ], - 'image_with_empty_width' => array( + 'image_with_empty_width' => [ '

', '

', - ), + ], - 'image_with_empty_height' => array( + 'image_with_empty_height' => [ '

', '

', - ), + ], - 'image_with_zero_width' => array( + 'image_with_zero_width' => [ '

', '

', - ), + ], - 'image_with_zero_width_and_height' => array( + 'image_with_zero_width_and_height' => [ '

', '

', - ), + ], - 'image_with_decimal_width' => array( + 'image_with_decimal_width' => [ '

', '

', - ), + ], - 'image_with_self_closing_tag' => array( + 'image_with_self_closing_tag' => [ 'Placeholder!', '', - ), + ], - 'image_with_no_end_tag' => array( + 'image_with_no_end_tag' => [ 'Placeholder!', '', - ), + ], - 'image_with_end_tag' => array( + 'image_with_end_tag' => [ 'Placeholder!', '', - ), + ], - 'image_with_extra_attributes' => array( + 'image_with_extra_attributes' => [ 'ALT!', '', - array(), - array( + [], + [ 'invalid_attribute', // The onclick attribute. - ), - ), + ], + ], - 'image_with_no_dimensions_is_forced' => array( + 'image_with_no_dimensions_is_forced' => [ '', '', - ), + ], - 'image_with_bad_src_url_get_fallback_dims' => array( + 'image_with_bad_src_url_get_fallback_dims' => [ '', '', - ), + ], - 'gif_image_conversion' => array( + 'gif_image_conversion' => [ 'Placeholder!', '', - ), + ], - 'gif_image_url_with_querystring' => array( + 'gif_image_url_with_querystring' => [ 'Placeholder!', '', - ), + ], - 'multiple_same_image' => array( + 'multiple_same_image' => [ '', '', - ), + ], - 'multiple_different_images' => array( + 'multiple_different_images' => [ '', '', - ), + ], - 'image_center_aligned' => array( + 'image_center_aligned' => [ '', '', - ), + ], - 'image_left_aligned' => array( + 'image_left_aligned' => [ '', '', - ), + ], - 'image_with_caption' => array( + 'image_with_caption' => [ '
This is an example caption.
', '
This is an example caption.
', - ), + ], - 'image_with_custom_lightbox_attrs' => array( + 'image_with_custom_lightbox_attrs' => [ '
', '
', - ), + ], - 'wide_image' => array( + 'wide_image' => [ '
Image Alignment 580x300
', '
', - ), + ], - 'wide_image_center_aligned' => array( + 'wide_image_center_aligned' => [ '
Image Alignment 580x300
', '
', - ), + ], - 'wide_image_left_aligned_custom_style' => array( + 'wide_image_left_aligned_custom_style' => [ '
Image Alignment 580x300
', '
', - ), + ], - 'wide_image_right_aligned' => array( + 'wide_image_right_aligned' => [ '
Image Alignment 580x300
', '
', - ), + ], - 'wide_image_is_resized' => array( + 'wide_image_is_resized' => [ '
Image Alignment 580x300
', '
', - ), + ], - 'amp_img_with_noscript_fallback' => array( + 'amp_img_with_noscript_fallback' => [ '', null, - ), + ], - 'img_with_sizes_attribute_removed' => array( + 'img_with_sizes_attribute_removed' => [ '', '', - ), + ], - 'amp_img_with_sizes_attribute_retained' => array( + 'amp_img_with_sizes_attribute_retained' => [ '', null, - ), + ], - 'img_with_http_protocol_src' => array( + 'img_with_http_protocol_src' => [ '', '', - ), + ], - 'img_with_http_protocol_srcset' => array( + 'img_with_http_protocol_srcset' => [ '', '', - ), + ], - 'img_with_fill_layout_inline_style' => array( + 'img_with_fill_layout_inline_style' => [ '', '', - array( + [ 'add_noscript_fallback' => false, - ), - ), + ], + ], - 'img_with_intrinsic_layout_inline_style' => array( + 'img_with_intrinsic_layout_inline_style' => [ '', '', - array( + [ 'add_noscript_fallback' => false, - ), - ), + ], + ], - 'img_with_responsive_layout_inline_style' => array( + 'img_with_responsive_layout_inline_style' => [ '', '', - array( + [ 'add_noscript_fallback' => false, - ), - ), + ], + ], - 'img_with_fixed_height_inline_style' => array( + 'img_with_fixed_height_inline_style' => [ '', '', - array( + [ 'add_noscript_fallback' => false, - ), - ), + ], + ], - 'img_with_flex_item_inline_style' => array( + 'img_with_flex_item_inline_style' => [ '', '', - array( + [ 'add_noscript_fallback' => false, - ), - ), + ], + ], - 'img_with_nodisplay_layout_inline_style' => array( + 'img_with_nodisplay_layout_inline_style' => [ '', '', - array( + [ 'add_noscript_fallback' => false, - ), - ), + ], + ], - 'img_static_emoji' => array( + 'img_static_emoji' => [ '👨🏻‍💻', '', - array( + [ 'add_noscript_fallback' => false, - ), - ), - ); + ], + ], + ]; } /** @@ -328,20 +328,20 @@ public function get_data() { * @param string[] $expected_error_codes Expected error codes. * @dataProvider get_data */ - public function test_converter( $source, $expected = null, $args = array(), $expected_error_codes = array() ) { + public function test_converter( $source, $expected = null, $args = [], $expected_error_codes = [] ) { if ( ! $expected ) { $expected = $source; } - $error_codes = array(); + $error_codes = []; $args = array_merge( - array( + [ 'use_document_element' => true, 'validation_error_callback' => static function( $error ) use ( &$error_codes ) { $error_codes[] = $error['code']; }, - ), + ], $args ); @@ -368,7 +368,7 @@ public function test_converter( $source, $expected = null, $args = array(), $exp */ public function test_no_gif_no_image_scripts() { $source = 'Placeholder!'; - $expected = array(); + $expected = []; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_Img_Sanitizer( $dom ); @@ -389,7 +389,7 @@ public function test_no_gif_no_image_scripts() { */ public function test_no_gif_image_scripts() { $source = 'Placeholder!'; - $expected = array( 'amp-anim' => true ); + $expected = [ 'amp-anim' => true ]; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_Img_Sanitizer( $dom ); diff --git a/tests/php/test-amp-instagram-embed.php b/tests/php/test-amp-instagram-embed.php index abaa3197806..bfeb18bdade 100644 --- a/tests/php/test-amp-instagram-embed.php +++ b/tests/php/test-amp-instagram-embed.php @@ -2,36 +2,36 @@ class AMP_Instagram_Embed_Test extends WP_UnitTestCase { public function get_conversion_data() { - return array( - 'no_embed' => array( + return [ + 'no_embed' => [ '

Hello world.

', '

Hello world.

' . PHP_EOL, - ), - 'simple_url' => array( + ], + 'simple_url' => [ 'https://instagram.com/p/7-l0z_p4A4/' . PHP_EOL, '

' . PHP_EOL, - ), + ], - 'short_url' => array( + 'short_url' => [ 'https://instagr.am/p/7-l0z_p4A4' . PHP_EOL, '

' . PHP_EOL, - ), + ], - 'shortcode_simple' => array( + 'shortcode_simple' => [ '[instagram url=https://www.instagram.com/p/BIyO4vXjE6b]' . PHP_EOL, '' . PHP_EOL, - ), + ], - 'shortcode_url_with_query' => array( + 'shortcode_url_with_query' => [ '[instagram url=https://www.instagram.com/p/BIyO4vXjE6b/?taken-by=natgeo]' . PHP_EOL, '' . PHP_EOL, - ), + ], - 'shortcode_with_short_url' => array( + 'shortcode_with_short_url' => [ '[instagram url=https://instagr.am/p/7-l0z_p4A4]' . PHP_EOL, '' . PHP_EOL, - ), - ); + ], + ]; } /** @@ -55,16 +55,16 @@ public function test__conversion( $source, $expected ) { * @return array */ public function get_scripts_data() { - return array( - 'not_converted' => array( + return [ + 'not_converted' => [ '

Hello World.

', - array(), - ), - 'converted' => array( + [], + ], + 'converted' => [ 'https://instagram.com/p/7-l0z_p4A4/' . PHP_EOL, - array( 'amp-instagram' => true ), - ), - ); + [ 'amp-instagram' => true ], + ], + ]; } /** @@ -96,36 +96,36 @@ public function test__get_scripts( $source, $expected ) { * @return array */ public function get_raw_embed_dataset() { - return array( - 'no_embed' => array( + return [ + 'no_embed' => [ '

Hello world.

', '

Hello world.

', - ), - 'embed_blockquote_without_instagram' => array( + ], + 'embed_blockquote_without_instagram' => [ '

lorem ipsum

', '

lorem ipsum

', - ), + ], - 'blockquote_embed' => array( + 'blockquote_embed' => [ wpautop( '
Lorem ipsum
' ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine '' . "\n\n", - ), + ], - 'blockquote_embed_notautop' => array( + 'blockquote_embed_notautop' => [ '
Lorem ipsum
', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine ' ', - ), + ], - 'blockquote_embed_with_caption' => array( + 'blockquote_embed_with_caption' => [ wpautop( '
Lorem ipsum
' ), // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine '' . "\n\n", - ), + ], - 'blockquote_embed_with_caption_notautop' => array( + 'blockquote_embed_with_caption_notautop' => [ '
Lorem ipsum
', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript, WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine ' ', - ), - ); + ], + ]; } /** diff --git a/tests/php/test-amp-o2-player-sanitizer.php b/tests/php/test-amp-o2-player-sanitizer.php index 07849ff0f42..c95efc2ce2e 100644 --- a/tests/php/test-amp-o2-player-sanitizer.php +++ b/tests/php/test-amp-o2-player-sanitizer.php @@ -18,27 +18,27 @@ class AMP_O2_Player_Sanitizer_Test extends WP_UnitTestCase { * @return array Data. */ public function get_data() { - return array( - 'no_o2_player_item' => array( + return [ + 'no_o2_player_item' => [ '

Im Not A O2 Player

', '

Im Not A O2 Player

', - ), - 'o2_player_item_without_script' => array( + ], + 'o2_player_item_without_script' => [ '
', '
', - ), + ], - 'o2_player_item' => array( + 'o2_player_item' => [ '
',// phpcs:ignore '', - ), + ], - 'o2_player_item_without_required_fields' => array( + 'o2_player_item_without_required_fields' => [ '
',// phpcs:ignore '
',// phpcs:ignore - ), + ], - ); + ]; } /** @@ -68,7 +68,7 @@ public function test_converter( $source, $expected ) { */ public function test_get_script__pid__vid__required() { $source = '
';// phpcs:ignore - $expected = array(); + $expected = []; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_O2_Player_Sanitizer( $dom ); @@ -89,7 +89,7 @@ public function test_get_script__pid__vid__required() { */ public function test_get_scripts__did_convert() { $source = '
';// phpcs:ignore - $expected = array( 'amp-o2-player' => true ); + $expected = [ 'amp-o2-player' => true ]; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_O2_Player_Sanitizer( $dom ); diff --git a/tests/php/test-amp-pinterest-embed.php b/tests/php/test-amp-pinterest-embed.php index 2143a9399ea..40335a377ec 100644 --- a/tests/php/test-amp-pinterest-embed.php +++ b/tests/php/test-amp-pinterest-embed.php @@ -2,20 +2,20 @@ class AMP_Pinterest_Embed_Test extends WP_UnitTestCase { public function get_conversion_data() { - return array( - 'no_embed' => array( + return [ + 'no_embed' => [ '

Hello world.

', '

Hello world.

' . PHP_EOL, - ), - 'simple_url_https' => array( + ], + 'simple_url_https' => [ 'https://www.pinterest.com/pin/606156431067611861/' . PHP_EOL, '

' . PHP_EOL, - ), - 'simple_url_http' => array( + ], + 'simple_url_http' => [ 'http://www.pinterest.com/pin/606156431067611861/' . PHP_EOL, '

' . PHP_EOL, - ), - ); + ], + ]; } /** @@ -30,16 +30,16 @@ public function test__conversion( $source, $expected ) { } public function get_scripts_data() { - return array( - 'not_converted' => array( + return [ + 'not_converted' => [ '

Hello World.

', - array(), - ), - 'converted' => array( + [], + ], + 'converted' => [ 'https://www.pinterest.com/pin/606156431067611861/' . PHP_EOL, - array( 'amp-pinterest' => true ), - ), - ); + [ 'amp-pinterest' => true ], + ], + ]; } /** diff --git a/tests/php/test-amp-playbuzz-sanitizer.php b/tests/php/test-amp-playbuzz-sanitizer.php index 4991559703e..aab78c3e17b 100644 --- a/tests/php/test-amp-playbuzz-sanitizer.php +++ b/tests/php/test-amp-playbuzz-sanitizer.php @@ -9,47 +9,47 @@ class AMP_Playbuzz_Sanitizer_Test extends WP_UnitTestCase { * @return array Data. */ public function get_data() { - return array( - 'no_playbuzz_item' => array( + return [ + 'no_playbuzz_item' => [ '

Im Not A Playbuzz Embed

', '

Im Not A Playbuzz Embed

', - ), + ], - 'playbuzz_item_without_sorce' => array( + 'playbuzz_item_without_sorce' => [ '
', '
', - ), + ], - 'playbuzz_item_with_data_item' => array( + 'playbuzz_item_with_data_item' => [ '
', '', - ), + ], - 'playbuzz_item_with_data_game' => array( + 'playbuzz_item_with_data_game' => [ '
', '', - ), + ], - 'playbuzz_item_with_data_game_and_data_item' => array( + 'playbuzz_item_with_data_game_and_data_item' => [ '
', '', - ), + ], - 'playbuzz_item_with_data_game_info' => array( + 'playbuzz_item_with_data_game_info' => [ '
', '', - ), + ], - 'playbuzz_item_with_data_shares_info' => array( + 'playbuzz_item_with_data_shares_info' => [ '
', '', - ), + ], - 'playbuzz_item_with_data_comments' => array( + 'playbuzz_item_with_data_comments' => [ '
', '', - ), - ); + ], + ]; } /** @@ -66,7 +66,7 @@ public function test_converter( $source, $expected ) { public function test_get_scripts__data_item_or_data_game_required() { $source = '
'; - $expected = array(); + $expected = []; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_Playbuzz_Sanitizer( $dom ); @@ -84,7 +84,7 @@ public function test_get_scripts__data_item_or_data_game_required() { public function test_get_scripts__didnt_convert() { $source = '

Im A Not Playbuzz Embed

'; - $expected = array(); + $expected = []; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_Playbuzz_Sanitizer( $dom ); @@ -105,7 +105,7 @@ public function test_get_scripts__didnt_convert() { */ public function test_get_scripts__did_convert() { $source = '
'; - $expected = array( 'amp-playbuzz' => true ); + $expected = [ 'amp-playbuzz' => true ]; $dom = AMP_DOM_Utils::get_dom_from_content( $source ); $sanitizer = new AMP_Playbuzz_Sanitizer( $dom ); diff --git a/tests/php/test-amp-render-post.php b/tests/php/test-amp-render-post.php index 780e83171ca..f15e16c6cf8 100644 --- a/tests/php/test-amp-render-post.php +++ b/tests/php/test-amp-render-post.php @@ -11,9 +11,9 @@ public function test__invalid_post() { public function test__valid_post() { $user_id = self::factory()->user->create(); - $post_id = self::factory()->post->create( array( 'post_author' => $user_id ) ); + $post_id = self::factory()->post->create( [ 'post_author' => $user_id ] ); - $output = get_echo( 'amp_render_post', array( $post_id ) ); + $output = get_echo( 'amp_render_post', [ $post_id ] ); $this->assertContains( 'assertEquals( 1, did_action( 'pre_amp_render_post', 'pre_amp_render_post action fire either did not fire or fired too many times.' ) ); @@ -34,17 +34,17 @@ public function test__valid_post() { public function test__is_amp_endpoint() { $user_id = self::factory()->user->create(); $post_id = self::factory()->post->create( - array( + [ 'post_author' => $user_id, - ) + ] ); $before_is_amp_endpoint = is_amp_endpoint(); - add_action( 'pre_amp_render_post', array( $this, 'check_is_amp_endpoint' ) ); + add_action( 'pre_amp_render_post', [ $this, 'check_is_amp_endpoint' ] ); $this->was_amp_endpoint = false; - $output = get_echo( 'amp_render_post', array( $post_id ) ); + $output = get_echo( 'amp_render_post', [ $post_id ] ); $this->assertContains( ' array( + return [ + 'document_write' => [ 'Has script? ', 'Has script? Nope!', - ), - 'nested_elements' => array( + ], + 'nested_elements' => [ '', 'before middle end', - ), - 'head_noscript_style' => array( + ], + 'head_noscript_style' => [ '', '', - ), - 'head_noscript_span' => array( + ], + 'head_noscript_span' => [ '', 'No script', - ), - ); + ], + ]; } /** @@ -92,9 +92,9 @@ public function test_boilerplate_preservation() { true, - ); + ]; $dom = AMP_DOM_Utils::get_dom( $html ); AMP_Content_Sanitizer::sanitize_document( $dom, amp_get_content_sanitizers(), $args ); diff --git a/tests/php/test-amp-soundcloud-embed.php b/tests/php/test-amp-soundcloud-embed.php index aa82a9c5c18..2453e6018ef 100644 --- a/tests/php/test-amp-soundcloud-embed.php +++ b/tests/php/test-amp-soundcloud-embed.php @@ -66,14 +66,14 @@ public function setUp() { add_shortcode( 'soundcloud', 'soundcloud_shortcode' ); } - add_filter( 'pre_http_request', array( $this, 'mock_http_request' ), 10, 3 ); + add_filter( 'pre_http_request', [ $this, 'mock_http_request' ], 10, 3 ); } /** * After a test method runs, reset any state in WordPress the test method might have changed. */ public function tearDown() { - remove_filter( 'pre_http_request', array( $this, 'mock_http_request' ) ); + remove_filter( 'pre_http_request', [ $this, 'mock_http_request' ] ); parent::tearDown(); } @@ -97,16 +97,16 @@ public function mock_http_request( $preempt, $r, $url ) { $body = $this->track_oembed_response; } - return array( + return [ 'body' => $body, - 'headers' => array(), - 'response' => array( + 'headers' => [], + 'response' => [ 'code' => 200, 'message' => 'ok', - ), - 'cookies' => array(), + ], + 'cookies' => [], 'http_response' => null, - ); + ]; } /** @@ -115,22 +115,22 @@ public function mock_http_request( $preempt, $r, $url ) { * @return array */ public function get_conversion_data() { - $data = array( - 'no_embed' => array( + $data = [ + 'no_embed' => [ '

Hello world.

', '

Hello world.

' . PHP_EOL, - ), + ], - 'track_simple' => array( + 'track_simple' => [ $this->track_url . PHP_EOL, '

' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? 'Mozart – Requiem in D minor Complete Full by Jack Villano Villano' : '' ) . '

' . PHP_EOL, - ), + ], - 'playlist_simple' => array( + 'playlist_simple' => [ $this->playlist_url . PHP_EOL, '

' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? 'Classical Music – The Essential Collection by Classical Music' : '' ) . '

' . PHP_EOL, - ), - ); + ], + ]; // @todo All the following should be moved to Jetpack. if ( defined( 'JETPACK__PLUGIN_DIR' ) ) { @@ -139,38 +139,38 @@ public function get_conversion_data() { if ( function_exists( 'soundcloud_shortcode' ) ) { $data = array_merge( $data, - array( - 'shortcode_with_bare_track_api_url' => array( + [ + 'shortcode_with_bare_track_api_url' => [ '[soundcloud https://api.soundcloud.com/tracks/89299804]' . PHP_EOL, '' . PHP_EOL, - ), + ], - 'shortcode_with_track_api_url' => array( + 'shortcode_with_track_api_url' => [ '[soundcloud url=https://api.soundcloud.com/tracks/89299804]' . PHP_EOL, '' . PHP_EOL, - ), + ], - 'shortcode_with_track_permalink' => array( + 'shortcode_with_track_permalink' => [ "[soundcloud url=$this->track_url]", '' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? 'Mozart - Requiem in D minor Complete Full by Jack Villano Villano' : '' ) . '' . PHP_EOL, - ), + ], - 'shortcode_with_bare_track_permalink' => array( + 'shortcode_with_bare_track_permalink' => [ "[soundcloud $this->track_url]", '' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? 'Mozart - Requiem in D minor Complete Full by Jack Villano Villano' : '' ) . '' . PHP_EOL, - ), + ], - 'shortcode_with_playlist_permalink' => array( + 'shortcode_with_playlist_permalink' => [ "[soundcloud url=$this->playlist_url]", '' . ( function_exists( 'wp_filter_oembed_iframe_title_attribute' ) ? 'Classical Music - The Essential Collection by Classical Music' : '' ) . '' . PHP_EOL, - ), + ], // This apparently only works on WordPress.com. - 'shortcode_with_id' => array( + 'shortcode_with_id' => [ '[soundcloud id=89299804]' . PHP_EOL, '' . PHP_EOL, - ), - ) + ], + ] ); } @@ -202,20 +202,20 @@ public function test__conversion( $source, $expected ) { * @return array Scripts data. */ public function get_scripts_data() { - return array( - 'not_converted' => array( + return [ + 'not_converted' => [ '

Hello World.

', - array(), - ), - 'converted_track' => array( + [], + ], + 'converted_track' => [ $this->track_url . PHP_EOL, - array( 'amp-soundcloud' => true ), - ), - 'converted_playlist' => array( + [ 'amp-soundcloud' => true ], + ], + 'converted_playlist' => [ $this->playlist_url . PHP_EOL, - array( 'amp-soundcloud' => true ), - ), - ); + [ 'amp-soundcloud' => true ], + ], + ]; } /** diff --git a/tests/php/test-amp-story-sanitizer.php b/tests/php/test-amp-story-sanitizer.php index cc48ef5ee52..66c7fb51349 100644 --- a/tests/php/test-amp-story-sanitizer.php +++ b/tests/php/test-amp-story-sanitizer.php @@ -29,24 +29,24 @@ public function setUp() { * @return array */ public function get_data() { - return array( - 'story_without_cta' => array( + return [ + 'story_without_cta' => [ '

Lorem Ipsum Demet Delorit.

', null, // Same. - ), - 'story_with_cta_on_first_page' => array( + ], + 'story_with_cta_on_first_page' => [ '

Lorem Ipsum Demet Delorit.

Foo
', '

Lorem Ipsum Demet Delorit.

', - ), - 'story_with_cta_on_second_page' => array( + ], + 'story_with_cta_on_second_page' => [ '

Lorem Ipsum Demet Delorit.

Lorem Ipsum Demet Delorit.

Foo
', null, // Same. - ), - 'story_with_multiple_cta_on_second_page' => array( + ], + 'story_with_multiple_cta_on_second_page' => [ '

Lorem Ipsum Demet Delorit.

FooFoo', '

Lorem Ipsum Demet Delorit.

Foo', - ), - ); + ], + ]; } /** diff --git a/tests/php/test-amp-style-sanitizer.php b/tests/php/test-amp-style-sanitizer.php index b8525ecba7c..490600eba11 100644 --- a/tests/php/test-amp-style-sanitizer.php +++ b/tests/php/test-amp-style-sanitizer.php @@ -39,203 +39,203 @@ public function tearDown() { * @return array */ public function get_body_style_attribute_data() { - return array( - 'empty' => array( + return [ + 'empty' => [ '', '', - array(), - ), + [], + ], - 'span_one_style' => array( + 'span_one_style' => [ 'This is green.', 'This is green.', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-bb01159{color:#0f0}', - ), - ), + ], + ], - 'span_one_style_bad_format' => array( + 'span_one_style_bad_format' => [ 'This is green.', 'This is green.', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-0837823{color:#0f0}', - ), - ), + ], + ], - 'span_two_styles_reversed' => array( + 'span_two_styles_reversed' => [ 'This is green.', 'This is green.', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-c71affe{color:#0f0;background-color:#000}', - ), - ), + ], + ], - 'span_display_none' => array( + 'span_display_none' => [ 'Kses-banned properties are allowed since Kses will have already applied if user does not have unfiltered_html.', 'Kses-banned properties are allowed since Kses will have already applied if user does not have unfiltered_html.', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-224b51a{display:none}', - ), - ), + ], + ], - '!important_is_ok' => array( + '!important_is_ok' => [ '!important is converted.', '!important is converted.', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-6a75598{padding:1px;outline:3px}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-6a75598{margin:2px}', - ), - ), + ], + ], - '!important_with_spaces_also_converted' => array( + '!important_with_spaces_also_converted' => [ '!important is converted.', '!important is converted.', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-952600b{color:red}', - ), - ), + ], + ], - '!important_multiple_is_converted' => array( + '!important_multiple_is_converted' => [ '!important is converted.', '!important is converted.', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-1e2bfaa{color:red;background:blue}', - ), - ), + ], + ], - '!important_takes_precedence_over_inline' => array( + '!important_takes_precedence_over_inline' => [ '
bold!
', '
bold!
', - array( + [ 'div > span{font-style:italic}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) div > span{font-weight:bold}@media screen and ( max-width: 640px ){div > span{font-style:normal}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) div > span{font-weight:normal}}', - ), - ), + ], + ], - 'illegal_unsafe_properties' => array( + 'illegal_unsafe_properties' => [ '', '', - array( + [ 'button{font-weight:bold}', '@media screen{button{font-weight:bold}}', - ), - array( 'illegal_css_property', 'illegal_css_property', 'illegal_css_property', 'illegal_css_property' ), - ), + ], + [ 'illegal_css_property', 'illegal_css_property', 'illegal_css_property', 'illegal_css_property' ], + ], - 'illegal_at_rule_in_style_attribute' => array( + 'illegal_at_rule_in_style_attribute' => [ 'invalid @-rule omitted.', 'invalid @-rule omitted.', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-481af57{color:brown}', - ), - array(), - ), + ], + [], + ], - 'illegal_at_rules_removed' => array( + 'illegal_at_rules_removed' => [ '', '', - array( + [ '@page{margin:1cm}body{color:black}', - ), - array( 'illegal_css_at_rule', 'illegal_css_at_rule', 'illegal_css_at_rule' ), - ), + ], + [ 'illegal_css_at_rule', 'illegal_css_at_rule', 'illegal_css_at_rule' ], + ], - 'allowed_at_rules_retained' => array( + 'allowed_at_rules_retained' => [ '
', '
', - array( + [ '@media screen and ( max-width: 640px ){body{font-size:small}}@font-face{font-family:"Open Sans";src:url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2")}@supports (display: grid){div{display:grid}}@-moz-keyframes appear{from{opacity:0}to{opacity:1}}@keyframes appear{from{opacity:0}to{opacity:1}}', - ), - ), + ], + ], - 'selector_specificity' => array( + 'selector_specificity' => [ '
onetwothree
', '
onetwothree
', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) #child{color:red}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) #parent #child{color:pink}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .foo{color:blue}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) #me .foo{color:green}', ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-64b4fd4{color:yellow}', ':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-ab79d9e{color:purple}', - ), - ), + ], + ], - 'grid_lines' => array( + 'grid_lines' => [ '
', '
', - array( + [ '.wrapper{display:grid;grid-template-columns:[main-start] 1fr [content-start] 1fr [content-end] 1fr [main-end];grid-template-rows:[main-start] 100px [content-start] 100px [content-end] 100px [main-end]}', - ), - ), + ], + ], - 'col_with_width_attribute' => array( + 'col_with_width_attribute' => [ '
', '
', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-cbcb5c2{width:253px}', - ), - ), + ], + ], - 'col_with_percent_width_attribute' => array( + 'col_with_percent_width_attribute' => [ '
', '
', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-cd7753e{width:50%}', - ), - ), + ], + ], - 'col_with_star_width_attribute' => array( + 'col_with_star_width_attribute' => [ '
', '
', - array(), - ), + [], + ], - 'col_with_width_attribute_and_existing_style' => array( + 'col_with_width_attribute_and_existing_style' => [ '
', '
', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-c8aa9e9{width:50px;width:60px;background-color:red}', - ), - ), + ], + ], - 'multi_selector_in_not_pseudo_class' => array( + 'multi_selector_in_not_pseudo_class' => [ '
    ', '
      ', - array( + [ '.widget:not(.widget_text,.jetpack_widget_social_icons[title="a,b"]) ul{color:red}', - ), - ), + ], + ], - 'selector_with_escaped_char_class_name' => array( + 'selector_with_escaped_char_class_name' => [ '
      ', '
      ', - array( + [ '.lg\:w-full{width:100%}', - ), - ), - ); + ], + ], + ]; } /** @@ -247,15 +247,15 @@ public function get_body_style_attribute_data() { * @param string $expected_stylesheets Expected stylesheets. * @param array $expected_errors Expected error codes. */ - public function test_body_style_attribute_sanitizer( $source, $expected_content, $expected_stylesheets, $expected_errors = array() ) { + public function test_body_style_attribute_sanitizer( $source, $expected_content, $expected_stylesheets, $expected_errors = [] ) { $dom = AMP_DOM_Utils::get_dom_from_content( $source ); - $error_codes = array(); - $args = array( + $error_codes = []; + $args = [ 'validation_error_callback' => static function( $error ) use ( &$error_codes ) { $error_codes[] = $error['code']; }, - ); + ]; $sanitizer = new AMP_Style_Sanitizer( $dom, $args ); $sanitizer->sanitize(); @@ -277,63 +277,63 @@ public function test_body_style_attribute_sanitizer( $source, $expected_content, * @return array */ public function get_link_and_style_test_data() { - return array( - 'multiple_amp_custom_and_other_styles' => array( + return [ + 'multiple_amp_custom_and_other_styles' => [ '1ius', - array( + [ ':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) b{color:red}', 'i{color:blue}', 'u{color:green}:root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) u{text-decoration:underline}', 's{color:yellow}', - ), - array(), - ), - 'style_elements_with_link_elements' => array( + ], + [], + ], + 'style_elements_with_link_elements' => [ sprintf( '', // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet includes_url( 'css/dashicons.css' ) ), - array( + [ 'strong.before-dashicon', '.dashicons-dashboard:before', 'strong.after-dashicon', ':root:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_) s{color:yellow}', - ), - array(), - ), - 'style_with_no_head' => array( + ], + [], + ], + 'style_with_no_head' => [ 'Not good!', - array( + [ 'body{color:red}', - ), - array(), - ), - 'style_with_not_selectors' => array( + ], + [], + ], + 'style_with_not_selectors' => [ '

      Hello

      ', - array( + [ 'body.foo:not(.bar) > p{color:blue}body.foo:not(.bar) p:not(.baz){color:green}body.foo p{color:yellow}', - ), - array(), - ), - 'style_with_attribute_selectors' => array( + ], + [], + ], + 'style_with_attribute_selectors' => [ '', - array( + [ '.social-navigation a[href*="example.com"]{color:red}', - ), - array(), - ), - 'style_on_root_element' => array( + ], + [], + ], + 'style_on_root_element' => [ 'Hi', - array( + [ 'html:not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_):not(#_){background-color:blue}', ':root:not(#_):not(#_):not(#_):not(#_):not(#_) .amp-wp-10b06ba{color:red}', - ), - array(), - ), - 'styles_with_dynamic_elements' => array( + ], + [], + ], + 'styles_with_dynamic_elements' => [ implode( '', - array( + [ '', '', '', @@ -344,56 +344,56 @@ public function get_link_and_style_test_data() { '
      • Hello
      ', ' ', '', - ) + ] ), - array( + [ 'form [submit-success] b{color:green}', // The [submit-failure] selector is removed because there is no div[submit-failure]. 'amp-live-list li .highlighted{background:yellow}', '', 'body amp-list .portland{color:blue}', - ), - array(), - ), - 'styles_with_calc_functions' => array( + ], + [], + ], + 'styles_with_calc_functions' => [ implode( '', - array( + [ '', '', '', '', // Test unbalanced parentheses. '
      ', - ) + ] ), - array( + [ 'body{color:red;width:calc(1px + calc(2vh / 3) - 2px * 5);outline:solid 1px blue}', '.alignwide{max-width:-webkit-calc(50% + 22.5rem);border:solid 1px red}', '.alignwide{color:red;content:")"}', - ), - array(), - ), - 'style_with_media_element' => array( + ], + [], + ], + 'style_with_media_element' => [ '', - array( + [ '@media print{.print{display:none}}', - ), - array(), - ), - 'selectors_with_ie_hacks_removed' => array( + ], + [], + ], + 'selectors_with_ie_hacks_removed' => [ 'Test', - array( + [ 'span{text-decoration:underline}', - ), - array(), - ), - 'unamerican_lang_attribute_selectors_removed' => array( // USA is used for convenience here. No political statement intended. + ], + [], + ], + 'unamerican_lang_attribute_selectors_removed' => [ // USA is used for convenience here. No political statement intended. 'Test', - array( + [ 'html[lang=en-US]{color:red}html[lang="en-US"]{color:white}html[lang^=en]{color:blue}', - ), - array(), - ), - 'unamerican_lang_selector_selectors_removed' => array( // USA is used for convenience here. No political statement intended. + ], + [], + ], + 'unamerican_lang_selector_selectors_removed' => [ // USA is used for convenience here. No political statement intended. ' Test ', - array( + [ 'html:lang(en-US){color:red}body span:lang(en-US){color:red}html:lang(en){color:white}.test:lang(en-us, en-CA){color:white}html span.test:lang(en-US){color:blue}html:lang("en-US") span.test{color:blue}', - ), - array(), - ), - 'external_link_without_css_file_extension' => array( + ], + [], + ], + 'external_link_without_css_file_extension' => [ 'externally-styled', // phpcs:ignore - array( + [ 'span:before{content:"Returned from: https://example.com/_static/??-eJx9kN1SAyEMhV9Iip3aOl44Pgs"}', - ), - array(), - ), - 'charset_ruleset_removed_without_warning' => array( + ], + [], + ], + 'charset_ruleset_removed_without_warning' => [ '', - array( + [ 'body{color:limegreen}', - ), - array(), - ), - 'dynamic_classes_preserved_always' => array( + ], + [], + ], + 'dynamic_classes_preserved_always' => [ ' @@ -450,14 +450,14 @@ public function get_link_and_style_test_data() {

      Hello!

      ', - array( + [ '.amp-viewer{color:blue}', '.amp-referrer-www-google-com{color:red}', '', // Because there is no
      , , and no non-existent. - ), - array(), - ), - 'dynamic_classes_preserved_conditionally' => array( + ], + [], + ], + 'dynamic_classes_preserved_conditionally' => [ ' @@ -493,7 +493,7 @@ public function get_link_and_style_test_data() { ', - array( + [ '.amp-viewer{color:blue}', '.amp-referrer-www-google-com{color:red}', '.amp-active{color:green}', @@ -511,10 +511,10 @@ public function get_link_and_style_test_data() { '.amp-geo-group-foo{color:peru}', '.amp-iso-country-us{color:oldlace}', '', // Because no non-existent. - ), - array(), - ), - ); + ], + [], + ], + ]; } /** @@ -525,7 +525,7 @@ public function get_link_and_style_test_data() { * @param array $expected_stylesheets Expected stylesheets. * @param array $expected_errors Expected error codes. */ - public function test_link_and_style_elements( $source, $expected_stylesheets, $expected_errors = array() ) { + public function test_link_and_style_elements( $source, $expected_stylesheets, $expected_errors = [] ) { add_filter( 'locale', static function() { @@ -535,15 +535,15 @@ static function() { add_filter( 'pre_http_request', static function( $preempt, $request, $url ) { - $preempt = array( - 'response' => array( + $preempt = [ + 'response' => [ 'code' => 200, - ), - 'headers' => array( + ], + 'headers' => [ 'content-type' => 'text/css', - ), + ], 'body' => sprintf( 'span:before { content: "Returned from: %s"; }', $url ), - ); + ]; return $preempt; }, 10, @@ -551,13 +551,13 @@ static function( $preempt, $request, $url ) { ); $dom = AMP_DOM_Utils::get_dom( $source ); - $error_codes = array(); - $args = array( + $error_codes = []; + $args = [ 'use_document_element' => true, 'validation_error_callback' => static function( $error ) use ( &$error_codes ) { $error_codes[] = $error['code']; }, - ); + ]; $sanitizer = new AMP_Style_Sanitizer( $dom, $args ); $sanitizer->sanitize(); @@ -592,83 +592,83 @@ static function( $preempt, $request, $url ) { * @return array */ public function get_amp_selector_data() { - return array( - 'img' => array( + return [ + 'img' => [ sprintf( '
      ', admin_url( 'images/wordpress-logo.png' ) ), 'div img.logo{border:solid 1px red}', 'div amp-img.logo{border:solid 1px red}', // Note amp-anim is still tree-shaken because it doesn't occur in the DOM. - ), - 'img-missing-class' => array( + ], + 'img-missing-class' => [ sprintf( '
      ', admin_url( 'images/wordpress-logo.png' ) ), 'div img.missing{border:solid 1px red}', '', // Tree-shaken because missing class doesn't occur in the DOM. - ), - 'img-and-anim' => array( + ], + 'img-and-anim' => [ sprintf( '
      ', admin_url( 'images/wordpress-logo.png' ), admin_url( 'images/spinner-2x.gif' ) ), 'div img{border:solid 1px red}', 'div amp-img,div amp-anim{border:solid 1px red}', - ), - 'img_with_amp_img' => array( + ], + 'img_with_amp_img' => [ '', 'amp-img img{background-color:red}', 'amp-img img{background-color:red}', - ), - 'img-cover' => array( + ], + 'img-cover' => [ sprintf( '
      ', admin_url( 'images/wordpress-logo.png' ) ), 'div amp-img.logo img{object-fit:cover}', 'div amp-img.logo img{object-fit:cover}', - ), - 'img-tree-shaking' => array( + ], + 'img-tree-shaking' => [ sprintf( '
      ', admin_url( 'images/wordpress-logo.png' ) ), 'div img.logo{border:solid 1px red}', '', // The selector is removed because there is no div element. - ), - 'attribute_selectors' => array( + ], + 'attribute_selectors' => [ '
      Top', '[type="button"], [type="reset"], [type^="submit"] {color:red} a[href^=http]:after, a[href^="#"]:after { color:blue } span[hidden] {display:none}#content[tabindex="-1"]:focus{ outline: solid 1px red; }', '[type="button"],[type="reset"],[type^="submit"]{color:red}a[href^=http]:after,a[href^="#"]:after{color:blue}span[hidden]{display:none}#content[tabindex="-1"]:focus{outline:solid 1px red}', // Any selector mentioning [type] or [href] will persist since value is not used for tree shaking. - ), - 'playbuzz' => array( + ], + 'playbuzz' => [ '

      hello

      ', 'p + div.pb_feed{border:solid 1px blue}', 'p + amp-playbuzz.pb_feed{border:solid 1px blue}', - ), - 'video' => array( + ], + 'video' => [ '
      ', 'article>video{border:solid 1px green}', 'article>amp-video{border:solid 1px green}', - ), - 'form' => array( + ], + 'form' => [ sprintf( '' ), '#search form label{display:block}', '#search form label{display:block}', - ), - 'video_with_amp_video' => array( + ], + 'video_with_amp_video' => [ '', 'amp-video.video video{border:solid 1px green}', 'amp-video.video video{border:solid 1px green}', - ), - 'iframe' => array( + ], + 'iframe' => [ '

      purple

      ', 'p>*:not(iframe){color:purple}', 'p>*:not(amp-iframe){color:purple}', - ), - 'audio' => array( + ], + 'audio' => [ '', 'audio{border:solid 1px yellow}', 'amp-audio{border:solid 1px yellow}', - ), - 'keyframes' => array( + ], + 'keyframes' => [ '
      test
      ', 'span {color:red;} @keyframes foo { from: { opacity:0; } 50% {opacity:0.5} 75%,80% { opacity:0.6 } to { opacity:1 } }', '@keyframes foo{from:{opacity:0}50%{opacity:.5}75%,80%{opacity:.6}to{opacity:1}}', - ), - 'type_class_names' => array( + ], + 'type_class_names' => [ '