array( 'type' => 'object', 'description' => __( 'Field name or key => new value. At least one entry required.', 'acrossai-abilities-manager' ), ), ); } protected function required_input(): array { return array( 'fields', ); } protected function output_properties(): array { return array( 'updated' => array( 'type' => 'array' ), 'failed' => array( 'type' => 'array' ), ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true, ); } protected function run( array $input ) { $target = Acf_Target::resolve( $input ); if ( is_wp_error( $target ) ) { return $target; } $fields = isset( $input['fields'] ) && is_array( $input['fields'] ) ? $input['fields'] : array(); if ( array() === $fields ) { return new WP_Error( 'invalid_input', __( 'Supply at least one field to change.', 'acrossai-abilities-manager' ) ); } $updated = array(); $failed = array(); foreach ( $fields as $selector => $value ) { $selector = (string) $selector; $written = Field_Repository::update( $selector, Slash_Input::slash( $value, $input ), $target ); if ( is_wp_error( $written ) ) { $failed[] = array( 'field' => $selector, 'reason' => $written->get_error_message(), ); continue; } $updated[] = $selector; } return array( 'updated' => $updated, 'failed' => $failed, 'message' => sprintf( /* translators: 1: number updated, 2: number failed */ __( '%1$d field(s) updated, %2$d failed.', 'acrossai-abilities-manager' ), count( $updated ), count( $failed ) ), ); } }