| @@ -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 ); |
| @@ -113,9 +123,9 @@ | ||
| 113 | 123 | * Create the default On submit action |
| 114 | 124 | * |
| 115 | 125 | * @since 6.0.0 |
| 116 | 126 | * |
| 117 | - * @param object|int $form Form object or ID. | |
| 127 | + * @param int|object $form Form object or ID. | |
| 118 | 128 | */ |
| 119 | 129 | private static function create_default_on_submit_action( $form ) { |
| 120 | 130 | FrmForm::maybe_get_form( $form ); |
| 121 | 131 | |
| @@ -134,16 +144,53 @@ | ||
| 134 | 144 | $action_control->create( $form->id ); |
| 135 | 145 | } |
| 136 | 146 | } |
| 137 | 147 | |
| 148 | + /** | |
| 149 | + * Creates submit button field. | |
| 150 | + * | |
| 151 | + * @since 6.9 | |
| 152 | + * | |
| 153 | + * @param int|object $form Form ID or object. | |
| 154 | + */ | |
| 155 | + private static function create_submit_button_field( $form ) { | |
| 156 | + FrmForm::maybe_get_form( $form ); | |
| 157 | + | |
| 158 | + if ( FrmSubmitHelper::get_submit_field( $form->id ) ) { | |
| 159 | + // Do not create submit button field if it exists. | |
| 160 | + return; | |
| 161 | + } | |
| 162 | + | |
| 163 | + FrmField::create( | |
| 164 | + array( | |
| 165 | + 'type' => FrmSubmitHelper::FIELD_TYPE, | |
| 166 | + 'name' => __( 'Submit', 'formidable' ), | |
| 167 | + 'field_order' => 9999, | |
| 168 | + 'form_id' => $form->id, | |
| 169 | + 'field_options' => FrmFieldsHelper::get_default_field_options( FrmSubmitHelper::FIELD_TYPE ), | |
| 170 | + 'description' => '', | |
| 171 | + 'default_value' => '', | |
| 172 | + 'options' => array(), | |
| 173 | + ) | |
| 174 | + ); | |
| 175 | + } | |
| 176 | + | |
| 177 | + /** | |
| 178 | + * @return void | |
| 179 | + */ | |
| 138 | 180 | public static function edit( $values = false ) { |
| 139 | 181 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 140 | 182 | |
| 141 | 183 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 142 | 184 | |
| 143 | - return self::get_edit_vars( $id ); | |
| 185 | + self::get_edit_vars( $id ); | |
| 144 | 186 | } |
| 145 | 187 | |
| 188 | + /** | |
| 189 | + * @param mixed $id | |
| 190 | + * @param string $message | |
| 191 | + * @return void | |
| 192 | + */ | |
| 146 | 193 | public static function settings( $id = false, $message = '' ) { |
| 147 | 194 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 148 | 195 | |
| 149 | 196 | if ( ! $id || ! is_numeric( $id ) ) { |
| @@ -151,21 +198,34 @@ | ||
| 151 | 198 | } |
| 152 | 199 | |
| 153 | 200 | FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id ); |
| 154 | 201 | |
| 155 | - return self::get_settings_vars( $id, array(), $message ); | |
| 202 | + self::get_settings_vars( $id, array(), $message ); | |
| 156 | 203 | } |
| 157 | 204 | |
| 158 | 205 | public static function update_settings() { |
| 159 | 206 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 207 | + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); | |
| 160 | 208 | |
| 209 | + if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { | |
| 210 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 211 | + $error_args = array( | |
| 212 | + 'title' => __( 'Verification failed', 'formidable' ), | |
| 213 | + 'body' => $frm_settings->admin_permission, | |
| 214 | + 'cancel_text' => __( 'Cancel', 'formidable' ), | |
| 215 | + ); | |
| 216 | + FrmAppController::show_error_modal( $error_args ); | |
| 217 | + return; | |
| 218 | + } | |
| 219 | + | |
| 161 | 220 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 162 | 221 | |
| 163 | - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 222 | + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 164 | 223 | $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 165 | 224 | |
| 166 | 225 | if ( count( $errors ) > 0 ) { |
| 167 | - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); | |
| 226 | + self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); | |
| 227 | + return; | |
| 168 | 228 | } |
| 169 | 229 | |
| 170 | 230 | do_action( 'frm_before_update_form_settings', $id ); |
| 171 | 231 | |
| @@ -179,9 +239,9 @@ | ||
| 179 | 239 | } |
| 180 | 240 | |
| 181 | 241 | $message = __( 'Settings Successfully Updated', 'formidable' ); |
| 182 | 242 | |
| 183 | - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); | |
| 243 | + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); | |
| 184 | 244 | } |
| 185 | 245 | |
| 186 | 246 | /** |
| 187 | 247 | * @param int $form_id |
| @@ -191,8 +251,11 @@ | ||
| 191 | 251 | $form = FrmForm::getOne( $form_id ); |
| 192 | 252 | return ! empty( $form->options['antispam'] ); |
| 193 | 253 | } |
| 194 | 254 | |
| 255 | + /** | |
| 256 | + * @return void | |
| 257 | + */ | |
| 195 | 258 | public static function update( $values = array() ) { |
| 196 | 259 | if ( empty( $values ) ) { |
| 197 | 260 | $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 198 | 261 | } |
| @@ -210,65 +273,74 @@ | ||
| 210 | 273 | |
| 211 | 274 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 212 | 275 | |
| 213 | 276 | 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' ); | |
| 277 | + self::get_edit_vars( $id, $errors ); | |
| 278 | + return; | |
| 279 | + } | |
| 218 | 280 | |
| 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 | - } | |
| 281 | + self::maybe_remove_draft_option_from_fields( $id ); | |
| 227 | 282 | |
| 228 | - if ( defined( 'DOING_AJAX' ) ) { | |
| 229 | - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 230 | - } | |
| 283 | + FrmForm::update( $id, $values ); | |
| 284 | + $message = __( 'Form was successfully updated.', 'formidable' ); | |
| 231 | 285 | |
| 232 | - return self::get_edit_vars( $id, array(), $message ); | |
| 286 | + if ( self::is_too_long( $values ) ) { | |
| 287 | + $message .= '<br/> ' . sprintf( | |
| 288 | + /* translators: %1$s: Start link HTML, %2$s: end link HTML */ | |
| 289 | + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ), | |
| 290 | + '<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">', | |
| 291 | + '</a>' | |
| 292 | + ); | |
| 233 | 293 | } |
| 294 | + | |
| 295 | + if ( defined( 'DOING_AJAX' ) ) { | |
| 296 | + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 297 | + } | |
| 298 | + | |
| 299 | + self::get_edit_vars( $id, array(), $message ); | |
| 234 | 300 | } |
| 235 | 301 | |
| 236 | 302 | /** |
| 303 | + * Remove the draft flag from any new fields from this current session. | |
| 304 | + * | |
| 305 | + * @since 6.8 | |
| 306 | + * | |
| 307 | + * @param int $form_id | |
| 308 | + * @return void | |
| 309 | + */ | |
| 310 | + private static function maybe_remove_draft_option_from_fields( $form_id ) { | |
| 311 | + $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' ); | |
| 312 | + if ( ! $draft_field_ids_csv ) { | |
| 313 | + // If the draft_fields input is empty there are no new fields in the session. | |
| 314 | + return; | |
| 315 | + } | |
| 316 | + | |
| 317 | + $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' ); | |
| 318 | + if ( ! $draft_field_ids ) { | |
| 319 | + // Exit early if the draft fields input is invalid. It should be a CSV of integer values. | |
| 320 | + return; | |
| 321 | + } | |
| 322 | + | |
| 323 | + $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids ); | |
| 324 | + foreach ( $draft_field_rows as $row ) { | |
| 325 | + $row->field_options['draft'] = 0; | |
| 326 | + FrmField::update( $row->id, array( 'field_options' => $row->field_options ) ); | |
| 327 | + } | |
| 328 | + } | |
| 329 | + | |
| 330 | + /** | |
| 237 | 331 | * Check if the value at the end of the form was included. |
| 238 | 332 | * If it's missing, it means other values at the end of the form |
| 239 | 333 | * were likely not saved either. |
| 240 | 334 | * |
| 241 | 335 | * @since 3.06.01 |
| 336 | + * | |
| 337 | + * @return bool | |
| 242 | 338 | */ |
| 243 | 339 | private static function is_too_long( $values ) { |
| 244 | - return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] ); | |
| 340 | + return empty( $values['frm_end'] ); | |
| 245 | 341 | } |
| 246 | 342 | |
| 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 | 343 | public static function duplicate() { |
| 272 | 344 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 273 | 345 | $nonce = FrmAppHelper::simple_get( '_wpnonce' ); |
| 274 | 346 | |
| @@ -282,10 +354,11 @@ | ||
| 282 | 354 | $url = admin_url( 'admin.php?page=formidable' ); |
| 283 | 355 | $message = 'form_duplicate_error'; |
| 284 | 356 | |
| 285 | 357 | if ( $form ) { |
| 286 | - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) ); | |
| 287 | - $message = 'form_duplicated'; | |
| 358 | + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : ''; | |
| 359 | + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template ); | |
| 360 | + $message = 'form_duplicated'; | |
| 288 | 361 | } |
| 289 | 362 | |
| 290 | 363 | $url .= '&message=' . $message; |
| 291 | 364 | |
| @@ -293,24 +366,28 @@ | ||
| 293 | 366 | exit(); |
| 294 | 367 | } |
| 295 | 368 | |
| 296 | 369 | /** |
| 297 | - * @return string | |
| 370 | + * @return string|null | |
| 298 | 371 | */ |
| 299 | 372 | public static function page_preview() { |
| 300 | 373 | $params = FrmForm::list_page_params(); |
| 301 | 374 | if ( ! $params['form'] ) { |
| 302 | - return; | |
| 375 | + return null; | |
| 303 | 376 | } |
| 304 | 377 | |
| 305 | 378 | $form = FrmForm::getOne( $params['form'] ); |
| 306 | - if ( $form ) { | |
| 307 | - return self::show_form( $form->id, '', 'auto', 'auto' ); | |
| 379 | + if ( ! $form ) { | |
| 380 | + return null; | |
| 308 | 381 | } |
| 382 | + | |
| 383 | + return self::show_form( $form->id, '', 'auto', 'auto' ); | |
| 309 | 384 | } |
| 310 | 385 | |
| 311 | 386 | /** |
| 312 | 387 | * @since 3.0 |
| 388 | + * | |
| 389 | + * @return void | |
| 313 | 390 | */ |
| 314 | 391 | public static function show_page_preview() { |
| 315 | 392 | echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 316 | 393 | } |
| @@ -360,8 +437,13 @@ | ||
| 360 | 437 | return; |
| 361 | 438 | } |
| 362 | 439 | |
| 363 | 440 | $random_page = reset( $random_page ); |
| 441 | + if ( ! is_a( $random_page, 'WP_Post' ) ) { | |
| 442 | + // The return type can also be int. | |
| 443 | + return; | |
| 444 | + } | |
| 445 | + | |
| 364 | 446 | query_posts( |
| 365 | 447 | array( |
| 366 | 448 | 'post_type' => 'page', |
| 367 | 449 | 'page_id' => $random_page->ID, |
| @@ -377,9 +459,9 @@ | ||
| 377 | 459 | * Set the WP $post global object. Used for in-theme preview when defining a page. |
| 378 | 460 | * |
| 379 | 461 | * @since 5.5.2 |
| 380 | 462 | * |
| 381 | - * @param WP_Post $post | |
| 463 | + * @param WP_Post $page The page object. | |
| 382 | 464 | * @return void |
| 383 | 465 | */ |
| 384 | 466 | private static function set_post_global( $page ) { |
| 385 | 467 | global $post; |
| @@ -387,8 +469,10 @@ | ||
| 387 | 469 | } |
| 388 | 470 | |
| 389 | 471 | /** |
| 390 | 472 | * @since 3.0 |
| 473 | + * | |
| 474 | + * @return void | |
| 391 | 475 | */ |
| 392 | 476 | private static function load_theme_preview() { |
| 393 | 477 | add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 ); |
| 394 | 478 | add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 ); |
| @@ -397,20 +481,39 @@ | ||
| 397 | 481 | add_filter( 'is_active_sidebar', '__return_false' ); |
| 398 | 482 | FrmStylesController::enqueue_css( 'enqueue', true ); |
| 399 | 483 | |
| 400 | 484 | if ( false === get_template_part( 'page' ) ) { |
| 485 | + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { | |
| 486 | + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' ); | |
| 487 | + } | |
| 401 | 488 | self::fallback_when_page_template_part_is_not_supported_by_theme(); |
| 402 | 489 | } |
| 403 | 490 | } |
| 404 | 491 | |
| 405 | 492 | /** |
| 493 | + * Add padding to the body for block themes. | |
| 494 | + * | |
| 495 | + * @since 6.5.2 | |
| 496 | + * | |
| 497 | + * @param array $classes The body classes list. | |
| 498 | + * @return array | |
| 499 | + */ | |
| 500 | + public static function preview_block_theme_body_classnames( $classes ) { | |
| 501 | + $classes[] = 'has-global-padding'; | |
| 502 | + return $classes; | |
| 503 | + } | |
| 504 | + | |
| 505 | + /** | |
| 406 | 506 | * Not every theme supports get_template_part( 'page' ). |
| 407 | 507 | * When this is not supported, false is returned, and we can handle a fallback. |
| 508 | + * | |
| 509 | + * @return void | |
| 408 | 510 | */ |
| 409 | 511 | private static function fallback_when_page_template_part_is_not_supported_by_theme() { |
| 410 | 512 | if ( have_posts() ) { |
| 411 | 513 | the_post(); |
| 412 | - get_header( '' ); | |
| 514 | + self::get_template( 'header' ); | |
| 515 | + | |
| 413 | 516 | // add some generic class names to the container to add some natural padding to the content. |
| 414 | 517 | // .entry-content catches the WordPress TwentyTwenty theme. |
| 415 | 518 | // .container catches Customizr content. |
| 416 | 519 | echo '<div class="container entry-content">'; |
| @@ -415,13 +518,54 @@ | ||
| 415 | 518 | // .container catches Customizr content. |
| 416 | 519 | echo '<div class="container entry-content">'; |
| 417 | 520 | the_content(); |
| 418 | 521 | echo '</div>'; |
| 419 | - get_footer(); | |
| 522 | + | |
| 523 | + self::get_template( 'footer' ); | |
| 420 | 524 | } |
| 421 | 525 | } |
| 422 | 526 | |
| 423 | 527 | /** |
| 528 | + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call | |
| 529 | + * and renders required html fragments calling required functions. | |
| 530 | + * | |
| 531 | + * @since 6.7.1 | |
| 532 | + * @param string $template | |
| 533 | + * @return void | |
| 534 | + */ | |
| 535 | + private static function get_template( $template ) { | |
| 536 | + if ( self::should_try_getting_template( $template ) ) { | |
| 537 | + call_user_func( 'get_' . $template ); | |
| 538 | + return; | |
| 539 | + } | |
| 540 | + | |
| 541 | + if ( 'header' === $template ) { | |
| 542 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php'; | |
| 543 | + return; | |
| 544 | + } | |
| 545 | + | |
| 546 | + if ( 'footer' === $template ) { | |
| 547 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php'; | |
| 548 | + } | |
| 549 | + } | |
| 550 | + | |
| 551 | + /** | |
| 552 | + * Returns true if calling a template function doesn't trigger deprecation warnings. | |
| 553 | + * | |
| 554 | + * @since 6.7.1 | |
| 555 | + * @param string $template | |
| 556 | + * @return bool | |
| 557 | + */ | |
| 558 | + private static function should_try_getting_template( $template ) { | |
| 559 | + $stylesheet_path = get_stylesheet_directory(); | |
| 560 | + $template_path = get_template_directory(); | |
| 561 | + $is_child_theme = $stylesheet_path !== $template_path; | |
| 562 | + $template_name = $template . '.php'; | |
| 563 | + | |
| 564 | + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name ); | |
| 565 | + } | |
| 566 | + | |
| 567 | + /** | |
| 424 | 568 | * Set the page title for the theme preview page |
| 425 | 569 | * |
| 426 | 570 | * @since 3.0 |
| 427 | 571 | */ |
| @@ -433,11 +577,14 @@ | ||
| 433 | 577 | return $title; |
| 434 | 578 | } |
| 435 | 579 | |
| 436 | 580 | /** |
| 437 | - * Set the page title for the theme preview page | |
| 581 | + * Set the page title for the theme preview page. | |
| 438 | 582 | * |
| 439 | 583 | * @since 3.0 |
| 584 | + * | |
| 585 | + * @param string $title | |
| 586 | + * @return string | |
| 440 | 587 | */ |
| 441 | 588 | public static function preview_title( $title ) { |
| 442 | 589 | return __( 'Form Preview', 'formidable' ); |
| 443 | 590 | } |
| @@ -442,15 +589,20 @@ | ||
| 442 | 589 | return __( 'Form Preview', 'formidable' ); |
| 443 | 590 | } |
| 444 | 591 | |
| 445 | 592 | /** |
| 446 | - * Set the page content for the theme preview page | |
| 593 | + * Set the page content for the theme preview page. | |
| 447 | 594 | * |
| 448 | 595 | * @since 3.0 |
| 596 | + * | |
| 597 | + * @param string $content | |
| 598 | + * @return string | |
| 449 | 599 | */ |
| 450 | 600 | public static function preview_content( $content ) { |
| 451 | 601 | if ( in_the_loop() ) { |
| 452 | - $content = self::show_page_preview(); | |
| 602 | + self::show_page_preview(); | |
| 603 | + // Clear the content for the page we're using. | |
| 604 | + $content = ''; | |
| 453 | 605 | } |
| 454 | 606 | |
| 455 | 607 | return $content; |
| 456 | 608 | } |
| @@ -460,8 +612,11 @@ | ||
| 460 | 612 | */ |
| 461 | 613 | private static function load_direct_preview() { |
| 462 | 614 | header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
| 463 | 615 | |
| 616 | + // print_emoji_styles is deprecated. | |
| 617 | + remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
| 618 | + | |
| 464 | 619 | $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' ); |
| 465 | 620 | if ( $key == '' ) { |
| 466 | 621 | $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' ); |
| 467 | 622 | } |
| @@ -470,11 +625,38 @@ | ||
| 470 | 625 | if ( empty( $form ) ) { |
| 471 | 626 | $form = FrmForm::getAll( array(), '', 1 ); |
| 472 | 627 | } |
| 473 | 628 | |
| 474 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' ); | |
| 629 | + self::fix_deprecated_null_param_warning(); | |
| 630 | + | |
| 631 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php'; | |
| 475 | 632 | } |
| 476 | 633 | |
| 634 | + /** | |
| 635 | + * Some themes have a null $src value. | |
| 636 | + * This function adds a filter to ensure that $src is not null. | |
| 637 | + * WP will call str_starts_with with the null value triggering a deprecated message otherwise. | |
| 638 | + * | |
| 639 | + * @since 6.10 | |
| 640 | + * | |
| 641 | + * @return void | |
| 642 | + */ | |
| 643 | + private static function fix_deprecated_null_param_warning() { | |
| 644 | + add_filter( | |
| 645 | + 'script_loader_src', | |
| 646 | + /** | |
| 647 | + * @param string|null $src | |
| 648 | + * @return string | |
| 649 | + */ | |
| 650 | + function ( $src ) { | |
| 651 | + if ( is_null( $src ) ) { | |
| 652 | + $src = ''; | |
| 653 | + } | |
| 654 | + return $src; | |
| 655 | + } | |
| 656 | + ); | |
| 657 | + } | |
| 658 | + | |
| 477 | 659 | public static function untrash() { |
| 478 | 660 | self::change_form_status( 'untrash' ); |
| 479 | 661 | } |
| 480 | 662 | |
| @@ -537,14 +719,14 @@ | ||
| 537 | 719 | FrmAppHelper::permission_check( $available_status[ $status ]['permission'] ); |
| 538 | 720 | |
| 539 | 721 | $params = FrmForm::list_page_params(); |
| 540 | 722 | |
| 541 | - //check nonce url | |
| 723 | + // Check nonce url. | |
| 542 | 724 | check_admin_referer( $status . '_form_' . $params['id'] ); |
| 543 | 725 | |
| 544 | 726 | $count = 0; |
| 545 | 727 | if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) { |
| 546 | - $count ++; | |
| 728 | + ++$count; | |
| 547 | 729 | } |
| 548 | 730 | |
| 549 | 731 | $form_type = FrmAppHelper::get_simple_request( |
| 550 | 732 | array( |
| @@ -556,9 +738,9 @@ | ||
| 556 | 738 | /* translators: %1$s: Number of forms */ |
| 557 | 739 | $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count ); |
| 558 | 740 | |
| 559 | 741 | /* 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>' ); | |
| 742 | + $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 | 743 | |
| 562 | 744 | $message = $available_status[ $status ]['message']; |
| 563 | 745 | |
| 564 | 746 | self::display_forms_list( $params, $message ); |
| @@ -563,8 +745,12 @@ | ||
| 563 | 745 | |
| 564 | 746 | self::display_forms_list( $params, $message ); |
| 565 | 747 | } |
| 566 | 748 | |
| 749 | + /** | |
| 750 | + * @param array $ids | |
| 751 | + * @return string | |
| 752 | + */ | |
| 567 | 753 | public static function bulk_trash( $ids ) { |
| 568 | 754 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 569 | 755 | |
| 570 | 756 | $count = 0; |
| @@ -569,9 +755,9 @@ | ||
| 569 | 755 | |
| 570 | 756 | $count = 0; |
| 571 | 757 | foreach ( $ids as $id ) { |
| 572 | 758 | if ( FrmForm::trash( $id ) ) { |
| 573 | - $count ++; | |
| 759 | + ++$count; | |
| 574 | 760 | } |
| 575 | 761 | } |
| 576 | 762 | |
| 577 | 763 | $current_page = FrmAppHelper::get_simple_request( |
| @@ -600,9 +786,9 @@ | ||
| 600 | 786 | check_admin_referer( 'destroy_form_' . $params['id'] ); |
| 601 | 787 | |
| 602 | 788 | $count = 0; |
| 603 | 789 | if ( FrmForm::destroy( $params['id'] ) ) { |
| 604 | - $count ++; | |
| 790 | + ++$count; | |
| 605 | 791 | } |
| 606 | 792 | |
| 607 | 793 | /* translators: %1$s: Number of forms */ |
| 608 | 794 | $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count ); |
| @@ -609,8 +795,12 @@ | ||
| 609 | 795 | |
| 610 | 796 | self::display_forms_list( $params, $message ); |
| 611 | 797 | } |
| 612 | 798 | |
| 799 | + /** | |
| 800 | + * @param array $ids | |
| 801 | + * @return string | |
| 802 | + */ | |
| 613 | 803 | public static function bulk_destroy( $ids ) { |
| 614 | 804 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 615 | 805 | |
| 616 | 806 | $count = 0; |
| @@ -616,19 +806,24 @@ | ||
| 616 | 806 | $count = 0; |
| 617 | 807 | foreach ( $ids as $id ) { |
| 618 | 808 | $d = FrmForm::destroy( $id ); |
| 619 | 809 | if ( $d ) { |
| 620 | - $count ++; | |
| 810 | + ++$count; | |
| 621 | 811 | } |
| 622 | 812 | } |
| 623 | 813 | |
| 624 | - /* translators: %1$s: Number of forms */ | |
| 625 | - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 814 | + if ( $count ) { | |
| 815 | + /* translators: %1$s: Number of forms */ | |
| 816 | + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 817 | + } | |
| 626 | 818 | |
| 627 | - return $message; | |
| 819 | + return ''; | |
| 628 | 820 | } |
| 629 | 821 | |
| 630 | - private static function delete_all() { | |
| 822 | + /** | |
| 823 | + * @since 6.7.1 Function went from private to public. | |
| 824 | + */ | |
| 825 | + public static function delete_all() { | |
| 631 | 826 | // Check nonce url. |
| 632 | 827 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
| 633 | 828 | if ( $permission_error !== false ) { |
| 634 | 829 | self::display_forms_list( array(), '', array( $permission_error ) ); |
| @@ -635,14 +830,15 @@ | ||
| 635 | 830 | |
| 636 | 831 | return; |
| 637 | 832 | } |
| 638 | 833 | |
| 639 | - $count = FrmForm::scheduled_delete( time() ); | |
| 834 | + $count = FrmForm::scheduled_delete( time() ); | |
| 835 | + $url = remove_query_arg( array( 'delete_all' ) ); | |
| 640 | 836 | |
| 641 | - /* translators: %1$s: Number of forms */ | |
| 642 | - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 837 | + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count; | |
| 643 | 838 | |
| 644 | - self::display_forms_list( array(), $message ); | |
| 839 | + wp_safe_redirect( $url ); | |
| 840 | + die(); | |
| 645 | 841 | } |
| 646 | 842 | |
| 647 | 843 | /** |
| 648 | 844 | * Create a new form from the modal. |
| @@ -655,9 +851,9 @@ | ||
| 655 | 851 | |
| 656 | 852 | $new_values = self::get_modal_values(); |
| 657 | 853 | $new_values['form_key'] = $new_values['name']; |
| 658 | 854 | $new_values['options'] = array( |
| 659 | - 'antispam' => 1, | |
| 855 | + 'antispam' => 1, | |
| 660 | 856 | 'on_submit_migrated' => 1, |
| 661 | 857 | ); |
| 662 | 858 | |
| 663 | 859 | /** |
| @@ -676,13 +872,14 @@ | ||
| 676 | 872 | * @param int $form_id |
| 677 | 873 | */ |
| 678 | 874 | do_action( 'frm_build_new_form', $form_id ); |
| 679 | 875 | |
| 876 | + self::create_submit_button_field( $form_id ); | |
| 680 | 877 | self::create_default_on_submit_action( $form_id ); |
| 681 | 878 | self::create_default_email_action( $form_id ); |
| 682 | 879 | |
| 683 | 880 | $response = array( |
| 684 | - 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 881 | + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 685 | 882 | ); |
| 686 | 883 | |
| 687 | 884 | echo wp_json_encode( $response ); |
| 688 | 885 | wp_die(); |
| @@ -688,46 +885,15 @@ | ||
| 688 | 885 | wp_die(); |
| 689 | 886 | } |
| 690 | 887 | |
| 691 | 888 | /** |
| 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 | 889 | * Before creating a new form, get the name and description from the modal. |
| 726 | 890 | * |
| 727 | 891 | * @since 4.0 |
| 892 | + * | |
| 893 | + * @return array<string,string> | |
| 728 | 894 | */ |
| 729 | - private static function get_modal_values() { | |
| 895 | + public static function get_modal_values() { | |
| 730 | 896 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 731 | 897 | $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 732 | 898 | |
| 733 | 899 | return array( |
| @@ -740,17 +906,24 @@ | ||
| 740 | 906 | * Inserts Formidable button |
| 741 | 907 | * Hook exists since 2.5.0 |
| 742 | 908 | * |
| 743 | 909 | * @since 2.0.15 |
| 910 | + * | |
| 911 | + * @return void | |
| 744 | 912 | */ |
| 745 | 913 | public static function insert_form_button() { |
| 746 | 914 | 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>'; | |
| 915 | + // Store the result in memory and re-use it when this function is called multiple times. | |
| 916 | + // This helps speed up the form builder when there are a lot of HTML fields, where this | |
| 917 | + // button is inserted once per HTML field. | |
| 918 | + // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally. | |
| 919 | + if ( ! isset( self::$formidable_tinymce_button ) ) { | |
| 920 | + FrmAppHelper::load_admin_wide_js(); | |
| 921 | + $menu_name = FrmAppHelper::get_menu_name(); | |
| 922 | + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() ); | |
| 923 | + 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>'; | |
| 924 | + } | |
| 925 | + echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 753 | 926 | } |
| 754 | 927 | } |
| 755 | 928 | |
| 756 | 929 | /** |
| @@ -838,9 +1011,9 @@ | ||
| 838 | 1011 | $form_id = $opts['form_id']; |
| 839 | 1012 | unset( $opts['form_id'] ); |
| 840 | 1013 | } |
| 841 | 1014 | |
| 842 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' ); | |
| 1015 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php'; | |
| 843 | 1016 | |
| 844 | 1017 | echo '</div>'; |
| 845 | 1018 | |
| 846 | 1019 | wp_die(); |
| @@ -908,8 +1081,11 @@ | ||
| 908 | 1081 | |
| 909 | 1082 | return $columns; |
| 910 | 1083 | } |
| 911 | 1084 | |
| 1085 | + /** | |
| 1086 | + * @return array<string,string> | |
| 1087 | + */ | |
| 912 | 1088 | public static function get_sortable_columns() { |
| 913 | 1089 | return array( |
| 914 | 1090 | 'id' => 'id', |
| 915 | 1091 | 'name' => 'name', |
| @@ -943,9 +1119,9 @@ | ||
| 943 | 1119 | return $hidden_columns; |
| 944 | 1120 | } |
| 945 | 1121 | |
| 946 | 1122 | public static function save_per_page( $save, $option, $value ) { |
| 947 | - if ( $option == 'formidable_page_formidable_per_page' ) { | |
| 1123 | + if ( $option === 'formidable_page_formidable_per_page' ) { | |
| 948 | 1124 | $save = (int) $value; |
| 949 | 1125 | } |
| 950 | 1126 | |
| 951 | 1127 | return $save; |
| @@ -951,146 +1127,49 @@ | ||
| 951 | 1127 | return $save; |
| 952 | 1128 | } |
| 953 | 1129 | |
| 954 | 1130 | /** |
| 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 | - * | |
| 1131 | + * @param int|string $id | |
| 1132 | + * @param array $errors | |
| 1133 | + * @param string $message | |
| 1134 | + * @param bool $create_link | |
| 965 | 1135 | * @return void |
| 966 | 1136 | */ |
| 967 | - public static function before_list_templates() { | |
| 968 | - global $frm_templates; | |
| 969 | - global $frm_expired; | |
| 970 | - global $frm_license_type; | |
| 1137 | + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1138 | + global $frm_vars; | |
| 971 | 1139 | |
| 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 | - } | |
| 1140 | + $form = FrmForm::getOne( $id ); | |
| 1141 | + $error_args = array( | |
| 1142 | + 'title' => __( 'You can\'t edit the form', 'formidable' ), | |
| 1143 | + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ), | |
| 1144 | + 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 1145 | + 'continue_url' => add_query_arg( | |
| 1146 | + array( | |
| 1147 | + 'page' => 'formidable', | |
| 1148 | + ) | |
| 1149 | + ), | |
| 1029 | 1150 | ); |
| 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 | - } | |
| 1151 | + if ( ! $form ) { | |
| 1152 | + FrmAppController::show_error_modal( $error_args ); | |
| 1153 | + return; | |
| 1056 | 1154 | } |
| 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 | 1155 | |
| 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, | |
| 1156 | + if ( 'trash' === $form->status ) { | |
| 1157 | + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' ); | |
| 1158 | + $error_args['continue_url'] = add_query_arg( | |
| 1159 | + array( | |
| 1160 | + 'page' => 'formidable', | |
| 1161 | + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ), | |
| 1162 | + 'form_type' => 'trash', | |
| 1163 | + 'frm_action' => 'untrash', | |
| 1164 | + 'id' => $id, | |
| 1165 | + ) | |
| 1079 | 1166 | ); |
| 1080 | - array_unshift( $templates, $template ); | |
| 1081 | - unset( $template ); | |
| 1167 | + $error_args['continue_text'] = __( 'Restore form', 'formidable' ); | |
| 1168 | + FrmAppController::show_error_modal( $error_args ); | |
| 1169 | + return; | |
| 1082 | 1170 | } |
| 1083 | - } | |
| 1084 | 1171 | |
| 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 | 1172 | if ( $form->parent_form_id ) { |
| 1094 | 1173 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1095 | 1174 | 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 | 1175 | } |
| @@ -1101,8 +1180,9 @@ | ||
| 1101 | 1180 | |
| 1102 | 1181 | // Automatically add end section fields if they don't exist (2.0 migration). |
| 1103 | 1182 | $reset_fields = false; |
| 1104 | 1183 | FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
| 1184 | + FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields ); | |
| 1105 | 1185 | |
| 1106 | 1186 | if ( $reset_fields ) { |
| 1107 | 1187 | $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
| 1108 | 1188 | } |
| @@ -1129,17 +1209,21 @@ | ||
| 1129 | 1209 | |
| 1130 | 1210 | self::maybe_update_form_builder_message( $message ); |
| 1131 | 1211 | |
| 1132 | 1212 | $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); |
| 1133 | - $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] ); | |
| 1213 | + $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] ); | |
| 1134 | 1214 | |
| 1135 | 1215 | if ( defined( 'DOING_AJAX' ) ) { |
| 1136 | 1216 | wp_die(); |
| 1137 | - } else { | |
| 1138 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); | |
| 1139 | 1217 | } |
| 1218 | + | |
| 1219 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php'; | |
| 1140 | 1220 | } |
| 1141 | 1221 | |
| 1222 | + /** | |
| 1223 | + * @param array $fields | |
| 1224 | + * @return array | |
| 1225 | + */ | |
| 1142 | 1226 | public static function update_form_builder_fields( $fields, $form ) { |
| 1143 | 1227 | foreach ( $fields as $field ) { |
| 1144 | 1228 | $field->do_not_include_icons = true; |
| 1145 | 1229 | } |
| @@ -1151,13 +1235,21 @@ | ||
| 1151 | 1235 | $message = __( 'Form was Successfully Copied', 'formidable' ); |
| 1152 | 1236 | } |
| 1153 | 1237 | } |
| 1154 | 1238 | |
| 1239 | + /** | |
| 1240 | + * @param int|string $id | |
| 1241 | + * @param array $errors | |
| 1242 | + * @param array|string $args | |
| 1243 | + * @return void | |
| 1244 | + */ | |
| 1155 | 1245 | public static function get_settings_vars( $id, $errors = array(), $args = array() ) { |
| 1156 | 1246 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 1157 | 1247 | |
| 1158 | 1248 | global $frm_vars; |
| 1159 | 1249 | |
| 1250 | + self::maybe_print_media_templates(); | |
| 1251 | + | |
| 1160 | 1252 | if ( ! is_array( $args ) ) { |
| 1161 | 1253 | // For reverse compatibility. |
| 1162 | 1254 | $args = array( |
| 1163 | 1255 | 'message' => $args, |
| @@ -1190,17 +1282,38 @@ | ||
| 1190 | 1282 | |
| 1191 | 1283 | $sections = self::get_settings_tabs( $values ); |
| 1192 | 1284 | $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' ); |
| 1193 | 1285 | |
| 1194 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' ); | |
| 1286 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php'; | |
| 1195 | 1287 | } |
| 1196 | 1288 | |
| 1197 | 1289 | /** |
| 1290 | + * 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. | |
| 1291 | + * | |
| 1292 | + * @since 6.10 | |
| 1293 | + * | |
| 1294 | + * @return void | |
| 1295 | + */ | |
| 1296 | + private static function maybe_print_media_templates() { | |
| 1297 | + if ( FrmAppHelper::pro_is_included() ) { | |
| 1298 | + // This issue does not exist when Pro is active so exit early. | |
| 1299 | + return; | |
| 1300 | + } | |
| 1301 | + | |
| 1302 | + add_action( | |
| 1303 | + 'wp_enqueue_editor', | |
| 1304 | + function () { | |
| 1305 | + wp_print_media_templates(); | |
| 1306 | + } | |
| 1307 | + ); | |
| 1308 | + } | |
| 1309 | + | |
| 1310 | + /** | |
| 1198 | 1311 | * @since 4.0 |
| 1199 | 1312 | */ |
| 1200 | 1313 | public static function form_publish_button( $atts ) { |
| 1201 | 1314 | $values = $atts['values']; |
| 1202 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' ); | |
| 1315 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php'; | |
| 1203 | 1316 | } |
| 1204 | 1317 | |
| 1205 | 1318 | /** |
| 1206 | 1319 | * Get a list of all the settings tabs for the form settings page. |
| @@ -1225,9 +1338,9 @@ | ||
| 1225 | 1338 | 'icon' => 'frm_icon_font frm_mail_bulk_icon', |
| 1226 | 1339 | ), |
| 1227 | 1340 | 'permissions' => array( |
| 1228 | 1341 | 'name' => __( 'Form Permissions', 'formidable' ), |
| 1229 | - 'icon' => 'frm_icon_font frm_lock_icon', | |
| 1342 | + 'icon' => 'frm_icon_font frm_lock_closed_icon', | |
| 1230 | 1343 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1231 | 1344 | 'data' => array( |
| 1232 | 1345 | 'medium' => 'permissions', |
| 1233 | 1346 | 'upgrade' => __( 'Form Permissions', 'formidable' ), |
| @@ -1234,9 +1347,9 @@ | ||
| 1234 | 1347 | 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ), |
| 1235 | 1348 | 'screenshot' => 'permissions.png', |
| 1236 | 1349 | ), |
| 1237 | 1350 | ), |
| 1238 | - 'scheduling' => array( | |
| 1351 | + 'scheduling' => array( | |
| 1239 | 1352 | 'name' => __( 'Form Scheduling', 'formidable' ), |
| 1240 | 1353 | 'icon' => 'frm_icon_font frm_calendar_icon', |
| 1241 | 1354 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1242 | 1355 | 'data' => array( |
| @@ -1269,9 +1382,9 @@ | ||
| 1269 | 1382 | 'screenshot' => 'chat.png', |
| 1270 | 1383 | ) |
| 1271 | 1384 | ), |
| 1272 | 1385 | ), |
| 1273 | - 'abandonment' => array( | |
| 1386 | + 'abandonment' => array( | |
| 1274 | 1387 | 'name' => __( 'Form Abandonment', 'formidable' ), |
| 1275 | 1388 | 'icon' => 'frm_icon_font frm_abandoned_icon', |
| 1276 | 1389 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1277 | 1390 | 'data' => FrmAppHelper::get_upgrade_data_params( |
| @@ -1298,13 +1411,8 @@ | ||
| 1298 | 1411 | } |
| 1299 | 1412 | |
| 1300 | 1413 | $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values ); |
| 1301 | 1414 | |
| 1302 | - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) { | |
| 1303 | - // Prevent settings from showing in 2 spots. | |
| 1304 | - unset( $sections['permissions'], $sections['scheduling'] ); | |
| 1305 | - } | |
| 1306 | - | |
| 1307 | 1415 | foreach ( $sections as $key => $section ) { |
| 1308 | 1416 | $defaults = array( |
| 1309 | 1417 | 'html_class' => '', |
| 1310 | 1418 | 'name' => ucfirst( $key ), |
| @@ -1326,9 +1434,9 @@ | ||
| 1326 | 1434 | $section['id'] = $section['anchor']; |
| 1327 | 1435 | } |
| 1328 | 1436 | |
| 1329 | 1437 | $sections[ $key ] = $section; |
| 1330 | - } | |
| 1438 | + }//end foreach | |
| 1331 | 1439 | |
| 1332 | 1440 | return $sections; |
| 1333 | 1441 | } |
| 1334 | 1442 | |
| @@ -1335,8 +1443,9 @@ | ||
| 1335 | 1443 | /** |
| 1336 | 1444 | * @since 4.0 |
| 1337 | 1445 | * |
| 1338 | 1446 | * @param array $values |
| 1447 | + * @return void | |
| 1339 | 1448 | */ |
| 1340 | 1449 | public static function advanced_settings( $values ) { |
| 1341 | 1450 | $first_h3 = 'frm_first_h3'; |
| 1342 | 1451 | |
| @@ -1344,8 +1453,9 @@ | ||
| 1344 | 1453 | } |
| 1345 | 1454 | |
| 1346 | 1455 | /** |
| 1347 | 1456 | * @param array $values |
| 1457 | + * @return void | |
| 1348 | 1458 | */ |
| 1349 | 1459 | public static function render_spam_settings( $values ) { |
| 1350 | 1460 | if ( function_exists( 'akismet_http_post' ) ) { |
| 1351 | 1461 | include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php'; |
| @@ -1357,16 +1467,12 @@ | ||
| 1357 | 1467 | /** |
| 1358 | 1468 | * @since 4.0 |
| 1359 | 1469 | * |
| 1360 | 1470 | * @param array $values |
| 1471 | + * @return void | |
| 1361 | 1472 | */ |
| 1362 | 1473 | public static function buttons_settings( $values ) { |
| 1363 | - $styles = apply_filters( 'frm_get_style_opts', array() ); | |
| 1364 | - | |
| 1365 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 1366 | - $no_global_style = $frm_settings->load_style === 'none'; | |
| 1367 | - | |
| 1368 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' ); | |
| 1474 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php'; | |
| 1369 | 1475 | } |
| 1370 | 1476 | |
| 1371 | 1477 | /** |
| 1372 | 1478 | * @since 4.0 |
| @@ -1371,11 +1477,12 @@ | ||
| 1371 | 1477 | /** |
| 1372 | 1478 | * @since 4.0 |
| 1373 | 1479 | * |
| 1374 | 1480 | * @param array $values |
| 1481 | + * @return void | |
| 1375 | 1482 | */ |
| 1376 | 1483 | public static function html_settings( $values ) { |
| 1377 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' ); | |
| 1484 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php'; | |
| 1378 | 1485 | } |
| 1379 | 1486 | |
| 1380 | 1487 | /** |
| 1381 | 1488 | * Replace old Submit Button href with new href to avoid errors in Chrome |
| @@ -1381,9 +1488,10 @@ | ||
| 1381 | 1488 | * Replace old Submit Button href with new href to avoid errors in Chrome |
| 1382 | 1489 | * |
| 1383 | 1490 | * @since 2.03.08 |
| 1384 | 1491 | * |
| 1385 | - * @param array|boolean $values | |
| 1492 | + * @param array|bool $values | |
| 1493 | + * @return void | |
| 1386 | 1494 | */ |
| 1387 | 1495 | private static function clean_submit_html( &$values ) { |
| 1388 | 1496 | if ( is_array( $values ) && isset( $values['submit_html'] ) ) { |
| 1389 | 1497 | $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] ); |
| @@ -1404,8 +1512,13 @@ | ||
| 1404 | 1512 | |
| 1405 | 1513 | return $classes; |
| 1406 | 1514 | } |
| 1407 | 1515 | |
| 1516 | + /** | |
| 1517 | + * @param int|string $form_id | |
| 1518 | + * @param string $class | |
| 1519 | + * @return void | |
| 1520 | + */ | |
| 1408 | 1521 | public static function mb_tags_box( $form_id, $class = '' ) { |
| 1409 | 1522 | $fields = FrmField::get_all_for_form( $form_id, '', 'include' ); |
| 1410 | 1523 | |
| 1411 | 1524 | /** |
| @@ -1418,9 +1531,9 @@ | ||
| 1418 | 1531 | */ |
| 1419 | 1532 | $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) ); |
| 1420 | 1533 | $linked_forms = array(); |
| 1421 | 1534 | $col = 'one'; |
| 1422 | - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false; | |
| 1535 | + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ); | |
| 1423 | 1536 | |
| 1424 | 1537 | $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() ); |
| 1425 | 1538 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 1426 | 1539 | |
| @@ -1425,9 +1538,9 @@ | ||
| 1425 | 1538 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 1426 | 1539 | |
| 1427 | 1540 | $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) ); |
| 1428 | 1541 | |
| 1429 | - include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' ); | |
| 1542 | + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php'; | |
| 1430 | 1543 | } |
| 1431 | 1544 | |
| 1432 | 1545 | /** |
| 1433 | 1546 | * @since 3.04.01 |
| @@ -1440,9 +1553,9 @@ | ||
| 1440 | 1553 | ), |
| 1441 | 1554 | ); |
| 1442 | 1555 | |
| 1443 | 1556 | $user_fields = self::user_shortcodes(); |
| 1444 | - if ( ! empty( $user_fields ) ) { | |
| 1557 | + if ( $user_fields ) { | |
| 1445 | 1558 | $user_helpers = array(); |
| 1446 | 1559 | foreach ( $user_fields as $uk => $uf ) { |
| 1447 | 1560 | $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf; |
| 1448 | 1561 | unset( $uk, $uf ); |
| @@ -1448,9 +1561,9 @@ | ||
| 1448 | 1561 | unset( $uk, $uf ); |
| 1449 | 1562 | } |
| 1450 | 1563 | |
| 1451 | 1564 | $advanced_helpers['user_id'] = array( |
| 1452 | - 'codes' => $user_helpers, | |
| 1565 | + 'codes' => $user_helpers, | |
| 1453 | 1566 | ); |
| 1454 | 1567 | } |
| 1455 | 1568 | |
| 1456 | 1569 | /** |
| @@ -1591,11 +1704,11 @@ | ||
| 1591 | 1704 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1592 | 1705 | |
| 1593 | 1706 | echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 1594 | 1707 | array( |
| 1595 | - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), | |
| 1708 | + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1596 | 1709 | 'default_email' => true, |
| 1597 | - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), | |
| 1710 | + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1598 | 1711 | ) |
| 1599 | 1712 | ); |
| 1600 | 1713 | wp_die(); |
| 1601 | 1714 | } |
| @@ -1601,10 +1714,10 @@ | ||
| 1601 | 1714 | } |
| 1602 | 1715 | |
| 1603 | 1716 | /** |
| 1604 | 1717 | * @param string $content |
| 1605 | - * @param stdClass|string|int $form | |
| 1606 | - * @param stdClass|string|int|false $entry | |
| 1718 | + * @param int|stdClass|string $form | |
| 1719 | + * @param false|int|stdClass|string $entry | |
| 1607 | 1720 | * @return string |
| 1608 | 1721 | */ |
| 1609 | 1722 | public static function filter_content( $content, $form, $entry = false ) { |
| 1610 | 1723 | $content = self::replace_form_name_shortcodes( $content, $form ); |
| @@ -1617,8 +1730,16 @@ | ||
| 1617 | 1730 | if ( is_object( $form ) ) { |
| 1618 | 1731 | $form = $form->id; |
| 1619 | 1732 | } |
| 1620 | 1733 | |
| 1734 | + /* | |
| 1735 | + * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty, | |
| 1736 | + * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work. | |
| 1737 | + */ | |
| 1738 | + if ( ! empty( $entry->parent_entry ) ) { | |
| 1739 | + $form = $entry->parent_entry->form_id; | |
| 1740 | + } | |
| 1741 | + | |
| 1621 | 1742 | $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form ); |
| 1622 | 1743 | $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes ); |
| 1623 | 1744 | |
| 1624 | 1745 | return $content; |
| @@ -1628,11 +1749,11 @@ | ||
| 1628 | 1749 | * Replace any [form_name] shortcodes in a string. |
| 1629 | 1750 | * |
| 1630 | 1751 | * @since 5.5 |
| 1631 | 1752 | * |
| 1632 | - * @param string|array $string | |
| 1633 | - * @param stdClass|string|int $form | |
| 1634 | - * @return string|array | |
| 1753 | + * @param array|string $string | |
| 1754 | + * @param int|stdClass|string $form | |
| 1755 | + * @return array|string | |
| 1635 | 1756 | */ |
| 1636 | 1757 | public static function replace_form_name_shortcodes( $string, $form ) { |
| 1637 | 1758 | if ( ! is_string( $string ) ) { |
| 1638 | 1759 | return $string; |
| @@ -1650,9 +1771,9 @@ | ||
| 1650 | 1771 | return str_replace( '[form_name]', $form_name, $string ); |
| 1651 | 1772 | } |
| 1652 | 1773 | |
| 1653 | 1774 | /** |
| 1654 | - * @param stdClass|string|int|false $entry | |
| 1775 | + * @param false|int|stdClass|string $entry | |
| 1655 | 1776 | * @return void |
| 1656 | 1777 | */ |
| 1657 | 1778 | private static function get_entry_by_param( &$entry ) { |
| 1658 | 1779 | if ( ! $entry || ! is_object( $entry ) ) { |
| @@ -1667,8 +1788,12 @@ | ||
| 1667 | 1788 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
| 1668 | 1789 | return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); |
| 1669 | 1790 | } |
| 1670 | 1791 | |
| 1792 | + /** | |
| 1793 | + * @param array $errors | |
| 1794 | + * @return array | |
| 1795 | + */ | |
| 1671 | 1796 | public static function process_bulk_form_actions( $errors ) { |
| 1672 | 1797 | if ( ! $_REQUEST ) { |
| 1673 | 1798 | return $errors; |
| 1674 | 1799 | } |
| @@ -1712,9 +1837,9 @@ | ||
| 1712 | 1837 | case 'untrash': |
| 1713 | 1838 | $message = self::bulk_untrash( $ids ); |
| 1714 | 1839 | } |
| 1715 | 1840 | |
| 1716 | - if ( isset( $message ) && ! empty( $message ) ) { | |
| 1841 | + if ( ! empty( $message ) ) { | |
| 1717 | 1842 | $errors['message'] = $message; |
| 1718 | 1843 | } |
| 1719 | 1844 | |
| 1720 | 1845 | return $errors; |
| @@ -1734,9 +1859,9 @@ | ||
| 1734 | 1859 | $json_vars = json_decode( $json_vars, true ); |
| 1735 | 1860 | if ( empty( $json_vars ) ) { |
| 1736 | 1861 | // json decoding failed so we should return an error message. |
| 1737 | 1862 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 1738 | - if ( 'edit' == $action ) { | |
| 1863 | + if ( 'edit' === $action ) { | |
| 1739 | 1864 | $action = 'update'; |
| 1740 | 1865 | } |
| 1741 | 1866 | |
| 1742 | 1867 | add_filter( 'frm_validate_form', 'FrmFormsController::json_error' ); |
| @@ -1752,16 +1877,14 @@ | ||
| 1752 | 1877 | if ( isset( $_REQUEST['delete_all'] ) ) { |
| 1753 | 1878 | // Override the action for this page. |
| 1754 | 1879 | $action = 'delete_all'; |
| 1755 | 1880 | } |
| 1756 | - } | |
| 1881 | + }//end if | |
| 1757 | 1882 | |
| 1758 | 1883 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1759 | 1884 | FrmAppHelper::trigger_hook_load( 'form' ); |
| 1760 | 1885 | |
| 1761 | 1886 | switch ( $action ) { |
| 1762 | - case 'new': | |
| 1763 | - return self::new_form( $vars ); | |
| 1764 | 1887 | case 'create': |
| 1765 | 1888 | case 'edit': |
| 1766 | 1889 | case 'update': |
| 1767 | 1890 | case 'trash': |
| @@ -1766,16 +1889,17 @@ | ||
| 1766 | 1889 | case 'update': |
| 1767 | 1890 | case 'trash': |
| 1768 | 1891 | case 'untrash': |
| 1769 | 1892 | case 'destroy': |
| 1770 | - case 'delete_all': | |
| 1771 | 1893 | case 'settings': |
| 1772 | 1894 | case 'update_settings': |
| 1773 | 1895 | return self::$action( $vars ); |
| 1774 | 1896 | case 'lite-reports': |
| 1775 | - return self::no_reports( $vars ); | |
| 1897 | + self::no_reports( $vars ); | |
| 1898 | + return; | |
| 1776 | 1899 | case 'views': |
| 1777 | - return self::no_views( $vars ); | |
| 1900 | + self::no_views( $vars ); | |
| 1901 | + return; | |
| 1778 | 1902 | default: |
| 1779 | 1903 | do_action( 'frm_form_action_' . $action ); |
| 1780 | 1904 | if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) { |
| 1781 | 1905 | return; |
| @@ -1798,14 +1922,47 @@ | ||
| 1798 | 1922 | self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) ); |
| 1799 | 1923 | return; |
| 1800 | 1924 | } |
| 1801 | 1925 | |
| 1926 | + if ( 'forms_permanently_deleted' === $message ) { | |
| 1927 | + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' ); | |
| 1928 | + /* translators: %1$s: Number of forms */ | |
| 1929 | + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 1930 | + self::display_forms_list( array(), $message, '' ); | |
| 1931 | + return; | |
| 1932 | + } | |
| 1933 | + | |
| 1802 | 1934 | self::display_forms_list(); |
| 1803 | 1935 | |
| 1804 | 1936 | return; |
| 1805 | - } | |
| 1937 | + }//end switch | |
| 1806 | 1938 | } |
| 1807 | 1939 | |
| 1940 | + /** | |
| 1941 | + * Rename a form. | |
| 1942 | + * | |
| 1943 | + * Handles the AJAX request for renaming a form. | |
| 1944 | + * | |
| 1945 | + * @since 6.7 | |
| 1946 | + * | |
| 1947 | + * @return void | |
| 1948 | + */ | |
| 1949 | + public static function rename_form() { | |
| 1950 | + // Check permission and nonce | |
| 1951 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 1952 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 1953 | + | |
| 1954 | + // Get posted data | |
| 1955 | + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); | |
| 1956 | + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' ); | |
| 1957 | + | |
| 1958 | + // Update the form name and form key. | |
| 1959 | + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' ); | |
| 1960 | + FrmForm::update( $form_id, compact( 'name', 'form_key' ) ); | |
| 1961 | + | |
| 1962 | + wp_send_json_success( compact( 'form_key' ) ); | |
| 1963 | + } | |
| 1964 | + | |
| 1808 | 1965 | public static function json_error( $errors ) { |
| 1809 | 1966 | $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
| 1810 | 1967 | |
| 1811 | 1968 | return $errors; |
| @@ -1814,11 +1971,12 @@ | ||
| 1814 | 1971 | /** |
| 1815 | 1972 | * Education for premium features. |
| 1816 | 1973 | * |
| 1817 | 1974 | * @since 4.05 |
| 1975 | + * @return void | |
| 1818 | 1976 | */ |
| 1819 | 1977 | public static function add_form_style_tab_options() { |
| 1820 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' ); | |
| 1978 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php'; | |
| 1821 | 1979 | } |
| 1822 | 1980 | |
| 1823 | 1981 | /** |
| 1824 | 1982 | * Add education about views. |
| @@ -1823,8 +1981,10 @@ | ||
| 1823 | 1981 | /** |
| 1824 | 1982 | * Add education about views. |
| 1825 | 1983 | * |
| 1826 | 1984 | * @since 4.07 |
| 1985 | + * | |
| 1986 | + * @return void | |
| 1827 | 1987 | */ |
| 1828 | 1988 | public static function no_views( $values = array() ) { |
| 1829 | 1989 | FrmAppHelper::include_svg(); |
| 1830 | 1990 | $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| @@ -1836,8 +1996,10 @@ | ||
| 1836 | 1996 | /** |
| 1837 | 1997 | * Add education about reports. |
| 1838 | 1998 | * |
| 1839 | 1999 | * @since 4.07 |
| 2000 | + * | |
| 2001 | + * @return void | |
| 1840 | 2002 | */ |
| 1841 | 2003 | public static function no_reports( $values = array() ) { |
| 1842 | 2004 | $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| 1843 | 2005 | $form = $id ? FrmForm::getOne( $id ) : false; |
| @@ -1844,9 +2006,11 @@ | ||
| 1844 | 2006 | |
| 1845 | 2007 | include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php'; |
| 1846 | 2008 | } |
| 1847 | 2009 | |
| 1848 | - /* FRONT-END FORMS */ | |
| 2010 | + /** | |
| 2011 | + * FRONT-END FORMS. | |
| 2012 | + */ | |
| 1849 | 2013 | public static function admin_bar_css() { |
| 1850 | 2014 | if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 1851 | 2015 | return; |
| 1852 | 2016 | } |
| @@ -1935,10 +2099,10 @@ | ||
| 1935 | 2099 | * @return string |
| 1936 | 2100 | */ |
| 1937 | 2101 | public static function get_form_shortcode( $atts ) { |
| 1938 | 2102 | global $frm_vars; |
| 1939 | - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) { | |
| 1940 | - $sc = '[formidable'; | |
| 2103 | + if ( ! empty( $frm_vars['skip_shortcode'] ) ) { | |
| 2104 | + $sc = '[formidable'; | |
| 1941 | 2105 | $sc .= FrmAppHelper::array_to_html_params( $atts ); |
| 1942 | 2106 | return $sc . ']'; |
| 1943 | 2107 | } |
| 1944 | 2108 | |
| @@ -1963,11 +2127,11 @@ | ||
| 1963 | 2127 | |
| 1964 | 2128 | /** |
| 1965 | 2129 | * @since 5.2.01 |
| 1966 | 2130 | * |
| 1967 | - * @param string|int|false $id | |
| 1968 | - * @param string|false $key | |
| 1969 | - * @return stdClass|false | |
| 2131 | + * @param false|int|string $id | |
| 2132 | + * @param false|string $key | |
| 2133 | + * @return false|stdClass | |
| 1970 | 2134 | */ |
| 1971 | 2135 | private static function maybe_get_form_by_id_or_key( $id, $key ) { |
| 1972 | 2136 | if ( ! $id ) { |
| 1973 | 2137 | $id = $key; |
| @@ -1975,12 +2139,12 @@ | ||
| 1975 | 2139 | return self::maybe_get_form_to_show( $id ); |
| 1976 | 2140 | } |
| 1977 | 2141 | |
| 1978 | 2142 | /** |
| 1979 | - * @param string|int|false $id | |
| 1980 | - * @param string|false $key | |
| 1981 | - * @param string|int|bool $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 1982 | - * @param string|int|bool $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 2143 | + * @param false|int|string $id | |
| 2144 | + * @param false|string $key | |
| 2145 | + * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 2146 | + * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 1983 | 2147 | * @param array $atts |
| 1984 | 2148 | * @return string |
| 1985 | 2149 | */ |
| 1986 | 2150 | public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
| @@ -2028,15 +2192,16 @@ | ||
| 2028 | 2192 | return $form; |
| 2029 | 2193 | } |
| 2030 | 2194 | |
| 2031 | 2195 | /** |
| 2032 | - * @param string|int|false $id | |
| 2033 | - * @return stdClass|false | |
| 2196 | + * @param false|int|string $id | |
| 2197 | + * @return false|stdClass | |
| 2034 | 2198 | */ |
| 2035 | 2199 | private static function maybe_get_form_to_show( $id ) { |
| 2036 | 2200 | $form = false; |
| 2037 | 2201 | |
| 2038 | - if ( ! empty( $id ) ) { // form id or key is set | |
| 2202 | + if ( ! empty( $id ) ) { | |
| 2203 | + // Form id or key is set. | |
| 2039 | 2204 | $form = FrmForm::getOne( $id ); |
| 2040 | 2205 | if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) { |
| 2041 | 2206 | $form = false; |
| 2042 | 2207 | } |
| @@ -2094,11 +2259,11 @@ | ||
| 2094 | 2259 | |
| 2095 | 2260 | do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description ); |
| 2096 | 2261 | |
| 2097 | 2262 | if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) { |
| 2098 | - $entry_id = self::just_created_entry( $form->id ); | |
| 2099 | - $pass_args['entry_id'] = $entry_id; | |
| 2100 | - $pass_args['reset'] = true; | |
| 2263 | + $entry_id = self::just_created_entry( $form->id ); | |
| 2264 | + $pass_args['entry_id'] = $entry_id; | |
| 2265 | + $pass_args['reset'] = true; | |
| 2101 | 2266 | |
| 2102 | 2267 | self::run_on_submit_actions( $pass_args ); |
| 2103 | 2268 | |
| 2104 | 2269 | do_action( |
| @@ -2108,9 +2273,9 @@ | ||
| 2108 | 2273 | 'form' => $form, |
| 2109 | 2274 | ) |
| 2110 | 2275 | ); |
| 2111 | 2276 | } |
| 2112 | - } | |
| 2277 | + }//end if | |
| 2113 | 2278 | } |
| 2114 | 2279 | |
| 2115 | 2280 | /** |
| 2116 | 2281 | * If the form was processed earlier (init), get the generated errors |
| @@ -2142,9 +2307,9 @@ | ||
| 2142 | 2307 | */ |
| 2143 | 2308 | public static function just_created_entry( $form_id ) { |
| 2144 | 2309 | global $frm_vars; |
| 2145 | 2310 | |
| 2146 | - 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; | |
| 2311 | + 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; | |
| 2147 | 2312 | } |
| 2148 | 2313 | |
| 2149 | 2314 | /** |
| 2150 | 2315 | * Gets confirmation method. |
| @@ -2157,14 +2322,14 @@ | ||
| 2157 | 2322 | * |
| 2158 | 2323 | * @type object $form Form object. |
| 2159 | 2324 | * @type int $entry_id Entry ID. |
| 2160 | 2325 | * } |
| 2161 | - * @return string|array | |
| 2326 | + * @return array|string | |
| 2162 | 2327 | */ |
| 2163 | 2328 | private static function get_confirmation_method( $atts ) { |
| 2164 | 2329 | $action = FrmOnSubmitHelper::current_event( $atts ); |
| 2165 | 2330 | $opt = 'update' === $action ? 'edit_action' : 'success_action'; |
| 2166 | - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message'; | |
| 2331 | + $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message'; | |
| 2167 | 2332 | |
| 2168 | 2333 | if ( ! empty( $atts['entry_id'] ) ) { |
| 2169 | 2334 | $met_actions = self::get_met_on_submit_actions( $atts, $action ); |
| 2170 | 2335 | if ( $met_actions ) { |
| @@ -2173,9 +2338,9 @@ | ||
| 2173 | 2338 | } |
| 2174 | 2339 | |
| 2175 | 2340 | $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action ); |
| 2176 | 2341 | |
| 2177 | - if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { | |
| 2342 | + if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { | |
| 2178 | 2343 | $method = 'message'; |
| 2179 | 2344 | } |
| 2180 | 2345 | |
| 2181 | 2346 | return $method; |
| @@ -2260,9 +2425,9 @@ | ||
| 2260 | 2425 | unset( $extra_args['form'] ); |
| 2261 | 2426 | |
| 2262 | 2427 | do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args ); |
| 2263 | 2428 | |
| 2264 | - $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit'; | |
| 2429 | + $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit'; | |
| 2265 | 2430 | |
| 2266 | 2431 | $args['success_opt'] = $opt; |
| 2267 | 2432 | $args['ajax'] = ! empty( $frm_vars['ajax'] ); |
| 2268 | 2433 | |
| @@ -2288,16 +2453,16 @@ | ||
| 2288 | 2453 | if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) { |
| 2289 | 2454 | return array(); |
| 2290 | 2455 | } |
| 2291 | 2456 | |
| 2292 | - // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab. | |
| 2457 | + // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab. | |
| 2293 | 2458 | if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) { |
| 2294 | 2459 | return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) ); |
| 2295 | 2460 | } |
| 2296 | 2461 | |
| 2297 | - $entry = FrmEntry::getOne( $args['entry_id'], true ); | |
| 2298 | - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); | |
| 2299 | - $met_actions = array(); | |
| 2462 | + $entry = FrmEntry::getOne( $args['entry_id'], true ); | |
| 2463 | + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); | |
| 2464 | + $met_actions = array(); | |
| 2300 | 2465 | $has_redirect = false; |
| 2301 | 2466 | |
| 2302 | 2467 | foreach ( $actions as $action ) { |
| 2303 | 2468 | if ( ! in_array( $event, $action->post_content['event'], true ) ) { |
| @@ -2310,9 +2475,10 @@ | ||
| 2310 | 2475 | |
| 2311 | 2476 | $action_type = FrmOnSubmitHelper::get_action_type( $action ); |
| 2312 | 2477 | |
| 2313 | 2478 | if ( 'redirect' === $action_type ) { |
| 2314 | - if ( $has_redirect ) { // Do not process because we run the first redirect action only. | |
| 2479 | + if ( $has_redirect ) { | |
| 2480 | + // Do not process because we run the first redirect action only. | |
| 2315 | 2481 | continue; |
| 2316 | 2482 | } |
| 2317 | 2483 | } |
| 2318 | 2484 | |
| @@ -2325,9 +2491,9 @@ | ||
| 2325 | 2491 | } |
| 2326 | 2492 | |
| 2327 | 2493 | $met_actions[] = $action; |
| 2328 | 2494 | unset( $action ); |
| 2329 | - } | |
| 2495 | + }//end foreach | |
| 2330 | 2496 | |
| 2331 | 2497 | $args['event'] = $event; |
| 2332 | 2498 | |
| 2333 | 2499 | /** |
| @@ -2516,9 +2682,9 @@ | ||
| 2516 | 2682 | add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 ); |
| 2517 | 2683 | } |
| 2518 | 2684 | |
| 2519 | 2685 | $post = $old_post; |
| 2520 | - } | |
| 2686 | + }//end if | |
| 2521 | 2687 | } |
| 2522 | 2688 | |
| 2523 | 2689 | /** |
| 2524 | 2690 | * @since 3.0 |
| @@ -2539,14 +2705,16 @@ | ||
| 2539 | 2705 | $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args ); |
| 2540 | 2706 | |
| 2541 | 2707 | $doing_ajax = FrmAppHelper::doing_ajax(); |
| 2542 | 2708 | |
| 2543 | - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs. | |
| 2709 | + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { | |
| 2710 | + // Is AJAX submit and there is just one Redirect action runs. | |
| 2544 | 2711 | echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) ); |
| 2545 | 2712 | wp_die(); |
| 2546 | 2713 | } |
| 2547 | 2714 | |
| 2548 | - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2715 | + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { | |
| 2716 | + // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2549 | 2717 | if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { |
| 2550 | 2718 | self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ); |
| 2551 | 2719 | self::$redirected_in_new_tab[ $args['form']->id ] = 1; |
| 2552 | 2720 | return; |
| @@ -2552,9 +2720,10 @@ | ||
| 2552 | 2720 | return; |
| 2553 | 2721 | } |
| 2554 | 2722 | |
| 2555 | 2723 | wp_redirect( esc_url_raw( $success_url ) ); |
| 2556 | - die(); // do not use wp_die or redirect fails | |
| 2724 | + // Do not use wp_die or redirect fails. | |
| 2725 | + die(); | |
| 2557 | 2726 | } |
| 2558 | 2727 | |
| 2559 | 2728 | // Redirect with a delay. |
| 2560 | 2729 | self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) ); |
| @@ -2605,9 +2774,9 @@ | ||
| 2605 | 2774 | |
| 2606 | 2775 | $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args ); |
| 2607 | 2776 | |
| 2608 | 2777 | ob_start(); |
| 2609 | - self::show_lone_success_messsage( $args ); | |
| 2778 | + self::show_lone_success_message( $args ); | |
| 2610 | 2779 | $response_data['content'] = ob_get_clean(); |
| 2611 | 2780 | |
| 2612 | 2781 | $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args ); |
| 2613 | 2782 | } |
| @@ -2631,9 +2800,9 @@ | ||
| 2631 | 2800 | * Filters the delay time before redirecting when On Submit Redirect action is delayed. |
| 2632 | 2801 | * |
| 2633 | 2802 | * @since 6.0 |
| 2634 | 2803 | * |
| 2635 | - * @param int $delay_time Delay time in miliseconds. | |
| 2804 | + * @param int $delay_time Delay time in milliseconds. | |
| 2636 | 2805 | */ |
| 2637 | 2806 | $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 ); |
| 2638 | 2807 | |
| 2639 | 2808 | if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { |
| @@ -2645,9 +2814,10 @@ | ||
| 2645 | 2814 | add_filter( 'frm_use_wpautop', '__return_true' ); |
| 2646 | 2815 | |
| 2647 | 2816 | echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2648 | 2817 | echo '<script>'; |
| 2649 | - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load. | |
| 2818 | + if ( empty( $args['doing_ajax'] ) ) { | |
| 2819 | + // Not AJAX submit, delay JS until window.load. | |
| 2650 | 2820 | echo 'window.onload=function(){'; |
| 2651 | 2821 | } |
| 2652 | 2822 | echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2653 | 2823 | if ( empty( $args['doing_ajax'] ) ) { |
| @@ -2660,9 +2830,9 @@ | ||
| 2660 | 2830 | * @since 3.0 |
| 2661 | 2831 | * |
| 2662 | 2832 | * @param string $success_url |
| 2663 | 2833 | * @param string $success_msg |
| 2664 | - * @param array $args | |
| 2834 | + * @param array $args | |
| 2665 | 2835 | */ |
| 2666 | 2836 | private static function get_redirect_message( $success_url, $success_msg, $args ) { |
| 2667 | 2837 | $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . |
| 2668 | 2838 | self::get_redirect_fallback_message( $success_url, $args ) . |
| @@ -2720,9 +2890,9 @@ | ||
| 2720 | 2890 | } else { |
| 2721 | 2891 | self::show_form_after_submit( $atts ); |
| 2722 | 2892 | } |
| 2723 | 2893 | } else { |
| 2724 | - self::show_lone_success_messsage( $atts ); | |
| 2894 | + self::show_lone_success_message( $atts ); | |
| 2725 | 2895 | } |
| 2726 | 2896 | } |
| 2727 | 2897 | |
| 2728 | 2898 | /** |
| @@ -2761,11 +2931,10 @@ | ||
| 2761 | 2931 | include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php'; |
| 2762 | 2932 | } |
| 2763 | 2933 | |
| 2764 | 2934 | /** |
| 2935 | + * @since 4.05.02 | |
| 2765 | 2936 | * @return string - 'before', 'after', or 'submit' |
| 2766 | - * | |
| 2767 | - * @since 4.05.02 | |
| 2768 | 2937 | */ |
| 2769 | 2938 | private static function message_placement( $form, $message ) { |
| 2770 | 2939 | $place = 'before'; |
| 2771 | 2940 | |
| @@ -2777,11 +2946,10 @@ | ||
| 2777 | 2946 | } |
| 2778 | 2947 | } |
| 2779 | 2948 | |
| 2780 | 2949 | /** |
| 2950 | + * @since 4.05.02 | |
| 2781 | 2951 | * @return string - 'before' or 'after' |
| 2782 | - * | |
| 2783 | - * @since 4.05.02 | |
| 2784 | 2952 | */ |
| 2785 | 2953 | return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) ); |
| 2786 | 2954 | } |
| 2787 | 2955 | |
| @@ -2815,9 +2983,9 @@ | ||
| 2815 | 2983 | * Show the success message without the form |
| 2816 | 2984 | * |
| 2817 | 2985 | * @since 2.05 |
| 2818 | 2986 | */ |
| 2819 | - private static function show_lone_success_messsage( $atts ) { | |
| 2987 | + private static function show_lone_success_message( $atts ) { | |
| 2820 | 2988 | global $frm_vars; |
| 2821 | 2989 | $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true ); |
| 2822 | 2990 | self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] ); |
| 2823 | 2991 | |
| @@ -2826,9 +2994,9 @@ | ||
| 2826 | 2994 | $errors = array(); |
| 2827 | 2995 | $form = $atts['form']; |
| 2828 | 2996 | $message = $atts['message']; |
| 2829 | 2997 | |
| 2830 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' ); | |
| 2998 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php'; | |
| 2831 | 2999 | } |
| 2832 | 3000 | |
| 2833 | 3001 | /** |
| 2834 | 3002 | * Prepare the success message before it's shown |
| @@ -2948,9 +3116,9 @@ | ||
| 2948 | 3116 | global $frm_vars; |
| 2949 | 3117 | |
| 2950 | 3118 | FrmStylesController::enqueue_css(); |
| 2951 | 3119 | |
| 2952 | - if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) { | |
| 3120 | + if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) { | |
| 2953 | 3121 | // load formidable js |
| 2954 | 3122 | wp_enqueue_script( 'formidable' ); |
| 2955 | 3123 | } |
| 2956 | 3124 | } |
| @@ -2966,12 +3134,12 @@ | ||
| 2966 | 3134 | } |
| 2967 | 3135 | |
| 2968 | 3136 | /** |
| 2969 | 3137 | * @since 2.0.8 |
| 2970 | - * @return boolean | |
| 3138 | + * @return bool | |
| 2971 | 3139 | */ |
| 2972 | 3140 | private static function is_minification_on( $atts ) { |
| 2973 | - return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] ); | |
| 3141 | + return ! empty( $atts['minimize'] ); | |
| 2974 | 3142 | } |
| 2975 | 3143 | |
| 2976 | 3144 | /** |
| 2977 | 3145 | * @since 5.0.16 |
| @@ -2999,9 +3167,9 @@ | ||
| 2999 | 3167 | * Create a page with an embedded formidable Gutenberg block. |
| 3000 | 3168 | * |
| 3001 | 3169 | * @since 5.2 |
| 3002 | 3170 | * |
| 3003 | - * @return never | |
| 3171 | + * @return void | |
| 3004 | 3172 | */ |
| 3005 | 3173 | public static function create_page_with_shortcode() { |
| 3006 | 3174 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3007 | 3175 | die( 0 ); |
| @@ -3046,10 +3214,9 @@ | ||
| 3046 | 3214 | |
| 3047 | 3215 | /** |
| 3048 | 3216 | * @since 5.3 |
| 3049 | 3217 | * |
| 3050 | - * @param string $content | |
| 3051 | - * @param int $form_id | |
| 3218 | + * @param int $form_id | |
| 3052 | 3219 | * @return string |
| 3053 | 3220 | */ |
| 3054 | 3221 | private static function get_page_shortcode_content_for_form( $form_id ) { |
| 3055 | 3222 | $shortcode = '[formidable id="' . $form_id . '"]'; |
| @@ -3060,9 +3227,9 @@ | ||
| 3060 | 3227 | |
| 3061 | 3228 | /** |
| 3062 | 3229 | * Get page dropdown for AJAX request for embedding form in an existing page. |
| 3063 | 3230 | * |
| 3064 | - * @return never | |
| 3231 | + * @return void | |
| 3065 | 3232 | */ |
| 3066 | 3233 | public static function get_page_dropdown() { |
| 3067 | 3234 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3068 | 3235 | die( 0 ); |
| @@ -3070,9 +3237,9 @@ | ||
| 3070 | 3237 | |
| 3071 | 3238 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 3072 | 3239 | |
| 3073 | 3240 | $html = FrmAppHelper::clip( |
| 3074 | - function() { | |
| 3241 | + function () { | |
| 3075 | 3242 | FrmAppHelper::maybe_autocomplete_pages_options( |
| 3076 | 3243 | array( |
| 3077 | 3244 | 'field_name' => 'frm_page_dropdown', |
| 3078 | 3245 | 'page_id' => '', |
| @@ -3092,15 +3259,8 @@ | ||
| 3092 | 3259 | |
| 3093 | 3260 | /** |
| 3094 | 3261 | * @deprecated 4.0 |
| 3095 | 3262 | */ |
| 3096 | - public static function new_form( $values = array() ) { | |
| 3097 | - FrmDeprecated::new_form( $values ); | |
| 3098 | - } | |
| 3099 | - | |
| 3100 | - /** | |
| 3101 | - * @deprecated 4.0 | |
| 3102 | - */ | |
| 3103 | 3263 | public static function create( $values = array() ) { |
| 3104 | 3264 | _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' ); |
| 3105 | 3265 | self::update( $values ); |
| 3106 | 3266 | } |
| @@ -3105,35 +3265,13 @@ | ||
| 3105 | 3265 | self::update( $values ); |
| 3106 | 3266 | } |
| 3107 | 3267 | |
| 3108 | 3268 | /** |
| 3109 | - * @deprecated 3.0 | |
| 3110 | - * @codeCoverageIgnore | |
| 3269 | + * @deprecated 6.7 | |
| 3270 | + * | |
| 3271 | + * @return bool | |
| 3111 | 3272 | */ |
| 3112 | - public static function bulk_create_template( $ids ) { | |
| 3113 | - return FrmDeprecated::bulk_create_template( $ids ); | |
| 3114 | - } | |
| 3115 | - | |
| 3116 | - /** | |
| 3117 | - * @deprecated 3.0 | |
| 3118 | - * @codeCoverageIgnore | |
| 3119 | - */ | |
| 3120 | - public static function edit_key() { | |
| 3121 | - FrmDeprecated::edit_key(); | |
| 3122 | - } | |
| 3123 | - | |
| 3124 | - /** | |
| 3125 | - * @deprecated 3.0 | |
| 3126 | - * @codeCoverageIgnore | |
| 3127 | - */ | |
| 3128 | - public static function edit_description() { | |
| 3129 | - FrmDeprecated::edit_description(); | |
| 3130 | - } | |
| 3131 | - | |
| 3132 | - /** | |
| 3133 | - * @deprecated 4.08 | |
| 3134 | - * @since 3.06 | |
| 3135 | - */ | |
| 3136 | - public static function add_new() { | |
| 3137 | - _deprecated_function( __FUNCTION__, '4.08' ); | |
| 3273 | + public static function expired() { | |
| 3274 | + _deprecated_function( __METHOD__, '6.7' ); | |
| 3275 | + return FrmAddonsController::is_license_expired(); | |
| 3138 | 3276 | } |
| 3139 | 3277 | } |