| @@ -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,15 +106,23 @@ | ||
| 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 | |
| 111 | + * @return void | |
| 101 | 112 | */ |
| 102 | 113 | private static function create_default_email_action( $form ) { |
| 103 | 114 | FrmForm::maybe_get_form( $form ); |
| 115 | + if ( ! is_object( $form ) ) { | |
| 116 | + return; | |
| 117 | + } | |
| 118 | + | |
| 104 | 119 | $create_email = apply_filters( 'frm_create_default_email_action', true, $form ); |
| 105 | 120 | |
| 106 | 121 | if ( $create_email ) { |
| 122 | + /** | |
| 123 | + * @var FrmFormAction | |
| 124 | + */ | |
| 107 | 125 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
| 108 | 126 | $action_control->create( $form->id ); |
| 109 | 127 | } |
| 110 | 128 | } |
| @@ -113,12 +131,16 @@ | ||
| 113 | 131 | * Create the default On submit action |
| 114 | 132 | * |
| 115 | 133 | * @since 6.0.0 |
| 116 | 134 | * |
| 117 | - * @param object|int $form Form object or ID. | |
| 135 | + * @param int|object $form Form object or ID. | |
| 136 | + * @return void | |
| 118 | 137 | */ |
| 119 | 138 | private static function create_default_on_submit_action( $form ) { |
| 120 | 139 | FrmForm::maybe_get_form( $form ); |
| 140 | + if ( ! is_object( $form ) ) { | |
| 141 | + return; | |
| 142 | + } | |
| 121 | 143 | |
| 122 | 144 | /** |
| 123 | 145 | * Enable or disable the default On Submit action. |
| 124 | 146 | * |
| @@ -129,21 +151,65 @@ | ||
| 129 | 151 | */ |
| 130 | 152 | $create = apply_filters( 'frm_create_default_on_submit_action', true, $form ); |
| 131 | 153 | |
| 132 | 154 | if ( $create ) { |
| 155 | + /** | |
| 156 | + * @var FrmFormAction | |
| 157 | + */ | |
| 133 | 158 | $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug ); |
| 134 | 159 | $action_control->create( $form->id ); |
| 135 | 160 | } |
| 136 | 161 | } |
| 137 | 162 | |
| 163 | + /** | |
| 164 | + * Creates submit button field. | |
| 165 | + * | |
| 166 | + * @since 6.9 | |
| 167 | + * | |
| 168 | + * @param int|object $form Form ID or object. | |
| 169 | + * @return void | |
| 170 | + */ | |
| 171 | + private static function create_submit_button_field( $form ) { | |
| 172 | + FrmForm::maybe_get_form( $form ); | |
| 173 | + if ( ! is_object( $form ) ) { | |
| 174 | + return; | |
| 175 | + } | |
| 176 | + | |
| 177 | + if ( FrmSubmitHelper::get_submit_field( $form->id ) ) { | |
| 178 | + // Do not create submit button field if it exists. | |
| 179 | + return; | |
| 180 | + } | |
| 181 | + | |
| 182 | + FrmField::create( | |
| 183 | + array( | |
| 184 | + 'type' => FrmSubmitHelper::FIELD_TYPE, | |
| 185 | + 'name' => __( 'Submit', 'formidable' ), | |
| 186 | + 'field_order' => FrmSubmitHelper::DEFAULT_ORDER, | |
| 187 | + 'form_id' => $form->id, | |
| 188 | + 'field_options' => FrmFieldsHelper::get_default_field_options( FrmSubmitHelper::FIELD_TYPE ), | |
| 189 | + 'description' => '', | |
| 190 | + 'default_value' => '', | |
| 191 | + 'options' => array(), | |
| 192 | + ) | |
| 193 | + ); | |
| 194 | + } | |
| 195 | + | |
| 196 | + /** | |
| 197 | + * @return void | |
| 198 | + */ | |
| 138 | 199 | public static function edit( $values = false ) { |
| 139 | 200 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 140 | 201 | |
| 141 | 202 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 142 | 203 | |
| 143 | - return self::get_edit_vars( $id ); | |
| 204 | + self::get_edit_vars( $id ); | |
| 144 | 205 | } |
| 145 | 206 | |
| 207 | + /** | |
| 208 | + * @param mixed $id | |
| 209 | + * @param string $message | |
| 210 | + * @return void | |
| 211 | + */ | |
| 146 | 212 | public static function settings( $id = false, $message = '' ) { |
| 147 | 213 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 148 | 214 | |
| 149 | 215 | if ( ! $id || ! is_numeric( $id ) ) { |
| @@ -151,21 +217,34 @@ | ||
| 151 | 217 | } |
| 152 | 218 | |
| 153 | 219 | FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id ); |
| 154 | 220 | |
| 155 | - return self::get_settings_vars( $id, array(), $message ); | |
| 221 | + self::get_settings_vars( $id, array(), $message ); | |
| 156 | 222 | } |
| 157 | 223 | |
| 158 | 224 | public static function update_settings() { |
| 159 | 225 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 226 | + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); | |
| 160 | 227 | |
| 228 | + if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { | |
| 229 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 230 | + $error_args = array( | |
| 231 | + 'title' => __( 'Verification failed', 'formidable' ), | |
| 232 | + 'body' => $frm_settings->admin_permission, | |
| 233 | + 'cancel_text' => __( 'Cancel', 'formidable' ), | |
| 234 | + ); | |
| 235 | + FrmAppController::show_error_modal( $error_args ); | |
| 236 | + return; | |
| 237 | + } | |
| 238 | + | |
| 161 | 239 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 162 | 240 | |
| 163 | - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 241 | + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 164 | 242 | $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 165 | 243 | |
| 166 | 244 | if ( count( $errors ) > 0 ) { |
| 167 | - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); | |
| 245 | + self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); | |
| 246 | + return; | |
| 168 | 247 | } |
| 169 | 248 | |
| 170 | 249 | do_action( 'frm_before_update_form_settings', $id ); |
| 171 | 250 | |
| @@ -179,9 +258,9 @@ | ||
| 179 | 258 | } |
| 180 | 259 | |
| 181 | 260 | $message = __( 'Settings Successfully Updated', 'formidable' ); |
| 182 | 261 | |
| 183 | - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); | |
| 262 | + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); | |
| 184 | 263 | } |
| 185 | 264 | |
| 186 | 265 | /** |
| 187 | 266 | * @param int $form_id |
| @@ -191,8 +270,11 @@ | ||
| 191 | 270 | $form = FrmForm::getOne( $form_id ); |
| 192 | 271 | return ! empty( $form->options['antispam'] ); |
| 193 | 272 | } |
| 194 | 273 | |
| 274 | + /** | |
| 275 | + * @return void | |
| 276 | + */ | |
| 195 | 277 | public static function update( $values = array() ) { |
| 196 | 278 | if ( empty( $values ) ) { |
| 197 | 279 | $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 198 | 280 | } |
| @@ -210,65 +292,74 @@ | ||
| 210 | 292 | |
| 211 | 293 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 212 | 294 | |
| 213 | 295 | 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' ); | |
| 296 | + self::get_edit_vars( $id, $errors ); | |
| 297 | + return; | |
| 298 | + } | |
| 218 | 299 | |
| 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 | - } | |
| 300 | + self::maybe_remove_draft_option_from_fields( $id ); | |
| 227 | 301 | |
| 228 | - if ( defined( 'DOING_AJAX' ) ) { | |
| 229 | - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 230 | - } | |
| 302 | + FrmForm::update( $id, $values ); | |
| 303 | + $message = __( 'Form was successfully updated.', 'formidable' ); | |
| 231 | 304 | |
| 232 | - return self::get_edit_vars( $id, array(), $message ); | |
| 305 | + if ( self::is_too_long( $values ) ) { | |
| 306 | + $message .= '<br/> ' . sprintf( | |
| 307 | + /* translators: %1$s: Start link HTML, %2$s: end link HTML */ | |
| 308 | + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ), | |
| 309 | + '<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">', | |
| 310 | + '</a>' | |
| 311 | + ); | |
| 233 | 312 | } |
| 313 | + | |
| 314 | + if ( defined( 'DOING_AJAX' ) ) { | |
| 315 | + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 316 | + } | |
| 317 | + | |
| 318 | + self::get_edit_vars( $id, array(), $message ); | |
| 234 | 319 | } |
| 235 | 320 | |
| 236 | 321 | /** |
| 322 | + * Remove the draft flag from any new fields from this current session. | |
| 323 | + * | |
| 324 | + * @since 6.8 | |
| 325 | + * | |
| 326 | + * @param int $form_id | |
| 327 | + * @return void | |
| 328 | + */ | |
| 329 | + private static function maybe_remove_draft_option_from_fields( $form_id ) { | |
| 330 | + $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' ); | |
| 331 | + if ( ! $draft_field_ids_csv ) { | |
| 332 | + // If the draft_fields input is empty there are no new fields in the session. | |
| 333 | + return; | |
| 334 | + } | |
| 335 | + | |
| 336 | + $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' ); | |
| 337 | + if ( ! $draft_field_ids ) { | |
| 338 | + // Exit early if the draft fields input is invalid. It should be a CSV of integer values. | |
| 339 | + return; | |
| 340 | + } | |
| 341 | + | |
| 342 | + $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids ); | |
| 343 | + foreach ( $draft_field_rows as $row ) { | |
| 344 | + $row->field_options['draft'] = 0; | |
| 345 | + FrmField::update( $row->id, array( 'field_options' => $row->field_options ) ); | |
| 346 | + } | |
| 347 | + } | |
| 348 | + | |
| 349 | + /** | |
| 237 | 350 | * Check if the value at the end of the form was included. |
| 238 | 351 | * If it's missing, it means other values at the end of the form |
| 239 | 352 | * were likely not saved either. |
| 240 | 353 | * |
| 241 | 354 | * @since 3.06.01 |
| 355 | + * | |
| 356 | + * @return bool | |
| 242 | 357 | */ |
| 243 | 358 | private static function is_too_long( $values ) { |
| 244 | - return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] ); | |
| 359 | + return empty( $values['frm_end'] ); | |
| 245 | 360 | } |
| 246 | 361 | |
| 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 | 362 | public static function duplicate() { |
| 272 | 363 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 273 | 364 | $nonce = FrmAppHelper::simple_get( '_wpnonce' ); |
| 274 | 365 | |
| @@ -282,10 +373,11 @@ | ||
| 282 | 373 | $url = admin_url( 'admin.php?page=formidable' ); |
| 283 | 374 | $message = 'form_duplicate_error'; |
| 284 | 375 | |
| 285 | 376 | if ( $form ) { |
| 286 | - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) ); | |
| 287 | - $message = 'form_duplicated'; | |
| 377 | + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : ''; | |
| 378 | + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template ); | |
| 379 | + $message = 'form_duplicated'; | |
| 288 | 380 | } |
| 289 | 381 | |
| 290 | 382 | $url .= '&message=' . $message; |
| 291 | 383 | |
| @@ -293,24 +385,28 @@ | ||
| 293 | 385 | exit(); |
| 294 | 386 | } |
| 295 | 387 | |
| 296 | 388 | /** |
| 297 | - * @return string | |
| 389 | + * @return string|null | |
| 298 | 390 | */ |
| 299 | 391 | public static function page_preview() { |
| 300 | 392 | $params = FrmForm::list_page_params(); |
| 301 | 393 | if ( ! $params['form'] ) { |
| 302 | - return; | |
| 394 | + return null; | |
| 303 | 395 | } |
| 304 | 396 | |
| 305 | 397 | $form = FrmForm::getOne( $params['form'] ); |
| 306 | - if ( $form ) { | |
| 307 | - return self::show_form( $form->id, '', 'auto', 'auto' ); | |
| 398 | + if ( ! $form ) { | |
| 399 | + return null; | |
| 308 | 400 | } |
| 401 | + | |
| 402 | + return self::show_form( $form->id, '', 'auto', 'auto' ); | |
| 309 | 403 | } |
| 310 | 404 | |
| 311 | 405 | /** |
| 312 | 406 | * @since 3.0 |
| 407 | + * | |
| 408 | + * @return void | |
| 313 | 409 | */ |
| 314 | 410 | public static function show_page_preview() { |
| 315 | 411 | echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 316 | 412 | } |
| @@ -360,8 +456,13 @@ | ||
| 360 | 456 | return; |
| 361 | 457 | } |
| 362 | 458 | |
| 363 | 459 | $random_page = reset( $random_page ); |
| 460 | + if ( ! is_a( $random_page, 'WP_Post' ) ) { | |
| 461 | + // The return type can also be int. | |
| 462 | + return; | |
| 463 | + } | |
| 464 | + | |
| 364 | 465 | query_posts( |
| 365 | 466 | array( |
| 366 | 467 | 'post_type' => 'page', |
| 367 | 468 | 'page_id' => $random_page->ID, |
| @@ -377,9 +478,9 @@ | ||
| 377 | 478 | * Set the WP $post global object. Used for in-theme preview when defining a page. |
| 378 | 479 | * |
| 379 | 480 | * @since 5.5.2 |
| 380 | 481 | * |
| 381 | - * @param WP_Post $post | |
| 482 | + * @param WP_Post $page The page object. | |
| 382 | 483 | * @return void |
| 383 | 484 | */ |
| 384 | 485 | private static function set_post_global( $page ) { |
| 385 | 486 | global $post; |
| @@ -387,8 +488,10 @@ | ||
| 387 | 488 | } |
| 388 | 489 | |
| 389 | 490 | /** |
| 390 | 491 | * @since 3.0 |
| 492 | + * | |
| 493 | + * @return void | |
| 391 | 494 | */ |
| 392 | 495 | private static function load_theme_preview() { |
| 393 | 496 | add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 ); |
| 394 | 497 | add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 ); |
| @@ -397,20 +500,39 @@ | ||
| 397 | 500 | add_filter( 'is_active_sidebar', '__return_false' ); |
| 398 | 501 | FrmStylesController::enqueue_css( 'enqueue', true ); |
| 399 | 502 | |
| 400 | 503 | if ( false === get_template_part( 'page' ) ) { |
| 504 | + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { | |
| 505 | + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' ); | |
| 506 | + } | |
| 401 | 507 | self::fallback_when_page_template_part_is_not_supported_by_theme(); |
| 402 | 508 | } |
| 403 | 509 | } |
| 404 | 510 | |
| 405 | 511 | /** |
| 512 | + * Add padding to the body for block themes. | |
| 513 | + * | |
| 514 | + * @since 6.5.2 | |
| 515 | + * | |
| 516 | + * @param array $classes The body classes list. | |
| 517 | + * @return array | |
| 518 | + */ | |
| 519 | + public static function preview_block_theme_body_classnames( $classes ) { | |
| 520 | + $classes[] = 'has-global-padding'; | |
| 521 | + return $classes; | |
| 522 | + } | |
| 523 | + | |
| 524 | + /** | |
| 406 | 525 | * Not every theme supports get_template_part( 'page' ). |
| 407 | 526 | * When this is not supported, false is returned, and we can handle a fallback. |
| 527 | + * | |
| 528 | + * @return void | |
| 408 | 529 | */ |
| 409 | 530 | private static function fallback_when_page_template_part_is_not_supported_by_theme() { |
| 410 | 531 | if ( have_posts() ) { |
| 411 | 532 | the_post(); |
| 412 | - get_header( '' ); | |
| 533 | + self::get_template( 'header' ); | |
| 534 | + | |
| 413 | 535 | // add some generic class names to the container to add some natural padding to the content. |
| 414 | 536 | // .entry-content catches the WordPress TwentyTwenty theme. |
| 415 | 537 | // .container catches Customizr content. |
| 416 | 538 | echo '<div class="container entry-content">'; |
| @@ -415,13 +537,54 @@ | ||
| 415 | 537 | // .container catches Customizr content. |
| 416 | 538 | echo '<div class="container entry-content">'; |
| 417 | 539 | the_content(); |
| 418 | 540 | echo '</div>'; |
| 419 | - get_footer(); | |
| 541 | + | |
| 542 | + self::get_template( 'footer' ); | |
| 420 | 543 | } |
| 421 | 544 | } |
| 422 | 545 | |
| 423 | 546 | /** |
| 547 | + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call | |
| 548 | + * and renders required html fragments calling required functions. | |
| 549 | + * | |
| 550 | + * @since 6.7.1 | |
| 551 | + * @param string $template | |
| 552 | + * @return void | |
| 553 | + */ | |
| 554 | + private static function get_template( $template ) { | |
| 555 | + if ( self::should_try_getting_template( $template ) ) { | |
| 556 | + call_user_func( 'get_' . $template ); | |
| 557 | + return; | |
| 558 | + } | |
| 559 | + | |
| 560 | + if ( 'header' === $template ) { | |
| 561 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php'; | |
| 562 | + return; | |
| 563 | + } | |
| 564 | + | |
| 565 | + if ( 'footer' === $template ) { | |
| 566 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php'; | |
| 567 | + } | |
| 568 | + } | |
| 569 | + | |
| 570 | + /** | |
| 571 | + * Returns true if calling a template function doesn't trigger deprecation warnings. | |
| 572 | + * | |
| 573 | + * @since 6.7.1 | |
| 574 | + * @param string $template | |
| 575 | + * @return bool | |
| 576 | + */ | |
| 577 | + private static function should_try_getting_template( $template ) { | |
| 578 | + $stylesheet_path = get_stylesheet_directory(); | |
| 579 | + $template_path = get_template_directory(); | |
| 580 | + $is_child_theme = $stylesheet_path !== $template_path; | |
| 581 | + $template_name = $template . '.php'; | |
| 582 | + | |
| 583 | + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name ); | |
| 584 | + } | |
| 585 | + | |
| 586 | + /** | |
| 424 | 587 | * Set the page title for the theme preview page |
| 425 | 588 | * |
| 426 | 589 | * @since 3.0 |
| 427 | 590 | */ |
| @@ -433,11 +596,14 @@ | ||
| 433 | 596 | return $title; |
| 434 | 597 | } |
| 435 | 598 | |
| 436 | 599 | /** |
| 437 | - * Set the page title for the theme preview page | |
| 600 | + * Set the page title for the theme preview page. | |
| 438 | 601 | * |
| 439 | 602 | * @since 3.0 |
| 603 | + * | |
| 604 | + * @param string $title | |
| 605 | + * @return string | |
| 440 | 606 | */ |
| 441 | 607 | public static function preview_title( $title ) { |
| 442 | 608 | return __( 'Form Preview', 'formidable' ); |
| 443 | 609 | } |
| @@ -442,15 +608,20 @@ | ||
| 442 | 608 | return __( 'Form Preview', 'formidable' ); |
| 443 | 609 | } |
| 444 | 610 | |
| 445 | 611 | /** |
| 446 | - * Set the page content for the theme preview page | |
| 612 | + * Set the page content for the theme preview page. | |
| 447 | 613 | * |
| 448 | 614 | * @since 3.0 |
| 615 | + * | |
| 616 | + * @param string $content | |
| 617 | + * @return string | |
| 449 | 618 | */ |
| 450 | 619 | public static function preview_content( $content ) { |
| 451 | 620 | if ( in_the_loop() ) { |
| 452 | - $content = self::show_page_preview(); | |
| 621 | + self::show_page_preview(); | |
| 622 | + // Clear the content for the page we're using. | |
| 623 | + $content = ''; | |
| 453 | 624 | } |
| 454 | 625 | |
| 455 | 626 | return $content; |
| 456 | 627 | } |
| @@ -460,8 +631,11 @@ | ||
| 460 | 631 | */ |
| 461 | 632 | private static function load_direct_preview() { |
| 462 | 633 | header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
| 463 | 634 | |
| 635 | + // print_emoji_styles is deprecated. | |
| 636 | + remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
| 637 | + | |
| 464 | 638 | $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' ); |
| 465 | 639 | if ( $key == '' ) { |
| 466 | 640 | $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' ); |
| 467 | 641 | } |
| @@ -470,11 +644,38 @@ | ||
| 470 | 644 | if ( empty( $form ) ) { |
| 471 | 645 | $form = FrmForm::getAll( array(), '', 1 ); |
| 472 | 646 | } |
| 473 | 647 | |
| 474 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' ); | |
| 648 | + self::fix_deprecated_null_param_warning(); | |
| 649 | + | |
| 650 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php'; | |
| 475 | 651 | } |
| 476 | 652 | |
| 653 | + /** | |
| 654 | + * Some themes have a null $src value. | |
| 655 | + * This function adds a filter to ensure that $src is not null. | |
| 656 | + * WP will call str_starts_with with the null value triggering a deprecated message otherwise. | |
| 657 | + * | |
| 658 | + * @since 6.10 | |
| 659 | + * | |
| 660 | + * @return void | |
| 661 | + */ | |
| 662 | + private static function fix_deprecated_null_param_warning() { | |
| 663 | + add_filter( | |
| 664 | + 'script_loader_src', | |
| 665 | + /** | |
| 666 | + * @param string|null $src | |
| 667 | + * @return string | |
| 668 | + */ | |
| 669 | + function ( $src ) { | |
| 670 | + if ( is_null( $src ) ) { | |
| 671 | + $src = ''; | |
| 672 | + } | |
| 673 | + return $src; | |
| 674 | + } | |
| 675 | + ); | |
| 676 | + } | |
| 677 | + | |
| 477 | 678 | public static function untrash() { |
| 478 | 679 | self::change_form_status( 'untrash' ); |
| 479 | 680 | } |
| 480 | 681 | |
| @@ -537,14 +738,14 @@ | ||
| 537 | 738 | FrmAppHelper::permission_check( $available_status[ $status ]['permission'] ); |
| 538 | 739 | |
| 539 | 740 | $params = FrmForm::list_page_params(); |
| 540 | 741 | |
| 541 | - //check nonce url | |
| 742 | + // Check nonce url. | |
| 542 | 743 | check_admin_referer( $status . '_form_' . $params['id'] ); |
| 543 | 744 | |
| 544 | 745 | $count = 0; |
| 545 | 746 | if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) { |
| 546 | - $count ++; | |
| 747 | + ++$count; | |
| 547 | 748 | } |
| 548 | 749 | |
| 549 | 750 | $form_type = FrmAppHelper::get_simple_request( |
| 550 | 751 | array( |
| @@ -556,9 +757,9 @@ | ||
| 556 | 757 | /* translators: %1$s: Number of forms */ |
| 557 | 758 | $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count ); |
| 558 | 759 | |
| 559 | 760 | /* 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>' ); | |
| 761 | + $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 | 762 | |
| 562 | 763 | $message = $available_status[ $status ]['message']; |
| 563 | 764 | |
| 564 | 765 | self::display_forms_list( $params, $message ); |
| @@ -563,8 +764,12 @@ | ||
| 563 | 764 | |
| 564 | 765 | self::display_forms_list( $params, $message ); |
| 565 | 766 | } |
| 566 | 767 | |
| 768 | + /** | |
| 769 | + * @param array $ids | |
| 770 | + * @return string | |
| 771 | + */ | |
| 567 | 772 | public static function bulk_trash( $ids ) { |
| 568 | 773 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 569 | 774 | |
| 570 | 775 | $count = 0; |
| @@ -569,12 +774,16 @@ | ||
| 569 | 774 | |
| 570 | 775 | $count = 0; |
| 571 | 776 | foreach ( $ids as $id ) { |
| 572 | 777 | if ( FrmForm::trash( $id ) ) { |
| 573 | - $count ++; | |
| 778 | + ++$count; | |
| 574 | 779 | } |
| 575 | 780 | } |
| 576 | 781 | |
| 782 | + if ( ! $count ) { | |
| 783 | + return ''; | |
| 784 | + } | |
| 785 | + | |
| 577 | 786 | $current_page = FrmAppHelper::get_simple_request( |
| 578 | 787 | array( |
| 579 | 788 | 'param' => 'form_type', |
| 580 | 789 | 'type' => 'request', |
| @@ -600,9 +809,9 @@ | ||
| 600 | 809 | check_admin_referer( 'destroy_form_' . $params['id'] ); |
| 601 | 810 | |
| 602 | 811 | $count = 0; |
| 603 | 812 | if ( FrmForm::destroy( $params['id'] ) ) { |
| 604 | - $count ++; | |
| 813 | + ++$count; | |
| 605 | 814 | } |
| 606 | 815 | |
| 607 | 816 | /* translators: %1$s: Number of forms */ |
| 608 | 817 | $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count ); |
| @@ -609,8 +818,12 @@ | ||
| 609 | 818 | |
| 610 | 819 | self::display_forms_list( $params, $message ); |
| 611 | 820 | } |
| 612 | 821 | |
| 822 | + /** | |
| 823 | + * @param array $ids | |
| 824 | + * @return string | |
| 825 | + */ | |
| 613 | 826 | public static function bulk_destroy( $ids ) { |
| 614 | 827 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 615 | 828 | |
| 616 | 829 | $count = 0; |
| @@ -616,19 +829,24 @@ | ||
| 616 | 829 | $count = 0; |
| 617 | 830 | foreach ( $ids as $id ) { |
| 618 | 831 | $d = FrmForm::destroy( $id ); |
| 619 | 832 | if ( $d ) { |
| 620 | - $count ++; | |
| 833 | + ++$count; | |
| 621 | 834 | } |
| 622 | 835 | } |
| 623 | 836 | |
| 624 | - /* translators: %1$s: Number of forms */ | |
| 625 | - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 837 | + if ( $count ) { | |
| 838 | + /* translators: %1$s: Number of forms */ | |
| 839 | + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 840 | + } | |
| 626 | 841 | |
| 627 | - return $message; | |
| 842 | + return ''; | |
| 628 | 843 | } |
| 629 | 844 | |
| 630 | - private static function delete_all() { | |
| 845 | + /** | |
| 846 | + * @since 6.7.1 Function went from private to public. | |
| 847 | + */ | |
| 848 | + public static function delete_all() { | |
| 631 | 849 | // Check nonce url. |
| 632 | 850 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
| 633 | 851 | if ( $permission_error !== false ) { |
| 634 | 852 | self::display_forms_list( array(), '', array( $permission_error ) ); |
| @@ -635,14 +853,15 @@ | ||
| 635 | 853 | |
| 636 | 854 | return; |
| 637 | 855 | } |
| 638 | 856 | |
| 639 | - $count = FrmForm::scheduled_delete( time() ); | |
| 857 | + $count = FrmForm::scheduled_delete( time() ); | |
| 858 | + $url = remove_query_arg( array( 'delete_all' ) ); | |
| 640 | 859 | |
| 641 | - /* translators: %1$s: Number of forms */ | |
| 642 | - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 860 | + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count; | |
| 643 | 861 | |
| 644 | - self::display_forms_list( array(), $message ); | |
| 862 | + wp_safe_redirect( $url ); | |
| 863 | + die(); | |
| 645 | 864 | } |
| 646 | 865 | |
| 647 | 866 | /** |
| 648 | 867 | * Create a new form from the modal. |
| @@ -655,9 +874,9 @@ | ||
| 655 | 874 | |
| 656 | 875 | $new_values = self::get_modal_values(); |
| 657 | 876 | $new_values['form_key'] = $new_values['name']; |
| 658 | 877 | $new_values['options'] = array( |
| 659 | - 'antispam' => 1, | |
| 878 | + 'antispam' => 1, | |
| 660 | 879 | 'on_submit_migrated' => 1, |
| 661 | 880 | ); |
| 662 | 881 | |
| 663 | 882 | /** |
| @@ -676,13 +895,14 @@ | ||
| 676 | 895 | * @param int $form_id |
| 677 | 896 | */ |
| 678 | 897 | do_action( 'frm_build_new_form', $form_id ); |
| 679 | 898 | |
| 899 | + self::create_submit_button_field( $form_id ); | |
| 680 | 900 | self::create_default_on_submit_action( $form_id ); |
| 681 | 901 | self::create_default_email_action( $form_id ); |
| 682 | 902 | |
| 683 | 903 | $response = array( |
| 684 | - 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 904 | + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 685 | 905 | ); |
| 686 | 906 | |
| 687 | 907 | echo wp_json_encode( $response ); |
| 688 | 908 | wp_die(); |
| @@ -688,46 +908,15 @@ | ||
| 688 | 908 | wp_die(); |
| 689 | 909 | } |
| 690 | 910 | |
| 691 | 911 | /** |
| 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 | 912 | * Before creating a new form, get the name and description from the modal. |
| 726 | 913 | * |
| 727 | 914 | * @since 4.0 |
| 915 | + * | |
| 916 | + * @return array<string,string> | |
| 728 | 917 | */ |
| 729 | - private static function get_modal_values() { | |
| 918 | + public static function get_modal_values() { | |
| 730 | 919 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 731 | 920 | $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 732 | 921 | |
| 733 | 922 | return array( |
| @@ -740,17 +929,24 @@ | ||
| 740 | 929 | * Inserts Formidable button |
| 741 | 930 | * Hook exists since 2.5.0 |
| 742 | 931 | * |
| 743 | 932 | * @since 2.0.15 |
| 933 | + * | |
| 934 | + * @return void | |
| 744 | 935 | */ |
| 745 | 936 | public static function insert_form_button() { |
| 746 | 937 | 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>'; | |
| 938 | + // Store the result in memory and re-use it when this function is called multiple times. | |
| 939 | + // This helps speed up the form builder when there are a lot of HTML fields, where this | |
| 940 | + // button is inserted once per HTML field. | |
| 941 | + // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally. | |
| 942 | + if ( ! isset( self::$formidable_tinymce_button ) ) { | |
| 943 | + FrmAppHelper::load_admin_wide_js(); | |
| 944 | + $menu_name = FrmAppHelper::get_menu_name(); | |
| 945 | + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() ); | |
| 946 | + 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>'; | |
| 947 | + } | |
| 948 | + echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 753 | 949 | } |
| 754 | 950 | } |
| 755 | 951 | |
| 756 | 952 | /** |
| @@ -838,9 +1034,9 @@ | ||
| 838 | 1034 | $form_id = $opts['form_id']; |
| 839 | 1035 | unset( $opts['form_id'] ); |
| 840 | 1036 | } |
| 841 | 1037 | |
| 842 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' ); | |
| 1038 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php'; | |
| 843 | 1039 | |
| 844 | 1040 | echo '</div>'; |
| 845 | 1041 | |
| 846 | 1042 | wp_die(); |
| @@ -880,8 +1076,14 @@ | ||
| 880 | 1076 | wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) ); |
| 881 | 1077 | die(); |
| 882 | 1078 | } |
| 883 | 1079 | |
| 1080 | + $inbox = new FrmInbox(); | |
| 1081 | + $error = $inbox->check_for_error(); | |
| 1082 | + if ( $error ) { | |
| 1083 | + $show_messages = array( $error['subject'] . '. ' . $error['message'] ); | |
| 1084 | + } | |
| 1085 | + | |
| 884 | 1086 | require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php'; |
| 885 | 1087 | } |
| 886 | 1088 | |
| 887 | 1089 | /** |
| @@ -908,8 +1110,11 @@ | ||
| 908 | 1110 | |
| 909 | 1111 | return $columns; |
| 910 | 1112 | } |
| 911 | 1113 | |
| 1114 | + /** | |
| 1115 | + * @return array<string,string> | |
| 1116 | + */ | |
| 912 | 1117 | public static function get_sortable_columns() { |
| 913 | 1118 | return array( |
| 914 | 1119 | 'id' => 'id', |
| 915 | 1120 | 'name' => 'name', |
| @@ -943,9 +1148,9 @@ | ||
| 943 | 1148 | return $hidden_columns; |
| 944 | 1149 | } |
| 945 | 1150 | |
| 946 | 1151 | public static function save_per_page( $save, $option, $value ) { |
| 947 | - if ( $option == 'formidable_page_formidable_per_page' ) { | |
| 1152 | + if ( $option === 'formidable_page_formidable_per_page' ) { | |
| 948 | 1153 | $save = (int) $value; |
| 949 | 1154 | } |
| 950 | 1155 | |
| 951 | 1156 | return $save; |
| @@ -951,146 +1156,49 @@ | ||
| 951 | 1156 | return $save; |
| 952 | 1157 | } |
| 953 | 1158 | |
| 954 | 1159 | /** |
| 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 | - * | |
| 1160 | + * @param int|string $id | |
| 1161 | + * @param array $errors | |
| 1162 | + * @param string $message | |
| 1163 | + * @param bool $create_link | |
| 965 | 1164 | * @return void |
| 966 | 1165 | */ |
| 967 | - public static function before_list_templates() { | |
| 968 | - global $frm_templates; | |
| 969 | - global $frm_expired; | |
| 970 | - global $frm_license_type; | |
| 1166 | + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1167 | + global $frm_vars; | |
| 971 | 1168 | |
| 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 | - } | |
| 1169 | + $form = FrmForm::getOne( $id ); | |
| 1170 | + $error_args = array( | |
| 1171 | + 'title' => __( 'You can\'t edit the form', 'formidable' ), | |
| 1172 | + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ), | |
| 1173 | + 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 1174 | + 'continue_url' => add_query_arg( | |
| 1175 | + array( | |
| 1176 | + 'page' => 'formidable', | |
| 1177 | + ) | |
| 1178 | + ), | |
| 1029 | 1179 | ); |
| 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 | - } | |
| 1180 | + if ( ! $form ) { | |
| 1181 | + FrmAppController::show_error_modal( $error_args ); | |
| 1182 | + return; | |
| 1056 | 1183 | } |
| 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 | 1184 | |
| 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, | |
| 1185 | + if ( 'trash' === $form->status ) { | |
| 1186 | + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' ); | |
| 1187 | + $error_args['continue_url'] = add_query_arg( | |
| 1188 | + array( | |
| 1189 | + 'page' => 'formidable', | |
| 1190 | + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ), | |
| 1191 | + 'form_type' => 'trash', | |
| 1192 | + 'frm_action' => 'untrash', | |
| 1193 | + 'id' => $id, | |
| 1194 | + ) | |
| 1079 | 1195 | ); |
| 1080 | - array_unshift( $templates, $template ); | |
| 1081 | - unset( $template ); | |
| 1196 | + $error_args['continue_text'] = __( 'Restore form', 'formidable' ); | |
| 1197 | + FrmAppController::show_error_modal( $error_args ); | |
| 1198 | + return; | |
| 1082 | 1199 | } |
| 1083 | - } | |
| 1084 | 1200 | |
| 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 | 1201 | if ( $form->parent_form_id ) { |
| 1094 | 1202 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1095 | 1203 | 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 | 1204 | } |
| @@ -1101,8 +1209,9 @@ | ||
| 1101 | 1209 | |
| 1102 | 1210 | // Automatically add end section fields if they don't exist (2.0 migration). |
| 1103 | 1211 | $reset_fields = false; |
| 1104 | 1212 | FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
| 1213 | + FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields ); | |
| 1105 | 1214 | |
| 1106 | 1215 | if ( $reset_fields ) { |
| 1107 | 1216 | $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
| 1108 | 1217 | } |
| @@ -1128,18 +1237,21 @@ | ||
| 1128 | 1237 | } |
| 1129 | 1238 | |
| 1130 | 1239 | self::maybe_update_form_builder_message( $message ); |
| 1131 | 1240 | |
| 1132 | - $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); | |
| 1133 | - $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] ); | |
| 1241 | + $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] ); | |
| 1134 | 1242 | |
| 1135 | 1243 | if ( defined( 'DOING_AJAX' ) ) { |
| 1136 | 1244 | wp_die(); |
| 1137 | - } else { | |
| 1138 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); | |
| 1139 | 1245 | } |
| 1246 | + | |
| 1247 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php'; | |
| 1140 | 1248 | } |
| 1141 | 1249 | |
| 1250 | + /** | |
| 1251 | + * @param array $fields | |
| 1252 | + * @return array | |
| 1253 | + */ | |
| 1142 | 1254 | public static function update_form_builder_fields( $fields, $form ) { |
| 1143 | 1255 | foreach ( $fields as $field ) { |
| 1144 | 1256 | $field->do_not_include_icons = true; |
| 1145 | 1257 | } |
| @@ -1151,13 +1263,21 @@ | ||
| 1151 | 1263 | $message = __( 'Form was Successfully Copied', 'formidable' ); |
| 1152 | 1264 | } |
| 1153 | 1265 | } |
| 1154 | 1266 | |
| 1267 | + /** | |
| 1268 | + * @param int|string $id | |
| 1269 | + * @param array $errors | |
| 1270 | + * @param array|string $args | |
| 1271 | + * @return void | |
| 1272 | + */ | |
| 1155 | 1273 | public static function get_settings_vars( $id, $errors = array(), $args = array() ) { |
| 1156 | 1274 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 1157 | 1275 | |
| 1158 | 1276 | global $frm_vars; |
| 1159 | 1277 | |
| 1278 | + self::maybe_print_media_templates(); | |
| 1279 | + | |
| 1160 | 1280 | if ( ! is_array( $args ) ) { |
| 1161 | 1281 | // For reverse compatibility. |
| 1162 | 1282 | $args = array( |
| 1163 | 1283 | 'message' => $args, |
| @@ -1190,17 +1310,38 @@ | ||
| 1190 | 1310 | |
| 1191 | 1311 | $sections = self::get_settings_tabs( $values ); |
| 1192 | 1312 | $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' ); |
| 1193 | 1313 | |
| 1194 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' ); | |
| 1314 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php'; | |
| 1195 | 1315 | } |
| 1196 | 1316 | |
| 1197 | 1317 | /** |
| 1318 | + * 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. | |
| 1319 | + * | |
| 1320 | + * @since 6.10 | |
| 1321 | + * | |
| 1322 | + * @return void | |
| 1323 | + */ | |
| 1324 | + private static function maybe_print_media_templates() { | |
| 1325 | + if ( FrmAppHelper::pro_is_included() ) { | |
| 1326 | + // This issue does not exist when Pro is active so exit early. | |
| 1327 | + return; | |
| 1328 | + } | |
| 1329 | + | |
| 1330 | + add_action( | |
| 1331 | + 'wp_enqueue_editor', | |
| 1332 | + function () { | |
| 1333 | + wp_print_media_templates(); | |
| 1334 | + } | |
| 1335 | + ); | |
| 1336 | + } | |
| 1337 | + | |
| 1338 | + /** | |
| 1198 | 1339 | * @since 4.0 |
| 1199 | 1340 | */ |
| 1200 | 1341 | public static function form_publish_button( $atts ) { |
| 1201 | 1342 | $values = $atts['values']; |
| 1202 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' ); | |
| 1343 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php'; | |
| 1203 | 1344 | } |
| 1204 | 1345 | |
| 1205 | 1346 | /** |
| 1206 | 1347 | * Get a list of all the settings tabs for the form settings page. |
| @@ -1225,9 +1366,9 @@ | ||
| 1225 | 1366 | 'icon' => 'frm_icon_font frm_mail_bulk_icon', |
| 1226 | 1367 | ), |
| 1227 | 1368 | 'permissions' => array( |
| 1228 | 1369 | 'name' => __( 'Form Permissions', 'formidable' ), |
| 1229 | - 'icon' => 'frm_icon_font frm_lock_icon', | |
| 1370 | + 'icon' => 'frm_icon_font frm_lock_closed_icon', | |
| 1230 | 1371 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1231 | 1372 | 'data' => array( |
| 1232 | 1373 | 'medium' => 'permissions', |
| 1233 | 1374 | 'upgrade' => __( 'Form Permissions', 'formidable' ), |
| @@ -1234,9 +1375,9 @@ | ||
| 1234 | 1375 | 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ), |
| 1235 | 1376 | 'screenshot' => 'permissions.png', |
| 1236 | 1377 | ), |
| 1237 | 1378 | ), |
| 1238 | - 'scheduling' => array( | |
| 1379 | + 'scheduling' => array( | |
| 1239 | 1380 | 'name' => __( 'Form Scheduling', 'formidable' ), |
| 1240 | 1381 | 'icon' => 'frm_icon_font frm_calendar_icon', |
| 1241 | 1382 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1242 | 1383 | 'data' => array( |
| @@ -1269,9 +1410,9 @@ | ||
| 1269 | 1410 | 'screenshot' => 'chat.png', |
| 1270 | 1411 | ) |
| 1271 | 1412 | ), |
| 1272 | 1413 | ), |
| 1273 | - 'abandonment' => array( | |
| 1414 | + 'abandonment' => array( | |
| 1274 | 1415 | 'name' => __( 'Form Abandonment', 'formidable' ), |
| 1275 | 1416 | 'icon' => 'frm_icon_font frm_abandoned_icon', |
| 1276 | 1417 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1277 | 1418 | 'data' => FrmAppHelper::get_upgrade_data_params( |
| @@ -1290,8 +1431,12 @@ | ||
| 1290 | 1431 | 'icon' => 'frm_icon_font frm_code_icon', |
| 1291 | 1432 | ), |
| 1292 | 1433 | ); |
| 1293 | 1434 | |
| 1435 | + if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) { | |
| 1436 | + unset( $sections['buttons'] ); | |
| 1437 | + } | |
| 1438 | + | |
| 1294 | 1439 | foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) { |
| 1295 | 1440 | if ( ! FrmAppHelper::show_new_feature( $feature ) ) { |
| 1296 | 1441 | unset( $sections[ $feature ] ); |
| 1297 | 1442 | } |
| @@ -1298,13 +1443,8 @@ | ||
| 1298 | 1443 | } |
| 1299 | 1444 | |
| 1300 | 1445 | $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values ); |
| 1301 | 1446 | |
| 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 | 1447 | foreach ( $sections as $key => $section ) { |
| 1308 | 1448 | $defaults = array( |
| 1309 | 1449 | 'html_class' => '', |
| 1310 | 1450 | 'name' => ucfirst( $key ), |
| @@ -1326,9 +1466,9 @@ | ||
| 1326 | 1466 | $section['id'] = $section['anchor']; |
| 1327 | 1467 | } |
| 1328 | 1468 | |
| 1329 | 1469 | $sections[ $key ] = $section; |
| 1330 | - } | |
| 1470 | + }//end foreach | |
| 1331 | 1471 | |
| 1332 | 1472 | return $sections; |
| 1333 | 1473 | } |
| 1334 | 1474 | |
| @@ -1335,8 +1475,9 @@ | ||
| 1335 | 1475 | /** |
| 1336 | 1476 | * @since 4.0 |
| 1337 | 1477 | * |
| 1338 | 1478 | * @param array $values |
| 1479 | + * @return void | |
| 1339 | 1480 | */ |
| 1340 | 1481 | public static function advanced_settings( $values ) { |
| 1341 | 1482 | $first_h3 = 'frm_first_h3'; |
| 1342 | 1483 | |
| @@ -1344,8 +1485,9 @@ | ||
| 1344 | 1485 | } |
| 1345 | 1486 | |
| 1346 | 1487 | /** |
| 1347 | 1488 | * @param array $values |
| 1489 | + * @return void | |
| 1348 | 1490 | */ |
| 1349 | 1491 | public static function render_spam_settings( $values ) { |
| 1350 | 1492 | if ( function_exists( 'akismet_http_post' ) ) { |
| 1351 | 1493 | include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php'; |
| @@ -1357,16 +1499,12 @@ | ||
| 1357 | 1499 | /** |
| 1358 | 1500 | * @since 4.0 |
| 1359 | 1501 | * |
| 1360 | 1502 | * @param array $values |
| 1503 | + * @return void | |
| 1361 | 1504 | */ |
| 1362 | 1505 | 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' ); | |
| 1506 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php'; | |
| 1369 | 1507 | } |
| 1370 | 1508 | |
| 1371 | 1509 | /** |
| 1372 | 1510 | * @since 4.0 |
| @@ -1371,11 +1509,12 @@ | ||
| 1371 | 1509 | /** |
| 1372 | 1510 | * @since 4.0 |
| 1373 | 1511 | * |
| 1374 | 1512 | * @param array $values |
| 1513 | + * @return void | |
| 1375 | 1514 | */ |
| 1376 | 1515 | public static function html_settings( $values ) { |
| 1377 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' ); | |
| 1516 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php'; | |
| 1378 | 1517 | } |
| 1379 | 1518 | |
| 1380 | 1519 | /** |
| 1381 | 1520 | * Replace old Submit Button href with new href to avoid errors in Chrome |
| @@ -1381,9 +1520,10 @@ | ||
| 1381 | 1520 | * Replace old Submit Button href with new href to avoid errors in Chrome |
| 1382 | 1521 | * |
| 1383 | 1522 | * @since 2.03.08 |
| 1384 | 1523 | * |
| 1385 | - * @param array|boolean $values | |
| 1524 | + * @param array|bool $values | |
| 1525 | + * @return void | |
| 1386 | 1526 | */ |
| 1387 | 1527 | private static function clean_submit_html( &$values ) { |
| 1388 | 1528 | if ( is_array( $values ) && isset( $values['submit_html'] ) ) { |
| 1389 | 1529 | $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] ); |
| @@ -1404,8 +1544,13 @@ | ||
| 1404 | 1544 | |
| 1405 | 1545 | return $classes; |
| 1406 | 1546 | } |
| 1407 | 1547 | |
| 1548 | + /** | |
| 1549 | + * @param int|string $form_id | |
| 1550 | + * @param string $class | |
| 1551 | + * @return void | |
| 1552 | + */ | |
| 1408 | 1553 | public static function mb_tags_box( $form_id, $class = '' ) { |
| 1409 | 1554 | $fields = FrmField::get_all_for_form( $form_id, '', 'include' ); |
| 1410 | 1555 | |
| 1411 | 1556 | /** |
| @@ -1418,9 +1563,9 @@ | ||
| 1418 | 1563 | */ |
| 1419 | 1564 | $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) ); |
| 1420 | 1565 | $linked_forms = array(); |
| 1421 | 1566 | $col = 'one'; |
| 1422 | - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false; | |
| 1567 | + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ); | |
| 1423 | 1568 | |
| 1424 | 1569 | $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() ); |
| 1425 | 1570 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 1426 | 1571 | |
| @@ -1425,9 +1570,9 @@ | ||
| 1425 | 1570 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 1426 | 1571 | |
| 1427 | 1572 | $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) ); |
| 1428 | 1573 | |
| 1429 | - include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' ); | |
| 1574 | + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php'; | |
| 1430 | 1575 | } |
| 1431 | 1576 | |
| 1432 | 1577 | /** |
| 1433 | 1578 | * @since 3.04.01 |
| @@ -1440,9 +1585,9 @@ | ||
| 1440 | 1585 | ), |
| 1441 | 1586 | ); |
| 1442 | 1587 | |
| 1443 | 1588 | $user_fields = self::user_shortcodes(); |
| 1444 | - if ( ! empty( $user_fields ) ) { | |
| 1589 | + if ( $user_fields ) { | |
| 1445 | 1590 | $user_helpers = array(); |
| 1446 | 1591 | foreach ( $user_fields as $uk => $uf ) { |
| 1447 | 1592 | $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf; |
| 1448 | 1593 | unset( $uk, $uf ); |
| @@ -1448,9 +1593,9 @@ | ||
| 1448 | 1593 | unset( $uk, $uf ); |
| 1449 | 1594 | } |
| 1450 | 1595 | |
| 1451 | 1596 | $advanced_helpers['user_id'] = array( |
| 1452 | - 'codes' => $user_helpers, | |
| 1597 | + 'codes' => $user_helpers, | |
| 1453 | 1598 | ); |
| 1454 | 1599 | } |
| 1455 | 1600 | |
| 1456 | 1601 | /** |
| @@ -1527,21 +1672,16 @@ | ||
| 1527 | 1672 | 'updated-at' => __( 'Entry updated', 'formidable' ), |
| 1528 | 1673 | '' => '', |
| 1529 | 1674 | 'siteurl' => __( 'Site URL', 'formidable' ), |
| 1530 | 1675 | 'sitename' => __( 'Site Name', 'formidable' ), |
| 1676 | + 'form_name' => __( 'Form Name', 'formidable' ), | |
| 1531 | 1677 | ); |
| 1532 | 1678 | |
| 1679 | + $entry_shortcodes = array_merge( FrmShortcodeHelper::get_contextual_shortcode_values(), $entry_shortcodes ); | |
| 1533 | 1680 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 1534 | 1681 | unset( $entry_shortcodes['post_id'] ); |
| 1535 | 1682 | } |
| 1536 | 1683 | |
| 1537 | - if ( $settings_tab ) { | |
| 1538 | - $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' ); | |
| 1539 | - $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' ); | |
| 1540 | - $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' ); | |
| 1541 | - $entry_shortcodes['form_name'] = __( 'Form Name', 'formidable' ); | |
| 1542 | - } | |
| 1543 | - | |
| 1544 | 1684 | /** |
| 1545 | 1685 | * Use this hook to add or remove buttons in the helpers section |
| 1546 | 1686 | * in the customization panel |
| 1547 | 1687 | * |
| @@ -1591,11 +1731,11 @@ | ||
| 1591 | 1731 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1592 | 1732 | |
| 1593 | 1733 | echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 1594 | 1734 | array( |
| 1595 | - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), | |
| 1735 | + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1596 | 1736 | 'default_email' => true, |
| 1597 | - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), | |
| 1737 | + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1598 | 1738 | ) |
| 1599 | 1739 | ); |
| 1600 | 1740 | wp_die(); |
| 1601 | 1741 | } |
| @@ -1601,10 +1741,10 @@ | ||
| 1601 | 1741 | } |
| 1602 | 1742 | |
| 1603 | 1743 | /** |
| 1604 | 1744 | * @param string $content |
| 1605 | - * @param stdClass|string|int $form | |
| 1606 | - * @param stdClass|string|int|false $entry | |
| 1745 | + * @param int|stdClass|string $form | |
| 1746 | + * @param false|int|stdClass|string $entry | |
| 1607 | 1747 | * @return string |
| 1608 | 1748 | */ |
| 1609 | 1749 | public static function filter_content( $content, $form, $entry = false ) { |
| 1610 | 1750 | $content = self::replace_form_name_shortcodes( $content, $form ); |
| @@ -1617,8 +1757,16 @@ | ||
| 1617 | 1757 | if ( is_object( $form ) ) { |
| 1618 | 1758 | $form = $form->id; |
| 1619 | 1759 | } |
| 1620 | 1760 | |
| 1761 | + /* | |
| 1762 | + * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty, | |
| 1763 | + * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work. | |
| 1764 | + */ | |
| 1765 | + if ( ! empty( $entry->parent_entry ) ) { | |
| 1766 | + $form = $entry->parent_entry->form_id; | |
| 1767 | + } | |
| 1768 | + | |
| 1621 | 1769 | $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form ); |
| 1622 | 1770 | $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes ); |
| 1623 | 1771 | |
| 1624 | 1772 | return $content; |
| @@ -1628,11 +1776,11 @@ | ||
| 1628 | 1776 | * Replace any [form_name] shortcodes in a string. |
| 1629 | 1777 | * |
| 1630 | 1778 | * @since 5.5 |
| 1631 | 1779 | * |
| 1632 | - * @param string|array $string | |
| 1633 | - * @param stdClass|string|int $form | |
| 1634 | - * @return string|array | |
| 1780 | + * @param array|string $string | |
| 1781 | + * @param int|stdClass|string $form | |
| 1782 | + * @return array|string | |
| 1635 | 1783 | */ |
| 1636 | 1784 | public static function replace_form_name_shortcodes( $string, $form ) { |
| 1637 | 1785 | if ( ! is_string( $string ) ) { |
| 1638 | 1786 | return $string; |
| @@ -1650,9 +1798,9 @@ | ||
| 1650 | 1798 | return str_replace( '[form_name]', $form_name, $string ); |
| 1651 | 1799 | } |
| 1652 | 1800 | |
| 1653 | 1801 | /** |
| 1654 | - * @param stdClass|string|int|false $entry | |
| 1802 | + * @param false|int|stdClass|string $entry | |
| 1655 | 1803 | * @return void |
| 1656 | 1804 | */ |
| 1657 | 1805 | private static function get_entry_by_param( &$entry ) { |
| 1658 | 1806 | if ( ! $entry || ! is_object( $entry ) ) { |
| @@ -1667,8 +1815,12 @@ | ||
| 1667 | 1815 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
| 1668 | 1816 | return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); |
| 1669 | 1817 | } |
| 1670 | 1818 | |
| 1819 | + /** | |
| 1820 | + * @param array $errors | |
| 1821 | + * @return array | |
| 1822 | + */ | |
| 1671 | 1823 | public static function process_bulk_form_actions( $errors ) { |
| 1672 | 1824 | if ( ! $_REQUEST ) { |
| 1673 | 1825 | return $errors; |
| 1674 | 1826 | } |
| @@ -1712,9 +1864,9 @@ | ||
| 1712 | 1864 | case 'untrash': |
| 1713 | 1865 | $message = self::bulk_untrash( $ids ); |
| 1714 | 1866 | } |
| 1715 | 1867 | |
| 1716 | - if ( isset( $message ) && ! empty( $message ) ) { | |
| 1868 | + if ( ! empty( $message ) ) { | |
| 1717 | 1869 | $errors['message'] = $message; |
| 1718 | 1870 | } |
| 1719 | 1871 | |
| 1720 | 1872 | return $errors; |
| @@ -1734,9 +1886,9 @@ | ||
| 1734 | 1886 | $json_vars = json_decode( $json_vars, true ); |
| 1735 | 1887 | if ( empty( $json_vars ) ) { |
| 1736 | 1888 | // json decoding failed so we should return an error message. |
| 1737 | 1889 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 1738 | - if ( 'edit' == $action ) { | |
| 1890 | + if ( 'edit' === $action ) { | |
| 1739 | 1891 | $action = 'update'; |
| 1740 | 1892 | } |
| 1741 | 1893 | |
| 1742 | 1894 | add_filter( 'frm_validate_form', 'FrmFormsController::json_error' ); |
| @@ -1752,16 +1904,14 @@ | ||
| 1752 | 1904 | if ( isset( $_REQUEST['delete_all'] ) ) { |
| 1753 | 1905 | // Override the action for this page. |
| 1754 | 1906 | $action = 'delete_all'; |
| 1755 | 1907 | } |
| 1756 | - } | |
| 1908 | + }//end if | |
| 1757 | 1909 | |
| 1758 | 1910 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1759 | 1911 | FrmAppHelper::trigger_hook_load( 'form' ); |
| 1760 | 1912 | |
| 1761 | 1913 | switch ( $action ) { |
| 1762 | - case 'new': | |
| 1763 | - return self::new_form( $vars ); | |
| 1764 | 1914 | case 'create': |
| 1765 | 1915 | case 'edit': |
| 1766 | 1916 | case 'update': |
| 1767 | 1917 | case 'trash': |
| @@ -1766,16 +1916,17 @@ | ||
| 1766 | 1916 | case 'update': |
| 1767 | 1917 | case 'trash': |
| 1768 | 1918 | case 'untrash': |
| 1769 | 1919 | case 'destroy': |
| 1770 | - case 'delete_all': | |
| 1771 | 1920 | case 'settings': |
| 1772 | 1921 | case 'update_settings': |
| 1773 | 1922 | return self::$action( $vars ); |
| 1774 | 1923 | case 'lite-reports': |
| 1775 | - return self::no_reports( $vars ); | |
| 1924 | + self::no_reports( $vars ); | |
| 1925 | + return; | |
| 1776 | 1926 | case 'views': |
| 1777 | - return self::no_views( $vars ); | |
| 1927 | + self::no_views( $vars ); | |
| 1928 | + return; | |
| 1778 | 1929 | default: |
| 1779 | 1930 | do_action( 'frm_form_action_' . $action ); |
| 1780 | 1931 | if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) { |
| 1781 | 1932 | return; |
| @@ -1798,14 +1949,47 @@ | ||
| 1798 | 1949 | self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) ); |
| 1799 | 1950 | return; |
| 1800 | 1951 | } |
| 1801 | 1952 | |
| 1953 | + if ( 'forms_permanently_deleted' === $message ) { | |
| 1954 | + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' ); | |
| 1955 | + /* translators: %1$s: Number of forms */ | |
| 1956 | + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 1957 | + self::display_forms_list( array(), $message, '' ); | |
| 1958 | + return; | |
| 1959 | + } | |
| 1960 | + | |
| 1802 | 1961 | self::display_forms_list(); |
| 1803 | 1962 | |
| 1804 | 1963 | return; |
| 1805 | - } | |
| 1964 | + }//end switch | |
| 1806 | 1965 | } |
| 1807 | 1966 | |
| 1967 | + /** | |
| 1968 | + * Rename a form. | |
| 1969 | + * | |
| 1970 | + * Handles the AJAX request for renaming a form. | |
| 1971 | + * | |
| 1972 | + * @since 6.7 | |
| 1973 | + * | |
| 1974 | + * @return void | |
| 1975 | + */ | |
| 1976 | + public static function rename_form() { | |
| 1977 | + // Check permission and nonce | |
| 1978 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 1979 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 1980 | + | |
| 1981 | + // Get posted data | |
| 1982 | + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); | |
| 1983 | + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' ); | |
| 1984 | + | |
| 1985 | + // Update the form name and form key. | |
| 1986 | + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' ); | |
| 1987 | + FrmForm::update( $form_id, compact( 'name', 'form_key' ) ); | |
| 1988 | + | |
| 1989 | + wp_send_json_success( compact( 'form_key' ) ); | |
| 1990 | + } | |
| 1991 | + | |
| 1808 | 1992 | public static function json_error( $errors ) { |
| 1809 | 1993 | $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
| 1810 | 1994 | |
| 1811 | 1995 | return $errors; |
| @@ -1811,20 +1995,13 @@ | ||
| 1811 | 1995 | return $errors; |
| 1812 | 1996 | } |
| 1813 | 1997 | |
| 1814 | 1998 | /** |
| 1815 | - * Education for premium features. | |
| 1816 | - * | |
| 1817 | - * @since 4.05 | |
| 1818 | - */ | |
| 1819 | - public static function add_form_style_tab_options() { | |
| 1820 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' ); | |
| 1821 | - } | |
| 1822 | - | |
| 1823 | - /** | |
| 1824 | 1999 | * Add education about views. |
| 1825 | 2000 | * |
| 1826 | 2001 | * @since 4.07 |
| 2002 | + * | |
| 2003 | + * @return void | |
| 1827 | 2004 | */ |
| 1828 | 2005 | public static function no_views( $values = array() ) { |
| 1829 | 2006 | FrmAppHelper::include_svg(); |
| 1830 | 2007 | $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| @@ -1836,8 +2013,10 @@ | ||
| 1836 | 2013 | /** |
| 1837 | 2014 | * Add education about reports. |
| 1838 | 2015 | * |
| 1839 | 2016 | * @since 4.07 |
| 2017 | + * | |
| 2018 | + * @return void | |
| 1840 | 2019 | */ |
| 1841 | 2020 | public static function no_reports( $values = array() ) { |
| 1842 | 2021 | $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| 1843 | 2022 | $form = $id ? FrmForm::getOne( $id ) : false; |
| @@ -1844,9 +2023,11 @@ | ||
| 1844 | 2023 | |
| 1845 | 2024 | include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php'; |
| 1846 | 2025 | } |
| 1847 | 2026 | |
| 1848 | - /* FRONT-END FORMS */ | |
| 2027 | + /** | |
| 2028 | + * FRONT-END FORMS. | |
| 2029 | + */ | |
| 1849 | 2030 | public static function admin_bar_css() { |
| 1850 | 2031 | if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 1851 | 2032 | return; |
| 1852 | 2033 | } |
| @@ -1920,9 +2101,9 @@ | ||
| 1920 | 2101 | $wp_admin_bar->add_node( |
| 1921 | 2102 | array( |
| 1922 | 2103 | 'parent' => 'frm-forms', |
| 1923 | 2104 | 'id' => 'edit_form_' . $form_id, |
| 1924 | - 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name, | |
| 2105 | + 'title' => empty( $name ) ? FrmFormsHelper::get_no_title_text() : $name, | |
| 1925 | 2106 | 'href' => FrmForm::get_edit_link( $form_id ), |
| 1926 | 2107 | ) |
| 1927 | 2108 | ); |
| 1928 | 2109 | } |
| @@ -1935,10 +2116,10 @@ | ||
| 1935 | 2116 | * @return string |
| 1936 | 2117 | */ |
| 1937 | 2118 | public static function get_form_shortcode( $atts ) { |
| 1938 | 2119 | global $frm_vars; |
| 1939 | - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) { | |
| 1940 | - $sc = '[formidable'; | |
| 2120 | + if ( ! empty( $frm_vars['skip_shortcode'] ) ) { | |
| 2121 | + $sc = '[formidable'; | |
| 1941 | 2122 | $sc .= FrmAppHelper::array_to_html_params( $atts ); |
| 1942 | 2123 | return $sc . ']'; |
| 1943 | 2124 | } |
| 1944 | 2125 | |
| @@ -1963,11 +2144,11 @@ | ||
| 1963 | 2144 | |
| 1964 | 2145 | /** |
| 1965 | 2146 | * @since 5.2.01 |
| 1966 | 2147 | * |
| 1967 | - * @param string|int|false $id | |
| 1968 | - * @param string|false $key | |
| 1969 | - * @return stdClass|false | |
| 2148 | + * @param false|int|string $id | |
| 2149 | + * @param false|string $key | |
| 2150 | + * @return false|stdClass | |
| 1970 | 2151 | */ |
| 1971 | 2152 | private static function maybe_get_form_by_id_or_key( $id, $key ) { |
| 1972 | 2153 | if ( ! $id ) { |
| 1973 | 2154 | $id = $key; |
| @@ -1975,12 +2156,12 @@ | ||
| 1975 | 2156 | return self::maybe_get_form_to_show( $id ); |
| 1976 | 2157 | } |
| 1977 | 2158 | |
| 1978 | 2159 | /** |
| 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. | |
| 2160 | + * @param false|int|string $id | |
| 2161 | + * @param false|string $key | |
| 2162 | + * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 2163 | + * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 1983 | 2164 | * @param array $atts |
| 1984 | 2165 | * @return string |
| 1985 | 2166 | */ |
| 1986 | 2167 | public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
| @@ -2028,15 +2209,16 @@ | ||
| 2028 | 2209 | return $form; |
| 2029 | 2210 | } |
| 2030 | 2211 | |
| 2031 | 2212 | /** |
| 2032 | - * @param string|int|false $id | |
| 2033 | - * @return stdClass|false | |
| 2213 | + * @param false|int|string $id | |
| 2214 | + * @return false|stdClass | |
| 2034 | 2215 | */ |
| 2035 | 2216 | private static function maybe_get_form_to_show( $id ) { |
| 2036 | 2217 | $form = false; |
| 2037 | 2218 | |
| 2038 | - if ( ! empty( $id ) ) { // form id or key is set | |
| 2219 | + if ( ! empty( $id ) ) { | |
| 2220 | + // Form id or key is set. | |
| 2039 | 2221 | $form = FrmForm::getOne( $id ); |
| 2040 | 2222 | if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) { |
| 2041 | 2223 | $form = false; |
| 2042 | 2224 | } |
| @@ -2094,11 +2276,11 @@ | ||
| 2094 | 2276 | |
| 2095 | 2277 | do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description ); |
| 2096 | 2278 | |
| 2097 | 2279 | 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; | |
| 2280 | + $entry_id = self::just_created_entry( $form->id ); | |
| 2281 | + $pass_args['entry_id'] = $entry_id; | |
| 2282 | + $pass_args['reset'] = true; | |
| 2101 | 2283 | |
| 2102 | 2284 | self::run_on_submit_actions( $pass_args ); |
| 2103 | 2285 | |
| 2104 | 2286 | do_action( |
| @@ -2108,9 +2290,9 @@ | ||
| 2108 | 2290 | 'form' => $form, |
| 2109 | 2291 | ) |
| 2110 | 2292 | ); |
| 2111 | 2293 | } |
| 2112 | - } | |
| 2294 | + }//end if | |
| 2113 | 2295 | } |
| 2114 | 2296 | |
| 2115 | 2297 | /** |
| 2116 | 2298 | * If the form was processed earlier (init), get the generated errors |
| @@ -2142,9 +2324,9 @@ | ||
| 2142 | 2324 | */ |
| 2143 | 2325 | public static function just_created_entry( $form_id ) { |
| 2144 | 2326 | global $frm_vars; |
| 2145 | 2327 | |
| 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; | |
| 2328 | + 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 | 2329 | } |
| 2148 | 2330 | |
| 2149 | 2331 | /** |
| 2150 | 2332 | * Gets confirmation method. |
| @@ -2157,14 +2339,14 @@ | ||
| 2157 | 2339 | * |
| 2158 | 2340 | * @type object $form Form object. |
| 2159 | 2341 | * @type int $entry_id Entry ID. |
| 2160 | 2342 | * } |
| 2161 | - * @return string|array | |
| 2343 | + * @return array|string | |
| 2162 | 2344 | */ |
| 2163 | 2345 | private static function get_confirmation_method( $atts ) { |
| 2164 | 2346 | $action = FrmOnSubmitHelper::current_event( $atts ); |
| 2165 | 2347 | $opt = 'update' === $action ? 'edit_action' : 'success_action'; |
| 2166 | - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message'; | |
| 2348 | + $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message'; | |
| 2167 | 2349 | |
| 2168 | 2350 | if ( ! empty( $atts['entry_id'] ) ) { |
| 2169 | 2351 | $met_actions = self::get_met_on_submit_actions( $atts, $action ); |
| 2170 | 2352 | if ( $met_actions ) { |
| @@ -2173,9 +2355,9 @@ | ||
| 2173 | 2355 | } |
| 2174 | 2356 | |
| 2175 | 2357 | $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action ); |
| 2176 | 2358 | |
| 2177 | - if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { | |
| 2359 | + if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { | |
| 2178 | 2360 | $method = 'message'; |
| 2179 | 2361 | } |
| 2180 | 2362 | |
| 2181 | 2363 | return $method; |
| @@ -2209,9 +2391,9 @@ | ||
| 2209 | 2391 | * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}. |
| 2210 | 2392 | */ |
| 2211 | 2393 | public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) { |
| 2212 | 2394 | if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) { |
| 2213 | - if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) ) { | |
| 2395 | + if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) { | |
| 2214 | 2396 | $event = FrmOnSubmitHelper::current_event( $params ); |
| 2215 | 2397 | FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event ); |
| 2216 | 2398 | $conf_method = 'redirect'; |
| 2217 | 2399 | } |
| @@ -2260,9 +2442,9 @@ | ||
| 2260 | 2442 | unset( $extra_args['form'] ); |
| 2261 | 2443 | |
| 2262 | 2444 | do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args ); |
| 2263 | 2445 | |
| 2264 | - $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit'; | |
| 2446 | + $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit'; | |
| 2265 | 2447 | |
| 2266 | 2448 | $args['success_opt'] = $opt; |
| 2267 | 2449 | $args['ajax'] = ! empty( $frm_vars['ajax'] ); |
| 2268 | 2450 | |
| @@ -2288,16 +2470,16 @@ | ||
| 2288 | 2470 | if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) { |
| 2289 | 2471 | return array(); |
| 2290 | 2472 | } |
| 2291 | 2473 | |
| 2292 | - // If a redirect action has already opened the URL in a new tab, we show the default message in the currect tab. | |
| 2474 | + // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab. | |
| 2293 | 2475 | if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) { |
| 2294 | 2476 | return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) ); |
| 2295 | 2477 | } |
| 2296 | 2478 | |
| 2297 | - $entry = FrmEntry::getOne( $args['entry_id'], true ); | |
| 2298 | - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); | |
| 2299 | - $met_actions = array(); | |
| 2479 | + $entry = FrmEntry::getOne( $args['entry_id'], true ); | |
| 2480 | + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); | |
| 2481 | + $met_actions = array(); | |
| 2300 | 2482 | $has_redirect = false; |
| 2301 | 2483 | |
| 2302 | 2484 | foreach ( $actions as $action ) { |
| 2303 | 2485 | if ( ! in_array( $event, $action->post_content['event'], true ) ) { |
| @@ -2310,9 +2492,10 @@ | ||
| 2310 | 2492 | |
| 2311 | 2493 | $action_type = FrmOnSubmitHelper::get_action_type( $action ); |
| 2312 | 2494 | |
| 2313 | 2495 | if ( 'redirect' === $action_type ) { |
| 2314 | - if ( $has_redirect ) { // Do not process because we run the first redirect action only. | |
| 2496 | + if ( $has_redirect ) { | |
| 2497 | + // Do not process because we run the first redirect action only. | |
| 2315 | 2498 | continue; |
| 2316 | 2499 | } |
| 2317 | 2500 | } |
| 2318 | 2501 | |
| @@ -2325,9 +2508,9 @@ | ||
| 2325 | 2508 | } |
| 2326 | 2509 | |
| 2327 | 2510 | $met_actions[] = $action; |
| 2328 | 2511 | unset( $action ); |
| 2329 | - } | |
| 2512 | + }//end foreach | |
| 2330 | 2513 | |
| 2331 | 2514 | $args['event'] = $event; |
| 2332 | 2515 | |
| 2333 | 2516 | /** |
| @@ -2516,9 +2699,9 @@ | ||
| 2516 | 2699 | add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 ); |
| 2517 | 2700 | } |
| 2518 | 2701 | |
| 2519 | 2702 | $post = $old_post; |
| 2520 | - } | |
| 2703 | + }//end if | |
| 2521 | 2704 | } |
| 2522 | 2705 | |
| 2523 | 2706 | /** |
| 2524 | 2707 | * @since 3.0 |
| @@ -2539,14 +2722,16 @@ | ||
| 2539 | 2722 | $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args ); |
| 2540 | 2723 | |
| 2541 | 2724 | $doing_ajax = FrmAppHelper::doing_ajax(); |
| 2542 | 2725 | |
| 2543 | - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs. | |
| 2726 | + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { | |
| 2727 | + // Is AJAX submit and there is just one Redirect action runs. | |
| 2544 | 2728 | echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) ); |
| 2545 | 2729 | wp_die(); |
| 2546 | 2730 | } |
| 2547 | 2731 | |
| 2548 | - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2732 | + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) && empty( $args['form']->options['redirect_delay'] ) ) { | |
| 2733 | + // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2549 | 2734 | if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { |
| 2550 | 2735 | self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ); |
| 2551 | 2736 | self::$redirected_in_new_tab[ $args['form']->id ] = 1; |
| 2552 | 2737 | return; |
| @@ -2552,9 +2737,10 @@ | ||
| 2552 | 2737 | return; |
| 2553 | 2738 | } |
| 2554 | 2739 | |
| 2555 | 2740 | wp_redirect( esc_url_raw( $success_url ) ); |
| 2556 | - die(); // do not use wp_die or redirect fails | |
| 2741 | + // Do not use wp_die or redirect fails. | |
| 2742 | + die(); | |
| 2557 | 2743 | } |
| 2558 | 2744 | |
| 2559 | 2745 | // Redirect with a delay. |
| 2560 | 2746 | self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) ); |
| @@ -2589,28 +2775,46 @@ | ||
| 2589 | 2775 | * @param array $args See {@see FrmFormsController::run_success_action()}. |
| 2590 | 2776 | * @return array |
| 2591 | 2777 | */ |
| 2592 | 2778 | private static function get_ajax_redirect_response_data( $args ) { |
| 2593 | - $response_data = array( 'redirect' => $args['success_url'] ); | |
| 2779 | + $response_data = array( | |
| 2780 | + 'redirect' => $args['success_url'], | |
| 2781 | + 'content' => '', | |
| 2782 | + ); | |
| 2783 | + $unset_content = true; | |
| 2594 | 2784 | |
| 2785 | + if ( ! empty( $args['form']->options['redirect_delay'] ) ) { | |
| 2786 | + $response_data['delay'] = $args['form']->options['redirect_delay_time']; | |
| 2787 | + $response_data['content'] .= self::get_redirect_message( $args['success_url'], $args['form']->options['redirect_delay_msg'], $args ); | |
| 2788 | + $unset_content = false; | |
| 2789 | + } | |
| 2790 | + | |
| 2595 | 2791 | if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { |
| 2596 | 2792 | $response_data['openInNewTab'] = 1; |
| 2597 | 2793 | |
| 2598 | - $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg(); | |
| 2794 | + // Only show open in new tab text if there is no delay. | |
| 2795 | + if ( empty( $response_data['content'] ) ) { | |
| 2796 | + $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg(); | |
| 2599 | 2797 | |
| 2600 | - $args['form']->options['success_msg'] = $args['message']; | |
| 2601 | - $args['form']->options['edit_msg'] = $args['message']; | |
| 2602 | - if ( ! isset( $args['fields'] ) ) { | |
| 2603 | - $args['fields'] = FrmField::get_all_for_form( $args['form']->id ); | |
| 2604 | - } | |
| 2798 | + $args['form']->options['success_msg'] = $args['message']; | |
| 2799 | + $args['form']->options['edit_msg'] = $args['message']; | |
| 2800 | + if ( ! isset( $args['fields'] ) ) { | |
| 2801 | + $args['fields'] = FrmField::get_all_for_form( $args['form']->id ); | |
| 2802 | + } | |
| 2605 | 2803 | |
| 2606 | - $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args ); | |
| 2804 | + $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args ); | |
| 2607 | 2805 | |
| 2608 | - ob_start(); | |
| 2609 | - self::show_lone_success_messsage( $args ); | |
| 2610 | - $response_data['content'] = ob_get_clean(); | |
| 2806 | + ob_start(); | |
| 2807 | + self::show_lone_success_message( $args ); | |
| 2808 | + $response_data['content'] .= ob_get_clean(); | |
| 2809 | + $unset_content = false; | |
| 2810 | + }//end if | |
| 2611 | 2811 | |
| 2612 | 2812 | $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args ); |
| 2813 | + }//end if | |
| 2814 | + | |
| 2815 | + if ( $unset_content && '' === $response_data['content'] ) { | |
| 2816 | + unset( $response_data['content'] ); | |
| 2613 | 2817 | } |
| 2614 | 2818 | |
| 2615 | 2819 | return $response_data; |
| 2616 | 2820 | } |
| @@ -2622,9 +2826,9 @@ | ||
| 2622 | 2826 | * |
| 2623 | 2827 | * @param array $args See {@see FrmFormsController::run_success_action()}. |
| 2624 | 2828 | */ |
| 2625 | 2829 | private static function redirect_after_submit_using_js( $args ) { |
| 2626 | - $success_msg = FrmOnSubmitHelper::get_default_redirect_msg(); | |
| 2830 | + $success_msg = $args['form']->options['redirect_delay_msg']; | |
| 2627 | 2831 | $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args ); |
| 2628 | 2832 | $success_url = esc_url_raw( $args['success_url'] ); |
| 2629 | 2833 | |
| 2630 | 2834 | /** |
| @@ -2631,11 +2835,11 @@ | ||
| 2631 | 2835 | * Filters the delay time before redirecting when On Submit Redirect action is delayed. |
| 2632 | 2836 | * |
| 2633 | 2837 | * @since 6.0 |
| 2634 | 2838 | * |
| 2635 | - * @param int $delay_time Delay time in miliseconds. | |
| 2839 | + * @param int $delay_time Delay time in milliseconds. | |
| 2636 | 2840 | */ |
| 2637 | - $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 ); | |
| 2841 | + $delay_time = apply_filters( 'frm_redirect_delay_time', 1000 * $args['form']->options['redirect_delay_time'] ); | |
| 2638 | 2842 | |
| 2639 | 2843 | if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { |
| 2640 | 2844 | $redirect_js = 'window.open("' . $success_url . '", "_blank")'; |
| 2641 | 2845 | } else { |
| @@ -2645,9 +2849,10 @@ | ||
| 2645 | 2849 | add_filter( 'frm_use_wpautop', '__return_true' ); |
| 2646 | 2850 | |
| 2647 | 2851 | echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2648 | 2852 | echo '<script>'; |
| 2649 | - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load. | |
| 2853 | + if ( empty( $args['doing_ajax'] ) ) { | |
| 2854 | + // Not AJAX submit, delay JS until window.load. | |
| 2650 | 2855 | echo 'window.onload=function(){'; |
| 2651 | 2856 | } |
| 2652 | 2857 | echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2653 | 2858 | if ( empty( $args['doing_ajax'] ) ) { |
| @@ -2660,11 +2865,13 @@ | ||
| 2660 | 2865 | * @since 3.0 |
| 2661 | 2866 | * |
| 2662 | 2867 | * @param string $success_url |
| 2663 | 2868 | * @param string $success_msg |
| 2664 | - * @param array $args | |
| 2869 | + * @param array $args | |
| 2665 | 2870 | */ |
| 2666 | 2871 | private static function get_redirect_message( $success_url, $success_msg, $args ) { |
| 2872 | + $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] ); | |
| 2873 | + $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) ); | |
| 2667 | 2874 | $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . |
| 2668 | 2875 | self::get_redirect_fallback_message( $success_url, $args ) . |
| 2669 | 2876 | '</div></div>'; |
| 2670 | 2877 | |
| @@ -2720,9 +2927,9 @@ | ||
| 2720 | 2927 | } else { |
| 2721 | 2928 | self::show_form_after_submit( $atts ); |
| 2722 | 2929 | } |
| 2723 | 2930 | } else { |
| 2724 | - self::show_lone_success_messsage( $atts ); | |
| 2931 | + self::show_lone_success_message( $atts ); | |
| 2725 | 2932 | } |
| 2726 | 2933 | } |
| 2727 | 2934 | |
| 2728 | 2935 | /** |
| @@ -2761,11 +2968,10 @@ | ||
| 2761 | 2968 | include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php'; |
| 2762 | 2969 | } |
| 2763 | 2970 | |
| 2764 | 2971 | /** |
| 2972 | + * @since 4.05.02 | |
| 2765 | 2973 | * @return string - 'before', 'after', or 'submit' |
| 2766 | - * | |
| 2767 | - * @since 4.05.02 | |
| 2768 | 2974 | */ |
| 2769 | 2975 | private static function message_placement( $form, $message ) { |
| 2770 | 2976 | $place = 'before'; |
| 2771 | 2977 | |
| @@ -2777,11 +2983,10 @@ | ||
| 2777 | 2983 | } |
| 2778 | 2984 | } |
| 2779 | 2985 | |
| 2780 | 2986 | /** |
| 2987 | + * @since 4.05.02 | |
| 2781 | 2988 | * @return string - 'before' or 'after' |
| 2782 | - * | |
| 2783 | - * @since 4.05.02 | |
| 2784 | 2989 | */ |
| 2785 | 2990 | return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) ); |
| 2786 | 2991 | } |
| 2787 | 2992 | |
| @@ -2815,9 +3020,9 @@ | ||
| 2815 | 3020 | * Show the success message without the form |
| 2816 | 3021 | * |
| 2817 | 3022 | * @since 2.05 |
| 2818 | 3023 | */ |
| 2819 | - private static function show_lone_success_messsage( $atts ) { | |
| 3024 | + private static function show_lone_success_message( $atts ) { | |
| 2820 | 3025 | global $frm_vars; |
| 2821 | 3026 | $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true ); |
| 2822 | 3027 | self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] ); |
| 2823 | 3028 | |
| @@ -2826,9 +3031,9 @@ | ||
| 2826 | 3031 | $errors = array(); |
| 2827 | 3032 | $form = $atts['form']; |
| 2828 | 3033 | $message = $atts['message']; |
| 2829 | 3034 | |
| 2830 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' ); | |
| 3035 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php'; | |
| 2831 | 3036 | } |
| 2832 | 3037 | |
| 2833 | 3038 | /** |
| 2834 | 3039 | * Prepare the success message before it's shown |
| @@ -2948,9 +3153,9 @@ | ||
| 2948 | 3153 | global $frm_vars; |
| 2949 | 3154 | |
| 2950 | 3155 | FrmStylesController::enqueue_css(); |
| 2951 | 3156 | |
| 2952 | - if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) { | |
| 3157 | + if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) { | |
| 2953 | 3158 | // load formidable js |
| 2954 | 3159 | wp_enqueue_script( 'formidable' ); |
| 2955 | 3160 | } |
| 2956 | 3161 | } |
| @@ -2966,12 +3171,12 @@ | ||
| 2966 | 3171 | } |
| 2967 | 3172 | |
| 2968 | 3173 | /** |
| 2969 | 3174 | * @since 2.0.8 |
| 2970 | - * @return boolean | |
| 3175 | + * @return bool | |
| 2971 | 3176 | */ |
| 2972 | 3177 | private static function is_minification_on( $atts ) { |
| 2973 | - return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] ); | |
| 3178 | + return ! empty( $atts['minimize'] ); | |
| 2974 | 3179 | } |
| 2975 | 3180 | |
| 2976 | 3181 | /** |
| 2977 | 3182 | * @since 5.0.16 |
| @@ -2999,9 +3204,9 @@ | ||
| 2999 | 3204 | * Create a page with an embedded formidable Gutenberg block. |
| 3000 | 3205 | * |
| 3001 | 3206 | * @since 5.2 |
| 3002 | 3207 | * |
| 3003 | - * @return never | |
| 3208 | + * @return void | |
| 3004 | 3209 | */ |
| 3005 | 3210 | public static function create_page_with_shortcode() { |
| 3006 | 3211 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3007 | 3212 | die( 0 ); |
| @@ -3046,10 +3251,9 @@ | ||
| 3046 | 3251 | |
| 3047 | 3252 | /** |
| 3048 | 3253 | * @since 5.3 |
| 3049 | 3254 | * |
| 3050 | - * @param string $content | |
| 3051 | - * @param int $form_id | |
| 3255 | + * @param int $form_id | |
| 3052 | 3256 | * @return string |
| 3053 | 3257 | */ |
| 3054 | 3258 | private static function get_page_shortcode_content_for_form( $form_id ) { |
| 3055 | 3259 | $shortcode = '[formidable id="' . $form_id . '"]'; |
| @@ -3060,9 +3264,9 @@ | ||
| 3060 | 3264 | |
| 3061 | 3265 | /** |
| 3062 | 3266 | * Get page dropdown for AJAX request for embedding form in an existing page. |
| 3063 | 3267 | * |
| 3064 | - * @return never | |
| 3268 | + * @return void | |
| 3065 | 3269 | */ |
| 3066 | 3270 | public static function get_page_dropdown() { |
| 3067 | 3271 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3068 | 3272 | die( 0 ); |
| @@ -3070,9 +3274,9 @@ | ||
| 3070 | 3274 | |
| 3071 | 3275 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 3072 | 3276 | |
| 3073 | 3277 | $html = FrmAppHelper::clip( |
| 3074 | - function() { | |
| 3278 | + function () { | |
| 3075 | 3279 | FrmAppHelper::maybe_autocomplete_pages_options( |
| 3076 | 3280 | array( |
| 3077 | 3281 | 'field_name' => 'frm_page_dropdown', |
| 3078 | 3282 | 'page_id' => '', |
| @@ -3092,15 +3296,8 @@ | ||
| 3092 | 3296 | |
| 3093 | 3297 | /** |
| 3094 | 3298 | * @deprecated 4.0 |
| 3095 | 3299 | */ |
| 3096 | - public static function new_form( $values = array() ) { | |
| 3097 | - FrmDeprecated::new_form( $values ); | |
| 3098 | - } | |
| 3099 | - | |
| 3100 | - /** | |
| 3101 | - * @deprecated 4.0 | |
| 3102 | - */ | |
| 3103 | 3300 | public static function create( $values = array() ) { |
| 3104 | 3301 | _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' ); |
| 3105 | 3302 | self::update( $values ); |
| 3106 | 3303 | } |
| @@ -3105,35 +3302,16 @@ | ||
| 3105 | 3302 | self::update( $values ); |
| 3106 | 3303 | } |
| 3107 | 3304 | |
| 3108 | 3305 | /** |
| 3109 | - * @deprecated 3.0 | |
| 3110 | - * @codeCoverageIgnore | |
| 3306 | + * Education for premium features. | |
| 3307 | + * | |
| 3308 | + * @since 4.05 | |
| 3309 | + * @deprecated 6.16.3 | |
| 3310 | + * | |
| 3311 | + * @return void | |
| 3111 | 3312 | */ |
| 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' ); | |
| 3313 | + public static function add_form_style_tab_options() { | |
| 3314 | + _deprecated_function( __METHOD__, '6.16.3' ); | |
| 3315 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php'; | |
| 3138 | 3316 | } |
| 3139 | 3317 | } |