*/ protected function input_properties(): array { return array( 'panel' => array( 'type' => 'string', 'enum' => Settings_Registry::panel_slugs(), 'description' => __( 'Which settings panel to read.', 'acrossai-abilities-manager' ), ), 'object' => array( 'type' => 'string', 'description' => __( 'Post type or taxonomy name. Required for the post-type and taxonomy panels, whose field ids are patterned per object.', 'acrossai-abilities-manager' ), ), ); } /** * @return array */ protected function output_properties(): array { return array( 'panel' => array( 'type' => 'string' ), 'object' => array( 'type' => 'string' ), 'option_type' => array( 'type' => 'string' ), 'source' => array( 'type' => 'string' ), 'fields' => array( 'type' => 'array' ), 'state' => array( 'type' => 'object' ), ); } /** * @return string[] */ protected function required_input(): array { return array( 'panel' ); } /** * @return array{readonly:bool,destructive:bool,idempotent:bool} */ protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $panel = isset( $input['panel'] ) ? sanitize_key( (string) $input['panel'] ) : ''; $definition = Settings_Registry::panel( $panel ); if ( null === $definition ) { return new WP_Error( 'invalid_input', sprintf( /* translators: 1: submitted panel slug, 2: comma-separated list of valid panels */ __( 'Unknown panel "%1$s". Valid panels: %2$s.', 'acrossai-abilities-manager' ), $panel, implode( ', ', Settings_Registry::panel_slugs() ) ) ); } // Runtime capability re-check — see the class docblock. $cap = (string) $definition['cap']; if ( ! Rank_Math_Guard::has_cap( $cap ) ) { return new WP_Error( 'insufficient_capability', sprintf( /* translators: 1: panel slug, 2: WordPress capability name */ __( 'Reading panel "%1$s" requires the %2$s capability.', 'acrossai-abilities-manager' ), $panel, 'rank_math_' . str_replace( '-', '_', $cap ) ) ); } $object = isset( $input['object'] ) ? sanitize_key( (string) $input['object'] ) : ''; $result = Settings_Writer::read( $panel, $object ); if ( is_wp_error( $result ) ) { return $result; } if ( 'general-robots-txt' === $panel ) { $result['state'] = self::robots_txt_state(); } $result['message'] = sprintf( /* translators: 1: number of fields, 2: panel slug */ _n( 'Returned %1$d field from the Rank Math "%2$s" panel.', 'Returned %1$d fields from the Rank Math "%2$s" panel.', count( $result['fields'] ), 'acrossai-abilities-manager' ), count( $result['fields'] ), $panel ); return $result; } /** * Read-only state that determines whether robots.txt is editable at all. * * A physical robots.txt on disk makes Rank Math's virtual editor inert, and a * non-public site suppresses the output entirely. Reporting this is the * difference between "your write did nothing" and knowing why up front. * * @return array */ private static function robots_txt_state(): array { $physical = ABSPATH . 'robots.txt'; $exists = file_exists( $physical ); return array( 'editable' => ! $exists && (bool) get_option( 'blog_public' ), 'physical_file_exists' => $exists, 'physical_file_path' => $exists ? $physical : '', 'site_not_public' => ! get_option( 'blog_public' ), ); } }