Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP: Add some code comments for future reference #12974

Merged
merged 5 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions includes/Admin/ImgAreaSelect_Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

/**
* Class ImgAreaSelect_Patch
*
* TODO Remove this workaround once WP 6.2 is min version. See https://github.com/WordPress/wordpress-develop/commit/ef0c1d1dd28f13bbe6b39447fb5fbc36edf7df80
*/
class ImgAreaSelect_Patch implements Conditional, Service, Registerable {
/**
Expand Down
1 change: 1 addition & 0 deletions includes/REST_API/Font_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ 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 );

Expand Down
1 change: 1 addition & 0 deletions includes/REST_API/Publisher_Logos_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ 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 );

Expand Down
2 changes: 2 additions & 0 deletions includes/REST_API/Stories_Autosaves_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
/**
* Stories_Autosaves_Controller class.
*
* Register using register_post_type once https://core.trac.wordpress.org/ticket/56922 is committed.
*
* @phpstan-import-type Schema from \Google\Web_Stories\REST_API\Stories_Base_Controller
*/
class Stories_Autosaves_Controller extends WP_REST_Autosaves_Controller implements Service, Delayed, Registerable, HasRequirements {
Expand Down
2 changes: 2 additions & 0 deletions includes/REST_API/Stories_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public function prime_post_caches( $posts ): array {
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 );
Expand Down Expand Up @@ -443,6 +444,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 ) );

Expand Down
1 change: 1 addition & 0 deletions includes/REST_API/Stories_Lock_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ 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 ) );

$post_type = $this->story_post_type->get_slug();
Expand Down
4 changes: 3 additions & 1 deletion includes/REST_API/Stories_Media_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ protected function process_post( $post_id, $parent_post, $original_id ) {
* @return int[] Array of post ids.
*/
protected function get_attached_post_ids( array $posts ): array {
$thumb_ids = array_filter( array_map( 'get_post_thumbnail_id', $posts ) );
// 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 ] );
Expand Down
7 changes: 1 addition & 6 deletions includes/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@ function load_functions(): void {
* @return array<string, array{body: string, headers: array<string,string>}|array<string, array{body: string, headers: array<string,string>}>> Modified reduce accumulator.
*/
function rest_preload_api_request( array $memo, $path ): array {
// array_reduce() doesn't support passing an array in PHP 5.2,
// so we need to make sure we start with one.
if ( ! \is_array( $memo ) ) {
$memo = [];
}

if ( empty( $path ) ) {
return $memo;
}
Expand Down Expand Up @@ -210,6 +204,7 @@ function rest_preload_api_request( array $memo, $path ): array {
return $memo;
}

// This line is different from code. Adds untrailingslashit. See https://core.trac.wordpress.org/ticket/57048.
$request = new WP_REST_Request( $method, untrailingslashit( $path_parts['path'] ) );
if ( ! empty( $path_parts['query'] ) ) {
$query_params = [];
Expand Down