builder
1 month ago
form-migrator
1 month ago
plugin-updates
8 years ago
settings
1 month ago
views
1 month ago
class-evf-admin-addons.php
4 months ago
class-evf-admin-assets.php
2 weeks ago
class-evf-admin-builder.php
2 months ago
class-evf-admin-dashboard.php
1 month ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-embed-wizard.php
2 years ago
class-evf-admin-entries-table-list.php
2 months ago
class-evf-admin-entries.php
2 months ago
class-evf-admin-form-templates.php
1 month ago
class-evf-admin-forms-table-list.php
4 months ago
class-evf-admin-forms.php
4 months ago
class-evf-admin-import-export.php
1 month ago
class-evf-admin-menus.php
1 month ago
class-evf-admin-notices.php
4 months ago
class-evf-admin-preview-confirmation.php
1 year ago
class-evf-admin-settings.php
1 month ago
class-evf-admin-tools.php
2 months ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 months ago
class-evf-base-list-table.php
4 months ago
evf-admin-functions.php
1 month ago
class-evf-admin-entries-table-list.php
1233 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Entries Table List |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @since 1.1.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | if ( ! class_exists( 'EVF_Base_List_Table' ) ) { |
| 12 | require_once __DIR__ . '/class-evf-base-list-table.php'; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Entries table list class. |
| 17 | */ |
| 18 | class EVF_Admin_Entries_Table_List extends EVF_Base_List_Table { |
| 19 | |
| 20 | /** |
| 21 | * Form ID. |
| 22 | * |
| 23 | * @var int |
| 24 | */ |
| 25 | public $form_id; |
| 26 | |
| 27 | /** |
| 28 | * Forms object. |
| 29 | * |
| 30 | * @var EVF_Form_Handler |
| 31 | */ |
| 32 | public $form; |
| 33 | |
| 34 | /** |
| 35 | * Forms object. |
| 36 | * |
| 37 | * @var EVF_Form_Handler[] |
| 38 | */ |
| 39 | public $forms; |
| 40 | |
| 41 | /** |
| 42 | * Form data as an array. |
| 43 | * |
| 44 | * @var array |
| 45 | */ |
| 46 | public $form_data; |
| 47 | |
| 48 | /** |
| 49 | * Initialize the log table list. |
| 50 | */ |
| 51 | public function __construct() { |
| 52 | $this->forms = evf_get_all_forms( true ); |
| 53 | if ( ! empty( $this->forms ) ) { |
| 54 | $this->form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification |
| 55 | |
| 56 | $default_form_id = apply_filters( 'everest_forms_entry_list_default_form_id', key( $this->forms ) ); |
| 57 | $active_form_id = ( $this->form_id > 0 ) ? $this->form_id : $default_form_id; |
| 58 | |
| 59 | $this->form = evf()->form->get( $active_form_id ); |
| 60 | $this->form_data = ! empty( $this->form->post_content ) ? evf_decode( $this->form->post_content ) : ''; |
| 61 | } |
| 62 | |
| 63 | parent::__construct( |
| 64 | array( |
| 65 | 'singular' => 'entry', |
| 66 | 'plural' => 'entries', |
| 67 | 'ajax' => false, |
| 68 | ) |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get the current action selected from the bulk actions dropdown. |
| 74 | * |
| 75 | * @since 1.5.3 |
| 76 | * |
| 77 | * @return string|false The action name or False if no action was selected. |
| 78 | */ |
| 79 | public function current_action() { |
| 80 | if ( isset( $_REQUEST['export_action'] ) && ! empty( $_REQUEST['export_action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 85 | return 'delete_all'; |
| 86 | } |
| 87 | |
| 88 | return parent::current_action(); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * No items found text. |
| 93 | */ |
| 94 | public function no_items() { |
| 95 | esc_html_e( 'Whoops, it appears you do not have any form entries yet.', 'everest-forms' ); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Get list columns. |
| 100 | * |
| 101 | * @return array |
| 102 | */ |
| 103 | public function get_columns() { |
| 104 | $columns = array(); |
| 105 | $columns['cb'] = '<input type="checkbox" />'; |
| 106 | $columns = apply_filters( 'everest_forms_add_extra_columns', $columns ); |
| 107 | |
| 108 | if ( 0 === $this->form_id ) { |
| 109 | $columns['entry'] = esc_html__( 'Entry', 'everest-forms' ); |
| 110 | $columns['form'] = esc_html__( 'Form', 'everest-forms' ); |
| 111 | $columns['date'] = esc_html__( 'Date Created', 'everest-forms' ); |
| 112 | } else { |
| 113 | $columns = apply_filters( 'everest_forms_entries_table_form_fields_columns', $this->get_columns_form_fields( $columns ), $this->form_id, $this->form_data ); |
| 114 | $columns['date'] = esc_html__( 'Date Created', 'everest-forms' ); |
| 115 | } |
| 116 | |
| 117 | return apply_filters( 'everest_forms_entries_table_columns', $columns, $this->form_data ); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Get a list of sortable columns. |
| 122 | * |
| 123 | * @return array |
| 124 | */ |
| 125 | protected function get_sortable_columns() { |
| 126 | $sortable_columns = array(); |
| 127 | |
| 128 | if ( isset( $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 129 | $sortable_columns = array( |
| 130 | 'date' => array( 'date_created', false ), |
| 131 | ); |
| 132 | } |
| 133 | |
| 134 | return $sortable_columns; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Generates content for a single row of the table. |
| 139 | * |
| 140 | * @since 1.6.0 |
| 141 | * |
| 142 | * @param object $entry Entry data. |
| 143 | */ |
| 144 | public function single_row( $entry ) { |
| 145 | if ( empty( $_GET['status'] ) || ( isset( $_GET['status'] ) && 'trash' !== $_GET['status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 146 | echo '<tr class="' . ( $entry->viewed ? 'read' : 'unread' ) . '">'; |
| 147 | $this->single_row_columns( $entry ); |
| 148 | echo '</tr>'; |
| 149 | } else { |
| 150 | parent::single_row( $entry ); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Get the list of fields, that are disallowed to be displayed as column in a table. |
| 156 | * |
| 157 | * @return array |
| 158 | */ |
| 159 | public static function get_columns_form_disallowed_fields() { |
| 160 | return (array) apply_filters( 'everest_forms_entries_table_fields_disallow', array( 'html', 'title', 'captcha', 'repeater-fields', 'authorize-net', 'private-note' ) ); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Logic to determine which fields are displayed in the table columns. |
| 165 | * |
| 166 | * @param array $columns List of colums. |
| 167 | * @param int $display Numbers of columns to display. |
| 168 | * |
| 169 | * @return array |
| 170 | */ |
| 171 | public function get_columns_form_fields( $columns = array(), $display = 3 ) { |
| 172 | $entry_columns = evf()->form->get_meta( $this->form_id, 'entry_columns' ); |
| 173 | |
| 174 | if ( ! $entry_columns && ! empty( $this->form_data['form_fields'] ) ) { |
| 175 | $x = 0; |
| 176 | foreach ( $this->form_data['form_fields'] as $id => $field ) { |
| 177 | if ( ! in_array( $field['type'], self::get_columns_form_disallowed_fields(), true ) && $x < $display ) { |
| 178 | $columns[ 'evf_field_' . $id ] = ! empty( $field['label'] ) ? wp_strip_all_tags( $field['label'] ) : esc_html__( 'Field', 'everest-forms' ); |
| 179 | ++$x; |
| 180 | } |
| 181 | } |
| 182 | } elseif ( ! empty( $entry_columns ) ) { |
| 183 | $key = array_search( 'sn', $entry_columns, true ); |
| 184 | if ( false !== $key ) { |
| 185 | unset( $entry_columns[ $key ] ); |
| 186 | $entry_columns = array_merge( array( 'sn' ), $entry_columns ); |
| 187 | } |
| 188 | |
| 189 | $key = array_search( 'id', $entry_columns, true ); |
| 190 | if ( false !== $key ) { |
| 191 | unset( $entry_columns[ $key ] ); |
| 192 | $entry_columns = array_merge( array( 'id' ), $entry_columns ); |
| 193 | } |
| 194 | foreach ( $entry_columns as $id ) { |
| 195 | // Check to make sure the field as not been removed. |
| 196 | $status = defined( 'EFP_VERSION' ) ? true : false; |
| 197 | $status = apply_filters( 'everest_forms_plugin_active_status', $status ); |
| 198 | if ( empty( $this->form_data['form_fields'][ $id ] ) ) { |
| 199 | if ( $status ) { |
| 200 | if ( 'sn' === $id ) { |
| 201 | $extra_column = apply_filters( 'everest_forms_entries_table_extra_columns', array(), 0, array() ); |
| 202 | $columns = array_merge( $columns, $extra_column ); |
| 203 | } |
| 204 | if ( 'id' === $id ) { |
| 205 | $extra_column = apply_filters( 'everest_forms_entries_table_extra_columns_id', array(), 0, array() ); |
| 206 | $columns = array_merge( $columns, $extra_column ); |
| 207 | } |
| 208 | } |
| 209 | continue; |
| 210 | } |
| 211 | |
| 212 | $columns[ 'evf_field_' . $id ] = ! empty( $this->form_data['form_fields'][ $id ]['label'] ) ? wp_strip_all_tags( $this->form_data['form_fields'][ $id ]['label'] ) : esc_html__( 'Field', 'everest-forms' ); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return apply_filters( 'everest_forms_entries_table_form_field_columns', $columns, $this->form_id, $this->form_data ); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Column cb. |
| 221 | * |
| 222 | * @param object $entry Entry object. |
| 223 | * @return string |
| 224 | */ |
| 225 | public function column_cb( $entry ) { |
| 226 | return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $entry->entry_id ); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Column for simplified "Entry" view (All Forms only) |
| 231 | * |
| 232 | * @param object $entry Entry object. |
| 233 | * @return string |
| 234 | */ |
| 235 | public function column_entry( $entry ) { |
| 236 | if ( empty( $entry->meta ) ) { |
| 237 | return '<span class="na">—</span>'; |
| 238 | } |
| 239 | |
| 240 | // Skip system fields |
| 241 | $skip_fields = array( 'entry_id', 'form_id', 'user_id', 'user_device', 'user_ip_address', 'viewed', 'starred', 'status' ); |
| 242 | |
| 243 | // Find first non-empty field value |
| 244 | foreach ( $entry->meta as $key => $value ) { |
| 245 | if ( in_array( $key, $skip_fields, true ) || strpos( $key, '_' ) === 0 ) { |
| 246 | continue; |
| 247 | } |
| 248 | |
| 249 | // Process the value |
| 250 | $field_value = $this->process_field_value( $value ); |
| 251 | |
| 252 | if ( ! empty( $field_value ) && '—' !== $field_value ) { |
| 253 | return $field_value; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | return '<span class="na">—</span>'; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Column for form name (All Forms view only) |
| 262 | * |
| 263 | * @param object $entry Entry object. |
| 264 | * @return string |
| 265 | */ |
| 266 | public function column_form( $entry ) { |
| 267 | $form_title = get_the_title( $entry->form_id ); |
| 268 | |
| 269 | if ( empty( $form_title ) ) { |
| 270 | return '—'; |
| 271 | } |
| 272 | |
| 273 | return '<a href="' . esc_url( admin_url( 'admin.php?page=evf-entries&form_id=' . $entry->form_id ) ) . '">' . esc_html( $form_title ) . '</a>'; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Process field value for display |
| 278 | * |
| 279 | * @param mixed $value Field value. |
| 280 | * @return string Processed value. |
| 281 | */ |
| 282 | private function process_field_value( $value ) { |
| 283 | if ( empty( $value ) ) { |
| 284 | return '—'; |
| 285 | } |
| 286 | |
| 287 | if ( evf_is_json( $value ) ) { |
| 288 | $field_value = json_decode( $value, true ); |
| 289 | $value = isset( $field_value['value'] ) ? $field_value['value'] : $value; |
| 290 | } |
| 291 | |
| 292 | if ( is_serialized( $value ) ) { |
| 293 | $field_value = evf_maybe_unserialize( $value ); |
| 294 | $field_label = ! empty( $field_value['label'] ) ? evf_clean( $field_value['label'] ) : $field_value; |
| 295 | |
| 296 | if ( is_array( $field_label ) ) { |
| 297 | $value = implode( ', ', array_map( 'esc_html', $field_label ) ); |
| 298 | } else { |
| 299 | $value = esc_html( $field_label ); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | if ( is_array( $value ) ) { |
| 304 | if ( isset( $value['label'] ) ) { |
| 305 | $value = is_array( $value['label'] ) ? implode( ', ', $value['label'] ) : $value['label']; |
| 306 | } else { |
| 307 | $value = implode( ', ', $value ); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | if ( is_string( $value ) && filter_var( $value, FILTER_VALIDATE_URL ) ) { |
| 312 | $path = wp_parse_url( $value, PHP_URL_PATH ); |
| 313 | if ( ! empty( $path ) ) { |
| 314 | $value = basename( $path ); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | $value = (string) $value; |
| 319 | if ( strlen( $value ) > 100 ) { |
| 320 | $value = substr( $value, 0, 100 ) . '…'; |
| 321 | } |
| 322 | |
| 323 | $value = wp_strip_all_tags( trim( $value ) ); |
| 324 | |
| 325 | return $value; |
| 326 | } |
| 327 | |
| 328 | |
| 329 | |
| 330 | /** |
| 331 | * Show specific form fields (for specific form view). |
| 332 | * |
| 333 | * @param object $entry Entry object. |
| 334 | * @param string $column_name Column Name. |
| 335 | * @return string |
| 336 | */ |
| 337 | public function column_form_field( $entry, $column_name ) { |
| 338 | $field_id = str_replace( 'evf_field_', '', $column_name ); |
| 339 | $meta_key = isset( $this->form_data['form_fields'][ $field_id ]['meta-key'] ) ? strtolower( $this->form_data['form_fields'][ $field_id ]['meta-key'] ) : $field_id; |
| 340 | $field_type = isset( $this->form_data['form_fields'][ $field_id ]['type'] ) ? $this->form_data['form_fields'][ $field_id ]['type'] : ''; |
| 341 | |
| 342 | if ( ! empty( $entry->meta[ $meta_key ] ) || ( isset( $entry->meta[ $meta_key ] ) && is_numeric( $entry->meta[ $meta_key ] ) ) ) { |
| 343 | $value = $entry->meta[ $meta_key ]; |
| 344 | if ( evf_is_json( $value ) ) { |
| 345 | $field_value = json_decode( $value, true ); |
| 346 | $decoded = isset( $field_value['value'] ) ? $field_value['value'] : $field_value; |
| 347 | |
| 348 | // Coupons field stores data on array. |
| 349 | if ( is_array( $decoded ) ) { |
| 350 | $codes = array(); |
| 351 | foreach ( $decoded as $item ) { |
| 352 | if ( is_array( $item ) && ! empty( $item['code'] ) ) { |
| 353 | $codes[] = esc_html( $item['code'] ); |
| 354 | } |
| 355 | } |
| 356 | $value = ! empty( $codes ) ? implode( ', ', $codes ) : implode( ', ', array_filter( array_map( 'strval', $decoded ) ) ); |
| 357 | } else { |
| 358 | $value = $decoded; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | if ( is_serialized( $value ) ) { |
| 363 | $field_html = array(); |
| 364 | $field_value = evf_maybe_unserialize( $value ); |
| 365 | |
| 366 | $field_label = ! empty( $field_value['label'] ) ? evf_clean( $field_value['label'] ) : $field_value; |
| 367 | if ( is_array( $field_label ) ) { |
| 368 | foreach ( $field_label as $item ) { |
| 369 | // Coupon field: each item is an array with 'code', 'discount_type', etc. |
| 370 | if ( is_array( $item ) ) { |
| 371 | if ( ! empty( $item['code'] ) ) { |
| 372 | $field_html[] = esc_html( $item['code'] ); |
| 373 | } |
| 374 | } else { |
| 375 | $field_html[] = esc_html( $item ); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | $value = implode( ', ', $field_html ); |
| 380 | } else { |
| 381 | $value = esc_html( $field_label ); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | $value = isset( $value['label'] ) && is_array( $value['label'] ) ? implode( ', ', $value['label'] ) : ( is_array( $value ) ? implode( ', ', $value ) : $value ); |
| 386 | |
| 387 | $value = (string) $value; |
| 388 | |
| 389 | if ( false === strpos( $value, 'http' ) ) { |
| 390 | $lines = explode( "\n", $value ); |
| 391 | $value = array_slice( $lines, 0, 4 ); |
| 392 | $value = implode( "\n", $value ); |
| 393 | |
| 394 | if ( count( $lines ) > 5 ) { |
| 395 | $value .= '…'; |
| 396 | } elseif ( strlen( $value ) > 75 ) { |
| 397 | $value = substr( $value, 0, 75 ) . '…'; |
| 398 | } |
| 399 | |
| 400 | $value = nl2br( wp_strip_all_tags( trim( $value ) ) ); |
| 401 | } |
| 402 | $value = apply_filters( 'everest_forms_html_field_value', $value, $entry->meta[ $meta_key ], $entry, 'entry-table', $meta_key ); |
| 403 | |
| 404 | if ( in_array( $field_type, array( 'file-upload', 'image-upload', 'signature', 'wysiwyg', 'color', 'rating', 'country', 'likert', 'checkbox', 'radio', 'repeater-fields', 'payment-checkbox' ), true ) ) { |
| 405 | return nl2br( make_clickable( $value ) ); |
| 406 | }elseif( 'address' === $field_type ){ |
| 407 | $allowed_tags = array( |
| 408 | 'br' => array(), |
| 409 | 'span' => array(), |
| 410 | 'p' => array(), |
| 411 | ); |
| 412 | |
| 413 | $output = nl2br( $value ); |
| 414 | return wp_kses( $output, $allowed_tags ); |
| 415 | } |
| 416 | else{ |
| 417 | return esc_html( $value ); |
| 418 | } |
| 419 | } else { |
| 420 | return '<span class="na">—</span>'; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Renders the columns. |
| 426 | * |
| 427 | * @param object $entry Entry object. |
| 428 | * @param string $column_name Column Name. |
| 429 | * @return string |
| 430 | */ |
| 431 | public function column_default( $entry, $column_name ) { |
| 432 | switch ( $column_name ) { |
| 433 | case 'id': |
| 434 | $value = absint( $entry->entry_id ); |
| 435 | break; |
| 436 | |
| 437 | case 'date': |
| 438 | $value = date_i18n( |
| 439 | 'Y/m/d', |
| 440 | strtotime( $entry->date_created ) + ( get_option( 'gmt_offset' ) * 3600 ) |
| 441 | ); |
| 442 | |
| 443 | break; |
| 444 | |
| 445 | case 'sn': |
| 446 | $position = array_search( $entry, $this->items, true ); |
| 447 | $value = $position + 1; |
| 448 | break; |
| 449 | |
| 450 | case 'entry': |
| 451 | $value = $this->column_entry( $entry ); |
| 452 | break; |
| 453 | |
| 454 | case 'form': |
| 455 | $value = $this->column_form( $entry ); |
| 456 | break; |
| 457 | |
| 458 | default: |
| 459 | if ( false !== strpos( $column_name, 'evf_field_' ) ) { |
| 460 | $value = $this->column_form_field( $entry, $column_name ); |
| 461 | } else { |
| 462 | $value = ''; |
| 463 | } |
| 464 | break; |
| 465 | } |
| 466 | |
| 467 | return apply_filters( 'everest_forms_entry_table_column_value', $value, $entry, $column_name ); |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Get row actions for an entry. |
| 472 | * |
| 473 | * @param object $entry Entry object. |
| 474 | * @return array |
| 475 | */ |
| 476 | protected function get_row_actions( $entry ) { |
| 477 | $actions = array(); |
| 478 | $status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : ''; |
| 479 | |
| 480 | if ( 'trash' !== $entry->status ) { |
| 481 | if ( current_user_can( 'everest_forms_view_entry', $entry->entry_id ) ) { |
| 482 | $actions['view'] = '<a href="' . esc_url( admin_url( 'admin.php?page=evf-entries&form_id=' . $entry->form_id . '&view-entry=' . $entry->entry_id ) ) . '">' . esc_html__( 'View', 'everest-forms' ) . '</a>'; |
| 483 | } |
| 484 | |
| 485 | $user_can_edit_entry = is_admin() && current_user_can( 'everest_forms_edit_entry', $entry->entry_id ); |
| 486 | |
| 487 | if ( $user_can_edit_entry ) { |
| 488 | switch ( $status ) { |
| 489 | case 'spam': |
| 490 | $actions['unspam'] = '<a href="' . esc_url( |
| 491 | wp_nonce_url( |
| 492 | add_query_arg( |
| 493 | array( |
| 494 | 'unspam-entry' => $entry->entry_id, |
| 495 | 'form_id' => $entry->form_id, |
| 496 | ), |
| 497 | admin_url( 'admin.php?page=evf-entries' ) |
| 498 | ), |
| 499 | 'unspam-entry' |
| 500 | ) |
| 501 | ) . '">' . esc_html__( 'Remove From Spam', 'everest-forms' ) . '</a>'; |
| 502 | break; |
| 503 | default: |
| 504 | $actions['spam'] = '<a href="' . esc_url( |
| 505 | wp_nonce_url( |
| 506 | add_query_arg( |
| 507 | array( |
| 508 | 'spam-entry' => $entry->entry_id, |
| 509 | 'form_id' => $entry->form_id, |
| 510 | ), |
| 511 | admin_url( 'admin.php?page=evf-entries' ) |
| 512 | ), |
| 513 | 'spam-entry' |
| 514 | ) |
| 515 | ) . '">' . esc_html__( 'Mark as Spam', 'everest-forms' ) . '</a>'; |
| 516 | break; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | if ( current_user_can( 'everest_forms_delete_entry', $entry->entry_id ) ) { |
| 521 | /* translators: %s: entry name */ |
| 522 | $actions['trash'] = '<a class="submitdelete" aria-label="' . esc_attr__( 'Trash form entry', 'everest-forms' ) . '" href="' . esc_url( |
| 523 | wp_nonce_url( |
| 524 | add_query_arg( |
| 525 | array( |
| 526 | 'trash' => $entry->entry_id, |
| 527 | 'form_id' => $this->form_id, |
| 528 | ), |
| 529 | admin_url( 'admin.php?page=evf-entries' ) |
| 530 | ), |
| 531 | 'trash-entry' |
| 532 | ) |
| 533 | ) . '">' . esc_html__( 'Trash', 'everest-forms' ) . '</a>'; |
| 534 | } |
| 535 | } else { |
| 536 | if ( current_user_can( 'everest_forms_edit_entry', $entry->entry_id ) ) { |
| 537 | $actions['untrash'] = '<a aria-label="' . esc_attr__( 'Restore form entry from trash', 'everest-forms' ) . '" href="' . esc_url( |
| 538 | wp_nonce_url( |
| 539 | add_query_arg( |
| 540 | array( |
| 541 | 'untrash' => $entry->entry_id, |
| 542 | 'form_id' => $this->form_id, |
| 543 | ), |
| 544 | admin_url( 'admin.php?page=evf-entries' ) |
| 545 | ), |
| 546 | 'untrash-entry' |
| 547 | ) |
| 548 | ) . '">' . esc_html__( 'Restore', 'everest-forms' ) . '</a>'; |
| 549 | } |
| 550 | |
| 551 | if ( current_user_can( 'everest_forms_delete_entry', $entry->entry_id ) ) { |
| 552 | /* translators: %s: entry name */ |
| 553 | $actions['delete'] = '<a class="submitdelete" aria-label="' . esc_attr__( 'Delete form entry permanently', 'everest-forms' ) . '" href="' . esc_url( |
| 554 | wp_nonce_url( |
| 555 | add_query_arg( |
| 556 | array( |
| 557 | 'delete' => $entry->entry_id, |
| 558 | 'form_id' => $this->form_id, |
| 559 | ), |
| 560 | admin_url( 'admin.php?page=evf-entries' ) |
| 561 | ), |
| 562 | 'delete-entry' |
| 563 | ) |
| 564 | ) . '">' . esc_html__( 'Delete Permanently', 'everest-forms' ) . '</a>'; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | return apply_filters( 'everest_forms_entry_table_actions', $actions, $entry ); |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Render the actions column. |
| 573 | * |
| 574 | * @param object $entry Entry object. |
| 575 | * @return string |
| 576 | */ |
| 577 | public function column_actions( $entry ) { |
| 578 | $actions = $this->get_row_actions( $entry ); |
| 579 | return implode( ' <span class="sep">|</span> ', $actions ); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * Handle row actions for the primary column. |
| 584 | * |
| 585 | * @param object $entry Entry object. |
| 586 | * @param string $column_name Current column name. |
| 587 | * @param string $primary Primary column name. |
| 588 | * @return string |
| 589 | */ |
| 590 | protected function handle_row_actions( $entry, $column_name, $primary ) { |
| 591 | if ( $primary !== $column_name ) { |
| 592 | return ''; |
| 593 | } |
| 594 | |
| 595 | $actions = $this->get_row_actions( $entry ); |
| 596 | return $this->row_actions( $actions, false ); |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Get the name of the primary column. |
| 601 | * |
| 602 | * @return string |
| 603 | */ |
| 604 | protected function get_primary_column_name() { |
| 605 | // For All Forms view |
| 606 | if ( 0 === $this->form_id ) { |
| 607 | return 'entry'; |
| 608 | } |
| 609 | |
| 610 | // For specific form view - use existing logic |
| 611 | $columns = $this->get_columns(); |
| 612 | |
| 613 | unset( $columns['cb'], $columns['actions'], $columns['more'] ); |
| 614 | |
| 615 | $primary = ''; |
| 616 | if ( ! empty( $columns ) ) { |
| 617 | foreach ( $columns as $column_key => $column_name ) { |
| 618 | if ( strpos( $column_key, 'evf_field_' ) === 0 ) { |
| 619 | $primary = $column_key; |
| 620 | break; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | if ( empty( $primary ) ) { |
| 625 | reset( $columns ); |
| 626 | $primary = key( $columns ); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | return $primary; |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Get the status label for entries. |
| 635 | * |
| 636 | * @param string $status_name Status name. |
| 637 | * @param int $amount Amount of entries. |
| 638 | * @return array |
| 639 | */ |
| 640 | private function get_status_label( $status_name, $amount ) { |
| 641 | $statuses = evf_get_entry_statuses( $this->form_data ); |
| 642 | |
| 643 | if ( isset( $statuses[ $status_name ] ) ) { |
| 644 | return array( |
| 645 | 'singular' => sprintf( '%s <span class="count">(<span class="%s-count">%s</span>)</span>', esc_html( $statuses[ $status_name ] ), $status_name, $amount ), |
| 646 | 'plural' => sprintf( '%s <span class="count">(<span class="%s-count">%s</span>)</span>', esc_html( $statuses[ $status_name ] ), $status_name, $amount ), |
| 647 | 'context' => '', |
| 648 | 'domain' => 'everest-forms', |
| 649 | ); |
| 650 | } |
| 651 | |
| 652 | return array( |
| 653 | 'singular' => sprintf( '%s <span class="count">(<span class="%s-count">%s</span>)</span>', esc_html( $statuses[ $status_name ] ), $status_name, $amount ), |
| 654 | 'plural' => sprintf( '%s <span class="count">(%s)</span>', esc_html( $status_name ), $amount ), |
| 655 | 'context' => '', |
| 656 | 'domain' => 'everest-forms', |
| 657 | ); |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Table list views. |
| 662 | * |
| 663 | * @return array |
| 664 | */ |
| 665 | protected function get_views() { |
| 666 | |
| 667 | return array(); |
| 668 | |
| 669 | // $status_links = array(); |
| 670 | |
| 671 | // if ( 0 === $this->form_id ) { |
| 672 | // $num_entries = $this->get_all_forms_entry_counts(); |
| 673 | // } else { |
| 674 | // $num_entries = evf_get_count_entries_by_status( $this->form_id ); |
| 675 | // } |
| 676 | |
| 677 | // $total_entries = apply_filters( 'everest_forms_total_entries_count', (int) $num_entries['publish'], $num_entries, $this->form_id ); |
| 678 | // $spam_entries = apply_filters( 'everest_forms_spam_total_entries_count', (int) $num_entries['spam'], $num_entries, $this->form_id ); |
| 679 | |
| 680 | // $statuses = array_keys( evf_get_entry_statuses( $this->form_data ) ); |
| 681 | // $class = empty( $_REQUEST['status'] ) ? ' class="current"' : ''; // phpcs:ignore WordPress.Security.NonceVerification |
| 682 | |
| 683 | // $base_url = admin_url( 'admin.php?page=evf-entries' ); |
| 684 | // if ( $this->form_id > 0 ) { |
| 685 | // $base_url = add_query_arg( 'form_id', $this->form_id, $base_url ); |
| 686 | // } |
| 687 | |
| 688 | // /* translators: %s: count */ |
| 689 | // $status_links['all'] = "<a href='" . esc_url( $base_url ) . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_entries, 'entries', 'everest-forms' ), number_format_i18n( $total_entries ) ) . '</a>'; |
| 690 | |
| 691 | // /* translators: %s: count */ |
| 692 | // $spam_url = add_query_arg( 'status', 'spam', $base_url ); |
| 693 | // $spam_class = ( isset( $_REQUEST['status'] ) && 'spam' === $_REQUEST['status'] ) ? ' class="current"' : ''; |
| 694 | // $status_links['spam'] = "<a href='" . esc_url( $spam_url ) . "'$spam_class>" . sprintf( _nx( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', $spam_entries, 'entries', 'everest-forms' ), number_format_i18n( $spam_entries ) ) . '</a>'; |
| 695 | |
| 696 | // foreach ( $statuses as $status_name ) { |
| 697 | // if ( 'publish' === $status_name ) { |
| 698 | // continue; |
| 699 | // } |
| 700 | |
| 701 | // if ( isset( $_REQUEST['status'] ) && sanitize_key( wp_unslash( $_REQUEST['status'] ) ) === $status_name ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 702 | // $class = ' class="current"'; |
| 703 | // } else { |
| 704 | // $class = ''; |
| 705 | // } |
| 706 | |
| 707 | // $label = $this->get_status_label( $status_name, $num_entries[ $status_name ] ); |
| 708 | // $status_url = add_query_arg( 'status', $status_name, $base_url ); |
| 709 | |
| 710 | // $status_links[ $status_name ] = "<a href='" . esc_url( $status_url ) . "'$class>" . sprintf( translate_nooped_plural( $label, $num_entries[ $status_name ] ), number_format_i18n( $num_entries[ $status_name ] ) ) . '</a>'; |
| 711 | // } |
| 712 | |
| 713 | // return apply_filters( 'everest_forms_entries_table_views', $status_links, $num_entries, $this->form_data ); |
| 714 | } |
| 715 | |
| 716 | /** |
| 717 | * Get entry counts across all forms |
| 718 | * |
| 719 | * @return array |
| 720 | */ |
| 721 | private function get_all_forms_entry_counts() { |
| 722 | global $wpdb; |
| 723 | |
| 724 | // Initialize counts array with default counts for each status |
| 725 | $counts = array( |
| 726 | 'publish' => 0, |
| 727 | 'spam' => 0, |
| 728 | 'trash' => 0, |
| 729 | 'pending' => 0, |
| 730 | 'denied' => 0, |
| 731 | 'unread' => 0, |
| 732 | 'read' => 0, |
| 733 | 'starred' => 0, // Add starred count |
| 734 | ); |
| 735 | |
| 736 | $results = $wpdb->get_results( "SELECT status, COUNT(*) as count FROM {$wpdb->prefix}evf_entries GROUP BY status" ); |
| 737 | |
| 738 | foreach ( $results as $row ) { |
| 739 | $counts[ $row->status ] = (int) $row->count; |
| 740 | } |
| 741 | |
| 742 | // Count the unread entries (viewed = 0, status != 'trash') |
| 743 | $unread_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}evf_entries WHERE viewed = 0 AND status != 'trash'" ); |
| 744 | |
| 745 | $read_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}evf_entries WHERE viewed = 1 AND status != 'trash'" ); |
| 746 | |
| 747 | $counts['unread'] = (int) $unread_count; |
| 748 | $counts['read'] = (int) $read_count; |
| 749 | |
| 750 | $starred_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}evf_entries WHERE starred = 1 AND status != 'trash'" ); |
| 751 | |
| 752 | $counts['starred'] = (int) $starred_count; |
| 753 | |
| 754 | return $counts; |
| 755 | } |
| 756 | |
| 757 | |
| 758 | /** |
| 759 | * Get bulk actions. |
| 760 | * |
| 761 | * @return array |
| 762 | */ |
| 763 | protected function get_bulk_actions() { |
| 764 | if ( isset( $_GET['status'] ) && 'trash' === $_GET['status'] ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 765 | $actions = array( |
| 766 | 'untrash' => __( 'Restore', 'everest-forms' ), |
| 767 | 'delete' => __( 'Delete Permanently', 'everest-forms' ), |
| 768 | ); |
| 769 | } else { |
| 770 | $actions = array( |
| 771 | 'trash' => __( 'Move to Trash', 'everest-forms' ), |
| 772 | ); |
| 773 | } |
| 774 | |
| 775 | return apply_filters( 'everest_forms_entry_bulk_actions', $actions ); |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * Process bulk actions. |
| 780 | * |
| 781 | * @since 1.2.0 |
| 782 | */ |
| 783 | public function process_bulk_action() { |
| 784 | $pagenum = $this->get_pagenum(); |
| 785 | $doaction = $this->current_action(); |
| 786 | $entry_ids = isset( $_REQUEST['entry'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['entry'] ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification |
| 787 | $form_id = isset( $_REQUEST['form_id'] ) ? sanitize_key( wp_unslash( $_REQUEST['form_id'] ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification |
| 788 | $count = 0; |
| 789 | |
| 790 | if ( $doaction ) { |
| 791 | check_admin_referer( 'bulk-entries' ); |
| 792 | |
| 793 | $sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted' ), wp_get_referer() ); |
| 794 | if ( ! $sendback ) { |
| 795 | $sendback = admin_url( 'admin.php?page=evf-entries' ); |
| 796 | } |
| 797 | $sendback = add_query_arg( 'paged', $pagenum, $sendback ); |
| 798 | |
| 799 | if ( ! isset( $entry_ids ) ) { |
| 800 | wp_safe_redirect( $sendback ); |
| 801 | exit; |
| 802 | } |
| 803 | |
| 804 | switch ( $doaction ) { |
| 805 | case 'star': |
| 806 | case 'unstar': |
| 807 | foreach ( $entry_ids as $entry_id ) { |
| 808 | if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) { |
| 809 | ++$count; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | add_settings_error( |
| 814 | 'bulk_action', |
| 815 | 'bulk_action', |
| 816 | /* translators: %d: number of entries, %s: entries status */ |
| 817 | sprintf( _n( '%1$d entry successfully %2$s.', '%1$d entries successfully %2$s.', $count, 'everest-forms' ), $count, 'star' === $doaction ? 'starred' : 'unstarred' ), |
| 818 | 'updated' |
| 819 | ); |
| 820 | break; |
| 821 | case 'read': |
| 822 | case 'unread': |
| 823 | foreach ( $entry_ids as $entry_id ) { |
| 824 | if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) { |
| 825 | ++$count; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | add_settings_error( |
| 830 | 'bulk_action', |
| 831 | 'bulk_action', |
| 832 | /* translators: %d: number of entries, %s: entries status */ |
| 833 | sprintf( _n( '%1$d entry successfully marked as %2$s.', '%1$d entries successfully marked as %2$s.', $count, 'everest-forms' ), $count, $doaction ), |
| 834 | 'updated' |
| 835 | ); |
| 836 | break; |
| 837 | case 'approved': |
| 838 | foreach ( $entry_ids as $entry_id ) { |
| 839 | if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) { |
| 840 | $admin_email = esc_attr( get_bloginfo( 'admin_email' ) ); |
| 841 | $header = "Reply-To: {$admin_email} \r\n"; |
| 842 | $header .= 'Content-Type: text/html; charset=UTF-8'; |
| 843 | $subject = ''; |
| 844 | $message = ''; |
| 845 | |
| 846 | $entry = evf_get_entry( $entry_id ); |
| 847 | $entry_date = $entry->date_created; |
| 848 | $entry_data = $entry->meta; |
| 849 | $site_name = get_option( 'blogname' ); |
| 850 | |
| 851 | $first_name = ''; |
| 852 | $last_name = ''; |
| 853 | $email = ''; |
| 854 | $name = ''; |
| 855 | |
| 856 | foreach ( $entry_data as $key => $value ) { |
| 857 | if ( preg_match( '/^name/', $key ) ) { |
| 858 | $name = $value; |
| 859 | } |
| 860 | |
| 861 | if ( preg_match( '/^first_name_/', $key ) ) { |
| 862 | $first_name = $value; |
| 863 | } |
| 864 | |
| 865 | if ( preg_match( '/^last_name_/', $key ) ) { |
| 866 | $last_name = $value; |
| 867 | } |
| 868 | |
| 869 | if ( preg_match( '/^email/', $key ) ) { |
| 870 | $email = $value; |
| 871 | } |
| 872 | |
| 873 | if ( '' === $name ) { |
| 874 | if ( ! empty( $first_name ) && ! empty( $last_name ) ) { |
| 875 | $name = $first_name . ' ' . $last_name; |
| 876 | } elseif ( ! empty( $first_name ) ) { |
| 877 | $name = $first_name; |
| 878 | } else { |
| 879 | $name = $last_name; |
| 880 | } |
| 881 | } else { |
| 882 | $name = $name; |
| 883 | } |
| 884 | |
| 885 | $subject = apply_filters( 'everest_forms_entry_submission_approval_subject', esc_html__( 'Form Entry Approved', 'everest-forms' ) ); |
| 886 | /* translators:%s: User name of form entry */ |
| 887 | $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>'; |
| 888 | /* translators:%s: Form Entry Date */ |
| 889 | $message .= '<br/>' . sprintf( __( 'We’re pleased to inform you that your form entry submitted on %s has been successfully approved.', 'everest-forms' ), $entry_date ) . '<br/>'; |
| 890 | $message .= '<br/>' . __( 'Thank you for giving us your precious time', 'everest-forms' ) . '<br/>'; |
| 891 | /* translators:%s: Site Name */ |
| 892 | $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name ); |
| 893 | $message = apply_filters( 'everest_forms_entry_approval_message', $message, $name, $entry_date, $site_name ); |
| 894 | } |
| 895 | $email_obj = new EVF_Emails(); |
| 896 | $email_obj->send( $email, $subject, $message ); |
| 897 | ++$count; |
| 898 | } |
| 899 | } |
| 900 | break; |
| 901 | case 'denied': |
| 902 | foreach ( $entry_ids as $entry_id ) { |
| 903 | if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) { |
| 904 | $admin_email = esc_attr( get_bloginfo( 'admin_email' ) ); |
| 905 | $header = "Reply-To: {$admin_email} \r\n"; |
| 906 | $header .= 'Content-Type: text/html; charset=UTF-8'; |
| 907 | $subject = ''; |
| 908 | $message = ''; |
| 909 | |
| 910 | $entry = evf_get_entry( $entry_id ); |
| 911 | $entry_date = $entry->date_created; |
| 912 | $entry_data = $entry->meta; |
| 913 | $site_name = get_option( 'blogname' ); |
| 914 | |
| 915 | $first_name = ''; |
| 916 | $last_name = ''; |
| 917 | $email = ''; |
| 918 | $name = ''; |
| 919 | |
| 920 | foreach ( $entry_data as $key => $value ) { |
| 921 | if ( preg_match( '/^name/', $key ) ) { |
| 922 | $name = $value; |
| 923 | } |
| 924 | |
| 925 | if ( preg_match( '/^first_name_/', $key ) ) { |
| 926 | $first_name = $value; |
| 927 | } |
| 928 | |
| 929 | if ( preg_match( '/^last_name_/', $key ) ) { |
| 930 | $last_name = $value; |
| 931 | } |
| 932 | |
| 933 | if ( preg_match( '/^email/', $key ) ) { |
| 934 | $email = $value; |
| 935 | } |
| 936 | |
| 937 | if ( '' === $name ) { |
| 938 | if ( ! empty( $first_name ) && ! empty( $last_name ) ) { |
| 939 | $name = $first_name . ' ' . $last_name; |
| 940 | } elseif ( ! empty( $first_name ) ) { |
| 941 | $name = $first_name; |
| 942 | } else { |
| 943 | $name = $last_name; |
| 944 | } |
| 945 | } else { |
| 946 | $name = $name; |
| 947 | } |
| 948 | |
| 949 | $subject = apply_filters( 'everest_forms_entry_submission_denial_subject', esc_html__( 'Form Entry Denied', 'everest-forms' ) ); |
| 950 | /* translators:%s: User name of form entry */ |
| 951 | $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>'; |
| 952 | /* translators:%s: Form Entry Date */ |
| 953 | $message .= '<br/>' . sprintf( __( 'We regret to inform you that your form entry submitted on %s has been denied.', 'everest-forms' ), $entry_date ) . '<br/>'; |
| 954 | $message .= '<br/>' . __( 'Thank you for giving us your precious time', 'everest-forms' ) . '<br/>'; |
| 955 | /* translators:%s: Site Name */ |
| 956 | $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name ); |
| 957 | $message = apply_filters( 'everest_forms_entry_denial_message', $message, $name, $entry_date, $site_name ); |
| 958 | } |
| 959 | $email_obj = new EVF_Emails(); |
| 960 | $email_obj->send( $email, $subject, $message ); |
| 961 | ++$count; |
| 962 | } |
| 963 | } |
| 964 | break; |
| 965 | case 'trash': |
| 966 | foreach ( $entry_ids as $entry_id ) { |
| 967 | if ( EVF_Admin_Entries::update_status( $entry_id, 'trash' ) ) { |
| 968 | ++$count; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | add_settings_error( |
| 973 | 'bulk_action', |
| 974 | 'bulk_action', |
| 975 | /* translators: %d: number of entries */ |
| 976 | sprintf( _n( '%d entry moved to the Trash.', '%d entries moved to the Trash.', $count, 'everest-forms' ), $count ), |
| 977 | 'updated' |
| 978 | ); |
| 979 | break; |
| 980 | case 'untrash': |
| 981 | foreach ( $entry_ids as $entry_id ) { |
| 982 | if ( EVF_Admin_Entries::update_status( $entry_id, 'publish' ) ) { |
| 983 | ++$count; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | add_settings_error( |
| 988 | 'bulk_action', |
| 989 | 'bulk_action', |
| 990 | /* translators: %d: number of entries */ |
| 991 | sprintf( _n( '%d entry restored from the Trash.', '%d entries restored from the Trash.', $count, 'everest-forms' ), $count ), |
| 992 | 'updated' |
| 993 | ); |
| 994 | break; |
| 995 | case 'delete': |
| 996 | foreach ( $entry_ids as $entry_id ) { |
| 997 | if ( EVF_Admin_Entries::remove_entry( $entry_id, $form_id ) ) { |
| 998 | ++$count; |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | add_settings_error( |
| 1003 | 'bulk_action', |
| 1004 | 'bulk_action', |
| 1005 | /* translators: %d: number of entries */ |
| 1006 | sprintf( _n( '%d entry permanently deleted.', '%d entries permanently deleted.', $count, 'everest-forms' ), $count ), |
| 1007 | 'updated' |
| 1008 | ); |
| 1009 | break; |
| 1010 | case 'spam': |
| 1011 | foreach ( $entry_ids as $entry_id ) { |
| 1012 | if ( EVF_Admin_Entries::update_status( $entry_id, 'spam' ) ) { |
| 1013 | ++$count; |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | add_settings_error( |
| 1018 | 'bulk_action', |
| 1019 | 'bulk_action', |
| 1020 | /* translators: %d: number of entries */ |
| 1021 | sprintf( _n( '%d entry sent to spam.', '%d entries sent to Spam.', $count, 'everest-forms' ), $count ), |
| 1022 | 'updated' |
| 1023 | ); |
| 1024 | break; |
| 1025 | case 'unspam': |
| 1026 | foreach ( $entry_ids as $entry_id ) { |
| 1027 | if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) { |
| 1028 | ++$count; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | add_settings_error( |
| 1033 | 'bulk_action', |
| 1034 | 'bulk_action', |
| 1035 | /* translators: %d: number of entries */ |
| 1036 | sprintf( _n( '%d removed from spam.', '%d entries removed from spam.', $count, 'everest-forms' ), $count ), |
| 1037 | 'updated' |
| 1038 | ); |
| 1039 | break; |
| 1040 | } |
| 1041 | $sendback = remove_query_arg( array( 'action', 'action2' ), $sendback ); |
| 1042 | |
| 1043 | wp_safe_redirect( $sendback ); |
| 1044 | exit(); |
| 1045 | } elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) && isset( $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 1046 | wp_safe_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 1047 | exit(); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * Extra controls to be displayed between bulk actions and pagination. |
| 1053 | * |
| 1054 | * @param string $which The location of the extra table nav markup. |
| 1055 | */ |
| 1056 | protected function extra_tablenav( $which ) { |
| 1057 | global $entries_table_list, $wpdb; |
| 1058 | $num_entries = ( 0 === $this->form_id ) ? $this->get_all_forms_entry_counts() : evf_get_count_entries_by_status( $this->form_id ); |
| 1059 | $show_export = isset( $_GET['status'] ) && 'trash' === $_GET['status'] ? false : true; // phpcs:ignore WordPress.Security.NonceVerification |
| 1060 | ?> |
| 1061 | <div class="everest-forms-extra-table-nav"> |
| 1062 | <?php |
| 1063 | if ( ! empty( $this->forms ) && 'top' === $which ) { |
| 1064 | if ( defined( 'EFP_VERSION' ) && $this->form_id > 0 ) { |
| 1065 | ?> |
| 1066 | <button |
| 1067 | type="button" |
| 1068 | class="button evf-manage-columns-btn everest-forms-entries-setting" |
| 1069 | id="evf-manage-columns" |
| 1070 | data-evf-form_id="<?php echo esc_attr( $this->form_id ); ?>" |
| 1071 | > |
| 1072 | <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" style="vertical-align: middle; margin-right: 6px;"> |
| 1073 | <path d="M2 4.66667H14M2 8H14M2 11.3333H14" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> |
| 1074 | </svg> |
| 1075 | <?php esc_html_e( 'Manage Columns', 'everest-forms' ); ?> |
| 1076 | </button> |
| 1077 | <?php |
| 1078 | } |
| 1079 | |
| 1080 | $this->status_dropdown( $num_entries ); |
| 1081 | |
| 1082 | // Export CSV submit button. |
| 1083 | if ( apply_filters( 'everest_forms_enable_csv_export', $show_export ) && current_user_can( 'export' ) && $this->form_id > 0 ) { |
| 1084 | ?> |
| 1085 | <button type="submit" name="export_action" value="1" class="button" id="export-csv-submit"> |
| 1086 | <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" style="vertical-align: middle; margin-right: 6px;"> |
| 1087 | <path d="M14 10V12.6667C14 13.0203 13.8595 13.3594 13.6095 13.6095C13.3594 13.8595 13.0203 14 12.6667 14H3.33333C2.97971 14 2.64057 13.8595 2.39052 13.6095C2.14048 13.3594 2 13.0203 2 12.6667V10M11.3333 5.33333L8 2M8 2L4.66667 5.33333M8 2V10" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> |
| 1088 | </svg> |
| 1089 | <?php esc_html_e( 'Export CSV', 'everest-forms' ); ?> |
| 1090 | </button> |
| 1091 | <?php |
| 1092 | } |
| 1093 | |
| 1094 | if ( $num_entries['trash'] && isset( $_GET['status'] ) && 'trash' === $_GET['status'] && current_user_can( 'manage_everest_forms' ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 1095 | submit_button( __( 'Empty Trash', 'everest-forms' ), 'apply', 'delete_all', false ); |
| 1096 | } |
| 1097 | } |
| 1098 | ?> |
| 1099 | </div> |
| 1100 | <?php |
| 1101 | do_action( 'everest_forms_entries_table_extra_filters', $this->form_id, $which ); |
| 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * Display a form dropdown for filtering entries. |
| 1106 | */ |
| 1107 | public function forms_dropdown() { |
| 1108 | $forms = evf_get_all_forms( true ); |
| 1109 | $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : $this->form_id; // phpcs:ignore WordPress.Security.NonceVerification |
| 1110 | ?> |
| 1111 | <label for="filter-by-form" class="screen-reader-text"><?php esc_html_e( 'Filter by form', 'everest-forms' ); ?></label> |
| 1112 | <select name="form_id" id="filter-by-form" class="evf-enhanced-normal-select evf-auto-filter" style="min-width: 200px;" data-placeholder="<?php esc_attr_e( 'Search form...', 'everest-forms' ); ?>"> |
| 1113 | <option value="0" <?php selected( $form_id, 0 ); ?>><?php esc_html_e( 'All Forms', 'everest-forms' ); ?></option> |
| 1114 | <?php foreach ( $forms as $id => $form ) : ?> |
| 1115 | <option value="<?php echo esc_attr( $id ); ?>" <?php selected( $form_id, $id ); ?>><?php echo esc_html( $form ); ?></option> |
| 1116 | <?php endforeach; ?> |
| 1117 | </select> |
| 1118 | <?php |
| 1119 | } |
| 1120 | |
| 1121 | /** |
| 1122 | * Display a status dropdown for filtering entries. |
| 1123 | */ |
| 1124 | public function status_dropdown( $num_entries ) { |
| 1125 | $current_status = isset( $_REQUEST['status'] ) ? sanitize_key( wp_unslash( $_REQUEST['status'] ) ) : ''; |
| 1126 | |
| 1127 | $statuses = array( |
| 1128 | 'all' => __( 'All', 'everest-forms' ), |
| 1129 | 'unread' => __( 'Unread', 'everest-forms' ), |
| 1130 | 'read' => __( 'Read', 'everest-forms' ), |
| 1131 | 'spam' => __( 'Spam', 'everest-forms' ), |
| 1132 | 'trash' => __( 'Trash', 'everest-forms' ), |
| 1133 | ); |
| 1134 | |
| 1135 | if ( ! empty( $this->form_data ) ) { |
| 1136 | $extra_statuses = evf_get_entry_statuses( $this->form_data ); |
| 1137 | foreach ( $extra_statuses as $key => $label ) { |
| 1138 | if ( ! isset( $statuses[ $key ] ) && 'publish' !== $key ) { |
| 1139 | $statuses[ $key ] = $label; |
| 1140 | } |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | // Map status keys to count keys. |
| 1145 | $count_map = array( |
| 1146 | 'all' => 'publish', |
| 1147 | 'unread' => 'unread', |
| 1148 | 'read' => 'read', |
| 1149 | 'spam' => 'spam', |
| 1150 | 'trash' => 'trash', |
| 1151 | ); |
| 1152 | ?> |
| 1153 | <select name="status" id="filter-by-status" class="evf-enhanced-normal-select evf-auto-filter"> |
| 1154 | <?php |
| 1155 | foreach ( $statuses as $key => $label ) : |
| 1156 | $count_key = isset( $count_map[ $key ] ) ? $count_map[ $key ] : $key; |
| 1157 | $count = isset( $num_entries[ $count_key ] ) ? (int) $num_entries[ $count_key ] : 0; |
| 1158 | $display = sprintf( '%s (%d)', $label, $count ); |
| 1159 | ?> |
| 1160 | <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $current_status, $key ); ?>> |
| 1161 | <?php echo esc_html( $display ); ?> |
| 1162 | </option> |
| 1163 | <?php endforeach; ?> |
| 1164 | </select> |
| 1165 | <?php |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | /** |
| 1170 | * Prepare table list items. |
| 1171 | */ |
| 1172 | public function prepare_items() { |
| 1173 | $per_page = $this->get_items_per_page( 'evf_entries_per_page' ); |
| 1174 | $current_page = $this->get_pagenum(); |
| 1175 | |
| 1176 | // Query args. |
| 1177 | $args = array( |
| 1178 | 'status' => 'publish', |
| 1179 | 'form_id' => $this->form_id, |
| 1180 | 'limit' => $per_page, |
| 1181 | 'offset' => $per_page * ( $current_page - 1 ), |
| 1182 | ); |
| 1183 | |
| 1184 | // Handle the status query. |
| 1185 | if ( ! empty( $_REQUEST['status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 1186 | $status = sanitize_key( wp_unslash( $_REQUEST['status'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 1187 | |
| 1188 | if ( 'unread' === $status ) { |
| 1189 | $args['status'] = 'publish'; |
| 1190 | $args['viewed'] = 0; |
| 1191 | } elseif ( 'read' === $status ) { |
| 1192 | $args['status'] = 'publish'; |
| 1193 | $args['viewed'] = 1; |
| 1194 | } elseif ( 'all' === $status ) { |
| 1195 | $args['status'] = 'publish'; |
| 1196 | } else { |
| 1197 | $args['status'] = $status; |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | // Handle the search query. |
| 1202 | if ( ! empty( $_REQUEST['s'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 1203 | $args['search'] = sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 1204 | } |
| 1205 | |
| 1206 | if ( ! empty( $_REQUEST['orderby'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 1207 | $args['orderby'] = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 1208 | } |
| 1209 | |
| 1210 | if ( ! empty( $_REQUEST['order'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 1211 | $args['order'] = sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 1212 | } |
| 1213 | |
| 1214 | // Get the entries. |
| 1215 | $entries = evf_search_entries( $args ); |
| 1216 | $this->items = array_map( 'evf_get_entry', $entries ); |
| 1217 | |
| 1218 | // Get total items. |
| 1219 | $args['limit'] = -1; |
| 1220 | $args['offset'] = 0; |
| 1221 | $total_items = count( evf_search_entries( $args ) ); |
| 1222 | |
| 1223 | // Set the pagination. |
| 1224 | $this->set_pagination_args( |
| 1225 | array( |
| 1226 | 'total_items' => $total_items, |
| 1227 | 'per_page' => $per_page, |
| 1228 | 'total_pages' => ceil( $total_items / $per_page ), |
| 1229 | ) |
| 1230 | ); |
| 1231 | } |
| 1232 | } |
| 1233 |