From 75437da58196ec9d67b1d002b671229dbb74b99c Mon Sep 17 00:00:00 2001 From: Alec Geatches Date: Mon, 22 Apr 2024 13:15:19 -0600 Subject: [PATCH 1/9] Increase composer.json required PHP version to 7.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 935b0b97..e55cb0c8 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require": { "composer/installers": "~1.0", - "php": ">=5.6" + "php": ">=7.4" }, "require-dev": { "automattic/vipwpcs": "^2.2", From fdce51cafaa26fa232bf9796341381cda41eaff4 Mon Sep 17 00:00:00 2001 From: Alec Geatches Date: Mon, 22 Apr 2024 13:19:08 -0600 Subject: [PATCH 2/9] Update README to match required PHP version 7.4 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dccda58c..94ce3833 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Stable tag: 3.6.0 Requires at least: 4.1 Tested up to: 6.5 -Requires PHP: 5.6 +Requires PHP: 7.4 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: authors, users, multiple authors, co-authors, multi-author, publishing From da21813fc0e8e01714e72da1477523cd97fb91d8 Mon Sep 17 00:00:00 2001 From: Alec Geatches Date: Mon, 22 Apr 2024 13:24:38 -0600 Subject: [PATCH 3/9] Remove PHP 7.1 from integration tests --- .github/workflows/integrate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index ed42ed30..ff3caa44 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: wordpress: [ '5.7', '6.3' ] - php: [ '7.1', '7.4', '8.0', '8.2' ] + php: [ '7.4', '8.0', '8.2' ] allowed_failure: [ false ] include: # Check upcoming WP. From fd9b266c619666a203bf9e403ef5e9158727c16e Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 23 Apr 2024 16:19:51 +0100 Subject: [PATCH 4/9] PHP 7.4: Use array_key_first() Slightly cleaner to use the native function for getting the first key's value from an array. --- .../block-coauthor-avatar/class-block-coauthor-avatar.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php index b9541cfa..52e47f6f 100644 --- a/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php +++ b/php/blocks/block-coauthor-avatar/class-block-coauthor-avatar.php @@ -6,7 +6,7 @@ * @since 3.6.0 */ -namespace CoAuthors\Blocks; +namespace CoAuthors\Blocks; use WP_Block; /** @@ -52,12 +52,12 @@ public static function render_block( array $attributes, string $content, WP_Bloc if ( empty( $avatar_urls ) ) { return ''; } - + $display_name = esc_html( $author['display_name'] ?? '' ); $link = esc_url( $author['link'] ?? '' ); $is_link = '' !== $link && $attributes['isLink'] ?? false; $rel = $attributes['rel'] ?? ''; - $size = $attributes['size'] ?? array_keys( $avatar_urls )[0]; + $size = $attributes['size'] ?? array_key_first( $avatar_urls ); $align = esc_attr( $attributes['align'] ?? '' ); $srcset = array_map( From 2c4c9ecc380c20fd3940d436c3959783ba0ebfd3 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 23 Apr 2024 16:26:45 +0100 Subject: [PATCH 5/9] PHP 7.4: Use instanceof --- php/api/endpoints/class-coauthors-controller.php | 6 +++--- php/blocks/class-blocks.php | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/php/api/endpoints/class-coauthors-controller.php b/php/api/endpoints/class-coauthors-controller.php index 7faef532..3166ec89 100644 --- a/php/api/endpoints/class-coauthors-controller.php +++ b/php/api/endpoints/class-coauthors-controller.php @@ -164,7 +164,7 @@ public function get_item( $request ) { * @param WP_User|stdClass $coauthor */ public static function is_coauthor( $coauthor ): bool { - return is_a( $coauthor, 'WP_User' ) || self::is_guest_author( $coauthor ); + return $coauthor instanceof \WP_User || self::is_guest_author( $coauthor ); } /** @@ -320,10 +320,10 @@ public function get_item_schema(): array { * @return WP_REST_Response|WP_Error */ public function prepare_item_for_response( $author, $request ) { - + $fields = $this->get_fields_for_response( $request ); - if ( is_a( $author, 'WP_User' ) ) { + if ( $author instanceof \WP_User ) { $author = $author->data; $author->description = get_user_meta( $author->ID, 'description', true ); } diff --git a/php/blocks/class-blocks.php b/php/blocks/class-blocks.php index 2f8abd81..a668d2e9 100644 --- a/php/blocks/class-blocks.php +++ b/php/blocks/class-blocks.php @@ -1,7 +1,7 @@ get_registered( $block_name ); - if ( ! is_a( $block, 'WP_Block_Type' ) ) { + if ( ! $block instanceof \WP_Block_Type ) { return false; } @@ -165,7 +165,7 @@ public static function enqueue_store(): void { * @return null|array Either an array of data about an author, or null. */ public static function get_author_with_api_schema( $author ): ?array { - if ( ! ( is_a( $author, 'stdClass' ) || is_a( $author, 'WP_User' ) ) ) { + if ( ! ( $author instanceof \stdClass || $author instanceof \WP_User ) ) { return null; } @@ -199,10 +199,10 @@ public static function get_author_with_api_schema( $author ): ?array { /** * Get CoAuthors with API Schema - * + * * Use the global WP_REST_Server to fetch co-authors for a post, * so that it matches what a user would see in the editor. - * + * * @since 3.6.0 * @param int $post_id Post ID for querying co-authors. * @param array $data Co-authors as returned by the REST API. From 5692feb34bf9b02d867d211bdb360e3f3af3d1c0 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 23 Apr 2024 16:29:53 +0100 Subject: [PATCH 6/9] PHP 7.4: Use null coalescing --- php/class-coauthors-endpoint.php | 2 +- php/class-coauthors-guest-authors.php | 28 +++++++++++++-------------- php/class-coauthors-plus.php | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/php/class-coauthors-endpoint.php b/php/class-coauthors-endpoint.php index 7db6574c..51ef9d07 100644 --- a/php/class-coauthors-endpoint.php +++ b/php/class-coauthors-endpoint.php @@ -130,7 +130,7 @@ public function get_coauthors_search_results( $request ) { $response = array(); $search = strtolower( $request->get_param( 'q' ) ); - $ignorable = null === $request->get_param( 'existing_authors' ) ? '' : $request->get_param( 'existing_authors' ); + $ignorable = $request->get_param( 'existing_authors' ) ?? ''; $ignore = explode( ',', $ignorable ); $authors = $this->coauthors->search_authors( $search, $ignore ); diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index 5ba9047b..ae14719c 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -109,21 +109,21 @@ public function __construct() { $args = array( 'label' => $this->labels['singular'], 'labels' => array( - 'name' => isset( $this->labels['plural'] ) ? $this->labels['plural'] : '', - 'singular_name' => isset( $this->labels['singular'] ) ? $this->labels['singular'] : '', + 'name' => $this->labels['plural'] ?? '', + 'singular_name' => $this->labels['singular'] ?? '', 'add_new' => _x( 'Add New', 'guest author', 'co-authors-plus' ), - 'all_items' => isset( $this->labels['all_items'] ) ? $this->labels['all_items'] : '', - 'add_new_item' => isset( $this->labels['add_new_item'] ) ? $this->labels['add_new_item'] : '', - 'edit_item' => isset( $this->labels['edit_item'] ) ? $this->labels['edit_item'] : '', - 'new_item' => isset( $this->labels['new_item'] ) ? $this->labels['new_item'] : '', - 'view_item' => isset( $this->labels['view_item'] ) ? $this->labels['view_item'] : '', - 'search_items' => isset( $this->labels['search_items'] ) ? $this->labels['search_items'] : '', - 'not_found' => isset( $this->labels['not_found'] ) ? $this->labels['not_found'] : '', - 'not_found_in_trash' => isset( $this->labels['not_found_in_trash'] ) ? $this->labels['not_found_in_trash'] : '', - 'featured_image' => isset( $this->labels['featured_image'] ) ? $this->labels['featured_image'] : '', - 'set_featured_image' => isset( $this->labels['set_featured_image'] ) ? $this->labels['set_featured_image'] : '', - 'use_featured_image' => isset( $this->labels['use_featured_image'] ) ? $this->labels['use_featured_image'] : '', - 'remove_featured_image' => isset( $this->labels['remove_featured_image'] ) ? $this->labels['remove_featured_image'] : '', + 'all_items' => $this->labels['all_items'] ?? '', + 'add_new_item' => $this->labels['add_new_item'] ?? '', + 'edit_item' => $this->labels['edit_item'] ?? '', + 'new_item' => $this->labels['new_item'] ?? '', + 'view_item' => $this->labels['view_item'] ?? '', + 'search_items' => $this->labels['search_items'] ?? '', + 'not_found' => $this->labels['not_found'] ?? '', + 'not_found_in_trash' => $this->labels['not_found_in_trash'] ?? '', + 'featured_image' => $this->labels['featured_image'] ?? '', + 'set_featured_image' => $this->labels['set_featured_image'] ?? '', + 'use_featured_image' => $this->labels['use_featured_image'] ?? '', + 'remove_featured_image' => $this->labels['remove_featured_image'] ?? '', ), 'public' => true, 'publicly_queryable' => false, diff --git a/php/class-coauthors-plus.php b/php/class-coauthors-plus.php index fb7df6ce..fbee12d1 100644 --- a/php/class-coauthors-plus.php +++ b/php/class-coauthors-plus.php @@ -1519,8 +1519,8 @@ public function get_to_be_filtered_caps() { public function filter_user_has_cap( $allcaps, $caps, $args ) { $cap = $args[0]; - $user_id = isset( $args[1] ) ? $args[1] : 0; - $post_id = isset( $args[2] ) ? $args[2] : 0; + $user_id = $args[1] ?? 0; + $post_id = $args[2] ?? 0; if ( ! in_array( $cap, $this->get_to_be_filtered_caps(), true ) ) { return $allcaps; From c1d7f63f74ba05d404a9fbbc08de1ecfdcb5346c Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 23 Apr 2024 16:47:46 +0100 Subject: [PATCH 7/9] PHP 7.4: Add return types --- php/class-coauthors-endpoint.php | 20 ++--- php/class-coauthors-guest-authors.php | 46 +++++----- php/class-coauthors-iterator.php | 8 +- php/class-coauthors-plus.php | 86 +++++++++---------- php/class-coauthors-template-filters.php | 6 +- php/class-coauthors-wp-list-table.php | 6 +- php/class-wp-cli.php | 38 ++++---- php/integrations/yoast.php | 24 +++--- php/integrations/yoast/class-coauthor.php | 6 +- tests/Behat/FeatureContext.php | 6 +- tests/Integration/AuthorQueriedObjectTest.php | 4 +- tests/Integration/AuthorQueriesTest.php | 14 +-- tests/Integration/CoAuthorsPlusTest.php | 48 +++++------ tests/Integration/EndpointsTest.php | 18 ++-- tests/Integration/GuestAuthorsTest.php | 48 +++++------ tests/Integration/ManageCoAuthorsTest.php | 24 +++--- .../TemplateTags/CoauthorsGetAvatarTest.php | 10 +-- .../CoauthorsPostsLinksSingleTest.php | 6 +- .../TemplateTags/CoauthorsPostsLinksTest.php | 8 +- .../CoauthorsWpListAuthorsTest.php | 20 ++--- .../TemplateTags/GetCoauthorsTest.php | 12 +-- .../TemplateTags/IsCoauthorForPostTest.php | 10 +-- tests/Integration/TemplateTagsTest.php | 22 ++--- 23 files changed, 246 insertions(+), 244 deletions(-) diff --git a/php/class-coauthors-endpoint.php b/php/class-coauthors-endpoint.php index 51ef9d07..96198988 100644 --- a/php/class-coauthors-endpoint.php +++ b/php/class-coauthors-endpoint.php @@ -51,7 +51,7 @@ public function __construct( $coauthors_instance ) { /** * Register endpoints. */ - public function add_endpoints() { + public function add_endpoints(): void { register_rest_route( static::NS, static::SEARCH_ROUTE, @@ -126,7 +126,7 @@ public function add_endpoints() { * @param WP_REST_Request $request Request object. * @return WP_REST_Response */ - public function get_coauthors_search_results( $request ) { + public function get_coauthors_search_results( $request ): WP_REST_Response { $response = array(); $search = strtolower( $request->get_param( 'q' ) ); @@ -149,7 +149,7 @@ public function get_coauthors_search_results( $request ) { * @param WP_REST_Request $request Request object. * @return WP_REST_Response */ - public function get_coauthors( $request ) { + public function get_coauthors( $request ): WP_REST_Response { $response = array(); $this->_build_authors_response( $response, $request ); @@ -163,7 +163,7 @@ public function get_coauthors( $request ) { * @param WP_REST_Request $request Request object. * @return WP_REST_Response */ - public function update_coauthors( $request ) { + public function update_coauthors( $request ): WP_REST_Response { $response = array(); @@ -185,7 +185,7 @@ public function update_coauthors( $request ) { * @param mixed $param Value to validate. * @return bool */ - public function validate_numeric( $param ) { + public function validate_numeric( $param ): bool { return is_numeric( $param ); } @@ -194,7 +194,7 @@ public function validate_numeric( $param ) { * * @return bool */ - public function can_edit_coauthors() { + public function can_edit_coauthors(): bool { return $this->coauthors->current_user_can_set_authors(); } @@ -205,7 +205,7 @@ public function can_edit_coauthors() { * @param object $author The result from co-authors methods. * @return array */ - public function _format_author_data( $author ) { + public function _format_author_data( $author ): array { return array( 'id' => esc_html( $author->ID ), @@ -223,7 +223,7 @@ public function _format_author_data( $author ) { * @param array The response array. * @param int The post ID from the request. */ - public function _build_authors_response( &$response, $request ) { + public function _build_authors_response( &$response, $request ): void { $authors = get_coauthors( $request->get_param( 'post_id' ) ); if ( ! empty( $authors ) ) { @@ -237,7 +237,7 @@ public function _build_authors_response( &$response, $request ) { * Add filters to REST endpoints for each post that * supports co-authors. */ - public function modify_responses() { + public function modify_responses(): void { $post_types = $this->coauthors->supported_post_types(); @@ -266,7 +266,7 @@ public function modify_responses() { * @param WP_REST_Request $request Request object. * @return WP_REST_Response */ - public function remove_author_link( $response, $post, $request ) { + public function remove_author_link( $response, $post, $request ): WP_REST_Response { if ( ! isset( $request['context'] ) || 'edit' !== $request['context'] diff --git a/php/class-coauthors-guest-authors.php b/php/class-coauthors-guest-authors.php index ae14719c..299f68ea 100644 --- a/php/class-coauthors-guest-authors.php +++ b/php/class-coauthors-guest-authors.php @@ -195,7 +195,7 @@ public function filter_post_updated_messages( $messages ) { * * @since 3.0 */ - public function handle_create_guest_author_action() { + public function handle_create_guest_author_action(): void { if ( ! isset( $_GET['action'], $_GET['nonce'], $_GET['user_id'] ) || 'cap-create-guest-author' !== $_GET['action'] ) { return; @@ -232,7 +232,7 @@ public function handle_create_guest_author_action() { * * @since 3.0 */ - public function handle_delete_guest_author_action() { + public function handle_delete_guest_author_action(): void { global $coauthors_plus; if ( ! isset( $_POST['action'], $_POST['reassign'], $_POST['_wpnonce'], $_POST['id'] ) || 'delete-guest-author' != $_POST['action'] ) { @@ -305,7 +305,7 @@ public function handle_delete_guest_author_action() { * * @since 3.0 */ - public function handle_ajax_search_coauthors_to_assign() { + public function handle_ajax_search_coauthors_to_assign(): void { global $coauthors_plus; if ( ! current_user_can( $this->list_guest_authors_cap ) ) { @@ -377,7 +377,7 @@ public function action_parse_request( $query ) { * * @since 3.0 */ - public function action_admin_menu() { + public function action_admin_menu(): void { add_submenu_page( $this->parent_page, $this->labels['plural'], $this->labels['plural'], $this->list_guest_authors_cap, 'view-guest-authors', array( $this, 'view_guest_authors_list' ) ); @@ -388,7 +388,7 @@ public function action_admin_menu() { * * @since 3.0 */ - public function action_admin_enqueue_scripts() { + public function action_admin_enqueue_scripts(): void { global $pagenow; // Enqueue our guest author CSS on the related pages if ( $this->parent_page === $pagenow && isset( $_GET['page'] ) && 'view-guest-authors' === $_GET['page'] ) { @@ -408,7 +408,7 @@ public function action_admin_enqueue_scripts() { * * @since 3.0.1 */ - public function change_title_icon() { + public function change_title_icon(): void { ?>