PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | stripe/helpers/FrmTransLiteListHelper.php +213 -82 6.5.2 → trunk View file →
@@ -15,12 +15,15 @@
15 15 * This is retrieved all at once with a single database query.
16 16 * This is used to determine if a specific entry is deleted.
17 17 * When an entry is deleted, there is no link to the deleted entry.
18 18 *
19 - * @var int[] $valid_entry_ids
19 + * @var int[]
20 20 */
21 21 private $valid_entry_ids = array();
22 22
23 + /**
24 + * @param array $args
25 + */
23 26 public function __construct( $args ) {
24 27 $this->table = FrmAppHelper::get_simple_request(
25 28 array(
26 29 'param' => 'trans_type',
@@ -26,9 +29,15 @@
26 29 'param' => 'trans_type',
27 30 'type' => 'request',
28 31 )
29 32 );
33 +
30 34 parent::__construct( $args );
35 + $this->screen->set_screen_reader_content(
36 + array(
37 + 'heading_list' => esc_html__( 'Payments list', 'formidable' ),
38 + )
39 + );
31 40 }
32 41
33 42 /**
34 43 * @return void
@@ -35,11 +44,16 @@
35 44 */
36 45 public function prepare_items() {
37 46 global $wpdb;
38 47
39 - $orderby = FrmAppHelper::get_param( 'orderby', 'id', 'get', 'sanitize_title' );
40 - $order = FrmAppHelper::get_param( 'order', 'DESC', 'get', 'sanitize_text_field' );
41 - if ( ! in_array( $order, array( 'ASC', 'DESC' ), true ) ) {
48 + $orderby = FrmAppHelper::get_param( 'orderby', 'id', 'get', 'sanitize_title' );
49 + $order = FrmAppHelper::get_param( 'order', 'DESC', 'get', 'sanitize_text_field' );
50 +
51 + if ( ! is_string( $orderby ) ) {
52 + $orderby = 'id';
53 + }
54 +
55 + if ( ! is_string( $order ) || ! in_array( strtoupper( $order ), array( 'ASC', 'DESC' ), true ) ) {
42 56 $order = 'DESC';
43 57 }
44 58
45 59 $page = $this->get_pagenum();
@@ -51,9 +65,9 @@
51 65
52 66 // @codingStandardsIgnoreStart
53 67 $this->items = $wpdb->get_results(
54 68 $wpdb->prepare(
55 - 'SELECT * ' . $query . $order_query . ' LIMIT %d, %d',
69 + 'SELECT p.* ' . $query . $order_query . ' LIMIT %d, %d',
56 70 $start,
57 71 $per_page
58 72 )
59 73 );
@@ -76,22 +90,20 @@
76 90
77 91 $table_name = $this->table === 'subscriptions' ? 'frm_subscriptions' : 'frm_payments';
78 92 $form_id = FrmAppHelper::get_param( 'form', 0, 'get', 'absint' );
79 93
80 - if ( $form_id ) {
81 - // @codingStandardsIgnoreStart
82 - $query = $wpdb->prepare(
83 - "FROM `{$wpdb->prefix}{$table_name}` p
84 - LEFT JOIN `{$wpdb->prefix}frm_items` i ON p.item_id = i.id
85 - WHERE i.form_id = %d",
86 - $form_id
87 - );
88 - // @codingStandardsIgnoreEnd
89 - } else {
90 - $query = "FROM `{$wpdb->prefix}{$table_name}` p";
94 + if ( ! $form_id ) {
95 + return "FROM `{$wpdb->prefix}{$table_name}` p";
91 96 }
92 97
93 - return $query;
98 + // @codingStandardsIgnoreStart
99 + return $wpdb->prepare(
100 + "FROM `{$wpdb->prefix}{$table_name}` p
101 + JOIN `{$wpdb->prefix}frm_items` i ON p.item_id = i.id
102 + WHERE i.form_id = %d",
103 + $form_id
104 + );
105 + // @codingStandardsIgnoreEnd
94 106 }
95 107
96 108 /**
97 109 * @return void
@@ -96,9 +108,9 @@
96 108 /**
97 109 * @return void
98 110 */
99 111 public function no_items() {
100 - esc_html_e( 'No payments found.', 'formidable' );
112 + include FrmTransLiteAppHelper::plugin_path() . '/views/lists/no-payments.php';
101 113 }
102 114
103 115 /**
104 116 * @return array
@@ -108,10 +120,9 @@
108 120 'payments' => __( 'Payments', 'formidable' ),
109 121 'subscriptions' => __( 'Subscriptions', 'formidable' ),
110 122 );
111 123
112 - $links = array();
113 -
124 + $links = array();
114 125 $frm_payment = new FrmTransLitePayment();
115 126 $frm_sub = new FrmTransLiteSubscription();
116 127 $counts = array(
117 128 'payments' => $frm_payment->get_count(),
@@ -125,19 +136,17 @@
125 136 )
126 137 );
127 138
128 139 foreach ( $statuses as $status => $name ) {
129 - if ( $status === $type ) {
130 - $class = ' class="current"';
131 - } else {
132 - $class = '';
133 - }
140 + $class = $status === $type ? ' class="current"' : '';
134 141
135 - if ( $counts[ $status ] || 'published' === $status ) {
142 + if ( $counts[ $status ] || 'payments' === $status ) {
143 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
136 144 $links[ $status ] = '<a href="' . esc_url( '?page=formidable-payments&trans_type=' . $status ) . '" ' . $class . '>'
137 - // translators: %1$s: Transaction type (Payments or Subscriptions), %2$s: Span start tag, %3$s: Count, %3$s: Span close tag.
145 + // translators: %1$s: Transaction type (Payments or Subscriptions), %2$s: Span start tag, %3$s: Count, %4$s: Span close tag.
138 146 . sprintf( esc_html__( '%1$s %2$s(%3$s)%4$s', 'formidable' ), esc_html( $name ), '<span class="count">', number_format_i18n( $counts[ $status ] ), '</span>' )
139 147 . '</a>';
148 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
140 149 }
141 150
142 151 unset( $status, $name );
143 152 }
@@ -163,8 +172,9 @@
163 172 'receipt_id' => 'receipt_id',
164 173 'sub_id' => 'sub_id',
165 174 'begin_date' => 'begin_date',
166 175 'expire_date' => 'expire_date',
176 + 'paysys' => 'paysys',
167 177 'status' => 'status',
168 178 'next_bill_date' => 'next_bill_date',
169 179 );
170 180 }
@@ -169,18 +179,38 @@
169 179 );
170 180 }
171 181
172 182 /**
183 + * If the Payments submodule or the PayPal add-on is active, add a bulk delete action.
184 + *
185 + * @since 6.27
186 + *
187 + * @return array
188 + */
189 + public function get_bulk_actions() {
190 + $actions = array();
191 +
192 + if ( $this->payments_addon_list_helper_exists() ) {
193 + $actions['bulk_delete'] = __( 'Delete', 'formidable' );
194 + }
195 +
196 + return $actions;
197 + }
198 +
199 + /**
173 200 * @param string $which
201 + *
174 202 * @return void
175 203 */
176 204 public function extra_tablenav( $which ) {
177 205 $footer = $which !== 'top';
206 +
178 207 if ( $footer ) {
179 208 return;
180 209 }
181 210
182 211 $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
212 +
183 213 if ( $form_id ) {
184 214 // Don't show the switcher if it's already in the header.
185 215 return;
186 216 }
@@ -199,20 +229,20 @@
199 229 * @return void
200 230 */
201 231 public function display_rows() {
202 232 $date_format = FrmTransLiteAppHelper::get_date_format();
233 + $gateways = FrmTransLiteAppHelper::get_gateways();
234 + $alt = 0;
235 + $form_ids = $this->get_form_ids();
236 + $args = compact( 'form_ids', 'date_format', 'gateways' );
237 + // $form_ids is indexed by entry ID.
238 + $this->valid_entry_ids = array_keys( $form_ids );
203 239
204 - $alt = 0;
205 -
206 - $form_ids = $this->get_form_ids();
207 - $args = compact( 'form_ids', 'date_format' );
208 - $this->valid_entry_ids = array_keys( $form_ids ); // $form_ids is indexed by entry ID.
209 -
210 240 foreach ( $this->items as $item ) {
211 241 echo '<tr id="payment-' . esc_attr( $item->id ) . '" ';
212 242
213 243 $is_alternate = 0 === $alt % 2;
214 - $alt++;
244 + ++$alt;
215 245
216 246 if ( $is_alternate ) {
217 247 echo 'class="alternate"';
218 248 }
@@ -225,9 +255,10 @@
225 255 }
226 256 }
227 257
228 258 /**
229 - * @param array $args
259 + * @param object $item
260 + * @param array $args
230 261 *
231 262 * @return void
232 263 */
233 264 private function display_columns( $item, $args ) {
@@ -244,15 +275,33 @@
244 275 }
245 276
246 277 protected function get_column_info() {
247 278 $column_info = parent::get_column_info();
248 - unset( $column_info[0]['cb'] ); // Remove the checkbox column.
279 +
280 + if ( ! $this->payments_addon_list_helper_exists() ) {
281 + // Remove the checkbox column for Lite only.
282 + unset( $column_info[0]['cb'] );
283 + }
284 +
249 285 return $column_info;
250 286 }
251 287
252 288 /**
289 + * Check for Payments submodule (Stripe, Authorize.Net add-ons), as well as PayPal.
290 + *
291 + * @since 6.27
292 + *
293 + * @return bool
294 + */
295 + private function payments_addon_list_helper_exists() {
296 + return class_exists( 'FrmTransListHelper' ) || class_exists( 'FrmPaymentsListHelper' );
297 + }
298 +
299 + /**
253 300 * @param object $item
254 301 * @param array $args
302 + *
303 + * @return string
255 304 */
256 305 private function get_column_value( $item, $args ) {
257 306 $column_name = $args['column_name'];
258 307 $function_name = 'get_' . $column_name . '_column';
@@ -261,9 +310,9 @@
261 310 $val = $this->$function_name( $item, $args );
262 311 } else {
263 312 $val = $item->$column_name ? $item->$column_name : '';
264 313
265 - if ( strpos( $column_name, '_date' ) !== false ) {
314 + if ( str_contains( $column_name, '_date' ) ) {
266 315 if ( ! empty( $item->$column_name ) && $item->$column_name !== '0000-00-00' ) {
267 316 $val = FrmTransLiteAppHelper::format_the_date( $item->$column_name, $args['date_format'] );
268 317 } else {
269 318 $val = '';
@@ -278,8 +327,9 @@
278 327 * @return array
279 328 */
280 329 private function get_form_ids() {
281 330 $entry_ids = array();
331 +
282 332 foreach ( $this->items as $item ) {
283 333 $entry_ids[] = absint( $item->item_id );
284 334 unset( $item );
285 335 }
@@ -298,8 +348,9 @@
298 348 // @codingStandardsIgnoreEnd
299 349 unset( $entry_ids );
300 350
301 351 $form_ids = array();
352 +
302 353 foreach ( $forms as $form ) {
303 354 $form_ids[ $form->id ] = $form;
304 355 unset( $form );
305 356 }
@@ -314,9 +365,9 @@
314 365 */
315 366 private function get_row_classes( $atts ) {
316 367 $class = 'column-' . $atts['column_name'];
317 368
318 - if ( in_array( $atts['column_name'], $atts['hidden'] ) ) {
369 + if ( in_array( $atts['column_name'], $atts['hidden'], true ) ) {
319 370 $class .= ' frm_hidden';
320 371 }
321 372
322 373 return 'class="' . esc_attr( $class ) . '"';
@@ -322,12 +373,26 @@
322 373 return 'class="' . esc_attr( $class ) . '"';
323 374 }
324 375
325 376 /**
377 + * Get the checkbox for bulk actions.
378 + * This is only required when the Payments submodule or PayPal is active.
379 + *
380 + * @since 6.27
381 + *
326 382 * @param object $item
327 383 *
328 384 * @return string
329 385 */
386 + private function get_cb_column( $item ) {
387 + return '<input type="checkbox" name="item-action[]" value="' . esc_attr( $item->id ) . '" />';
388 + }
389 +
390 + /**
391 + * @param object $item
392 + *
393 + * @return string
394 + */
330 395 private function get_receipt_id_column( $item ) {
331 396 return $this->get_action_column( $item, 'receipt_id' );
332 397 }
333 398
@@ -337,32 +402,50 @@
337 402 *
338 403 * @return string
339 404 */
340 405 private function get_action_column( $item, $field ) {
341 - $link = add_query_arg(
342 - array(
343 - 'action' => 'show',
344 - 'id' => $item->id,
345 - 'type' => $this->table,
346 - )
347 - );
406 + $link = $this->get_view_payment_link( $item, $field );
407 + return '<strong>' . $link . '</strong><br />' . $this->row_actions( $this->get_row_actions( $item ) );
408 + }
348 409
410 + /**
411 + * @since 6.27
412 + *
413 + * @param object $item
414 + * @param string $field
415 + *
416 + * @return string
417 + */
418 + private function get_view_payment_link( $item, $field ) {
349 419 $link_params = array(
350 420 'class' => 'rot-title',
351 - 'href' => esc_url( $link ),
421 + 'href' => esc_url( $this->get_url_to_payment( $item->id, 'show' ) ),
352 422 'title' => __( 'View', 'formidable' ),
353 423 );
354 - $link = '<a ' . FrmAppHelper::array_to_html_params( $link_params ) . '>'
355 - . $item->{$field}
356 - . '</a>';
424 + return '<a ' . FrmAppHelper::array_to_html_params( $link_params ) . '>' . esc_html( $item->{ $field } ) . '</a>';
425 + }
357 426
358 - return '<strong>' . $link . '</strong>'
359 - . '<br />'
360 - . $this->row_actions( $this->get_row_actions( $item ) );
427 + /**
428 + * @param int|string $payment_id
429 + * @param string $action Supports 'show' and 'edit'.
430 + *
431 + * @return string
432 + */
433 + private function get_url_to_payment( $payment_id, $action = 'show' ) {
434 + return add_query_arg(
435 + array(
436 + 'action' => $action,
437 + 'id' => $payment_id,
438 + 'type' => $this->table,
439 + 'page' => FrmAppHelper::simple_get( 'page' ),
440 + ),
441 + admin_url( 'admin.php' )
442 + );
361 443 }
362 444
363 445 /**
364 446 * @param object $item
447 + *
365 448 * @return array
366 449 */
367 450 private function get_row_actions( $item ) {
368 451 $base_link = '?page=formidable-payments&action=';
@@ -368,23 +451,44 @@
368 451 $base_link = '?page=formidable-payments&action=';
369 452 $view_link = $base_link . 'show&id=' . $item->id . '&type=' . $this->table;
370 453 $delete_link = $base_link . 'destroy&id=' . $item->id . '&type=' . $this->table;
371 454
372 - $actions = array();
373 - $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . esc_html__( 'View', 'formidable' ) . '</a>';
374 - $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" data-frmverify="' . esc_attr__( 'Permanently delete this payment?', 'formidable' ) . '" data-frmverify-btn="frm-button-red">' . esc_html__( 'Delete', 'formidable' ) . '</a>';
455 + $actions = array();
456 + $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . esc_html__( 'View', 'formidable' ) . '</a>';
375 457
458 + if ( $this->supports_edit_link() ) {
459 + $edit_link = $base_link . 'edit&id=' . $item->id;
460 + $actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'formidable' ) . '</a>';
461 + }
462 +
463 + $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" data-frmverify="' . esc_attr__( 'Permanently delete this payment?', 'formidable' ) . '" data-frmverify-btn="frm-button-red">' . esc_html__( 'Delete', 'formidable' ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
464 +
376 465 return $actions;
377 466 }
378 467
379 468 /**
469 + * @since 6.27
470 + *
471 + * @return bool
472 + */
473 + private function supports_edit_link() {
474 + if ( $this->table === 'subscriptions' ) {
475 + return false;
476 + }
477 +
478 + return class_exists( 'FrmTransAppController', false ) || class_exists( 'FrmPaymentsController', false );
479 + }
480 +
481 + /**
380 482 * Get the column value for displaying an entry ID.
381 483 *
382 484 * @param object $item A payment or subscription object.
485 + *
383 486 * @return string
384 487 */
385 488 private function get_item_id_column( $item ) {
386 - $entry_id = (int) $item->item_id;
489 + $entry_id = (int) $item->item_id;
490 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
387 491 $entry_is_deleted = ! in_array( $entry_id, $this->valid_entry_ids );
388 492
389 493 if ( $entry_is_deleted ) {
390 494 // translators: %d: ID of the deleted entry.
@@ -396,14 +500,14 @@
396 500
397 501 /**
398 502 * @param object $item
399 503 * @param array $atts
504 + *
400 505 * @return mixed
401 506 */
402 507 private function get_form_id_column( $item, $atts ) {
403 508 if ( isset( $atts['form_ids'][ $item->item_id ] ) ) {
404 - $form_link = FrmFormsHelper::edit_form_link( $atts['form_ids'][ $item->item_id ]->form_id );
405 - return $form_link;
509 + return FrmFormsHelper::edit_form_link( $atts['form_ids'][ $item->item_id ]->form_id );
406 510 }
407 511
408 512 return '';
409 513 }
@@ -409,12 +513,12 @@
409 513 }
410 514
411 515 /**
412 516 * @param object $item
517 + *
413 518 * @return string
414 519 */
415 520 private function get_user_id_column( $item ) {
416 - global $wpdb;
417 521 $val = FrmDb::get_var( 'frm_items', array( 'id' => $item->item_id ), 'user_id' );
418 522 return FrmTransLiteAppHelper::get_user_link( $val );
419 523 }
420 524
@@ -420,8 +524,9 @@
420 524
421 525 /**
422 526 * @param object $item
423 527 * @param array $atts
528 + *
424 529 * @return string
425 530 */
426 531 private function get_created_at_column( $item, $atts ) {
427 532 if ( empty( $item->created_at ) || $item->created_at === '0000-00-00 00:00:00' ) {
@@ -429,13 +534,14 @@
429 534 }
430 535
431 536 $date = FrmAppHelper::get_localized_date( $atts['date_format'], $item->created_at );
432 537 $date_title = FrmAppHelper::get_localized_date( $atts['date_format'] . ' g:i:s A', $item->created_at );
433 - $val = '<abbr title="' . esc_attr( $date_title ) . '">' . $date . '</abbr>';
434 - return $val;
538 + return '<abbr title="' . esc_attr( $date_title ) . '">' . $date . '</abbr>';
435 539 }
436 540
437 541 /**
542 + * @param object $item
543 + *
438 544 * @return string
439 545 */
440 546 private function get_amount_column( $item ) {
441 547 if ( $this->table === 'subscriptions' ) {
@@ -452,24 +558,23 @@
452 558 private function get_end_count_column( $item ) {
453 559 $limit = $item->end_count >= 9999 ? __( 'unlimited', 'formidable' ) : $item->end_count;
454 560 $frm_payment = new FrmTransLitePayment();
455 561 $completed_payments = $frm_payment->get_all_by( $item->id, 'sub_id' );
456 - $count = 0;
562 + $count = FrmTransLiteAppHelper::count_completed_payments( $completed_payments );
457 563
458 - foreach ( $completed_payments as $completed_payment ) {
459 - if ( $completed_payment->status === 'complete' ) {
460 - $count++;
461 - }
462 - }
463 -
464 564 // translators: %1$s: Count, %2$s: Limit.
465 565 return sprintf( __( '%1$s of %2$s', 'formidable' ), $count, $limit );
466 566 }
467 567
568 + /**
569 + * @param object $item
570 + *
571 + * @return string
572 + */
468 573 private function get_status_column( $item ) {
469 574 $status = esc_html( FrmTransLiteAppHelper::show_status( FrmTransLiteAppHelper::get_payment_status( $item ) ) );
470 575
471 - if ( 'processing' === $item->status ) {
576 + if ( 'processing' === ( $item->status ?? '' ) ) {
472 577 $status .= $this->get_processing_tooltip();
473 578 }
474 579
475 580 return $status;
@@ -481,16 +586,10 @@
481 586 * @return string
482 587 */
483 588 private function get_processing_tooltip() {
484 589 return FrmAppHelper::clip(
485 - function() {
486 - $params = array(
487 - 'class' => 'frm_help frm_icon_font frm_tooltip_icon',
488 - 'title' => __( 'This payment method may take between 4-5 business days to process.', 'formidable' ),
489 - );
490 - ?>
491 - <span <?php FrmAppHelper::array_to_html_params( $params, true ); ?>></span>
492 - <?php
590 + function () {
591 + FrmAppHelper::tooltip_icon( __( 'This payment method may take between 4-5 business days to process.', 'formidable' ) );
493 592 }
494 593 );
495 594 }
496 595
@@ -495,8 +594,9 @@
495 594 }
496 595
497 596 /**
498 597 * @param object $item
598 + *
499 599 * @return string
500 600 */
501 601 private function get_sub_id_column( $item ) {
502 602 if ( empty( $item->sub_id ) ) {
@@ -515,16 +615,47 @@
515 615 * Convert the supported pay systems to their proper case.
516 616 *
517 617 * @param object $item
518 618 * @param array $atts
619 + *
519 620 * @return string
520 621 */
521 622 private function get_paysys_column( $item, $atts ) {
522 - switch ( $item->paysys ) {
523 - case 'stripe':
524 - return 'Stripe';
525 - case 'paypal':
526 - return 'PayPal';
623 + if ( isset( $atts['gateways'][ $item->paysys ] ) ) {
624 + return $atts['gateways'][ $item->paysys ]['label'];
527 625 }
626 +
528 627 return $item->paysys;
628 + }
629 +
630 + /**
631 + * Display 'Test' or 'Live' in a mode column if the value is known.
632 + * Old payment entries will have a NULL 'test' column value.
633 + *
634 + * @since 6.6
635 + *
636 + * @param stdClass $item Payment or Subscription object.
637 + *
638 + * @return string
639 + */
640 + private function get_mode_column( $item ) {
641 + return esc_html( FrmTransLiteAppHelper::get_test_mode_display_string( $item ) );
642 + }
643 +
644 + /**
645 + * Render the tabs for the payments list, if the user has access to coupons.
646 + *
647 + * @since 6.27
648 + *
649 + * @param string $active_tab
650 + *
651 + * @return void
652 + */
653 + public static function render_tabs( $active_tab = 'payments' ) {
654 + if ( ! current_user_can( 'frm_change_settings' ) ) {
655 + // Coupons are only available to people who can access global settings.
656 + return;
657 + }
658 +
659 + include FrmTransLiteAppHelper::plugin_path() . '/views/lists/tabs.php';
529 660 }
530 661 }