diff --git a/README.md b/README.md
index a0c378b..36fcb15 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,8 @@ Provides compatibility between the [WPForms](https://wpforms.com/) (or [WPForms
### Notes
-* Tested with WPForms plugin version 1.9.1.2
+* Tested with WPForms plugin version 1.9.1.3
+* The _File Upload_ field with a _Modern_ style is not compatible with _Stateless_ mode. Change the WPForms field style to _Classic_ or use another WP-Stateless mode with the _Modern_ field style.
### Support, Feedback, & Contribute
diff --git a/changelog.txt b/changelog.txt
index 9023a0b..1ca6c46 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,3 +1,9 @@
== Changelog ==
+= 0.0.2 =
+
+* FIX: WPForms Builder issues when `Cache Busting` enabled.
+* FIX: Added support for `File Upload` field type.
+* FIX: Added support for `File Upload` field type in emails.
+
= 0.0.1 =
* Initial public release.
diff --git a/changes.md b/changes.md
index 74999db..14ca5dd 100644
--- a/changes.md
+++ b/changes.md
@@ -1,3 +1,9 @@
+#### 0.0.2
+
+* FIX: WPForms Builder issues when `Cache Busting` enabled.
+* FIX: Added support for `File Upload` field type.
+* FIX: Added support for `File Upload` field type in emails.
+
#### 0.0.1
- Initial public release.
diff --git a/class-wpforms.php b/class-wpforms.php
index 4ff84f4..18931af 100644
--- a/class-wpforms.php
+++ b/class-wpforms.php
@@ -14,24 +14,62 @@ class WPForms extends Compatibility {
const UPLOAD_FIELD_TYPE = 'file-upload';
const MESSAGE_KEY = 'stateless-wpforms-modern';
const DISMISSED_MESSAGE_KEY = 'dismissed_notice_' . self::MESSAGE_KEY;
+ const WPFORMS_BUILDER_PAGE = 'wpforms-builder';
protected $id = 'wpforms';
protected $title = 'WPForms';
protected $constant = 'WP_STATELESS_COMPATIBILITY_WPFORMS';
protected $description = 'Ensures compatibility with WPForms.';
protected $plugin_file = ['wpforms-lite/wpforms.php', 'wpforms/wpforms.php'];
+ protected $filesystem = null;
/**
* @param $sm
*/
public function module_init($sm) {
- add_action( 'current_screen', [$this, 'disable_cache_busting'], 20);
+ if ( !class_exists('\WP_Filesystem_Direct') ) {
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');
+ }
+
+ $this->filesystem = new \WP_Filesystem_Direct( false );
+
+ /**
+ * Disable cache busting for WPForms Builder page
+ */
+ if ( isset($_GET['page']) ) {
+ $page = sanitize_text_field($_GET['page']);
+
+ if ( $page === self::WPFORMS_BUILDER_PAGE ) {
+ $this->remove_cache_busting();
+ }
+ }
+
+ add_action( 'wp', [$this, 'check_processing_form_submit'], 5);
add_action( 'wp_ajax_wpforms_upload_chunk_init', [$this, 'remove_cache_busting'], 5);
add_action( 'wp_ajax_nopriv_wpforms_upload_chunk_init', [$this, 'remove_cache_busting'], 5);
add_action( 'wp_ajax_wpforms_submit', [$this, 'remove_cache_busting'], 5);
add_action( 'wp_ajax_nopriv_wpforms_submit', [$this, 'remove_cache_busting'], 5);
+ add_action( 'wpforms_process_entry_saved', [ $this, 'entry_saved' ], 10, 4 );
+ add_action( 'wpforms_pre_delete_entries', [ $this, 'pre_delete_entries' ], 10, 1 );
+ add_action( 'wpforms_pro_admin_entries_page_empty_trash_before', [ $this, 'before_empty_trash' ], 10, 1 );
+ add_action( 'wpforms_pre_delete_entry_fields', [ $this, 'pre_delete_entry_fields' ], 10, 2 );
+ add_action( 'wpforms_builder_save_form', [ $this, 'builder_save_form' ], 10, 2 );
+ add_action( 'admin_init', [ $this, 'show_message' ]);
+ add_filter( 'wpforms_process_after_filter', [ $this, 'upload_complete' ], 10, 3 );
+ add_filter( 'wpforms_entry_email_data', [ $this, 'entry_email_data' ], 10, 3 );
add_filter( 'sm:sync::syncArgs', [$this, 'sync_args'], 10, 4);
+ add_filter( 'sm:sync::nonMediaFiles', [$this, 'sync_non_media_files'], 20);
+ }
+
+ /**
+ * Remove cache busting before processing WPForm submition.
+ */
+ public function check_processing_form_submit() {
+ if ( isset( $_POST['wpforms'] ) && !empty($_POST['wpforms']) ) {
+ $this->remove_cache_busting();
+ }
}
/**
@@ -45,21 +83,21 @@ protected function storage_position($name) {
}
/**
- * Skip cache busting for WPForms files.
+ * Check if the uploaded file is in the media library.
+ *
+ * @return bool
*/
- public function remove_cache_busting() {
- remove_filter('sanitize_file_name', ['wpCloud\StatelessMedia\Utility', 'randomize_filename'], 10);
+ protected function is_media_library($form_data, $field_id) {
+ $field_data = isset( $form_data['fields'] ) && isset( $form_data['fields'][$field_id] ) ? $form_data['fields'][$field_id] : [];
+
+ return isset( $field_data['media_library'] ) && !empty( $field_data['media_library'] );
}
/**
- * Disable cache busting for WPForms Builder page
- *
- * @param $screen
+ * Skip cache busting for WPForms files.
*/
- public function disable_cache_busting($screen) {
- if ( $screen->id === 'wpforms_page_wpforms-builder' ) {
- $this->remove_cache_busting();
- }
+ public function remove_cache_busting() {
+ remove_filter('sanitize_file_name', ['wpCloud\StatelessMedia\Utility', 'randomize_filename'], 10);
}
/**
@@ -86,4 +124,422 @@ public function sync_args($args, $name, $file, $force) {
return $args;
}
+
+ /**
+ * In Stateless mode move the file from /tmp to GCS, so thar WPForms could complete the upload.
+ *
+ * @param array $fields Fields data.
+ * @param array $entry Submitted form entry.
+ * @param array $form_data Form data and settings.
+ *
+ * @return array
+ *
+ */
+ public function upload_complete($fields, $entry, $form_data) {
+ if ( !ud_get_stateless_media()->is_mode('stateless') ) {
+ return $fields;
+ }
+
+ foreach ( $fields as $field_id => $field ) {
+ if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
+ continue;
+ }
+
+ // If uploads are saved to the media library
+ if ( $this->is_media_library($form_data, $field_id) ) {
+ continue;
+ }
+
+ $is_visible = ! isset( wpforms()->get( 'process' )->fields[ $field_id ]['visible'] ) || ! empty( wpforms()->get( 'process' )->fields[ $field_id ]['visible'] );
+
+ if ( ! $is_visible ) {
+ continue;
+ }
+
+ $input_name = sprintf( 'wpforms_%d_%d', absint( $form_data['id'] ), $field_id );
+ // we are $_FILES after WPForms performed all the security checks
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ $file = isset( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ] ) ? $_FILES[ $input_name ] : false;
+
+ // If there was no file uploaded stop here before we continue with the upload process.
+ if ( ! $file || $file['error'] !== 0 ) {
+ continue;
+ }
+
+ $dir = apply_filters('wp_stateless_addon_sync_files_path', '', self::TMP_PATH);
+ // we are $_FILES after WPForms performed all the security checks
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ $filename = $dir . $_FILES[ $input_name ]['name'];
+
+ // we are $_FILES after WPForms performed all the security checks
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ if ( $this->filesystem->move( $_FILES[ $input_name ]['tmp_name'], $filename, true ) ) {
+ $_FILES[ $input_name ]['tmp_name'] = $filename;
+ }
+ }
+
+ return $fields;
+ }
+
+ /**
+ * If Media Library is not used for file upload
+ * - move the file to '/wpforms' dir
+ * - run sync
+ * - update entry data with the new file path
+ */
+ public function entry_saved($fields, $entry, $form_data, $entry_id) {
+ $wp_uploads_dir = wp_get_upload_dir();
+ global $wpdb;
+
+ foreach ( $fields as $field_id => $field ) {
+ if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
+ continue;
+ }
+
+ if ( !isset( $field['value'] ) || empty($field['value']) ) {
+ continue;
+ }
+
+ // If uploads are saved to the media library
+ if ( $this->is_media_library($form_data, $field_id) ) {
+ continue;
+ }
+
+ $url = $field['value'];
+
+ /**
+ * Multifile upload support
+ */
+ $files = explode("\n", $url);
+
+ foreach ($files as $file) {
+ $name = str_replace($wp_uploads_dir['baseurl'] . '/', '', $file);
+ $absolutePath = apply_filters('wp_stateless_addon_files_root', '');
+ $absolutePath .= '/' . $name;
+
+ // Move file to the correct location
+ if ( ud_get_stateless_media()->is_mode('stateless') ) {
+ $source = str_replace( ud_get_stateless_media()->get_gs_host(), ud_get_stateless_media()->get_gs_path(), $file );
+ $destination = str_replace( ud_get_stateless_media()->get_gs_host(), ud_get_stateless_media()->get_gs_path(), $absolutePath );
+
+ $this->filesystem->move( $source, $destination, true );
+ }
+
+ // Sync non-media file
+ $name = apply_filters('wp_stateless_file_name', $name, 0);
+ do_action('sm:sync::syncFile', $name, $absolutePath);
+ }
+
+ // Update entry data with the new file path
+ if ( !ud_get_stateless_media()->is_mode( ['disabled', 'backup'] ) ) {
+ $url = ud_get_stateless_media()->is_mode('stateless')
+ ? str_replace( ud_get_stateless_media()->get_gs_path(), ud_get_stateless_media()->get_gs_host(), $absolutePath )
+ : str_replace( $wp_uploads_dir['baseurl'], ud_get_stateless_media()->get_gs_host(), $url );
+
+ try {
+ // WPForms uses direct database access and ignores caching, we should too
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $entry_fields = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT fields FROM {$wpdb->prefix}wpforms_entries WHERE entry_id = %d AND form_id = %d",
+ $entry_id,
+ $form_data['id']
+ )
+ );
+
+ $entry_fields = json_decode($entry_fields, true);
+
+ if ( isset( $entry_fields[ $field_id ] ) && isset( $entry_fields[ $field_id ]['value'] ) ) {
+ $entry_fields[ $field_id ]['value'] = $url;
+
+ if ( isset( $entry_fields[ $field_id ]['value_raw'] ) && is_array( $entry_fields[ $field_id ]['value_raw'] ) && !empty( $entry_fields[ $field_id ]['value_raw'] )) {
+ foreach ( $entry_fields[ $field_id ]['value_raw'] as $key => $value_raw ) {
+ $entry_fields[ $field_id ]['value_raw'][ $key ]['value'] = ud_get_stateless_media()->is_mode('stateless')
+ ? str_replace( ud_get_stateless_media()->get_gs_path(), ud_get_stateless_media()->get_gs_host(), $value_raw['value'] )
+ : str_replace( $wp_uploads_dir['baseurl'], ud_get_stateless_media()->get_gs_host(), $value_raw['value'] );
+ }
+ }
+
+ // WPForms uses direct database access and ignores caching, we should too
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $wpdb->update(
+ $wpdb->prefix . 'wpforms_entries',
+ ['fields' => wp_json_encode($entry_fields)],
+ [
+ 'entry_id' => $entry_id,
+ 'form_id' => $form_data['id'],
+ ],
+ );
+
+ Helper::debug( $entry_fields );
+ }
+
+ // WPForms uses direct database access and ignores caching, we should too
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $wpdb->update(
+ $wpdb->prefix . 'wpforms_entry_fields',
+ ['value' => $url],
+ [
+ 'entry_id' => $entry_id,
+ 'field_id' => $field_id,
+ 'form_id' => $form_data['id'],
+ ],
+ );
+ Helper::debug( $url );
+
+ } catch (\Throwable $e) {
+ error_log( $e->getMessage() );
+ }
+
+ $fields[$field_id]['value'] = $url;
+ }
+ }
+ }
+
+ /**
+ * Update email data with the new file path
+ */
+ public function entry_email_data($fields, $entry, $form_data) {
+ if ( !ud_get_stateless_media()->is_mode('stateless') ) {
+ return $fields;
+ }
+
+ $wp_uploads_dir = wp_get_upload_dir();
+
+ foreach ( $fields as $field_id => $field ) {
+ if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
+ continue;
+ }
+
+ // If uploads are saved to the media library
+ if ( $this->is_media_library($form_data, $field_id) ) {
+ continue;
+ }
+
+ $url = $field['value'];
+ $name = str_replace($wp_uploads_dir['baseurl'] . '/', '', $url);
+ $absolutePath = apply_filters('wp_stateless_addon_files_root', '');
+ $absolutePath .= '/' . $name;
+
+ $absolutePath = str_replace( ud_get_stateless_media()->get_gs_path(), ud_get_stateless_media()->get_gs_host(), $absolutePath );
+
+ $fields[$field_id]['value'] = $absolutePath;
+ }
+
+ return $fields;
+ }
+
+ /**
+ * Delete files from GCS when deleting entries.
+ */
+ public function pre_delete_entries($entry_id) {
+ global $wpdb;
+
+ try {
+ // WPForms uses direct database access and ignores caching, we should too
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $entry_fields = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT fields FROM {$wpdb->prefix}wpforms_entries WHERE entry_id = %d",
+ $entry_id,
+ )
+ );
+
+ $entry_fields = json_decode($entry_fields, true);
+
+ foreach ( $entry_fields as $field_id => $field ) {
+ if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
+ continue;
+ }
+
+ // If uploads were saved to the media library
+ if ( isset( $field['attachment_id'] ) && !empty($field['attachment_id']) ) {
+ continue;
+ }
+
+ $url = isset($field['value']) ? $field['value'] : false;
+
+ if ( empty($url) ) {
+ continue;
+ }
+
+ $name = str_replace( trailingslashit( ud_get_stateless_media()->get_gs_host() ), '', $url);
+
+ do_action('sm:sync::deleteFile', $name);
+ }
+
+ } catch (\Throwable $e) {
+ error_log( $e->getMessage() );
+ }
+ }
+
+ /**
+ * Delete files from GCS when emptying entries trash.
+ */
+ public function before_empty_trash($entry_ids) {
+ foreach ( $entry_ids as $id ) {
+ $this->pre_delete_entries($id);
+ }
+ }
+
+ /**
+ * Filter files created by WPForms for sync.
+ *
+ * @param array $file_list
+ * @return array
+ */
+ public function sync_non_media_files($file_list) {
+ if ( !method_exists('\wpCloud\StatelessMedia\Utility', 'get_files') ) {
+ Helper::log('WP-Stateless version too old, please update.');
+
+ return $file_list;
+ }
+
+ $dir = apply_filters('wp_stateless_addon_sync_files_path', '', self::STORAGE_PATH);
+
+ if (is_dir($dir)) {
+ // Getting all the files from dir recursively.
+ $files = Utility::get_files($dir);
+
+ // validating and adding to the $files array.
+ foreach ($files as $file) {
+ if (!file_exists($file)) {
+ continue;
+ }
+
+ // filter temporary files
+ if (strpos($file, self::TMP_PATH) !== false) {
+ continue;
+ }
+
+ // filter index.html, .htaccess files
+ $basename = basename($file);
+
+ if ( in_array($basename, array('index.html', '.htaccess')) ) {
+ continue;
+ }
+
+ $file = self::STORAGE_PATH . str_replace( $dir, '', wp_normalize_path($file) );
+ $file = trim($file, '/');
+
+ if ( !in_array($file, $file_list) ) {
+ $file_list[] = $file;
+ }
+ }
+ }
+
+ return $file_list;
+ }
+
+ /**
+ * Delete files from GCS when file deleted from entry.
+ */
+ public function pre_delete_entry_fields($row_id, $primary_key) {
+ // other cases are handled by other hooks
+ if ( $primary_key !== 'id' ) {
+ return;
+ }
+
+ global $wpdb;
+
+ try {
+ // WPForms uses direct database access and ignores caching, we should too
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ $value = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT value FROM {$wpdb->prefix}wpforms_entry_fields WHERE id = %d",
+ $row_id,
+ )
+ );
+
+ // Not a file or not on GCS
+ if ( strpos( $value, ud_get_stateless_media()->get_gs_host() ) === false ) {
+ return;
+ }
+
+ // Not a WPForms file or Media Library file
+ if ( $this->storage_position($value) === false ) {
+ return;
+ }
+
+ $name = str_replace( trailingslashit( ud_get_stateless_media()->get_gs_host() ), '', $value);
+
+ do_action('sm:sync::deleteFile', $name);
+ } catch (\Throwable $e) {
+ error_log( $e->getMessage() );
+ }
+ }
+
+ /**
+ * Show message in Admin Panel when Modern upload style is used during using Stateless mode
+ */
+ public function show_message() {
+ if ( !ud_get_stateless_media()->is_mode('stateless') ) {
+ return;
+ }
+
+ $message_option = get_option(self::MESSAGE_KEY, []);
+
+ if ( empty($message_option) ) {
+ return;
+ }
+
+ $form_names = array_filter( array_values($message_option) );
+
+ if ( empty($form_names) ) {
+ return;
+ }
+
+ $form_names = implode(', ', $form_names);
+ $form_names = '' . $form_names . '';
+
+ /* translators: %s: list of forms */
+ $message = __('The File Upload field with a Modern style is not compatible with Stateless mode. Change the WPForms field style to Classic or use another WP-Stateless mode with the Modern field style. Affected Form: %s', ud_get_stateless_media()->domain);
+ $message = sprintf($message, $form_names);
+
+ ud_get_stateless_media()->errors->add([
+ 'title' => __('WP-Stateless: Problem Detected With WPForms', ud_get_stateless_media()->domain),
+ 'message' => $message,
+ 'key' => self::MESSAGE_KEY,
+ ], 'warning');
+ }
+
+ /**
+ * When saving form - show warning for the Modern upload style during using Stateless mode
+ */
+ public function builder_save_form($form_id, $form_data) {
+ $fields = is_array($form_data) && isset( $form_data['fields'] ) ? $form_data['fields'] : [];
+ $message_option = get_option(self::MESSAGE_KEY, []);
+ $found = false;
+
+ foreach ( $fields as $field ) {
+ if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
+ continue;
+ }
+
+ if ( isset( $field['style'] ) && $field['style'] == 'modern' ) {
+ $found = true;
+ break;
+ }
+ }
+
+ if ( $found ) {
+ $title = isset( $form_data['settings']['form_title'] )
+ ? $form_data['settings']['form_title']
+ /* translators: %d: form ID */
+ : sprintf( __('Form %d', 'wp-stateless-wpforms-addon'), $form_id);
+
+ $message_option[$form_id] = $title;
+
+ delete_option(self::DISMISSED_MESSAGE_KEY);
+ } else {
+ unset($message_option[$form_id]);
+ }
+
+ if ( empty($message_option) ) {
+ delete_option(self::MESSAGE_KEY);
+ } else {
+ update_option(self::MESSAGE_KEY, $message_option);
+ }
+ }
}
diff --git a/readme.txt b/readme.txt
index 17dff59..550bb45 100644
--- a/readme.txt
+++ b/readme.txt
@@ -6,7 +6,7 @@ License: GPLv2 or later
Requires PHP: 8.0
Requires at least: 5.0
Tested up to: 6.6.2
-Stable tag: 0.0.1
+Stable tag: 0.0.2
Provides compatibility between the WPForms and the WP-Stateless plugins.
@@ -20,7 +20,8 @@ Provides compatibility between the [WPForms](https://wpforms.com/) (or [WPForms
= Notes =
-* Tested with WPForms plugin version 1.9.1.2
+* Tested with WPForms plugin version 1.9.1.3
+* The _File Upload_ field with a _Modern_ style is not compatible with _Stateless_ mode. Change the WPForms field style to _Classic_ or use another WP-Stateless mode with the _Modern_ field style.
= Support, Feedback, & Contribute =
@@ -44,6 +45,12 @@ To ensure new releases cause as little disruption as possible, we rely on early
== Changelog ==
+= 0.0.2 =
+
+* FIX: WPForms Builder issues when `Cache Busting` enabled.
+* FIX: Added support for `File Upload` field type.
+* FIX: Added support for `File Upload` field type in emails.
+
= 0.0.1 =
* Initial public release.
diff --git a/tests/ClassWPFormsTest.php b/tests/ClassWPFormsTest.php
index 5202089..44405bd 100644
--- a/tests/ClassWPFormsTest.php
+++ b/tests/ClassWPFormsTest.php
@@ -39,20 +39,29 @@ public function testShouldInitHooks() {
$wPForms->module_init([]);
- self::assertNotFalse( has_action('current_screen', [ $wPForms, 'disable_cache_busting' ]) );
+ self::assertNotFalse( has_action('wp', [ $wPForms, 'check_processing_form_submit' ]) );
self::assertNotFalse( has_action('wp_ajax_wpforms_upload_chunk_init', [ $wPForms, 'remove_cache_busting' ]) );
self::assertNotFalse( has_action('wp_ajax_nopriv_wpforms_upload_chunk_init', [ $wPForms, 'remove_cache_busting' ]) );
self::assertNotFalse( has_action('wp_ajax_wpforms_submit', [ $wPForms, 'remove_cache_busting' ]) );
self::assertNotFalse( has_action('wp_ajax_nopriv_wpforms_submit', [ $wPForms, 'remove_cache_busting' ]) );
-
+ self::assertNotFalse( has_action('wpforms_process_entry_saved', [ $wPForms, 'entry_saved' ]) );
+ self::assertNotFalse( has_action('wpforms_pre_delete_entries', [ $wPForms, 'pre_delete_entries' ]) );
+ self::assertNotFalse( has_action('wpforms_pro_admin_entries_page_empty_trash_before', [ $wPForms, 'before_empty_trash' ]) );
+ self::assertNotFalse( has_action('wpforms_pre_delete_entry_fields', [ $wPForms, 'pre_delete_entry_fields' ]) );
+ self::assertNotFalse( has_action('wpforms_builder_save_form', [ $wPForms, 'builder_save_form' ]) );
+ self::assertNotFalse( has_action('admin_init', [ $wPForms, 'show_message' ]) );
+
+ self::assertNotFalse( has_filter('wpforms_process_after_filter', [ $wPForms, 'upload_complete' ]) );
+ self::assertNotFalse( has_filter('wpforms_entry_email_data', [ $wPForms, 'entry_email_data' ]) );
self::assertNotFalse( has_filter('sm:sync::syncArgs', [ $wPForms, 'sync_args' ]) );
- }
+ self::assertNotFalse( has_filter('sm:sync::nonMediaFiles', [ $wPForms, 'sync_non_media_files' ]) );
+ }
public function testShouldCountHooks() {
$wPForms = new WPForms();
- Functions\expect('add_action')->times(5);
- Functions\expect('add_filter')->times(1);
+ Functions\expect('add_action')->times(11);
+ Functions\expect('add_filter')->times(4);
$wPForms->module_init([]);
}
@@ -62,7 +71,9 @@ public function testShouldRemoveFilter() {
add_filter('sanitize_file_name', [ 'wpCloud\StatelessMedia\Utility', 'randomize_filename' ]);
- $wPForms->disable_cache_busting( (object) ['id' => 'wpforms_page_wpforms-builder'] );
+ $_GET['page'] = 'wpforms-builder';
+
+ $wPForms->module_init([]);
self::assertFalse( has_filter('sanitize_file_name', [ 'wpCloud\StatelessMedia\Utility', 'randomize_filename' ]) );
}
@@ -72,9 +83,9 @@ public function testShouldKeepFilter() {
add_filter('sanitize_file_name', [ 'wpCloud\StatelessMedia\Utility', 'randomize_filename' ]);
- $_GET['page'] = 'wpforms-builder';
+ unset( $_GET['page'] );
- $wPForms->disable_cache_busting( (object) ['id' => 'another_admin_screen'] );
+ $wPForms->module_init([]);
self::assertNotFalse( has_filter('sanitize_file_name', [ 'wpCloud\StatelessMedia\Utility', 'randomize_filename' ]) );
}
@@ -111,4 +122,26 @@ public function testShouldNotUpdateArgs() {
count( $wPForms->sync_args([], self::TEST_URL, '', false) )
);
}
+
+ public function testShouldNotMoveUploadedFile() {
+ $wPForms = new WPForms();
+
+ self::assertEquals(
+ 0,
+ count( $wPForms->upload_complete([], [], []) )
+ );
+ }
+
+ public function testShouldNotUpdateEmailData() {
+ $wPForms = new WPForms();
+
+ self::assertEquals(
+ 0,
+ count( $wPForms->entry_email_data([], [], []) )
+ );
+ }
}
+
+function sanitize_text_field($value) {
+ return $value;
+}
\ No newline at end of file
diff --git a/vendor/bin/.phpunit.result.cache b/vendor/bin/.phpunit.result.cache
index 43b12b1..b854934 100644
--- a/vendor/bin/.phpunit.result.cache
+++ b/vendor/bin/.phpunit.result.cache
@@ -1 +1 @@
-{"version":1,"defects":{"WPSL\\WPForms\\ClassWPFormsTest::testShouldInitHooks":3,"WPSL\\WPForms\\ClassWPFormsTest::testShouldDoSomething":5,"SLCA\\WPForms\\ClassWPFormsTest::testShouldRemoveFilter":3,"SLCA\\WPForms\\ClassWPFormsTest::testShouldInitHooks":3,"SLCA\\WPForms\\ClassWPFormsTest::testShouldUpdateArgs":4,"SLCA\\WPForms\\ClassWPFormsTest::testShouldUpdateArgsStateless":3,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotUpdateEmailData":4,"SLCA\\WPForms\\ClassWPFormsTest::testShouldCountHooks":4,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotMoveUploadedFile":4},"times":{"WPSL\\WPForms\\ClassWPFormsTest::testShouldInitHooks":0.114,"WPSL\\WPForms\\ClassWPFormsTest::testShouldDoSomething":0,"WPSL\\WPForms\\ClassWPFormsTest::testShouldKeepFilter":0.069,"WPSL\\WPForms\\ClassWPFormsTest::testShouldRemoveFilter":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldInitHooks":0.078,"SLCA\\WPForms\\ClassWPFormsTest::testShouldRemoveFilter":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldKeepFilter":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldUpdateArgs":0.002,"SLCA\\WPForms\\ClassWPFormsTest::testShouldUpdateArgsStateless":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotUpdateArgs":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotMoveUploadedFile":0.003,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotUpdateEmailData":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldCountHooks":0.046}}
\ No newline at end of file
+{"version":1,"defects":{"WPSL\\WPForms\\ClassWPFormsTest::testShouldInitHooks":3,"WPSL\\WPForms\\ClassWPFormsTest::testShouldDoSomething":5,"SLCA\\WPForms\\ClassWPFormsTest::testShouldRemoveFilter":4,"SLCA\\WPForms\\ClassWPFormsTest::testShouldInitHooks":3,"SLCA\\WPForms\\ClassWPFormsTest::testShouldUpdateArgs":4,"SLCA\\WPForms\\ClassWPFormsTest::testShouldUpdateArgsStateless":3,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotUpdateEmailData":4,"SLCA\\WPForms\\ClassWPFormsTest::testShouldCountHooks":4,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotMoveUploadedFile":4,"SLCA\\WPForms\\ClassWPFormsTest::testShouldKeepFilter":3},"times":{"WPSL\\WPForms\\ClassWPFormsTest::testShouldInitHooks":0.114,"WPSL\\WPForms\\ClassWPFormsTest::testShouldDoSomething":0,"WPSL\\WPForms\\ClassWPFormsTest::testShouldKeepFilter":0.069,"WPSL\\WPForms\\ClassWPFormsTest::testShouldRemoveFilter":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldInitHooks":0.076,"SLCA\\WPForms\\ClassWPFormsTest::testShouldRemoveFilter":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldKeepFilter":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldUpdateArgs":0.002,"SLCA\\WPForms\\ClassWPFormsTest::testShouldUpdateArgsStateless":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotUpdateArgs":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotMoveUploadedFile":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldNotUpdateEmailData":0,"SLCA\\WPForms\\ClassWPFormsTest::testShouldCountHooks":0.045}}
\ No newline at end of file
diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php
index fbc91a0..0891470 100644
--- a/vendor/composer/installed.php
+++ b/vendor/composer/installed.php
@@ -3,7 +3,7 @@
'name' => 'udx/wp-stateless-wpforms-lite-addon',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
- 'reference' => '0cc49ba9b7c63339722bfabbb0a5a5b9a9a7b010',
+ 'reference' => '4c78c1be7294768d25f1af662f06b6f38ebf3a3e',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -13,7 +13,7 @@
'udx/wp-stateless-wpforms-lite-addon' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
- 'reference' => '0cc49ba9b7c63339722bfabbb0a5a5b9a9a7b010',
+ 'reference' => '4c78c1be7294768d25f1af662f06b6f38ebf3a3e',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
diff --git a/wp-stateless-wpforms-addon.php b/wp-stateless-wpforms-addon.php
index eabc050..a823717 100644
--- a/wp-stateless-wpforms-addon.php
+++ b/wp-stateless-wpforms-addon.php
@@ -5,7 +5,7 @@
* Plugin URI: https://stateless.udx.io/addons/wpforms/
* Description: Provides compatibility between the WPForms and the WP-Stateless plugins.
* Author: UDX
- * Version: 0.0.1
+ * Version: 0.0.2
* Text Domain: wp-stateless-wpforms-addon
* Author URI: https://udx.io
* License: GPLv2 or later