*/ protected function input_properties(): array { return array( 'panel' => array( 'type' => 'string', 'enum' => Settings_Registry::panel_slugs(), 'description' => __( 'Which settings panel to read. Omit to list every panel instead.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.44 * @return array */ protected function output_properties(): array { return array( 'panel' => array( 'type' => array( 'string', 'null' ) ), 'label' => array( 'type' => array( 'string', 'null' ) ), 'capability' => array( 'type' => array( 'string', 'null' ) ), 'writable' => array( 'type' => array( 'boolean', 'null' ) ), 'permitted' => array( 'type' => array( 'boolean', 'null' ) ), 'fields' => array( 'type' => array( 'object', 'null' ) ), 'panels' => array( 'type' => array( 'array', 'null' ) ), ); } /** * @since 0.0.44 * @return array */ protected function required_input(): array { return array(); } /** * @since 0.0.44 * @return array{readonly: bool, destructive: bool, idempotent: bool} */ protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true, ); } /** * @since 0.0.44 * @param array $input Input. * @return array|WP_Error */ protected function run( array $input ) { $panel = self::scalar( $input['panel'] ?? '' ); if ( '' === $panel ) { return array( 'panel' => null, 'label' => null, 'capability' => null, 'writable' => null, 'permitted' => null, 'fields' => null, 'panels' => $this->panel_directory(), 'message' => __( 'Every All in One SEO settings panel, with the AIOSEO capability each needs. Call again with one panel to read its fields.', 'acrossai-abilities-manager' ), ); } $resolved = Settings_Registry::resolve( $panel ); if ( is_wp_error( $resolved ) ) { return $resolved; } $allowed = Aioseo_Guard::assert_capability( (string) $resolved['capability'] ); if ( is_wp_error( $allowed ) ) { return $allowed; } $fields = Settings_Registry::fields( $panel ); if ( is_wp_error( $fields ) ) { return $fields; } return array( 'panel' => $panel, 'label' => (string) $resolved['label'], 'capability' => (string) $resolved['capability'], 'writable' => Settings_Registry::is_writable( $panel ), 'permitted' => true, 'fields' => $fields, 'panels' => null, 'message' => Settings_Registry::is_writable( $panel ) ? sprintf( /* translators: 1: number of fields, 2: panel slug */ _n( '%1$d field in the "%2$s" panel.', '%1$d fields in the "%2$s" panel.', count( $fields ), 'acrossai-abilities-manager' ), count( $fields ), $panel ) : sprintf( /* translators: %s: panel slug */ __( 'The "%s" panel is readable but not writable here — AIOSEO\'s own aioseo-robots/rules-add, rules-update and rules-delete manage these rules by id.', 'acrossai-abilities-manager' ), $panel ), ); } /** * Every panel, with whether this caller may write it. * * @since 0.0.44 * @return array> */ private function panel_directory(): array { $rows = array(); foreach ( Settings_Registry::panels() as $slug => $panel ) { $rows[] = array( 'panel' => $slug, 'label' => (string) $panel['label'], 'capability' => (string) $panel['capability'], 'writable' => Settings_Registry::is_writable( $slug ), 'permitted' => Aioseo_Guard::has_capability( (string) $panel['capability'] ), ); } return $rows; } }