* : The token from your Clvrly portal, or the whole install snippet in quotes. * * @param array $args Positional arguments. */ public function connect( $args ) { $token = Clvrly_Settings::extract_token( $args[0] ); if ( ! Clvrly_Settings::is_valid_token( $token ) ) { WP_CLI::error( 'That doesn\'t look like a Clvrly token.' ); } $this->save( array( 'token' => $token ) ); WP_CLI::success( 'Token saved.' ); $this->check(); } /** * Remove the saved token. */ public function disconnect() { $this->save( array( 'token' => '' ) ); WP_CLI::success( 'Token removed. The assistant no longer loads.' ); } /** * Show the assistant to visitors. */ public function enable() { $this->save( array( 'enabled' => 1 ) ); WP_CLI::success( 'Assistant enabled.' ); } /** * Hide the assistant from visitors without removing the token. */ public function disable() { $this->save( array( 'enabled' => 0 ) ); WP_CLI::success( 'Assistant disabled.' ); } /** * Check the token, domain, subscription and homepage, and print the results. * * Exits with an error code if anything needs fixing, so it can be used in scripts. */ public function check() { if ( ! Clvrly_Settings::has_token() ) { WP_CLI::error( 'No token set. Run: wp clvrly connect ' ); } $status = Clvrly_Status::run(); $labels = array( 'ok' => '%G✓%n', 'info' => '%Bi%n', 'warning' => '%Y!%n', 'error' => '%R✗%n', ); foreach ( $status['items'] as $item ) { WP_CLI::line( WP_CLI::colorize( $labels[ $item['status'] ] ) . ' ' . $item['label'] . ( $item['detail'] ? ' - ' . $item['detail'] : '' ) ); } if ( ! Clvrly_Settings::is_enabled() ) { WP_CLI::warning( 'The assistant is disabled. Run: wp clvrly enable' ); } if ( 'error' === $status['state'] ) { WP_CLI::error( 'Clvrly needs attention.' ); } if ( 'warning' === $status['state'] ) { WP_CLI::warning( 'Clvrly is connected, with warnings.' ); return; } WP_CLI::success( 'Clvrly is set up correctly.' ); } /** * Merge changes into the saved settings. * * @param array $changes Setting => value. */ private function save( $changes ) { update_option( CLVRLY_OPTION, array_merge( Clvrly_Settings::get(), $changes ) ); } }