array( 'type' => 'integer', 'minimum' => 1, ), 'messages' => array( 'type' => 'object', 'description' => __( 'Message slug => new text.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'form_id' => array( 'type' => 'integer' ), 'updated' => array( 'type' => 'array' ), ); } protected function required_input(): array { return array( 'form_id', 'messages' ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true, ); } protected function run( array $input ) { $form_id = absint( $input['form_id'] ?? 0 ); $form = Form_Repository::get( $form_id ); if ( is_wp_error( $form ) ) { return $form; } $allowed = Contact_Form_7_Guard::assert_can_edit( $form_id ); if ( is_wp_error( $allowed ) ) { return $allowed; } $patch = isset( $input['messages'] ) && is_array( $input['messages'] ) ? $input['messages'] : array(); if ( array() === $patch ) { return new WP_Error( 'invalid_input', __( 'Supply at least one message to change.', 'acrossai-abilities-manager' ) ); } $known = Form_Repository::default_messages(); $messages = (array) $form->prop( 'messages' ); $updated = array(); foreach ( $patch as $slug => $text ) { $slug = (string) $slug; if ( ! array_key_exists( $slug, $known ) ) { return new WP_Error( 'unknown_message', sprintf( /* translators: %s: message slug */ __( '"%s" is not a Contact Form 7 message slug.', 'acrossai-abilities-manager' ), $slug ) ); } $messages[ $slug ] = (string) $text; $updated[] = $slug; } $saved = Form_Repository::save( array( 'id' => $form_id, 'messages' => $messages, ) ); if ( is_wp_error( $saved ) ) { return $saved; } return array( 'form_id' => $form_id, 'updated' => $updated, 'message' => sprintf( /* translators: %s: comma-separated message slugs */ __( 'Updated: %s.', 'acrossai-abilities-manager' ), implode( ', ', $updated ) ), ); } }