id = 'thinkrank/update-social-meta-settings'; $this->label = __( 'Update ThinkRank Social Meta Settings', 'thinkrank' ); $this->description = __( 'Update ThinkRank social meta settings, covering Open Graph, Twitter Cards, and per-network verification and handle configuration. Read the current values with get-social-meta-settings first; only the keys you pass are changed.', 'thinkrank' ); } /** * {@inheritDoc} * * @return array */ public function get_annotations() { return [ 'readonly' => false, // Settings writes are recoverable: the matching get-* ability reads // the previous value, so nothing is lost that cannot be put back. // `destructive` is reserved for calls that lose data or reach // outside the site, and marking routine configuration with it made // MCP clients demand a human approval for every save — which users // reported as a permission bug, because the client's refusal reads // as "No approval received" (#675). 'destructive' => false, 'idempotent' => true, 'priority' => 2.0, 'openWorldHint' => false, ]; } /** * Build the JSON schema properties for social meta 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::STRING_KEYS as $key ) { $props[ $key ] = [ 'type' => 'string' ]; } return $props; } /** * {@inheritDoc} * * @return array */ public function get_input_schema() { return [ 'type' => 'object', 'additionalProperties' => false, 'properties' => [ 'settings' => [ 'type' => 'object', 'description' => __( 'Social meta settings to update.', 'thinkrank' ), 'properties' => self::schema_properties(), ], ], 'required' => [ 'settings' ], ]; } /** * {@inheritDoc} * * @return array */ public function get_output_schema() { return [ 'type' => 'object', 'properties' => [ 'success' => [ 'type' => 'boolean' ], 'message' => [ 'type' => 'string' ], ], ]; } /** * Execute ability. * * @param array $input Ability input payload. * @return array|\WP_Error */ public function execute( $input ) { $settings = isset( $input['settings'] ) && is_array( $input['settings'] ) ? $input['settings'] : []; if ( empty( $settings ) ) { return new \WP_Error( 'thinkrank_missing_social_meta_settings_payload', __( 'A social meta settings payload is required.', 'thinkrank' ), [ 'status' => 400 ] ); } $mgr = new Social_Meta_Manager(); $merged = $mgr->get_settings( 'site', null ); $found = false; foreach ( self::BOOL_KEYS as $key ) { if ( array_key_exists( $key, $settings ) ) { $merged[ $key ] = (bool) $settings[ $key ]; $found = true; } } foreach ( self::INT_KEYS as $key ) { if ( array_key_exists( $key, $settings ) ) { $merged[ $key ] = (int) $settings[ $key ]; $found = true; } } foreach ( self::STRING_KEYS as $key ) { if ( array_key_exists( $key, $settings ) ) { $merged[ $key ] = sanitize_text_field( (string) $settings[ $key ] ); $found = true; } } if ( ! $found ) { return new \WP_Error( 'thinkrank_no_valid_social_meta_setting_keys', __( 'No valid social meta setting keys were provided.', 'thinkrank' ), [ 'status' => 400 ] ); } $result = $mgr->save_settings( 'site', null, $merged ); return [ 'success' => (bool) $result, 'message' => (bool) $result ? __( 'Social meta settings updated.', 'thinkrank' ) : __( 'Failed to update social meta settings.', 'thinkrank' ), ]; } }