Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
325c715
feat(api): add storage and field protection hooks
Crabcyborg Nov 4, 2026
6b901b5
feat(api): pass the entry ID to the save filter and report denied del…
Crabcyborg Nov 11, 2026
c5da052
fix(api): report denied deletes and check once
Crabcyborg Nov 11, 2026
f207a0d
Merge master into feat/integration-storage-guards
Crabcyborg Nov 11, 2026
f3d5263
fix(fields): keep missing deletes idempotent
Crabcyborg Nov 12, 2026
fad0eaa
Merge master into feat/integration-storage-guards
Crabcyborg Nov 16, 2026
fe661c9
Merge master into feat/integration-storage-guards
Crabcyborg Nov 16, 2026
2f43596
Merge master into feat/integration-storage-guards
Crabcyborg Nov 16, 2026
d69c425
Merge master into feat/integration-storage-guards
Crabcyborg Nov 16, 2026
26f4b3b
Merge remote-tracking branch 'origin/master' into feat/integration-st…
Crabcyborg Nov 18, 2026
9248ea7
Guard entry duplication and denied field deletes
Crabcyborg Nov 19, 2026
28d20a7
Merge master into feat/integration-storage-guards
Crabcyborg Nov 19, 2026
8516239
fix(abilities): protect repeater children on delete
Crabcyborg Nov 23, 2026
1c63d70
Merge branch 'master' into feat/integration-storage-guards
Crabcyborg Nov 23, 2026
9e7aaa0
Merge remote-tracking branch 'origin/master' into HEAD
Crabcyborg Nov 27, 2026
6fe9533
Integrate current master and rebuild page-specific admin scripts
Crabcyborg Nov 30, 2026
f0bbee0
Merge master into feat/integration-storage-guards
Crabcyborg Dec 1, 2026
2808593
Merge remote-tracking branch 'origin/master' into feat/integration-st…
Crabcyborg Dec 1, 2026
06c1c13
Merge origin/master into feat/integration-storage-guards
Crabcyborg Dec 1, 2026
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
46 changes: 18 additions & 28 deletions classes/controllers/FrmAbilitiesFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,27 +477,27 @@ public static function execute_delete_field( $input ) {
}

if ( ! self::field_belongs_to_form( $field, $form->id ) ) {
return new WP_Error(
'frm_field_wrong_form',
__( 'That field does not belong to that form.', 'formidable' ),
array( 'status' => 404 )
);
return new WP_Error( 'frm_field_wrong_form', __( 'That field does not belong to that form.', 'formidable' ), array( 'status' => 404 ) );
}
}

// Read the field before it is gone, so the caller gets back what it deleted.
$data = self::prepare_field_for_response( $field );
$form_id = $field->form_id;
$child_ids = self::get_repeater_field_ids( $field );
foreach ( array_merge( array( $field->id ), $child_ids ) as $field_id ) {
if ( ! FrmField::can_destroy( $field_id ) ) {
return new WP_Error( 'frm_field_delete_denied', __( 'This field cannot be deleted.', 'formidable' ), array( 'status' => 403 ) );
}
}

