Skip to content

Is there a way to hide public class methods from WP CLI? #5754

Answered by trepmal
hirasso asked this question in How do I?
Discussion options

You must be logged in to vote

If you're not opposed to a closure, I think this could work.

\WP_CLI::add_command('my-command', 'MyCommandClass' );

class MyCommandClass {
	public function send_email(): void
	{
		$wp_mail_from = function(): string {
			return $_ENV['LOGGER_MAIL_FROM'];
		};
		add_filter('wp_mail_from', $wp_mail_from );
		wp_mail(
			$_ENV['LOGGER_MAIL_TO'],
			"Hello there!",
			"Hello again :)",
		);
		remove_filter('wp_mail_from', $wp_mail_from );
	}
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hirasso
Comment options

Answer selected by hirasso
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants