backwpup icon indicating copy to clipboard operation
backwpup copied to clipboard

Disable output info on CLI?

Open remcotolsma opened this issue 7 months ago • 1 comments

We run the WordPress cron via the following cron job command:

wp cron event run --due-now --quiet

Here we deliberately use the --quiet parameter so that the command does not give any output. If there is output due to errors, we will receive an e-mail notification about it. Because BackWPup does give standard output, we now also receive a daily e-mail notification with the BackWPup CLI info:

https://github.com/wp-media/backwpup/blob/0fc91387b9375456a2261e15e0d1ae5a92c108a3/inc/class-job.php#L617-L620

Is it possible to add something to disable this CLI info write?

remcotolsma avatar Apr 07 '25 09:04 remcotolsma

I just discovered that the problem is not only in the following lines of code:

https://github.com/wp-media/backwpup/blob/0fc91387b9375456a2261e15e0d1ae5a92c108a3/inc/class-job.php#L617-L620

The following lines of code are also relevant here:

https://github.com/wp-media/backwpup/blob/92f32e1dd96ea1e2aa60b7e6c366703113ec9c6e/inc/class-job.php#L864-L887

Checking the availability of WP_CLI is a possible solution.

Should the WP_CLI::log() method be used instead of WP_CLI::line( )?

Message is written to STDOUT, or discarded when --quiet flag is supplied.

https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-log/

Message is written to STDOUT. WP_CLI::log() is typically recommended; WP_CLI::line() is included for historical compat.

https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-line/

I personally prefer this approach:

if ( \method_exists( WP_CLI::class, 'log' ) ) {
	WP_CLI::log( $message );
}

remcotolsma avatar Apr 08 '25 07:04 remcotolsma