| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | class FrmFormsController { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Track the form that opened the redirect URL in a new tab. This is used to check if we should show the default |
| 10 | - * message in the currect tab. | |
| 10 | + * message in the current tab. | |
| 11 | 11 | * |
| 12 | 12 | * @since 6.2 |
| 13 | 13 | * |
| 14 | 14 | * @var array Keys are form IDs and values are 1. |
| @@ -14,8 +14,18 @@ | ||
| 14 | 14 | * @var array Keys are form IDs and values are 1. |
| 15 | 15 | */ |
| 16 | 16 | private static $redirected_in_new_tab = array(); |
| 17 | 17 | |
| 18 | + /** | |
| 19 | + * The HTML for the Formdiable TinyMCE button (That triggers a popup to insert shortcodes) | |
| 20 | + * is stored here and re-used as an optimization. | |
| 21 | + * | |
| 22 | + * @since 6.11 | |
| 23 | + * | |
| 24 | + * @var string|null | |
| 25 | + */ | |
| 26 | + private static $formidable_tinymce_button; | |
| 27 | + | |
| 18 | 28 | public static function menu() { |
| 19 | 29 | $menu_label = __( 'Forms', 'formidable' ); |
| 20 | 30 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 21 | 31 | $menu_label .= ' (Lite)'; |
| @@ -54,9 +64,9 @@ | ||
| 54 | 64 | */ |
| 55 | 65 | public static function logic_tip() { |
| 56 | 66 | $images_url = FrmAppHelper::plugin_url() . '/images/'; |
| 57 | 67 | $data_message = __( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', 'formidable' ); |
| 58 | - $data_message .= ' <img src="' . esc_attr( $images_url ) . '/survey-logic.png" srcset="' . esc_attr( $images_url ) . 'survey-logic@2x.png 2x" alt="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '"/>'; | |
| 68 | + $data_message .= ' <img src="' . esc_url( $images_url ) . '/survey-logic.png" srcset="' . esc_url( $images_url ) . 'survey-logic@2x.png 2x" alt="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '"/>'; | |
| 59 | 69 | echo '<a href="javascript:void(0)" class="frm_noallow frm_show_upgrade frm_add_logic_link frm-collapsed frm-flex-justify" data-upgrade="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '" data-message="' . esc_attr( $data_message ) . '" data-medium="builder" data-content="logic">'; |
| 60 | 70 | esc_html_e( 'Conditional Logic', 'formidable' ); |
| 61 | 71 | FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon', array( 'aria-hidden' => 'true' ) ); |
| 62 | 72 | echo '</a>'; |
| @@ -96,9 +106,9 @@ | ||
| 96 | 106 | * Create the default email action |
| 97 | 107 | * |
| 98 | 108 | * @since 2.02.11 |
| 99 | 109 | * |
| 100 | - * @param object|int $form | |
| 110 | + * @param int|object $form | |
| 101 | 111 | */ |
| 102 | 112 | private static function create_default_email_action( $form ) { |
| 103 | 113 | FrmForm::maybe_get_form( $form ); |
| 104 | 114 | $create_email = apply_filters( 'frm_create_default_email_action', true, $form ); |
| @@ -103,8 +113,11 @@ | ||
| 103 | 113 | FrmForm::maybe_get_form( $form ); |
| 104 | 114 | $create_email = apply_filters( 'frm_create_default_email_action', true, $form ); |
| 105 | 115 | |
| 106 | 116 | if ( $create_email ) { |
| 117 | + /** | |
| 118 | + * @var FrmFormAction | |
| 119 | + */ | |
| 107 | 120 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
| 108 | 121 | $action_control->create( $form->id ); |
| 109 | 122 | } |
| 110 | 123 | } |
| @@ -113,9 +126,9 @@ | ||
| 113 | 126 | * Create the default On submit action |
| 114 | 127 | * |
| 115 | 128 | * @since 6.0.0 |
| 116 | 129 | * |
| 117 | - * @param object|int $form Form object or ID. | |
| 130 | + * @param int|object $form Form object or ID. | |
| 118 | 131 | */ |
| 119 | 132 | private static function create_default_on_submit_action( $form ) { |
| 120 | 133 | FrmForm::maybe_get_form( $form ); |
| 121 | 134 | |
| @@ -129,21 +142,61 @@ | ||
| 129 | 142 | */ |
| 130 | 143 | $create = apply_filters( 'frm_create_default_on_submit_action', true, $form ); |
| 131 | 144 | |
| 132 | 145 | if ( $create ) { |
| 146 | + /** | |
| 147 | + * @var FrmFormAction | |
| 148 | + */ | |
| 133 | 149 | $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug ); |
| 134 | 150 | $action_control->create( $form->id ); |
| 135 | 151 | } |
| 136 | 152 | } |
| 137 | 153 | |
| 154 | + /** | |
| 155 | + * Creates submit button field. | |
| 156 | + * | |
| 157 | + * @since 6.9 | |
| 158 | + * | |
| 159 | + * @param int|object $form Form ID or object. | |
| 160 | + */ | |
| 161 | + private static function create_submit_button_field( $form ) { | |
| 162 | + FrmForm::maybe_get_form( $form ); | |
| 163 | + | |
| 164 | + if ( FrmSubmitHelper::get_submit_field( $form->id ) ) { | |
| 165 | + // Do not create submit button field if it exists. | |
| 166 | + return; | |
| 167 | + } | |
| 168 | + | |
| 169 | + FrmField::create( | |
| 170 | + array( | |
| 171 | + 'type' => FrmSubmitHelper::FIELD_TYPE, | |
| 172 | + 'name' => __( 'Submit', 'formidable' ), | |
| 173 | + 'field_order' => 9999, | |
| 174 | + 'form_id' => $form->id, | |
| 175 | + 'field_options' => FrmFieldsHelper::get_default_field_options( FrmSubmitHelper::FIELD_TYPE ), | |
| 176 | + 'description' => '', | |
| 177 | + 'default_value' => '', | |
| 178 | + 'options' => array(), | |
| 179 | + ) | |
| 180 | + ); | |
| 181 | + } | |
| 182 | + | |
| 183 | + /** | |
| 184 | + * @return void | |
| 185 | + */ | |
| 138 | 186 | public static function edit( $values = false ) { |
| 139 | 187 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 140 | 188 | |
| 141 | 189 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 142 | 190 | |
| 143 | - return self::get_edit_vars( $id ); | |
| 191 | + self::get_edit_vars( $id ); | |
| 144 | 192 | } |
| 145 | 193 | |
| 194 | + /** | |
| 195 | + * @param mixed $id | |
| 196 | + * @param string $message | |
| 197 | + * @return void | |
| 198 | + */ | |
| 146 | 199 | public static function settings( $id = false, $message = '' ) { |
| 147 | 200 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 148 | 201 | |
| 149 | 202 | if ( ! $id || ! is_numeric( $id ) ) { |
| @@ -151,21 +204,34 @@ | ||
| 151 | 204 | } |
| 152 | 205 | |
| 153 | 206 | FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id ); |
| 154 | 207 | |
| 155 | - return self::get_settings_vars( $id, array(), $message ); | |
| 208 | + self::get_settings_vars( $id, array(), $message ); | |
| 156 | 209 | } |
| 157 | 210 | |
| 158 | 211 | public static function update_settings() { |
| 159 | 212 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 213 | + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); | |
| 160 | 214 | |
| 215 | + if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { | |
| 216 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 217 | + $error_args = array( | |
| 218 | + 'title' => __( 'Verification failed', 'formidable' ), | |
| 219 | + 'body' => $frm_settings->admin_permission, | |
| 220 | + 'cancel_text' => __( 'Cancel', 'formidable' ), | |
| 221 | + ); | |
| 222 | + FrmAppController::show_error_modal( $error_args ); | |
| 223 | + return; | |
| 224 | + } | |
| 225 | + | |
| 161 | 226 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 162 | 227 | |
| 163 | - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 228 | + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 164 | 229 | $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 165 | 230 | |
| 166 | 231 | if ( count( $errors ) > 0 ) { |
| 167 | - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); | |
| 232 | + self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); | |
| 233 | + return; | |
| 168 | 234 | } |
| 169 | 235 | |
| 170 | 236 | do_action( 'frm_before_update_form_settings', $id ); |
| 171 | 237 | |
| @@ -179,9 +245,9 @@ | ||
| 179 | 245 | } |
| 180 | 246 | |
| 181 | 247 | $message = __( 'Settings Successfully Updated', 'formidable' ); |
| 182 | 248 | |
| 183 | - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); | |
| 249 | + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); | |
| 184 | 250 | } |
| 185 | 251 | |
| 186 | 252 | /** |
| 187 | 253 | * @param int $form_id |
| @@ -191,8 +257,11 @@ | ||
| 191 | 257 | $form = FrmForm::getOne( $form_id ); |
| 192 | 258 | return ! empty( $form->options['antispam'] ); |
| 193 | 259 | } |
| 194 | 260 | |
| 261 | + /** | |
| 262 | + * @return void | |
| 263 | + */ | |
| 195 | 264 | public static function update( $values = array() ) { |
| 196 | 265 | if ( empty( $values ) ) { |
| 197 | 266 | $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 198 | 267 | } |
| @@ -210,65 +279,74 @@ | ||
| 210 | 279 | |
| 211 | 280 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 212 | 281 | |
| 213 | 282 | if ( count( $errors ) > 0 ) { |
| 214 | - return self::get_edit_vars( $id, $errors ); | |
| 215 | - } else { | |
| 216 | - FrmForm::update( $id, $values ); | |
| 217 | - $message = __( 'Form was successfully updated.', 'formidable' ); | |
| 283 | + self::get_edit_vars( $id, $errors ); | |
| 284 | + return; | |
| 285 | + } | |
| 218 | 286 | |
| 219 | - if ( self::is_too_long( $values ) ) { | |
| 220 | - $message .= '<br/> ' . sprintf( | |
| 221 | - /* translators: %1$s: Start link HTML, %2$s: end link HTML */ | |
| 222 | - __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ), | |
| 223 | - '<a href="https://formidableforms.com/knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/?utm_source=WordPress&utm_medium=builder&utm_campaign=liteplugin" target="_blank" rel="noopener">', | |
| 224 | - '</a>' | |
| 225 | - ); | |
| 226 | - } | |
| 287 | + self::maybe_remove_draft_option_from_fields( $id ); | |
| 227 | 288 | |
| 228 | - if ( defined( 'DOING_AJAX' ) ) { | |
| 229 | - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 230 | - } | |
| 289 | + FrmForm::update( $id, $values ); | |
| 290 | + $message = __( 'Form was successfully updated.', 'formidable' ); | |
| 231 | 291 | |
| 232 | - return self::get_edit_vars( $id, array(), $message ); | |
| 292 | + if ( self::is_too_long( $values ) ) { | |
| 293 | + $message .= '<br/> ' . sprintf( | |
| 294 | + /* translators: %1$s: Start link HTML, %2$s: end link HTML */ | |
| 295 | + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ), | |
| 296 | + '<a href="https://formidableforms.com/knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/?utm_source=WordPress&utm_medium=builder&utm_campaign=liteplugin" target="_blank" rel="noopener">', | |
| 297 | + '</a>' | |
| 298 | + ); | |
| 233 | 299 | } |
| 300 | + | |
| 301 | + if ( defined( 'DOING_AJAX' ) ) { | |
| 302 | + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 303 | + } | |
| 304 | + | |
| 305 | + self::get_edit_vars( $id, array(), $message ); | |
| 234 | 306 | } |
| 235 | 307 | |
| 236 | 308 | /** |
| 309 | + * Remove the draft flag from any new fields from this current session. | |
| 310 | + * | |
| 311 | + * @since 6.8 | |
| 312 | + * | |
| 313 | + * @param int $form_id | |
| 314 | + * @return void | |
| 315 | + */ | |
| 316 | + private static function maybe_remove_draft_option_from_fields( $form_id ) { | |
| 317 | + $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' ); | |
| 318 | + if ( ! $draft_field_ids_csv ) { | |
| 319 | + // If the draft_fields input is empty there are no new fields in the session. | |
| 320 | + return; | |
| 321 | + } | |
| 322 | + | |
| 323 | + $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' ); | |
| 324 | + if ( ! $draft_field_ids ) { | |
| 325 | + // Exit early if the draft fields input is invalid. It should be a CSV of integer values. | |
| 326 | + return; | |
| 327 | + } | |
| 328 | + | |
| 329 | + $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids ); | |
| 330 | + foreach ( $draft_field_rows as $row ) { | |
| 331 | + $row->field_options['draft'] = 0; | |
| 332 | + FrmField::update( $row->id, array( 'field_options' => $row->field_options ) ); | |
| 333 | + } | |
| 334 | + } | |
| 335 | + | |
| 336 | + /** | |
| 237 | 337 | * Check if the value at the end of the form was included. |
| 238 | 338 | * If it's missing, it means other values at the end of the form |
| 239 | 339 | * were likely not saved either. |
| 240 | 340 | * |
| 241 | 341 | * @since 3.06.01 |
| 342 | + * | |
| 343 | + * @return bool | |
| 242 | 344 | */ |
| 243 | 345 | private static function is_too_long( $values ) { |
| 244 | - return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] ); | |
| 346 | + return empty( $values['frm_end'] ); | |
| 245 | 347 | } |
| 246 | 348 | |
| 247 | - /** | |
| 248 | - * Redirect to the url for creating from a template | |
| 249 | - * Also delete the current form | |
| 250 | - * | |
| 251 | - * @since 2.0 | |
| 252 | - * @deprecated 3.06 | |
| 253 | - */ | |
| 254 | - public static function _create_from_template() { | |
| 255 | - _deprecated_function( __FUNCTION__, '3.06' ); | |
| 256 | - | |
| 257 | - FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 258 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 259 | - | |
| 260 | - $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' ); | |
| 261 | - $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); | |
| 262 | - | |
| 263 | - if ( $current_form ) { | |
| 264 | - FrmForm::destroy( $current_form ); | |
| 265 | - } | |
| 266 | - | |
| 267 | - echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) ); | |
| 268 | - wp_die(); | |
| 269 | - } | |
| 270 | - | |
| 271 | 349 | public static function duplicate() { |
| 272 | 350 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 273 | 351 | $nonce = FrmAppHelper::simple_get( '_wpnonce' ); |
| 274 | 352 | |
| @@ -282,10 +360,11 @@ | ||
| 282 | 360 | $url = admin_url( 'admin.php?page=formidable' ); |
| 283 | 361 | $message = 'form_duplicate_error'; |
| 284 | 362 | |
| 285 | 363 | if ( $form ) { |
| 286 | - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) ); | |
| 287 | - $message = 'form_duplicated'; | |
| 364 | + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : ''; | |
| 365 | + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template ); | |
| 366 | + $message = 'form_duplicated'; | |
| 288 | 367 | } |
| 289 | 368 | |
| 290 | 369 | $url .= '&message=' . $message; |
| 291 | 370 | |
| @@ -293,24 +372,28 @@ | ||
| 293 | 372 | exit(); |
| 294 | 373 | } |
| 295 | 374 | |
| 296 | 375 | /** |
| 297 | - * @return string | |
| 376 | + * @return string|null | |
| 298 | 377 | */ |
| 299 | 378 | public static function page_preview() { |
| 300 | 379 | $params = FrmForm::list_page_params(); |
| 301 | 380 | if ( ! $params['form'] ) { |
| 302 | - return; | |
| 381 | + return null; | |
| 303 | 382 | } |
| 304 | 383 | |
| 305 | 384 | $form = FrmForm::getOne( $params['form'] ); |
| 306 | - if ( $form ) { | |
| 307 | - return self::show_form( $form->id, '', 'auto', 'auto' ); | |
| 385 | + if ( ! $form ) { | |
| 386 | + return null; | |
| 308 | 387 | } |
| 388 | + | |
| 389 | + return self::show_form( $form->id, '', 'auto', 'auto' ); | |
| 309 | 390 | } |
| 310 | 391 | |
| 311 | 392 | /** |
| 312 | 393 | * @since 3.0 |
| 394 | + * | |
| 395 | + * @return void | |
| 313 | 396 | */ |
| 314 | 397 | public static function show_page_preview() { |
| 315 | 398 | echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 316 | 399 | } |
| @@ -360,8 +443,13 @@ | ||
| 360 | 443 | return; |
| 361 | 444 | } |
| 362 | 445 | |
| 363 | 446 | $random_page = reset( $random_page ); |
| 447 | + if ( ! is_a( $random_page, 'WP_Post' ) ) { | |
| 448 | + // The return type can also be int. | |
| 449 | + return; | |
| 450 | + } | |
| 451 | + | |
| 364 | 452 | query_posts( |
| 365 | 453 | array( |
| 366 | 454 | 'post_type' => 'page', |
| 367 | 455 | 'page_id' => $random_page->ID, |
| @@ -377,9 +465,9 @@ | ||
| 377 | 465 | * Set the WP $post global object. Used for in-theme preview when defining a page. |
| 378 | 466 | * |
| 379 | 467 | * @since 5.5.2 |
| 380 | 468 | * |
| 381 | - * @param WP_Post $post | |
| 469 | + * @param WP_Post $page The page object. | |
| 382 | 470 | * @return void |
| 383 | 471 | */ |
| 384 | 472 | private static function set_post_global( $page ) { |
| 385 | 473 | global $post; |
| @@ -387,8 +475,10 @@ | ||
| 387 | 475 | } |
| 388 | 476 | |
| 389 | 477 | /** |
| 390 | 478 | * @since 3.0 |
| 479 | + * | |
| 480 | + * @return void | |
| 391 | 481 | */ |
| 392 | 482 | private static function load_theme_preview() { |
| 393 | 483 | add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 ); |
| 394 | 484 | add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 ); |
| @@ -397,20 +487,39 @@ | ||
| 397 | 487 | add_filter( 'is_active_sidebar', '__return_false' ); |
| 398 | 488 | FrmStylesController::enqueue_css( 'enqueue', true ); |
| 399 | 489 | |
| 400 | 490 | if ( false === get_template_part( 'page' ) ) { |
| 491 | + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { | |
| 492 | + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' ); | |
| 493 | + } | |
| 401 | 494 | self::fallback_when_page_template_part_is_not_supported_by_theme(); |
| 402 | 495 | } |
| 403 | 496 | } |
| 404 | 497 | |
| 405 | 498 | /** |
| 499 | + * Add padding to the body for block themes. | |
| 500 | + * | |
| 501 | + * @since 6.5.2 | |
| 502 | + * | |
| 503 | + * @param array $classes The body classes list. | |
| 504 | + * @return array | |
| 505 | + */ | |
| 506 | + public static function preview_block_theme_body_classnames( $classes ) { | |
| 507 | + $classes[] = 'has-global-padding'; | |
| 508 | + return $classes; | |
| 509 | + } | |
| 510 | + | |
| 511 | + /** | |
| 406 | 512 | * Not every theme supports get_template_part( 'page' ). |
| 407 | 513 | * When this is not supported, false is returned, and we can handle a fallback. |
| 514 | + * | |
| 515 | + * @return void | |
| 408 | 516 | */ |
| 409 | 517 | private static function fallback_when_page_template_part_is_not_supported_by_theme() { |
| 410 | 518 | if ( have_posts() ) { |
| 411 | 519 | the_post(); |
| 412 | - get_header( '' ); | |
| 520 | + self::get_template( 'header' ); | |
| 521 | + | |
| 413 | 522 | // add some generic class names to the container to add some natural padding to the content. |
| 414 | 523 | // .entry-content catches the WordPress TwentyTwenty theme. |
| 415 | 524 | // .container catches Customizr content. |
| 416 | 525 | echo '<div class="container entry-content">'; |
| @@ -415,13 +524,54 @@ | ||
| 415 | 524 | // .container catches Customizr content. |
| 416 | 525 | echo '<div class="container entry-content">'; |
| 417 | 526 | the_content(); |
| 418 | 527 | echo '</div>'; |
| 419 | - get_footer(); | |
| 528 | + | |
| 529 | + self::get_template( 'footer' ); | |
| 420 | 530 | } |
| 421 | 531 | } |
| 422 | 532 | |
| 423 | 533 | /** |
| 534 | + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call | |
| 535 | + * and renders required html fragments calling required functions. | |
| 536 | + * | |
| 537 | + * @since 6.7.1 | |
| 538 | + * @param string $template | |
| 539 | + * @return void | |
| 540 | + */ | |
| 541 | + private static function get_template( $template ) { | |
| 542 | + if ( self::should_try_getting_template( $template ) ) { | |
| 543 | + call_user_func( 'get_' . $template ); | |
| 544 | + return; | |
| 545 | + } | |
| 546 | + | |
| 547 | + if ( 'header' === $template ) { | |
| 548 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php'; | |
| 549 | + return; | |
| 550 | + } | |
| 551 | + | |
| 552 | + if ( 'footer' === $template ) { | |
| 553 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php'; | |
| 554 | + } | |
| 555 | + } | |
| 556 | + | |
| 557 | + /** | |
| 558 | + * Returns true if calling a template function doesn't trigger deprecation warnings. | |
| 559 | + * | |
| 560 | + * @since 6.7.1 | |
| 561 | + * @param string $template | |
| 562 | + * @return bool | |
| 563 | + */ | |
| 564 | + private static function should_try_getting_template( $template ) { | |
| 565 | + $stylesheet_path = get_stylesheet_directory(); | |
| 566 | + $template_path = get_template_directory(); | |
| 567 | + $is_child_theme = $stylesheet_path !== $template_path; | |
| 568 | + $template_name = $template . '.php'; | |
| 569 | + | |
| 570 | + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name ); | |
| 571 | + } | |
| 572 | + | |
| 573 | + /** | |
| 424 | 574 | * Set the page title for the theme preview page |
| 425 | 575 | * |
| 426 | 576 | * @since 3.0 |
| 427 | 577 | */ |
| @@ -433,11 +583,14 @@ | ||
| 433 | 583 | return $title; |
| 434 | 584 | } |
| 435 | 585 | |
| 436 | 586 | /** |
| 437 | - * Set the page title for the theme preview page | |
| 587 | + * Set the page title for the theme preview page. | |
| 438 | 588 | * |
| 439 | 589 | * @since 3.0 |
| 590 | + * | |
| 591 | + * @param string $title | |
| 592 | + * @return string | |
| 440 | 593 | */ |
| 441 | 594 | public static function preview_title( $title ) { |
| 442 | 595 | return __( 'Form Preview', 'formidable' ); |
| 443 | 596 | } |
| @@ -442,15 +595,20 @@ | ||
| 442 | 595 | return __( 'Form Preview', 'formidable' ); |
| 443 | 596 | } |
| 444 | 597 | |
| 445 | 598 | /** |
| 446 | - * Set the page content for the theme preview page | |
| 599 | + * Set the page content for the theme preview page. | |
| 447 | 600 | * |
| 448 | 601 | * @since 3.0 |
| 602 | + * | |
| 603 | + * @param string $content | |
| 604 | + * @return string | |
| 449 | 605 | */ |
| 450 | 606 | public static function preview_content( $content ) { |
| 451 | 607 | if ( in_the_loop() ) { |
| 452 | - $content = self::show_page_preview(); | |
| 608 | + self::show_page_preview(); | |
| 609 | + // Clear the content for the page we're using. | |
| 610 | + $content = ''; | |
| 453 | 611 | } |
| 454 | 612 | |
| 455 | 613 | return $content; |
| 456 | 614 | } |
| @@ -460,8 +618,11 @@ | ||
| 460 | 618 | */ |
| 461 | 619 | private static function load_direct_preview() { |
| 462 | 620 | header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
| 463 | 621 | |
| 622 | + // print_emoji_styles is deprecated. | |
| 623 | + remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
| 624 | + | |
| 464 | 625 | $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' ); |
| 465 | 626 | if ( $key == '' ) { |
| 466 | 627 | $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' ); |
| 467 | 628 | } |
| @@ -470,11 +631,38 @@ | ||
| 470 | 631 | if ( empty( $form ) ) { |
| 471 | 632 | $form = FrmForm::getAll( array(), '', 1 ); |
| 472 | 633 | } |
| 473 | 634 | |
| 474 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' ); | |
| 635 | + self::fix_deprecated_null_param_warning(); | |
| 636 | + | |
| 637 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php'; | |
| 475 | 638 | } |
| 476 | 639 | |
| 640 | + /** | |
| 641 | + * Some themes have a null $src value. | |
| 642 | + * This function adds a filter to ensure that $src is not null. | |
| 643 | + * WP will call str_starts_with with the null value triggering a deprecated message otherwise. | |
| 644 | + * | |
| 645 | + * @since 6.10 | |
| 646 | + * | |
| 647 | + * @return void | |
| 648 | + */ | |
| 649 | + private static function fix_deprecated_null_param_warning() { | |
| 650 | + add_filter( | |
| 651 | + 'script_loader_src', | |
| 652 | + /** | |
| 653 | + * @param string|null $src | |
| 654 | + * @return string | |
| 655 | + */ | |
| 656 | + function ( $src ) { | |
| 657 | + if ( is_null( $src ) ) { | |
| 658 | + $src = ''; | |
| 659 | + } | |
| 660 | + return $src; | |
| 661 | + } | |
| 662 | + ); | |
| 663 | + } | |
| 664 | + | |
| 477 | 665 | public static function untrash() { |
| 478 | 666 | self::change_form_status( 'untrash' ); |
| 479 | 667 | } |
| 480 | 668 | |
| @@ -537,14 +725,14 @@ | ||
| 537 | 725 | FrmAppHelper::permission_check( $available_status[ $status ]['permission'] ); |
| 538 | 726 | |
| 539 | 727 | $params = FrmForm::list_page_params(); |
| 540 | 728 | |
| 541 | - //check nonce url | |
| 729 | + // Check nonce url. | |
| 542 | 730 | check_admin_referer( $status . '_form_' . $params['id'] ); |
| 543 | 731 | |
| 544 | 732 | $count = 0; |
| 545 | 733 | if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) { |
| 546 | - $count ++; | |
| 734 | + ++$count; | |
| 547 | 735 | } |
| 548 | 736 | |
| 549 | 737 | $form_type = FrmAppHelper::get_simple_request( |
| 550 | 738 | array( |
| @@ -556,9 +744,9 @@ | ||
| 556 | 744 | /* translators: %1$s: Number of forms */ |
| 557 | 745 | $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count ); |
| 558 | 746 | |
| 559 | 747 | /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */ |
| 560 | - $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' ); | |
| 748 | + $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' ); | |
| 561 | 749 | |
| 562 | 750 | $message = $available_status[ $status ]['message']; |
| 563 | 751 | |
| 564 | 752 | self::display_forms_list( $params, $message ); |
| @@ -563,8 +751,12 @@ | ||
| 563 | 751 | |
| 564 | 752 | self::display_forms_list( $params, $message ); |
| 565 | 753 | } |
| 566 | 754 | |
| 755 | + /** | |
| 756 | + * @param array $ids | |
| 757 | + * @return string | |
| 758 | + */ | |
| 567 | 759 | public static function bulk_trash( $ids ) { |
| 568 | 760 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 569 | 761 | |
| 570 | 762 | $count = 0; |
| @@ -569,9 +761,9 @@ | ||
| 569 | 761 | |
| 570 | 762 | $count = 0; |
| 571 | 763 | foreach ( $ids as $id ) { |
| 572 | 764 | if ( FrmForm::trash( $id ) ) { |
| 573 | - $count ++; | |
| 765 | + ++$count; | |
| 574 | 766 | } |
| 575 | 767 | } |
| 576 | 768 | |
| 577 | 769 | $current_page = FrmAppHelper::get_simple_request( |
| @@ -600,9 +792,9 @@ | ||
| 600 | 792 | check_admin_referer( 'destroy_form_' . $params['id'] ); |
| 601 | 793 | |
| 602 | 794 | $count = 0; |
| 603 | 795 | if ( FrmForm::destroy( $params['id'] ) ) { |
| 604 | - $count ++; | |
| 796 | + ++$count; | |
| 605 | 797 | } |
| 606 | 798 | |
| 607 | 799 | /* translators: %1$s: Number of forms */ |
| 608 | 800 | $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count ); |
| @@ -609,8 +801,12 @@ | ||
| 609 | 801 | |
| 610 | 802 | self::display_forms_list( $params, $message ); |
| 611 | 803 | } |
| 612 | 804 | |
| 805 | + /** | |
| 806 | + * @param array $ids | |
| 807 | + * @return string | |
| 808 | + */ | |
| 613 | 809 | public static function bulk_destroy( $ids ) { |
| 614 | 810 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 615 | 811 | |
| 616 | 812 | $count = 0; |
| @@ -616,19 +812,24 @@ | ||
| 616 | 812 | $count = 0; |
| 617 | 813 | foreach ( $ids as $id ) { |
| 618 | 814 | $d = FrmForm::destroy( $id ); |
| 619 | 815 | if ( $d ) { |
| 620 | - $count ++; | |
| 816 | + ++$count; | |
| 621 | 817 | } |
| 622 | 818 | } |
| 623 | 819 | |
| 624 | - /* translators: %1$s: Number of forms */ | |
| 625 | - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 820 | + if ( $count ) { | |
| 821 | + /* translators: %1$s: Number of forms */ | |
| 822 | + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 823 | + } | |
| 626 | 824 | |
| 627 | - return $message; | |
| 825 | + return ''; | |
| 628 | 826 | } |
| 629 | 827 | |
| 630 | - private static function delete_all() { | |
| 828 | + /** | |
| 829 | + * @since 6.7.1 Function went from private to public. | |
| 830 | + */ | |
| 831 | + public static function delete_all() { | |
| 631 | 832 | // Check nonce url. |
| 632 | 833 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
| 633 | 834 | if ( $permission_error !== false ) { |
| 634 | 835 | self::display_forms_list( array(), '', array( $permission_error ) ); |
| @@ -635,14 +836,15 @@ | ||
| 635 | 836 | |
| 636 | 837 | return; |
| 637 | 838 | } |
| 638 | 839 | |
| 639 | - $count = FrmForm::scheduled_delete( time() ); | |
| 840 | + $count = FrmForm::scheduled_delete( time() ); | |
| 841 | + $url = remove_query_arg( array( 'delete_all' ) ); | |
| 640 | 842 | |
| 641 | - /* translators: %1$s: Number of forms */ | |
| 642 | - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 843 | + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count; | |
| 643 | 844 | |
| 644 | - self::display_forms_list( array(), $message ); | |
| 845 | + wp_safe_redirect( $url ); | |
| 846 | + die(); | |
| 645 | 847 | } |
| 646 | 848 | |
| 647 | 849 | /** |
| 648 | 850 | * Create a new form from the modal. |
| @@ -655,9 +857,9 @@ | ||
| 655 | 857 | |
| 656 | 858 | $new_values = self::get_modal_values(); |
| 657 | 859 | $new_values['form_key'] = $new_values['name']; |
| 658 | 860 | $new_values['options'] = array( |
| 659 | - 'antispam' => 1, | |
| 861 | + 'antispam' => 1, | |
| 660 | 862 | 'on_submit_migrated' => 1, |
| 661 | 863 | ); |
| 662 | 864 | |
| 663 | 865 | /** |
| @@ -676,13 +878,14 @@ | ||
| 676 | 878 | * @param int $form_id |
| 677 | 879 | */ |
| 678 | 880 | do_action( 'frm_build_new_form', $form_id ); |
| 679 | 881 | |
| 882 | + self::create_submit_button_field( $form_id ); | |
| 680 | 883 | self::create_default_on_submit_action( $form_id ); |
| 681 | 884 | self::create_default_email_action( $form_id ); |
| 682 | 885 | |
| 683 | 886 | $response = array( |
| 684 | - 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 887 | + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 685 | 888 | ); |
| 686 | 889 | |
| 687 | 890 | echo wp_json_encode( $response ); |
| 688 | 891 | wp_die(); |
| @@ -688,46 +891,15 @@ | ||
| 688 | 891 | wp_die(); |
| 689 | 892 | } |
| 690 | 893 | |
| 691 | 894 | /** |
| 692 | - * Create a custom template from a form | |
| 693 | - * | |
| 694 | - * @since 3.06 | |
| 695 | - */ | |
| 696 | - public static function build_template() { | |
| 697 | - global $wpdb; | |
| 698 | - | |
| 699 | - FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 700 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 701 | - | |
| 702 | - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' ); | |
| 703 | - $new_form_id = FrmForm::duplicate( $form_id, 1, true ); | |
| 704 | - if ( ! $new_form_id ) { | |
| 705 | - $response = array( | |
| 706 | - 'message' => __( 'There was an error creating a template.', 'formidable' ), | |
| 707 | - ); | |
| 708 | - } else { | |
| 709 | - $new_values = self::get_modal_values(); | |
| 710 | - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) ); | |
| 711 | - if ( $query_results ) { | |
| 712 | - FrmForm::clear_form_cache(); | |
| 713 | - } | |
| 714 | - | |
| 715 | - $response = array( | |
| 716 | - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(), | |
| 717 | - ); | |
| 718 | - } | |
| 719 | - | |
| 720 | - echo wp_json_encode( $response ); | |
| 721 | - wp_die(); | |
| 722 | - } | |
| 723 | - | |
| 724 | - /** | |
| 725 | 895 | * Before creating a new form, get the name and description from the modal. |
| 726 | 896 | * |
| 727 | 897 | * @since 4.0 |
| 898 | + * | |
| 899 | + * @return array<string,string> | |
| 728 | 900 | */ |
| 729 | - private static function get_modal_values() { | |
| 901 | + public static function get_modal_values() { | |
| 730 | 902 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 731 | 903 | $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 732 | 904 | |
| 733 | 905 | return array( |
| @@ -740,17 +912,24 @@ | ||
| 740 | 912 | * Inserts Formidable button |
| 741 | 913 | * Hook exists since 2.5.0 |
| 742 | 914 | * |
| 743 | 915 | * @since 2.0.15 |
| 916 | + * | |
| 917 | + * @return void | |
| 744 | 918 | */ |
| 745 | 919 | public static function insert_form_button() { |
| 746 | 920 | if ( current_user_can( 'frm_view_forms' ) ) { |
| 747 | - FrmAppHelper::load_admin_wide_js(); | |
| 748 | - $menu_name = FrmAppHelper::get_menu_name(); | |
| 749 | - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() ); | |
| 750 | - echo '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' . | |
| 751 | - FrmAppHelper::kses( $icon, 'all' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 752 | - ' ' . esc_html( $menu_name ) . '</a>'; | |
| 921 | + // Store the result in memory and re-use it when this function is called multiple times. | |
| 922 | + // This helps speed up the form builder when there are a lot of HTML fields, where this | |
| 923 | + // button is inserted once per HTML field. | |
| 924 | + // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally. | |
| 925 | + if ( ! isset( self::$formidable_tinymce_button ) ) { | |
| 926 | + FrmAppHelper::load_admin_wide_js(); | |
| 927 | + $menu_name = FrmAppHelper::get_menu_name(); | |
| 928 | + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() ); | |
| 929 | + self::$formidable_tinymce_button = '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' . FrmAppHelper::kses( $icon, 'all' ) . ' ' . esc_html( $menu_name ) . '</a>'; | |
| 930 | + } | |
| 931 | + echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 753 | 932 | } |
| 754 | 933 | } |
| 755 | 934 | |
| 756 | 935 | /** |
| @@ -838,9 +1017,9 @@ | ||
| 838 | 1017 | $form_id = $opts['form_id']; |
| 839 | 1018 | unset( $opts['form_id'] ); |
| 840 | 1019 | } |
| 841 | 1020 | |
| 842 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' ); | |
| 1021 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php'; | |
| 843 | 1022 | |
| 844 | 1023 | echo '</div>'; |
| 845 | 1024 | |
| 846 | 1025 | wp_die(); |
| @@ -908,8 +1087,11 @@ | ||
| 908 | 1087 | |
| 909 | 1088 | return $columns; |
| 910 | 1089 | } |
| 911 | 1090 | |
| 1091 | + /** | |
| 1092 | + * @return array<string,string> | |
| 1093 | + */ | |
| 912 | 1094 | public static function get_sortable_columns() { |
| 913 | 1095 | return array( |
| 914 | 1096 | 'id' => 'id', |
| 915 | 1097 | 'name' => 'name', |
| @@ -943,9 +1125,9 @@ | ||
| 943 | 1125 | return $hidden_columns; |
| 944 | 1126 | } |
| 945 | 1127 | |
| 946 | 1128 | public static function save_per_page( $save, $option, $value ) { |
| 947 | - if ( $option == 'formidable_page_formidable_per_page' ) { | |
| 1129 | + if ( $option === 'formidable_page_formidable_per_page' ) { | |
| 948 | 1130 | $save = (int) $value; |
| 949 | 1131 | } |
| 950 | 1132 | |
| 951 | 1133 | return $save; |
| @@ -951,146 +1133,49 @@ | ||
| 951 | 1133 | return $save; |
| 952 | 1134 | } |
| 953 | 1135 | |
| 954 | 1136 | /** |
| 955 | - * @return bool | |
| 956 | - */ | |
| 957 | - public static function expired() { | |
| 958 | - global $frm_expired; | |
| 959 | - return $frm_expired; | |
| 960 | - } | |
| 961 | - | |
| 962 | - /** | |
| 963 | - * Get data from api before rendering it so that we can flag the modal as expired | |
| 964 | - * | |
| 1137 | + * @param int|string $id | |
| 1138 | + * @param array $errors | |
| 1139 | + * @param string $message | |
| 1140 | + * @param bool $create_link | |
| 965 | 1141 | * @return void |
| 966 | 1142 | */ |
| 967 | - public static function before_list_templates() { | |
| 968 | - global $frm_templates; | |
| 969 | - global $frm_expired; | |
| 970 | - global $frm_license_type; | |
| 1143 | + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1144 | + global $frm_vars; | |
| 971 | 1145 | |
| 972 | - $api = new FrmFormTemplateApi(); | |
| 973 | - $frm_templates = $api->get_api_info(); | |
| 974 | - $expired = false; | |
| 975 | - $license_type = ''; | |
| 976 | - if ( isset( $frm_templates['error'] ) ) { | |
| 977 | - $error = $frm_templates['error']['message']; | |
| 978 | - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error ); | |
| 979 | - $expired = 'expired' === $frm_templates['error']['code']; | |
| 980 | - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : ''; | |
| 981 | - unset( $frm_templates['error'] ); | |
| 982 | - } | |
| 983 | - | |
| 984 | - $frm_expired = $expired; | |
| 985 | - $frm_license_type = $license_type; | |
| 986 | - } | |
| 987 | - | |
| 988 | - /** | |
| 989 | - * @return void | |
| 990 | - */ | |
| 991 | - public static function list_templates() { | |
| 992 | - global $frm_templates; | |
| 993 | - global $frm_license_type; | |
| 994 | - | |
| 995 | - $templates = $frm_templates; | |
| 996 | - $custom_templates = array(); | |
| 997 | - $templates_by_category = array(); | |
| 998 | - | |
| 999 | - self::add_user_templates( $custom_templates ); | |
| 1000 | - | |
| 1001 | - foreach ( $templates as $template ) { | |
| 1002 | - if ( ! isset( $template['categories'] ) ) { | |
| 1003 | - continue; | |
| 1004 | - } | |
| 1005 | - | |
| 1006 | - foreach ( $template['categories'] as $category ) { | |
| 1007 | - if ( ! isset( $templates_by_category[ $category ] ) ) { | |
| 1008 | - $templates_by_category[ $category ] = array(); | |
| 1009 | - } | |
| 1010 | - | |
| 1011 | - $templates_by_category[ $category ][] = $template; | |
| 1012 | - } | |
| 1013 | - } | |
| 1014 | - unset( $template ); | |
| 1015 | - | |
| 1016 | - // Subcategories that are included elsewhere. | |
| 1017 | - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' ); | |
| 1018 | - | |
| 1019 | - $categories = array_keys( $templates_by_category ); | |
| 1020 | - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() ); | |
| 1021 | - $categories = array_diff( $categories, $redundant_cats ); | |
| 1022 | - sort( $categories ); | |
| 1023 | - | |
| 1024 | - array_walk( | |
| 1025 | - $custom_templates, | |
| 1026 | - function( &$template ) { | |
| 1027 | - $template['custom'] = true; | |
| 1028 | - } | |
| 1146 | + $form = FrmForm::getOne( $id ); | |
| 1147 | + $error_args = array( | |
| 1148 | + 'title' => __( 'You can\'t edit the form', 'formidable' ), | |
| 1149 | + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ), | |
| 1150 | + 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 1151 | + 'continue_url' => add_query_arg( | |
| 1152 | + array( | |
| 1153 | + 'page' => 'formidable', | |
| 1154 | + ) | |
| 1155 | + ), | |
| 1029 | 1156 | ); |
| 1030 | - | |
| 1031 | - $my_templates_translation = __( 'My Templates', 'formidable' ); | |
| 1032 | - $categories = array_merge( array( $my_templates_translation ), $categories ); | |
| 1033 | - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' ); | |
| 1034 | - $license_type = $frm_license_type; | |
| 1035 | - $args = compact( 'pricing', 'license_type' ); | |
| 1036 | - $where = apply_filters( 'frm_forms_dropdown', array(), '' ); | |
| 1037 | - $forms = FrmForm::get_published_forms( $where ); | |
| 1038 | - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/'; | |
| 1039 | - | |
| 1040 | - $templates_by_category[ $my_templates_translation ] = $custom_templates; | |
| 1041 | - | |
| 1042 | - unset( $pricing, $license_type, $where ); | |
| 1043 | - wp_enqueue_script( 'accordion' ); // register accordion for template groups | |
| 1044 | - require $view_path . 'list-templates.php'; | |
| 1045 | - } | |
| 1046 | - | |
| 1047 | - /** | |
| 1048 | - * @since 4.03.01 | |
| 1049 | - */ | |
| 1050 | - private static function get_template_categories( $templates ) { | |
| 1051 | - $categories = array(); | |
| 1052 | - foreach ( $templates as $template ) { | |
| 1053 | - if ( isset( $template['categories'] ) ) { | |
| 1054 | - $categories = array_merge( $categories, $template['categories'] ); | |
| 1055 | - } | |
| 1157 | + if ( ! $form ) { | |
| 1158 | + FrmAppController::show_error_modal( $error_args ); | |
| 1159 | + return; | |
| 1056 | 1160 | } |
| 1057 | - $exclude_cats = FrmFormsHelper::ignore_template_categories(); | |
| 1058 | - $categories = array_unique( $categories ); | |
| 1059 | - $categories = array_diff( $categories, $exclude_cats ); | |
| 1060 | - sort( $categories ); | |
| 1061 | - return $categories; | |
| 1062 | - } | |
| 1063 | 1161 | |
| 1064 | - private static function add_user_templates( &$templates ) { | |
| 1065 | - $user_templates = array( | |
| 1066 | - 'is_template' => 1, | |
| 1067 | - 'default_template' => 0, | |
| 1068 | - ); | |
| 1069 | - $user_templates = FrmForm::getAll( $user_templates, 'name' ); | |
| 1070 | - foreach ( $user_templates as $template ) { | |
| 1071 | - $template = array( | |
| 1072 | - 'id' => $template->id, | |
| 1073 | - 'name' => $template->name, | |
| 1074 | - 'key' => $template->form_key, | |
| 1075 | - 'description' => $template->description, | |
| 1076 | - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ), | |
| 1077 | - 'released' => $template->created_at, | |
| 1078 | - 'installed' => 1, | |
| 1162 | + if ( 'trash' === $form->status ) { | |
| 1163 | + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' ); | |
| 1164 | + $error_args['continue_url'] = add_query_arg( | |
| 1165 | + array( | |
| 1166 | + 'page' => 'formidable', | |
| 1167 | + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ), | |
| 1168 | + 'form_type' => 'trash', | |
| 1169 | + 'frm_action' => 'untrash', | |
| 1170 | + 'id' => $id, | |
| 1171 | + ) | |
| 1079 | 1172 | ); |
| 1080 | - array_unshift( $templates, $template ); | |
| 1081 | - unset( $template ); | |
| 1173 | + $error_args['continue_text'] = __( 'Restore form', 'formidable' ); | |
| 1174 | + FrmAppController::show_error_modal( $error_args ); | |
| 1175 | + return; | |
| 1082 | 1176 | } |
| 1083 | - } | |
| 1084 | 1177 | |
| 1085 | - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1086 | - global $frm_vars; | |
| 1087 | - | |
| 1088 | - $form = FrmForm::getOne( $id ); | |
| 1089 | - if ( ! $form ) { | |
| 1090 | - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) ); | |
| 1091 | - } | |
| 1092 | - | |
| 1093 | 1178 | if ( $form->parent_form_id ) { |
| 1094 | 1179 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1095 | 1180 | wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) ); |
| 1096 | 1181 | } |
| @@ -1101,8 +1186,9 @@ | ||
| 1101 | 1186 | |
| 1102 | 1187 | // Automatically add end section fields if they don't exist (2.0 migration). |
| 1103 | 1188 | $reset_fields = false; |
| 1104 | 1189 | FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
| 1190 | + FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields ); | |
| 1105 | 1191 | |
| 1106 | 1192 | if ( $reset_fields ) { |
| 1107 | 1193 | $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
| 1108 | 1194 | } |
| @@ -1128,18 +1214,21 @@ | ||
| 1128 | 1214 | } |
| 1129 | 1215 | |
| 1130 | 1216 | self::maybe_update_form_builder_message( $message ); |
| 1131 | 1217 | |
| 1132 | - $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); | |
| 1133 | - $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] ); | |
| 1218 | + $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] ); | |
| 1134 | 1219 | |
| 1135 | 1220 | if ( defined( 'DOING_AJAX' ) ) { |
| 1136 | 1221 | wp_die(); |
| 1137 | - } else { | |
| 1138 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); | |
| 1139 | 1222 | } |
| 1223 | + | |
| 1224 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php'; | |
| 1140 | 1225 | } |
| 1141 | 1226 | |
| 1227 | + /** | |
| 1228 | + * @param array $fields | |
| 1229 | + * @return array | |
| 1230 | + */ | |
| 1142 | 1231 | public static function update_form_builder_fields( $fields, $form ) { |
| 1143 | 1232 | foreach ( $fields as $field ) { |
| 1144 | 1233 | $field->do_not_include_icons = true; |
| 1145 | 1234 | } |
| @@ -1151,13 +1240,21 @@ | ||
| 1151 | 1240 | $message = __( 'Form was Successfully Copied', 'formidable' ); |
| 1152 | 1241 | } |
| 1153 | 1242 | } |
| 1154 | 1243 | |
| 1244 | + /** | |
| 1245 | + * @param int|string $id | |
| 1246 | + * @param array $errors | |
| 1247 | + * @param array|string $args | |
| 1248 | + * @return void | |
| 1249 | + */ | |
| 1155 | 1250 | public static function get_settings_vars( $id, $errors = array(), $args = array() ) { |
| 1156 | 1251 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 1157 | 1252 | |
| 1158 | 1253 | global $frm_vars; |
| 1159 | 1254 | |
| 1255 | + self::maybe_print_media_templates(); | |
| 1256 | + | |
| 1160 | 1257 | if ( ! is_array( $args ) ) { |
| 1161 | 1258 | // For reverse compatibility. |
| 1162 | 1259 | $args = array( |
| 1163 | 1260 | 'message' => $args, |
| @@ -1190,17 +1287,38 @@ | ||
| 1190 | 1287 | |
| 1191 | 1288 | $sections = self::get_settings_tabs( $values ); |
| 1192 | 1289 | $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' ); |
| 1193 | 1290 | |
| 1194 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' ); | |
| 1291 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php'; | |
| 1195 | 1292 | } |
| 1196 | 1293 | |
| 1197 | 1294 | /** |
| 1295 | + * Print WordPress media templates email actions does not trigger a "Uncaught Error: Template not found: #tmpl-media-selection" error when the media button is clicked. | |
| 1296 | + * | |
| 1297 | + * @since 6.10 | |
| 1298 | + * | |
| 1299 | + * @return void | |
| 1300 | + */ | |
| 1301 | + private static function maybe_print_media_templates() { | |
| 1302 | + if ( FrmAppHelper::pro_is_included() ) { | |
| 1303 | + // This issue does not exist when Pro is active so exit early. | |
| 1304 | + return; | |
| 1305 | + } | |
| 1306 | + | |
| 1307 | + add_action( | |
| 1308 | + 'wp_enqueue_editor', | |
| 1309 | + function () { | |
| 1310 | + wp_print_media_templates(); | |
| 1311 | + } | |
| 1312 | + ); | |
| 1313 | + } | |
| 1314 | + | |
| 1315 | + /** | |
| 1198 | 1316 | * @since 4.0 |
| 1199 | 1317 | */ |
| 1200 | 1318 | public static function form_publish_button( $atts ) { |
| 1201 | 1319 | $values = $atts['values']; |
| 1202 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' ); | |
| 1320 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php'; | |
| 1203 | 1321 | } |
| 1204 | 1322 | |
| 1205 | 1323 | /** |
| 1206 | 1324 | * Get a list of all the settings tabs for the form settings page. |
| @@ -1225,9 +1343,9 @@ | ||
| 1225 | 1343 | 'icon' => 'frm_icon_font frm_mail_bulk_icon', |
| 1226 | 1344 | ), |
| 1227 | 1345 | 'permissions' => array( |
| 1228 | 1346 | 'name' => __( 'Form Permissions', 'formidable' ), |
| 1229 | - 'icon' => 'frm_icon_font frm_lock_icon', | |
| 1347 | + 'icon' => 'frm_icon_font frm_lock_closed_icon', | |
| 1230 | 1348 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1231 | 1349 | 'data' => array( |
| 1232 | 1350 | 'medium' => 'permissions', |
| 1233 | 1351 | 'upgrade' => __( 'Form Permissions', 'formidable' ), |
| @@ -1234,9 +1352,9 @@ | ||
| 1234 | 1352 | 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ), |
| 1235 | 1353 | 'screenshot' => 'permissions.png', |
| 1236 | 1354 | ), |
| 1237 | 1355 | ), |
| 1238 | - 'scheduling' => array( | |
| 1356 | + 'scheduling' => array( | |
| 1239 | 1357 | 'name' => __( 'Form Scheduling', 'formidable' ), |
| 1240 | 1358 | 'icon' => 'frm_icon_font frm_calendar_icon', |
| 1241 | 1359 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1242 | 1360 | 'data' => array( |
| @@ -1269,8 +1387,21 @@ | ||
| 1269 | 1387 | 'screenshot' => 'chat.png', |
| 1270 | 1388 | ) |
| 1271 | 1389 | ), |
| 1272 | 1390 | ), |
| 1391 | + 'abandonment' => array( | |
| 1392 | + 'name' => __( 'Form Abandonment', 'formidable' ), | |
| 1393 | + 'icon' => 'frm_icon_font frm_abandoned_icon', | |
| 1394 | + 'html_class' => 'frm_show_upgrade_tab frm_noallow', | |
| 1395 | + 'data' => FrmAppHelper::get_upgrade_data_params( | |
| 1396 | + 'abandonment', | |
| 1397 | + array( | |
| 1398 | + 'upgrade' => __( 'Form abandonment settings', 'formidable' ), | |
| 1399 | + 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ), | |
| 1400 | + 'screenshot' => 'abandonment.png', | |
| 1401 | + ) | |
| 1402 | + ), | |
| 1403 | + ), | |
| 1273 | 1404 | 'html' => array( |
| 1274 | 1405 | 'name' => __( 'Customize HTML', 'formidable' ), |
| 1275 | 1406 | 'class' => __CLASS__, |
| 1276 | 1407 | 'function' => 'html_settings', |
| @@ -1277,9 +1408,9 @@ | ||
| 1277 | 1408 | 'icon' => 'frm_icon_font frm_code_icon', |
| 1278 | 1409 | ), |
| 1279 | 1410 | ); |
| 1280 | 1411 | |
| 1281 | - foreach ( array( 'landing', 'chat' ) as $feature ) { | |
| 1412 | + foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) { | |
| 1282 | 1413 | if ( ! FrmAppHelper::show_new_feature( $feature ) ) { |
| 1283 | 1414 | unset( $sections[ $feature ] ); |
| 1284 | 1415 | } |
| 1285 | 1416 | } |
| @@ -1285,13 +1416,8 @@ | ||
| 1285 | 1416 | } |
| 1286 | 1417 | |
| 1287 | 1418 | $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values ); |
| 1288 | 1419 | |
| 1289 | - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) { | |
| 1290 | - // Prevent settings from showing in 2 spots. | |
| 1291 | - unset( $sections['permissions'], $sections['scheduling'] ); | |
| 1292 | - } | |
| 1293 | - | |
| 1294 | 1420 | foreach ( $sections as $key => $section ) { |
| 1295 | 1421 | $defaults = array( |
| 1296 | 1422 | 'html_class' => '', |
| 1297 | 1423 | 'name' => ucfirst( $key ), |
| @@ -1313,9 +1439,9 @@ | ||
| 1313 | 1439 | $section['id'] = $section['anchor']; |
| 1314 | 1440 | } |
| 1315 | 1441 | |
| 1316 | 1442 | $sections[ $key ] = $section; |
| 1317 | - } | |
| 1443 | + }//end foreach | |
| 1318 | 1444 | |
| 1319 | 1445 | return $sections; |
| 1320 | 1446 | } |
| 1321 | 1447 | |
| @@ -1322,8 +1448,9 @@ | ||
| 1322 | 1448 | /** |
| 1323 | 1449 | * @since 4.0 |
| 1324 | 1450 | * |
| 1325 | 1451 | * @param array $values |
| 1452 | + * @return void | |
| 1326 | 1453 | */ |
| 1327 | 1454 | public static function advanced_settings( $values ) { |
| 1328 | 1455 | $first_h3 = 'frm_first_h3'; |
| 1329 | 1456 | |
| @@ -1331,8 +1458,9 @@ | ||
| 1331 | 1458 | } |
| 1332 | 1459 | |
| 1333 | 1460 | /** |
| 1334 | 1461 | * @param array $values |
| 1462 | + * @return void | |
| 1335 | 1463 | */ |
| 1336 | 1464 | public static function render_spam_settings( $values ) { |
| 1337 | 1465 | if ( function_exists( 'akismet_http_post' ) ) { |
| 1338 | 1466 | include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php'; |
| @@ -1344,16 +1472,12 @@ | ||
| 1344 | 1472 | /** |
| 1345 | 1473 | * @since 4.0 |
| 1346 | 1474 | * |
| 1347 | 1475 | * @param array $values |
| 1476 | + * @return void | |
| 1348 | 1477 | */ |
| 1349 | 1478 | public static function buttons_settings( $values ) { |
| 1350 | - $styles = apply_filters( 'frm_get_style_opts', array() ); | |
| 1351 | - | |
| 1352 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 1353 | - $no_global_style = $frm_settings->load_style === 'none'; | |
| 1354 | - | |
| 1355 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' ); | |
| 1479 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php'; | |
| 1356 | 1480 | } |
| 1357 | 1481 | |
| 1358 | 1482 | /** |
| 1359 | 1483 | * @since 4.0 |
| @@ -1358,11 +1482,12 @@ | ||
| 1358 | 1482 | /** |
| 1359 | 1483 | * @since 4.0 |
| 1360 | 1484 | * |
| 1361 | 1485 | * @param array $values |
| 1486 | + * @return void | |
| 1362 | 1487 | */ |
| 1363 | 1488 | public static function html_settings( $values ) { |
| 1364 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' ); | |
| 1489 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php'; | |
| 1365 | 1490 | } |
| 1366 | 1491 | |
| 1367 | 1492 | /** |
| 1368 | 1493 | * Replace old Submit Button href with new href to avoid errors in Chrome |
| @@ -1368,9 +1493,10 @@ | ||
| 1368 | 1493 | * Replace old Submit Button href with new href to avoid errors in Chrome |
| 1369 | 1494 | * |
| 1370 | 1495 | * @since 2.03.08 |
| 1371 | 1496 | * |
| 1372 | - * @param array|boolean $values | |
| 1497 | + * @param array|bool $values | |
| 1498 | + * @return void | |
| 1373 | 1499 | */ |
| 1374 | 1500 | private static function clean_submit_html( &$values ) { |
| 1375 | 1501 | if ( is_array( $values ) && isset( $values['submit_html'] ) ) { |
| 1376 | 1502 | $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] ); |
| @@ -1391,8 +1517,13 @@ | ||
| 1391 | 1517 | |
| 1392 | 1518 | return $classes; |
| 1393 | 1519 | } |
| 1394 | 1520 | |
| 1521 | + /** | |
| 1522 | + * @param int|string $form_id | |
| 1523 | + * @param string $class | |
| 1524 | + * @return void | |
| 1525 | + */ | |
| 1395 | 1526 | public static function mb_tags_box( $form_id, $class = '' ) { |
| 1396 | 1527 | $fields = FrmField::get_all_for_form( $form_id, '', 'include' ); |
| 1397 | 1528 | |
| 1398 | 1529 | /** |
| @@ -1405,9 +1536,9 @@ | ||
| 1405 | 1536 | */ |
| 1406 | 1537 | $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) ); |
| 1407 | 1538 | $linked_forms = array(); |
| 1408 | 1539 | $col = 'one'; |
| 1409 | - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false; | |
| 1540 | + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ); | |
| 1410 | 1541 | |
| 1411 | 1542 | $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() ); |
| 1412 | 1543 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 1413 | 1544 | |
| @@ -1412,9 +1543,9 @@ | ||
| 1412 | 1543 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 1413 | 1544 | |
| 1414 | 1545 | $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) ); |
| 1415 | 1546 | |
| 1416 | - include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' ); | |
| 1547 | + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php'; | |
| 1417 | 1548 | } |
| 1418 | 1549 | |
| 1419 | 1550 | /** |
| 1420 | 1551 | * @since 3.04.01 |
| @@ -1427,9 +1558,9 @@ | ||
| 1427 | 1558 | ), |
| 1428 | 1559 | ); |
| 1429 | 1560 | |
| 1430 | 1561 | $user_fields = self::user_shortcodes(); |
| 1431 | - if ( ! empty( $user_fields ) ) { | |
| 1562 | + if ( $user_fields ) { | |
| 1432 | 1563 | $user_helpers = array(); |
| 1433 | 1564 | foreach ( $user_fields as $uk => $uf ) { |
| 1434 | 1565 | $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf; |
| 1435 | 1566 | unset( $uk, $uf ); |
| @@ -1435,9 +1566,9 @@ | ||
| 1435 | 1566 | unset( $uk, $uf ); |
| 1436 | 1567 | } |
| 1437 | 1568 | |
| 1438 | 1569 | $advanced_helpers['user_id'] = array( |
| 1439 | - 'codes' => $user_helpers, | |
| 1570 | + 'codes' => $user_helpers, | |
| 1440 | 1571 | ); |
| 1441 | 1572 | } |
| 1442 | 1573 | |
| 1443 | 1574 | /** |
| @@ -1578,11 +1709,11 @@ | ||
| 1578 | 1709 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1579 | 1710 | |
| 1580 | 1711 | echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 1581 | 1712 | array( |
| 1582 | - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), | |
| 1713 | + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1583 | 1714 | 'default_email' => true, |
| 1584 | - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), | |
| 1715 | + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1585 | 1716 | ) |
| 1586 | 1717 | ); |
| 1587 | 1718 | wp_die(); |
| 1588 | 1719 | } |
| @@ -1588,10 +1719,10 @@ | ||
| 1588 | 1719 | } |
| 1589 | 1720 | |
| 1590 | 1721 | /** |
| 1591 | 1722 | * @param string $content |
| 1592 | - * @param stdClass|string|int $form | |
| 1593 | - * @param stdClass|string|int|false $entry | |
| 1723 | + * @param int|stdClass|string $form | |
| 1724 | + * @param false|int|stdClass|string $entry | |
| 1594 | 1725 | * @return string |
| 1595 | 1726 | */ |
| 1596 | 1727 | public static function filter_content( $content, $form, $entry = false ) { |
| 1597 | 1728 | $content = self::replace_form_name_shortcodes( $content, $form ); |
| @@ -1604,8 +1735,16 @@ | ||
| 1604 | 1735 | if ( is_object( $form ) ) { |
| 1605 | 1736 | $form = $form->id; |
| 1606 | 1737 | } |
| 1607 | 1738 | |
| 1739 | + /* | |
| 1740 | + * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty, | |
| 1741 | + * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work. | |
| 1742 | + */ | |
| 1743 | + if ( ! empty( $entry->parent_entry ) ) { | |
| 1744 | + $form = $entry->parent_entry->form_id; | |
| 1745 | + } | |
| 1746 | + | |
| 1608 | 1747 | $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form ); |
| 1609 | 1748 | $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes ); |
| 1610 | 1749 | |
| 1611 | 1750 | return $content; |
| @@ -1615,11 +1754,11 @@ | ||
| 1615 | 1754 | * Replace any [form_name] shortcodes in a string. |
| 1616 | 1755 | * |
| 1617 | 1756 | * @since 5.5 |
| 1618 | 1757 | * |
| 1619 | - * @param string|array $string | |
| 1620 | - * @param stdClass|string|int $form | |
| 1621 | - * @return string|array | |
| 1758 | + * @param array|string $string | |
| 1759 | + * @param int|stdClass|string $form | |
| 1760 | + * @return array|string | |
| 1622 | 1761 | */ |
| 1623 | 1762 | public static function replace_form_name_shortcodes( $string, $form ) { |
| 1624 | 1763 | if ( ! is_string( $string ) ) { |
| 1625 | 1764 | return $string; |
| @@ -1637,9 +1776,9 @@ | ||
| 1637 | 1776 | return str_replace( '[form_name]', $form_name, $string ); |
| 1638 | 1777 | } |
| 1639 | 1778 | |
| 1640 | 1779 | /** |
| 1641 | - * @param stdClass|string|int|false $entry | |
| 1780 | + * @param false|int|stdClass|string $entry | |
| 1642 | 1781 | * @return void |
| 1643 | 1782 | */ |
| 1644 | 1783 | private static function get_entry_by_param( &$entry ) { |
| 1645 | 1784 | if ( ! $entry || ! is_object( $entry ) ) { |
| @@ -1654,8 +1793,12 @@ | ||
| 1654 | 1793 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
| 1655 | 1794 | return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); |
| 1656 | 1795 | } |
| 1657 | 1796 | |
| 1797 | + /** | |
| 1798 | + * @param array $errors | |
| 1799 | + * @return array | |
| 1800 | + */ | |
| 1658 | 1801 | public static function process_bulk_form_actions( $errors ) { |
| 1659 | 1802 | if ( ! $_REQUEST ) { |
| 1660 | 1803 | return $errors; |
| 1661 | 1804 | } |
| @@ -1699,9 +1842,9 @@ | ||
| 1699 | 1842 | case 'untrash': |
| 1700 | 1843 | $message = self::bulk_untrash( $ids ); |
| 1701 | 1844 | } |
| 1702 | 1845 | |
| 1703 | - if ( isset( $message ) && ! empty( $message ) ) { | |
| 1846 | + if ( ! empty( $message ) ) { | |
| 1704 | 1847 | $errors['message'] = $message; |
| 1705 | 1848 | } |
| 1706 | 1849 | |
| 1707 | 1850 | return $errors; |
| @@ -1721,9 +1864,9 @@ | ||
| 1721 | 1864 | $json_vars = json_decode( $json_vars, true ); |
| 1722 | 1865 | if ( empty( $json_vars ) ) { |
| 1723 | 1866 | // json decoding failed so we should return an error message. |
| 1724 | 1867 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 1725 | - if ( 'edit' == $action ) { | |
| 1868 | + if ( 'edit' === $action ) { | |
| 1726 | 1869 | $action = 'update'; |
| 1727 | 1870 | } |
| 1728 | 1871 | |
| 1729 | 1872 | add_filter( 'frm_validate_form', 'FrmFormsController::json_error' ); |
| @@ -1739,16 +1882,14 @@ | ||
| 1739 | 1882 | if ( isset( $_REQUEST['delete_all'] ) ) { |
| 1740 | 1883 | // Override the action for this page. |
| 1741 | 1884 | $action = 'delete_all'; |
| 1742 | 1885 | } |
| 1743 | - } | |
| 1886 | + }//end if | |
| 1744 | 1887 | |
| 1745 | 1888 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1746 | 1889 | FrmAppHelper::trigger_hook_load( 'form' ); |
| 1747 | 1890 | |
| 1748 | 1891 | switch ( $action ) { |
| 1749 | - case 'new': | |
| 1750 | - return self::new_form( $vars ); | |
| 1751 | 1892 | case 'create': |
| 1752 | 1893 | case 'edit': |
| 1753 | 1894 | case 'update': |
| 1754 | 1895 | case 'trash': |
| @@ -1753,16 +1894,17 @@ | ||
| 1753 | 1894 | case 'update': |
| 1754 | 1895 | case 'trash': |
| 1755 | 1896 | case 'untrash': |
| 1756 | 1897 | case 'destroy': |
| 1757 | - case 'delete_all': | |
| 1758 | 1898 | case 'settings': |
| 1759 | 1899 | case 'update_settings': |
| 1760 | 1900 | return self::$action( $vars ); |
| 1761 | 1901 | case 'lite-reports': |
| 1762 | - return self::no_reports( $vars ); | |
| 1902 | + self::no_reports( $vars ); | |
| 1903 | + return; | |
| 1763 | 1904 | case 'views': |
| 1764 | - return self::no_views( $vars ); | |
| 1905 | + self::no_views( $vars ); | |
| 1906 | + return; | |
| 1765 | 1907 | default: |
| 1766 | 1908 | do_action( 'frm_form_action_' . $action ); |
| 1767 | 1909 | if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) { |
| 1768 | 1910 | return; |
| @@ -1785,14 +1927,47 @@ | ||
| 1785 | 1927 | self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) ); |
| 1786 | 1928 | return; |
| 1787 | 1929 | } |
| 1788 | 1930 | |
| 1931 | + if ( 'forms_permanently_deleted' === $message ) { | |
| 1932 | + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' ); | |
| 1933 | + /* translators: %1$s: Number of forms */ | |
| 1934 | + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 1935 | + self::display_forms_list( array(), $message, '' ); | |
| 1936 | + return; | |
| 1937 | + } | |
| 1938 | + | |
| 1789 | 1939 | self::display_forms_list(); |
| 1790 | 1940 | |
| 1791 | 1941 | return; |
| 1792 | - } | |
| 1942 | + }//end switch | |
| 1793 | 1943 | } |
| 1794 | 1944 | |
| 1945 | + /** | |
| 1946 | + * Rename a form. | |
| 1947 | + * | |
| 1948 | + * Handles the AJAX request for renaming a form. | |
| 1949 | + * | |
| 1950 | + * @since 6.7 | |
| 1951 | + * | |
| 1952 | + * @return void | |
| 1953 | + */ | |
| 1954 | + public static function rename_form() { | |
| 1955 | + // Check permission and nonce | |
| 1956 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 1957 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 1958 | + | |
| 1959 | + // Get posted data | |
| 1960 | + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); | |
| 1961 | + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' ); | |
| 1962 | + | |
| 1963 | + // Update the form name and form key. | |
| 1964 | + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' ); | |
| 1965 | + FrmForm::update( $form_id, compact( 'name', 'form_key' ) ); | |
| 1966 | + | |
| 1967 | + wp_send_json_success( compact( 'form_key' ) ); | |
| 1968 | + } | |
| 1969 | + | |
| 1795 | 1970 | public static function json_error( $errors ) { |
| 1796 | 1971 | $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
| 1797 | 1972 | |
| 1798 | 1973 | return $errors; |
| @@ -1801,11 +1976,12 @@ | ||
| 1801 | 1976 | /** |
| 1802 | 1977 | * Education for premium features. |
| 1803 | 1978 | * |
| 1804 | 1979 | * @since 4.05 |
| 1980 | + * @return void | |
| 1805 | 1981 | */ |
| 1806 | 1982 | public static function add_form_style_tab_options() { |
| 1807 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' ); | |
| 1983 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php'; | |
| 1808 | 1984 | } |
| 1809 | 1985 | |
| 1810 | 1986 | /** |
| 1811 | 1987 | * Add education about views. |
| @@ -1810,8 +1986,10 @@ | ||
| 1810 | 1986 | /** |
| 1811 | 1987 | * Add education about views. |
| 1812 | 1988 | * |
| 1813 | 1989 | * @since 4.07 |
| 1990 | + * | |
| 1991 | + * @return void | |
| 1814 | 1992 | */ |
| 1815 | 1993 | public static function no_views( $values = array() ) { |
| 1816 | 1994 | FrmAppHelper::include_svg(); |
| 1817 | 1995 | $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| @@ -1823,8 +2001,10 @@ | ||
| 1823 | 2001 | /** |
| 1824 | 2002 | * Add education about reports. |
| 1825 | 2003 | * |
| 1826 | 2004 | * @since 4.07 |
| 2005 | + * | |
| 2006 | + * @return void | |
| 1827 | 2007 | */ |
| 1828 | 2008 | public static function no_reports( $values = array() ) { |
| 1829 | 2009 | $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| 1830 | 2010 | $form = $id ? FrmForm::getOne( $id ) : false; |
| @@ -1831,9 +2011,11 @@ | ||
| 1831 | 2011 | |
| 1832 | 2012 | include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php'; |
| 1833 | 2013 | } |
| 1834 | 2014 | |
| 1835 | - /* FRONT-END FORMS */ | |
| 2015 | + /** | |
| 2016 | + * FRONT-END FORMS. | |
| 2017 | + */ | |
| 1836 | 2018 | public static function admin_bar_css() { |
| 1837 | 2019 | if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 1838 | 2020 | return; |
| 1839 | 2021 | } |
| @@ -1922,10 +2104,10 @@ | ||
| 1922 | 2104 | * @return string |
| 1923 | 2105 | */ |
| 1924 | 2106 | public static function get_form_shortcode( $atts ) { |
| 1925 | 2107 | global $frm_vars; |
| 1926 | - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) { | |
| 1927 | - $sc = '[formidable'; | |
| 2108 | + if ( ! empty( $frm_vars['skip_shortcode'] ) ) { | |
| 2109 | + $sc = '[formidable'; | |
| 1928 | 2110 | $sc .= FrmAppHelper::array_to_html_params( $atts ); |
| 1929 | 2111 | return $sc . ']'; |
| 1930 | 2112 | } |
| 1931 | 2113 | |
| @@ -1950,11 +2132,11 @@ | ||
| 1950 | 2132 | |
| 1951 | 2133 | /** |
| 1952 | 2134 | * @since 5.2.01 |
| 1953 | 2135 | * |
| 1954 | - * @param string|int|false $id | |
| 1955 | - * @param string|false $key | |
| 1956 | - * @return stdClass|false | |
| 2136 | + * @param false|int|string $id | |
| 2137 | + * @param false|string $key | |
| 2138 | + * @return false|stdClass | |
| 1957 | 2139 | */ |
| 1958 | 2140 | private static function maybe_get_form_by_id_or_key( $id, $key ) { |
| 1959 | 2141 | if ( ! $id ) { |
| 1960 | 2142 | $id = $key; |
| @@ -1962,12 +2144,12 @@ | ||
| 1962 | 2144 | return self::maybe_get_form_to_show( $id ); |
| 1963 | 2145 | } |
| 1964 | 2146 | |
| 1965 | 2147 | /** |
| 1966 | - * @param string|int|false $id | |
| 1967 | - * @param string|false $key | |
| 1968 | - * @param string|int|bool $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 1969 | - * @param string|int|bool $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 2148 | + * @param false|int|string $id | |
| 2149 | + * @param false|string $key | |
| 2150 | + * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 2151 | + * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 1970 | 2152 | * @param array $atts |
| 1971 | 2153 | * @return string |
| 1972 | 2154 | */ |
| 1973 | 2155 | public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
| @@ -2015,15 +2197,16 @@ | ||
| 2015 | 2197 | return $form; |
| 2016 | 2198 | } |
| 2017 | 2199 | |
| 2018 | 2200 | /** |
| 2019 | - * @param string|int|false $id | |
| 2020 | - * @return stdClass|false | |
| 2201 | + * @param false|int|string $id | |
| 2202 | + * @return false|stdClass | |
| 2021 | 2203 | */ |
| 2022 | 2204 | private static function maybe_get_form_to_show( $id ) { |
| 2023 | 2205 | $form = false; |
| 2024 | 2206 | |
| 2025 | - if ( ! empty( $id ) ) { // form id or key is set | |
| 2207 | + if ( ! empty( $id ) ) { | |
| 2208 | + // Form id or key is set. | |
| 2026 | 2209 | $form = FrmForm::getOne( $id ); |
| 2027 | 2210 | if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) { |
| 2028 | 2211 | $form = false; |
| 2029 | 2212 | } |
| @@ -2081,11 +2264,11 @@ | ||
| 2081 | 2264 | |
| 2082 | 2265 | do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description ); |
| 2083 | 2266 | |
| 2084 | 2267 | if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) { |
| 2085 | - $entry_id = self::just_created_entry( $form->id ); | |
| 2086 | - $pass_args['entry_id'] = $entry_id; | |
| 2087 | - $pass_args['reset'] = true; | |
| 2268 | + $entry_id = self::just_created_entry( $form->id ); | |
| 2269 | + $pass_args['entry_id'] = $entry_id; | |
| 2270 | + $pass_args['reset'] = true; | |
| 2088 | 2271 | |
| 2089 | 2272 | self::run_on_submit_actions( $pass_args ); |
| 2090 | 2273 | |
| 2091 | 2274 | do_action( |
| @@ -2095,9 +2278,9 @@ | ||
| 2095 | 2278 | 'form' => $form, |
| 2096 | 2279 | ) |
| 2097 | 2280 | ); |
| 2098 | 2281 | } |
| 2099 | - } | |
| 2282 | + }//end if | |
| 2100 | 2283 | } |
| 2101 | 2284 | |
| 2102 | 2285 | /** |
| 2103 | 2286 | * If the form was processed earlier (init), get the generated errors |
| @@ -2129,9 +2312,9 @@ | ||
| 2129 | 2312 | */ |
| 2130 | 2313 | public static function just_created_entry( $form_id ) { |
| 2131 | 2314 | global $frm_vars; |
| 2132 | 2315 | |
| 2133 | - return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0; | |
| 2316 | + return isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0; | |
| 2134 | 2317 | } |
| 2135 | 2318 | |
| 2136 | 2319 | /** |
| 2137 | 2320 | * Gets confirmation method. |
| @@ -2144,14 +2327,14 @@ | ||
| 2144 | 2327 | * |
| 2145 | 2328 | * @type object $form Form object. |
| 2146 | 2329 | * @type int $entry_id Entry ID. |
| 2147 | 2330 | * } |
| 2148 | - * @return string|array | |
| 2331 | + * @return array|string | |
| 2149 | 2332 | */ |
| 2150 | 2333 | private static function get_confirmation_method( $atts ) { |
| 2151 | 2334 | $action = FrmOnSubmitHelper::current_event( $atts ); |
| 2152 | 2335 | $opt = 'update' === $action ? 'edit_action' : 'success_action'; |
| 2153 | - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message'; | |
| 2336 | + $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message'; | |
| 2154 | 2337 | |
| 2155 | 2338 | if ( ! empty( $atts['entry_id'] ) ) { |
| 2156 | 2339 | $met_actions = self::get_met_on_submit_actions( $atts, $action ); |
| 2157 | 2340 | if ( $met_actions ) { |
| @@ -2160,9 +2343,9 @@ | ||
| 2160 | 2343 | } |
| 2161 | 2344 | |
| 2162 | 2345 | $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action ); |
| 2163 | 2346 | |
| 2164 | - if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { | |
| 2347 | + if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { | |
| 2165 | 2348 | $method = 'message'; |
| 2166 | 2349 | } |
| 2167 | 2350 | |
| 2168 | 2351 | return $method; |
| @@ -2247,9 +2430,9 @@ | ||
| 2247 | 2430 | unset( $extra_args['form'] ); |
| 2248 | 2431 | |
| 2249 | 2432 | do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args ); |
| 2250 | 2433 | |
| 2251 | - $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit'; | |
| 2434 | + $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit'; | |
| 2252 | 2435 | |
| 2253 | 2436 | $args['success_opt'] = $opt; |
| 2254 | 2437 | $args['ajax'] = ! empty( $frm_vars['ajax'] ); |
| 2255 | 2438 | |
| @@ -2275,16 +2458,16 @@ | ||
| 2275 | 2458 | if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) { |
| 2276 | 2459 | return array(); |
| 2277 | 2460 | } |
| 2278 | 2461 | |
| 2279 | - // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab. | |
| 2462 | + // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab. | |
| 2280 | 2463 | if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) { |
| 2281 | 2464 | return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) ); |
| 2282 | 2465 | } |
| 2283 | 2466 | |
| 2284 | - $entry = FrmEntry::getOne( $args['entry_id'], true ); | |
| 2285 | - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); | |
| 2286 | - $met_actions = array(); | |
| 2467 | + $entry = FrmEntry::getOne( $args['entry_id'], true ); | |
| 2468 | + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); | |
| 2469 | + $met_actions = array(); | |
| 2287 | 2470 | $has_redirect = false; |
| 2288 | 2471 | |
| 2289 | 2472 | foreach ( $actions as $action ) { |
| 2290 | 2473 | if ( ! in_array( $event, $action->post_content['event'], true ) ) { |
| @@ -2297,9 +2480,10 @@ | ||
| 2297 | 2480 | |
| 2298 | 2481 | $action_type = FrmOnSubmitHelper::get_action_type( $action ); |
| 2299 | 2482 | |
| 2300 | 2483 | if ( 'redirect' === $action_type ) { |
| 2301 | - if ( $has_redirect ) { // Do not process because we run the first redirect action only. | |
| 2484 | + if ( $has_redirect ) { | |
| 2485 | + // Do not process because we run the first redirect action only. | |
| 2302 | 2486 | continue; |
| 2303 | 2487 | } |
| 2304 | 2488 | } |
| 2305 | 2489 | |
| @@ -2312,9 +2496,9 @@ | ||
| 2312 | 2496 | } |
| 2313 | 2497 | |
| 2314 | 2498 | $met_actions[] = $action; |
| 2315 | 2499 | unset( $action ); |
| 2316 | - } | |
| 2500 | + }//end foreach | |
| 2317 | 2501 | |
| 2318 | 2502 | $args['event'] = $event; |
| 2319 | 2503 | |
| 2320 | 2504 | /** |
| @@ -2503,9 +2687,9 @@ | ||
| 2503 | 2687 | add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 ); |
| 2504 | 2688 | } |
| 2505 | 2689 | |
| 2506 | 2690 | $post = $old_post; |
| 2507 | - } | |
| 2691 | + }//end if | |
| 2508 | 2692 | } |
| 2509 | 2693 | |
| 2510 | 2694 | /** |
| 2511 | 2695 | * @since 3.0 |
| @@ -2526,14 +2710,16 @@ | ||
| 2526 | 2710 | $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args ); |
| 2527 | 2711 | |
| 2528 | 2712 | $doing_ajax = FrmAppHelper::doing_ajax(); |
| 2529 | 2713 | |
| 2530 | - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs. | |
| 2714 | + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { | |
| 2715 | + // Is AJAX submit and there is just one Redirect action runs. | |
| 2531 | 2716 | echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) ); |
| 2532 | 2717 | wp_die(); |
| 2533 | 2718 | } |
| 2534 | 2719 | |
| 2535 | - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2720 | + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { | |
| 2721 | + // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2536 | 2722 | if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { |
| 2537 | 2723 | self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ); |
| 2538 | 2724 | self::$redirected_in_new_tab[ $args['form']->id ] = 1; |
| 2539 | 2725 | return; |
| @@ -2539,9 +2725,10 @@ | ||
| 2539 | 2725 | return; |
| 2540 | 2726 | } |
| 2541 | 2727 | |
| 2542 | 2728 | wp_redirect( esc_url_raw( $success_url ) ); |
| 2543 | - die(); // do not use wp_die or redirect fails | |
| 2729 | + // Do not use wp_die or redirect fails. | |
| 2730 | + die(); | |
| 2544 | 2731 | } |
| 2545 | 2732 | |
| 2546 | 2733 | // Redirect with a delay. |
| 2547 | 2734 | self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) ); |
| @@ -2592,9 +2779,9 @@ | ||
| 2592 | 2779 | |
| 2593 | 2780 | $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args ); |
| 2594 | 2781 | |
| 2595 | 2782 | ob_start(); |
| 2596 | - self::show_lone_success_messsage( $args ); | |
| 2783 | + self::show_lone_success_message( $args ); | |
| 2597 | 2784 | $response_data['content'] = ob_get_clean(); |
| 2598 | 2785 | |
| 2599 | 2786 | $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args ); |
| 2600 | 2787 | } |
| @@ -2618,9 +2805,9 @@ | ||
| 2618 | 2805 | * Filters the delay time before redirecting when On Submit Redirect action is delayed. |
| 2619 | 2806 | * |
| 2620 | 2807 | * @since 6.0 |
| 2621 | 2808 | * |
| 2622 | - * @param int $delay_time Delay time in miliseconds. | |
| 2809 | + * @param int $delay_time Delay time in milliseconds. | |
| 2623 | 2810 | */ |
| 2624 | 2811 | $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 ); |
| 2625 | 2812 | |
| 2626 | 2813 | if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { |
| @@ -2632,9 +2819,10 @@ | ||
| 2632 | 2819 | add_filter( 'frm_use_wpautop', '__return_true' ); |
| 2633 | 2820 | |
| 2634 | 2821 | echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2635 | 2822 | echo '<script>'; |
| 2636 | - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load. | |
| 2823 | + if ( empty( $args['doing_ajax'] ) ) { | |
| 2824 | + // Not AJAX submit, delay JS until window.load. | |
| 2637 | 2825 | echo 'window.onload=function(){'; |
| 2638 | 2826 | } |
| 2639 | 2827 | echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2640 | 2828 | if ( empty( $args['doing_ajax'] ) ) { |
| @@ -2647,9 +2835,9 @@ | ||
| 2647 | 2835 | * @since 3.0 |
| 2648 | 2836 | * |
| 2649 | 2837 | * @param string $success_url |
| 2650 | 2838 | * @param string $success_msg |
| 2651 | - * @param array $args | |
| 2839 | + * @param array $args | |
| 2652 | 2840 | */ |
| 2653 | 2841 | private static function get_redirect_message( $success_url, $success_msg, $args ) { |
| 2654 | 2842 | $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . |
| 2655 | 2843 | self::get_redirect_fallback_message( $success_url, $args ) . |
| @@ -2707,9 +2895,9 @@ | ||
| 2707 | 2895 | } else { |
| 2708 | 2896 | self::show_form_after_submit( $atts ); |
| 2709 | 2897 | } |
| 2710 | 2898 | } else { |
| 2711 | - self::show_lone_success_messsage( $atts ); | |
| 2899 | + self::show_lone_success_message( $atts ); | |
| 2712 | 2900 | } |
| 2713 | 2901 | } |
| 2714 | 2902 | |
| 2715 | 2903 | /** |
| @@ -2748,11 +2936,10 @@ | ||
| 2748 | 2936 | include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php'; |
| 2749 | 2937 | } |
| 2750 | 2938 | |
| 2751 | 2939 | /** |
| 2940 | + * @since 4.05.02 | |
| 2752 | 2941 | * @return string - 'before', 'after', or 'submit' |
| 2753 | - * | |
| 2754 | - * @since 4.05.02 | |
| 2755 | 2942 | */ |
| 2756 | 2943 | private static function message_placement( $form, $message ) { |
| 2757 | 2944 | $place = 'before'; |
| 2758 | 2945 | |
| @@ -2764,11 +2951,10 @@ | ||
| 2764 | 2951 | } |
| 2765 | 2952 | } |
| 2766 | 2953 | |
| 2767 | 2954 | /** |
| 2955 | + * @since 4.05.02 | |
| 2768 | 2956 | * @return string - 'before' or 'after' |
| 2769 | - * | |
| 2770 | - * @since 4.05.02 | |
| 2771 | 2957 | */ |
| 2772 | 2958 | return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) ); |
| 2773 | 2959 | } |
| 2774 | 2960 | |
| @@ -2802,9 +2988,9 @@ | ||
| 2802 | 2988 | * Show the success message without the form |
| 2803 | 2989 | * |
| 2804 | 2990 | * @since 2.05 |
| 2805 | 2991 | */ |
| 2806 | - private static function show_lone_success_messsage( $atts ) { | |
| 2992 | + private static function show_lone_success_message( $atts ) { | |
| 2807 | 2993 | global $frm_vars; |
| 2808 | 2994 | $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true ); |
| 2809 | 2995 | self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] ); |
| 2810 | 2996 | |
| @@ -2813,9 +2999,9 @@ | ||
| 2813 | 2999 | $errors = array(); |
| 2814 | 3000 | $form = $atts['form']; |
| 2815 | 3001 | $message = $atts['message']; |
| 2816 | 3002 | |
| 2817 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' ); | |
| 3003 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php'; | |
| 2818 | 3004 | } |
| 2819 | 3005 | |
| 2820 | 3006 | /** |
| 2821 | 3007 | * Prepare the success message before it's shown |
| @@ -2935,9 +3121,9 @@ | ||
| 2935 | 3121 | global $frm_vars; |
| 2936 | 3122 | |
| 2937 | 3123 | FrmStylesController::enqueue_css(); |
| 2938 | 3124 | |
| 2939 | - if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) { | |
| 3125 | + if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) { | |
| 2940 | 3126 | // load formidable js |
| 2941 | 3127 | wp_enqueue_script( 'formidable' ); |
| 2942 | 3128 | } |
| 2943 | 3129 | } |
| @@ -2953,12 +3139,12 @@ | ||
| 2953 | 3139 | } |
| 2954 | 3140 | |
| 2955 | 3141 | /** |
| 2956 | 3142 | * @since 2.0.8 |
| 2957 | - * @return boolean | |
| 3143 | + * @return bool | |
| 2958 | 3144 | */ |
| 2959 | 3145 | private static function is_minification_on( $atts ) { |
| 2960 | - return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] ); | |
| 3146 | + return ! empty( $atts['minimize'] ); | |
| 2961 | 3147 | } |
| 2962 | 3148 | |
| 2963 | 3149 | /** |
| 2964 | 3150 | * @since 5.0.16 |
| @@ -2986,9 +3172,9 @@ | ||
| 2986 | 3172 | * Create a page with an embedded formidable Gutenberg block. |
| 2987 | 3173 | * |
| 2988 | 3174 | * @since 5.2 |
| 2989 | 3175 | * |
| 2990 | - * @return never | |
| 3176 | + * @return void | |
| 2991 | 3177 | */ |
| 2992 | 3178 | public static function create_page_with_shortcode() { |
| 2993 | 3179 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 2994 | 3180 | die( 0 ); |
| @@ -3033,10 +3219,9 @@ | ||
| 3033 | 3219 | |
| 3034 | 3220 | /** |
| 3035 | 3221 | * @since 5.3 |
| 3036 | 3222 | * |
| 3037 | - * @param string $content | |
| 3038 | - * @param int $form_id | |
| 3223 | + * @param int $form_id | |
| 3039 | 3224 | * @return string |
| 3040 | 3225 | */ |
| 3041 | 3226 | private static function get_page_shortcode_content_for_form( $form_id ) { |
| 3042 | 3227 | $shortcode = '[formidable id="' . $form_id . '"]'; |
| @@ -3047,9 +3232,9 @@ | ||
| 3047 | 3232 | |
| 3048 | 3233 | /** |
| 3049 | 3234 | * Get page dropdown for AJAX request for embedding form in an existing page. |
| 3050 | 3235 | * |
| 3051 | - * @return never | |
| 3236 | + * @return void | |
| 3052 | 3237 | */ |
| 3053 | 3238 | public static function get_page_dropdown() { |
| 3054 | 3239 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3055 | 3240 | die( 0 ); |
| @@ -3057,9 +3242,9 @@ | ||
| 3057 | 3242 | |
| 3058 | 3243 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 3059 | 3244 | |
| 3060 | 3245 | $html = FrmAppHelper::clip( |
| 3061 | - function() { | |
| 3246 | + function () { | |
| 3062 | 3247 | FrmAppHelper::maybe_autocomplete_pages_options( |
| 3063 | 3248 | array( |
| 3064 | 3249 | 'field_name' => 'frm_page_dropdown', |
| 3065 | 3250 | 'page_id' => '', |
| @@ -3079,15 +3264,8 @@ | ||
| 3079 | 3264 | |
| 3080 | 3265 | /** |
| 3081 | 3266 | * @deprecated 4.0 |
| 3082 | 3267 | */ |
| 3083 | - public static function new_form( $values = array() ) { | |
| 3084 | - FrmDeprecated::new_form( $values ); | |
| 3085 | - } | |
| 3086 | - | |
| 3087 | - /** | |
| 3088 | - * @deprecated 4.0 | |
| 3089 | - */ | |
| 3090 | 3268 | public static function create( $values = array() ) { |
| 3091 | 3269 | _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' ); |
| 3092 | 3270 | self::update( $values ); |
| 3093 | 3271 | } |
| @@ -3092,35 +3270,13 @@ | ||
| 3092 | 3270 | self::update( $values ); |
| 3093 | 3271 | } |
| 3094 | 3272 | |
| 3095 | 3273 | /** |
| 3096 | - * @deprecated 3.0 | |
| 3097 | - * @codeCoverageIgnore | |
| 3274 | + * @deprecated 6.7 | |
| 3275 | + * | |
| 3276 | + * @return bool | |
| 3098 | 3277 | */ |
| 3099 | - public static function bulk_create_template( $ids ) { | |
| 3100 | - return FrmDeprecated::bulk_create_template( $ids ); | |
| 3101 | - } | |
| 3102 | - | |
| 3103 | - /** | |
| 3104 | - * @deprecated 3.0 | |
| 3105 | - * @codeCoverageIgnore | |
| 3106 | - */ | |
| 3107 | - public static function edit_key() { | |
| 3108 | - FrmDeprecated::edit_key(); | |
| 3109 | - } | |
| 3110 | - | |
| 3111 | - /** | |
| 3112 | - * @deprecated 3.0 | |
| 3113 | - * @codeCoverageIgnore | |
| 3114 | - */ | |
| 3115 | - public static function edit_description() { | |
| 3116 | - FrmDeprecated::edit_description(); | |
| 3117 | - } | |
| 3118 | - | |
| 3119 | - /** | |
| 3120 | - * @deprecated 4.08 | |
| 3121 | - * @since 3.06 | |
| 3122 | - */ | |
| 3123 | - public static function add_new() { | |
| 3124 | - _deprecated_function( __FUNCTION__, '4.08' ); | |
| 3278 | + public static function expired() { | |
| 3279 | + _deprecated_function( __METHOD__, '6.7' ); | |
| 3280 | + return FrmAddonsController::is_license_expired(); | |
| 3125 | 3281 | } |
| 3126 | 3282 | } |