esc_html__( 'Mark as Read', 'wpforms' ),
'unread' => esc_html__( 'Mark as Unread', 'wpforms' ),
'star' => esc_html__( 'Star', 'wpforms' ),
'unstar' => esc_html__( 'Unstar', 'wpforms' ),
'print' => esc_html__( 'Print', 'wpforms' ),
];
$bulk_actions = $this->get_addtional_bulk_actions( $bulk_actions );
/**
* Filters bulk actions.
*
* @since 1.8.3
*
* @param array $bulk_actions Bulk actions.
*
* @return array
*/
return apply_filters( 'wpforms_entries_table_get_bulk_actions', $bulk_actions ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
}
/**
* Define additional bulk actions available for our table listing.
* Additional settings are all related to the delete/restore action.
*
* @since 1.8.5
*
* @param array $bulk_actions Bulk actions.
*
* @return array
*/
private function get_addtional_bulk_actions( $bulk_actions ) {
if ( ! wpforms_current_user_can( 'delete_entries_form_single', $this->form_id ) ) {
return $bulk_actions;
}
$bulk_actions['null'] = esc_html__( '----------', 'wpforms' );
if ( wpforms()->obj( 'spam_entry' )->is_spam_list() ) {
$bulk_actions['unspam'] = esc_html__( 'Mark as Not Spam', 'wpforms' );
} else {
$bulk_actions['spam'] = esc_html__( 'Mark as Spam', 'wpforms' );
}
if ( $this->is_trash_list() ) {
$bulk_actions['restore'] = esc_html__( 'Restore', 'wpforms' );
} else {
$bulk_actions['trash'] = esc_html__( 'Move to Trash', 'wpforms' );
}
$bulk_actions['delete'] = esc_html__( 'Delete', 'wpforms' );
return $bulk_actions;
}
/**
* Process the bulk actions.
*
* @since 1.8.6
*/
public function process_bulk_actions() {
$this->display_bulk_action_message();
if ( empty( $_REQUEST['_wpnonce'] ) ) {
return;
}
if (
! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'bulk-entries' ) &&
! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'bulk-entries-nonce' )
) {
return;
}
$this->process_bulk_action_single();
}
/**
* Process single bulk action.
*
* @since 1.8.6
*/
protected function process_bulk_action_single() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
$doaction = $this->current_action();
$status = '';
if ( empty( $doaction ) || $doaction === 'filter_date' ) {
return;
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended
$ids = isset( $_GET['entry_id'] ) ? wp_unslash( $_GET['entry_id'] ) : false;
if ( ! is_array( $ids ) ) {
$ids = [ $ids ];
}
$ids = array_map( 'absint', $ids );
if ( empty( $ids ) ) {
return;
}
// Check if it is a Trash list.
if ( $this->is_trash_list() ) {
$status = Page::TRASH_ENTRY_STATUS;
}
$spam_entry = wpforms()->obj( 'spam_entry' );
// Check if it is a Spam list.
if ( $spam_entry->is_spam_list() ) {
$status = $spam_entry::ENTRY_STATUS;
}
$args = [
'entry_id' => $ids,
'is_filtered' => true,
'number' => $this->get_items_per_page( 'wpforms_entries_per_page', $this->per_page ),
'status' => $status,
];
// Get entries, that would be affected.
$entries_list = wpforms()->obj( 'entry' )->get_entries( $args );
/**
* Filter entries list.
*
* @since 1.8.3
*
* @param array $entries_list List of entries.
* @param array $args Arguments.
*/
$entries_list = apply_filters( 'wpforms_entries_table_process_actions_entries_list', $entries_list, $args ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
$sendback = remove_query_arg( [ 'read', 'unread', 'spam', 'unspam', 'starred', 'unstarred', 'print', 'deleted', 'trashed', 'restored', 'paged' ], wp_get_referer() );
switch ( $doaction ) {
// Mark as read.
case 'read':
$sendback = $this->process_bulk_action_single_read( $entries_list, $ids, $sendback );
break;
// Mark as unread.
case 'unread':
$sendback = $this->process_bulk_action_single_unread( $entries_list, $ids, $sendback );
break;
// Star entry.
case 'star':
$sendback = $this->process_bulk_action_single_star( $entries_list, $ids, $sendback );
break;
// Unstar entry.
case 'unstar':
$sendback = $this->process_bulk_action_single_unstar( $entries_list, $ids, $sendback );
break;
// Print entries.
case 'print':
$this->process_bulk_action_single_print( $ids );
break;
// Trash entries.
case 'trash':
$sendback = $this->process_bulk_action_single_trash( $ids, $sendback );
break;
// Delete entries.
case 'delete':
$sendback = $this->process_bulk_action_single_delete( $ids, $sendback );
break;
// Restore entries.
case 'restore':
$sendback = $this->process_bulk_action_single_restore( $ids, $sendback );
break;
// Mark as Spam.
case 'spam':
$sendback = $this->process_bulk_action_single_spam( $entries_list, $ids, $sendback );
break;
// Mark as Not Spam.
case 'unspam':
$sendback = $this->process_bulk_action_single_unspam( $entries_list, $ids, $sendback );
break;
}
$sendback = remove_query_arg( [ 'action', 'action2', 'entry_id' ], $sendback );
wp_safe_redirect( $sendback );
exit();
}
/**
* Process the bulk action read.
*
* @since 1.5.7
*
* @param array $entries_list Filtered entries list.
* @param array $ids IDs to process.
* @param string $sendback URL query string.
*
* @return string
*/
protected function process_bulk_action_single_read( $entries_list, $ids, $sendback ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false;
if ( empty( $form_id ) ) {
return $sendback;
}
$user_id = get_current_user_id();
$entries = wp_list_pluck( $entries_list, 'viewed', 'entry_id' );
$read = 0;
foreach ( $ids as $id ) {
if ( ! array_key_exists( $id, $entries ) ) {
continue;
}
if ( $entries[ $id ] === '1' ) {
continue;
}
$success = wpforms()->obj( 'entry' )->update(
$id,
[
'viewed' => '1',
]
);
if ( $success ) {
wpforms()->obj( 'entry_meta' )->add(
[
'entry_id' => $id,
'form_id' => $form_id,
'user_id' => $user_id,
'type' => 'log',
'data' => wpautop( sprintf( '%s', esc_html__( 'Entry read.', 'wpforms' ) ) ),
],
'entry_meta'
);
++$read;
}
}
return add_query_arg( 'read', $read, $sendback );
}
/**
* Process the bulk action unread.
*
* @since 1.8.6
*
* @param array $entries_list Filtered entries list.
* @param array $ids IDs to process.
* @param string $sendback URL query string.
*
* @return string
*/
protected function process_bulk_action_single_unread( $entries_list, $ids, $sendback ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false;
if ( empty( $form_id ) ) {
return $sendback;
}
$user_id = get_current_user_id();
$entries = wp_list_pluck( $entries_list, 'viewed', 'entry_id' );
$unread = 0;
foreach ( $ids as $id ) {
if ( ! array_key_exists( $id, $entries ) ) {
continue;
}
if ( $entries[ $id ] === '0' ) {
continue;
}
$success = wpforms()->obj( 'entry' )->update(
$id,
[
'viewed' => '0',
]
);
if ( $success ) {
wpforms()->obj( 'entry_meta' )->add(
[
'entry_id' => $id,
'form_id' => $form_id,
'user_id' => $user_id,
'type' => 'log',
'data' => wpautop( sprintf( '%s', esc_html__( 'Entry unread.', 'wpforms' ) ) ),
],
'entry_meta'
);
++$unread;
}
}
return add_query_arg( 'unread', $unread, $sendback );
}
/**
* Process the bulk action spam.
*
* @since 1.8.9
*
* @param array $entries_list Filtered entries list.
* @param array $ids IDs to process.
* @param string $sendback URL query string.
*/
protected function process_bulk_action_single_spam( $entries_list, $ids, $sendback ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false;
if ( empty( $form_id ) ) {
return $sendback;
}
$user = get_user_by( 'id', get_current_user_id() );
$entries = wp_list_pluck( $entries_list, 'status', 'entry_id' );
$spam_entry = wpforms()->obj( 'spam_entry' );
$spam = 0;
foreach ( $ids as $id ) {
if ( ! array_key_exists( $id, $entries ) ) {
continue;
}
if ( $entries[ $id ] === $spam_entry::ENTRY_STATUS ) {
continue;
}
$spam_entry->set_as_spam( $id, $form_id, $user->display_name );
++$spam;
}
return add_query_arg( 'spam', $spam, $sendback );
}
/**
* Process the bulk action unspam.
*
* @since 1.8.9
*
* @param array $entries_list Filtered entries list.
* @param array $ids IDs to process.
* @param string $sendback URL query string.
*
* @return string
*/
protected function process_bulk_action_single_unspam( $entries_list, $ids, $sendback ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false;
if ( empty( $form_id ) ) {
return $sendback;
}
$entries = wp_list_pluck( $entries_list, 'status', 'entry_id' );
$spam_entry = wpforms()->obj( 'spam_entry' );
$unspam = 0;
foreach ( $ids as $id ) {
if ( ! array_key_exists( $id, $entries ) ) {
continue;
}
if ( $entries[ $id ] !== $spam_entry::ENTRY_STATUS ) {
continue;
}
$entry = wpforms()->obj( 'entry' )->get( $id );
$spam_entry->set_as_not_spam( $entry );
++$unspam;
}
return add_query_arg( 'unspam', $unspam, $sendback );
}
/**
* Process the bulk action star.
*
* @since 1.8.6
*
* @param array $entries_list Filtered entries list.
* @param array $ids IDs to process.
* @param string $sendback URL query string.
*
* @return string
*/
protected function process_bulk_action_single_star( $entries_list, $ids, $sendback ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity
$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( empty( $form_id ) ) {
return $sendback;
}
$user_id = get_current_user_id();
$entries = wp_list_pluck( $entries_list, 'starred', 'entry_id' );
$starred = 0;
foreach ( $ids as $id ) {
if ( ! array_key_exists( $id, $entries ) ) {
continue;
}
if ( $entries[ $id ] === '1' ) {
continue;
}
$success = wpforms()->obj( 'entry' )->update(
$id,
[
'starred' => '1',
]
);
if ( $success ) {
wpforms()->obj( 'entry_meta' )->add(
[
'entry_id' => $id,
'form_id' => $form_id,
'user_id' => $user_id,
'type' => 'log',
'data' => wpautop( sprintf( '%s', esc_html__( 'Entry starred.', 'wpforms' ) ) ),
],
'entry_meta'
);
++$starred;
}
}
return add_query_arg( 'starred', $starred, $sendback );
}
/**
* Process the bulk action unstar.
*
* @since 1.8.6
*
* @param array $entries_list Filtered entries list.
* @param array $ids IDs to process.
* @param string $sendback URL query string.
*
* @return string
*/
protected function process_bulk_action_single_unstar( $entries_list, $ids, $sendback ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false;
if ( empty( $form_id ) ) {
return $sendback;
}
$user_id = get_current_user_id();
$entries = wp_list_pluck( $entries_list, 'starred', 'entry_id' );
$unstarred = 0;
foreach ( $ids as $id ) {
if ( ! array_key_exists( $id, $entries ) ) {
continue;
}
if ( $entries[ $id ] === '0' ) {
continue;
}
$success = wpforms()->obj( 'entry' )->update(
$id,
[
'starred' => '0',
]
);
if ( $success ) {
wpforms()->obj( 'entry_meta' )->add(
[
'entry_id' => $id,
'form_id' => $form_id,
'user_id' => $user_id,
'type' => 'log',
'data' => wpautop( sprintf( '%s', esc_html__( 'Entry unstarred.', 'wpforms' ) ) ),
],
'entry_meta'
);
++$unstarred;
}
}
return add_query_arg( 'unstarred', $unstarred, $sendback );
}
/**
* Process the bulk action print.
*
* @since 1.8.6
*
* @param array $ids IDs to process.
*
* @return void
*/
private function process_bulk_action_single_print( $ids ) {
$print_url = add_query_arg(
[
'page' => 'wpforms-entries',
'view' => 'print',
'entry_id' => implode( ',', $ids ),
],
admin_url( 'admin.php' )
);
wp_safe_redirect( $print_url );
exit();
}
/**
* Process the bulk delete action.
*
* @since 1.8.5
*
* @param array $ids IDs to process.
* @param string $sendback URL query string.
*
* @return string
*/
private function process_bulk_action_single_trash( $ids, $sendback ) {
$trashed = 0;
$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$user_id = get_current_user_id();
foreach ( $ids as $id ) {
// Get the entry first.
$entry = wpforms()->obj( 'entry' )->get( $id );
if ( ! $entry ) {
continue;
}
$status = $entry->status;
/**
* TODO :: After the support for PHP 7 ends,
* we can update the following code to use named arguments and skip the optional params.
*/
$success = wpforms()->obj( 'entry' )->update(
$id,
[ 'status' => Page::TRASH_ENTRY_STATUS ],
'',
'',
[ 'cap' => 'delete_entry_single' ] // Force the cap to trash the entry, since we cant provide edit cap here.
);
// If it didn't work, continue.
if ( ! $success ) {
continue;
}
if ( $status !== '' ) {
wpforms()->obj( 'entry_meta' )->add(
[
'entry_id' => $id,
'form_id' => $form_id,
'user_id' => $user_id,
'type' => 'status_prev',
'data' => '',
'status' => $status,
],
'entry_meta'
);
}
++$trashed;
}
// If trashed entries are more than 1, then clear widget cache.
if ( $trashed >= 1 ) {
DashboardWidget::clear_widget_cache();
}
return add_query_arg(
[
'trashed' => $trashed,
'view' => 'list', // force the list view to make sure we go to the right page.
'form_id' => $form_id,
],
$sendback
);
}
/**
* Process the bulk action restores.
*
* @since 1.8.5
*
* @param array $ids IDs to process.
* @param string $sendback URL query string.
*
* @return string
*/
private function process_bulk_action_single_restore( $ids, $sendback ) {
$restored = 0;
foreach ( $ids as $id ) {
// Reset or set initial status.
$status = '';
// Get the entry first.
$entry = wpforms()->obj( 'entry' )->get( $id );
if ( ! $entry ) {
continue;
}
$meta = wpforms()->obj( 'entry_meta' )->get_meta(
[
'entry_id' => $id,
'type' => 'status_prev',
]
);
// check meta for status log to restore the status.
if ( $meta ) {
$status = $meta[0]->status;
// After taking status from meta, delete the meta.
wpforms()->obj( 'entry_meta' )->delete_by( 'id', $meta[0]->id );
}
/**
* TODO :: After the support for PHP 7 ends,
* we can update the following code to use named arguments and skip the optional params.
*/
$success = wpforms()->obj( 'entry' )->update(
$id,
[ 'status' => $status ],
'',
'',
[ 'cap' => 'delete_entry_single' ] // Force the cap to trash the entry, since we cant provide edit cap here.
);
// If it didn't work, continue.
if ( ! $success ) {
continue;
}
++$restored;
}
$trash_count = wpforms()->obj( 'entry' )->get_entries(
[
'form_id' => $this->form_id,
'status' => Page::TRASH_ENTRY_STATUS,
],
true
);
// If trash is emptied.
if ( $trash_count < 1 ) {
$sendback = remove_query_arg( 'status', $sendback );
}
// If restored entries are more than 1, then clear widget cache.
if ( $restored >= 1 ) {
DashboardWidget::clear_widget_cache();
}
return add_query_arg( 'restored', $restored, $sendback );
}
/**
* Process the bulk delete action.
*
* @since 1.8.6
*
* @param array $ids IDs to process.
* @param string $sendback URL query string.
*
* @return string
*/
protected function process_bulk_action_single_delete( $ids, $sendback ) {
$deleted = 0;
$form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
foreach ( $ids as $id ) {
if ( wpforms()->obj( 'entry' )->delete( $id ) ) {
++$deleted;
}
}
return add_query_arg(
[
'deleted' => $deleted,
'view' => 'list', // force the list view to make sure we go to the right page.
'form_id' => $form_id,
],
$sendback
);
}
/**
* Display a bulk action result message.
*
* @since 1.8.6
*/
protected function display_bulk_action_message() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$bulk_counts = [
'read' => isset( $_REQUEST['read'] ) ? absint( $_REQUEST['read'] ) : 0,
'unread' => isset( $_REQUEST['unread'] ) ? absint( $_REQUEST['unread'] ) : 0,
'spam' => isset( $_REQUEST['spam'] ) ? absint( $_REQUEST['spam'] ) : 0,
'unspam' => isset( $_REQUEST['unspam'] ) ? absint( $_REQUEST['unspam'] ) : 0,
'starred' => isset( $_REQUEST['starred'] ) ? absint( $_REQUEST['starred'] ) : 0,
'unstarred' => isset( $_REQUEST['unstarred'] ) ? absint( $_REQUEST['unstarred'] ) : 0,
'deleted' => isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0,
'trashed' => isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0,
'restored' => isset( $_REQUEST['restored'] ) ? (int) $_REQUEST['restored'] : 0,
];
// phpcs:enable WordPress.Security.NonceVerification.Recommended
$bulk_messages = [
/* translators: %d - number of processed entries. */
'read' => _n( '%d entry was successfully marked as read.', '%d entries were successfully marked as read.', $bulk_counts['read'], 'wpforms' ),
/* translators: %d - number of processed entries. */
'unread' => _n( '%d entry was successfully marked as unread.', '%d entries were successfully marked as unread.', $bulk_counts['unread'], 'wpforms' ),
/* translators: %d - number of processed entries. */
'spam' => _n( '%d entry was successfully marked as spam.', '%d entries were successfully marked as spam.', $bulk_counts['spam'], 'wpforms' ),
/* translators: %d - number of processed entries. */
'unspam' => _n( '%d entry was successfully marked as not spam.', '%d entries were successfully marked as not spam.', $bulk_counts['unspam'], 'wpforms' ),
/* translators: %d - number of processed entries. */
'starred' => _n( '%d entry was successfully starred.', '%d entries were successfully starred.', $bulk_counts['starred'], 'wpforms' ),
/* translators: %d - number of processed entries. */
'unstarred' => _n( '%d entry was successfully unstarred.', '%d entries were successfully unstarred.', $bulk_counts['unstarred'], 'wpforms' ),
/* translators: %d - number of processed entries. */
'deleted' => _n( '%d entry was successfully deleted.', '%d entries were successfully deleted.', $bulk_counts['deleted'], 'wpforms' ),
/* translators: %d - number of processed entries. */
'trashed' => _n( '%d entry was successfully trashed.', '%d entries were successfully trashed.', $bulk_counts['trashed'], 'wpforms' ),
/* translators: %d - number of processed entries. */
'restored' => _n( '%d entry was successfully restored.', '%d entries were successfully restored.', $bulk_counts['restored'], 'wpforms' ),
];
if ( $bulk_counts['deleted'] === -1 ) {
$bulk_messages['deleted'] = esc_html__( 'All entries for the currently selected form were successfully deleted.', 'wpforms' );
}
if ( $bulk_counts['trashed'] === -1 ) {
$bulk_messages['trashed'] = esc_html__( 'All entries for the currently selected form were successfully trashed.', 'wpforms' );
}
// Leave only non-zero counts, so only those that were processed are left.
$bulk_counts = array_filter( $bulk_counts );
// If we have bulk messages to display.
$messages = [];
foreach ( $bulk_counts as $type => $count ) {
if ( isset( $bulk_messages[ $type ] ) ) {
$messages[] = sprintf( $bulk_messages[ $type ], $count );
}
}
if ( $messages ) {
Notice::success( implode( ' ', array_map( 'esc_html', $messages ) ) );
}
}
/**
* Message to be displayed when there are no entries.
*
* @since 1.8.6
*/
public function no_items() {
printf(
'
%1$s
',
esc_html__( 'No entries found.', 'wpforms' )
);
}
/**
* Entries list form search.
*
* @since 1.8.6
*
* @param string $text The 'submit' button label.
* @param string $input_id ID attribute value for the search input field.
*/
public function search_box( $text, $input_id ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity
$input_id .= '-search-input';
/**
* Fires before output the search box on the Entries list page.
*
* @since 1.4.4
*
* @param array $forms_data Form data.
*/
do_action( 'wpforms_entries_list_form_filters_before', $this->form_data ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
$filter_fields = [];
if ( ! empty( $this->form_data['fields'] ) ) {
foreach ( $this->form_data['fields'] as $id => $field ) {
if ( in_array( $field['type'], self::get_columns_form_disallowed_fields(), true ) ) {
continue;
}
$filter_fields[ $id ] = ! empty( $field['label'] ) ? wp_strip_all_tags( $field['label'] ) : esc_html__( 'Field', 'wpforms' );
}
}
/**
* Filters fields displayed in the search box.
*
* @since 1.5.5.1
*
* @param array $fields Search box fields.
* @param ListTable $fields Instance of the ListTable class.
*
* @return array
*/
$filter_fields = (array) apply_filters( 'wpforms_entries_list_form_filters_search_fields', $filter_fields, $this ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
$cur_field = 'any';
// phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['search']['field'] ) ) {
if ( is_numeric( $_GET['search']['field'] ) ) {
$cur_field = (int) $_GET['search']['field'];
} else {
$cur_field = sanitize_key( $_GET['search']['field'] );
}
}
$advanced_options = Helpers::get_search_fields_advanced_options();
$cur_comparison = ! empty( $_GET['search']['comparison'] ) ? sanitize_key( $_GET['search']['comparison'] ) : 'contains';
$cur_term = '';
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
if ( isset( $_GET['search']['term'] ) && ! wpforms_is_empty_string( $_GET['search']['term'] ) ) {
$cur_term = sanitize_text_field( wp_unslash( $_GET['search']['term'] ) );
$cur_term = empty( $cur_term ) ? htmlspecialchars( wp_unslash( $_GET['search']['term'] ) ) : $cur_term; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
$this->search_box_output( $text, $input_id, $filter_fields, $advanced_options, $cur_field, $cur_comparison, $cur_term );
/**
* Allows developers output some HTML after the filter forms on the entries' list page.
*
* @since 1.4.4
*
* @param array $form_data Form data.
*/
do_action( 'wpforms_entries_list_form_filters_after', $this->form_data ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
}
/**
* Entries list form search.
*
* @since 1.8.6
*
* @param string $text The 'submit' button label.
* @param string $input_id ID attribute value for the search input field.
* @param array $filter_fields Filter fields options.
* @param array $search_advanced_options Advanced options.
* @param mixed $cur_field Current (selected) field or advanced option.
* @param string $cur_comparison Current comparison.
* @param string $cur_term Current search term.
*
* @noinspection HtmlUnknownAttribute*/
private function search_box_output( $text, $input_id, $filter_fields, $search_advanced_options, $cur_field, $cur_comparison, $cur_term ) {
?>
>
get_counts();
// Set up the columns.
$columns = $this->get_columns();
// Hidden columns (none).
$hidden = [];
// Define which columns can be sorted.
$sortable = $this->get_sortable_columns();
// Get a primary column. It will be a 3rd column.
$primary = key( array_slice( $columns, 2, 1 ) );
// Set column headers.
$this->_column_headers = [ $columns, $hidden, $sortable, $primary ];
// Get entries.
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$total_items = $this->counts['total'];
$page = $this->get_pagenum();
$order = isset( $_GET['order'] ) ? sanitize_key( $_GET['order'] ) : 'DESC';
$orderby = isset( $_GET['orderby'] ) ? sanitize_key( $_GET['orderby'] ) : 'entry_id';
$per_page = $this->get_items_per_page( 'wpforms_entries_per_page', $this->per_page );
$data_args = [
'form_id' => $this->form_id,
'number' => $per_page,
'offset' => $per_page * ( $page - 1 ),
'order' => $order,
'orderby' => $orderby,
];
if ( ! empty( $_GET['type'] ) && $_GET['type'] === 'starred' ) {
$data_args['starred'] = '1';
$total_items = $this->counts['starred'];
}
if ( ! empty( $_GET['type'] ) && $_GET['type'] === 'unread' ) {
$data_args['viewed'] = '0';
$total_items = $this->counts['unread'];
}
if ( ! empty( $_GET['type'] ) && $_GET['type'] === 'payment' ) {
$data_args['type'] = 'payment';
$total_items = $this->counts['payment'];
}
if ( ! empty( $_GET['type'] ) && $_GET['type'] === 'imported' ) {
$data_args['type'] = 'imported';
$total_items = $this->counts['imported'];
}
if ( ! empty( $_GET['status'] ) ) {
$status = sanitize_text_field( $_GET['status'] ); // phpcs:ignore WordPress.Security
$total_items = ! empty( $this->counts[ $status ] ) ? $this->counts[ $status ] : 0;
$data_args['status'] = $status === 'published' ? [ '' ] : $status;
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
if ( array_key_exists( 'notes_count', $columns ) ) {
$data_args['notes_count'] = true;
}
// Reset the orderby if the parameter does not exist in columns.
if ( ! array_key_exists( $orderby, $columns ) ) {
$data_args['orderby'] = 'entry_id';
}
/**
* Filters get entries arguments array.
*
* @since 1.4.0
*
* @param array $args Arguments.
*
* @return array
*/
$data_args = apply_filters( 'wpforms_entry_table_args', $data_args ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
$data = wpforms()->obj( 'entry' )->get_entries( $data_args );
// Giddy up.
$this->items = $data;
// Finalize pagination.
$this->set_pagination_args(
[
'total_items' => $total_items,
'total_pages' => (int) ceil( $total_items / $per_page ),
'per_page' => $per_page,
]
);
}
/**
* Extending the `display_rows()` method to add hooks.
*
* @since 1.8.6
*/
public function display_rows() {
/**
* Fires before displaying the table rows.
*
* @since 1.5.6.2
*
* @param ListTable $list_table_obj ListTable instance.
*/
do_action( 'wpforms_admin_entries_before_rows', $this ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
parent::display_rows();
/**
* Fires after displaying the table rows.
*
* @since 1.5.6.2
*
* @param ListTable $list_table_obj ListTable instance.
*/
do_action( 'wpforms_admin_entries_after_rows', $this ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
}
/**
* Truncate long text value to X lines and Y characters.
*
* @since 1.8.6
*
* @param string $value The value to truncate, if needed.
* @param string $field_type Field type.
*
* @return string
*/
private function truncate_long_value( $value, $field_type ) {
// Limit multiline text to 4 lines, 5 for Address field, and overall length to 75 characters.
$lines_limit = $field_type === 'address' ? 5 : 4;
$chars_limit = 75;
// Decode HTML entities to avoid truncating on € and similar.
$value = html_entity_decode( $value, ENT_COMPAT, 'UTF-8' );
$lines = preg_split( '/\r\n|\r|\n/', $value );
$value = array_slice( $lines, 0, $lines_limit );
$value = implode( PHP_EOL, $value );
// Encode HTML entities back to prevent XSS.
$value = htmlentities( $value, ENT_COMPAT, 'UTF-8' );
if ( strlen( $value ) > $chars_limit ) {
return mb_substr( $value, 0, $chars_limit ) . '…';
}
// Ellipsis should be on a new line if the value is multiline, and extra lines were truncated.
if ( count( $lines ) > $lines_limit ) {
return $value . PHP_EOL . '…';
}
return $value;
}
/**
* Returns payment status label, slug and payment object by given entry ID.
* The returned data includes:
* - label: payment status label.
* - slug: payment status slug.
* - payment: payment object.
*
* @since 1.8.6
*
* @param int $entry_id Entry ID.
*
* @return array
*/
private function get_payment_status_by_entry_id( $entry_id ) {
// Get payment data.
$payment = wpforms()->obj( 'payment' )->get_by( 'entry_id', $entry_id );
// If payment data is not found, return N/A.
if ( ! $payment ) {
return [
__( 'N/A', 'wpforms' ),
'n-a',
null,
];
}
$allowed_statuses = ValueValidator::get_allowed_statuses();
$payment_status = ! empty( $payment->subscription_id ) ? $payment->subscription_status : $payment->status;
$status_slug = ! empty( $payment_status ) ? $payment_status : 'n-a';
$status_label = $allowed_statuses[ $payment_status ] ?? __( 'N/A', 'wpforms' );
return [ $status_label, $status_slug, $payment ];
}
/**
* Check the status of entries to check if they are trashable.
*
* @since 1.8.5
*
* @param int $entry_id Entry id to check.
*
* @return boolean
*/
private function should_delete( $entry_id ) {
$entry = wpforms()->obj( 'entry' )->get( $entry_id );
if ( ! $entry ) {
return false;
}
return $entry->status === Page::TRASH_ENTRY_STATUS;
}
/**
* Check if the current page is a trash list.
*
* @since 1.8.5
*
* @return bool
*/
public function is_trash_list(): bool {
$status = isset( $_GET['status'] ) ? sanitize_key( $_GET['status'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return $status === Page::TRASH_ENTRY_STATUS;
}
/**
* Displays the table.
*
* @since 1.8.6
*/
public function display() {
$singular = $this->_args['singular'];
$this->display_tablenav( 'top' );
$this->screen->render_screen_reader_content( 'heading_list' );
?>
print_table_description(); ?>
print_column_headers(); ?>
>
display_rows_or_placeholder(); ?>
print_column_headers( false ); ?>
display_tablenav( 'bottom' );
}
/**
* Print column headers but without the `actions` column if this is bottom table header.
*
* @since 1.8.6
*
* @param bool $with_id Whether to print the `
` element with an `id` attribute.
*/
public function print_column_headers( $with_id = true ) {
if ( $with_id ) {
parent::print_column_headers();
} else {
$column_headers = $this->_column_headers[0];
if ( isset( $column_headers['actions'] ) ) {
$column_headers['actions'] = esc_html__( 'Actions', 'wpforms' );
$this->_column_headers[0] = $column_headers;
}
parent::print_column_headers( false );
}
}
}