io = $io; } /** * Prints hide-unused or show-all for the user, and nothing else. * * ## EXAMPLES * * $ wp adminkeep view get --user=admin * show-all * * @param array $args Positional arguments. * @param array $assoc_args Flags. * @return void */ public function get( $args, $assoc_args ) { $user_id = $this->user_id(); $this->io->line( SettingsPage::hides_unused( $user_id ) ? 'hide-unused' : 'show-all' ); } /** * Hides switched-off features from the settings screen's nav. * * The same as switching "Hide unused features" on in the screen. * * ## EXAMPLES * * $ wp adminkeep view hide-unused --user=admin * * @subcommand hide-unused * * @param array $args Positional arguments. * @param array $assoc_args Flags. * @return void */ public function hide_unused( $args, $assoc_args ) { $user_id = $this->user_id(); SettingsPage::set_hides_unused( $user_id, true ); $this->io->success( sprintf( 'Unused features are hidden for user %d.', $user_id ) ); } /** * Shows every feature in the settings screen's nav. The default. * * ## EXAMPLES * * $ wp adminkeep view show-all --user=admin * * @subcommand show-all * * @param array $args Positional arguments. * @param array $assoc_args Flags. * @return void */ public function show_all( $args, $assoc_args ) { $user_id = $this->user_id(); SettingsPage::set_hides_unused( $user_id, false ); $this->io->success( sprintf( 'Every feature is shown for user %d.', $user_id ) ); } /** * The user the command is for: the one WP-CLI's global --user picked. A command cannot * declare its own --user; WP-CLI reserves the name. * * @return int */ private function user_id() { $user_id = get_current_user_id(); if ( ! $user_id ) { $this->io->error( 'The view is set per user. Pick one with --user=.' ); } // Someone who cannot open the settings screen has no view of it to set. if ( ! current_user_can( SettingsPage::CAPABILITY ) ) { $this->io->error( sprintf( 'User %d cannot open the Adminkeep settings screen (it needs %s).', $user_id, SettingsPage::CAPABILITY ) ); } return $user_id; } }