PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8.1
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 | classes/helpers/FrmFormsListHelper.php +92 -381 6.326.8.1 View file →
@@ -3,37 +3,16 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmFormsListHelper extends FrmListHelper {
7 -
8 - /**
9 - * The transient name that stores data for which posts a form is embedded in.
10 - *
11 - * @since 6.32
12 - *
13 - * @var string
14 - */
15 - private static $embed_posts_transient_name = 'frm_posts_contain_form';
16 -
17 - /**
18 - * @var string
19 - */
20 7 public $status = '';
21 8
22 9 public $total_items = 0;
23 10
24 - /**
25 - * @param array $args
26 - */
27 11 public function __construct( $args ) {
28 12 $this->status = self::get_param( array( 'param' => 'form_type' ) );
29 13
30 14 parent::__construct( $args );
31 - $this->screen->set_screen_reader_content(
32 - array(
33 - 'heading_list' => esc_html__( 'Forms list', 'formidable' ),
34 - )
35 - );
36 15 }
37 16
38 17 /**
39 18 * @return void
@@ -38,20 +17,19 @@
38 17 /**
39 18 * @return void
40 19 */
41 20 public function prepare_items() {
42 - global $per_page, $mode;
21 + global $wpdb, $per_page, $mode;
43 22
44 23 $page = $this->get_pagenum();
45 24 $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
46 25
47 - $mode = self::get_param(
26 + $mode = self::get_param(
48 27 array(
49 28 'param' => 'mode',
50 29 'default' => 'list',
51 30 )
52 31 );
53 -
54 32 $orderby = self::get_param(
55 33 array(
56 34 'param' => 'orderby',
57 35 'default' => 'name',
@@ -62,12 +40,9 @@
62 40 'param' => 'order',
63 41 'default' => 'ASC',
64 42 )
65 43 );
66 -
67 - FrmAppController::apply_saved_sort_preference( $orderby, $order );
68 -
69 - $start = self::get_param(
44 + $start = self::get_param(
70 45 array(
71 46 'param' => 'start',
72 47 'default' => ( $page - 1 ) * $per_page,
73 48 )
@@ -99,14 +74,12 @@
99 74 'param' => 's',
100 75 'sanitize' => 'sanitize_text_field',
101 76 )
102 77 );
103 -
104 - if ( $s !== '' ) {
78 + if ( $s != '' ) {
105 79 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
106 80 $search_terms = array_map( 'trim', $matches[0] );
107 -
108 - foreach ( $search_terms as $term ) {
81 + foreach ( (array) $search_terms as $term ) {
109 82 $s_query[] = array(
110 83 'or' => true,
111 84 'name LIKE' => $term,
112 85 'description LIKE' => $term,
@@ -117,10 +90,10 @@
117 90 unset( $term );
118 91 }
119 92 }
120 93
121 - $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
122 - $total_items = FrmDb::get_count( 'frm_forms', $s_query );
94 + $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
95 + $total_items = FrmDb::get_count( 'frm_forms', $s_query );
123 96 $this->total_items = $total_items;
124 97
125 98 $this->set_pagination_args(
126 99 array(
@@ -136,15 +109,13 @@
136 109 public function no_items() {
137 110 if ( $this->status === 'trash' ) {
138 111 echo '<p>';
139 112 esc_html_e( 'No forms found in the trash.', 'formidable' );
140 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
141 113 ?>
142 114 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
143 115 <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
144 116 </a>
145 117 <?php
146 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
147 118 echo '</p>';
148 119 } else {
149 120 $title = __( 'No Forms Found', 'formidable' );
150 121 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_no_forms.php';
@@ -153,9 +124,9 @@
153 124
154 125 public function get_bulk_actions() {
155 126 $actions = array();
156 127
157 - if ( 'trash' === $this->status ) {
128 + if ( 'trash' == $this->status ) {
158 129 if ( current_user_can( 'frm_edit_forms' ) ) {
159 130 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
160 131 }
161 132
@@ -171,34 +142,26 @@
171 142 return $actions;
172 143 }
173 144
174 145 /**
175 - * @param string $which
176 - *
177 146 * @return void
178 147 */
179 148 public function extra_tablenav( $which ) {
180 - if ( 'top' !== $which ) {
149 + if ( 'top' != $which ) {
181 150 return;
182 151 }
183 152
184 - if ( 'trash' !== $this->status || ! current_user_can( 'frm_delete_forms' ) ) {
185 - return;
153 + if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
154 + ?>
155 + <div class="alignleft actions frm_visible_overflow">
156 + <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
157 + </div>
158 + <?php
186 159 }
187 -
188 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
189 - ?>
190 - <div class="alignleft actions frm_visible_overflow">
191 - <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
192 - </div>
193 - <?php
194 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
195 160 }
196 161
197 - /**
198 - * @return array
199 - */
200 162 public function get_views() {
163 +
201 164 $statuses = array(
202 165 'published' => __( 'My Forms', 'formidable' ),
203 166 'draft' => __( 'Drafts', 'formidable' ),
204 167 'trash' => __( 'Trash', 'formidable' ),
@@ -219,13 +182,18 @@
219 182 )
220 183 );
221 184
222 185 foreach ( $statuses as $status => $name ) {
223 - $class = $status == $form_type ? ' class="current"' : ''; // phpcs:ignore Universal.Operators.StrictComparisons
224 186
187 + if ( $status == $form_type ) {
188 + $class = ' class="current"';
189 + } else {
190 + $class = '';
191 + }
192 +
225 193 if ( $counts->{$status} || 'draft' !== $status ) {
226 194 /* translators: %1$s: Status, %2$s: Number of items */
227 - $links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
195 + $links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
228 196 }
229 197
230 198 unset( $status, $name );
231 199 }
@@ -233,15 +201,27 @@
233 201 return $links;
234 202 }
235 203
236 204 /**
205 + * @return void
206 + */
207 + public function pagination( $which ) {
208 + global $mode;
209 +
210 + parent::pagination( $which );
211 +
212 + if ( 'top' === $which ) {
213 + $this->view_switcher( $mode );
214 + }
215 + }
216 +
217 + /**
237 218 * @param stdClass $item
238 219 * @param string $style
239 - *
240 220 * @return string
241 221 */
242 222 public function single_row( $item, $style = '' ) {
243 - global $mode;
223 + global $frm_vars, $mode;
244 224
245 225 // Set up the hover actions for this user
246 226 $actions = array();
247 227 $edit_link = FrmForm::get_edit_link( $item->id );
@@ -248,25 +228,34 @@
248 228
249 229 $this->get_actions( $actions, $item, $edit_link );
250 230
251 231 $action_links = $this->row_actions( $actions );
252 - $checkbox = $this->get_row_checkbox( $item );
253 - $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
254 232
233 + // Set up the checkbox ( because the user is editable, otherwise its empty )
234 + $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
235 + $checkbox_label_text = sprintf(
236 + // translators: Form title
237 + __( 'Select %s', 'formidable' ),
238 + ! empty( $item->name ) ? $item->name : __( '(no title)', 'formidable' )
239 + );
240 +
241 + $checkbox .= '<label for="cb-item-action-' . absint( $item->id ) . '"><span class="screen-reader-text">' . $checkbox_label_text . '</span></label>';
242 +
243 + $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
244 +
255 245 list( $columns, $hidden ) = $this->get_column_info();
256 246
257 247 $format = 'Y/m/d';
258 -
259 - if ( 'list' !== $mode ) {
248 + if ( 'list' != $mode ) {
260 249 $format .= ' \<\b\r \/\> g:i:s a';
261 250 }
262 251
263 252 foreach ( $columns as $column_name => $column_display_name ) {
264 - $class = $column_name . ' column-' . $column_name . ( 'name' === $column_name ? ' post-title page-title column-title' : '' );
253 + $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
254 +
265 255 $style = '';
266 -
267 - if ( in_array( $column_name, $hidden, true ) ) {
268 - $class .= ' hidden';
256 + if ( in_array( $column_name, $hidden ) ) {
257 + $class .= ' frm_hidden';
269 258 }
270 259
271 260 if ( $column_name === 'name' ) {
272 261 $class .= ' column-primary';
@@ -271,10 +260,11 @@
271 260 if ( $column_name === 'name' ) {
272 261 $class .= ' column-primary';
273 262 }
274 263
275 - $class = 'class="' . esc_attr( $class ) . '"';
276 - $attributes = $class . $style . $this->get_column_data_attr( $column_name, $column_display_name );
264 + $class = 'class="' . esc_attr( $class ) . '"';
265 + $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
266 + $attributes = $class . $style . $data_colname;
277 267
278 268 switch ( $column_name ) {
279 269 case 'cb':
280 270 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
@@ -283,9 +273,9 @@
283 273 case 'form_key':
284 274 $val = $item->{$column_name};
285 275 break;
286 276 case 'name':
287 - $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
277 + $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
288 278 $val .= $action_links;
289 279 break;
290 280 case 'created_at':
291 281 $date = gmdate( $format, strtotime( $item->created_at ) );
@@ -291,9 +281,21 @@
291 281 $date = gmdate( $format, strtotime( $item->created_at ) );
292 282 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
293 283 break;
294 284 case 'entries':
295 - $val = $this->get_entries_column_value( $item );
285 + if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
286 + $val = FrmAppHelper::icon_by_class(
287 + 'frmfont frm_forbid_icon frm_bstooltip',
288 + array(
289 + 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
290 + 'echo' => false,
291 + )
292 + );
293 + } else {
294 + $text = FrmEntry::getRecordCount( $item->id );
295 + $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
296 + unset( $text );
297 + }
296 298 break;
297 299 default:
298 300 if ( method_exists( $this, 'column_' . $column_name ) ) {
299 301 $val = call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@@ -307,80 +309,30 @@
307 309 $r .= '</td>';
308 310 }
309 311 unset( $val );
310 312 }//end foreach
311 - return $r . '</tr>';
312 - }
313 + $r .= '</tr>';
313 314
314 - /**
315 - * @param string $column_name
316 - * @param string $column_display_name
317 - *
318 - * @return string
319 - */
320 - private function get_column_data_attr( $column_name, $column_display_name ) {
321 - if ( 'settings' === $column_name ) {
322 - return ' data-colname="' . esc_attr( trim( strip_tags( $column_display_name ) ) ) . '"';
323 - }
324 - return ' data-colname="' . esc_attr( $column_display_name ) . '"';
315 + return $r;
325 316 }
326 317
327 318 /**
328 - * @param object $item
329 - *
330 - * @return string
331 - */
332 - private function get_entries_column_value( $item ) {
333 - if ( ! empty( $item->options['no_save'] ) ) {
334 - return (string) FrmAppHelper::icon_by_class(
335 - 'frmfont frm_forbid_icon frm_bstooltip',
336 - array(
337 - 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
338 - 'echo' => false,
339 - )
340 - );
341 - }
342 -
343 - $text = intval( FrmEntry::getRecordCount( $item->id ) );
344 - return current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : (string) $text; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
345 - }
346 -
347 - /**
348 - * @param object $item
349 - *
350 - * @return string
351 - */
352 - private function get_row_checkbox( $item ) {
353 - // Set up the checkbox (because the user is editable, otherwise it's empty).
354 - $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
355 - $checkbox_label_text = sprintf(
356 - // translators: Form title
357 - __( 'Select %s', 'formidable' ),
358 - ! empty( $item->name ) ? $item->name : FrmFormsHelper::get_no_title_text()
359 - );
360 -
361 - return $checkbox . '<label for="cb-item-action-' . absint( $item->id ) . '"><span class="screen-reader-text">' . esc_html( $checkbox_label_text ) . '</span></label>';
362 - }
363 -
364 - /**
365 319 * Get the HTML for the Actions column in the form list.
366 320 * This includes multiple icons for triggering the embed modal, the visual styler, and an active landing page.
367 321 *
368 322 * @since 6.0
369 - * @deprecated 6.32 We moved these actions to other places. This column will show if there is a filter added to the hook.
370 323 *
371 324 * @param stdClass $form
372 - *
373 325 * @return string
374 326 */
375 327 protected function column_shortcode( $form ) {
376 - $val = '<a href="#" class="frm-embed-form" role="button" aria-label="' . esc_attr__( 'Embed Form', 'formidable' ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_code_icon', array( 'echo' => false ) ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
328 + $val = '<a href="#" class="frm-embed-form" role="button" aria-label="' . esc_html__( 'Embed Form', 'formidable' ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_code_icon', array( 'echo' => false ) ) . '</a>';
377 329 $val .= $this->column_style( $form );
378 - $val .= $this->column_views( $form );
379 330 $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $form ) );
380 331 // Remove the space hard coded in Landing pages.
381 332 $val = str_replace( '&nbsp;', '', $val );
382 - return '<div>' . $val . '</div>';
333 + $val = '<div>' . $val . '</div>';
334 + return $val;
383 335 }
384 336
385 337 /**
386 338 * Get the HTML for the Style column in the form list.
@@ -387,13 +339,12 @@
387 339 *
388 340 * @since 6.0
389 341 *
390 342 * @param stdClass $form
391 - *
392 343 * @return string
393 344 */
394 345 protected function column_style( $form ) {
395 - $style_setting = $form->options['custom_style'] ?? '';
346 + $style_setting = isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : '';
396 347 $frm_settings = FrmAppHelper::get_settings();
397 348
398 349 if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) {
399 350 // Don't show a link if styling is off.
@@ -400,9 +351,8 @@
400 351 return '';
401 352 }
402 353
403 354 $style = FrmStylesController::get_form_style( $form );
404 -
405 355 if ( ! $style ) {
406 356 // Do a second pass to avoid null values.
407 357 $frm_style = new FrmStyle( 'default' );
408 358 $style = $frm_style->get_one();
@@ -408,53 +358,12 @@
408 358 $style = $frm_style->get_one();
409 359 }
410 360
411 361 $href = FrmStylesHelper::get_edit_url( $style, $form->id );
412 - return '<a href="' . esc_url( $href ) . '" title="' . esc_attr( $style->post_title ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_pallet_icon', array( 'echo' => false ) ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
362 + return '<a href="' . esc_url( $href ) . '" title="' . esc_attr( $style->post_title ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_pallet_icon', array( 'echo' => false ) ) . '</a>';
413 363 }
414 364
415 365 /**
416 - * Generate the HTML for the form Views page.
417 - *
418 - * @since 6.19
419 - *
420 - * @param stdClass $form Form object.
421 - *
422 - * @return string
423 - */
424 - protected function column_views( $form ) {
425 - $attributes = array(
426 - 'href' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $form->id ) . '&show_nav=1' ),
427 - 'title' => __( 'Link to list of all views for this form.', 'formidable' ),
428 - 'target' => '_blank',
429 - );
430 -
431 - if ( class_exists( 'FrmViewsDisplay' ) ) {
432 - $view_ids = FrmViewsDisplay::get_display_ids_by_form( $form->id );
433 - $view_count = $view_ids ? count( $view_ids ) : 0;
434 - } else {
435 - $view_count = 0;
436 - }
437 -
438 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
439 - return '<a ' . FrmAppHelper::array_to_html_params( $attributes ) . '>
440 - ' . intval( $view_count ) .
441 - '</a>';
442 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
443 - }
444 -
445 - /**
446 - * Get the HTML for the Settings column in the form list.
447 - *
448 - * @since 6.32
449 - *
450 - * @return string
451 - */
452 - protected function column_settings() {
453 - return '&nbsp;';
454 - }
455 -
456 - /**
457 366 * @param array $actions
458 367 * @param object $item
459 368 * @param string $edit_link
460 369 *
@@ -461,26 +370,25 @@
461 370 * @return void
462 371 */
463 372 private function get_actions( &$actions, $item, $edit_link ) {
464 373 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
465 -
466 374 foreach ( $new_actions as $link => $action ) {
467 375 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
468 376 }
469 377
470 - if ( 'trash' === $this->status ) {
378 + if ( 'trash' == $this->status ) {
471 379 $actions = $new_actions;
380 +
472 381 return;
473 382 }
474 383
475 384 if ( current_user_can( 'frm_edit_forms' ) ) {
476 - $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'formidable' ) . '</a>';
477 - $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . esc_html__( 'Settings', 'formidable' ) . '</a>';
385 + $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
386 + $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
478 387 }
479 388
480 - $actions = array_merge( $actions, $new_actions );
481 - $actions['embed'] = '<a href="#" class="frm-embed-form" role="button" aria-label="' . esc_attr__( 'Embed Form', 'formidable' ) . '">' . esc_html__( 'Embed', 'formidable' ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
482 - $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . esc_html__( 'Preview', 'formidable' ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
389 + $actions = array_merge( $actions, $new_actions );
390 + $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
483 391 }
484 392
485 393 /**
486 394 * @param object $item
@@ -491,25 +399,21 @@
491 399 * @return string
492 400 */
493 401 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
494 402 $form_name = $item->name;
495 -
496 - if ( is_null( $form_name ) || trim( $form_name ) === '' ) {
497 - $form_name = FrmFormsHelper::get_no_title_text();
403 + if ( trim( $form_name ) == '' ) {
404 + $form_name = __( '(no title)', 'formidable' );
498 405 }
499 -
500 406 $form_name = FrmAppHelper::kses( $form_name );
501 -
502 - if ( 'excerpt' !== $mode ) {
407 + if ( 'excerpt' != $mode ) {
503 408 $form_name = FrmAppHelper::truncate( $form_name, 50 );
504 409 }
505 410
506 411 $val = '<strong>';
507 -
508 - if ( 'trash' === $this->status ) {
412 + if ( 'trash' == $this->status ) {
509 413 $val .= $form_name;
510 414 } else {
511 - $val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> '; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
415 + $val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> ';
512 416 }
513 417
514 418 $this->add_draft_label( $item, $val );
515 419 $val .= '</strong>';
@@ -525,10 +429,10 @@
525 429 *
526 430 * @return void
527 431 */
528 432 private function add_draft_label( $item, &$val ) {
529 - if ( 'draft' === $item->status && 'draft' !== $this->status ) {
530 - $val .= ' - <span class="post-state">' . esc_html__( 'Draft', 'formidable' ) . '</span>';
433 + if ( 'draft' == $item->status && 'draft' != $this->status ) {
434 + $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
531 435 }
532 436 }
533 437
534 438 /**
@@ -538,10 +442,9 @@
538 442 * @return void
539 443 */
540 444 private function add_form_description( $item, &$val ) {
541 445 global $mode;
542 -
543 - if ( 'excerpt' === $mode && ! is_null( $item->description ) ) {
446 + if ( 'excerpt' == $mode ) {
544 447 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
545 448 }
546 449 }
547 450
@@ -549,198 +452,6 @@
549 452 * @return string
550 453 */
551 454 protected function confirm_bulk_delete() {
552 455 return __( 'ALL selected forms and their entries will be permanently deleted. Want to proceed?', 'formidable' );
553 - }
554 -
555 - /**
556 - * @param stdClass $form
557 - *
558 - * @return string
559 - */
560 - public function column_embeds( $form ) {
561 - $posts = $this->get_posts_contain_form( $form );
562 -
563 - if ( ! $posts ) {
564 - return '<span class="frm-forms-list-embeds-zero">0</span>';
565 - }
566 -
567 - return FrmAppHelper::clip(
568 - function () use ( $posts ) {
569 - ?>
570 - <a href="#" class="frm-forms-list-embeds-btn" data-posts="<?php echo esc_attr( wp_json_encode( $posts ) ); ?>">
571 - <?php
572 - FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon' );
573 - echo intval( count( $posts ) );
574 - ?>
575 - </a>
576 - <?php
577 - }
578 - );
579 - }
580 -
581 - /**
582 - * Gets posts or pages that contain the form shortcode.
583 - *
584 - * @since 6.32
585 - *
586 - * @param stdClass $form Form object.
587 - *
588 - * @return array
589 - */
590 - private function get_posts_contain_form( $form ) {
591 - $cached_posts = get_transient( self::$embed_posts_transient_name );
592 -
593 - if ( isset( $cached_posts[ $form->id ] ) && is_array( $cached_posts[ $form->id ] ) ) {
594 - return $cached_posts[ $form->id ];
595 - }
596 -
597 - $posts = $this->query_posts_contain_form( $form );
598 -
599 - if ( ! is_array( $posts ) ) {
600 - return array();
601 - }
602 -
603 - foreach ( $posts as $post ) {
604 - if ( ! property_exists( $post, 'permalink' ) ) {
605 - $post->permalink = get_permalink( $post->ID );
606 - }
607 -
608 - if ( ! property_exists( $post, 'edit_link' ) ) {
609 - $post->edit_link = get_edit_post_link( $post->ID );
610 - }
611 -
612 - // Ensure post_name is not null or the string "null"
613 - if ( ! isset( $post->post_name ) ) {
614 - $post->post_name = '';
615 - }
616 -
617 - // Ensure post_title is not null or the string "null"
618 - if ( ! isset( $post->post_title ) ) {
619 - $post->post_title = '';
620 - }
621 -
622 - if ( '' === $post->post_title ) {
623 - $post->post_title = __( '(no title)', 'formidable' );
624 - }
625 - }//end foreach
626 -
627 - if ( ! is_array( $cached_posts ) ) {
628 - $cached_posts = array();
629 - }
630 -
631 - $cached_posts[ $form->id ] = $posts;
632 - set_transient( self::$embed_posts_transient_name, $cached_posts, DAY_IN_SECONDS );
633 -
634 - return $posts;
635 - }
636 -
637 - /**
638 - * Gets search strings for a form inside a post.
639 - *
640 - * @since 6.32
641 - *
642 - * @param int $form_id Form ID.
643 - *
644 - * @return string[]
645 - */
646 - protected function get_search_strings_for_form( $form_id ) {
647 - return $this->get_base_search_strings_for_form( $form_id );
648 - }
649 -
650 - /**
651 - * Gets the base search strings for a form inside a post.
652 - *
653 - * @since 6.32
654 - *
655 - * @param int $form_id Form ID.
656 - *
657 - * @return string[]
658 - */
659 - protected function get_base_search_strings_for_form( $form_id ) {
660 - return array(
661 - '[formidable id=' . $form_id . ']',
662 - '[formidable id=' . $form_id . ' ',
663 - '[formidable id="' . $form_id . '"',
664 - "[formidable id='" . $form_id . "'",
665 - '<!-- wp:formidable/simple-form {"formId":"' . $form_id . '"',
666 - );
667 - }
668 -
669 - /**
670 - * Queries for posts that contain the form shortcode.
671 - *
672 - * @param stdClass $form Form object.
673 - *
674 - * @return array
675 - */
676 - private function query_posts_contain_form( $form ) {
677 - $form_id = $form->id;
678 - global $wpdb;
679 - $query_strings = $this->get_search_strings_for_form( $form_id );
680 - $like_where = array();
681 -
682 - foreach ( $query_strings as $query_string ) {
683 - $like_where[] = $wpdb->remove_placeholder_escape( $wpdb->prepare( 'post_content LIKE %s', '%' . $query_string . '%' ) );
684 - }
685 -
686 - $like_where = implode( ' OR ', $like_where );
687 - $where = "post_type IN ('post', 'page') AND ($like_where)";
688 -
689 - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
690 - $posts = $wpdb->get_results( "SELECT ID,post_title,post_name FROM $wpdb->posts WHERE $where" );
691 -
692 - if ( ! is_array( $posts ) ) {
693 - return array();
694 - }
695 -
696 - /**
697 - * @since 6.32
698 - *
699 - * @param stdClass[] $posts
700 - * @param array $args
701 - */
702 - $filtered_posts = apply_filters( 'frm_get_posts_contain_form', $posts, compact( 'form' ) );
703 -
704 - if ( ! is_array( $filtered_posts ) ) {
705 - _doing_it_wrong( 'frm_get_posts_contain_form', 'Filter should return an array.', '6.32' );
706 - return $posts;
707 - }
708 -
709 - return $filtered_posts;
710 - }
711 -
712 - /**
713 - * Maybe clear the embed posts transient.
714 - *
715 - * @since 6.32
716 - *
717 - * @param int $post_id Post ID.
718 - * @param WP_Post $post Post object.
719 - *
720 - * @return void
721 - */
722 - public static function maybe_clear_embed_posts_transient( $post_id, $post ) {
723 - if ( str_contains( $post->post_content, '[formidable ' ) || str_contains( $post->post_content, '<!-- wp:formidable/simple-form ' ) ) {
724 - // New post contains the form shortcode, so clear the embed posts transient.
725 - delete_transient( self::$embed_posts_transient_name );
726 - return;
727 - }
728 -
729 - $cached_posts = get_transient( self::$embed_posts_transient_name );
730 -
731 - if ( ! is_array( $cached_posts ) ) {
732 - return;
733 - }
734 -
735 - // If the new post data of a cached post doesn't contain the Formidable forms, clear the transient.
736 - foreach ( $cached_posts as $posts ) {
737 - foreach ( $posts as $post_data ) {
738 - if ( intval( $post_data->ID ) === intval( $post_id ) ) {
739 - // This post contains the form shortcode before updating, so clear the embed posts transient.
740 - delete_transient( self::$embed_posts_transient_name );
741 - return;
742 - }
743 - }
744 - }
745 456 }
746 457 }