Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions admin/form-builder/views/post-form-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ function wpuf_render_settings_field( $field_key, $field, $form_settings, $post_t
$value = ! empty( $field['default'] ) ? $field['default'] : '';
$value = ! empty( $field['value'] ) ? $field['value'] : $value; // default value

$is_pro_preview = ! empty( $field['pro_preview'] ) || ( ! wpuf_is_pro_active() && in_array( $field_key, [ 'notification_edit', 'notification_edit_to', 'notification_edit_subject', 'notification_edit_body' ] ) );

// replace default value if already saved in DB
if ( ! empty( $field['name'] ) ) {
preg_match('/wpuf_settings\[(.*?)\]\[(.*?)\]/', $field['name'], $matches);
Expand All @@ -327,7 +329,9 @@ function wpuf_render_settings_field( $field_key, $field, $form_settings, $post_t
}

// if the field is a pro fields preview, no need to load fields from db
if ( empty( $field['pro_preview'] ) ) {
if ( $is_pro_preview ) {
$value = ! empty( $field['value'] ) ? $field['value'] : $value;
} else {
$value = isset( $form_settings[ $field_key ] ) ? $form_settings[ $field_key ] : $value; // checking with isset because saved value can be empty string
}

Expand All @@ -342,8 +346,9 @@ function wpuf_render_settings_field( $field_key, $field, $form_settings, $post_t
<input
:class="[setting_class_names('checkbox'), '!wpuf-mr-2']"
type="checkbox"
name="<?php echo $name; ?>"
name="<?php echo $is_pro_preview ? '' : $name; ?>"
<?php echo esc_attr( checked( $value, 'on', false ) ); ?>
<?php echo $is_pro_preview ? 'disabled' : ''; ?>
id="<?php echo $field_key; ?>"/>
<?php } ?>
<?php
Expand Down Expand Up @@ -373,15 +378,22 @@ function wpuf_render_settings_field( $field_key, $field, $form_settings, $post_t
echo '</div>';
}
?>
<?php if ( 'toggle' === $field['type'] ) { ?>
<?php if ( 'toggle' === $field['type'] ) {
// For pro preview notification fields, always show as 'off' (unchecked)
$toggle_value = $value;
if ( $is_pro_preview && strpos( $field_key, 'notification_' ) === 0 ) {
$toggle_value = 'off';
}
?>
<label
for="<?php echo $field_key; ?>"
class="wpuf-relative wpuf-inline-flex wpuf-items-center wpuf-cursor-pointer wpuf-ml-2">
<input
type="checkbox"
id="<?php echo $field_key; ?>"
name="<?php echo $name; ?>"
<?php echo esc_attr( checked( $value, 'on', false ) ); ?>
name="<?php echo $is_pro_preview ? '' : $name; ?>"
<?php echo esc_attr( checked( $toggle_value, 'on', false ) ); ?>
<?php echo $is_pro_preview ? 'disabled' : ''; ?>
class="wpuf-sr-only wpuf-peer">
<span class="wpuf-flex wpuf-items-center wpuf-w-10 wpuf-h-4 wpuf-bg-gray-300 wpuf-rounded-full wpuf-peer peer-checked:wpuf-bg-primary after:wpuf-w-6 after:wpuf-h-6 after:wpuf-bg-white after:wpuf-rounded-full after:wpuf-shadow-md after:wpuf-duration-300 peer-checked:after:wpuf-translate-x-4 after:wpuf-border after:wpuf-border-solid after:wpuf-border-gray-50"></span>
</label>
Expand Down Expand Up @@ -458,8 +470,9 @@ class="fa fa-angle-down !wpuf-font-bold !wpuf-text-xl !wpuf-leading-none wpuf-te
<input
:class="setting_class_names('text')"
type="<?php echo $field['type']; ?>"
name="<?php echo $name; ?>"
name="<?php echo $is_pro_preview ? '' : $name; ?>"
<?php echo ! empty( $field['placeholder'] ) ? 'placeholder=' . $field['placeholder'] : ''; ?>
<?php echo $is_pro_preview ? 'disabled' : ''; ?>
id="<?php echo $field_key; ?>"
value="<?php echo $value; ?>"/>
<?php } ?>
Expand All @@ -470,7 +483,8 @@ class="fa fa-angle-down !wpuf-font-bold !wpuf-text-xl !wpuf-leading-none wpuf-te
<textarea
:class="setting_class_names('textarea')"
rows="6"
name="<?php echo $name; ?>"
name="<?php echo $is_pro_preview ? '' : $name; ?>"
<?php echo $is_pro_preview ? 'disabled' : ''; ?>
id="<?php echo $field_key; ?>"><?php echo $value; ?></textarea>
<?php } ?>

Expand Down
25 changes: 24 additions & 1 deletion includes/Admin/Forms/Admin_Form_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
'form_settings_key' => '',
'post_id' => 0,
'shortcodes' => [],
// [ [ 'name' => 'wpuf_form', 'type' => 'profile' ], [ 'name' => 'wpuf_form', 'type' => 'registration' ] ]

Check warning on line 46 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 56% valid code; is this commented out code?
];
$this->settings = wp_parse_args( $settings, $defaults );
// set post data to global $post
$post = get_post( $this->settings['post_id'] );

Check failure on line 50 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Overriding WordPress globals is prohibited. Found assignment to $post
// if we have an existing post, then let's start
if ( ! empty( $post->ID ) ) {
add_action( 'in_admin_header', 'wpuf_remove_admin_notices' );
Expand Down Expand Up @@ -317,7 +317,7 @@
'last_column_warn_msg' => __( 'This field must contain at least one column', 'wp-user-frontend' ),
'is_a_pro_feature' => __( 'is a pro feature', 'wp-user-frontend' ),
'pro_feature_msg' => __(
'<p class="wpuf-text-gray-500 wpuf-font-medium wpuf-text-xl">Please upgrade to the Pro version to unlock all these awesome features</p>',

Check warning on line 320 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Translatable string should not be wrapped in HTML. Found: '<p class="wpuf-text-gray-500 wpuf-font-medium wpuf-text-xl">Please upgrade to the Pro version to unlock all these awesome features</p>'
'wp-user-frontend'
),
'upgrade_to_pro' => __( 'Upgrade to PRO', 'wp-user-frontend' ),
Expand All @@ -337,19 +337,19 @@
*
* @param array $data Contains form_fields, form_settings, form_settings_key data
*
* @return bool
* @return array
*/
public static function save_form( $data ) {
$saved_wpuf_inputs = [];
wp_update_post( [ 'ID' => $data['form_id'], 'post_status' => 'publish', 'post_title' => $data['post_title'] ] );

Check warning on line 344 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

When a multi-item array uses associative keys, each value should start on a new line.
$existing_wpuf_input_ids = get_children( [

Check failure on line 345 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Opening parenthesis of a multi-line function call must be the last content on the line
'post_parent' => $data['form_id'],

Check warning on line 346 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'post_status' => 'publish',

Check warning on line 347 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'post_type' => 'wpuf_input',

Check warning on line 348 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'numberposts' => '-1',

Check warning on line 349 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'orderby' => 'menu_order',

Check warning on line 350 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'order' => 'ASC',

Check warning on line 351 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'fields' => 'ids',

Check warning on line 352 in includes/Admin/Forms/Admin_Form_Builder.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
] );
$new_wpuf_input_ids = [];
if ( ! empty( $data['form_fields'] ) ) {
Expand All @@ -373,6 +373,29 @@
wp_delete_post( $delete_id, true );
}
}

// Filter out pro notification settings if pro version is not active
if ( ! wpuf_is_pro_active() && isset( $data['form_settings']['notification'] ) ) {
// Remove update post notification settings for free version
if ( isset( $data['form_settings']['notification']['edit'] ) ) {
unset( $data['form_settings']['notification']['edit'] );
}
if ( isset( $data['form_settings']['notification']['edit_to'] ) ) {
unset( $data['form_settings']['notification']['edit_to'] );
}
if ( isset( $data['form_settings']['notification']['edit_subject'] ) ) {
unset( $data['form_settings']['notification']['edit_subject'] );
}
if ( isset( $data['form_settings']['notification']['edit_body'] ) ) {
unset( $data['form_settings']['notification']['edit_body'] );
}
}

// Also filter out standalone notification_edit field if it exists
if ( ! wpuf_is_pro_active() && isset( $data['form_settings']['notification_edit'] ) ) {
unset( $data['form_settings']['notification_edit'] );
}

update_post_meta( $data['form_id'], $data['form_settings_key'], $data['form_settings'] );
update_post_meta( $data['form_id'], 'notifications', $data['notifications'] );
update_post_meta( $data['form_id'], 'integrations', $data['integrations'] );
Expand Down
3 changes: 3 additions & 0 deletions includes/Free/Free_Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use WeDevs\Wpuf\Admin\Forms\Post\Templates\Post_Form_Template_WooCommerce;
use WeDevs\Wpuf\Admin\Forms\Post\Templates\Pro_Form_Preview_EDD;
use WeDevs\Wpuf\Pro\Admin\Coupon_Elements;
use WeDevs\Wpuf\Hooks\Form_Settings_Cleanup;

class Free_Loader extends Pro_Prompt {

Expand Down Expand Up @@ -72,6 +73,7 @@ public function run_hooks() {
public function includes() {
// class files to include pro elements
require_once WPUF_INCLUDES . '/functions/user/edit-user.php';
require_once WPUF_INCLUDES . '/Hooks/Form_Settings_Cleanup.php';
}

public function instantiate() {
Expand All @@ -90,6 +92,7 @@ public function instantiate() {

if ( $load_free ) {
new WPUF_Admin_Form_Free();
new Form_Settings_Cleanup();
}
}
}
Expand Down
107 changes: 107 additions & 0 deletions includes/Hooks/Form_Settings_Cleanup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace WeDevs\Wpuf\Hooks;

/**
* Form Settings Cleanup
*

Check failure on line 7 in includes/Hooks/Form_Settings_Cleanup.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Whitespace found at end of line
* Cleans up pro-only settings from form configurations in the free version
* to prevent unintended activation of premium features.
*/
class Form_Settings_Cleanup {

/**
* Constructor
*/
public function __construct() {
add_action( 'wpuf_form_builder_save_form', [ $this, 'cleanup_pro_settings' ], 10, 1 );
add_action( 'save_post', [ $this, 'cleanup_form_meta_pro_settings' ], 10, 2 );
}

/**
* Clean up pro settings after form save
*
* @param int $form_id Form ID
*/
public function cleanup_pro_settings( $form_id ) {
if ( wpuf_is_pro_active() ) {
return;
}

$form_settings = wpuf_get_form_settings( $form_id );

Check failure on line 32 in includes/Hooks/Form_Settings_Cleanup.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Whitespace found at end of line
if ( empty( $form_settings ) ) {
return;
}

$cleaned_settings = $this->remove_pro_notification_settings( $form_settings );

Check failure on line 38 in includes/Hooks/Form_Settings_Cleanup.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Whitespace found at end of line
// Update if settings were modified
if ( $cleaned_settings !== $form_settings ) {
update_post_meta( $form_id, 'wpuf_form_settings', $cleaned_settings );
}
}

/**
* Clean up pro settings from post meta
*
* @param int $post_id Post ID
* @param \WP_Post $post Post object
*/
public function cleanup_form_meta_pro_settings( $post_id, $post ) {
if ( wpuf_is_pro_active() || $post->post_type !== 'wpuf_forms' ) {
return;
}

$form_settings = get_post_meta( $post_id, 'wpuf_form_settings', true );

Check failure on line 57 in includes/Hooks/Form_Settings_Cleanup.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Whitespace found at end of line
if ( empty( $form_settings ) ) {
return;
}

$cleaned_settings = $this->remove_pro_notification_settings( $form_settings );

Check failure on line 63 in includes/Hooks/Form_Settings_Cleanup.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Whitespace found at end of line
// Update if settings were modified
if ( $cleaned_settings !== $form_settings ) {
update_post_meta( $post_id, 'wpuf_form_settings', $cleaned_settings );
}
}

/**
* Remove pro notification settings from form settings
*
* @param array $form_settings Form settings array
* @return array Cleaned form settings
*/
private function remove_pro_notification_settings( $form_settings ) {
if ( ! is_array( $form_settings ) ) {
return $form_settings;
}

// List of pro-only notification settings to remove
$pro_notification_keys = [
'notification_edit',
'notification_edit_to',

Check failure on line 84 in includes/Hooks/Form_Settings_Cleanup.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Whitespace found at end of line
'notification_edit_subject',
'notification_edit_body'

Check failure on line 86 in includes/Hooks/Form_Settings_Cleanup.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There should be a comma after the last array item in a multi-line array.
];

foreach ( $pro_notification_keys as $key ) {
if ( isset( $form_settings[ $key ] ) ) {
unset( $form_settings[ $key ] );
}
}

if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
$notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];

Check failure on line 97 in includes/Hooks/Form_Settings_Cleanup.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Whitespace found at end of line
foreach ( $notification_pro_keys as $key ) {
if ( isset( $form_settings['notification'][ $key ] ) ) {
unset( $form_settings['notification'][ $key ] );
}
}
}

return $form_settings;
}
}
Comment on lines +76 to +107
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix code formatting issues identified by PHPCS.

The logic is correct, but there are several formatting issues that need to be addressed.

Apply this diff to fix the formatting issues:

-    /**
-     * Remove pro notification settings from form settings
-     *
-     * @param array $form_settings Form settings array
-     * @return array Cleaned form settings
-     */
-    private function remove_pro_notification_settings( $form_settings ) {
-        if ( ! is_array( $form_settings ) ) {
-            return $form_settings;
-        }
-
-        // List of pro-only notification settings to remove
-        $pro_notification_keys = [
-            'notification_edit',
-            'notification_edit_to', 
-            'notification_edit_subject',
-            'notification_edit_body'
-        ];
-
-        foreach ( $pro_notification_keys as $key ) {
-            if ( isset( $form_settings[ $key ] ) ) {
-                unset( $form_settings[ $key ] );
-            }
-        }
-
-        if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
-            $notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
-            
-            foreach ( $notification_pro_keys as $key ) {
-                if ( isset( $form_settings['notification'][ $key ] ) ) {
-                    unset( $form_settings['notification'][ $key ] );
-                }
-            }
-        }
-
-        return $form_settings;
-    }
+    /**
+     * Remove pro notification settings from form settings
+     *
+     * @param array $form_settings Form settings array
+     * @return array Cleaned form settings
+     */
+    private function remove_pro_notification_settings( $form_settings ) {
+        if ( ! is_array( $form_settings ) ) {
+            return $form_settings;
+        }
+
+        // List of pro-only notification settings to remove
+        $pro_notification_keys = [
+            'notification_edit',
+            'notification_edit_to',
+            'notification_edit_subject',
+            'notification_edit_body',
+        ];
+
+        foreach ( $pro_notification_keys as $key ) {
+            if ( isset( $form_settings[ $key ] ) ) {
+                unset( $form_settings[ $key ] );
+            }
+        }
+
+        if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
+            $notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
+
+            foreach ( $notification_pro_keys as $key ) {
+                if ( isset( $form_settings['notification'][ $key ] ) ) {
+                    unset( $form_settings['notification'][ $key ] );
+                }
+            }
+        }
+
+        return $form_settings;
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private function remove_pro_notification_settings( $form_settings ) {
if ( ! is_array( $form_settings ) ) {
return $form_settings;
}
// List of pro-only notification settings to remove
$pro_notification_keys = [
'notification_edit',
'notification_edit_to',
'notification_edit_subject',
'notification_edit_body'
];
foreach ( $pro_notification_keys as $key ) {
if ( isset( $form_settings[ $key ] ) ) {
unset( $form_settings[ $key ] );
}
}
if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
$notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
foreach ( $notification_pro_keys as $key ) {
if ( isset( $form_settings['notification'][ $key ] ) ) {
unset( $form_settings['notification'][ $key ] );
}
}
}
return $form_settings;
}
}
private function remove_pro_notification_settings( $form_settings ) {
if ( ! is_array( $form_settings ) ) {
return $form_settings;
}
// List of pro-only notification settings to remove
$pro_notification_keys = [
'notification_edit',
'notification_edit_to',
'notification_edit_subject',
'notification_edit_body',
];
foreach ( $pro_notification_keys as $key ) {
if ( isset( $form_settings[ $key ] ) ) {
unset( $form_settings[ $key ] );
}
}
if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
$notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
foreach ( $notification_pro_keys as $key ) {
if ( isset( $form_settings['notification'][ $key ] ) ) {
unset( $form_settings['notification'][ $key ] );
}
}
}
return $form_settings;
}
}
🧰 Tools
🪛 GitHub Check: Run PHPCS inspection

[failure] 97-97:
Whitespace found at end of line


[failure] 86-86:
There should be a comma after the last array item in a multi-line array.


[failure] 84-84:
Whitespace found at end of line

🤖 Prompt for AI Agents
In includes/Hooks/Form_Settings_Cleanup.php around lines 76 to 107, the code
logic is correct but the formatting does not comply with PHPCS standards. Fix
the formatting issues by ensuring proper indentation, consistent spacing around
array elements and control structures, and correct placement of braces according
to the project's coding standards. This includes aligning array keys and values,
adding or removing blank lines where necessary, and making sure the overall code
style matches the rest of the codebase.

Loading