Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/gutena-forms/build/blocks/existing-forms/index.asset.php
+++ b/gutena-forms/build/blocks/existing-forms/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '935b0c54b2c17cd5cbd2');
--- a/gutena-forms/build/blocks/field-group/index.asset.php
+++ b/gutena-forms/build/blocks/field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => 'f354e90f32596e5420b6');
--- a/gutena-forms/build/blocks/field-label/index.asset.php
+++ b/gutena-forms/build/blocks/field-label/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element'), 'version' => 'e9fa0d46138446593747');
--- a/gutena-forms/build/blocks/form-confirm-msg/index.asset.php
+++ b/gutena-forms/build/blocks/form-confirm-msg/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => '674724572e3a51b9d3d8');
--- a/gutena-forms/build/blocks/form-error-msg/index.asset.php
+++ b/gutena-forms/build/blocks/form-error-msg/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => '9b1758a0a986970a5dc0');
--- a/gutena-forms/build/blocks/form-field-blocks/checkbox-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/checkbox-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'd37f69a85d9edcd8693f');
--- a/gutena-forms/build/blocks/form-field-blocks/dropdown-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/dropdown-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '27c453b29f89ec378ed3');
--- a/gutena-forms/build/blocks/form-field-blocks/dropdown-field/view.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/dropdown-field/view.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array(), 'version' => '2b43e6f79659c985f1ab');
--- a/gutena-forms/build/blocks/form-field-blocks/email-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/email-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'cc8b5342d32d3c4ce0f2');
--- a/gutena-forms/build/blocks/form-field-blocks/number-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/number-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'ac676ada797ed6f3a0d2');
--- a/gutena-forms/build/blocks/form-field-blocks/optin-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/optin-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '91a1f4ad8f271de780c2');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/country-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/country-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '1621bc5435d5f780c5c6');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/date-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/date-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '9acc57637da0a3437bee');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/file-upload-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/file-upload-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => 'eddb37cb305cf814729b');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/hidden-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/hidden-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => 'd38fd8fd1febaa58e93b');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/password-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/password-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => 'a717162251ae73d7e9b7');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/phone-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/phone-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '539957fb6211dc9f331b');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/rating-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/rating-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '534caa92d4ff5ff5e046');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/state-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/state-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '4cbbd7e81d237f23c5f2');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/time-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/time-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '54bf756f685f3d03da61');
--- a/gutena-forms/build/blocks/form-field-blocks/pro/url-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/pro/url-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '5a7d5034b8342e151cb3');
--- a/gutena-forms/build/blocks/form-field-blocks/radio-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/radio-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'be5446b42399a83a017b');
--- a/gutena-forms/build/blocks/form-field-blocks/range-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/range-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'dde5d7bb5a96b9f5dae1');
--- a/gutena-forms/build/blocks/form-field-blocks/text-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/text-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '4b026f5d4aaac5baed39');
--- a/gutena-forms/build/blocks/form-field-blocks/textarea-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field-blocks/textarea-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'd63d123bf6dcac3692b7');
--- a/gutena-forms/build/blocks/form-field/index.asset.php
+++ b/gutena-forms/build/blocks/form-field/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '888a1b7f4479fe35ce1b');
--- a/gutena-forms/build/blocks/form-fields/checkbox-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/checkbox-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => '5baed2bdc2fbfef600e3');
--- a/gutena-forms/build/blocks/form-fields/dropdown-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/dropdown-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => 'b62d243cc49a14c26645');
--- a/gutena-forms/build/blocks/form-fields/email-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/email-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => 'e308d63b5e684990dcbf');
--- a/gutena-forms/build/blocks/form-fields/number-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/number-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => 'd885a273d8b4675cef68');
--- a/gutena-forms/build/blocks/form-fields/optin-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/optin-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => 'f5d986d0adc0fea73f3b');
--- a/gutena-forms/build/blocks/form-fields/pro/country-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/country-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '6e7f93290ed663b47b8d');
--- a/gutena-forms/build/blocks/form-fields/pro/date-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/date-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '8fbebc1c16420382b86a');
--- a/gutena-forms/build/blocks/form-fields/pro/file-upload-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/file-upload-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => 'e78ee17a192d21cdc48b');
--- a/gutena-forms/build/blocks/form-fields/pro/hidden-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/hidden-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => 'b176159d38c3d6c9e5c1');
--- a/gutena-forms/build/blocks/form-fields/pro/password-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/password-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '6e17db46769f45d5e130');
--- a/gutena-forms/build/blocks/form-fields/pro/phone-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/phone-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '8fac6be0279a6f499938');
--- a/gutena-forms/build/blocks/form-fields/pro/rating-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/rating-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '300926a6e9032c406cdc');
--- a/gutena-forms/build/blocks/form-fields/pro/state-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/state-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '61cfb27cec5a42bd3dab');
--- a/gutena-forms/build/blocks/form-fields/pro/time-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/time-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => 'ce99d6aa8003b8a5af2e');
--- a/gutena-forms/build/blocks/form-fields/pro/url-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/pro/url-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-components'), 'version' => '290630fc63ab7d2d1175');
--- a/gutena-forms/build/blocks/form-fields/radio-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/radio-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => '59f699fb5441c9ea48b8');
--- a/gutena-forms/build/blocks/form-fields/range-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/range-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => 'aa82ea0b82c84feffe3c');
--- a/gutena-forms/build/blocks/form-fields/text-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/text-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => '300623a1c61d9d31103c');
--- a/gutena-forms/build/blocks/form-fields/textarea-field-group/index.asset.php
+++ b/gutena-forms/build/blocks/form-fields/textarea-field-group/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components'), 'version' => '58d0a83beddd0fa6b98c');
--- a/gutena-forms/build/blocks/form/index.asset.php
+++ b/gutena-forms/build/blocks/form/index.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array('lodash', 'react', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-i18n'), 'version' => '15f336d32b1cf6b0e251');
--- a/gutena-forms/build/blocks/form/script.asset.php
+++ b/gutena-forms/build/blocks/form/script.asset.php
@@ -0,0 +1 @@
+<?php return array('dependencies' => array(), 'version' => 'de02780cf10e163d57db');
--- a/gutena-forms/gutena-forms.php
+++ b/gutena-forms/gutena-forms.php
@@ -4,7 +4,7 @@
* Description: Gutena Forms is the easiest way to create forms inside the WordPress block editor. Our plugin does not use jQuery and is lightweight, so you can rest assured that it won’t slow down your website. Instead, it allows you to quickly and easily create custom forms right inside the block editor.
* Requires at least: 6.5
* Requires PHP: 5.6
- * Version: 1.9.0
+ * Version: 2.0.0
* Author: Gutena Forms
* Author URI: https://gutenaforms.com
* License: GPL-2.0-or-later
@@ -41,7 +41,17 @@
* Plugin version.
*/
if ( ! defined( 'GUTENA_FORMS_VERSION' ) ) {
- define( 'GUTENA_FORMS_VERSION', '1.9.0' );
+ define( 'GUTENA_FORMS_VERSION', '2.0.0' );
+}
+
+/**
+ * Minimum Gutena Forms Pro version compatible with this Free version.
+ *
+ * Older Pro builds hide the form field blocks from the inserter and do not
+ * register the standalone field blocks, so users on an outdated Pro must update.
+ */
+if ( ! defined( 'GUTENA_FORMS_MIN_PRO_VERSION' ) ) {
+ define( 'GUTENA_FORMS_MIN_PRO_VERSION', '1.3.0' );
}
/**
@@ -187,13 +197,18 @@
include_once GUTENA_FORMS_DIR_PATH . 'includes/class-gutena-migration.php';
include_once GUTENA_FORMS_DIR_PATH . 'includes/class-gutena-dummy-fields.php';
+ include_once GUTENA_FORMS_DIR_PATH . 'includes/blocks/legacy-blocks.php';
include_once GUTENA_FORMS_DIR_PATH . 'includes/blocks/class-form-block.php';
include_once GUTENA_FORMS_DIR_PATH . 'includes/blocks/class-field-block.php';
include_once GUTENA_FORMS_DIR_PATH . 'includes/blocks/class-form-field-block.php';
include_once GUTENA_FORMS_DIR_PATH . 'includes/blocks/class-existing-forms-block.php';
include_once GUTENA_FORMS_DIR_PATH . 'includes/blocks/class-field-label-block.php';
+ include_once GUTENA_FORMS_DIR_PATH . 'includes/blocks/class-pro-field-blocks.php';
+ include_once GUTENA_FORMS_DIR_PATH . 'includes/blocks/class-fields.php';
+
include_once GUTENA_FORMS_DIR_PATH . 'includes/handlers/class-handle-save-form.php';
include_once GUTENA_FORMS_DIR_PATH . 'includes/handlers/class-form-submit-handler.php';
+
include_once GUTENA_FORMS_DIR_PATH . 'includes/rest-api/class-rest-api.php';
}
@@ -215,11 +230,129 @@
add_action( 'wp_ajax_nopriv_gutena_forms_submit', array( Gutena_Forms_Submit_Form_Handler::get_instance(), 'handle_submit' ) );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ), 1000 );
add_filter( 'gutena_forms__register_fields', array( $this, 'register_fields' ) );
+ add_action( 'admin_notices', array( $this, 'maybe_show_update_pro_notice' ) );
+ add_action( 'admin_init', array( $this, 'register_pro_plugin_row_notice' ) );
$this->load_dashboard();
}
/**
+ * Show an admin notice when an outdated Gutena Forms Pro is active.
+ *
+ * Older Pro builds hide the form field blocks from the inserter and do not
+ * register standalone field blocks, which removes the fields from the editor.
+ * Prompt the user to update Pro so the blocks are restored.
+ *
+ * @since 1.9.1
+ */
+ public function maybe_show_update_pro_notice() {
+ if ( ! current_user_can( 'update_plugins' ) ) {
+ return;
+ }
+
+ if ( ! is_gutena_forms_pro() ) {
+ return;
+ }
+
+ $pro_version = $this->get_pro_plugin_version();
+
+ if ( '' === $pro_version || ! version_compare( $pro_version, GUTENA_FORMS_MIN_PRO_VERSION, '<=' ) ) {
+ return;
+ }
+ ?>
+ <div class="notice notice-error is-dismissible">
+ <p>
+ <?php
+ printf(
+ /* translators: %s: current Gutena Forms Pro version number. */
+ wp_kses(
+ __( 'Please update <strong>Gutena Forms Pro</strong> to the latest version to get blocks back. You are currently using version <strong>%s</strong>.', 'gutena-forms' ),
+ array( 'strong' => array() )
+ ),
+ esc_html( $pro_version )
+ );
+ ?>
+ </p>
+ </div>
+ <?php
+ }
+
+ /**
+ * Hook the outdated-Pro notice into the Pro plugin row on the Plugins screen.
+ *
+ * @since 1.9.1
+ */
+ public function register_pro_plugin_row_notice() {
+ if ( ! defined( 'GUTENA_FORMS_PRO_FILE' ) ) {
+ return;
+ }
+
+ $basename = plugin_basename( GUTENA_FORMS_PRO_FILE );
+ add_action( "after_plugin_row_{$basename}", array( $this, 'render_pro_plugin_row_notice' ), 10, 2 );
+ }
+
+ /**
+ * Render an inline notice under the Gutena Forms Pro row on the Plugins screen.
+ *
+ * @since 1.9.1
+ * @param string $plugin_file Plugin file path (unused).
+ * @param array $plugin_data Plugin header data (unused).
+ */
+ public function render_pro_plugin_row_notice( $plugin_file, $plugin_data ) {
+ if ( ! current_user_can( 'update_plugins' ) || ! is_gutena_forms_pro() ) {
+ return;
+ }
+
+ $pro_version = $this->get_pro_plugin_version();
+
+ if ( '' === $pro_version || ! version_compare( $pro_version, GUTENA_FORMS_MIN_PRO_VERSION, '<=' ) ) {
+ return;
+ }
+
+ $list_table = function_exists( '_get_list_table' ) ? _get_list_table( 'WP_Plugins_List_Table' ) : null;
+ $colspan = ( $list_table && method_exists( $list_table, 'get_column_count' ) ) ? $list_table->get_column_count() : 3;
+ ?>
+ <tr class="plugin-update-tr active">
+ <td colspan="<?php echo esc_attr( $colspan ); ?>" class="plugin-update colspanchange">
+ <div class="update-message notice inline notice-error notice-alt">
+ <p>
+ <?php
+ printf(
+ /* translators: %s: current Gutena Forms Pro version number. */
+ wp_kses(
+ __( 'Please update <strong>Gutena Forms Pro</strong> to the latest version to get blocks back. You are currently using version <strong>%s</strong>.', 'gutena-forms' ),
+ array( 'strong' => array() )
+ ),
+ esc_html( $pro_version )
+ );
+ ?>
+ </p>
+ </div>
+ </td>
+ </tr>
+ <?php
+ }
+
+ /**
+ * Get the installed Gutena Forms Pro version from its plugin header.
+ *
+ * Reads the header instead of GUTENA_FORMS_PRO_VERSION because Pro sets that
+ * constant to a timestamp in dev environments, which breaks version comparisons.
+ *
+ * @since 1.9.1
+ * @return string Pro plugin version, or empty string when it cannot be resolved.
+ */
+ private function get_pro_plugin_version() {
+ if ( ! defined( 'GUTENA_FORMS_PRO_FILE' ) || ! file_exists( GUTENA_FORMS_PRO_FILE ) ) {
+ return '';
+ }
+
+ $pro_data = get_file_data( GUTENA_FORMS_PRO_FILE, array( 'Version' => 'Version' ) );
+
+ return ( ! empty( $pro_data['Version'] ) ) ? $pro_data['Version'] : '';
+ }
+
+ /**
* Enqueue scripts
*/
public function enqueue_recaptcha_scripts() {
@@ -386,18 +519,25 @@
}
Gutena_Forms_Form_Block::get_instance()->register_block();
- Gutena_Forms_Field_Block::get_instance()->register_block();
- Gutena_Forms_Form_Field_Block::get_instance()->register_block();
Gutena_Forms_Existing_Forms_Block::get_instance()->register_block();
- Gutena_Forms_Field_Label_Block::get_instance()->register_block();
+ Gutena_Forms_Fields::get_instance()->register_blocks();
+ Gutena_Forms_Pro_Field_Blocks::get_instance()->register_blocks( 'only when pro version not available' );
+
+
+ Gutena_Forms_Field_Block::get_instance()->register_block( 'backward compatibility' );
+ Gutena_Forms_Form_Field_Block::get_instance()->register_block( 'backward compatibility' );
+ Gutena_Forms_Field_Label_Block::get_instance()->register_block( 'backward compatibility' );
+
+ register_block_type(
+ GUTENA_FORMS_DIR_PATH . 'build/blocks/field-group',
+ gutena_forms_legacy_block_registration_args()
+ );
// Form Confirmation Message Block.
- register_block_type( __DIR__ . '/build/form-confirm-msg' );
+ register_block_type( __DIR__ . '/build/blocks/form-confirm-msg' );
// Form Error Message Block.
- register_block_type( __DIR__ . '/build/form-error-msg' );
-
- register_block_type( __DIR__ . '/build/field-group' );
+ register_block_type( __DIR__ . '/build/blocks/form-error-msg' );
// google recaptcha.
$grecaptcha = get_option( 'gutena_forms__recaptcha', array() );
@@ -415,6 +555,7 @@
'required_msg_select' => __( 'Please select an option', 'gutena-forms' ),
'required_msg_check' => __( 'Please check an option', 'gutena-forms' ),
'invalid_email_msg' => __( 'Please enter a valid email address', 'gutena-forms' ),
+ 'invalid_url_msg' => __( 'Please enter a valid URL', 'gutena-forms' ),
'min_value_msg' => __( 'Input value should be greater than', 'gutena-forms' ),
'max_value_msg' => __( 'Input value should be less than', 'gutena-forms' ),
);
@@ -473,6 +614,7 @@
'is_gutena_forms_post_type' => $gutena_forms_post_type,
'forms_available' => $forms_available,
'honeypot' => get_option( 'gutena_forms__honeypot', array() ),
+ 'legacyHiddenBlocks' => gutena_forms_get_legacy_hidden_block_names(),
),
$gf_message
)
@@ -701,6 +843,7 @@
'required_msg_select' => __( 'Please select an option', 'gutena-forms' ),
'required_msg_check' => __( 'Please check an option', 'gutena-forms' ),
'invalid_email_msg' => __( 'Please enter a valid email address', 'gutena-forms' ),
+ 'invalid_url_msg' => __( 'Please enter a valid URL', 'gutena-forms' ),
'min_value_msg' => __( 'Input value should be greater than', 'gutena-forms' ),
'max_value_msg' => __( 'Input value should be less than', 'gutena-forms' ),
);
@@ -740,7 +883,17 @@
$current_form_id = $single_form_schema['form_attrs']['formID'];
// Only inherited/default messages may update the global option; local overrides stay on this form only.
// If no forms exist yet, or only this form exists, it is the Primary Form.
- if ( $is_default_messages && ( empty( $all_form_ids ) || ( count( $all_form_ids ) === 1 && in_array( $current_form_id, $all_form_ids, true ) ) ) ) {
+ if (
+ $is_default_messages
+ && (
+ empty( $all_form_ids )
+ || ( count( $all_form_ids ) === 1 && in_array( $current_form_id, $all_form_ids, true ) )
+ || (
+ class_exists( 'Gutena_Forms_Settings_Migrator' )
+ && Gutena_Forms_Settings_Migrator::is_global_module_empty( 'messages' )
+ )
+ )
+ ) {
$messages_for_global = json_decode( wp_json_encode( $single_form_schema['form_attrs']['messages'] ), true );
if ( ! is_array( $messages_for_global ) ) {
$messages_for_global = is_array( $single_form_schema['form_attrs']['messages'] ) ? $single_form_schema['form_attrs']['messages'] : array();
@@ -861,7 +1014,14 @@
}
if ( ! empty( $block['blockName'] ) && 'gutena/form-field' === $block['blockName'] && ! empty( $block['attrs']['nameAttr'] ) ) {
- $form_schema[ $form_id ]['form_fields'][ $block['attrs']['nameAttr'] ] = $block['attrs'];
+ $form_schema[ $form_id ]['form_fields'][ $block['attrs']['nameAttr'] ] = Gutena_Forms_Helper::merge_block_default_attributes(
+ $block['blockName'],
+ $block['attrs']
+ );
+ }
+
+ if ( ! empty( $form_id ) && ! empty( $block['blockName'] ) ) {
+ $form_schema = apply_filters( 'gutena_forms_map_block_field_schema', $form_schema, $block, $form_id );
}
if ( ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) {
--- a/gutena-forms/includes/admin/class-admin.php
+++ b/gutena-forms/includes/admin/class-admin.php
@@ -136,7 +136,6 @@
Gutena_Forms_Admin_Helper::optimize_submenu();
Gutena_Forms_Admin_Helper::pricing_page_redirection();
Gutena_Forms_Admin_Helper::feature_request_redirection();
- Gutena_Forms_Admin_Helper::include_wp_list_table();
}
/**
--- a/gutena-forms/includes/admin/class-manage-store.php
+++ b/gutena-forms/includes/admin/class-manage-store.php
@@ -25,68 +25,12 @@
return self::$instance;
}
- public function __construct() {
- parent::__construct();
- //Filter gutena forms render form
- add_filter('gutena_forms_save_form_schema', array( $this, 'save_form_schema' ), 10, 3 );
- //save submiited gutena forms
+ public function __construct() {
+ parent::__construct();
+ add_filter( 'gutena_forms_save_form_schema', array( $this, 'save_form_schema' ), 10, 3 );
add_action( 'gutena_forms_submitted_data', array( $this, 'save_form_entry' ), 10, 3 );
-
- //Update form entry status to read
- add_action( 'wp_ajax_gutena_forms_entries_read', array( $this, 'entries_read_status_update' ) );
-
- add_action( 'wp_loaded', array($this, 'process_bulk_action') );
-
- }
-
- //form entries table bulk action
- public function process_bulk_action() {
-
- if ( ! empty( $_REQUEST['action'] ) && ! empty( $_REQUEST['form_entry_id'] ) && function_exists( 'absint' ) && ! empty( $_GET['formid'] ) && is_numeric( $_GET['formid'] ) ) {
-
- //check nonce
- check_ajax_referer( 'gutena_Forms', 'gfnonce' );
- $form_id = sanitize_key( $_GET['formid'] );
-
- //check user access
- if ( ( ! has_filter( 'gutena_forms_check_user_access' ) && ! Gutena_Forms_Admin_Helper::is_admin() ) || ! apply_filters( 'gutena_forms_check_user_access', true, 'edit_entries' ) ) {
- wp_redirect( esc_url( admin_url( 'admin.php?page=gutena-forms&formid='.$form_id ) ) );
- }
-
- $form_entry_id = wp_unslash( $_REQUEST['form_entry_id'] );
-
- global $wpdb;
- $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) );
- //Admin Action
- do_action( 'gutena_forms_entries_admin_action', $form_id, $action, $form_entry_id );
- $this->update_entries_status( $action, $form_entry_id );
-
- wp_safe_redirect( add_query_arg(
- array(
- 'page' => 'gutena-forms',
- 'formid' => $form_id,
- ), admin_url( 'admin.php' ) )
- );
- }
- }
-
- //Update form entry status to read mb
- public function entries_read_status_update() {
- check_ajax_referer( 'gutena_Forms', 'gfnonce' );
- global $wpdb;
- //Update status
- if ( ! empty( $wpdb ) && ! empty( $_POST['form_entry_id'] ) && is_numeric( $_POST['form_entry_id'] ) && function_exists( 'absint' ) ) {
-
- $this->update_entries_status( 'read', absint( wp_unslash( $_POST['form_entry_id'] ) ) );
-
- wp_send_json_success( array(
- 'status' => 'success',
- 'message' => __( 'Status updated successfully', 'gutena-forms' ),
- ) );
- }
}
-
/**
* add new meta for form or entries
* Required at least : 'form_id', 'data_type', 'metadata'
--- a/gutena-forms/includes/admin/class-store.php
+++ b/gutena-forms/includes/admin/class-store.php
@@ -55,36 +55,11 @@
return false;
}
- /**
- * @return array associative array of form block_form_id and form_id
- */
- public function get_block_id_form_id_array() {
- global $wpdb;
- $forms = array();
- if ( $this->is_forms_store_exists() ) {
- $form_rows = $this->get_form_list();
- if ( ! empty( $form_rows ) ) {
- foreach ( $form_rows as $key => $form ) {
- $forms[ $form->block_form_id ] = $form->form_id;
- }
- }
- }
- return $forms;
- }
-
public function get_form_name( $form_schema ) {
$form_schema = $this->maybe_unserialize( $form_schema );
return ( empty( $form_schema ) || empty( $form_schema['form_attrs'] ) || empty( $form_schema['form_attrs']['formName'] ) ) ? __( 'Contact Form', 'gutena-forms' ) : sanitize_text_field( $form_schema['form_attrs']['formName'] );
}
-
- public function get_form_list() {
- global $wpdb;
- return empty( $wpdb ) ? '' : $wpdb->get_results(
- "SELECT form_id, form_name, block_form_id FROM {$this->table_gutenaforms} WHERE form_id IN (SELECT DISTINCT form_id FROM {$this->table_gutenaforms_entries} WHERE trash = 0)"
- );
- }
-
/**
* Update entry status
*
@@ -165,109 +140,6 @@
}
}
- /**
- * Prepares the list of items for displaying.
- *
- * @param number $id entry_id
- *
- * @return array entry details for admin view
- */
- public function get_entry_details( $id ) {
- $entry_data = array();
- if ( ! empty( $id ) && is_numeric( $id ) ) {
- global $wpdb;
- // get entries details
- $entry_data = $wpdb->get_row(
- $wpdb->prepare(
- "SELECT e.*,(SELECT GROUP_CONCAT(entries.entry_id SEPARATOR ',') from {$this->table_gutenaforms_entries} entries WHERE entries.trash = 0 AND entries.form_id = e.form_id GROUP BY entries.trash) AS all_entries, f.form_name, u.display_name as user_display_name, u.user_email FROM {$this->table_gutenaforms_entries} e LEFT JOIN {$this->table_gutenaforms} f ON e.form_id = f.form_id LEFT JOIN {$this->table_users} u ON u.ID = e.user_id WHERE e.entry_id= %d AND e.trash = %d",
- $id,
- 0,
- ),
- ARRAY_A
- );
-
- if ( empty( $entry_data ) || empty( $entry_data['entry_data'] ) ) {
- return $entry_data;
- }
-
- // unserialize form data
- $entry_data['entry_data'] = maybe_unserialize( $entry_data['entry_data'] );
- if ( empty( $this->form_id ) ) {
- $this->form_id = empty( $entry_data['form_id'] ) ? 0 : $entry_data['form_id'];
- }
- // filter field values
- if ( is_array( $entry_data['entry_data'] ) ) {
- foreach ( $entry_data['entry_data'] as $field_slug => $fieldData ) {
- $fieldData['value'] = $this->view_field_value( $fieldData );
- $entry_data['entry_data'][ $field_slug ] = $fieldData;
- }
- }
- // Update entry status to read from unread
- if ( ! empty( $entry_data['entry_status'] ) && 'unread' === $entry_data['entry_status'] ) {
- $this->update_entries_status( 'read', absint( $entry_data['entry_id'] ) );
- }
-
- // Processs data for entry navigation: i.e. next or previous
- if ( ! empty( $entry_data['all_entries'] ) ) {
- // Array of all entry id
- $entry_data['all_entries'] = explode( ',', $entry_data['all_entries'] );
-
- // Total entries
- $entry_data['total_entries'] = count( $entry_data['all_entries'] );
-
- // Current entry serial number
- $entry_data['current_entry_sno'] = array_search( $id, $entry_data['all_entries'] );
-
- // Next entry id
- if ( $entry_data['current_entry_sno'] < ( $entry_data['total_entries'] - 1 ) ) {
- $entry_data['next_entry_id'] = $entry_data['current_entry_sno'] + 1;
- $entry_data['next_entry_id'] = empty( $entry_data['all_entries'][ $entry_data['next_entry_id'] ] ) ? '' : $entry_data['all_entries'][ $entry_data['next_entry_id'] ];
- }
-
- // Previous entry id
- if ( 1 <= $entry_data['current_entry_sno'] ) {
- $entry_data['previous_entry_id'] = $entry_data['current_entry_sno'] - 1;
- $entry_data['previous_entry_id'] = empty( $entry_data['all_entries'][ $entry_data['previous_entry_id'] ] ) ? '' : $entry_data['all_entries'][ $entry_data['previous_entry_id'] ];
- }
-
- $entry_data['current_entry_sno'] += 1;
- }
-
- // related_entry
- if ( ! empty( $entry_data['user_id'] ) && is_numeric( $entry_data['user_id'] ) ) {
- $entry_data['related_entry'] = $wpdb->get_var(
- $wpdb->prepare(
- "SELECT count(entry_id) FROM {$this->table_gutenaforms_entries} WHERE trash = 0 AND user_id=%d ",
- $entry_data['user_id'],
- )
- );
- }
- }
-
- return $entry_data;
- }
-
- public function view_field_value( $fieldData, $fieldvalue = '' ) {
- return ( empty( $fieldData ) || empty( $fieldData['value'] ) ) ? '' : wp_kses(
- apply_filters(
- 'gutena_forms_view_field_value',
- empty( $fieldvalue ) ? $fieldData['value'] : $fieldvalue,
- $fieldData
- ),
- array_merge(
- wp_kses_allowed_html( 'post' ),
- array(
- 'a' => array(
- 'href' => 1,
- 'class' => 1,
- 'target' => 1,
- 'modalid' => 1,
- ),
- )
- )
- );
- }
-
// save new form
protected function save_new_form( $form_id, $form_schema ) {
// return if form id or data not available
@@ -295,28 +167,5 @@
return $wpdb->insert_id;
}
-
- /**
- * Admin dashboard header
- *
- * @param array $form_list list of form name with respective id
- *
- * @return string - html
- */
- public function get_dashboard_header() {
- // logo title
- return '<div class="gf-header">
- <div id="gf-header-left-section" class="gf-logo-title">
- <a href="' . esc_url( admin_url( 'admin.php?page=gutena-forms&pagetype=introduction' ) ) . '" >
- <img src="' . GUTENA_FORMS_PLUGIN_URL . 'assets/img/logo.png' . '" />
- </a>
- <div id="gfp-dashboard-navigation" class="gfp-dashboard-navigation"></div>
- </div>
-
- <div class="pr-16">
- ' . ( is_gutena_forms_pro( false ) ? '' : '<a href="https://gutenaforms.com/pricing/?utm_source=plugin_dashboard&utm_medium=website&utm_campaign=free_plugin" target="_blank" rel="noopener noreferrer" class="gf-btn gf-pro-btn" > <span class="gf-btn-text">' . __( 'Go Premium', 'gutena-forms' ) . '</span> </a>' ) . '
- </div>
- </div>';
- }
}
}
--- a/gutena-forms/includes/admin/dashboard/build/index.asset.php
+++ b/gutena-forms/includes/admin/dashboard/build/index.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-url'), 'version' => '14092fab2b28dd02a6fd');
+<?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-url'), 'version' => 'bd05a62a516e44e51d05');
--- a/gutena-forms/includes/admin/modules/cloudflare/class-cloudflare.php
+++ b/gutena-forms/includes/admin/modules/cloudflare/class-cloudflare.php
@@ -92,7 +92,11 @@
return array(
'id' => 'cloudflare',
'title' => __( 'Cloudflare Turnstile', 'gutena-forms' ),
- 'description' => __( 'Secure your forms with Cloudflare Turnstile to block bots without affecting user experience.', 'gutena-forms' ),
+ 'description' => sprintf(
+ /* translators: %1$s: Learn More link. */
+ __( 'Secure your forms with Cloudflare Turnstile to block bots without affecting user experience. %1$s', 'gutena-forms' ),
+ '<a target="_blank" href="https://gutenaforms.com/docs/spam-protection/cloudflare-turnstile/">' . __( 'Learn More', 'gutena-forms' ) . '</a>'
+ ),
'fields' => array(
array(
'id' => 'enable',
@@ -159,28 +163,6 @@
* @since 1.8.0
*/
private function run() {
- add_action( 'gutena_forms__saving_block', array( $this, 'save_cloudflare' ), 10, 3 );
- }
-
- /**
- * Saving cloudflare settings.
- *
- * @since 1.8.0
- * @param array $attributes Block attributes.
- * @param array $block Current block.
- * @param WP_Post $post Post object.
- */
- public function save_cloudflare( $attributes, $block, $post ) {
- if ( ! Gutena_Forms_Settings_Migrator::is_single_form_site() ) {
- return;
- }
-
- if ( empty( $attributes['cloudflareTurnstile'] ) || ! is_array( $attributes['cloudflareTurnstile'] ) ) {
- return;
- }
-
- $this->settings = Gutena_Forms_Settings_Migrator::sanitize_settings_for_option( $attributes['cloudflareTurnstile'] );
- update_option( 'gutena_forms__cloudflare', $this->settings );
}
}
--- a/gutena-forms/includes/admin/modules/honeypot/class-honeypot.php
+++ b/gutena-forms/includes/admin/modules/honeypot/class-honeypot.php
@@ -55,7 +55,11 @@
public function get_settings() {
return array(
'title' => __( 'Honeypot Field Settings', 'gutena-forms' ),
- 'description' => __( 'Use Honeypot protection to silently block spam bots without affecting real users.', 'gutena-forms' ),
+ 'description' => sprintf(
+ /* translators: %1$s: Learn More link. */
+ __( 'Use Honeypot protection to silently block spam bots without affecting real users. %1$s', 'gutena-forms' ),
+ '<a target="_blank" href="https://gutenaforms.com/docs/spam-protection/honeypot-security/">' . __( 'Learn More', 'gutena-forms' ) . '</a>'
+ ),
'fields' => array(
array(
'id' => 'enable',
@@ -144,30 +148,6 @@
* @since 1.8.0
*/
private function run() {
- add_action( 'gutena_forms__saving_block', array( $this, 'save_honeypot' ), 10, 3 );
- }
-
- /**
- * Saving the default settings.
- *
- * @since 1.8.0
- * @param array $attributes The attiributes of the block being saved, including the honeypot settings.
- * @param array $blocks All blocks of the post.
- * @param WP_Post $post Current post object.
- */
- public function save_honeypot( $attributes, $blocks, $post ) {
- $honeypot = isset( $attributes['honeypot'] ) && is_array( $attributes['honeypot'] ) ? $attributes['honeypot'] : array();
-
- if ( ! Gutena_Forms_Settings_Migrator::is_single_form_site() ) {
- return;
- }
-
- if ( empty( $honeypot ) ) {
- return;
- }
-
- $this->settings = Gutena_Forms_Settings_Migrator::sanitize_settings_for_option( $honeypot );
- update_option( 'gutena_forms__honeypot', $this->settings );
}
}
--- a/gutena-forms/includes/admin/modules/recaptcha/class-recaptcha.php
+++ b/gutena-forms/includes/admin/modules/recaptcha/class-recaptcha.php
@@ -69,7 +69,11 @@
return array(
'id' => 'recaptcha',
'title' => __( 'Google reCAPTCHA Settings', 'gutena-forms' ),
- 'description' => __( 'Protect your forms using Google reCAPTCHA to prevent automated spam.', 'gutena-forms' ),
+ 'description' => sprintf(
+ /* translators: %1$s: Learn More link. */
+ __( 'Protect your forms using Google reCAPTCHA to prevent automated spam. %1$s', 'gutena-forms' ),
+ '<a target="_blank" href="https://gutenaforms.com/docs/spam-protection/google-recaptcha/">' . __( 'Learn More', 'gutena-forms' ) . '</a>'
+ ),
'fields' => array(
array(
'id' => 'enable',
@@ -220,29 +224,6 @@
* Running whole module
*/
public function run() {
- add_action( 'gutena_forms__saving_block', array( $this, 'save_recaptcha_settings' ), 10, 3 );
- }
-
- /**
- * Saving recaptcha settings
- *
- * @since 1.8.0
- * @param array $attributes Block attributes.
- * @param array $block All blocks.
- * @param WP_Post $post Post object.
- */
- public function save_recaptcha_settings( $attributes, $block, $post ) {
- if ( ! Gutena_Forms_Settings_Migrator::is_single_form_site() ) {
- return;
- }
-
- $recaptcha = isset( $attributes['recaptcha'] ) && is_array( $attributes['recaptcha'] ) ? $attributes['recaptcha'] : array();
- if ( empty( $recaptcha ) ) {
- return;
- }
-
- $this->settings = Gutena_Forms_Settings_Migrator::sanitize_settings_for_option( $recaptcha );
- update_option( 'gutena_forms__recaptcha', $this->settings );
}
}
--- a/gutena-forms/includes/admin/modules/settings-migrator/class-settings-migrator.php
+++ b/gutena-forms/includes/admin/modules/settings-migrator/class-settings-migrator.php
@@ -51,6 +51,20 @@
*/
private function __construct() {
add_action( 'admin_init', array( $this, 'fetch_all_gutena_forms' ) );
+ add_action( 'gutena_forms__saving_block', array( __CLASS__, 'on_saving_form_block' ), 5, 3 );
+ }
+
+ /**
+ * Seed or sync globals when a gutena/forms block is saved.
+ *
+ * @since 1.9.0
+ * @param array $attributes Block attributes.
+ * @param array $block Block data.
+ * @param WP_Post $post Post object.
+ */
+ public static function on_saving_form_block( $attributes, $block, $post ) {
+ unset( $block, $post );
+ self::seed_globals_from_form_block( $attributes );
}
/**
@@ -127,7 +141,10 @@
* @return int
*/
public static function get_form_count() {
- return count( self::get_form_ids_list() );
+ $from_option = count( self::get_form_ids_list() );
+ $from_cpt = count( self::collect_form_ids_from_cpts() );
+
+ return max( $from_option, $from_cpt );
}
/**
@@ -533,49 +550,290 @@
}
/**
+ * Whether a global module option is empty or has no meaningful configuration.
+ *
+ * @since 1.9.0
+ * @param string $module_key Module attr key (recaptcha, cloudflareTurnstile, honeypot, messages).
+ * @return bool
+ */
+ public static function is_global_module_empty( $module_key ) {
+ $option_name = self::global_option_name_for_module( $module_key );
+ if ( '' === $option_name ) {
+ return true;
+ }
+
+ $settings = get_option( $option_name, array() );
+
+ return ! self::is_module_settings_meaningful( $module_key, $settings );
+ }
+
+ /**
+ * Whether a global integration slice is empty or has no meaningful configuration.
+ *
+ * @since 1.9.0
+ * @param string $integration_id Integration key (mailchimp, brevo, activecampaign).
+ * @return bool
+ */
+ public static function is_integration_global_empty( $integration_id ) {
+ $integration_id = sanitize_key( $integration_id );
+ if ( '' === $integration_id ) {
+ return true;
+ }
+
+ $all_settings = get_option( 'gutena_forms__integration_settings', array() );
+ if ( ! is_array( $all_settings ) || empty( $all_settings[ $integration_id ] ) ) {
+ return true;
+ }
+
+ return ! self::is_integration_attrs_meaningful( $integration_id, $all_settings[ $integration_id ] );
+ }
+
+ /**
+ * Whether form block attrs for a module contain meaningful configuration worth seeding globals.
+ *
+ * @since 1.9.0
+ * @param string $module_key Module attr key.
+ * @param array $slice Module settings from block attrs.
+ * @return bool
+ */
+ public static function is_module_attrs_meaningful( $module_key, $slice ) {
+ return self::is_module_settings_meaningful( $module_key, $slice );
+ }
+
+ /**
+ * Whether stored module settings contain meaningful configuration.
+ *
+ * @since 1.9.0
+ * @param string $module_key Module attr key.
+ * @param array $settings Settings array.
+ * @return bool
+ */
+ public static function is_module_settings_meaningful( $module_key, $settings ) {
+ $settings = self::sanitize_settings_for_option( is_array( $settings ) ? $settings : array() );
+
+ switch ( $module_key ) {
+ case 'recaptcha':
+ if ( ! empty( $settings['enable'] ) ) {
+ return true;
+ }
+ if ( class_exists( 'Gutena_Forms_ReCAPTCHA' ) ) {
+ $resolved = Gutena_Forms_ReCAPTCHA::resolve_settings( $settings );
+ return ! empty( $resolved['site_key'] ) || ! empty( $resolved['secret_key'] );
+ }
+ return ! empty( $settings['site_key'] ) || ! empty( $settings['secret_key'] );
+
+ case 'cloudflareTurnstile':
+ if ( ! empty( $settings['enable'] ) ) {
+ return true;
+ }
+ return ! empty( $settings['site_key'] ) || ! empty( $settings['secret_key'] );
+
+ case 'honeypot':
+ return ! empty( $settings['enable'] ) || ! empty( $settings['timeCheckValue'] );
+
+ case 'messages':
+ $message_keys = array(
+ 'required_msg',
+ 'required_msg_optin',
+ 'required_msg_select',
+ 'required_msg_check',
+ 'invalid_email_msg',
+ 'invalid_url_msg',
+ 'min_value_msg',
+ 'max_value_msg',
+ );
+ foreach ( $message_keys as $message_key ) {
+ if ( ! empty( $settings[ $message_key ] ) ) {
+ return true;
+ }
+ }
+ return false;
+
+ default:
+ return ! empty( $settings );
+ }
+ }
+
+ /**
+ * Whether integration block attrs contain meaningful configuration.
+ *
+ * @since 1.9.0
+ * @param string $integration_id Integration key.
+ * @param array $slice Integration settings from block attrs.
+ * @return bool
+ */
+ public static function is_integration_attrs_meaningful( $integration_id, $slice ) {
+ $integration_id = sanitize_key( $integration_id );
+ $slice = self::sanitize_settings_for_option( is_array( $slice ) ? $slice : array() );
+
+ if ( ! empty( $slice['enable'] ) ) {
+ return true;
+ }
+
+ switch ( $integration_id ) {
+ case 'mailchimp':
+ case 'brevo':
+ return ! empty( $slice['api_key'] ) || ! empty( $slice['list_id'] );
+ case 'activecampaign':
+ return ! empty( $slice['api_key'] ) || ! empty( $slice['api_url'] );
+ default:
+ return ! empty( $slice );
+ }
+ }
+
+ /**
+ * Whether form block attrs may update the global option for a module.
+ *
+ * @since 1.9.0
+ * @param string $module_key Module attr key.
+ * @param array $module_settings Module settings from block attrs.
+ * @param bool $only_if_empty Multi-form seed mode when true.
+ * @return bool
+ */
+ public static function should_form_push_module_to_global( $module_key, $module_settings, $only_if_empty ) {
+ if ( ! self::is_module_attrs_meaningful( $module_key, $module_settings ) ) {
+ return false;
+ }
+
+ if ( self::is_global_module_empty( $module_key ) ) {
+ return true;
+ }
+
+ $uses_global_defaults = ! isset( $module_settings['defaultSettings'] )
+ || rest_sanitize_boolean( $module_settings['defaultSettings'] );
+
+ if ( ! $uses_global_defaults ) {
+ return false;
+ }
+
+ return ! $only_if_empty;
+ }
+
+ /**
+ * Whether form block attrs may update the global option for an integration.
+ *
+ * @since 1.9.0
+ * @param string $integration_id Integration key.
+ * @param array $slice Integration settings from block attrs.
+ * @param bool $only_if_empty Multi-form seed mode when true.
+ * @return bool
+ */
+ public static function should_form_push_integration_to_global( $integration_id, $slice, $only_if_empty ) {
+ if ( ! self::is_integration_attrs_meaningful( $integration_id, $slice ) ) {
+ return false;
+ }
+
+ if ( self::is_integration_global_empty( $integration_id ) ) {
+ return true;
+ }
+
+ $uses_global_defaults = ! isset( $slice['defaultSettings'] )
+ || rest_sanitize_boolean( $slice['defaultSettings'] );
+
+ if ( ! $uses_global_defaults ) {
+ return false;
+ }
+
+ return ! $only_if_empty;
+ }
+
+ /**
+ * Seed globals from form block attrs and sync inheriting forms.
+ *
+ * @since 1.9.0
+ * @param array $attributes Form block attributes.
+ */
+ public static function seed_globals_from_form_block( $attributes ) {
+ $attributes = is_array( $attributes ) ? $attributes : array();
+ $only_if_empty = ! self::is_single_form_site();
+
+ $previous_modules = self::get_pre_upgrade_global_modules_snapshot();
+ $previous_integrations = get_option( 'gutena_forms__integration_settings', array() );
+ if ( ! is_array( $previous_integrations ) ) {
+ $previous_integrations = array();
+ }
+
+ $seeded = self::apply_attrs_to_globals( $attributes, $only_if_empty );
+
+ foreach ( $seeded['modules'] as $module_key ) {
+ $option_name = self::global_option_name_for_module( $module_key );
+ if ( '' === $option_name ) {
+ continue;
+ }
+ $next = get_option( $option_name, array() );
+ $prev = isset( $previous_modules[ $module_key ] ) ? $previous_modules[ $module_key ] : array();
+ self::sync_global_module_to_forms( $module_key, $prev, $next );
+ }
+
+ foreach ( $seeded['integrations'] as $integration_id ) {
+ $all_settings = get_option( 'gutena_forms__integration_settings', array() );
+ $next = ( is_array( $all_settings ) && isset( $all_settings[ $integration_id ] ) )
+ ? $all_settings[ $integration_id ]
+ : array();
+ $prev = isset( $previous_integrations[ $integration_id ] )
+ ? $previous_integrations[ $integration_id ]
+ : array();
+ self::sync_global_integration_to_forms(
+ $integration_id,
+ self::sanitize_settings_for_option( $prev ),
+ self::sanitize_settings_for_option( $next )
+ );
+ }
+ }
+
+ /**
* Write global options from form attrs (only fills empty options when $only_if_empty).
*
* @since 1.9.0
* @param array $attributes Form block attrs.
* @param bool $only_if_empty Only update when target option is empty.
+ * @return array{modules: string[], integrations: string[]} Keys of modules/integrations written.
*/
public static function apply_attrs_to_globals( $attributes, $only_if_empty = false ) {
$attributes = is_array( $attributes ) ? $attributes : array();
+ $seeded = array(
+ 'modules' => array(),
+ 'integrations' => array(),
+ );
if ( ! empty( $attributes['recaptcha'] ) && is_array( $attributes['recaptcha'] ) ) {
- if ( ! $only_if_empty || empty( get_option( 'gutena_forms__recaptcha', array() ) ) ) {
+ if ( self::should_form_push_module_to_global( 'recaptcha', $attributes['recaptcha'], $only_if_empty ) ) {
$recaptcha = self::sanitize_settings_for_option( $attributes['recaptcha'] );
if ( class_exists( 'Gutena_Forms_ReCAPTCHA' ) ) {
$recaptcha = Gutena_Forms_ReCAPTCHA::resolve_settings( $recaptcha );
}
update_option( 'gutena_forms__recaptcha', $recaptcha );
+ $seeded['modules'][] = 'recaptcha';
}
}
if ( ! empty( $attributes['cloudflareTurnstile'] ) && is_array( $attributes['cloudflareTurnstile'] ) ) {
- if ( ! $only_if_empty || empty( get_option( 'gutena_forms__cloudflare', array() ) ) ) {
+ if ( self::should_form_push_module_to_global( 'cloudflareTurnstile', $attributes['cloudflareTurnstile'], $only_if_empty ) ) {
update_option(
'gutena_forms__cloudflare',
self::sanitize_settings_for_option( $attributes['cloudflareTurnstile'] )
);
+ $seeded['modules'][] = 'cloudflareTurnstile';
}
}
if ( ! empty( $attributes['honeypot'] ) && is_array( $attributes['honeypot'] ) ) {
- if ( ! $only_if_empty || empty( get_option( 'gutena_forms__honeypot', array() ) ) ) {
+ if ( self::should_form_push_module_to_global( 'honeypot', $attributes['honeypot'], $only_if_empty ) ) {
update_option(
'gutena_forms__honeypot',
self::sanitize_settings_for_option( $attributes['honeypot'] )
);
+ $seeded['modules'][] = 'honeypot';
}
}
if ( ! empty( $attributes['messages'] ) && is_array( $attributes['messages'] ) ) {
- if ( ! $only_if_empty || empty( get_option( 'gutena_forms__form_validation_messages', array() ) ) ) {
+ if ( self::should_form_push_module_to_global( 'messages', $attributes['messages'], $only_if_empty ) ) {
update_option(
'gutena_forms__form_validation_messages',
self::sanitize_settings_for_option( $attributes['messages'] )
);
+ $seeded['modules'][] = 'messages';
}
}
@@ -595,18 +853,20 @@
) {
continue;
}
- if ( $only_if_empty && ! empty( $integration_option[ $integration_id ] ) ) {
+ $slice = $attributes['settings']['integration'][ $integration_id ];
+ if ( ! self::should_form_push_integration_to_global( $integration_id, $slice, $only_if_empty ) ) {
continue;
}
- $integration_option[ $integration_id ] = self::sanitize_settings_for_option(
- $attributes['settings']['integration'][ $integration_id ]
- );
+ $integration_option[ $integration_id ] = self::sanitize_settings_for_option( $slice );
+ $seeded['integrations'][] = $integration_id;
$changed = true;
}
if ( $changed ) {
update_option( 'gutena_forms__integration_settings', $integration_option );
}
}
+
+ return $seeded;
}
/**
--- a/gutena-forms/includes/admin/modules/validation-messages/class-validation-messages.php
+++ b/gutena-forms/includes/admin/modules/validation-messages/class-validation-messages.php
@@ -188,26 +188,6 @@
* @since 1.8.0
*/
private function run() {
- add_action( 'gutena_forms__saving_block', array( $this, 'save_messages_to_default_option' ), 10, 3 );
- }
-
- /**
- * Saving the settings global settings.
- *
- * @since 1.8.0
- * @param array $attributes Block attributes.
- * @param array $block bocks.
- * @param WP_Post $post Current post object.
- */
- public function save_messages_to_default_option( $attributes, $block, $post ) {
- $messages = isset( $attributes['messages'] ) && is_array( $attributes['messages'] ) ? $attributes['messages'] : array();
-
- if ( ! Gutena_Forms_Settings_Migrator::is_single_form_site() || empty( $messages ) ) {
- return;
- }
-
- $this->settings = Gutena_Forms_Settings_Migrator::sanitize_settings_for_option( $messages );
- update_option( 'gutena_forms__form_validation_messages', $this->settings );
}
}
--- a/gutena-forms/includes/blocks/class-existing-forms-block.php
+++ b/gutena-forms/includes/blocks/class-existing-forms-block.php
@@ -24,7 +24,7 @@
*/
public function register_block() {
register_block_type(
- GUTENA_FORMS_DIR_PATH . 'build/existing-forms',
+ GUTENA_FORMS_DIR_PATH . 'build/blocks/existing-forms',
array(
'render_callback' => array( $this, 'render' ),
)
--- a/gutena-forms/includes/blocks/class-field-block.php
+++ b/gutena-forms/includes/blocks/class-field-block.php
@@ -30,7 +30,7 @@
*/
public function register_block() {
$fields = apply_filters( 'gutena_forms__register_fields', array() );
- $group_dir = GUTENA_FORMS_DIR_PATH . 'build/form-fields/';
+ $group_dir = GUTENA_FORMS_DIR_PATH . 'build/blocks/form-fields/';
usort(
$fields,
@@ -39,11 +39,13 @@
}
);
+ $legacy_args = gutena_forms_legacy_block_registration_args();
+
foreach ( $fields as $field => $field_args ) {
if ( file_exists( $group_dir . $field_args['dir'] . '/block.json' ) ) {
- register_block_type( $group_dir . $field_args['dir'] );
+ register_block_type( $group_dir . $field_args['dir'], $legacy_args );
} elseif ( file_exists( $field_args['dir'] . '/block.json' ) ) {
- register_block_type( $field_args['dir'] );
+ register_block_type( $field_args['dir'], $legacy_args );
}
}
}
--- a/gutena-forms/includes/blocks/class-field-label-block.php
+++ b/gutena-forms/includes/blocks/class-field-label-block.php
@@ -30,7 +30,7 @@
*/
public function register_block() {
register_block_type(
- GUTENA_FORMS_DIR_PATH . 'build/field-label',
+ GUTENA_FORMS_DIR_PATH . 'build/blocks/field-label',
array(
'render_callback' => array( $this, 'render' ),
)
--- a/gutena-forms/includes/blocks/class-fields.php
+++ b/gutena-forms/includes/blocks/class-fields.php
@@ -0,0 +1,127 @@
+<?php
+/**
+ * Gutena Forms new Fields
+ *
+ * @since 1.9.1
+ * @package Gutena Forms
+ */
+
+defined( 'ABSPATH' ) || exit;
+
+if ( ! class_exists( 'Gutena_Forms_Fields' ) ) :
+ class Gutena_Forms_Fields {
+ private static $instance;
+
+ private $fields = array();
+
+ public static function get_instance() {
+ if ( is_null( self::$instance ) ) {
+ self::$instance = new Gutena_Forms_Fields();
+ }
+
+ return self::$instance;
+ }
+
+ private function __construct() {
+ $this->fields = array(
+ array(
+ 'name' => 'checkbox',
+ 'args' => array(),
+ ),
+ array(
+ 'name' => 'dropdown',
+ 'args' => array(),
+ ),
+ array(
+ 'name' => 'email',
+ 'args' => array(),
+ ),
+ array(
+ 'name' => 'number',
+ 'args' => array(),
+ ),
+ array(
+ 'name' => 'optin',
+ 'args' => array(),
+ ),
+ array(
+ 'name' => 'radio',
+ 'args' => array(),
+ ),
+ array(
+ 'name' => 'range',
+ 'args' => array(),
+ ),
+ array(
+ 'name' => 'text',
+ 'args' => array(),
+ ),
+ array(
+ 'name' => 'textarea',
+ 'args' => array(),
+ ),
+ );
+
+ add_filter( 'gutena_forms__register_form_fields', array( $this, 'register_fields' ) );
+ add_filter( 'gutena_forms_map_block_field_schema', array( $this, 'map_block_field_schema' ), 10, 3 );
+ }
+
+ /**
+ * Map standalone field blocks into the form schema on save.
+ *
+ * @param array $form_schema Form schema being built.
+ * @param array $block Parsed block.
+ * @param string $form_id Current form ID.
+ * @return array
+ */
+ public function map_block_field_schema( $form_schema, $block, $form_id ) {
+ if ( empty( $form_id ) || empty( $block['blockName'] ) || empty( $block['attrs']['nameAttr'] ) ) {
+ return $form_schema;
+ }
+
+ $standalone_block_names = array();
+ foreach ( $this->fields as $field ) {
+ $standalone_block_names[] = 'gutena/' . $field['name'] . '-field';
+ }
+
+ if ( in_array( $block['blockName'], $standalone_block_names, true ) ) {
+ $form_schema[ $form_id ]['form_fields'][ $block['attrs']['nameAttr'] ] = Gutena_Forms_Helper::merge_block_default_attributes(
+ $block['blockName'],
+ $block['attrs']
+ );