| @@ -4,28 +4,8 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFormsController { |
| 7 | 7 | |
| 8 | - /** | |
| 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 current tab. | |
| 11 | - * | |
| 12 | - * @since 6.2 | |
| 13 | - * | |
| 14 | - * @var array Keys are form IDs and values are 1. | |
| 15 | - */ | |
| 16 | - private static $redirected_in_new_tab = array(); | |
| 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 | - | |
| 28 | 8 | public static function menu() { |
| 29 | 9 | $menu_label = __( 'Forms', 'formidable' ); |
| 30 | 10 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 31 | 11 | $menu_label .= ' (Lite)'; |
| @@ -64,12 +44,12 @@ | ||
| 64 | 44 | */ |
| 65 | 45 | public static function logic_tip() { |
| 66 | 46 | $images_url = FrmAppHelper::plugin_url() . '/images/'; |
| 67 | 47 | $data_message = __( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', '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' ) . '"/>'; | |
| 48 | + $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' ) . '"/>'; | |
| 69 | 49 | 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">'; |
| 70 | 50 | esc_html_e( 'Conditional Logic', 'formidable' ); |
| 71 | - FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon', array( 'aria-hidden' => 'true' ) ); | |
| 51 | + FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon', array( 'aria-hidden' => 'true' ) ); | |
| 72 | 52 | echo '</a>'; |
| 73 | 53 | } |
| 74 | 54 | |
| 75 | 55 | /** |
| @@ -106,23 +86,15 @@ | ||
| 106 | 86 | * Create the default email action |
| 107 | 87 | * |
| 108 | 88 | * @since 2.02.11 |
| 109 | 89 | * |
| 110 | - * @param int|object $form | |
| 111 | - * @return void | |
| 90 | + * @param object|int $form | |
| 112 | 91 | */ |
| 113 | 92 | private static function create_default_email_action( $form ) { |
| 114 | 93 | FrmForm::maybe_get_form( $form ); |
| 115 | - if ( ! is_object( $form ) ) { | |
| 116 | - return; | |
| 117 | - } | |
| 118 | - | |
| 119 | 94 | $create_email = apply_filters( 'frm_create_default_email_action', true, $form ); |
| 120 | 95 | |
| 121 | 96 | if ( $create_email ) { |
| 122 | - /** | |
| 123 | - * @var FrmFormAction | |
| 124 | - */ | |
| 125 | 97 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
| 126 | 98 | $action_control->create( $form->id ); |
| 127 | 99 | } |
| 128 | 100 | } |
| @@ -131,16 +103,12 @@ | ||
| 131 | 103 | * Create the default On submit action |
| 132 | 104 | * |
| 133 | 105 | * @since 6.0.0 |
| 134 | 106 | * |
| 135 | - * @param int|object $form Form object or ID. | |
| 136 | - * @return void | |
| 107 | + * @param object|int $form Form object or ID. | |
| 137 | 108 | */ |
| 138 | 109 | private static function create_default_on_submit_action( $form ) { |
| 139 | 110 | FrmForm::maybe_get_form( $form ); |
| 140 | - if ( ! is_object( $form ) ) { | |
| 141 | - return; | |
| 142 | - } | |
| 143 | 111 | |
| 144 | 112 | /** |
| 145 | 113 | * Enable or disable the default On Submit action. |
| 146 | 114 | * |
| @@ -151,65 +119,21 @@ | ||
| 151 | 119 | */ |
| 152 | 120 | $create = apply_filters( 'frm_create_default_on_submit_action', true, $form ); |
| 153 | 121 | |
| 154 | 122 | if ( $create ) { |
| 155 | - /** | |
| 156 | - * @var FrmFormAction | |
| 157 | - */ | |
| 158 | 123 | $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug ); |
| 159 | 124 | $action_control->create( $form->id ); |
| 160 | 125 | } |
| 161 | 126 | } |
| 162 | 127 | |
| 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 | - */ | |
| 199 | 128 | public static function edit( $values = false ) { |
| 200 | 129 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 201 | 130 | |
| 202 | 131 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 203 | 132 | |
| 204 | - self::get_edit_vars( $id ); | |
| 133 | + return self::get_edit_vars( $id ); | |
| 205 | 134 | } |
| 206 | 135 | |
| 207 | - /** | |
| 208 | - * @param mixed $id | |
| 209 | - * @param string $message | |
| 210 | - * @return void | |
| 211 | - */ | |
| 212 | 136 | public static function settings( $id = false, $message = '' ) { |
| 213 | 137 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 214 | 138 | |
| 215 | 139 | if ( ! $id || ! is_numeric( $id ) ) { |
| @@ -217,34 +141,21 @@ | ||
| 217 | 141 | } |
| 218 | 142 | |
| 219 | 143 | FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id ); |
| 220 | 144 | |
| 221 | - self::get_settings_vars( $id, array(), $message ); | |
| 145 | + return self::get_settings_vars( $id, array(), $message ); | |
| 222 | 146 | } |
| 223 | 147 | |
| 224 | 148 | public static function update_settings() { |
| 225 | 149 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 226 | - $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); | |
| 227 | 150 | |
| 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 | - | |
| 239 | 151 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 240 | 152 | |
| 241 | - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 153 | + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 242 | 154 | $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 243 | 155 | |
| 244 | 156 | if ( count( $errors ) > 0 ) { |
| 245 | - self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); | |
| 246 | - return; | |
| 157 | + return self::get_settings_vars( $id, $errors, compact( 'warnings' ) ); | |
| 247 | 158 | } |
| 248 | 159 | |
| 249 | 160 | do_action( 'frm_before_update_form_settings', $id ); |
| 250 | 161 | |
| @@ -258,9 +169,9 @@ | ||
| 258 | 169 | } |
| 259 | 170 | |
| 260 | 171 | $message = __( 'Settings Successfully Updated', 'formidable' ); |
| 261 | 172 | |
| 262 | - self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); | |
| 173 | + return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) ); | |
| 263 | 174 | } |
| 264 | 175 | |
| 265 | 176 | /** |
| 266 | 177 | * @param int $form_id |
| @@ -270,11 +181,8 @@ | ||
| 270 | 181 | $form = FrmForm::getOne( $form_id ); |
| 271 | 182 | return ! empty( $form->options['antispam'] ); |
| 272 | 183 | } |
| 273 | 184 | |
| 274 | - /** | |
| 275 | - * @return void | |
| 276 | - */ | |
| 277 | 185 | public static function update( $values = array() ) { |
| 278 | 186 | if ( empty( $values ) ) { |
| 279 | 187 | $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 280 | 188 | } |
| @@ -292,86 +200,63 @@ | ||
| 292 | 200 | |
| 293 | 201 | $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 294 | 202 | |
| 295 | 203 | if ( count( $errors ) > 0 ) { |
| 296 | - self::get_edit_vars( $id, $errors ); | |
| 297 | - return; | |
| 298 | - } | |
| 204 | + return self::get_edit_vars( $id, $errors ); | |
| 205 | + } else { | |
| 206 | + FrmForm::update( $id, $values ); | |
| 207 | + $message = __( 'Form was successfully updated.', 'formidable' ); | |
| 299 | 208 | |
| 300 | - self::maybe_remove_draft_option_from_fields( $id ); | |
| 209 | + if ( self::is_too_long( $values ) ) { | |
| 210 | + $message .= '<br/> ' . sprintf( | |
| 211 | + /* translators: %1$s: Start link HTML, %2$s: end link HTML */ | |
| 212 | + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ), | |
| 213 | + '<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">', | |
| 214 | + '</a>' | |
| 215 | + ); | |
| 216 | + } | |
| 301 | 217 | |
| 302 | - FrmForm::update( $id, $values ); | |
| 303 | - $message = __( 'Form was successfully updated.', 'formidable' ); | |
| 218 | + if ( defined( 'DOING_AJAX' ) ) { | |
| 219 | + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 220 | + } | |
| 304 | 221 | |
| 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="' . esc_url( self::get_form_too_long_docs_url() ) . '" target="_blank" rel="noopener">', | |
| 310 | - '</a>' | |
| 311 | - ); | |
| 222 | + return self::get_edit_vars( $id, array(), $message ); | |
| 312 | 223 | } |
| 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 ); | |
| 319 | 224 | } |
| 320 | 225 | |
| 321 | 226 | /** |
| 322 | - * @since 6.25.1 | |
| 227 | + * Check if the value at the end of the form was included. | |
| 228 | + * If it's missing, it means other values at the end of the form | |
| 229 | + * were likely not saved either. | |
| 323 | 230 | * |
| 324 | - * @return string | |
| 231 | + * @since 3.06.01 | |
| 325 | 232 | */ |
| 326 | - private static function get_form_too_long_docs_url() { | |
| 327 | - $utm = array( | |
| 328 | - 'campaign' => 'builder', | |
| 329 | - 'content' => 'form-too-long', | |
| 330 | - ); | |
| 331 | - return FrmAppHelper::admin_upgrade_link( $utm, 'knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/' ); | |
| 233 | + private static function is_too_long( $values ) { | |
| 234 | + return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] ); | |
| 332 | 235 | } |
| 333 | 236 | |
| 334 | 237 | /** |
| 335 | - * Remove the draft flag from any new fields from this current session. | |
| 238 | + * Redirect to the url for creating from a template | |
| 239 | + * Also delete the current form | |
| 336 | 240 | * |
| 337 | - * @since 6.8 | |
| 338 | - * | |
| 339 | - * @param int $form_id | |
| 340 | - * @return void | |
| 241 | + * @since 2.0 | |
| 242 | + * @deprecated 3.06 | |
| 341 | 243 | */ |
| 342 | - private static function maybe_remove_draft_option_from_fields( $form_id ) { | |
| 343 | - $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' ); | |
| 344 | - if ( ! $draft_field_ids_csv ) { | |
| 345 | - // If the draft_fields input is empty there are no new fields in the session. | |
| 346 | - return; | |
| 347 | - } | |
| 244 | + public static function _create_from_template() { | |
| 245 | + _deprecated_function( __FUNCTION__, '3.06' ); | |
| 348 | 246 | |
| 349 | - $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' ); | |
| 350 | - if ( ! $draft_field_ids ) { | |
| 351 | - // Exit early if the draft fields input is invalid. It should be a CSV of integer values. | |
| 352 | - return; | |
| 353 | - } | |
| 247 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 248 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 354 | 249 | |
| 355 | - $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids ); | |
| 356 | - foreach ( $draft_field_rows as $row ) { | |
| 357 | - $row->field_options['draft'] = 0; | |
| 358 | - FrmField::update( $row->id, array( 'field_options' => $row->field_options ) ); | |
| 250 | + $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' ); | |
| 251 | + $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); | |
| 252 | + | |
| 253 | + if ( $current_form ) { | |
| 254 | + FrmForm::destroy( $current_form ); | |
| 359 | 255 | } |
| 360 | - } | |
| 361 | 256 | |
| 362 | - /** | |
| 363 | - * Check if the value at the end of the form was included. | |
| 364 | - * If it's missing, it means other values at the end of the form | |
| 365 | - * were likely not saved either. | |
| 366 | - * | |
| 367 | - * @since 3.06.01 | |
| 368 | - * | |
| 369 | - * @param array $values | |
| 370 | - * @return bool | |
| 371 | - */ | |
| 372 | - private static function is_too_long( $values ) { | |
| 373 | - return empty( $values['frm_end'] ); | |
| 257 | + echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) ); | |
| 258 | + wp_die(); | |
| 374 | 259 | } |
| 375 | 260 | |
| 376 | 261 | public static function duplicate() { |
| 377 | 262 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| @@ -387,11 +272,10 @@ | ||
| 387 | 272 | $url = admin_url( 'admin.php?page=formidable' ); |
| 388 | 273 | $message = 'form_duplicate_error'; |
| 389 | 274 | |
| 390 | 275 | if ( $form ) { |
| 391 | - $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : ''; | |
| 392 | - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template ); | |
| 393 | - $message = 'form_duplicated'; | |
| 276 | + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) ); | |
| 277 | + $message = 'form_duplicated'; | |
| 394 | 278 | } |
| 395 | 279 | |
| 396 | 280 | $url .= '&message=' . $message; |
| 397 | 281 | |
| @@ -399,42 +283,27 @@ | ||
| 399 | 283 | exit(); |
| 400 | 284 | } |
| 401 | 285 | |
| 402 | 286 | /** |
| 403 | - * @return string|null | |
| 287 | + * @return string | |
| 404 | 288 | */ |
| 405 | 289 | public static function page_preview() { |
| 406 | 290 | $params = FrmForm::list_page_params(); |
| 407 | - if ( ! $params['form'] || is_numeric( $params['form'] ) ) { | |
| 408 | - return null; | |
| 291 | + if ( ! $params['form'] ) { | |
| 292 | + return; | |
| 409 | 293 | } |
| 410 | 294 | |
| 411 | - self::maybe_block_preview( $params['form'] ); | |
| 412 | - | |
| 413 | 295 | $form = FrmForm::getOne( $params['form'] ); |
| 414 | - if ( ! $form ) { | |
| 415 | - return null; | |
| 296 | + if ( $form ) { | |
| 297 | + return self::show_form( $form->id, '', 'auto', 'auto' ); | |
| 416 | 298 | } |
| 417 | - | |
| 418 | - return self::show_form( $form->id, '', 'auto', 'auto' ); | |
| 419 | 299 | } |
| 420 | 300 | |
| 421 | 301 | /** |
| 422 | 302 | * @since 3.0 |
| 423 | - * | |
| 424 | - * @return void | |
| 425 | 303 | */ |
| 426 | 304 | public static function show_page_preview() { |
| 427 | - $preview = self::page_preview(); | |
| 428 | - if ( is_null( $preview ) ) { | |
| 429 | - wp_die( | |
| 430 | - '<h1>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</h1>', | |
| 431 | - '<p>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</p>', | |
| 432 | - 404 | |
| 433 | - ); | |
| 434 | - } | |
| 435 | - | |
| 436 | - echo $preview; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 305 | + echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 437 | 306 | } |
| 438 | 307 | |
| 439 | 308 | /** |
| 440 | 309 | * @return void |
| @@ -445,17 +314,8 @@ | ||
| 445 | 314 | |
| 446 | 315 | global $frm_vars; |
| 447 | 316 | $frm_vars['preview'] = true; |
| 448 | 317 | |
| 449 | - // print_emoji_styles is deprecated. | |
| 450 | - remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
| 451 | - | |
| 452 | - if ( FrmTestModeController::should_add_test_mode_container() ) { | |
| 453 | - do_action( 'frm_test_mode_init' ); | |
| 454 | - add_action( 'wp_enqueue_scripts', 'FrmTestModeController::register_and_enqueue_required_scripts' ); | |
| 455 | - add_filter( 'frm_filter_final_form', 'FrmTestModeController::maybe_add_test_mode_container', 99 ); | |
| 456 | - } | |
| 457 | - | |
| 458 | 318 | $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' ); |
| 459 | 319 | if ( $include_theme ) { |
| 460 | 320 | self::set_preview_query(); |
| 461 | 321 | self::load_theme_preview(); |
| @@ -490,13 +350,8 @@ | ||
| 490 | 350 | return; |
| 491 | 351 | } |
| 492 | 352 | |
| 493 | 353 | $random_page = reset( $random_page ); |
| 494 | - if ( ! is_a( $random_page, 'WP_Post' ) ) { | |
| 495 | - // The return type can also be int. | |
| 496 | - return; | |
| 497 | - } | |
| 498 | - | |
| 499 | 354 | query_posts( |
| 500 | 355 | array( |
| 501 | 356 | 'post_type' => 'page', |
| 502 | 357 | 'page_id' => $random_page->ID, |
| @@ -512,9 +367,9 @@ | ||
| 512 | 367 | * Set the WP $post global object. Used for in-theme preview when defining a page. |
| 513 | 368 | * |
| 514 | 369 | * @since 5.5.2 |
| 515 | 370 | * |
| 516 | - * @param WP_Post $page The page object. | |
| 371 | + * @param WP_Post $post | |
| 517 | 372 | * @return void |
| 518 | 373 | */ |
| 519 | 374 | private static function set_post_global( $page ) { |
| 520 | 375 | global $post; |
| @@ -522,10 +377,8 @@ | ||
| 522 | 377 | } |
| 523 | 378 | |
| 524 | 379 | /** |
| 525 | 380 | * @since 3.0 |
| 526 | - * | |
| 527 | - * @return void | |
| 528 | 381 | */ |
| 529 | 382 | private static function load_theme_preview() { |
| 530 | 383 | add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 ); |
| 531 | 384 | add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 ); |
| @@ -534,39 +387,20 @@ | ||
| 534 | 387 | add_filter( 'is_active_sidebar', '__return_false' ); |
| 535 | 388 | FrmStylesController::enqueue_css( 'enqueue', true ); |
| 536 | 389 | |
| 537 | 390 | if ( false === get_template_part( 'page' ) ) { |
| 538 | - if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { | |
| 539 | - add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' ); | |
| 540 | - } | |
| 541 | 391 | self::fallback_when_page_template_part_is_not_supported_by_theme(); |
| 542 | 392 | } |
| 543 | 393 | } |
| 544 | 394 | |
| 545 | 395 | /** |
| 546 | - * Add padding to the body for block themes. | |
| 547 | - * | |
| 548 | - * @since 6.5.2 | |
| 549 | - * | |
| 550 | - * @param array $classes The body classes list. | |
| 551 | - * @return array | |
| 552 | - */ | |
| 553 | - public static function preview_block_theme_body_classnames( $classes ) { | |
| 554 | - $classes[] = 'has-global-padding'; | |
| 555 | - return $classes; | |
| 556 | - } | |
| 557 | - | |
| 558 | - /** | |
| 559 | 396 | * Not every theme supports get_template_part( 'page' ). |
| 560 | 397 | * When this is not supported, false is returned, and we can handle a fallback. |
| 561 | - * | |
| 562 | - * @return void | |
| 563 | 398 | */ |
| 564 | 399 | private static function fallback_when_page_template_part_is_not_supported_by_theme() { |
| 565 | 400 | if ( have_posts() ) { |
| 566 | 401 | the_post(); |
| 567 | - self::get_template( 'header' ); | |
| 568 | - | |
| 402 | + get_header( '' ); | |
| 569 | 403 | // add some generic class names to the container to add some natural padding to the content. |
| 570 | 404 | // .entry-content catches the WordPress TwentyTwenty theme. |
| 571 | 405 | // .container catches Customizr content. |
| 572 | 406 | echo '<div class="container entry-content">'; |
| @@ -571,58 +405,13 @@ | ||
| 571 | 405 | // .container catches Customizr content. |
| 572 | 406 | echo '<div class="container entry-content">'; |
| 573 | 407 | the_content(); |
| 574 | 408 | echo '</div>'; |
| 575 | - | |
| 576 | - // Prevent extra unexpected forms in the footer. | |
| 577 | - // For some reason this happens in the Twenty Twenty Five theme. | |
| 578 | - add_filter( 'frm_filter_final_form', '__return_empty_string' ); | |
| 579 | - | |
| 580 | - self::get_template( 'footer' ); | |
| 409 | + get_footer(); | |
| 581 | 410 | } |
| 582 | 411 | } |
| 583 | 412 | |
| 584 | 413 | /** |
| 585 | - * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call | |
| 586 | - * and renders required html fragments calling required functions. | |
| 587 | - * | |
| 588 | - * @since 6.7.1 | |
| 589 | - * @param string $template | |
| 590 | - * @return void | |
| 591 | - */ | |
| 592 | - private static function get_template( $template ) { | |
| 593 | - if ( self::should_try_getting_template( $template ) ) { | |
| 594 | - call_user_func( 'get_' . $template ); | |
| 595 | - return; | |
| 596 | - } | |
| 597 | - | |
| 598 | - if ( 'header' === $template ) { | |
| 599 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php'; | |
| 600 | - return; | |
| 601 | - } | |
| 602 | - | |
| 603 | - if ( 'footer' === $template ) { | |
| 604 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php'; | |
| 605 | - } | |
| 606 | - } | |
| 607 | - | |
| 608 | - /** | |
| 609 | - * Returns true if calling a template function doesn't trigger deprecation warnings. | |
| 610 | - * | |
| 611 | - * @since 6.7.1 | |
| 612 | - * @param string $template | |
| 613 | - * @return bool | |
| 614 | - */ | |
| 615 | - private static function should_try_getting_template( $template ) { | |
| 616 | - $stylesheet_path = get_stylesheet_directory(); | |
| 617 | - $template_path = get_template_directory(); | |
| 618 | - $is_child_theme = $stylesheet_path !== $template_path; | |
| 619 | - $template_name = $template . '.php'; | |
| 620 | - | |
| 621 | - return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name ); | |
| 622 | - } | |
| 623 | - | |
| 624 | - /** | |
| 625 | 414 | * Set the page title for the theme preview page |
| 626 | 415 | * |
| 627 | 416 | * @since 3.0 |
| 628 | 417 | */ |
| @@ -634,14 +423,11 @@ | ||
| 634 | 423 | return $title; |
| 635 | 424 | } |
| 636 | 425 | |
| 637 | 426 | /** |
| 638 | - * Set the page title for the theme preview page. | |
| 427 | + * Set the page title for the theme preview page | |
| 639 | 428 | * |
| 640 | 429 | * @since 3.0 |
| 641 | - * | |
| 642 | - * @param string $title | |
| 643 | - * @return string | |
| 644 | 430 | */ |
| 645 | 431 | public static function preview_title( $title ) { |
| 646 | 432 | return __( 'Form Preview', 'formidable' ); |
| 647 | 433 | } |
| @@ -646,20 +432,15 @@ | ||
| 646 | 432 | return __( 'Form Preview', 'formidable' ); |
| 647 | 433 | } |
| 648 | 434 | |
| 649 | 435 | /** |
| 650 | - * Set the page content for the theme preview page. | |
| 436 | + * Set the page content for the theme preview page | |
| 651 | 437 | * |
| 652 | 438 | * @since 3.0 |
| 653 | - * | |
| 654 | - * @param string $content | |
| 655 | - * @return string | |
| 656 | 439 | */ |
| 657 | 440 | public static function preview_content( $content ) { |
| 658 | 441 | if ( in_the_loop() ) { |
| 659 | - self::show_page_preview(); | |
| 660 | - // Clear the content for the page we're using. | |
| 661 | - $content = ''; | |
| 442 | + $content = self::show_page_preview(); | |
| 662 | 443 | } |
| 663 | 444 | |
| 664 | 445 | return $content; |
| 665 | 446 | } |
| @@ -667,88 +448,23 @@ | ||
| 667 | 448 | /** |
| 668 | 449 | * @since 3.0 |
| 669 | 450 | */ |
| 670 | 451 | private static function load_direct_preview() { |
| 452 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); | |
| 453 | + | |
| 671 | 454 | $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' ); |
| 672 | 455 | if ( $key == '' ) { |
| 673 | 456 | $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' ); |
| 674 | 457 | } |
| 675 | 458 | |
| 676 | - if ( ! $key ) { | |
| 677 | - $error = __( 'Form key is missing', 'formidable' ); | |
| 678 | - wp_die( | |
| 679 | - '<h1>' . esc_html( $error ) . '</h1>', | |
| 680 | - '<p>' . esc_html( $error ) . '</p>', | |
| 681 | - 404 | |
| 682 | - ); | |
| 683 | - } | |
| 684 | - | |
| 685 | - self::maybe_block_preview( $key ); | |
| 686 | - | |
| 687 | 459 | $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 ); |
| 688 | - if ( ! $form ) { | |
| 689 | - $error = __( 'Form does not exist', 'formidable' ); | |
| 690 | - wp_die( | |
| 691 | - '<h1>' . esc_html( $error ) . '</h1>', | |
| 692 | - '<p>' . esc_html( $error ) . '</p>', | |
| 693 | - 404 | |
| 694 | - ); | |
| 460 | + if ( empty( $form ) ) { | |
| 461 | + $form = FrmForm::getAll( array(), '', 1 ); | |
| 695 | 462 | } |
| 696 | 463 | |
| 697 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); | |
| 698 | - | |
| 699 | - self::fix_deprecated_null_param_warning(); | |
| 700 | - | |
| 701 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php'; | |
| 464 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' ); | |
| 702 | 465 | } |
| 703 | 466 | |
| 704 | - /** | |
| 705 | - * Block the form preview for the contact form by default if the user cannot view forms. | |
| 706 | - * This is to prevent the contact form being exploited. | |
| 707 | - * Since this form is added by default and every site uses the same key, it is too easy | |
| 708 | - * to guess this form. | |
| 709 | - * | |
| 710 | - * @since 6.20 | |
| 711 | - * | |
| 712 | - * @param string $form_key Form key. | |
| 713 | - * @return void | |
| 714 | - */ | |
| 715 | - public static function maybe_block_preview( $form_key ) { | |
| 716 | - if ( FrmFormsHelper::should_block_preview( $form_key ) ) { | |
| 717 | - $error = __( 'You do not have permission to view this form', 'formidable' ); | |
| 718 | - wp_die( | |
| 719 | - '<h1>' . esc_html( $error ) . '</h1>', | |
| 720 | - '<p>' . esc_html( $error ) . '</p>', | |
| 721 | - 403 | |
| 722 | - ); | |
| 723 | - } | |
| 724 | - } | |
| 725 | - | |
| 726 | - /** | |
| 727 | - * Some themes have a null $src value. | |
| 728 | - * This function adds a filter to ensure that $src is not null. | |
| 729 | - * WP will call str_starts_with with the null value triggering a deprecated message otherwise. | |
| 730 | - * | |
| 731 | - * @since 6.10 | |
| 732 | - * | |
| 733 | - * @return void | |
| 734 | - */ | |
| 735 | - private static function fix_deprecated_null_param_warning() { | |
| 736 | - add_filter( | |
| 737 | - 'script_loader_src', | |
| 738 | - /** | |
| 739 | - * @param string|null $src | |
| 740 | - * @return string | |
| 741 | - */ | |
| 742 | - function ( $src ) { | |
| 743 | - if ( is_null( $src ) ) { | |
| 744 | - $src = ''; | |
| 745 | - } | |
| 746 | - return $src; | |
| 747 | - } | |
| 748 | - ); | |
| 749 | - } | |
| 750 | - | |
| 751 | 467 | public static function untrash() { |
| 752 | 468 | self::change_form_status( 'untrash' ); |
| 753 | 469 | } |
| 754 | 470 | |
| @@ -811,14 +527,14 @@ | ||
| 811 | 527 | FrmAppHelper::permission_check( $available_status[ $status ]['permission'] ); |
| 812 | 528 | |
| 813 | 529 | $params = FrmForm::list_page_params(); |
| 814 | 530 | |
| 815 | - // Check nonce url. | |
| 531 | + //check nonce url | |
| 816 | 532 | check_admin_referer( $status . '_form_' . $params['id'] ); |
| 817 | 533 | |
| 818 | 534 | $count = 0; |
| 819 | 535 | if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) { |
| 820 | - ++$count; | |
| 536 | + $count ++; | |
| 821 | 537 | } |
| 822 | 538 | |
| 823 | 539 | $form_type = FrmAppHelper::get_simple_request( |
| 824 | 540 | array( |
| @@ -830,9 +546,9 @@ | ||
| 830 | 546 | /* translators: %1$s: Number of forms */ |
| 831 | 547 | $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count ); |
| 832 | 548 | |
| 833 | 549 | /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */ |
| 834 | - $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>' ); | |
| 550 | + $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>' ); | |
| 835 | 551 | |
| 836 | 552 | $message = $available_status[ $status ]['message']; |
| 837 | 553 | |
| 838 | 554 | self::display_forms_list( $params, $message ); |
| @@ -837,12 +553,8 @@ | ||
| 837 | 553 | |
| 838 | 554 | self::display_forms_list( $params, $message ); |
| 839 | 555 | } |
| 840 | 556 | |
| 841 | - /** | |
| 842 | - * @param array $ids | |
| 843 | - * @return string | |
| 844 | - */ | |
| 845 | 557 | public static function bulk_trash( $ids ) { |
| 846 | 558 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 847 | 559 | |
| 848 | 560 | $count = 0; |
| @@ -847,16 +559,12 @@ | ||
| 847 | 559 | |
| 848 | 560 | $count = 0; |
| 849 | 561 | foreach ( $ids as $id ) { |
| 850 | 562 | if ( FrmForm::trash( $id ) ) { |
| 851 | - ++$count; | |
| 563 | + $count ++; | |
| 852 | 564 | } |
| 853 | 565 | } |
| 854 | 566 | |
| 855 | - if ( ! $count ) { | |
| 856 | - return ''; | |
| 857 | - } | |
| 858 | - | |
| 859 | 567 | $current_page = FrmAppHelper::get_simple_request( |
| 860 | 568 | array( |
| 861 | 569 | 'param' => 'form_type', |
| 862 | 570 | 'type' => 'request', |
| @@ -882,9 +590,9 @@ | ||
| 882 | 590 | check_admin_referer( 'destroy_form_' . $params['id'] ); |
| 883 | 591 | |
| 884 | 592 | $count = 0; |
| 885 | 593 | if ( FrmForm::destroy( $params['id'] ) ) { |
| 886 | - ++$count; | |
| 594 | + $count ++; | |
| 887 | 595 | } |
| 888 | 596 | |
| 889 | 597 | /* translators: %1$s: Number of forms */ |
| 890 | 598 | $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count ); |
| @@ -891,12 +599,8 @@ | ||
| 891 | 599 | |
| 892 | 600 | self::display_forms_list( $params, $message ); |
| 893 | 601 | } |
| 894 | 602 | |
| 895 | - /** | |
| 896 | - * @param array $ids | |
| 897 | - * @return string | |
| 898 | - */ | |
| 899 | 603 | public static function bulk_destroy( $ids ) { |
| 900 | 604 | FrmAppHelper::permission_check( 'frm_delete_forms' ); |
| 901 | 605 | |
| 902 | 606 | $count = 0; |
| @@ -902,24 +606,19 @@ | ||
| 902 | 606 | $count = 0; |
| 903 | 607 | foreach ( $ids as $id ) { |
| 904 | 608 | $d = FrmForm::destroy( $id ); |
| 905 | 609 | if ( $d ) { |
| 906 | - ++$count; | |
| 610 | + $count ++; | |
| 907 | 611 | } |
| 908 | 612 | } |
| 909 | 613 | |
| 910 | - if ( $count ) { | |
| 911 | - /* translators: %1$s: Number of forms */ | |
| 912 | - return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 913 | - } | |
| 614 | + /* translators: %1$s: Number of forms */ | |
| 615 | + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 914 | 616 | |
| 915 | - return ''; | |
| 617 | + return $message; | |
| 916 | 618 | } |
| 917 | 619 | |
| 918 | - /** | |
| 919 | - * @since 6.7.1 Function went from private to public. | |
| 920 | - */ | |
| 921 | - public static function delete_all() { | |
| 620 | + private static function delete_all() { | |
| 922 | 621 | // Check nonce url. |
| 923 | 622 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
| 924 | 623 | if ( $permission_error !== false ) { |
| 925 | 624 | self::display_forms_list( array(), '', array( $permission_error ) ); |
| @@ -926,15 +625,14 @@ | ||
| 926 | 625 | |
| 927 | 626 | return; |
| 928 | 627 | } |
| 929 | 628 | |
| 930 | - $count = FrmForm::scheduled_delete( time() ); | |
| 931 | - $url = remove_query_arg( array( 'delete_all' ) ); | |
| 629 | + $count = FrmForm::scheduled_delete( time() ); | |
| 932 | 630 | |
| 933 | - $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count; | |
| 631 | + /* translators: %1$s: Number of forms */ | |
| 632 | + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 934 | 633 | |
| 935 | - wp_safe_redirect( $url ); | |
| 936 | - die(); | |
| 634 | + self::display_forms_list( array(), $message ); | |
| 937 | 635 | } |
| 938 | 636 | |
| 939 | 637 | /** |
| 940 | 638 | * Create a new form from the modal. |
| @@ -947,9 +645,9 @@ | ||
| 947 | 645 | |
| 948 | 646 | $new_values = self::get_modal_values(); |
| 949 | 647 | $new_values['form_key'] = $new_values['name']; |
| 950 | 648 | $new_values['options'] = array( |
| 951 | - 'antispam' => 1, | |
| 649 | + 'antispam' => 1, | |
| 952 | 650 | 'on_submit_migrated' => 1, |
| 953 | 651 | ); |
| 954 | 652 | |
| 955 | 653 | /** |
| @@ -968,14 +666,13 @@ | ||
| 968 | 666 | * @param int $form_id |
| 969 | 667 | */ |
| 970 | 668 | do_action( 'frm_build_new_form', $form_id ); |
| 971 | 669 | |
| 972 | - self::create_submit_button_field( $form_id ); | |
| 973 | 670 | self::create_default_on_submit_action( $form_id ); |
| 974 | 671 | self::create_default_email_action( $form_id ); |
| 975 | 672 | |
| 976 | 673 | $response = array( |
| 977 | - 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 674 | + 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 978 | 675 | ); |
| 979 | 676 | |
| 980 | 677 | echo wp_json_encode( $response ); |
| 981 | 678 | wp_die(); |
| @@ -981,15 +678,46 @@ | ||
| 981 | 678 | wp_die(); |
| 982 | 679 | } |
| 983 | 680 | |
| 984 | 681 | /** |
| 682 | + * Create a custom template from a form | |
| 683 | + * | |
| 684 | + * @since 3.06 | |
| 685 | + */ | |
| 686 | + public static function build_template() { | |
| 687 | + global $wpdb; | |
| 688 | + | |
| 689 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 690 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 691 | + | |
| 692 | + $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' ); | |
| 693 | + $new_form_id = FrmForm::duplicate( $form_id, 1, true ); | |
| 694 | + if ( ! $new_form_id ) { | |
| 695 | + $response = array( | |
| 696 | + 'message' => __( 'There was an error creating a template.', 'formidable' ), | |
| 697 | + ); | |
| 698 | + } else { | |
| 699 | + $new_values = self::get_modal_values(); | |
| 700 | + $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) ); | |
| 701 | + if ( $query_results ) { | |
| 702 | + FrmForm::clear_form_cache(); | |
| 703 | + } | |
| 704 | + | |
| 705 | + $response = array( | |
| 706 | + 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(), | |
| 707 | + ); | |
| 708 | + } | |
| 709 | + | |
| 710 | + echo wp_json_encode( $response ); | |
| 711 | + wp_die(); | |
| 712 | + } | |
| 713 | + | |
| 714 | + /** | |
| 985 | 715 | * Before creating a new form, get the name and description from the modal. |
| 986 | 716 | * |
| 987 | 717 | * @since 4.0 |
| 988 | - * | |
| 989 | - * @return array<string,string> | |
| 990 | 718 | */ |
| 991 | - public static function get_modal_values() { | |
| 719 | + private static function get_modal_values() { | |
| 992 | 720 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 993 | 721 | $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 994 | 722 | |
| 995 | 723 | return array( |
| @@ -1002,24 +730,17 @@ | ||
| 1002 | 730 | * Inserts Formidable button |
| 1003 | 731 | * Hook exists since 2.5.0 |
| 1004 | 732 | * |
| 1005 | 733 | * @since 2.0.15 |
| 1006 | - * | |
| 1007 | - * @return void | |
| 1008 | 734 | */ |
| 1009 | 735 | public static function insert_form_button() { |
| 1010 | 736 | if ( current_user_can( 'frm_view_forms' ) ) { |
| 1011 | - // Store the result in memory and re-use it when this function is called multiple times. | |
| 1012 | - // This helps speed up the form builder when there are a lot of HTML fields, where this | |
| 1013 | - // button is inserted once per HTML field. | |
| 1014 | - // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally. | |
| 1015 | - if ( ! isset( self::$formidable_tinymce_button ) ) { | |
| 1016 | - FrmAppHelper::load_admin_wide_js(); | |
| 1017 | - $menu_name = FrmAppHelper::get_menu_name(); | |
| 1018 | - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() ); | |
| 1019 | - 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>'; | |
| 1020 | - } | |
| 1021 | - echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 737 | + FrmAppHelper::load_admin_wide_js(); | |
| 738 | + $menu_name = FrmAppHelper::get_menu_name(); | |
| 739 | + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() ); | |
| 740 | + 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' ) . '">' . | |
| 741 | + FrmAppHelper::kses( $icon, 'all' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 742 | + ' ' . esc_html( $menu_name ) . '</a>'; | |
| 1022 | 743 | } |
| 1023 | 744 | } |
| 1024 | 745 | |
| 1025 | 746 | /** |
| @@ -1107,9 +828,9 @@ | ||
| 1107 | 828 | $form_id = $opts['form_id']; |
| 1108 | 829 | unset( $opts['form_id'] ); |
| 1109 | 830 | } |
| 1110 | 831 | |
| 1111 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php'; | |
| 832 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' ); | |
| 1112 | 833 | |
| 1113 | 834 | echo '</div>'; |
| 1114 | 835 | |
| 1115 | 836 | wp_die(); |
| @@ -1149,14 +870,8 @@ | ||
| 1149 | 870 | wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) ); |
| 1150 | 871 | die(); |
| 1151 | 872 | } |
| 1152 | 873 | |
| 1153 | - $inbox = new FrmInbox(); | |
| 1154 | - $error = $inbox->check_for_error(); | |
| 1155 | - if ( $error ) { | |
| 1156 | - $show_messages = array( $error['subject'] . '. ' . $error['message'] ); | |
| 1157 | - } | |
| 1158 | - | |
| 1159 | 874 | require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php'; |
| 1160 | 875 | } |
| 1161 | 876 | |
| 1162 | 877 | /** |
| @@ -1163,17 +878,15 @@ | ||
| 1163 | 878 | * @param array<string,string> $columns |
| 1164 | 879 | * @return array<string,string> |
| 1165 | 880 | */ |
| 1166 | 881 | public static function get_columns( $columns ) { |
| 1167 | - $columns['cb'] = '<input type="checkbox" />'; | |
| 1168 | - $columns['name'] = esc_html__( 'Form Title', 'formidable' ); | |
| 1169 | - $columns['entries'] = esc_html__( 'Entries', 'formidable' ); | |
| 1170 | - $columns['id'] = 'ID'; | |
| 1171 | - $columns['form_key'] = esc_html__( 'Key', 'formidable' ); | |
| 1172 | - if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) ) { | |
| 1173 | - $columns['shortcode'] = esc_html__( 'Actions', 'formidable' ); | |
| 1174 | - } | |
| 1175 | - $columns['created_at'] = esc_html__( 'Date', 'formidable' ); | |
| 882 | + $columns['cb'] = '<input type="checkbox" />'; | |
| 883 | + $columns['name'] = __( 'Form Title', 'formidable' ); | |
| 884 | + $columns['entries'] = __( 'Entries', 'formidable' ); | |
| 885 | + $columns['id'] = 'ID'; | |
| 886 | + $columns['form_key'] = __( 'Key', 'formidable' ); | |
| 887 | + $columns['shortcode'] = __( 'Actions', 'formidable' ); | |
| 888 | + $columns['created_at'] = __( 'Date', 'formidable' ); | |
| 1176 | 889 | |
| 1177 | 890 | add_screen_option( |
| 1178 | 891 | 'per_page', |
| 1179 | 892 | array( |
| @@ -1185,11 +898,8 @@ | ||
| 1185 | 898 | |
| 1186 | 899 | return $columns; |
| 1187 | 900 | } |
| 1188 | 901 | |
| 1189 | - /** | |
| 1190 | - * @return array<string,string> | |
| 1191 | - */ | |
| 1192 | 902 | public static function get_sortable_columns() { |
| 1193 | 903 | return array( |
| 1194 | 904 | 'id' => 'id', |
| 1195 | 905 | 'name' => 'name', |
| @@ -1223,9 +933,9 @@ | ||
| 1223 | 933 | return $hidden_columns; |
| 1224 | 934 | } |
| 1225 | 935 | |
| 1226 | 936 | public static function save_per_page( $save, $option, $value ) { |
| 1227 | - if ( $option === 'formidable_page_formidable_per_page' ) { | |
| 937 | + if ( $option == 'formidable_page_formidable_per_page' ) { | |
| 1228 | 938 | $save = (int) $value; |
| 1229 | 939 | } |
| 1230 | 940 | |
| 1231 | 941 | return $save; |
| @@ -1231,49 +941,146 @@ | ||
| 1231 | 941 | return $save; |
| 1232 | 942 | } |
| 1233 | 943 | |
| 1234 | 944 | /** |
| 1235 | - * @param int|string $id | |
| 1236 | - * @param array $errors | |
| 1237 | - * @param string $message | |
| 1238 | - * @param bool $create_link | |
| 945 | + * @return bool | |
| 946 | + */ | |
| 947 | + public static function expired() { | |
| 948 | + global $frm_expired; | |
| 949 | + return $frm_expired; | |
| 950 | + } | |
| 951 | + | |
| 952 | + /** | |
| 953 | + * Get data from api before rendering it so that we can flag the modal as expired | |
| 954 | + * | |
| 1239 | 955 | * @return void |
| 1240 | 956 | */ |
| 1241 | - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1242 | - global $frm_vars; | |
| 957 | + public static function before_list_templates() { | |
| 958 | + global $frm_templates; | |
| 959 | + global $frm_expired; | |
| 960 | + global $frm_license_type; | |
| 1243 | 961 | |
| 1244 | - $form = FrmForm::getOne( $id ); | |
| 1245 | - $error_args = array( | |
| 1246 | - 'title' => __( 'You can\'t edit the form', 'formidable' ), | |
| 1247 | - 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ), | |
| 1248 | - 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 1249 | - 'continue_url' => add_query_arg( | |
| 1250 | - array( | |
| 1251 | - 'page' => 'formidable', | |
| 1252 | - ) | |
| 1253 | - ), | |
| 962 | + $api = new FrmFormTemplateApi(); | |
| 963 | + $frm_templates = $api->get_api_info(); | |
| 964 | + $expired = false; | |
| 965 | + $license_type = ''; | |
| 966 | + if ( isset( $frm_templates['error'] ) ) { | |
| 967 | + $error = $frm_templates['error']['message']; | |
| 968 | + $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error ); | |
| 969 | + $expired = 'expired' === $frm_templates['error']['code']; | |
| 970 | + $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : ''; | |
| 971 | + unset( $frm_templates['error'] ); | |
| 972 | + } | |
| 973 | + | |
| 974 | + $frm_expired = $expired; | |
| 975 | + $frm_license_type = $license_type; | |
| 976 | + } | |
| 977 | + | |
| 978 | + /** | |
| 979 | + * @return void | |
| 980 | + */ | |
| 981 | + public static function list_templates() { | |
| 982 | + global $frm_templates; | |
| 983 | + global $frm_license_type; | |
| 984 | + | |
| 985 | + $templates = $frm_templates; | |
| 986 | + $custom_templates = array(); | |
| 987 | + $templates_by_category = array(); | |
| 988 | + | |
| 989 | + self::add_user_templates( $custom_templates ); | |
| 990 | + | |
| 991 | + foreach ( $templates as $template ) { | |
| 992 | + if ( ! isset( $template['categories'] ) ) { | |
| 993 | + continue; | |
| 994 | + } | |
| 995 | + | |
| 996 | + foreach ( $template['categories'] as $category ) { | |
| 997 | + if ( ! isset( $templates_by_category[ $category ] ) ) { | |
| 998 | + $templates_by_category[ $category ] = array(); | |
| 999 | + } | |
| 1000 | + | |
| 1001 | + $templates_by_category[ $category ][] = $template; | |
| 1002 | + } | |
| 1003 | + } | |
| 1004 | + unset( $template ); | |
| 1005 | + | |
| 1006 | + // Subcategories that are included elsewhere. | |
| 1007 | + $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' ); | |
| 1008 | + | |
| 1009 | + $categories = array_keys( $templates_by_category ); | |
| 1010 | + $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() ); | |
| 1011 | + $categories = array_diff( $categories, $redundant_cats ); | |
| 1012 | + sort( $categories ); | |
| 1013 | + | |
| 1014 | + array_walk( | |
| 1015 | + $custom_templates, | |
| 1016 | + function( &$template ) { | |
| 1017 | + $template['custom'] = true; | |
| 1018 | + } | |
| 1254 | 1019 | ); |
| 1255 | - if ( ! $form ) { | |
| 1256 | - FrmAppController::show_error_modal( $error_args ); | |
| 1257 | - return; | |
| 1020 | + | |
| 1021 | + $my_templates_translation = __( 'My Templates', 'formidable' ); | |
| 1022 | + $categories = array_merge( array( $my_templates_translation ), $categories ); | |
| 1023 | + $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' ); | |
| 1024 | + $license_type = $frm_license_type; | |
| 1025 | + $args = compact( 'pricing', 'license_type' ); | |
| 1026 | + $where = apply_filters( 'frm_forms_dropdown', array(), '' ); | |
| 1027 | + $forms = FrmForm::get_published_forms( $where ); | |
| 1028 | + $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/'; | |
| 1029 | + | |
| 1030 | + $templates_by_category[ $my_templates_translation ] = $custom_templates; | |
| 1031 | + | |
| 1032 | + unset( $pricing, $license_type, $where ); | |
| 1033 | + wp_enqueue_script( 'accordion' ); // register accordion for template groups | |
| 1034 | + require $view_path . 'list-templates.php'; | |
| 1035 | + } | |
| 1036 | + | |
| 1037 | + /** | |
| 1038 | + * @since 4.03.01 | |
| 1039 | + */ | |
| 1040 | + private static function get_template_categories( $templates ) { | |
| 1041 | + $categories = array(); | |
| 1042 | + foreach ( $templates as $template ) { | |
| 1043 | + if ( isset( $template['categories'] ) ) { | |
| 1044 | + $categories = array_merge( $categories, $template['categories'] ); | |
| 1045 | + } | |
| 1258 | 1046 | } |
| 1047 | + $exclude_cats = FrmFormsHelper::ignore_template_categories(); | |
| 1048 | + $categories = array_unique( $categories ); | |
| 1049 | + $categories = array_diff( $categories, $exclude_cats ); | |
| 1050 | + sort( $categories ); | |
| 1051 | + return $categories; | |
| 1052 | + } | |
| 1259 | 1053 | |
| 1260 | - if ( 'trash' === $form->status ) { | |
| 1261 | - $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' ); | |
| 1262 | - $error_args['continue_url'] = add_query_arg( | |
| 1263 | - array( | |
| 1264 | - 'page' => 'formidable', | |
| 1265 | - '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ), | |
| 1266 | - 'form_type' => 'trash', | |
| 1267 | - 'frm_action' => 'untrash', | |
| 1268 | - 'id' => $id, | |
| 1269 | - ) | |
| 1054 | + private static function add_user_templates( &$templates ) { | |
| 1055 | + $user_templates = array( | |
| 1056 | + 'is_template' => 1, | |
| 1057 | + 'default_template' => 0, | |
| 1058 | + ); | |
| 1059 | + $user_templates = FrmForm::getAll( $user_templates, 'name' ); | |
| 1060 | + foreach ( $user_templates as $template ) { | |
| 1061 | + $template = array( | |
| 1062 | + 'id' => $template->id, | |
| 1063 | + 'name' => $template->name, | |
| 1064 | + 'key' => $template->form_key, | |
| 1065 | + 'description' => $template->description, | |
| 1066 | + 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ), | |
| 1067 | + 'released' => $template->created_at, | |
| 1068 | + 'installed' => 1, | |
| 1270 | 1069 | ); |
| 1271 | - $error_args['continue_text'] = __( 'Restore form', 'formidable' ); | |
| 1272 | - FrmAppController::show_error_modal( $error_args ); | |
| 1273 | - return; | |
| 1070 | + array_unshift( $templates, $template ); | |
| 1071 | + unset( $template ); | |
| 1274 | 1072 | } |
| 1073 | + } | |
| 1275 | 1074 | |
| 1075 | + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1076 | + global $frm_vars; | |
| 1077 | + | |
| 1078 | + $form = FrmForm::getOne( $id ); | |
| 1079 | + if ( ! $form ) { | |
| 1080 | + wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) ); | |
| 1081 | + } | |
| 1082 | + | |
| 1276 | 1083 | if ( $form->parent_form_id ) { |
| 1277 | 1084 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1278 | 1085 | 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>' ) ); |
| 1279 | 1086 | } |
| @@ -1284,9 +1091,8 @@ | ||
| 1284 | 1091 | |
| 1285 | 1092 | // Automatically add end section fields if they don't exist (2.0 migration). |
| 1286 | 1093 | $reset_fields = false; |
| 1287 | 1094 | FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields ); |
| 1288 | - FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields ); | |
| 1289 | 1095 | |
| 1290 | 1096 | if ( $reset_fields ) { |
| 1291 | 1097 | $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' ); |
| 1292 | 1098 | } |
| @@ -1312,21 +1118,18 @@ | ||
| 1312 | 1118 | } |
| 1313 | 1119 | |
| 1314 | 1120 | self::maybe_update_form_builder_message( $message ); |
| 1315 | 1121 | |
| 1316 | - $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] ); | |
| 1122 | + $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' ); | |
| 1123 | + $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] ); | |
| 1317 | 1124 | |
| 1318 | 1125 | if ( defined( 'DOING_AJAX' ) ) { |
| 1319 | 1126 | wp_die(); |
| 1127 | + } else { | |
| 1128 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); | |
| 1320 | 1129 | } |
| 1321 | - | |
| 1322 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php'; | |
| 1323 | 1130 | } |
| 1324 | 1131 | |
| 1325 | - /** | |
| 1326 | - * @param array $fields | |
| 1327 | - * @return array | |
| 1328 | - */ | |
| 1329 | 1132 | public static function update_form_builder_fields( $fields, $form ) { |
| 1330 | 1133 | foreach ( $fields as $field ) { |
| 1331 | 1134 | $field->do_not_include_icons = true; |
| 1332 | 1135 | } |
| @@ -1338,21 +1141,13 @@ | ||
| 1338 | 1141 | $message = __( 'Form was Successfully Copied', 'formidable' ); |
| 1339 | 1142 | } |
| 1340 | 1143 | } |
| 1341 | 1144 | |
| 1342 | - /** | |
| 1343 | - * @param int|string $id | |
| 1344 | - * @param array $errors | |
| 1345 | - * @param array|string $args | |
| 1346 | - * @return void | |
| 1347 | - */ | |
| 1348 | 1145 | public static function get_settings_vars( $id, $errors = array(), $args = array() ) { |
| 1349 | 1146 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 1350 | 1147 | |
| 1351 | 1148 | global $frm_vars; |
| 1352 | 1149 | |
| 1353 | - self::maybe_print_media_templates(); | |
| 1354 | - | |
| 1355 | 1150 | if ( ! is_array( $args ) ) { |
| 1356 | 1151 | // For reverse compatibility. |
| 1357 | 1152 | $args = array( |
| 1358 | 1153 | 'message' => $args, |
| @@ -1385,38 +1180,17 @@ | ||
| 1385 | 1180 | |
| 1386 | 1181 | $sections = self::get_settings_tabs( $values ); |
| 1387 | 1182 | $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' ); |
| 1388 | 1183 | |
| 1389 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php'; | |
| 1184 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' ); | |
| 1390 | 1185 | } |
| 1391 | 1186 | |
| 1392 | 1187 | /** |
| 1393 | - * 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. | |
| 1394 | - * | |
| 1395 | - * @since 6.10 | |
| 1396 | - * | |
| 1397 | - * @return void | |
| 1398 | - */ | |
| 1399 | - private static function maybe_print_media_templates() { | |
| 1400 | - if ( FrmAppHelper::pro_is_included() ) { | |
| 1401 | - // This issue does not exist when Pro is active so exit early. | |
| 1402 | - return; | |
| 1403 | - } | |
| 1404 | - | |
| 1405 | - add_action( | |
| 1406 | - 'wp_enqueue_editor', | |
| 1407 | - function () { | |
| 1408 | - wp_print_media_templates(); | |
| 1409 | - } | |
| 1410 | - ); | |
| 1411 | - } | |
| 1412 | - | |
| 1413 | - /** | |
| 1414 | 1188 | * @since 4.0 |
| 1415 | 1189 | */ |
| 1416 | 1190 | public static function form_publish_button( $atts ) { |
| 1417 | 1191 | $values = $atts['values']; |
| 1418 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php'; | |
| 1192 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' ); | |
| 1419 | 1193 | } |
| 1420 | 1194 | |
| 1421 | 1195 | /** |
| 1422 | 1196 | * Get a list of all the settings tabs for the form settings page. |
| @@ -1430,9 +1204,9 @@ | ||
| 1430 | 1204 | $sections = array( |
| 1431 | 1205 | 'advanced' => array( |
| 1432 | 1206 | 'name' => __( 'General', 'formidable' ), |
| 1433 | 1207 | 'title' => __( 'General Form Settings', 'formidable' ), |
| 1434 | - 'function' => array( self::class, 'advanced_settings' ), | |
| 1208 | + 'function' => array( __CLASS__, 'advanced_settings' ), | |
| 1435 | 1209 | 'icon' => 'frm_icon_font frm_settings_icon', |
| 1436 | 1210 | ), |
| 1437 | 1211 | 'email' => array( |
| 1438 | 1212 | 'name' => __( 'Actions & Notifications', 'formidable' ), |
| @@ -1441,9 +1215,9 @@ | ||
| 1441 | 1215 | 'icon' => 'frm_icon_font frm_mail_bulk_icon', |
| 1442 | 1216 | ), |
| 1443 | 1217 | 'permissions' => array( |
| 1444 | 1218 | 'name' => __( 'Form Permissions', 'formidable' ), |
| 1445 | - 'icon' => 'frm_icon_font frm_lock_closed_icon', | |
| 1219 | + 'icon' => 'frm_icon_font frm_lock_icon', | |
| 1446 | 1220 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1447 | 1221 | 'data' => array( |
| 1448 | 1222 | 'medium' => 'permissions', |
| 1449 | 1223 | 'upgrade' => __( 'Form Permissions', 'formidable' ), |
| @@ -1450,9 +1224,9 @@ | ||
| 1450 | 1224 | 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ), |
| 1451 | 1225 | 'screenshot' => 'permissions.png', |
| 1452 | 1226 | ), |
| 1453 | 1227 | ), |
| 1454 | - 'scheduling' => array( | |
| 1228 | + 'scheduling' => array( | |
| 1455 | 1229 | 'name' => __( 'Form Scheduling', 'formidable' ), |
| 1456 | 1230 | 'icon' => 'frm_icon_font frm_calendar_icon', |
| 1457 | 1231 | 'html_class' => 'frm_show_upgrade_tab frm_noallow', |
| 1458 | 1232 | 'data' => array( |
| @@ -1462,9 +1236,9 @@ | ||
| 1462 | 1236 | ), |
| 1463 | 1237 | ), |
| 1464 | 1238 | 'buttons' => array( |
| 1465 | 1239 | 'name' => __( 'Buttons', 'formidable' ), |
| 1466 | - 'class' => self::class, | |
| 1240 | + 'class' => __CLASS__, | |
| 1467 | 1241 | 'function' => 'buttons_settings', |
| 1468 | 1242 | 'icon' => 'frm_icon_font frm_button_icon', |
| 1469 | 1243 | ), |
| 1470 | 1244 | 'landing' => array( |
| @@ -1485,34 +1259,17 @@ | ||
| 1485 | 1259 | 'screenshot' => 'chat.png', |
| 1486 | 1260 | ) |
| 1487 | 1261 | ), |
| 1488 | 1262 | ), |
| 1489 | - 'abandonment' => array( | |
| 1490 | - 'name' => __( 'Form Abandonment', 'formidable' ), | |
| 1491 | - 'icon' => 'frm_icon_font frm_abandoned_icon', | |
| 1492 | - 'html_class' => 'frm_show_upgrade_tab frm_noallow', | |
| 1493 | - 'data' => FrmAppHelper::get_upgrade_data_params( | |
| 1494 | - 'abandonment', | |
| 1495 | - array( | |
| 1496 | - 'upgrade' => __( 'Form abandonment settings', 'formidable' ), | |
| 1497 | - 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ), | |
| 1498 | - 'screenshot' => 'abandonment.png', | |
| 1499 | - ) | |
| 1500 | - ), | |
| 1501 | - ), | |
| 1502 | 1263 | 'html' => array( |
| 1503 | 1264 | 'name' => __( 'Customize HTML', 'formidable' ), |
| 1504 | - 'class' => self::class, | |
| 1265 | + 'class' => __CLASS__, | |
| 1505 | 1266 | 'function' => 'html_settings', |
| 1506 | 1267 | 'icon' => 'frm_icon_font frm_code_icon', |
| 1507 | 1268 | ), |
| 1508 | 1269 | ); |
| 1509 | 1270 | |
| 1510 | - if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) { | |
| 1511 | - unset( $sections['buttons'] ); | |
| 1512 | - } | |
| 1513 | - | |
| 1514 | - foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) { | |
| 1271 | + foreach ( array( 'landing', 'chat' ) as $feature ) { | |
| 1515 | 1272 | if ( ! FrmAppHelper::show_new_feature( $feature ) ) { |
| 1516 | 1273 | unset( $sections[ $feature ] ); |
| 1517 | 1274 | } |
| 1518 | 1275 | } |
| @@ -1518,8 +1275,13 @@ | ||
| 1518 | 1275 | } |
| 1519 | 1276 | |
| 1520 | 1277 | $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values ); |
| 1521 | 1278 | |
| 1279 | + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) { | |
| 1280 | + // Prevent settings from showing in 2 spots. | |
| 1281 | + unset( $sections['permissions'], $sections['scheduling'] ); | |
| 1282 | + } | |
| 1283 | + | |
| 1522 | 1284 | foreach ( $sections as $key => $section ) { |
| 1523 | 1285 | $defaults = array( |
| 1524 | 1286 | 'html_class' => '', |
| 1525 | 1287 | 'name' => ucfirst( $key ), |
| @@ -1541,9 +1303,9 @@ | ||
| 1541 | 1303 | $section['id'] = $section['anchor']; |
| 1542 | 1304 | } |
| 1543 | 1305 | |
| 1544 | 1306 | $sections[ $key ] = $section; |
| 1545 | - }//end foreach | |
| 1307 | + } | |
| 1546 | 1308 | |
| 1547 | 1309 | return $sections; |
| 1548 | 1310 | } |
| 1549 | 1311 | |
| @@ -1550,9 +1312,8 @@ | ||
| 1550 | 1312 | /** |
| 1551 | 1313 | * @since 4.0 |
| 1552 | 1314 | * |
| 1553 | 1315 | * @param array $values |
| 1554 | - * @return void | |
| 1555 | 1316 | */ |
| 1556 | 1317 | public static function advanced_settings( $values ) { |
| 1557 | 1318 | $first_h3 = 'frm_first_h3'; |
| 1558 | 1319 | |
| @@ -1560,15 +1321,14 @@ | ||
| 1560 | 1321 | } |
| 1561 | 1322 | |
| 1562 | 1323 | /** |
| 1563 | 1324 | * @param array $values |
| 1564 | - * @return void | |
| 1565 | 1325 | */ |
| 1566 | 1326 | public static function render_spam_settings( $values ) { |
| 1567 | 1327 | if ( function_exists( 'akismet_http_post' ) ) { |
| 1568 | 1328 | include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php'; |
| 1569 | 1329 | } |
| 1570 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/stopforumspam.php'; | |
| 1330 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/honeypot.php'; | |
| 1571 | 1331 | include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/antispam.php'; |
| 1572 | 1332 | } |
| 1573 | 1333 | |
| 1574 | 1334 | /** |
| @@ -1574,12 +1334,16 @@ | ||
| 1574 | 1334 | /** |
| 1575 | 1335 | * @since 4.0 |
| 1576 | 1336 | * |
| 1577 | 1337 | * @param array $values |
| 1578 | - * @return void | |
| 1579 | 1338 | */ |
| 1580 | 1339 | public static function buttons_settings( $values ) { |
| 1581 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php'; | |
| 1340 | + $styles = apply_filters( 'frm_get_style_opts', array() ); | |
| 1341 | + | |
| 1342 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 1343 | + $no_global_style = $frm_settings->load_style === 'none'; | |
| 1344 | + | |
| 1345 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' ); | |
| 1582 | 1346 | } |
| 1583 | 1347 | |
| 1584 | 1348 | /** |
| 1585 | 1349 | * @since 4.0 |
| @@ -1584,12 +1348,11 @@ | ||
| 1584 | 1348 | /** |
| 1585 | 1349 | * @since 4.0 |
| 1586 | 1350 | * |
| 1587 | 1351 | * @param array $values |
| 1588 | - * @return void | |
| 1589 | 1352 | */ |
| 1590 | 1353 | public static function html_settings( $values ) { |
| 1591 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php'; | |
| 1354 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' ); | |
| 1592 | 1355 | } |
| 1593 | 1356 | |
| 1594 | 1357 | /** |
| 1595 | 1358 | * Replace old Submit Button href with new href to avoid errors in Chrome |
| @@ -1595,10 +1358,9 @@ | ||
| 1595 | 1358 | * Replace old Submit Button href with new href to avoid errors in Chrome |
| 1596 | 1359 | * |
| 1597 | 1360 | * @since 2.03.08 |
| 1598 | 1361 | * |
| 1599 | - * @param array|bool $values | |
| 1600 | - * @return void | |
| 1362 | + * @param array|boolean $values | |
| 1601 | 1363 | */ |
| 1602 | 1364 | private static function clean_submit_html( &$values ) { |
| 1603 | 1365 | if ( is_array( $values ) && isset( $values['submit_html'] ) ) { |
| 1604 | 1366 | $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] ); |
| @@ -1619,13 +1381,8 @@ | ||
| 1619 | 1381 | |
| 1620 | 1382 | return $classes; |
| 1621 | 1383 | } |
| 1622 | 1384 | |
| 1623 | - /** | |
| 1624 | - * @param int|string $form_id | |
| 1625 | - * @param string $class | |
| 1626 | - * @return void | |
| 1627 | - */ | |
| 1628 | 1385 | public static function mb_tags_box( $form_id, $class = '' ) { |
| 1629 | 1386 | $fields = FrmField::get_all_for_form( $form_id, '', 'include' ); |
| 1630 | 1387 | |
| 1631 | 1388 | /** |
| @@ -1638,9 +1395,9 @@ | ||
| 1638 | 1395 | */ |
| 1639 | 1396 | $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) ); |
| 1640 | 1397 | $linked_forms = array(); |
| 1641 | 1398 | $col = 'one'; |
| 1642 | - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ); | |
| 1399 | + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false; | |
| 1643 | 1400 | |
| 1644 | 1401 | $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() ); |
| 1645 | 1402 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 1646 | 1403 | |
| @@ -1645,9 +1402,9 @@ | ||
| 1645 | 1402 | $entry_shortcodes = self::get_shortcode_helpers( $settings_tab ); |
| 1646 | 1403 | |
| 1647 | 1404 | $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) ); |
| 1648 | 1405 | |
| 1649 | - include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php'; | |
| 1406 | + include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' ); | |
| 1650 | 1407 | } |
| 1651 | 1408 | |
| 1652 | 1409 | /** |
| 1653 | 1410 | * @since 3.04.01 |
| @@ -1660,9 +1417,9 @@ | ||
| 1660 | 1417 | ), |
| 1661 | 1418 | ); |
| 1662 | 1419 | |
| 1663 | 1420 | $user_fields = self::user_shortcodes(); |
| 1664 | - if ( $user_fields ) { | |
| 1421 | + if ( ! empty( $user_fields ) ) { | |
| 1665 | 1422 | $user_helpers = array(); |
| 1666 | 1423 | foreach ( $user_fields as $uk => $uf ) { |
| 1667 | 1424 | $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf; |
| 1668 | 1425 | unset( $uk, $uf ); |
| @@ -1668,9 +1425,9 @@ | ||
| 1668 | 1425 | unset( $uk, $uf ); |
| 1669 | 1426 | } |
| 1670 | 1427 | |
| 1671 | 1428 | $advanced_helpers['user_id'] = array( |
| 1672 | - 'codes' => $user_helpers, | |
| 1429 | + 'codes' => $user_helpers, | |
| 1673 | 1430 | ); |
| 1674 | 1431 | } |
| 1675 | 1432 | |
| 1676 | 1433 | /** |
| @@ -1747,16 +1504,21 @@ | ||
| 1747 | 1504 | 'updated-at' => __( 'Entry updated', 'formidable' ), |
| 1748 | 1505 | '' => '', |
| 1749 | 1506 | 'siteurl' => __( 'Site URL', 'formidable' ), |
| 1750 | 1507 | 'sitename' => __( 'Site Name', 'formidable' ), |
| 1751 | - 'form_name' => __( 'Form Name', 'formidable' ), | |
| 1752 | 1508 | ); |
| 1753 | 1509 | |
| 1754 | - $entry_shortcodes = array_merge( FrmShortcodeHelper::get_contextual_shortcode_values(), $entry_shortcodes ); | |
| 1755 | 1510 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 1756 | 1511 | unset( $entry_shortcodes['post_id'] ); |
| 1757 | 1512 | } |
| 1758 | 1513 | |
| 1514 | + if ( $settings_tab ) { | |
| 1515 | + $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' ); | |
| 1516 | + $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' ); | |
| 1517 | + $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' ); | |
| 1518 | + $entry_shortcodes['form_name'] = __( 'Form Name', 'formidable' ); | |
| 1519 | + } | |
| 1520 | + | |
| 1759 | 1521 | /** |
| 1760 | 1522 | * Use this hook to add or remove buttons in the helpers section |
| 1761 | 1523 | * in the customization panel |
| 1762 | 1524 | * |
| @@ -1782,9 +1544,9 @@ | ||
| 1782 | 1544 | echo ' frm_js_validate '; |
| 1783 | 1545 | self::add_js_validate_form_to_global_vars( $form ); |
| 1784 | 1546 | } |
| 1785 | 1547 | |
| 1786 | - if ( FrmForm::is_ajax_on( $form ) ) { | |
| 1548 | + if ( ! FrmFormsHelper::should_use_pro_for_ajax_submit() && FrmForm::is_ajax_on( $form ) ) { | |
| 1787 | 1549 | echo ' frm_ajax_submit '; |
| 1788 | 1550 | } |
| 1789 | 1551 | } |
| 1790 | 1552 | |
| @@ -1806,11 +1568,11 @@ | ||
| 1806 | 1568 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1807 | 1569 | |
| 1808 | 1570 | echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 1809 | 1571 | array( |
| 1810 | - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1572 | + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), | |
| 1811 | 1573 | 'default_email' => true, |
| 1812 | - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1574 | + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), | |
| 1813 | 1575 | ) |
| 1814 | 1576 | ); |
| 1815 | 1577 | wp_die(); |
| 1816 | 1578 | } |
| @@ -1816,10 +1578,10 @@ | ||
| 1816 | 1578 | } |
| 1817 | 1579 | |
| 1818 | 1580 | /** |
| 1819 | 1581 | * @param string $content |
| 1820 | - * @param int|stdClass|string $form | |
| 1821 | - * @param false|int|stdClass|string $entry | |
| 1582 | + * @param stdClass|string|int $form | |
| 1583 | + * @param stdClass|string|int|false $entry | |
| 1822 | 1584 | * @return string |
| 1823 | 1585 | */ |
| 1824 | 1586 | public static function filter_content( $content, $form, $entry = false ) { |
| 1825 | 1587 | $content = self::replace_form_name_shortcodes( $content, $form ); |
| @@ -1832,16 +1594,8 @@ | ||
| 1832 | 1594 | if ( is_object( $form ) ) { |
| 1833 | 1595 | $form = $form->id; |
| 1834 | 1596 | } |
| 1835 | 1597 | |
| 1836 | - /* | |
| 1837 | - * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty, | |
| 1838 | - * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work. | |
| 1839 | - */ | |
| 1840 | - if ( ! empty( $entry->parent_entry ) ) { | |
| 1841 | - $form = $entry->parent_entry->form_id; | |
| 1842 | - } | |
| 1843 | - | |
| 1844 | 1598 | $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form ); |
| 1845 | 1599 | $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes ); |
| 1846 | 1600 | |
| 1847 | 1601 | return $content; |
| @@ -1851,17 +1605,13 @@ | ||
| 1851 | 1605 | * Replace any [form_name] shortcodes in a string. |
| 1852 | 1606 | * |
| 1853 | 1607 | * @since 5.5 |
| 1854 | 1608 | * |
| 1855 | - * @param array|string $string | |
| 1856 | - * @param int|stdClass|string $form | |
| 1857 | - * @return array|string | |
| 1609 | + * @param string $string | |
| 1610 | + * @param stdClass|string|int $form | |
| 1611 | + * @return string | |
| 1858 | 1612 | */ |
| 1859 | 1613 | public static function replace_form_name_shortcodes( $string, $form ) { |
| 1860 | - if ( ! is_string( $string ) ) { | |
| 1861 | - return $string; | |
| 1862 | - } | |
| 1863 | - | |
| 1864 | 1614 | if ( false === strpos( $string, '[form_name]' ) ) { |
| 1865 | 1615 | return $string; |
| 1866 | 1616 | } |
| 1867 | 1617 | |
| @@ -1873,9 +1623,9 @@ | ||
| 1873 | 1623 | return str_replace( '[form_name]', $form_name, $string ); |
| 1874 | 1624 | } |
| 1875 | 1625 | |
| 1876 | 1626 | /** |
| 1877 | - * @param false|int|stdClass|string $entry | |
| 1627 | + * @param stdClass|string|int|false $entry | |
| 1878 | 1628 | * @return void |
| 1879 | 1629 | */ |
| 1880 | 1630 | private static function get_entry_by_param( &$entry ) { |
| 1881 | 1631 | if ( ! $entry || ! is_object( $entry ) ) { |
| @@ -1890,12 +1640,8 @@ | ||
| 1890 | 1640 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
| 1891 | 1641 | return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes ); |
| 1892 | 1642 | } |
| 1893 | 1643 | |
| 1894 | - /** | |
| 1895 | - * @param array $errors | |
| 1896 | - * @return array | |
| 1897 | - */ | |
| 1898 | 1644 | public static function process_bulk_form_actions( $errors ) { |
| 1899 | 1645 | if ( ! $_REQUEST ) { |
| 1900 | 1646 | return $errors; |
| 1901 | 1647 | } |
| @@ -1939,9 +1685,9 @@ | ||
| 1939 | 1685 | case 'untrash': |
| 1940 | 1686 | $message = self::bulk_untrash( $ids ); |
| 1941 | 1687 | } |
| 1942 | 1688 | |
| 1943 | - if ( ! empty( $message ) ) { | |
| 1689 | + if ( isset( $message ) && ! empty( $message ) ) { | |
| 1944 | 1690 | $errors['message'] = $message; |
| 1945 | 1691 | } |
| 1946 | 1692 | |
| 1947 | 1693 | return $errors; |
| @@ -1946,26 +1692,13 @@ | ||
| 1946 | 1692 | |
| 1947 | 1693 | return $errors; |
| 1948 | 1694 | } |
| 1949 | 1695 | |
| 1950 | - /** | |
| 1951 | - * Includes html that shows a message when the device is too small to use Formidable Forms admin pages. | |
| 1952 | - * | |
| 1953 | - * @since 6.20 | |
| 1954 | - * @return void | |
| 1955 | - */ | |
| 1956 | - public static function include_device_too_small_message() { | |
| 1957 | - if ( ! FrmAppHelper::is_formidable_admin() ) { | |
| 1958 | - return; | |
| 1959 | - } | |
| 1960 | - | |
| 1961 | - include FrmAppHelper::plugin_path() . '/classes/views/shared/small-device-message.php'; | |
| 1962 | - } | |
| 1963 | - | |
| 1964 | 1696 | public static function route() { |
| 1965 | 1697 | $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
| 1966 | 1698 | $vars = array(); |
| 1967 | 1699 | FrmAppHelper::include_svg(); |
| 1700 | + | |
| 1968 | 1701 | if ( isset( $_POST['frm_compact_fields'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 1969 | 1702 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 1970 | 1703 | |
| 1971 | 1704 | // Javascript needs to be allowed in some field settings. |
| @@ -1974,9 +1707,9 @@ | ||
| 1974 | 1707 | $json_vars = json_decode( $json_vars, true ); |
| 1975 | 1708 | if ( empty( $json_vars ) ) { |
| 1976 | 1709 | // json decoding failed so we should return an error message. |
| 1977 | 1710 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 1978 | - if ( 'edit' === $action ) { | |
| 1711 | + if ( 'edit' == $action ) { | |
| 1979 | 1712 | $action = 'update'; |
| 1980 | 1713 | } |
| 1981 | 1714 | |
| 1982 | 1715 | add_filter( 'frm_validate_form', 'FrmFormsController::json_error' ); |
| @@ -1992,14 +1725,16 @@ | ||
| 1992 | 1725 | if ( isset( $_REQUEST['delete_all'] ) ) { |
| 1993 | 1726 | // Override the action for this page. |
| 1994 | 1727 | $action = 'delete_all'; |
| 1995 | 1728 | } |
| 1996 | - }//end if | |
| 1729 | + } | |
| 1997 | 1730 | |
| 1998 | 1731 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1999 | 1732 | FrmAppHelper::trigger_hook_load( 'form' ); |
| 2000 | 1733 | |
| 2001 | 1734 | switch ( $action ) { |
| 1735 | + case 'new': | |
| 1736 | + return self::new_form( $vars ); | |
| 2002 | 1737 | case 'create': |
| 2003 | 1738 | case 'edit': |
| 2004 | 1739 | case 'update': |
| 2005 | 1740 | case 'trash': |
| @@ -2004,17 +1739,16 @@ | ||
| 2004 | 1739 | case 'update': |
| 2005 | 1740 | case 'trash': |
| 2006 | 1741 | case 'untrash': |
| 2007 | 1742 | case 'destroy': |
| 1743 | + case 'delete_all': | |
| 2008 | 1744 | case 'settings': |
| 2009 | 1745 | case 'update_settings': |
| 2010 | 1746 | return self::$action( $vars ); |
| 2011 | 1747 | case 'lite-reports': |
| 2012 | - self::no_reports( $vars ); | |
| 2013 | - return; | |
| 1748 | + return self::no_reports( $vars ); | |
| 2014 | 1749 | case 'views': |
| 2015 | - self::no_views( $vars ); | |
| 2016 | - return; | |
| 1750 | + return self::no_views( $vars ); | |
| 2017 | 1751 | default: |
| 2018 | 1752 | do_action( 'frm_form_action_' . $action ); |
| 2019 | 1753 | if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) { |
| 2020 | 1754 | return; |
| @@ -2037,65 +1771,12 @@ | ||
| 2037 | 1771 | self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) ); |
| 2038 | 1772 | return; |
| 2039 | 1773 | } |
| 2040 | 1774 | |
| 2041 | - if ( 'forms_permanently_deleted' === $message ) { | |
| 2042 | - $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' ); | |
| 2043 | - /* translators: %1$s: Number of forms */ | |
| 2044 | - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 2045 | - self::display_forms_list( array(), $message, '' ); | |
| 2046 | - return; | |
| 2047 | - } | |
| 2048 | - | |
| 2049 | 1775 | self::display_forms_list(); |
| 2050 | 1776 | |
| 2051 | 1777 | return; |
| 2052 | - }//end switch | |
| 2053 | - } | |
| 2054 | - | |
| 2055 | - /** | |
| 2056 | - * Rename a form. | |
| 2057 | - * | |
| 2058 | - * Handles the AJAX request for renaming a form. | |
| 2059 | - * | |
| 2060 | - * @since 6.7 | |
| 2061 | - * | |
| 2062 | - * @return void | |
| 2063 | - */ | |
| 2064 | - public static function rename_form() { | |
| 2065 | - // Check permission and nonce | |
| 2066 | - FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 2067 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 2068 | - | |
| 2069 | - // Get posted data | |
| 2070 | - $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); | |
| 2071 | - $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' ); | |
| 2072 | - | |
| 2073 | - $form = FrmForm::getOne( $form_id ); | |
| 2074 | - if ( ! $form ) { | |
| 2075 | - wp_send_json_error( __( 'Form not found', 'formidable' ) ); | |
| 2076 | 1778 | } |
| 2077 | - | |
| 2078 | - if ( $name === $form->name ) { | |
| 2079 | - // Nothing to change so exit early. | |
| 2080 | - wp_send_json_success(); | |
| 2081 | - } | |
| 2082 | - | |
| 2083 | - $to_update = array( | |
| 2084 | - 'name' => $name, | |
| 2085 | - ); | |
| 2086 | - | |
| 2087 | - if ( '' !== $name ) { | |
| 2088 | - // Only update form_key if name is not empty. | |
| 2089 | - $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' ); | |
| 2090 | - $to_update['form_key'] = $form_key; | |
| 2091 | - } else { | |
| 2092 | - $form_key = $form->form_key; | |
| 2093 | - } | |
| 2094 | - | |
| 2095 | - FrmForm::update( $form_id, $to_update ); | |
| 2096 | - | |
| 2097 | - wp_send_json_success( compact( 'form_key' ) ); | |
| 2098 | 1779 | } |
| 2099 | 1780 | |
| 2100 | 1781 | public static function json_error( $errors ) { |
| 2101 | 1782 | $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
| @@ -2103,13 +1784,20 @@ | ||
| 2103 | 1784 | return $errors; |
| 2104 | 1785 | } |
| 2105 | 1786 | |
| 2106 | 1787 | /** |
| 1788 | + * Education for premium features. | |
| 1789 | + * | |
| 1790 | + * @since 4.05 | |
| 1791 | + */ | |
| 1792 | + public static function add_form_style_tab_options() { | |
| 1793 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' ); | |
| 1794 | + } | |
| 1795 | + | |
| 1796 | + /** | |
| 2107 | 1797 | * Add education about views. |
| 2108 | 1798 | * |
| 2109 | 1799 | * @since 4.07 |
| 2110 | - * | |
| 2111 | - * @return void | |
| 2112 | 1800 | */ |
| 2113 | 1801 | public static function no_views( $values = array() ) { |
| 2114 | 1802 | FrmAppHelper::include_svg(); |
| 2115 | 1803 | $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| @@ -2121,10 +1809,8 @@ | ||
| 2121 | 1809 | /** |
| 2122 | 1810 | * Add education about reports. |
| 2123 | 1811 | * |
| 2124 | 1812 | * @since 4.07 |
| 2125 | - * | |
| 2126 | - * @return void | |
| 2127 | 1813 | */ |
| 2128 | 1814 | public static function no_reports( $values = array() ) { |
| 2129 | 1815 | $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| 2130 | 1816 | $form = $id ? FrmForm::getOne( $id ) : false; |
| @@ -2131,11 +1817,9 @@ | ||
| 2131 | 1817 | |
| 2132 | 1818 | include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php'; |
| 2133 | 1819 | } |
| 2134 | 1820 | |
| 2135 | - /** | |
| 2136 | - * FRONT-END FORMS. | |
| 2137 | - */ | |
| 1821 | + /* FRONT-END FORMS */ | |
| 2138 | 1822 | public static function admin_bar_css() { |
| 2139 | 1823 | if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 2140 | 1824 | return; |
| 2141 | 1825 | } |
| @@ -2209,9 +1893,9 @@ | ||
| 2209 | 1893 | $wp_admin_bar->add_node( |
| 2210 | 1894 | array( |
| 2211 | 1895 | 'parent' => 'frm-forms', |
| 2212 | 1896 | 'id' => 'edit_form_' . $form_id, |
| 2213 | - 'title' => empty( $name ) ? FrmFormsHelper::get_no_title_text() : $name, | |
| 1897 | + 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name, | |
| 2214 | 1898 | 'href' => FrmForm::get_edit_link( $form_id ), |
| 2215 | 1899 | ) |
| 2216 | 1900 | ); |
| 2217 | 1901 | } |
| @@ -2224,10 +1908,10 @@ | ||
| 2224 | 1908 | * @return string |
| 2225 | 1909 | */ |
| 2226 | 1910 | public static function get_form_shortcode( $atts ) { |
| 2227 | 1911 | global $frm_vars; |
| 2228 | - if ( ! empty( $frm_vars['skip_shortcode'] ) ) { | |
| 2229 | - $sc = '[formidable'; | |
| 1912 | + if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) { | |
| 1913 | + $sc = '[formidable'; | |
| 2230 | 1914 | $sc .= FrmAppHelper::array_to_html_params( $atts ); |
| 2231 | 1915 | return $sc . ']'; |
| 2232 | 1916 | } |
| 2233 | 1917 | |
| @@ -2252,11 +1936,11 @@ | ||
| 2252 | 1936 | |
| 2253 | 1937 | /** |
| 2254 | 1938 | * @since 5.2.01 |
| 2255 | 1939 | * |
| 2256 | - * @param false|int|string $id | |
| 2257 | - * @param false|string $key | |
| 2258 | - * @return false|stdClass | |
| 1940 | + * @param string|int|false $id | |
| 1941 | + * @param string|false $key | |
| 1942 | + * @return stdClass|false | |
| 2259 | 1943 | */ |
| 2260 | 1944 | private static function maybe_get_form_by_id_or_key( $id, $key ) { |
| 2261 | 1945 | if ( ! $id ) { |
| 2262 | 1946 | $id = $key; |
| @@ -2264,12 +1948,12 @@ | ||
| 2264 | 1948 | return self::maybe_get_form_to_show( $id ); |
| 2265 | 1949 | } |
| 2266 | 1950 | |
| 2267 | 1951 | /** |
| 2268 | - * @param false|int|string $id | |
| 2269 | - * @param false|string $key | |
| 2270 | - * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 2271 | - * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 1952 | + * @param string|int|false $id | |
| 1953 | + * @param string|false $key | |
| 1954 | + * @param string|int|bool $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 1955 | + * @param string|int|bool $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0. | |
| 2272 | 1956 | * @param array $atts |
| 2273 | 1957 | * @return string |
| 2274 | 1958 | */ |
| 2275 | 1959 | public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) { |
| @@ -2317,16 +2001,15 @@ | ||
| 2317 | 2001 | return $form; |
| 2318 | 2002 | } |
| 2319 | 2003 | |
| 2320 | 2004 | /** |
| 2321 | - * @param false|int|string $id | |
| 2322 | - * @return false|stdClass | |
| 2005 | + * @param string|int|false $id | |
| 2006 | + * @return stdClass|false | |
| 2323 | 2007 | */ |
| 2324 | 2008 | private static function maybe_get_form_to_show( $id ) { |
| 2325 | 2009 | $form = false; |
| 2326 | 2010 | |
| 2327 | - if ( ! empty( $id ) ) { | |
| 2328 | - // Form id or key is set. | |
| 2011 | + if ( ! empty( $id ) ) { // form id or key is set | |
| 2329 | 2012 | $form = FrmForm::getOne( $id ); |
| 2330 | 2013 | if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) { |
| 2331 | 2014 | $form = false; |
| 2332 | 2015 | } |
| @@ -2384,11 +2067,11 @@ | ||
| 2384 | 2067 | |
| 2385 | 2068 | do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description ); |
| 2386 | 2069 | |
| 2387 | 2070 | if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) { |
| 2388 | - $entry_id = self::just_created_entry( $form->id ); | |
| 2389 | - $pass_args['entry_id'] = $entry_id; | |
| 2390 | - $pass_args['reset'] = true; | |
| 2071 | + $entry_id = self::just_created_entry( $form->id ); | |
| 2072 | + $pass_args['entry_id'] = $entry_id; | |
| 2073 | + $pass_args['reset'] = true; | |
| 2391 | 2074 | |
| 2392 | 2075 | self::run_on_submit_actions( $pass_args ); |
| 2393 | 2076 | |
| 2394 | 2077 | do_action( |
| @@ -2398,9 +2081,9 @@ | ||
| 2398 | 2081 | 'form' => $form, |
| 2399 | 2082 | ) |
| 2400 | 2083 | ); |
| 2401 | 2084 | } |
| 2402 | - }//end if | |
| 2085 | + } | |
| 2403 | 2086 | } |
| 2404 | 2087 | |
| 2405 | 2088 | /** |
| 2406 | 2089 | * If the form was processed earlier (init), get the generated errors |
| @@ -2432,9 +2115,9 @@ | ||
| 2432 | 2115 | */ |
| 2433 | 2116 | public static function just_created_entry( $form_id ) { |
| 2434 | 2117 | global $frm_vars; |
| 2435 | 2118 | |
| 2436 | - 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; | |
| 2119 | + 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; | |
| 2437 | 2120 | } |
| 2438 | 2121 | |
| 2439 | 2122 | /** |
| 2440 | 2123 | * Gets confirmation method. |
| @@ -2447,14 +2130,14 @@ | ||
| 2447 | 2130 | * |
| 2448 | 2131 | * @type object $form Form object. |
| 2449 | 2132 | * @type int $entry_id Entry ID. |
| 2450 | 2133 | * } |
| 2451 | - * @return array|string | |
| 2134 | + * @return string|array | |
| 2452 | 2135 | */ |
| 2453 | 2136 | private static function get_confirmation_method( $atts ) { |
| 2454 | 2137 | $action = FrmOnSubmitHelper::current_event( $atts ); |
| 2455 | 2138 | $opt = 'update' === $action ? 'edit_action' : 'success_action'; |
| 2456 | - $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message'; | |
| 2139 | + $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message'; | |
| 2457 | 2140 | |
| 2458 | 2141 | if ( ! empty( $atts['entry_id'] ) ) { |
| 2459 | 2142 | $met_actions = self::get_met_on_submit_actions( $atts, $action ); |
| 2460 | 2143 | if ( $met_actions ) { |
| @@ -2463,9 +2146,9 @@ | ||
| 2463 | 2146 | } |
| 2464 | 2147 | |
| 2465 | 2148 | $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action ); |
| 2466 | 2149 | |
| 2467 | - if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { | |
| 2150 | + if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) { | |
| 2468 | 2151 | $method = 'message'; |
| 2469 | 2152 | } |
| 2470 | 2153 | |
| 2471 | 2154 | return $method; |
| @@ -2499,9 +2182,9 @@ | ||
| 2499 | 2182 | * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}. |
| 2500 | 2183 | */ |
| 2501 | 2184 | public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) { |
| 2502 | 2185 | if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) { |
| 2503 | - if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) { | |
| 2186 | + if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) ) { | |
| 2504 | 2187 | $event = FrmOnSubmitHelper::current_event( $params ); |
| 2505 | 2188 | FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event ); |
| 2506 | 2189 | $conf_method = 'redirect'; |
| 2507 | 2190 | } |
| @@ -2550,9 +2233,9 @@ | ||
| 2550 | 2233 | unset( $extra_args['form'] ); |
| 2551 | 2234 | |
| 2552 | 2235 | do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args ); |
| 2553 | 2236 | |
| 2554 | - $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit'; | |
| 2237 | + $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit'; | |
| 2555 | 2238 | |
| 2556 | 2239 | $args['success_opt'] = $opt; |
| 2557 | 2240 | $args['ajax'] = ! empty( $frm_vars['ajax'] ); |
| 2558 | 2241 | |
| @@ -2578,16 +2261,11 @@ | ||
| 2578 | 2261 | if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) { |
| 2579 | 2262 | return array(); |
| 2580 | 2263 | } |
| 2581 | 2264 | |
| 2582 | - // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab. | |
| 2583 | - if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) { | |
| 2584 | - return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) ); | |
| 2585 | - } | |
| 2586 | - | |
| 2587 | - $entry = FrmEntry::getOne( $args['entry_id'], true ); | |
| 2588 | - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); | |
| 2589 | - $met_actions = array(); | |
| 2265 | + $entry = FrmEntry::getOne( $args['entry_id'], true ); | |
| 2266 | + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id ); | |
| 2267 | + $met_actions = array(); | |
| 2590 | 2268 | $has_redirect = false; |
| 2591 | 2269 | |
| 2592 | 2270 | foreach ( $actions as $action ) { |
| 2593 | 2271 | if ( ! in_array( $event, $action->post_content['event'], true ) ) { |
| @@ -2600,10 +2278,9 @@ | ||
| 2600 | 2278 | |
| 2601 | 2279 | $action_type = FrmOnSubmitHelper::get_action_type( $action ); |
| 2602 | 2280 | |
| 2603 | 2281 | if ( 'redirect' === $action_type ) { |
| 2604 | - if ( $has_redirect ) { | |
| 2605 | - // Do not process because we run the first redirect action only. | |
| 2282 | + if ( $has_redirect ) { // Do not process because we run the first redirect action only. | |
| 2606 | 2283 | continue; |
| 2607 | 2284 | } |
| 2608 | 2285 | } |
| 2609 | 2286 | |
| @@ -2616,9 +2293,9 @@ | ||
| 2616 | 2293 | } |
| 2617 | 2294 | |
| 2618 | 2295 | $met_actions[] = $action; |
| 2619 | 2296 | unset( $action ); |
| 2620 | - }//end foreach | |
| 2297 | + } | |
| 2621 | 2298 | |
| 2622 | 2299 | $args['event'] = $event; |
| 2623 | 2300 | |
| 2624 | 2301 | /** |
| @@ -2807,9 +2484,9 @@ | ||
| 2807 | 2484 | add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 ); |
| 2808 | 2485 | } |
| 2809 | 2486 | |
| 2810 | 2487 | $post = $old_post; |
| 2811 | - }//end if | |
| 2488 | + } | |
| 2812 | 2489 | } |
| 2813 | 2490 | |
| 2814 | 2491 | /** |
| 2815 | 2492 | * @since 3.0 |
| @@ -2830,25 +2507,16 @@ | ||
| 2830 | 2507 | $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args ); |
| 2831 | 2508 | |
| 2832 | 2509 | $doing_ajax = FrmAppHelper::doing_ajax(); |
| 2833 | 2510 | |
| 2834 | - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { | |
| 2835 | - // Is AJAX submit and there is just one Redirect action runs. | |
| 2836 | - echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) ); | |
| 2511 | + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs. | |
| 2512 | + echo json_encode( array( 'redirect' => $success_url ) ); | |
| 2837 | 2513 | wp_die(); |
| 2838 | 2514 | } |
| 2839 | 2515 | |
| 2840 | - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) && empty( $args['form']->options['redirect_delay'] ) ) { | |
| 2841 | - // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2842 | - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2843 | - self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ); | |
| 2844 | - self::$redirected_in_new_tab[ $args['form']->id ] = 1; | |
| 2845 | - return; | |
| 2846 | - } | |
| 2847 | - | |
| 2516 | + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2848 | 2517 | wp_redirect( esc_url_raw( $success_url ) ); |
| 2849 | - // Do not use wp_die or redirect fails. | |
| 2850 | - die(); | |
| 2518 | + die(); // do not use wp_die or redirect fails | |
| 2851 | 2519 | } |
| 2852 | 2520 | |
| 2853 | 2521 | // Redirect with a delay. |
| 2854 | 2522 | self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) ); |
| @@ -2854,81 +2522,8 @@ | ||
| 2854 | 2522 | self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) ); |
| 2855 | 2523 | } |
| 2856 | 2524 | |
| 2857 | 2525 | /** |
| 2858 | - * Prints open in new tab js with fallback handler. | |
| 2859 | - * | |
| 2860 | - * @since 6.3.1 | |
| 2861 | - * | |
| 2862 | - * @param string $success_url Success URL. | |
| 2863 | - * @param array $args See {@see FrmFormsController::redirect_after_submit()}. | |
| 2864 | - */ | |
| 2865 | - private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) { | |
| 2866 | - echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");'; | |
| 2867 | - echo 'if ( ! newTab ) {'; | |
| 2868 | - | |
| 2869 | - $data = array( | |
| 2870 | - 'formId' => intval( $args['form']->id ), | |
| 2871 | - 'message' => self::get_redirect_fallback_message( $success_url, $args ), | |
| 2872 | - ); | |
| 2873 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2874 | - echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';'; | |
| 2875 | - echo '}</script>'; | |
| 2876 | - } | |
| 2877 | - | |
| 2878 | - /** | |
| 2879 | - * Gets response data for redirect action when AJAX submitting. | |
| 2880 | - * | |
| 2881 | - * @since 6.3.1 | |
| 2882 | - * | |
| 2883 | - * @param array $args See {@see FrmFormsController::run_success_action()}. | |
| 2884 | - * @return array | |
| 2885 | - */ | |
| 2886 | - private static function get_ajax_redirect_response_data( $args ) { | |
| 2887 | - $response_data = array( | |
| 2888 | - 'redirect' => $args['success_url'], | |
| 2889 | - 'content' => '', | |
| 2890 | - ); | |
| 2891 | - $unset_content = true; | |
| 2892 | - | |
| 2893 | - if ( ! empty( $args['form']->options['redirect_delay'] ) ) { | |
| 2894 | - $response_data['delay'] = $args['form']->options['redirect_delay_time']; | |
| 2895 | - $response_data['content'] .= self::get_redirect_message( $args['success_url'], $args['form']->options['redirect_delay_msg'], $args ); | |
| 2896 | - $unset_content = false; | |
| 2897 | - } | |
| 2898 | - | |
| 2899 | - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2900 | - $response_data['openInNewTab'] = 1; | |
| 2901 | - | |
| 2902 | - // Only show open in new tab text if there is no delay. | |
| 2903 | - if ( empty( $response_data['content'] ) ) { | |
| 2904 | - $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg(); | |
| 2905 | - | |
| 2906 | - $args['form']->options['success_msg'] = $args['message']; | |
| 2907 | - $args['form']->options['edit_msg'] = $args['message']; | |
| 2908 | - if ( ! isset( $args['fields'] ) ) { | |
| 2909 | - $args['fields'] = FrmField::get_all_for_form( $args['form']->id ); | |
| 2910 | - } | |
| 2911 | - | |
| 2912 | - $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args ); | |
| 2913 | - | |
| 2914 | - ob_start(); | |
| 2915 | - self::show_lone_success_message( $args ); | |
| 2916 | - $response_data['content'] .= ob_get_clean(); | |
| 2917 | - $unset_content = false; | |
| 2918 | - }//end if | |
| 2919 | - | |
| 2920 | - $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args ); | |
| 2921 | - }//end if | |
| 2922 | - | |
| 2923 | - if ( $unset_content && '' === $response_data['content'] ) { | |
| 2924 | - unset( $response_data['content'] ); | |
| 2925 | - } | |
| 2926 | - | |
| 2927 | - return $response_data; | |
| 2928 | - } | |
| 2929 | - | |
| 2930 | - /** | |
| 2931 | 2526 | * Redirects after submitting using JS. This is used when showing message before redirecting. |
| 2932 | 2527 | * |
| 2933 | 2528 | * @since 6.0 |
| 2934 | 2529 | * |
| @@ -2934,11 +2529,10 @@ | ||
| 2934 | 2529 | * |
| 2935 | 2530 | * @param array $args See {@see FrmFormsController::run_success_action()}. |
| 2936 | 2531 | */ |
| 2937 | 2532 | private static function redirect_after_submit_using_js( $args ) { |
| 2938 | - $success_msg = $args['form']->options['redirect_delay_msg']; | |
| 2533 | + $success_msg = FrmOnSubmitHelper::get_default_redirect_msg(); | |
| 2939 | 2534 | $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args ); |
| 2940 | - $success_url = esc_url_raw( $args['success_url'] ); | |
| 2941 | 2535 | |
| 2942 | 2536 | /** |
| 2943 | 2537 | * Filters the delay time before redirecting when On Submit Redirect action is delayed. |
| 2944 | 2538 | * |
| @@ -2943,27 +2537,20 @@ | ||
| 2943 | 2537 | * Filters the delay time before redirecting when On Submit Redirect action is delayed. |
| 2944 | 2538 | * |
| 2945 | 2539 | * @since 6.0 |
| 2946 | 2540 | * |
| 2947 | - * @param int $delay_time Delay time in milliseconds. | |
| 2541 | + * @param int $delay_time Delay time in miliseconds. | |
| 2948 | 2542 | */ |
| 2949 | - $delay_time = apply_filters( 'frm_redirect_delay_time', 1000 * $args['form']->options['redirect_delay_time'] ); | |
| 2543 | + $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 ); | |
| 2950 | 2544 | |
| 2951 | - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 2952 | - $redirect_js = 'window.open("' . $success_url . '", "_blank")'; | |
| 2953 | - } else { | |
| 2954 | - $redirect_js = 'window.location="' . $success_url . '";'; | |
| 2955 | - } | |
| 2956 | - | |
| 2957 | 2545 | add_filter( 'frm_use_wpautop', '__return_true' ); |
| 2958 | 2546 | |
| 2959 | 2547 | echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2960 | 2548 | echo '<script>'; |
| 2961 | - if ( empty( $args['doing_ajax'] ) ) { | |
| 2962 | - // Not AJAX submit, delay JS until window.load. | |
| 2549 | + if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load. | |
| 2963 | 2550 | echo 'window.onload=function(){'; |
| 2964 | 2551 | } |
| 2965 | - echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2552 | + echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');'; | |
| 2966 | 2553 | if ( empty( $args['doing_ajax'] ) ) { |
| 2967 | 2554 | echo '};'; |
| 2968 | 2555 | } |
| 2969 | 2556 | echo '</script>'; |
| @@ -2973,15 +2560,14 @@ | ||
| 2973 | 2560 | * @since 3.0 |
| 2974 | 2561 | * |
| 2975 | 2562 | * @param string $success_url |
| 2976 | 2563 | * @param string $success_msg |
| 2977 | - * @param array $args | |
| 2564 | + * @param array $args | |
| 2978 | 2565 | */ |
| 2979 | 2566 | private static function get_redirect_message( $success_url, $success_msg, $args ) { |
| 2980 | - $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] ); | |
| 2981 | - $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) ); | |
| 2982 | 2567 | $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . |
| 2983 | - self::get_redirect_fallback_message( $success_url, $args ) . | |
| 2568 | + /* translators: %1$s: Start link HTML, %2$s: End link HTML */ | |
| 2569 | + sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) . | |
| 2984 | 2570 | '</div></div>'; |
| 2985 | 2571 | |
| 2986 | 2572 | $redirect_args = array( |
| 2987 | 2573 | 'entry_id' => $args['entry_id'], |
| @@ -2992,31 +2578,8 @@ | ||
| 2992 | 2578 | return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args ); |
| 2993 | 2579 | } |
| 2994 | 2580 | |
| 2995 | 2581 | /** |
| 2996 | - * Gets fallback message when redirecting failed. | |
| 2997 | - * | |
| 2998 | - * @since 6.3.1 | |
| 2999 | - * | |
| 3000 | - * @param string $success_url Redirect URL. | |
| 3001 | - * @param array $args Contains `form` object. | |
| 3002 | - * @return string | |
| 3003 | - */ | |
| 3004 | - private static function get_redirect_fallback_message( $success_url, $args ) { | |
| 3005 | - $target = ''; | |
| 3006 | - if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { | |
| 3007 | - $target = ' target="_blank"'; | |
| 3008 | - } | |
| 3009 | - | |
| 3010 | - return sprintf( | |
| 3011 | - /* translators: %1$s: Start link HTML, %2$s: End link HTML */ | |
| 3012 | - __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), | |
| 3013 | - '<a href="' . esc_url( $success_url ) . '"' . $target . '>', | |
| 3014 | - '</a>' | |
| 3015 | - ); | |
| 3016 | - } | |
| 3017 | - | |
| 3018 | - /** | |
| 3019 | 2582 | * Prepare to show the success message and empty form after submit |
| 3020 | 2583 | * |
| 3021 | 2584 | * @since 2.05 |
| 3022 | 2585 | */ |
| @@ -3035,9 +2598,9 @@ | ||
| 3035 | 2598 | } else { |
| 3036 | 2599 | self::show_form_after_submit( $atts ); |
| 3037 | 2600 | } |
| 3038 | 2601 | } else { |
| 3039 | - self::show_lone_success_message( $atts ); | |
| 2602 | + self::show_lone_success_messsage( $atts ); | |
| 3040 | 2603 | } |
| 3041 | 2604 | } |
| 3042 | 2605 | |
| 3043 | 2606 | /** |
| @@ -3065,9 +2628,9 @@ | ||
| 3065 | 2628 | |
| 3066 | 2629 | $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form ); |
| 3067 | 2630 | |
| 3068 | 2631 | $frm_settings = FrmAppHelper::get_settings(); |
| 3069 | - $submit = $form->options['submit_value'] ?? $frm_settings->submit_value; | |
| 2632 | + $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value; | |
| 3070 | 2633 | |
| 3071 | 2634 | global $frm_vars; |
| 3072 | 2635 | self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] ); |
| 3073 | 2636 | |
| @@ -3076,10 +2639,11 @@ | ||
| 3076 | 2639 | include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php'; |
| 3077 | 2640 | } |
| 3078 | 2641 | |
| 3079 | 2642 | /** |
| 2643 | + * @return string - 'before', 'after', or 'submit' | |
| 2644 | + * | |
| 3080 | 2645 | * @since 4.05.02 |
| 3081 | - * @return string - 'before', 'after', or 'submit' | |
| 3082 | 2646 | */ |
| 3083 | 2647 | private static function message_placement( $form, $message ) { |
| 3084 | 2648 | $place = 'before'; |
| 3085 | 2649 | |
| @@ -3091,10 +2655,11 @@ | ||
| 3091 | 2655 | } |
| 3092 | 2656 | } |
| 3093 | 2657 | |
| 3094 | 2658 | /** |
| 2659 | + * @return string - 'before' or 'after' | |
| 2660 | + * | |
| 3095 | 2661 | * @since 4.05.02 |
| 3096 | - * @return string - 'before' or 'after' | |
| 3097 | 2662 | */ |
| 3098 | 2663 | return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) ); |
| 3099 | 2664 | } |
| 3100 | 2665 | |
| @@ -3128,9 +2693,9 @@ | ||
| 3128 | 2693 | * Show the success message without the form |
| 3129 | 2694 | * |
| 3130 | 2695 | * @since 2.05 |
| 3131 | 2696 | */ |
| 3132 | - private static function show_lone_success_message( $atts ) { | |
| 2697 | + private static function show_lone_success_messsage( $atts ) { | |
| 3133 | 2698 | global $frm_vars; |
| 3134 | 2699 | $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true ); |
| 3135 | 2700 | self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] ); |
| 3136 | 2701 | |
| @@ -3139,9 +2704,9 @@ | ||
| 3139 | 2704 | $errors = array(); |
| 3140 | 2705 | $form = $atts['form']; |
| 3141 | 2706 | $message = $atts['message']; |
| 3142 | 2707 | |
| 3143 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php'; | |
| 2708 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' ); | |
| 3144 | 2709 | } |
| 3145 | 2710 | |
| 3146 | 2711 | /** |
| 3147 | 2712 | * Prepare the success message before it's shown |
| @@ -3155,12 +2720,12 @@ | ||
| 3155 | 2720 | * @return string |
| 3156 | 2721 | */ |
| 3157 | 2722 | private static function prepare_submit_message( $form, $entry_id, $args = array() ) { |
| 3158 | 2723 | $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) ); |
| 3159 | - $opt = $args['success_opt'] ?? 'success'; | |
| 2724 | + $opt = isset( $args['success_opt'] ) ? $args['success_opt'] : 'success'; | |
| 3160 | 2725 | |
| 3161 | 2726 | if ( $entry_id && is_numeric( $entry_id ) ) { |
| 3162 | - $message = $form->options[ $opt . '_msg' ] ?? $frm_settings->success_msg; | |
| 2727 | + $message = isset( $form->options[ $opt . '_msg' ] ) ? $form->options[ $opt . '_msg' ] : $frm_settings->success_msg; | |
| 3163 | 2728 | $class = 'frm_message'; |
| 3164 | 2729 | } else { |
| 3165 | 2730 | $message = $frm_settings->failed_msg; |
| 3166 | 2731 | $class = FrmFormsHelper::form_error_class(); |
| @@ -3261,13 +2826,11 @@ | ||
| 3261 | 2826 | global $frm_vars; |
| 3262 | 2827 | |
| 3263 | 2828 | FrmStylesController::enqueue_css(); |
| 3264 | 2829 | |
| 3265 | - if ( ! FrmAppHelper::is_admin() && $location !== 'header' && ! empty( $frm_vars['forms_loaded'] ) ) { | |
| 2830 | + if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) { | |
| 3266 | 2831 | // load formidable js |
| 3267 | 2832 | wp_enqueue_script( 'formidable' ); |
| 3268 | - | |
| 3269 | - FrmHoneypot::maybe_print_honeypot_js(); | |
| 3270 | 2833 | } |
| 3271 | 2834 | } |
| 3272 | 2835 | |
| 3273 | 2836 | /** |
| @@ -3281,12 +2844,12 @@ | ||
| 3281 | 2844 | } |
| 3282 | 2845 | |
| 3283 | 2846 | /** |
| 3284 | 2847 | * @since 2.0.8 |
| 3285 | - * @return bool | |
| 2848 | + * @return boolean | |
| 3286 | 2849 | */ |
| 3287 | 2850 | private static function is_minification_on( $atts ) { |
| 3288 | - return ! empty( $atts['minimize'] ); | |
| 2851 | + return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] ); | |
| 3289 | 2852 | } |
| 3290 | 2853 | |
| 3291 | 2854 | /** |
| 3292 | 2855 | * @since 5.0.16 |
| @@ -3314,9 +2877,9 @@ | ||
| 3314 | 2877 | * Create a page with an embedded formidable Gutenberg block. |
| 3315 | 2878 | * |
| 3316 | 2879 | * @since 5.2 |
| 3317 | 2880 | * |
| 3318 | - * @return void | |
| 2881 | + * @return never | |
| 3319 | 2882 | */ |
| 3320 | 2883 | public static function create_page_with_shortcode() { |
| 3321 | 2884 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3322 | 2885 | die( 0 ); |
| @@ -3361,9 +2924,10 @@ | ||
| 3361 | 2924 | |
| 3362 | 2925 | /** |
| 3363 | 2926 | * @since 5.3 |
| 3364 | 2927 | * |
| 3365 | - * @param int $form_id | |
| 2928 | + * @param string $content | |
| 2929 | + * @param int $form_id | |
| 3366 | 2930 | * @return string |
| 3367 | 2931 | */ |
| 3368 | 2932 | private static function get_page_shortcode_content_for_form( $form_id ) { |
| 3369 | 2933 | $shortcode = '[formidable id="' . $form_id . '"]'; |
| @@ -3374,9 +2938,9 @@ | ||
| 3374 | 2938 | |
| 3375 | 2939 | /** |
| 3376 | 2940 | * Get page dropdown for AJAX request for embedding form in an existing page. |
| 3377 | 2941 | * |
| 3378 | - * @return void | |
| 2942 | + * @return never | |
| 3379 | 2943 | */ |
| 3380 | 2944 | public static function get_page_dropdown() { |
| 3381 | 2945 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3382 | 2946 | die( 0 ); |
| @@ -3384,9 +2948,9 @@ | ||
| 3384 | 2948 | |
| 3385 | 2949 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 3386 | 2950 | |
| 3387 | 2951 | $html = FrmAppHelper::clip( |
| 3388 | - function () { | |
| 2952 | + function() { | |
| 3389 | 2953 | FrmAppHelper::maybe_autocomplete_pages_options( |
| 3390 | 2954 | array( |
| 3391 | 2955 | 'field_name' => 'frm_page_dropdown', |
| 3392 | 2956 | 'page_id' => '', |
| @@ -3406,8 +2970,15 @@ | ||
| 3406 | 2970 | |
| 3407 | 2971 | /** |
| 3408 | 2972 | * @deprecated 4.0 |
| 3409 | 2973 | */ |
| 2974 | + public static function new_form( $values = array() ) { | |
| 2975 | + FrmDeprecated::new_form( $values ); | |
| 2976 | + } | |
| 2977 | + | |
| 2978 | + /** | |
| 2979 | + * @deprecated 4.0 | |
| 2980 | + */ | |
| 3410 | 2981 | public static function create( $values = array() ) { |
| 3411 | 2982 | _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' ); |
| 3412 | 2983 | self::update( $values ); |
| 3413 | 2984 | } |
| @@ -3412,16 +2983,35 @@ | ||
| 3412 | 2983 | self::update( $values ); |
| 3413 | 2984 | } |
| 3414 | 2985 | |
| 3415 | 2986 | /** |
| 3416 | - * Education for premium features. | |
| 3417 | - * | |
| 3418 | - * @since 4.05 | |
| 3419 | - * @deprecated 6.16.3 | |
| 3420 | - * | |
| 3421 | - * @return void | |
| 2987 | + * @deprecated 3.0 | |
| 2988 | + * @codeCoverageIgnore | |
| 3422 | 2989 | */ |
| 3423 | - public static function add_form_style_tab_options() { | |
| 3424 | - _deprecated_function( __METHOD__, '6.16.3' ); | |
| 3425 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php'; | |
| 2990 | + public static function bulk_create_template( $ids ) { | |
| 2991 | + return FrmDeprecated::bulk_create_template( $ids ); | |
| 2992 | + } | |
| 2993 | + | |
| 2994 | + /** | |
| 2995 | + * @deprecated 3.0 | |
| 2996 | + * @codeCoverageIgnore | |
| 2997 | + */ | |
| 2998 | + public static function edit_key() { | |
| 2999 | + FrmDeprecated::edit_key(); | |
| 3000 | + } | |
| 3001 | + | |
| 3002 | + /** | |
| 3003 | + * @deprecated 3.0 | |
| 3004 | + * @codeCoverageIgnore | |
| 3005 | + */ | |
| 3006 | + public static function edit_description() { | |
| 3007 | + FrmDeprecated::edit_description(); | |
| 3008 | + } | |
| 3009 | + | |
| 3010 | + /** | |
| 3011 | + * @deprecated 4.08 | |
| 3012 | + * @since 3.06 | |
| 3013 | + */ | |
| 3014 | + public static function add_new() { | |
| 3015 | + _deprecated_function( __FUNCTION__, '4.08' ); | |
| 3426 | 3016 | } |
| 3427 | 3017 | } |