Skip to content

Commit d38c141

Browse files
authored
Fix: Disable Update Post Notification in free version (#1614)
- Prevent update post notification from being enabled by default in free version - Filter out pro notification fields from form settings before saving - Update UI to show Update Post Notification toggle as disabled/off in free version - Add Form_Settings_Cleanup hook to remove pro notification settings from saved form meta - Ensure backward compatibility and no impact on pro users - Resolves issue #1613 where free users received unwanted update notifications
1 parent 9658bb5 commit d38c141

File tree

4 files changed

+155
-8
lines changed

4 files changed

+155
-8
lines changed

admin/form-builder/views/post-form-settings.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ function wpuf_render_settings_field( $field_key, $field, $form_settings, $post_t
313313
$value = ! empty( $field['default'] ) ? $field['default'] : '';
314314
$value = ! empty( $field['value'] ) ? $field['value'] : $value; // default value
315315

316+
$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' ] ) );
317+
316318
// replace default value if already saved in DB
317319
if ( ! empty( $field['name'] ) ) {
318320
preg_match('/wpuf_settings\[(.*?)\]\[(.*?)\]/', $field['name'], $matches);
@@ -327,7 +329,9 @@ function wpuf_render_settings_field( $field_key, $field, $form_settings, $post_t
327329
}
328330

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

@@ -342,8 +346,9 @@ function wpuf_render_settings_field( $field_key, $field, $form_settings, $post_t
342346
<input
343347
:class="[setting_class_names('checkbox'), '!wpuf-mr-2']"
344348
type="checkbox"
345-
name="<?php echo $name; ?>"
349+
name="<?php echo $is_pro_preview ? '' : $name; ?>"
346350
<?php echo esc_attr( checked( $value, 'on', false ) ); ?>
351+
<?php echo $is_pro_preview ? 'disabled' : ''; ?>
347352
id="<?php echo $field_key; ?>"/>
348353
<?php } ?>
349354
<?php
@@ -373,15 +378,22 @@ function wpuf_render_settings_field( $field_key, $field, $form_settings, $post_t
373378
echo '</div>';
374379
}
375380
?>
376-
<?php if ( 'toggle' === $field['type'] ) { ?>
381+
<?php if ( 'toggle' === $field['type'] ) {
382+
// For pro preview notification fields, always show as 'off' (unchecked)
383+
$toggle_value = $value;
384+
if ( $is_pro_preview && strpos( $field_key, 'notification_' ) === 0 ) {
385+
$toggle_value = 'off';
386+
}
387+
?>
377388
<label
378389
for="<?php echo $field_key; ?>"
379390
class="wpuf-relative wpuf-inline-flex wpuf-items-center wpuf-cursor-pointer wpuf-ml-2">
380391
<input
381392
type="checkbox"
382393
id="<?php echo $field_key; ?>"
383-
name="<?php echo $name; ?>"
384-
<?php echo esc_attr( checked( $value, 'on', false ) ); ?>
394+
name="<?php echo $is_pro_preview ? '' : $name; ?>"
395+
<?php echo esc_attr( checked( $toggle_value, 'on', false ) ); ?>
396+
<?php echo $is_pro_preview ? 'disabled' : ''; ?>
385397
class="wpuf-sr-only wpuf-peer">
386398
<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>
387399
</label>
@@ -458,8 +470,9 @@ class="fa fa-angle-down !wpuf-font-bold !wpuf-text-xl !wpuf-leading-none wpuf-te
458470
<input
459471
:class="setting_class_names('text')"
460472
type="<?php echo $field['type']; ?>"
461-
name="<?php echo $name; ?>"
473+
name="<?php echo $is_pro_preview ? '' : $name; ?>"
462474
<?php echo ! empty( $field['placeholder'] ) ? 'placeholder=' . $field['placeholder'] : ''; ?>
475+
<?php echo $is_pro_preview ? 'disabled' : ''; ?>
463476
id="<?php echo $field_key; ?>"
464477
value="<?php echo $value; ?>"/>
465478
<?php } ?>
@@ -470,7 +483,8 @@ class="fa fa-angle-down !wpuf-font-bold !wpuf-text-xl !wpuf-leading-none wpuf-te
470483
<textarea
471484
:class="setting_class_names('textarea')"
472485
rows="6"
473-
name="<?php echo $name; ?>"
486+
name="<?php echo $is_pro_preview ? '' : $name; ?>"
487+
<?php echo $is_pro_preview ? 'disabled' : ''; ?>
474488
id="<?php echo $field_key; ?>"><?php echo $value; ?></textarea>
475489
<?php } ?>
476490

includes/Admin/Forms/Admin_Form_Builder.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ private function i18n() {
337337
*
338338
* @param array $data Contains form_fields, form_settings, form_settings_key data
339339
*
340-
* @return bool
340+
* @return array
341341
*/
342342
public static function save_form( $data ) {
343343
$saved_wpuf_inputs = [];
@@ -373,6 +373,29 @@ public static function save_form( $data ) {
373373
wp_delete_post( $delete_id, true );
374374
}
375375
}
376+
377+
// Filter out pro notification settings if pro version is not active
378+
if ( ! wpuf_is_pro_active() && isset( $data['form_settings']['notification'] ) ) {
379+
// Remove update post notification settings for free version
380+
if ( isset( $data['form_settings']['notification']['edit'] ) ) {
381+
unset( $data['form_settings']['notification']['edit'] );
382+
}
383+
if ( isset( $data['form_settings']['notification']['edit_to'] ) ) {
384+
unset( $data['form_settings']['notification']['edit_to'] );
385+
}
386+
if ( isset( $data['form_settings']['notification']['edit_subject'] ) ) {
387+
unset( $data['form_settings']['notification']['edit_subject'] );
388+
}
389+
if ( isset( $data['form_settings']['notification']['edit_body'] ) ) {
390+
unset( $data['form_settings']['notification']['edit_body'] );
391+
}
392+
}
393+
394+
// Also filter out standalone notification_edit field if it exists
395+
if ( ! wpuf_is_pro_active() && isset( $data['form_settings']['notification_edit'] ) ) {
396+
unset( $data['form_settings']['notification_edit'] );
397+
}
398+
376399
update_post_meta( $data['form_id'], $data['form_settings_key'], $data['form_settings'] );
377400
update_post_meta( $data['form_id'], 'notifications', $data['notifications'] );
378401
update_post_meta( $data['form_id'], 'integrations', $data['integrations'] );

includes/Free/Free_Loader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use WeDevs\Wpuf\Admin\Forms\Post\Templates\Post_Form_Template_WooCommerce;
77
use WeDevs\Wpuf\Admin\Forms\Post\Templates\Pro_Form_Preview_EDD;
88
use WeDevs\Wpuf\Pro\Admin\Coupon_Elements;
9+
use WeDevs\Wpuf\Hooks\Form_Settings_Cleanup;
910

1011
class Free_Loader extends Pro_Prompt {
1112

@@ -72,6 +73,7 @@ public function run_hooks() {
7273
public function includes() {
7374
// class files to include pro elements
7475
require_once WPUF_INCLUDES . '/functions/user/edit-user.php';
76+
require_once WPUF_INCLUDES . '/Hooks/Form_Settings_Cleanup.php';
7577
}
7678

7779
public function instantiate() {
@@ -90,6 +92,7 @@ public function instantiate() {
9092

9193
if ( $load_free ) {
9294
new WPUF_Admin_Form_Free();
95+
new Form_Settings_Cleanup();
9396
}
9497
}
9598
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace WeDevs\Wpuf\Hooks;
4+
5+
/**
6+
* Form Settings Cleanup
7+
*
8+
* Cleans up pro-only settings from form configurations in the free version
9+
* to prevent unintended activation of premium features.
10+
*/
11+
class Form_Settings_Cleanup {
12+
13+
/**
14+
* Constructor
15+
*/
16+
public function __construct() {
17+
add_action( 'wpuf_form_builder_save_form', [ $this, 'cleanup_pro_settings' ], 10, 1 );
18+
add_action( 'save_post', [ $this, 'cleanup_form_meta_pro_settings' ], 10, 2 );
19+
}
20+
21+
/**
22+
* Clean up pro settings after form save
23+
*
24+
* @param int $form_id Form ID
25+
*/
26+
public function cleanup_pro_settings( $form_id ) {
27+
if ( wpuf_is_pro_active() ) {
28+
return;
29+
}
30+
31+
$form_settings = wpuf_get_form_settings( $form_id );
32+
33+
if ( empty( $form_settings ) ) {
34+
return;
35+
}
36+
37+
$cleaned_settings = $this->remove_pro_notification_settings( $form_settings );
38+
39+
// Update if settings were modified
40+
if ( $cleaned_settings !== $form_settings ) {
41+
update_post_meta( $form_id, 'wpuf_form_settings', $cleaned_settings );
42+
}
43+
}
44+
45+
/**
46+
* Clean up pro settings from post meta
47+
*
48+
* @param int $post_id Post ID
49+
* @param \WP_Post $post Post object
50+
*/
51+
public function cleanup_form_meta_pro_settings( $post_id, $post ) {
52+
if ( wpuf_is_pro_active() || $post->post_type !== 'wpuf_forms' ) {
53+
return;
54+
}
55+
56+
$form_settings = get_post_meta( $post_id, 'wpuf_form_settings', true );
57+
58+
if ( empty( $form_settings ) ) {
59+
return;
60+
}
61+
62+
$cleaned_settings = $this->remove_pro_notification_settings( $form_settings );
63+
64+
// Update if settings were modified
65+
if ( $cleaned_settings !== $form_settings ) {
66+
update_post_meta( $post_id, 'wpuf_form_settings', $cleaned_settings );
67+
}
68+
}
69+
70+
/**
71+
* Remove pro notification settings from form settings
72+
*
73+
* @param array $form_settings Form settings array
74+
* @return array Cleaned form settings
75+
*/
76+
private function remove_pro_notification_settings( $form_settings ) {
77+
if ( ! is_array( $form_settings ) ) {
78+
return $form_settings;
79+
}
80+
81+
// List of pro-only notification settings to remove
82+
$pro_notification_keys = [
83+
'notification_edit',
84+
'notification_edit_to',
85+
'notification_edit_subject',
86+
'notification_edit_body'
87+
];
88+
89+
foreach ( $pro_notification_keys as $key ) {
90+
if ( isset( $form_settings[ $key ] ) ) {
91+
unset( $form_settings[ $key ] );
92+
}
93+
}
94+
95+
if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
96+
$notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
97+
98+
foreach ( $notification_pro_keys as $key ) {
99+
if ( isset( $form_settings['notification'][ $key ] ) ) {
100+
unset( $form_settings['notification'][ $key ] );
101+
}
102+
}
103+
}
104+
105+
return $form_settings;
106+
}
107+
}

0 commit comments

Comments
 (0)