Fix ( guest-authors-for-cli ): allow GAs for CLI context #3606
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
Fix / idea: Don't turn off Guest Authors for CLI. Most of the built-in CoAuthorsPlus CLI commands don't properly check to see if GAs are enabled or not. If GAs are not enabled, then many commands will throw a PHP FATAL:
PHP Fatal error: Uncaught Error: Call to a member function get_guest_author_by() on null in /wp-content/plugins/co-authors-plus/php/class-wp-cli.php:1085
Of all the CLIs, there is only 1 that checks if GAs are enabled:
https://github.com/Automattic/Co-Authors-Plus/blob/7330dc12643bd5f8dc3d177815f8b81ff5a72820/php/class-wp-cli.php#L855
Overall, it seems that the filter
coauthors_guest_authors_enabled
is generally ignored in CLI context, but used in WP Admin. Which seems inline with what the Newspack Plugin wants: to disable the existing GA admin page and replace with the new Newspack Contributor admin page.As such, this PR will keep GAs enabled for CLI.
This will also help with Newspack Custom Content Migrator and Newspack Migration Tools where their CLIs have a requirement for GA in their constructor. ( Issue: Automattic/newspack-migration-tools#41 )
How to test the changes in this Pull Request:
wp co-authors-plus create-author
-- Not found; creating profile. Warning: -- Failed to create guest author: display_name is a required field
. That is OK. It means no fatal was thrown and the CLI command can be used properly.Other information: