array( 'type' => 'integer', 'minimum' => 1, ), 'template' => array( 'type' => 'string', 'description' => __( 'The complete new template.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'form_id' => array( 'type' => 'integer' ), 'template' => array( 'type' => 'string' ), 'fields' => array( 'type' => 'array' ), 'config_errors' => array( 'type' => 'array' ), ); } protected function required_input(): array { return array( 'form_id', 'template' ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true, ); } protected function suggested_abilities(): array { return array( array( 'slug' => 'contact-form-7/validate-mail-tags', 'reason' => 'Replacing a template can drop a field the mail body still references, which fails silently.', ), ); } 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; } $saved = Form_Repository::save( array( 'id' => $form_id, 'form' => (string) ( $input['template'] ?? '' ), ) ); if ( is_wp_error( $saved ) ) { return $saved; } $fresh = Form_Repository::get( $form_id ); if ( is_wp_error( $fresh ) ) { return $fresh; } return array( 'form_id' => $form_id, 'template' => (string) $fresh->prop( 'form' ), 'fields' => \AcrossAI_Abilities_Manager\Includes\Abilities\Utilities\ContactForm7\Form_Tag_Repository::tags( $fresh ), 'config_errors' => Form_Repository::config_errors( $fresh ), 'message' => __( 'Form template replaced.', 'acrossai-abilities-manager' ), ); } }