if ( FrmField::is_repeating_field( $field ) && ! empty( $field->field_options['form_select'] ) ) {
self::destroy_fields_in_repeater( $field );
$data = self::prepare_field_for_response( $field );
foreach ( $child_ids as $field_id ) {
FrmField::destroy( $field_id );
}

if ( ! FrmField::destroy( $field->id ) ) {
return self::get_invalid_field_error();
}

FrmField::delete_form_transient( $form_id );
FrmField::delete_form_transient( $field->form_id );
FrmForm::clear_form_cache();

return $data;
Expand Down Expand Up @@ -886,26 +886,16 @@ private static function field_belongs_to_form( $field, $form_id ) {
}

/**
* Delete the fields inside a repeater's child form.
*
* @since 7.0
*
* @param stdClass $field Repeater field.
*
* @return void
* @param stdClass $field Field being deleted.
* @return array
*/
private static function destroy_fields_in_repeater( $field ) {
$repeater_form = FrmForm::getOne( $field->field_options['form_select'] );

if ( ! $repeater_form ) {
return;
private static function get_repeater_field_ids( $field ) {
if ( ! FrmField::is_repeating_field( $field ) || empty( $field->field_options['form_select'] ) ) {
return array();
}

$field_ids = FrmDb::get_col( 'frm_fields', array( 'form_id' => $repeater_form->id ) );

foreach ( $field_ids as $field_id ) {
FrmField::destroy( $field_id );
}
$form = FrmForm::getOne( $field->field_options['form_select'] );
return $form ? FrmDb::get_col( 'frm_fields', array( 'form_id' => $form->id ) ) : array();
}

/**
Expand Down
11 changes: 10 additions & 1 deletion classes/controllers/FrmFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,16 @@ public static function destroy() {
check_ajax_referer( 'frm_ajax', 'nonce' );

$field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
FrmField::destroy( $field_id );

if ( FrmField::getOne( $field_id ) && false === FrmField::destroy( $field_id ) ) {
wp_send_json_error(
array(
'message' => __( 'This field cannot be deleted.', 'formidable' ),
),
403
);
}

wp_die();
}

Expand Down
40 changes: 26 additions & 14 deletions classes/controllers/FrmFormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,12 @@ public static function update_settings() {

// Handle captcha field inclusion
$include_captcha = isset( $_POST['frm_include_captcha'] ) && '1' === $_POST['frm_include_captcha']; // phpcs:ignore WordPress.Security.NonceVerification.Missing
self::handle_captcha_field( $id, $include_captcha );
$captcha_updated = self::handle_captcha_field( $id, $include_captcha );
$gdpr_updated = self::maybe_handle_gdpr_field( $id );

self::maybe_handle_gdpr_field( $id );
if ( ! $captcha_updated || ! $gdpr_updated ) {
$warnings[] = __( 'Some fields could not be added or deleted.', 'formidable' );
}

$message = __( 'Settings Successfully Updated', 'formidable' );

Expand All @@ -314,10 +317,10 @@ private static function antispam_was_on( $form_id ) {
* @param int $form_id Form ID.
* @param bool $include_captcha Whether to include captcha field.
*
* @return void
* @return bool
*/
private static function handle_captcha_field( $form_id, $include_captcha ) {
self::toggle_field_in_form( $form_id, 'captcha', $include_captcha, __( 'Captcha', 'formidable' ) );
return self::toggle_field_in_form( $form_id, 'captcha', $include_captcha, __( 'Captcha', 'formidable' ) );
}

/**
Expand All @@ -328,16 +331,16 @@ private static function handle_captcha_field( $form_id, $include_captcha ) {
*
* @param int $form_id Form ID.
*
* @return void
* @return bool
*/
private static function maybe_handle_gdpr_field( $form_id ) {
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( ! isset( $_POST['frm_include_gdpr'] ) || FrmFieldGdprHelper::hide_gdpr_field() ) {
return;
return true;
}

$include_gdpr = '1' === $_POST['frm_include_gdpr']; // phpcs:ignore WordPress.Security.NonceVerification.Missing
self::toggle_field_in_form( $form_id, FrmFieldGdprHelper::FIELD_TYPE, $include_gdpr, __( 'GDPR', 'formidable' ) );
return self::toggle_field_in_form( $form_id, FrmFieldGdprHelper::FIELD_TYPE, $include_gdpr, __( 'GDPR', 'formidable' ) );
}

/**
Expand All @@ -350,7 +353,7 @@ private static function maybe_handle_gdpr_field( $form_id ) {
* @param bool $include Whether the form should include the field.
* @param string $field_name The name to give a newly created field.
*
* @return void
* @return bool
*/
private static function toggle_field_in_form( $form_id, $field_type, $include, $field_name ) {
$form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude' );
Expand All @@ -376,10 +379,14 @@ private static function toggle_field_in_form( $form_id, $field_type, $include, $
$field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
$field_values['name'] = $field_name;
$field_values['field_order'] = $submit_field_order > 0 ? $submit_field_order - 1 : $last_field_order + 1;
FrmField::create( $field_values );
} elseif ( ! $include && $existing_field_id ) {
FrmField::destroy( $existing_field_id );
return false !== FrmField::create( $field_values );
}

if ( ! $include && $existing_field_id ) {
return false !== FrmField::destroy( $existing_field_id );
}

return true;
}

/**
Expand Down Expand Up @@ -2736,16 +2743,21 @@ public static function show_form( $id = '', $key = '', $title = false, $descript
$form = do_shortcode( $frm_settings->login_msg );
} else {
do_action( 'frm_pre_get_form', $form );
$form = self::get_form( $form, $title, $description, $atts );
$form_object = $form;
$form = self::get_form( $form, $title, $description, $atts );

/**
* Use this shortcode to check for external shortcodes that may span
* across multiple fields in the customizable HTML
*
* @since 2.0.8
* @since x.x The form object is passed as the second argument.
*
* @param string $form Rendered form HTML.
* @param object $form_object Form being rendered.
*/
$form = apply_filters( 'frm_filter_final_form', $form );
}
$form = apply_filters( 'frm_filter_final_form', $form, $form_object );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function apply_filters invoked with 3 parameters, 2 required


The function call is not valid, which will result in a fatal runtime error.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function apply_filters invoked with 3 parameters, 2 required


The function call is not valid, which will result in a fatal runtime error.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function apply_filters invoked with 3 parameters, 2 required


The function call is not valid, which will result in a fatal runtime error.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function apply_filters invoked with 3 parameters, 2 required


The function call is not valid, which will result in a fatal runtime error.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function apply_filters invoked with 3 parameters, 2 required


The function call is not valid, which will result in a fatal runtime error.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function apply_filters invoked with 3 parameters, 2 required


The function call is not valid, which will result in a fatal runtime error.

}//end if

return $form;
}
Expand Down
20 changes: 15 additions & 5 deletions classes/helpers/FrmXMLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ public static function import_xml_forms( $forms, $imported ) {

self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported );

