Skip to content

Commit

Permalink
Merge pull request #7782 from ampproject/fix/query-get-posts
Browse files Browse the repository at this point in the history
Use posts member of WP_Query instead of get_posts method
  • Loading branch information
westonruter authored Jul 8, 2024
2 parents 546b0d2 + 3e75a33 commit 3175da6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bin/add-test-widgets-to-sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function amp_media( $type, $count = 3 ) {
)
);
}
return $query->get_posts();
return $query->posts;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion bin/create-embed-test-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function amp_get_media_items_ids( $type, $image_count = 3 ) {
)
);
}
return implode( ',', $query->get_posts() );
return implode( ',', $query->posts );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/validation/class-amp-validated-url-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ public static function delete_stylesheets_postmeta_batch( $count, $before ) {
'posts_per_page' => $count,
]
);
foreach ( $query->get_posts() as $post_id ) {
foreach ( $query->posts as $post_id ) {
if ( delete_post_meta( $post_id, self::STYLESHEETS_POST_META_KEY ) ) {
$deleted++;
}
Expand Down Expand Up @@ -1037,7 +1037,7 @@ public static function garbage_collect_validated_urls( $count = 100, $before = '
],
]
);
foreach ( $query->get_posts() as $post ) {
foreach ( $query->posts as $post ) {
if ( ! self::is_post_safe_to_garbage_collect( $post ) ) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Support/SupportData.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ public function get_amp_urls() {
];

$query = new WP_Query( $query_args );
$amp_validated_posts = $query->get_posts();
$amp_validated_posts = $query->posts;

foreach ( $amp_validated_posts as $amp_validated_post ) {
$validation_data = $this->process_raw_post_errors( $amp_validated_post );
Expand Down
4 changes: 2 additions & 2 deletions src/Validation/ScannableURLProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private function get_author_page_urls( $offset, $number ) {
'posts_per_page' => 1,
]
);
if ( count( $authored_post_query->get_posts() ) > 0 ) {
if ( count( $authored_post_query->posts ) > 0 ) {
$author_page_urls[] = get_author_posts_url( $author->ID, $author->user_nicename );
}
}
Expand Down Expand Up @@ -376,7 +376,7 @@ private function get_date_page() {
'order' => 'DESC',
]
);
$posts = $query->get_posts();
$posts = $query->posts;

$latest_post = array_shift( $posts );
if ( ! $latest_post ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/php/src/Validation/ScannableURLProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public function test_get_date_page() {
'fields' => 'ids',
]
);
foreach ( $query->get_posts() as $deleted_post ) {
foreach ( $query->posts as $deleted_post ) {
wp_delete_post( $deleted_post );
}
$this->assertNull( $this->call_private_method( $this->scannable_url_provider, 'get_date_page' ) );
Expand Down
14 changes: 12 additions & 2 deletions tests/php/test-amp-style-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3518,8 +3518,18 @@ function ( $original_dom, $original_source, $amphtml_dom, $amphtml_source ) {
$this->assertStringContainsString( 'admin-bar', $original_dom->body->getAttribute( 'class' ) );
$this->assertStringContainsString( 'earlyprintstyle', $original_source, 'Expected early print style to not be present.' );

$this->assertStringContainsString( '.wp-block-audio figcaption', $amphtml_source, 'Expected block-library/style.css' );
$this->assertStringContainsString( '[class^="wp-block-"]:not(.wp-block-gallery) figcaption', $amphtml_source, 'Expected twentyten/blocks.css' );
if ( defined( 'GUTENBERG_VERSION' ) && version_compare( GUTENBERG_VERSION, '18.7', '>=' ) ) {
$this->assertStringContainsString( '.wp-block-audio :where(figcaption)', $amphtml_source, 'Expected block-library/style.css' );
} else {
$this->assertStringContainsString( '.wp-block-audio figcaption', $amphtml_source, 'Expected block-library/style.css' );
}

if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '6.6', '>=' ) ) {
$this->assertStringContainsString( '[class^="wp-block-"]:not(.wp-block-gallery) > figcaption', $amphtml_source, 'Expected twentyten/blocks.css' );
} else {
$this->assertStringContainsString( '[class^="wp-block-"]:not(.wp-block-gallery) figcaption', $amphtml_source, 'Expected twentyten/blocks.css' );
}

$amphtml_source = preg_replace( '/\s*>\s*/', '>', $amphtml_source ); // Account for variance in postcss.
$this->assertStringContainsString( '.amp-wp-default-form-message>p', $amphtml_source, 'Expected amp-default.css' );
$this->assertStringContainsString( 'ab-empty-item', $amphtml_source, 'Expected admin-bar.css to still be present.' );
Expand Down

0 comments on commit 3175da6

Please sign in to comment.