array( 'type' => 'integer', 'minimum' => 1, ), 'title' => array( 'type' => 'string', 'description' => __( 'Title for the copy. Defaults to the original plus "_copy".', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'form' => array( 'type' => 'object' ), 'source_id' => array( 'type' => 'integer' ), ); } protected function required_input(): array { return array( 'form_id' ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => false, ); } protected function run( array $input ) { $source_id = absint( $input['form_id'] ?? 0 ); $source = Form_Repository::get( $source_id ); if ( is_wp_error( $source ) ) { return $source; } $new_id = Form_Repository::duplicate( $source, isset( $input['title'] ) ? sanitize_text_field( (string) $input['title'] ) : '' ); if ( is_wp_error( $new_id ) ) { return $new_id; } $copy = Form_Repository::get( $new_id ); if ( is_wp_error( $copy ) ) { return $copy; } return array( 'form' => Form_Repository::describe( $copy ), 'source_id' => $source_id, 'message' => sprintf( /* translators: 1: new title, 2: new id */ __( 'Duplicated as "%1$s" (id %2$d).', 'acrossai-abilities-manager' ), $copy->title(), $new_id ), ); } }