self::delete_removed_fields( $form_fields );
if ( ! self::delete_removed_fields( $form_fields ) ) {
$imported['warnings'][] = __( 'Some fields could not be deleted during import.', 'formidable' );
}

// Update field ids/keys to new ones.
do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) );
Expand Down Expand Up @@ -417,19 +419,23 @@ private static function get_form_fields( $form_id ) {
*
* @param array $form_fields
*
* @return void
* @return bool
*/
private static function delete_removed_fields( $form_fields ) {
if ( ! $form_fields ) {
return;
return true;
}

$deleted = true;

foreach ( $form_fields as $field ) {
if ( is_object( $field ) ) {
FrmField::destroy( $field->id );
if ( is_object( $field ) && false === FrmField::destroy( $field->id ) ) {
$deleted = false;
}
unset( $field );
}

return $deleted;
}

/**
Expand Down Expand Up @@ -1634,6 +1640,10 @@ public static function parse_message( $result, &$message, &$errors ) {
return;
}

if ( ! empty( $result['warnings'] ) ) {
$errors = array_merge( $errors, array_unique( $result['warnings'] ) );
}

$t_strings = array(
'imported' => __( 'Imported', 'formidable' ),
'updated' => __( 'Updated', 'formidable' ),
Expand Down
85 changes: 84 additions & 1 deletion classes/models/FrmEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,76 @@ public static function create( $values ) {
return self::create_entry( $values, 'standard' );
}

/**
* Allow integrations to prevent entry storage and its associated actions.
*
* This runs before the frm_pre_create_entry filter, so a callback on that filter that
* changes the form ID is not checked again.
*
* @since x.x
*
* @param array $values Entry values. On create this is the full set of posted values. On
* update it is the values being saved, with the entry's form ID added
* when they do not include one.
* @param int|string $entry_id The entry being updated, or 0 when a new entry is created.
*
* @return bool
*/
public static function allows_save( $values, $entry_id = 0 ) {
foreach ( array( 'form_id', 'parent_form_id' ) as $key ) {
if ( empty( $values[ $key ] ) ) {
continue;
}

$form = FrmForm::getOne( $values[ $key ] );

if ( $form && ! empty( $form->options['prevent_entry_storage'] ) ) {
return false;
}
}

/**
* Filter whether an entry may be saved.
*
* @since x.x
*
* @param bool $allow Whether the entry may be saved.
* @param array $values Entry values, including the form ID.
* @param int|string $entry_id The entry being updated, or 0 when a new entry is created.
*/
return (bool) apply_filters( 'frm_allow_entry_save', true, $values, (int) $entry_id );
}

/**
* Check whether an existing entry may be updated. The entry's own form is always
* checked, and so is the form in the new values when it moves the entry.
*
* @since x.x
*
* @param int $id Entry ID.
* @param array $values Values being saved.
*
* @return bool
*/
private static function allows_update( $id, $values ) {
$entry = self::getOne( $id );
$check_values = $values;

if ( $entry && empty( $check_values['form_id'] ) ) {
$check_values['form_id'] = $entry->form_id;
}

if ( ! self::allows_save( $check_values, $id ) ) {
return false;
}

if ( ! $entry || (int) $entry->form_id === (int) $check_values['form_id'] ) {
return true;
}

return self::allows_save( array( 'form_id' => $entry->form_id ), $id );
}

/**
* Create a new entry with some differences depending on type
*
Expand All @@ -32,6 +102,10 @@ public static function create( $values ) {
* @return bool|int Entry ID.
*/
private static function create_entry( $values, $type ) {
if ( ! self::allows_save( $values ) ) {
return false;
}

$new_values = self::before_insert_entry_in_database( $values, $type );

// Don't check XML entries for duplicates
Expand Down Expand Up @@ -286,7 +360,12 @@ private static function is_duplicate_check_needed( $values, $duplicate_entry_tim
public static function duplicate( $id ) {
global $wpdb;

$values = self::getOne( $id );
$values = self::getOne( $id );

if ( ! $values || ! self::allows_save( array( 'form_id' => $values->form_id ) ) ) {
return false;
}

$new_values = array();
$new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
$new_values['name'] = $values->name;
Expand Down Expand Up @@ -346,6 +425,10 @@ public static function update( $id, $values ) {
private static function update_entry( $id, $values, $update_type ) {
global $wpdb;

if ( ! self::allows_update( $id, $values ) ) {
return false;
}

$update = self::before_update_entry( $id, $values, $update_type );

if ( ! $update ) {
Expand Down
Loading