Skip to content

Commit

Permalink
Bump WP version requirement to 6.1 (#13413)
Browse files Browse the repository at this point in the history
Co-authored-by: Anurag Vasanwala <75766877+AnuragVasanwala@users.noreply.github.com>
  • Loading branch information
swissspidy and AnuragVasanwala committed Jul 12, 2023
1 parent a1266e1 commit e5ea5d7
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 218 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests-unit-php.yml
Expand Up @@ -66,7 +66,7 @@ jobs:
experimental: false

- php: '7.4'
wp: '6.0'
wp: '6.1'
experimental: false

- php: '8.0'
Expand Down
23 changes: 12 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions includes/REST_API/Font_Controller.php
Expand Up @@ -253,6 +253,8 @@ public function delete_item( $request ) {
/**
* Prepares a single post output for response.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @since 1.16.0
*
* @param WP_Post $item Post object.
Expand Down Expand Up @@ -313,20 +315,22 @@ public function prepare_item_for_response( $item, $request ): WP_REST_Response {
*/
$response = rest_ensure_response( $data );

// Make preparing links optional after WP 6.1 is min version. See https://github.com/WordPress/wordpress-develop/commit/b7bae6936a9ad54f85bad7e5a73a9d110190d927.
$links = $this->prepare_links( $post );
$response->add_links( $links );
if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
$links = $this->prepare_links( $post );
$response->add_links( $links );

if ( ! empty( $links['self']['href'] ) ) {
$actions = $this->get_available_actions( $post, $request );
if ( ! empty( $links['self']['href'] ) ) {
$actions = $this->get_available_actions( $post, $request );

$self = $links['self']['href'];
$self = $links['self']['href'];

foreach ( $actions as $rel ) {
$response->add_link( $rel, $self );
foreach ( $actions as $rel ) {
$response->add_link( $rel, $self );
}
}
}


return $response;
}

Expand Down
6 changes: 3 additions & 3 deletions includes/REST_API/Publisher_Logos_Controller.php
Expand Up @@ -426,9 +426,9 @@ public function prepare_item_for_response( $post, $request ): WP_REST_Response {
*/
$response = rest_ensure_response( $data );

// Make preparing links optional after WP 6.1 is min version. See https://github.com/WordPress/wordpress-develop/commit/b7bae6936a9ad54f85bad7e5a73a9d110190d927.
$links = $this->prepare_links( $post );
$response->add_links( $links );
if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
$response->add_links( $this->prepare_links( $post ) );
}

return $response;
}
Expand Down
28 changes: 2 additions & 26 deletions includes/REST_API/Stories_Controller.php
Expand Up @@ -320,16 +320,11 @@ public function filter_posts_clauses( $clauses, WP_Query $query ): array {
* @param WP_Post[] $posts Array of post objects.
* @return WP_Post[] Array of posts.
*/
public function prime_post_caches( $posts ): array {
public function prime_post_caches( array $posts ): array {
$post_ids = $this->get_attached_post_ids( $posts );
if ( ! empty( $post_ids ) ) {
_prime_post_caches( $post_ids );
}
// Should not be need once WP 6.1 is min required version. https://github.com/WordPress/wordpress-develop/commit/aff6a79b27d529b92e499018433d01d695457b09.
$user_ids = $this->get_attached_user_ids( $posts );
if ( ! empty( $user_ids ) ) {
cache_users( $user_ids );
}

return $posts;
}
Expand Down Expand Up @@ -420,21 +415,6 @@ public function get_collection_params(): array {
return $query_params;
}

/**
* Get an array of attached post objects.
*
* @since 1.22.0
*
* @param WP_Post[] $posts Array of post objects.
* @return int[] Array of post ids.
*/
protected function get_attached_user_ids( array $posts ): array {
$author_ids = wp_list_pluck( $posts, 'post_author' );
$author_ids = array_map( 'absint', $author_ids );

return array_unique( array_filter( $author_ids ) );
}

/**
* Get an array of attached post objects.
*
Expand All @@ -444,11 +424,7 @@ protected function get_attached_user_ids( array $posts ): array {
* @return int[] Array of post ids.
*/
protected function get_attached_post_ids( array $posts ): array {
// Post thumbnail should not be needed be primed once WP 6.1 is min version. See https://github.com/WordPress/wordpress-develop/commit/c2de42b9adec84397b4c3e5895809f01880a241a.
$thumb_ids = array_filter( array_map( 'get_post_thumbnail_id', $posts ) );
$publisher_ids = array_filter( array_map( [ $this, 'get_publisher_logo_id' ], $posts ) );

return array_unique( [ ...$thumb_ids, ...$publisher_ids ] );
return array_unique( array_filter( array_map( [ $this, 'get_publisher_logo_id' ], $posts ) ) );
}

/**
Expand Down
10 changes: 7 additions & 3 deletions includes/REST_API/Stories_Lock_Controller.php
Expand Up @@ -261,13 +261,16 @@ public function delete_item_permissions_check( $request ) {
/**
* Prepares a single lock output for response.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @since 1.6.0
*
* @param array{time?: int, user?: int}|false $item Lock value, default to false is not set.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response|WP_Error Response object.
*/
public function prepare_item_for_response( $item, $request ) {
public function prepare_item_for_response( $item, $request ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
$fields = $this->get_fields_for_response( $request );
$schema = $this->get_item_schema();

Expand Down Expand Up @@ -344,8 +347,9 @@ public function prepare_item_for_response( $item, $request ) {
*/
$post_id = $request['id'];

// Make preparing links optional after WP 6.1 is min version. See https://github.com/WordPress/wordpress-develop/commit/b7bae6936a9ad54f85bad7e5a73a9d110190d927.
$response->add_links( $this->prepare_links( $item, $post_id ) );
if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
$response->add_links( $this->prepare_links( $item, $post_id ) );
}

$post_type = $this->story_post_type->get_slug();

Expand Down
36 changes: 0 additions & 36 deletions includes/REST_API/Stories_Media_Controller.php
Expand Up @@ -115,9 +115,7 @@ public static function get_registration_action_priority(): int {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_items( $request ) {
add_filter( 'posts_results', [ $this, 'prime_post_caches' ] );
$response = parent::get_items( $request );
remove_filter( 'posts_results', [ $this, 'prime_post_caches' ] );

if ( $request['_web_stories_envelope'] && ! is_wp_error( $response ) ) {
/**
Expand Down Expand Up @@ -194,23 +192,6 @@ public function create_item( $request ) {
return $response;
}

/**
* Prime post caches for attachments and parents.
*
* @since 1.20.0
*
* @param WP_Post[] $posts Array of post objects.
* @return mixed Array of posts.
*/
public function prime_post_caches( $posts ) {
$post_ids = $this->get_attached_post_ids( $posts );
if ( ! empty( $post_ids ) ) {
_prime_post_caches( $post_ids );
}

return $posts;
}

/**
* Retrieves the query params for the posts collection.
*
Expand Down Expand Up @@ -374,23 +355,6 @@ protected function process_post( $post_id, $parent_post, $original_id ) {
return $this->get_post( $attachment_id );
}

/**
* Get an array of attached post objects.
*
* @since 1.20.0
*
* @param WP_Post[] $posts Array of post objects.
* @return int[] Array of post ids.
*/
protected function get_attached_post_ids( array $posts ): array {
// Post thumbnail should not be need to be primed once WP 6.1 is min version. See https://github.com/WordPress/wordpress-develop/commit/c2de42b9adec84397b4c3e5895809f01880a241a.
$thumb_ids = array_filter( array_map( 'get_post_thumbnail_id', $posts ) );
// Post parent should not be need to be primed once WP 6.1 is min version. See https://github.com/WordPress/wordpress-develop/commit/9a488568a027b3b84fbac7b4d25cf43f86dd7a13.
$parent_ids = array_filter( wp_list_pluck( $posts, 'post_parent' ) );

return array_unique( [ ...$thumb_ids, ...$parent_ids ] );
}

/**
* Filter request by allowed mime types.
*
Expand Down
39 changes: 8 additions & 31 deletions packages/e2e-test-utils/src/visitBlockWidgetScreen.js
Expand Up @@ -28,41 +28,18 @@ async function visitBlockWidgetScreen() {

// Disable welcome guide if it is enabled.
const isWelcomeGuideActive = await page.evaluate(() => {
// WordPress 6.0
if (wp.data.select('core/preferences')) {
return Boolean(
wp.data
.select('core/preferences')
.get('core/edit-widgets', 'welcomeGuide')
);
}

// WordPress 5.9
if (wp.data.select('core/interface')) {
return wp.data
.select('core/interface')
?.isFeatureActive?.('core/edit-widgets', 'welcomeGuide');
}

return false;
return Boolean(
wp.data
.select('core/preferences')
.get('core/edit-widgets', 'welcomeGuide')
);
});

if (isWelcomeGuideActive) {
await page.evaluate(() => {
// WordPress 6.0
if (wp.data.select('core/preferences')) {
wp.data
.dispatch('core/preferences')
.toggle('core/edit-widgets', 'welcomeGuide');
return;
}

// WordPress 5.9
if (wp.data.dispatch('core/interface')) {
wp.data
.dispatch('core/interface')
?.toggleFeature?.('core/edit-widgets', 'welcomeGuide');
}
wp.data
.dispatch('core/preferences')
.toggle('core/edit-widgets', 'welcomeGuide');
});
}
}
Expand Down
9 changes: 1 addition & 8 deletions packages/stories-block/src/block/components/storyCard.js
Expand Up @@ -25,12 +25,7 @@ import classNames from 'classnames';
*/
import { RawHTML } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import {
dateI18n,
format,
__experimentalGetSettings,
getSettings as __getSettings,
} from '@wordpress/date';
import { dateI18n, format, getSettings } from '@wordpress/date';

function StoryCard({
title,
Expand All @@ -49,8 +44,6 @@ function StoryCard({
});
const hasContentOverlay = isShowingTitle || isShowingAuthor || isShowingDate;

// @todo Remove this workaround when WP 6.1 is made minimum supported version.
const getSettings = __getSettings ? __getSettings : __experimentalGetSettings;
const dateFormat = getSettings().formats.date;

return (
Expand Down
Expand Up @@ -23,11 +23,7 @@ import PropTypes from 'prop-types';
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import {
dateI18n,
__experimentalGetSettings,
getSettings as __getSettings,
} from '@wordpress/date';
import { dateI18n, getSettings } from '@wordpress/date';
import { RawHTML, useMemo } from '@wordpress/element';

/**
Expand All @@ -44,8 +40,6 @@ function StoryPreview({
removeSelectedStory = noop,
isSelectable = true,
}) {
// @todo Remove this workaround when WP 6.1 is made minimum supported version.
const getSettings = __getSettings ? __getSettings : __experimentalGetSettings;
const dateFormat = getSettings().formats.date;
const displayDate = dateI18n(dateFormat, story.created);
const displayDateText = useMemo(() => {
Expand Down

0 comments on commit e5ea5d7

Please sign in to comment.