frm_user_can_edit

Back to Top
Knowledge BaseEntry Management → frm_user_can_edit

This hook allows you to customize which users can edit entries from the front-end.

Usage

add_filter('frm_user_can_edit', 'check_user_edit_form', 10, 2);

Parameters

  • $edit (true or false)
  • $args (array -- entry object, form object)

Examples

Formidable Hook - Helpful

Allow logged-out users to edit an entry

Submitted by  — 8 years ago

Use this code to allow all users, including logged-out users, to edit an entry.

add_filter('frm_user_can_edit', 'check_user_edit_form', 10, 2);
function check_user_edit_form($edit, $args){
  $form_id = is_numeric($args['form']) ? $args['form'] : $args['form']->id;
  if($form_id == 5){ //change 5 to the ID of your group form
    $edit = true;
  }
  return $edit;
}
Formidable Hook - Helpful

Prevent editing after a certain date

Submitted by  — 8 years ago

Use this code to prevent front-end editing of entries in a particular form after a certain date.

add_filter('frm_user_can_edit', 'check_user_edit_entry', 10, 2);
function check_user_edit_entry($edit, $args){
  $form_id = is_numeric($args['form']) ? $args['form'] : $args['form']->id;
  if($form_id == 45 and (time() >= strtotime('2014-01-31'))){ //change 45 to the ID of your form and change '2014-01-31' to the form closing date
    $edit = false;
  }
  return $edit;
}
Formidable Hook - Helpful

Prevent editing after 24 hours

Submitted by  — 8 years ago

If you would like to allow your users to edit their entry for a limited amount of time, you can add this to a child theme's functions.php file or the 'Code Snippets' plugin. Just replace 19 with the ID of your form and replace 24 with the number of hours that you want to allow editing.

add_filter('frm_user_can_edit', 'custom_prevent_editing_after_time_limit', 10, 2);
function custom_prevent_editing_after_time_limit($edit, $args){
	// If user can normally edit entries from this form, check if entry is within the time limit for editing
	if ( $edit && $args['form']->id == 19 ) {
		if ( is_numeric( $args[ 'entry' ] ) ) {
			$entry = FrmEntry::getOne( $args[ 'entry' ] );
		} else {
			$entry = $args[ 'entry' ];
		}

		if ( ( time() - strtotime( $entry->created_at ) ) >= ( 60 * 60 * 24 ) ) {  // change 24 to the number of hours to allow edit
			$edit = false;
		}
	}
	return $edit;
}
Formidable Hook - Helpful

Only allow one edit

Submitted by  — 8 years ago

If you would like to only allow an entry to be edited once, we can compare the updated and the creation dates. If they are different, the entry has already been edited. In order for this to work, you should enable editing in your form settings, and this code will prevent the editing. Keep in mind editing could also be done automatically

add_filter('frm_user_can_edit', 'check_user_edit_entry', 10, 2);
function check_user_edit_entry($edit, $args){
  $form_id = is_numeric($args['form']) ? $args['form'] : $args['form']->id;
  if ( $form_id == 45 ){ //change 45 to the ID of your form
    if ( is_numeric( $args['entry'] ) ) {
      $entry = FrmEntry::getOne( $entry );
    } else {
      $entry = $args['entry'];
    }
    if ( ! current_user_can('administrator') && $entry->created_at != $entry->updated_at ) {
      $edit = false;
    }
  }
  return $edit;
}
Formidable Hook - Helpful

Prevent editing based on field value

Submitted by  — 8 years ago

If your form is set up to allow editing, but you want to disallow editing when a certain field value is submitted, use the code below. Change 45 to the ID of your form, 123 to the ID of the field to check, and 'Closed' to the value that will prevent editing.

add_filter('frm_user_can_edit', 'maybe_prevent_user_edit_entry', 10, 2);
function maybe_prevent_user_edit_entry( $edit, $args ){
  if ( ! $edit ) {
    // user can't edit anyway, so don't check
    return $edit;
  }
  
  if ( $args['form']->id != 45 ) { //change 45 to the ID of your form
    return $edit;
  }

  if ( is_numeric( $args['entry'] ) ) {
    $entry_id = $args['entry'];
  } else {
    $entry_id = $args['entry']->id;
  }

  $field_value = FrmProEntriesController::get_field_value_shortcode( array( 'field_id' => 123, 'entry' => $entry_id ) );

  if ( $field_value == 'Closed'  ) {
    $edit = false;
  }

  return $edit;
}
If you would like to add your own example, click here.

Have something to add?

Click here to provide feedback on this page.