wp_cli = $wp_cli ? $wp_cli : new WP_CLI(); } /** * Register the WP-CLI commands by looping through the commands array and adding each command. * * @since 1.15.0 * * @return void */ public function register() { // Bail if not running in WP_CLI. if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) { return; } /** * Filter the list of classes that hold the commands to be registered. * * @since 1.15.0 * * @param CLICommandInterface[] $commands array of classes to register as commands. */ $commands = apply_filters( 'edac_filter_command_classes', $this->commands ); if ( ! is_array( $commands ) ) { $commands = []; } foreach ( $commands as $command ) { // All commands must follow the interface. if ( ! is_subclass_of( $command, CLICommandInterface::class, true ) ) { continue; } try { $this->wp_cli::add_command( $command::get_name(), $command, $command::get_args() ); // For ease of typing on cli there's a shortname too in some commands. if ( method_exists( $command, 'get_shortname' ) ) { $this->wp_cli::add_command( $command::get_shortname(), $command, $command::get_args() ); } } catch ( Exception $e ) { $this->wp_cli::warning( sprintf( // translators: 1: a php classname, 2: an error message that was thrown about why this failed to register. esc_html__( 'Failed to register command %1$s because %2$s', 'accessibility-checker' ), $command, $e->getMessage() ) ); } } } }