From 85020b87aa1ace83b72fe7cbcecaadca1707d1e7 Mon Sep 17 00:00:00 2001 From: leogermani Date: Tue, 5 Nov 2024 13:14:16 -0300 Subject: [PATCH] Releases 3.6.2 and 3.6.3 (#1075) * Increase composer.json required PHP version to 7.4 * Update README to match required PHP version 7.4 * Remove PHP 7.1 from integration tests * PHP 7.4: Use array_key_first() Slightly cleaner to use the native function for getting the first key's value from an array. * PHP 7.4: Use instanceof * PHP 7.4: Use null coalescing * PHP 7.4: Add return types * PHP 7.4: Collapse nested dirname() calls * CI: Remove MySQL workaround for PHP <= 7.3 * Increase WordPress required version to 5.9 * Update integration tests to use WordPress 5.9 * Remove unnecessary phpunit versions for WordPress 5.9 * CI: Update tested versions Doesn't make sense to test WP versions would unsupported PHP versions (e.g. WP 5.9 with PHP 8.3). * Composer: Update dev-dependencies * PHPCS: Consolidate config into config file The PHPCS in the composer.json was duplicating but obscuring some aspects of what was in the `phpcs.xml.dist` file. This change consolidates the Composer commands and the config file. * Support for Yoast %%name%% variable * CI: Update deploy.yml Increase actions/checkout dependency version. * CI: Update integrate.yml action versios * Contents edited to consolidate instructions within the Wiki and bring more attention to its existence (#1055) * add: created a new CLI cmd to backfill missing author terms for posts. (#1060) * add: created a new CLI cmd to backfill missing author terms for posts. * add: adding some comments to the new and old backfill commands. The comments are meant to clarify the key differences between the two commands, and that the new one should be preferred over the old one. * add: batching is the default, pass `--unbatched` flag to run w/o it. --------- Co-authored-by: Gary Jones Co-authored-by: Alec Geatches * Fix/missing wp user type (#988) * fix: preventing loss of fact that a guest author might also be a WP_User * fix: making the update operation dependent on $append flag. This might be a problematic decision. But the way I justify this change is that if you are appending co-authors, there may already be a WP_User set as the author. So we don't really have to care whether one is passed or not. Because of this, we do not need to forcibly return a `false` flag since that is confusing to the caller, especially because we actually do save the guest authors which are given in the call! Instead, if the $append flag is false, we should expect that at least one user will be a WP_User. In that case, if none is passed in, then there is a mismatch of the intended authors. Because now, the `wp_posts.post_author` column will have an old `wp_users.ID` which remains set and most likely isn't the intent of the caller. * fix: attempting DB update only when $new_author is not empty. Also, returning the actual response from the DB, to make this call even more accurate in terms of what is actually happen at the DB layer. * fix: need to ensure pure WP_User is processed correctly as post_author. A pure WP_User (i.e. a WP_User that IS NOT linked to a Guest Author) needs to be handled specially. * fix: a necessary refactor of the `get_coauthor_by` function. This refactor is absolutely necessary in order for all the previous fixes to work as expected. Without this fix, what happens is that when you use `get_coauthor_by` by searching with a Guest Author, if that Guest Author has a valid link to a WP_User, it is summarily ignored. Functions like `add_coauthors` expect at least one coauthor to be a valid WP_User so that the `wp_posts.post_author` column can be appropriately updated. The only case where this function is returning an expected value is when you search by the WP_User first. When it arrives at `$guest_author = $this->guest_authors->get_guest_author_by( $key, $value, $force );`, `$guest_author === false`. It is then forced to move to the switch statement to find a user via their WP_User data. With this refactor, `get_coauthor_by` will now check if the `linked_account` attribute is set. If so, it will attempt to find the corresponding user for the Guest Account. It still gives priority to returning a Guest Author. When a Guest Author is not found, it will search for a WP_User. If found, it will also search to see if a linked Guest Author account exists. If it does, it will return that Guest Author object instead, without losing the fact that this account also has a WP_User associated with it. * fix: returning a plain WP_User if guest authors is not enabled. I forgot to run tests on my previous commit. This satisfies the test Test_CoAuthors_Plus::test_get_coauthor_by_when_guest_authors_not_enabled which is expecting a WP_User when the plugin is not enabled. * feat: adding additional tests for co-authors-plus.php functionality. * fix: preventing loss of fact that a guest author might also be a WP_User * fix: making the update operation dependent on $append flag. This might be a problematic decision. But the way I justify this change is that if you are appending co-authors, there may already be a WP_User set as the author. So we don't really have to care whether one is passed or not. Because of this, we do not need to forcibly return a `false` flag since that is confusing to the caller, especially because we actually do save the guest authors which are given in the call! Instead, if the $append flag is false, we should expect that at least one user will be a WP_User. In that case, if none is passed in, then there is a mismatch of the intended authors. Because now, the `wp_posts.post_author` column will have an old `wp_users.ID` which remains set and most likely isn't the intent of the caller. * fix: attempting DB update only when $new_author is not empty. Also, returning the actual response from the DB, to make this call even more accurate in terms of what is actually happen at the DB layer. * fix: need to ensure pure WP_User is processed correctly as post_author. A pure WP_User (i.e. a WP_User that IS NOT linked to a Guest Author) needs to be handled specially. * fix: a necessary refactor of the get_coauthor_by function. This refactor is absolutely necessary in order for all the previous fixes to work as expected. Without this fix, what happens is that when you use `get_coauthor_by` by searching with a Guest Author, any link to a WP_User the Guest Author may have is summarily ignored. Functions like `add_coauthors` expect at least one coauthor to be a valid WP_User so that the `wp_posts.post_author` column can be appropriately updated. The only case where this function is currently returning an expected value is when you search by a WP_User account/field first. When it arrives at `$guest_author = $this->guest_authors->get_guest_author_by( $key, $value, $force );`, `$guest_author === false`. It is then forced to move to the switch statement to find a user via their WP_User data. With this refactor, `get_coauthor_by` will now check if the `linked_account` attribute is set. If so, it will then attempt to find the corresponding WP_User for the Guest Author. Crucially, it still gives priority to returning a Guest Author. When a Guest Author is not found, it will then attempt to search for a WP_User. If found, it will also search to see if a linked Guest Author account exists. If it does, it will return that Guest Author object instead, without losing the fact that this account also has a WP_User associated with it. * fix: renaming user_login's for new authors introduced for new tests. These user_login's were causing other tests to fail because you cannot create another user with the same user_login. * fix: removing use of assertObjectHasProperty Older version of PHPUnit do not have this function available. Updating to workaround: `assertTrue( property_exists( $obj, 'prop' ) )` * fix: typo in function call * fix: using strict comparison instead of function call `is_null` * fix: using more descriptive assertion for array validation. * fix: using `create_and_get` post factory func, to avoid query call. * fix: removing use of newly introduced is_wp_user property. Relying instead on wp_user property which has already been used before. * fix: PHPCS fixes and added commentary/descriptions to docblocks. * fix: some small quick fixes for formatting and documentation * fix: removing repetitive test. * add: new assertion func that determines if an obj is not a WP_User class * add: new assertion to help determine if a Post has the correct Authors * add: new test solely for CoAuthorPlus::get_coauthor_by(). By fully testing CoAuthorPlus::get_coauthor_by(), we can remove some repetitive assertions that don't directly relate to what's being tested. * fix: was passing string values when I should've been passing Author objs * fix: using a data provider for very similar tests --------- Co-authored-by: Gary Jones * bumping version to 3.6.2 (#1064) * bumping version to 3.6.2 * Update CHANGELOG.md Co-authored-by: Gary Jones * add changelog link --------- Co-authored-by: Gary Jones * fix: prevent the backfill from running forever. (#1065) * fix: prevent the backfill from running forever. There's an edge case where an author that no longer exists can still be assigned to a post. This throws the backfill script into an infinite loop, because the respective author-term is never found/created, and so the underlying problem of missing author-term records is never resolved. The infinite loop is started when at the end of the while loop, the script asks for "remaining posts which need author terms" and so it returns the same rows over and over. This fix addresses this in 2 ways: 1. If an author is not found, we look for the most prolific author on the site and assign the posts to them. If there is no prolific author, one is created. And if one can't be created, an exception is thrown so that the script can't proceed. 2. Checks have been added so that the script can't go beyond what should be the maximum number of rows needing to be addressed. * fix: obtaining the first available admin user account instead. * fix: updating output to reflect that the ID belongs to an Admin account. * fix: this function should be private * fix: switching tactic to skipping posts that have missing post_author. This approach is more faithful with what the current condition on the site would be anyway. If the post author doesn't exist on the site, you wouldn't be able to see the particular post in question in an author archive anyway. Skipping the post instead of reassigning it to the first available admin user is a cleaner solution. * fix: removed unused references from a past commit * fix: appeasing PHPCS * Bump versions to 3.6.3 (#1070) --------- Co-authored-by: Alec Geatches Co-authored-by: Gary Jones Co-authored-by: claudiulodro Co-authored-by: Yoli Hodde Co-authored-by: Eddie Carrasco --- .github/workflows/deploy.yml | 6 +- .github/workflows/integrate.yml | 40 +- .phpcs.xml.dist | 30 +- CHANGELOG.md | 24 +- README.md | 108 +- co-authors-plus.php | 6 +- composer.json | 16 +- package-lock.json | 4 +- package.json | 2 +- .../endpoints/class-coauthors-controller.php | 6 +- .../class-block-coauthor-avatar.php | 6 +- php/blocks/class-blocks.php | 14 +- php/class-coauthors-endpoint.php | 22 +- php/class-coauthors-guest-authors.php | 74 +- php/class-coauthors-iterator.php | 8 +- php/class-coauthors-plus.php | 221 +-- php/class-coauthors-template-filters.php | 6 +- php/class-coauthors-wp-list-table.php | 6 +- php/class-wp-cli.php | 401 +++++- php/integrations/yoast.php | 49 +- 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 | 1264 ++++++++++++++++- 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 +- tests/Integration/bootstrap.php | 4 +- 36 files changed, 2056 insertions(+), 469 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b33bccb8..7cb7e7de 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,15 +2,15 @@ name: Deploy to WordPress.org on: release: types: [released] - # Allow manually triggering the workflow. + # Allow manual triggering of the workflow. workflow_dispatch: jobs: release: name: New release to WordPress.org - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Push to WordPress.org uses: 10up/action-wordpress-plugin-deploy@stable env: diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index ed42ed30..6a70dccd 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -13,27 +13,28 @@ jobs: strategy: matrix: - wordpress: [ '5.7', '6.3' ] - php: [ '7.1', '7.4', '8.0', '8.2' ] - allowed_failure: [ false ] include: + # Check lowest supported WP version, with the lowest supported PHP. + - wordpress: '5.9' + php: '7.4' + allowed_failure: false + # Check latest WP with the highest supported PHP. + - wordpress: 'latest' + php: 'latest' + allowed_failure: false # Check upcoming WP. - - php: '8.2' - wordpress: 'trunk' + - wordpress: 'trunk' + php: 'latest' allowed_failure: true - # Check upcoming PHP. - - php: '8.3' - wordpress: 'latest' - allowed_failure: true - exclude: - # WordPress 5.7 doesn't support PHP 8.2. - - php: '8.2' - wordpress: '5.7' + # Check upcoming PHP - only needed when a new version has been forked (typically Sep-Nov) +# - wordpress: 'trunk' +# php: 'nightly' +# allowed_failure: true fail-fast: false steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up PHP ${{ matrix.php }} uses: shivammathur/setup-php@v2 @@ -43,13 +44,8 @@ jobs: ini-values: ${{ matrix.ini-values }} coverage: ${{ matrix.coverage }} - - name: Install PHPUnit 7.x for WP < 5.9 - if: ${{ matrix.wordpress < 5.9 }} - # Ignore platform requirements, so that PHPUnit 7.5 can be installed on PHP 8.0 (and above). - run: composer require --dev phpunit/phpunit:"^7.5" --ignore-platform-req=php+ --no-update --no-scripts --no-interaction - - name: Install Composer dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: composer-options: --ignore-platform-req=php+ @@ -67,10 +63,6 @@ jobs: - name: Start MySQL service run: sudo systemctl start mysql.service - - name: Setting mysql_native_password for PHP <= 7.3 - if: ${{ matrix.php <= 7.3 }} - run: mysql -u root -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'"; - - name: Install WordPress environment run: composer prepare ${{ matrix.wordpress }} diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index af71a3db..4759537c 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -2,12 +2,18 @@ Generally-applicable sniffs for WordPress plugins - - - - - + + + + + + + + + @@ -17,12 +23,15 @@ - - - + - - + + + + + + + . @@ -30,5 +39,6 @@ */dev-lib/* */node_modules/* */vendor/* + */tests/* */dist/* diff --git a/CHANGELOG.md b/CHANGELOG.md index a77d3535..62638630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.6.3] - 2024-10-25 + +### Fixed + +* Prevent terms backfill CLI command to enter an infinite loop when a post is assigned to a user that no longer exists #1065 + +## [3.6.2] - 2024-10-10 + +### Added + +* Support for Yoast Name variable #1046 +* New CLI cmd to backfill missing author terms for posts #1060 + +### Fixed + +* Correctly populates the post_author column for linked authors #988 + +### Maintenance +* Increase minimum supported WordPress version to 5.9 #1035 + ## [3.6.1] - 2024-04-25 ### Fixed @@ -494,7 +514,9 @@ Props to the many people who helped make this release possible: [catchmyfame](ht **1.1.0 (Apr. 14, 2009)** * Initial beta release. -[3.6.1]: https://github.com/automattic/co-authors-plus/compare/3.6.0..3.6.1 +[3.6.3]: https://github.com/automattic/co-authors-plus/compare/3.6.2...3.6.3 +[3.6.2]: https://github.com/automattic/co-authors-plus/compare/3.6.1...3.6.2 +[3.6.1]: https://github.com/automattic/co-authors-plus/compare/3.6.0...3.6.1 [3.6.0]: https://github.com/automattic/co-authors-plus/compare/3.5.15...3.6.0 [3.5.15]: https://github.com/automattic/co-authors-plus/compare/3.5.14...3.5.15 [3.5.14]: https://github.com/automattic/co-authors-plus/compare/3.5.13...3.5.14 diff --git a/README.md b/README.md index bf103dd6..efa4219c 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Co-Authors Plus -Stable tag: 3.6.1 -Requires at least: 4.1 -Tested up to: 6.5 -Requires PHP: 5.6 -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 +Stable tag: 3.6.3 +Requires at least: 5.9 +Tested up to: 6.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 Contributors: batmoo, danielbachhuber, automattic, GaryJ Assign multiple bylines to posts, pages, and custom post types with a search-as-you-type input box. @@ -19,9 +19,9 @@ Add writers as bylines without creating WordPress user accounts. Simply [create On the frontend, use the [Co-Authors Plus template tags](https://github.com/Automattic/Co-Authors-Plus/wiki/Template-tags) to list co-authors anywhere you'd normally list the author. -This plugin is an almost complete rewrite of the [Co-Authors](https://wordpress.org/plugins/co-authors/) plugin originally developed by Weston Ruter (2007). The original plugin was inspired by the '[Multiple Authors](https://txfx.net/2005/08/16/new-plugin-multiple-authors/)' plugin by Mark Jaquith (2005). +**For more detailed documentation refer to [the GitHub Wiki for this plugin](https://github.com/Automattic/Co-Authors-Plus/wiki).** -Refer to our [wiki](https://github.com/Automattic/Co-Authors-Plus/wiki) for detailed documentation. +Co-Authors Plus is an almost complete rewrite of the [Co-Authors](https://wordpress.org/plugins/co-authors/) plugin originally developed by Weston Ruter (2007). The original plugin was inspired by the '[Multiple Authors](https://txfx.net/2005/08/16/new-plugin-multiple-authors/)' plugin by Mark Jaquith (2005). ## Installation @@ -48,7 +48,7 @@ When a user is deleted from WordPress, they will be removed from all posts for w ### Can I use Co-Authors Plus with WordPress multisite? -Yes! Co-Authors Plus can be activated on a site-by-site basis or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. +Yes! You can [use Co-Authors Plus on WordPress multisite](https://github.com/Automattic/Co-Authors-Plus/wiki#wordpress-multisites). Co-Authors Plus can be activated on a site-by-site basis or network-activated. If you create guest authors, however, those guest authors will exist on a site-by-site basis. ### Who needs permission to do what? @@ -58,97 +58,13 @@ A WordPress user will need the `list_users` capability to create new guest autho ### Can I easily create a list of all co-authors? -Yes! A template tag called `coauthors_wp_list_authors()` accepts many of the same arguments as `wp_list_authors()`. Look in `template-tags.php` for more details. +Yes! You can [create a list of all co-authors with a template tag](https://github.com/Automattic/Co-Authors-Plus/wiki/Template-tags#create-a-list-of-all-co-authors) `coauthors_wp_list_authors()` template tag. This template tag accepts many of the same arguments as `wp_list_authors()`. Look in `template-tags.php` for more details. ### Can I disable Guest Authors? -Yes! Guest authors can be disabled entirely through a filter. Having the following line load on `init` will do the trick: +Yes! You can disable guest authors entirely through a filter. Having the following line load on `init` will do the trick: `add_filter( 'coauthors_guest_authors_enabled', '__return_false' )` ## Change Log [View the change log](https://github.com/Automattic/Co-Authors-Plus/blob/master/CHANGELOG.md). - -## Blocks - -### Co-Authors - -Use this block to create a repeating template that displays the co-authors of a post. By default it contains the Co-Author Name block, but you can add any other block you want to the template. If you choose another Co-Author block like avatar, biography or image it will automatically be supplied the author `context` that it needs. This works similarly to creating a Post Template in a Query Loop block. - -The Co-Authors Block supports two layouts: - -#### Inline Layout - -Use the inline layout to display co-authors in a list on a single wrapping line. - -You can control the characters displayed before, between and after co-authors in the list using the block settings, or change the defaults using the following server-side filters: - -``` -coauthors_default_before -coauthors_default_between -coauthors_default_between_last -coauthors_default_after -``` - -#### Block Layout - -Use the block layout to display co-authors in a vertical stack. While using the block layout you can use block spacing settings to control the vertical space between co-authors. - -Then you can create your own layout using blocks like group, row or stack and it will be applied to each co-author, similar to applying a layout to each post in a query loop. - -### Co-Author Name - -This block displays a co-author's `Display Name` and optionally turns it into a link to their author archive. - -Using the block's advanced settings you can select which HTML element is used to output the name. This is useful in contexts such as an author archive where you might want their name to be a heading. - -### Co-Author Avatar - -Like the post author avatar, or comment author avatar, this block displays a small scale square image of a co-author and utilizes the Gravatar default avatars as configured in your site's discussion options. - -To customize the available sizes, use the [rest_avatar_sizes](https://developer.wordpress.org/reference/hooks/rest_avatar_sizes/) filter. - -### Co-Author Biography - -This block outputs the biographical information for a co-author based on either their user or guest author data. - -The content is wrapped in paragraph elements using `wpautop` and is escaped using `wp_kses_post`. - -### Co-Author Featured Image - -This block requires the use of Guest Authors. Because guest author avatars are uploaded to the WordPress media library, there are more options for displaying these images. - -This block utilizes the image sizes configured in your theme and your site's media settings to present a guest author's avatar at a larger scale or higher resolution. It does not support Gravatars. - -## Block Context - -### Post, Page, Query Loop - -By default, all blocks receive the post context. The job of the Co-Authors Block is to use this context to find the relevant authors and provide context to its inner blocks. - -### Author Archive - -If you want to display data about the author on their own archive, use the individual co-author blocks directly without wrapping them in the Co-Authors Block. During requests for an author archive the correct context is derived from the `author_name` query variable and provided to all blocks that declare their use of the context `co-authors-plus/author`. - -### Extending - -If you make a custom block and want to use the author context, add `co-authors-plus/author` to the `usesContext` property in your block.json file. - -Example: -```json -{ - "usesContext": ["co-authors-plus/author"] -} -``` - -## Block Example Data - -When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the co-author blocks resembles a response to the `/coauthors/v1/coauthors/:user-nicename` REST API endpoint. - -### Extending - -If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `co-authors-plus.author-placeholder`. - -## Block Non-support - -To declare a lack of support for Co-Author Plus blocks on your site, use the filter `coauthors_plus_support_blocks` to return `false`. diff --git a/co-authors-plus.php b/co-authors-plus.php index fe0b7f85..94a2d64e 100755 --- a/co-authors-plus.php +++ b/co-authors-plus.php @@ -11,8 +11,8 @@ * Plugin Name: Co-Authors Plus * Plugin URI: https://wordpress.org/plugins/co-authors-plus/ * Description: Allows multiple authors to be assigned to a post. This plugin is an extended version of the Co-Authors plugin developed by Weston Ruter. - * Version: 3.6.1 - * Requires at least: 5.7 + * Version: 3.6.3 + * Requires at least: 5.9 * Requires PHP: 7.4 * Author: Mohammad Jangda, Daniel Bachhuber, Automattic * Author URI: https://automattic.com @@ -21,7 +21,7 @@ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt */ -const COAUTHORS_PLUS_VERSION = '3.6.1'; +const COAUTHORS_PLUS_VERSION = '3.6.3'; const COAUTHORS_PLUS_FILE = __FILE__; require_once __DIR__ . '/template-tags.php'; diff --git a/composer.json b/composer.json index 935b0b97..b1ad7c22 100644 --- a/composer.json +++ b/composer.json @@ -23,19 +23,17 @@ }, "require": { "composer/installers": "~1.0", - "php": ">=5.6" + "php": ">=7.4" }, "require-dev": { - "automattic/vipwpcs": "^2.2", - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7", + "automattic/vipwpcs": "^3", "dms/phpunit-arraysubset-asserts": "^0.5.0", "php-parallel-lint/php-parallel-lint": "^1.0", "phpcompatibility/phpcompatibility-wp": "^2.1", - "phpunit/phpunit": "^5 || ^6 || ^7 || ^8 || ^9", - "squizlabs/php_codesniffer": "^3.5", + "phpunit/phpunit": "^9", "wp-cli/extension-command": "^2.0", - "wp-cli/wp-cli-tests": "^3", - "wp-coding-standards/wpcs": "^2.3.0", + "wp-cli/wp-cli-tests": "^v4", + "wp-coding-standards/wpcs": "^3.1", "yoast/wp-test-utils": "^1.2" }, "autoload": { @@ -58,10 +56,10 @@ "@php ./vendor/bin/phpunit --exclude=ms-excluded" ], "cs": [ - "@php ./vendor/bin/phpcs -p -s -v -n . --standard=\"WordPress-VIP-Go\" --extensions=php --ignore=\"/vendor/*,/node_modules/*,/tests/*\"" + "@php ./vendor/bin/phpcs" ], "cbf": [ - "@php ./vendor/bin/phpcbf -p -s -v -n . --standard=\"WordPress-VIP-Go\" --extensions=php --ignore=\"/vendor/*,/node_modules/*,/tests/*\"" + "@php ./vendor/bin/phpcbf" ], "lint": [ "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" diff --git a/package-lock.json b/package-lock.json index 32f2fc94..921d9489 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "co-authors-plus", - "version": "3.6.1", + "version": "3.6.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "co-authors-plus", - "version": "3.5.15", + "version": "3.6.3", "license": "GPL-2.0-or-later", "dependencies": { "@wordpress/api-fetch": "^6.14.0", diff --git a/package.json b/package.json index 6e359c71..f4f161c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "co-authors-plus", - "version": "3.6.1", + "version": "3.6.3", "description": "Allows multiple authors to be assigned to a post.", "license": "GPL-2.0-or-later", "private": true, 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/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( 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. diff --git a/php/class-coauthors-endpoint.php b/php/class-coauthors-endpoint.php index 7db6574c..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,11 +126,11 @@ 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' ) ); - $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 ); @@ -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 5ba9047b..299f68ea 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, @@ -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 { ?>