PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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 +83 -463 6.335.4 View file →
@@ -3,55 +3,30 @@
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 - /**
39 - * @return void
40 - */
41 17 public function prepare_items() {
42 - global $per_page, $mode;
18 + global $wpdb, $per_page, $mode;
43 19
44 20 $page = $this->get_pagenum();
45 21 $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
46 22
47 - $mode = self::get_param(
23 + $mode = self::get_param(
48 24 array(
49 25 'param' => 'mode',
50 26 'default' => 'list',
51 27 )
52 28 );
53 -
54 29 $orderby = self::get_param(
55 30 array(
56 31 'param' => 'orderby',
57 32 'default' => 'name',
@@ -62,12 +37,9 @@
62 37 'param' => 'order',
63 38 'default' => 'ASC',
64 39 )
65 40 );
66 -
67 - FrmAppController::apply_saved_sort_preference( $orderby, $order );
68 -
69 - $start = self::get_param(
41 + $start = self::get_param(
70 42 array(
71 43 'param' => 'start',
72 44 'default' => ( $page - 1 ) * $per_page,
73 45 )
@@ -99,14 +71,12 @@
99 71 'param' => 's',
100 72 'sanitize' => 'sanitize_text_field',
101 73 )
102 74 );
103 -
104 - if ( $s !== '' ) {
75 + if ( $s != '' ) {
105 76 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
106 77 $search_terms = array_map( 'trim', $matches[0] );
107 -
108 - foreach ( $search_terms as $term ) {
78 + foreach ( (array) $search_terms as $term ) {
109 79 $s_query[] = array(
110 80 'or' => true,
111 81 'name LIKE' => $term,
112 82 'description LIKE' => $term,
@@ -117,10 +87,10 @@
117 87 unset( $term );
118 88 }
119 89 }
120 90
121 - $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
122 - $total_items = FrmDb::get_count( 'frm_forms', $s_query );
91 + $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
92 + $total_items = FrmDb::get_count( 'frm_forms', $s_query );
123 93 $this->total_items = $total_items;
124 94
125 95 $this->set_pagination_args(
126 96 array(
@@ -129,22 +99,17 @@
129 99 )
130 100 );
131 101 }
132 102
133 - /**
134 - * @return void
135 - */
136 103 public function no_items() {
137 104 if ( $this->status === 'trash' ) {
138 105 echo '<p>';
139 106 esc_html_e( 'No forms found in the trash.', 'formidable' );
140 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
141 107 ?>
142 108 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
143 109 <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
144 110 </a>
145 111 <?php
146 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
147 112 echo '</p>';
148 113 } else {
149 114 $title = __( 'No Forms Found', 'formidable' );
150 115 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_no_forms.php';
@@ -153,9 +118,9 @@
153 118
154 119 public function get_bulk_actions() {
155 120 $actions = array();
156 121
157 - if ( 'trash' === $this->status ) {
122 + if ( 'trash' == $this->status ) {
158 123 if ( current_user_can( 'frm_edit_forms' ) ) {
159 124 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
160 125 }
161 126
@@ -170,35 +135,24 @@
170 135
171 136 return $actions;
172 137 }
173 138
174 - /**
175 - * @param string $which
176 - *
177 - * @return void
178 - */
179 139 public function extra_tablenav( $which ) {
180 - if ( 'top' !== $which ) {
140 + if ( 'top' != $which ) {
181 141 return;
182 142 }
183 143
184 - if ( 'trash' !== $this->status || ! current_user_can( 'frm_delete_forms' ) ) {
185 - return;
144 + if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
145 + ?>
146 + <div class="alignleft actions frm_visible_overflow">
147 + <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
148 + </div>
149 + <?php
186 150 }
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 151 }
196 152
197 - /**
198 - * @return array
199 - */
200 153 public function get_views() {
154 +
201 155 $statuses = array(
202 156 'published' => __( 'My Forms', 'formidable' ),
203 157 'draft' => __( 'Drafts', 'formidable' ),
204 158 'trash' => __( 'Trash', 'formidable' ),
@@ -205,14 +159,8 @@
205 159 );
206 160
207 161 $links = array();
208 162 $counts = FrmForm::get_count();
209 - $form_type = FrmAppHelper::simple_get( 'form_type', 'sanitize_title', 'published' );
210 -
211 - if ( isset( $statuses[ $form_type ] ) ) {
212 - $counts->$form_type = $this->total_items;
213 - }
214 -
215 163 $form_type = self::get_param(
216 164 array(
217 165 'param' => 'form_type',
218 166 'default' => 'published',
@@ -219,13 +167,18 @@
219 167 )
220 168 );
221 169
222 170 foreach ( $statuses as $status => $name ) {
223 - $class = $status == $form_type ? ' class="current"' : ''; // phpcs:ignore Universal.Operators.StrictComparisons
224 171
172 + if ( $status == $form_type ) {
173 + $class = ' class="current"';
174 + } else {
175 + $class = '';
176 + }
177 +
225 178 if ( $counts->{$status} || 'draft' !== $status ) {
226 179 /* 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
180 + $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 181 }
229 182
230 183 unset( $status, $name );
231 184 }
@@ -232,16 +185,20 @@
232 185
233 186 return $links;
234 187 }
235 188
236 - /**
237 - * @param stdClass $item
238 - * @param string $style
239 - *
240 - * @return string
241 - */
189 + public function pagination( $which ) {
190 + global $mode;
191 +
192 + parent::pagination( $which );
193 +
194 + if ( 'top' === $which ) {
195 + $this->view_switcher( $mode );
196 + }
197 + }
198 +
242 199 public function single_row( $item, $style = '' ) {
243 - global $mode;
200 + global $frm_vars, $mode;
244 201
245 202 // Set up the hover actions for this user
246 203 $actions = array();
247 204 $edit_link = FrmForm::get_edit_link( $item->id );
@@ -248,34 +205,33 @@
248 205
249 206 $this->get_actions( $actions, $item, $edit_link );
250 207
251 208 $action_links = $this->row_actions( $actions );
252 - $checkbox = $this->get_row_checkbox( $item );
253 - $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
254 209
210 + // Set up the checkbox ( because the user is editable, otherwise its empty )
211 + $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
212 +
213 + $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
214 +
255 215 list( $columns, $hidden ) = $this->get_column_info();
256 216
257 217 $format = 'Y/m/d';
258 -
259 - if ( 'list' !== $mode ) {
218 + if ( 'list' != $mode ) {
260 219 $format .= ' \<\b\r \/\> g:i:s a';
261 220 }
262 221
263 222 foreach ( $columns as $column_name => $column_display_name ) {
264 - $class = $column_name . ' column-' . $column_name . ( 'name' === $column_name ? ' post-title page-title column-title' : '' );
223 + $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
224 +
265 225 $style = '';
266 -
267 - if ( in_array( $column_name, $hidden, true ) ) {
268 - $class .= ' hidden';
226 + if ( in_array( $column_name, $hidden ) ) {
227 + $class .= ' frm_hidden';
269 228 }
270 229
271 - if ( $column_name === 'name' ) {
272 - $class .= ' column-primary';
273 - }
230 + $class = 'class="' . esc_attr( $class ) . '"';
231 + $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
232 + $attributes = $class . $style . $data_colname;
274 233
275 - $class = 'class="' . esc_attr( $class ) . '"';
276 - $attributes = $class . $style . $this->get_column_data_attr( $column_name, $column_display_name );
277 -
278 234 switch ( $column_name ) {
279 235 case 'cb':
280 236 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
281 237 break;
@@ -283,17 +239,34 @@
283 239 case 'form_key':
284 240 $val = $item->{$column_name};
285 241 break;
286 242 case 'name':
287 - $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
243 + $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
288 244 $val .= $action_links;
245 +
289 246 break;
290 247 case 'created_at':
291 248 $date = gmdate( $format, strtotime( $item->created_at ) );
292 249 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
293 250 break;
251 + case 'shortcode':
252 + $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>';
253 + $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $item ) );
254 + break;
294 255 case 'entries':
295 - $val = $this->get_entries_column_value( $item );
256 + if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
257 + $val = FrmAppHelper::icon_by_class(
258 + 'frmfont frm_forbid_icon frm_bstooltip',
259 + array(
260 + 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
261 + 'echo' => false,
262 + )
263 + );
264 + } else {
265 + $text = FrmEntry::getRecordCount( $item->id );
266 + $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
267 + unset( $text );
268 + }
296 269 break;
297 270 default:
298 271 if ( method_exists( $this, 'column_' . $column_name ) ) {
299 272 $val = call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@@ -298,9 +271,9 @@
298 271 if ( method_exists( $this, 'column_' . $column_name ) ) {
299 272 $val = call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
300 273 }
301 274 break;
302 - }//end switch
275 + }
303 276
304 277 if ( isset( $val ) ) {
305 278 $r .= "<td $attributes>";
306 279 $r .= $val;
@@ -306,210 +279,56 @@
306 279 $r .= $val;
307 280 $r .= '</td>';
308 281 }
309 282 unset( $val );
310 - }//end foreach
311 - return $r . '</tr>';
312 - }
313 -
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 283 }
324 - return ' data-colname="' . esc_attr( $column_display_name ) . '"';
325 - }
284 + $r .= '</tr>';
326 285
327 - /**
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
286 + return $r;
345 287 }
346 288
347 289 /**
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 - * Get the HTML for the Actions column in the form list.
366 - * This includes multiple icons for triggering the embed modal, the visual styler, and an active landing page.
367 - *
368 - * @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 - *
371 - * @param stdClass $form
372 - *
373 - * @return string
374 - */
375 - 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
377 - $val .= $this->column_style( $form );
378 - $val .= $this->column_views( $form );
379 - $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $form ) );
380 - // Remove the space hard coded in Landing pages.
381 - $val = str_replace( '&nbsp;', '', $val );
382 - return '<div>' . $val . '</div>';
383 - }
384 -
385 - /**
386 - * Get the HTML for the Style column in the form list.
387 - *
388 - * @since 6.0
389 - *
390 - * @param stdClass $form
391 - *
392 - * @return string
393 - */
394 - protected function column_style( $form ) {
395 - $style_setting = $form->options['custom_style'] ?? '';
396 - $frm_settings = FrmAppHelper::get_settings();
397 -
398 - if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) {
399 - // Don't show a link if styling is off.
400 - return '';
401 - }
402 -
403 - $style = FrmStylesController::get_form_style( $form );
404 -
405 - if ( ! $style ) {
406 - // Do a second pass to avoid null values.
407 - $frm_style = new FrmStyle( 'default' );
408 - $style = $frm_style->get_one();
409 - }
410 -
411 - $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
413 - }
414 -
415 - /**
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 - * @param array $actions
458 - * @param object $item
459 290 * @param string $edit_link
460 - *
461 - * @return void
462 291 */
463 292 private function get_actions( &$actions, $item, $edit_link ) {
464 293 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
465 -
466 294 foreach ( $new_actions as $link => $action ) {
467 295 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
468 296 }
469 297
470 - if ( 'trash' === $this->status ) {
298 + if ( 'trash' == $this->status ) {
471 299 $actions = $new_actions;
300 +
472 301 return;
473 302 }
474 303
475 304 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>';
305 + $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
306 + $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
478 307 }
479 308
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
309 + $actions = array_merge( $actions, $new_actions );
310 + $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
483 311 }
484 312
485 313 /**
486 - * @param object $item
487 - * @param array $actions
488 314 * @param string $edit_link
489 - * @param string $mode
490 - *
491 - * @return string
492 315 */
493 316 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
494 317 $form_name = $item->name;
495 -
496 - if ( is_null( $form_name ) || trim( $form_name ) === '' ) {
497 - $form_name = FrmFormsHelper::get_no_title_text();
318 + if ( trim( $form_name ) == '' ) {
319 + $form_name = __( '(no title)', 'formidable' );
498 320 }
499 -
500 321 $form_name = FrmAppHelper::kses( $form_name );
501 -
502 - if ( 'excerpt' !== $mode ) {
322 + if ( 'excerpt' != $mode ) {
503 323 $form_name = FrmAppHelper::truncate( $form_name, 50 );
504 324 }
505 325
506 326 $val = '<strong>';
507 -
508 - if ( 'trash' === $this->status ) {
327 + if ( 'trash' == $this->status ) {
509 328 $val .= $form_name;
510 329 } 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
330 + $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 331 }
513 332
514 333 $this->add_draft_label( $item, $val );
515 334 $val .= '</strong>';
@@ -519,29 +338,22 @@
519 338 return $val;
520 339 }
521 340
522 341 /**
523 - * @param object $item
524 342 * @param string $val
525 - *
526 - * @return void
527 343 */
528 344 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>';
345 + if ( 'draft' == $item->status && 'draft' != $this->status ) {
346 + $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
531 347 }
532 348 }
533 349
534 350 /**
535 - * @param object $item
536 351 * @param string $val
537 - *
538 - * @return void
539 352 */
540 353 private function add_form_description( $item, &$val ) {
541 354 global $mode;
542 -
543 - if ( 'excerpt' === $mode && ! is_null( $item->description ) ) {
355 + if ( 'excerpt' == $mode ) {
544 356 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
545 357 }
546 358 }
547 359
@@ -549,198 +361,6 @@
549 361 * @return string
550 362 */
551 363 protected function confirm_bulk_delete() {
552 364 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 365 }
746 366 }