id = 'thinkrank/get-schema-settings'; $this->label = __( 'Get ThinkRank Schema Settings', 'thinkrank' ); $this->description = __( 'Retrieve ThinkRank structured-data (schema) settings, including organization, website, local business, and person markup.', 'thinkrank' ); } /** * {@inheritDoc} * * @return array */ public function get_annotations() { return [ 'readonly' => true, 'destructive' => false, 'idempotent' => true, 'priority' => 1.0, 'openWorldHint' => false, ]; } /** * Build the JSON schema properties for schema settings. * * @return array */ private static function schema_properties() { $props = []; foreach ( self::BOOL_KEYS as $key ) { $props[ $key ] = [ 'type' => 'boolean' ]; } foreach ( self::INT_KEYS as $key ) { $props[ $key ] = [ 'type' => 'integer' ]; } foreach ( self::ARRAY_KEYS as $key ) { $props[ $key ] = [ 'type' => 'array' ]; } foreach ( self::STRING_KEYS as $key ) { $props[ $key ] = [ 'type' => 'string' ]; } return $props; } /** * {@inheritDoc} * * @return array */ public function get_input_schema() { return [ 'type' => 'object', 'additionalProperties' => false, 'properties' => [], ]; } /** * {@inheritDoc} * * @return array */ public function get_output_schema() { return [ 'type' => 'object', 'properties' => [ 'settings' => [ 'type' => 'object', 'properties' => self::schema_properties(), ], ], ]; } /** * Execute ability. * * @param array $input Ability input payload. * @return array */ public function execute( $input ) { $mgr = new Schema_Management_System(); $s = $mgr->get_settings( 'site', null ); $out = []; foreach ( self::BOOL_KEYS as $key ) { $out[ $key ] = (bool) ( $s[ $key ] ?? false ); } foreach ( self::INT_KEYS as $key ) { $out[ $key ] = (int) ( $s[ $key ] ?? 0 ); } foreach ( self::ARRAY_KEYS as $key ) { $out[ $key ] = isset( $s[ $key ] ) && is_array( $s[ $key ] ) ? array_values( $s[ $key ] ) : []; } foreach ( self::STRING_KEYS as $key ) { $out[ $key ] = (string) ( $s[ $key ] ?? '' ); } return [ 'settings' => $out ]; } }