-
Hi there! I'd like to know if there is a way to hide public methods from a class-based custom WP_CLI command. I'm adding a custom command with subcommands like this: \WP_CLI::add_command('my-command', new MyCommandClass()); The class contains various public methods that are being resolved to subcommands as expected. A reduced example: class MyCommandClass {
public function send_email(): void
{
wp_mail(
$_ENV['LOGGER_MAIL_TO'],
"Hello there!",
"Hello again :)",
);
}
} Now I need to overwrite the class MyCommandClass {
public function send_email(): void
{
add_filter('wp_mail_from', [$this, 'wp_mail_from']);
wp_mail(
$_ENV['LOGGER_MAIL_TO'],
"Hello there!",
"Hello again :)",
);
remove_filter('wp_mail_from', [$this, 'wp_mail_from']);
}
/**
* Overwrite wp_mail_from
*/
public function wp_mail_from(): string
{
return $_ENV['LOGGER_MAIL_FROM'];
}
} On the shell I now get this: ❯ wp my-command
usage: wp my-command send_email
or: wp my-command wp_mail_from # I don't want this! Is there a way to hide the filter callback |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you're not opposed to a closure, I think this could work.
|
Beta Was this translation helpful? Give feedback.
If you're not opposed to a closure, I think this could work.