/home/techb158/on-time-movers.com/wp-content/plugins/wpforms/src/Pro/Admin/Entries
Edit: /home/techb158/on-time-movers.com/wp-content/plugins/wpforms/src/Pro/Admin/Entries/Edit.php (42438B)
is_admin_entry_editing_ajax() ) {
$entry_id = isset( $_POST['wpforms']['entry_id'] ) ? absint( wp_unslash( $_POST['wpforms']['entry_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
} else {
$entry_id = isset( $_GET['entry_id'] ) ? absint( wp_unslash( $_GET['entry_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
}
// Check permissions and other constraints.
if ( ! is_admin() || ! wpforms_current_user_can( 'edit_entry_single', $entry_id ) ) {
return;
}
$this->hooks();
}
/**
* Hooks.
*
* @since 1.6.0
*/
private function hooks() {
add_action( 'delete_attachment', [ $this, 'maybe_remove_attachment_data_from_entries' ] );
if ( $this->is_admin_entry_editing_ajax() ) {
remove_action( 'wp_ajax_wpforms_submit', [ wpforms()->process, 'ajax_submit' ] );
// Submit action AJAX endpoint.
add_action( 'wp_ajax_wpforms_submit', [ $this, 'ajax_submit' ] );
return;
}
// Check view entry page.
if ( wpforms_is_admin_page( 'entries', 'details' ) ) {
add_action( 'wpforms_entry_details_sidebar_details_action', [ $this, 'display_edit_button' ], 10, 2 );
}
// Check edit entry page.
if ( ! wpforms_is_admin_page( 'entries', 'edit' ) ) {
return;
}
// Entry processing and setup.
add_action( 'wpforms_entries_init', [ $this, 'setup' ], 10, 1 );
do_action( 'wpforms_entries_init', 'edit' );
// Instance of `\WPForms_Entries_Single` class.
$entries_single = new \WPForms_Entries_Single();
// Display Empty State screen.
add_action( 'wpforms_admin_page', [ $this, 'display_abort_message' ] );
// Output. Entry edit page.
add_action( 'wpforms_admin_page', [ $this, 'display_edit_page' ] );
// Entry edit form.
add_action( 'wpforms_pro_admin_entries_edit_content', [ $this, 'display_edit_form' ], 10, 2 );
// Reuse Debug metabox from `\WPForms_Entries_Single` class.
add_action( 'wpforms_pro_admin_entries_edit_content', [ $entries_single, 'details_debug' ], 50, 2 );
// Update button.
add_action( 'wpforms_entry_details_sidebar_details_action', [ $this, 'update_button' ], 10, 2 );
// Reuse Details metabox from `\WPForms_Entries_Single` class.
add_action( 'wpforms_pro_admin_entries_edit_sidebar', [ $entries_single, 'details_meta' ], 10, 2 );
// Remove Screen Options tab from admin area header.
add_filter( 'screen_options_show_screen', '__return_false' );
// Enqueues.
add_action( 'admin_enqueue_scripts', [ $this, 'enqueues' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'before_enqueue_media' ], 0 );
// Hook for add-ons.
do_action( 'wpforms_pro_admin_entries_edit_init', $this );
}
/**
* Enqueue assets.
*
* @since 1.6.0
*/
public function enqueues() {
if ( ! empty( $this->abort ) ) {
return;
}
$this->enqueue_styles();
$this->enqueue_scripts();
if ( empty( $this->form_data['fields'] ) || ! is_array( $this->form_data['fields'] ) ) {
return;
}
// Get a list of unique field types used in a form.
$field_types = array_filter( wp_list_pluck( $this->form_data['fields'], 'type' ) );
foreach ( $field_types as $field_type ) {
$obj = $this->get_entries_edit_field_object( $field_type );
$obj->enqueues();
}
}
/**
* Initialize Rich Text field related settings before calling wp_enqueue_media().
*
* @since 1.7.0
*/
public function before_enqueue_media() {
( new \WPForms_Field_Richtext( false ) )->edit_entry_before_enqueues();
}
/**
* Enqueue styles.
*
* @since 1.6.0
*/
public function enqueue_styles() {
wp_enqueue_media();
$min = wpforms_get_min_suffix();
// Frontend form base styles.
wp_enqueue_style(
'wpforms-base',
WPFORMS_PLUGIN_URL . 'assets/css/wpforms-base.css',
[],
WPFORMS_VERSION
);
// Entry Edit styles.
wp_enqueue_style(
'wpforms-entry-edit',
WPFORMS_PLUGIN_URL . "assets/pro/css/entry-edit{$min}.css",
[],
WPFORMS_VERSION
);
}
/**
* Enqueue scripts.
*
* @since 1.6.0
*/
public function enqueue_scripts() {
$min = wpforms_get_min_suffix();
if ( wpforms_has_field_setting( 'input_mask', $this->form, true ) ) {
// Load jQuery input mask library - https://github.com/RobinHerbots/jquery.inputmask.
wp_enqueue_script(
'wpforms-maskedinput',
WPFORMS_PLUGIN_URL . 'assets/lib/jquery.inputmask.min.js',
[ 'jquery' ],
'5.0.7-beta.29',
true
);
}
// Load admin utils JS.
wp_enqueue_script(
'wpforms-admin-utils',
WPFORMS_PLUGIN_URL . "assets/js/admin-utils{$min}.js",
[ 'jquery' ],
WPFORMS_VERSION,
true
);
wp_enqueue_script(
'wpforms-punycode',
WPFORMS_PLUGIN_URL . 'assets/lib/punycode.min.js',
[],
'1.0.0',
true
);
if ( wpforms_has_field_type( 'richtext', $this->form ) ) {
wp_enqueue_script(
'wpforms-richtext-field',
WPFORMS_PLUGIN_URL . "assets/pro/js/fields/richtext{$min}.js",
[ 'jquery' ],
WPFORMS_VERSION,
true
);
}
wp_enqueue_script(
'wpforms-generic-utils',
WPFORMS_PLUGIN_URL . "assets/js/utils{$min}.js",
[ 'jquery' ],
WPFORMS_VERSION,
true
);
// Load frontend base JS.
wp_enqueue_script(
'wpforms-frontend',
WPFORMS_PLUGIN_URL . "assets/js/wpforms{$min}.js",
[ 'jquery' ],
WPFORMS_VERSION,
true
);
// Load admin JS.
wp_enqueue_script(
'wpforms-admin-edit-entry',
WPFORMS_PLUGIN_URL . "assets/pro/js/admin/edit-entry{$min}.js",
[ 'jquery' ],
WPFORMS_VERSION,
true
);
// Localize frontend strings.
wp_localize_script(
'wpforms-frontend',
'wpforms_settings',
wpforms()->frontend->get_strings()
);
// Localize edit entry strings.
wp_localize_script(
'wpforms-admin-edit-entry',
'wpforms_admin_edit_entry',
$this->get_localized_data()
);
}
/**
* Get localized data.
*
* @since 1.6.0
*/
private function get_localized_data() {
$data['strings'] = [
'update' => esc_html__( 'Update', 'wpforms' ),
'success' => esc_html__( 'Success', 'wpforms' ),
'continue_editing' => esc_html__( 'Continue Editing', 'wpforms' ),
'view_entry' => esc_html__( 'View Entry', 'wpforms' ),
'msg_saved' => esc_html__( 'The entry was successfully saved.', 'wpforms' ),
'entry_delete_file' => sprintf( /* translators: %s - file name. */
esc_html__( 'Are you sure you want to permanently delete the file "%s"?', 'wpforms' ),
'{file_name}'
),
'entry_empty_file' => esc_html__( 'Empty', 'wpforms' ),
];
// View Entry URL.
$data['strings']['view_entry_url'] = add_query_arg(
[
'page' => 'wpforms-entries',
'view' => 'details',
'entry_id' => $this->entry_id,
],
admin_url( 'admin.php' )
);
return $data;
}
/**
* Setup entry edit page data.
*
* This function does the error checking and variable setup.
*
* @since 1.6.0
*/
public function setup() {
// No entry ID was provided, abort.
if ( empty( $_GET['entry_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$this->abort_message = esc_html__( 'It looks like the provided entry ID isn\'t valid.', 'wpforms' );
$this->abort = true;
return;
}
// Find the entry.
// phpcs:ignore WordPress.Security.NonceVerification
$entry = wpforms()->get( 'entry' )->get( (int) $_GET['entry_id'] );
// If entry exists.
if ( ! empty( $entry ) ) {
// Find the form information.
$form = wpforms()->get( 'form' )->get( $entry->form_id, [ 'cap' => 'edit_entries_form_single' ] );
}
// No entry was found, no form was found, the Form is in the Trash.
if ( empty( $entry ) || empty( $form ) || $form->post_status === 'trash' ) {
$this->abort_message = esc_html__( 'It looks like the entry you are trying to access is no longer available.', 'wpforms' );
$this->abort = true;
return;
}
// No editable fields, redirect back.
if ( ! wpforms()->get( 'entry' )->has_editable_fields( $entry ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$entry_list = add_query_arg(
[
'page' => 'wpforms-entries',
'view' => 'list',
'form_id' => $entry->form_id,
],
admin_url( 'admin.php' )
);
wp_safe_redirect( wp_get_referer() ? wp_get_referer() : $entry_list );
exit;
}
// Form data.
$form_data = wpforms_decode( $form->post_content );
$form->form_entries_url = add_query_arg(
[
'page' => 'wpforms-entries',
'view' => 'list',
'form_id' => absint( $form_data['id'] ),
],
admin_url( 'admin.php' )
);
// Make public.
$this->entry = $entry;
$this->entry_id = $entry->entry_id;
$this->entry_fields = apply_filters( 'wpforms_entry_single_data', wpforms_decode( $entry->fields ), $entry, $form_data );
$this->form = $form;
$this->form_data = $form_data;
$this->form_id = $form->ID;
// Lastly, mark entry as read if needed.
if ( $entry->viewed !== '1' && empty( $_GET['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$is_success = wpforms()->entry->update(
$entry->entry_id,
[
'viewed' => '1',
]
);
}
if ( ! empty( $is_success ) ) {
$this->add_entry_meta( esc_html__( 'Entry read.', 'wpforms' ) );
$this->entry->viewed = '1';
$this->entry->entry_logs = wpforms()->entry_meta->get_meta(
[
'entry_id' => $entry->entry_id,
'type' => 'log',
]
);
}
do_action( 'wpforms_pro_admin_entries_edit_setup', $this );
}
/**
* Edit button in Entry Details metabox on the single entry view page.
*
* @since 1.6.0
*
* @param object $entry Submitted entry values.
* @param array $form_data Form data and settings.
*/
public function display_edit_button( $entry, $form_data ) {
if ( ! isset( $form_data['id'] ) || ! isset( $entry->entry_id ) ) {
return;
}
if ( ! wpforms_current_user_can( 'edit_entries_form_single', $form_data['id'] ) || ! wpforms()->get( 'entry' )->has_editable_fields( $entry ) ) {
return;
}
// Edit Entry URL.
$edit_url = add_query_arg(
[
'page' => 'wpforms-entries',
'view' => 'edit',
'entry_id' => $entry->entry_id,
],
admin_url( 'admin.php' )
);
printf(
'
',
esc_url( $edit_url ),
esc_html__( 'Edit', 'wpforms' )
);
}
/**
* Entry Edit page.
*
* @since 1.6.0
*/
public function display_edit_page() {
if ( $this->abort ) {
return;
}
$entry = $this->entry;
$form_data = $this->form_data;
$form_id = ! empty( $form_data['id'] ) ? (int) $form_data['id'] : 0;
$view_entry_url = add_query_arg(
[
'page' => 'wpforms-entries',
'view' => 'details',
'entry_id' => $entry->entry_id,
],
admin_url( 'admin.php' )
);
$form_atts = [
'id' => 'wpforms-edit-entry-form',
'class' => [ 'wpforms-form', 'wpforms-validate' ],
'data' => [
'formid' => $form_id,
],
'atts' => [
'method' => 'POST',
'enctype' => 'multipart/form-data',
'action' => esc_url_raw( remove_query_arg( 'wpforms' ) ),
],
];
?>
abort ) {
return;
}
?>
';
echo ! wpforms_is_empty_string( $field_value ) ?
nl2br( make_clickable( $field_value ) ) : // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_html__( 'Empty', 'wpforms' );
echo '
';
}
/**
* Display a message about no fields in a form.
*
* @since 1.6.0.2
*/
private function display_edit_form_field_no_fields() {
echo '';
if ( \wpforms_current_user_can( 'edit_form_single', $this->form_data['id'] ) ) {
$edit_url = add_query_arg(
array(
'page' => 'wpforms-builder',
'view' => 'fields',
'form_id' => absint( $this->form_data['id'] ),
),
admin_url( 'admin.php' )
);
printf(
wp_kses( /* translators: %s - form edit URL. */
__( 'You don\'t have any fields in this form. Add some!', 'wpforms' ),
[
'a' => [
'href' => [],
],
]
),
esc_url( $edit_url )
);
} else {
esc_html_e( 'You don\'t have any fields in this form.', 'wpforms' );
}
echo '
';
}
/**
* Add Update Button to Entry Meta Details metabox actions.
*
* @since 1.6.0
*
* @param object $entry Entry data.
* @param array $form_data Form data.
*/
public function update_button( $entry, $form_data ) {
printf(
'