Skip to content

Conversation

@ronchambers
Copy link

@ronchambers ronchambers commented Dec 19, 2024

Description

Co-authors-plus allows developers to use the filter add_filter( 'coauthors_guest_authors_enabled', '__return_false' ), but when developers implement this filter, many of the Co-Authors-Plus CLI commands will then throw FATAL PHP errors.

This PR will verify that when a developers uses the filter add_filter( 'coauthors_guest_authors_enabled', '__return_false' ), that the CLI commands that need Guest Authors will display an error and die gracefully as opposed to throwing a fatal error in the debug.log.

This PR may not be inclusive of all the Co-Authors-Plus CLI commands that need to verified. I simply searched for $coauthors_plus->guest_authors in each command; and if found, I added $this->verify_guest_authors_or_die();.

I did not fully test all commands nor all edge cases as I'm not a Co-Authors-Plus expert.

Example fatal error (without this PR) when running CLI commands:

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:1087
Stack trace:
#0 wp-content/plugins/co-authors-plus/php/class-wp-cli.php(995): CoAuthorsPlus_Command->create_guest_author()
#1 [internal function]: CoAuthorsPlus_Command->create_author()

Deploy Notes

No new dependencies were added.

Steps to Test

  1. Do not pull this PR yet.
  2. Implement add_filter( 'coauthors_guest_authors_enabled', '__return_false' ) in a separate plugin.
  3. Run Co-Authors-Plus CLI commands and see that they throw FATAL errors.
  4. Pull this PR now.
  5. Re-run CLI commands and see that FATALs are no longer thrown and instead WP_CLI will show an error message to the user (and die gracefully).

@ronchambers ronchambers changed the title fix: verify Guest Authors when used in CLI commands fix: verify Guest Authors when running CLI commands Dec 19, 2024
@ronchambers ronchambers marked this pull request as ready for review December 19, 2024 19:44
@leogermani
Copy link
Contributor

This avoids the Fatals, but ideally these commands should work if guest authors are disabled.. :/ But that's I guess would require a bigger refactor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants