Modify logging behavior when WP CLI is being used#16
Conversation
Add check when logging outgoing messages to the error log, for WP CLI. If WP CLI is being used, displaying a single warning rather than dumping the entire email to the error log. Writing to the error log populates on the screen when using WP CLI. See #15
|
Hello @salcode , WP_CLI::warning( __( 'Stop Emails: Not logging email to error log, because WP CLI is being used.', 'stop-emails' ) );Best wishes, |
|
@mitchelldmiller Good point about needing to wrap the string in a translation function - thanks. |
|
I've been giving this overall topic some more thought. Previously, I said
I've given this some further thought. I do my development using Local by Flywheel, which uses Docker to run the WordPress sites within a virtual machine. Through some clever configuration that others far smarter than I figured out, I'm able to run WP CLI from my host machine on the guest machine inside docker. More details on using WP CLI from the host machine with Local by Flywheel. In this case, I don't think I know a way to write an email to the site error log on the guest machine, since we're running the PHP files on the host machine using a copy of PHP there. Therefore, I think we should definitely be providing some sort of message in WP CLI. It can be as simple as the message we're currently considering
but ultimately, it seems it would be helpful to log the actual email that is stopped (though in a nice format for WP CLI). |
This PR modifies logging to the error log when WP CLI is being used.
On the first pass, we're suppressing the email logging because when we write to the error log when using WP CLI it shows up in our on page output.
I'm not certain if this is the best solution. I think ideally, even when using WP CLI, I'd like to write the stopped email information in the error log (but not output the stopped email on the command line).
Props @mitchelldmiller for bringing up the issue of the current behavior, which definitely needs to be improved.
See #15