| @@ -15,8 +15,10 @@ | ||
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | $menu_name = FrmAppHelper::get_menu_name(); |
| 18 | 18 | add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() ); |
| 19 | + | |
| 20 | + self::maybe_add_black_friday_submenu_item(); | |
| 19 | 21 | } |
| 20 | 22 | |
| 21 | 23 | /** |
| 22 | 24 | * @return int |
| @@ -40,8 +42,84 @@ | ||
| 40 | 42 | return apply_filters( 'frm_icon', $icon ); |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | 45 | /** |
| 46 | + * @since 6.16 | |
| 47 | + * | |
| 48 | + * @return void | |
| 49 | + */ | |
| 50 | + private static function maybe_add_black_friday_submenu_item() { | |
| 51 | + if ( ! current_user_can( 'frm_change_settings' ) ) { | |
| 52 | + return; | |
| 53 | + } | |
| 54 | + | |
| 55 | + $is_black_friday = self::is_black_friday(); | |
| 56 | + $is_cyber_monday = self::is_cyber_monday(); | |
| 57 | + | |
| 58 | + if ( ! $is_black_friday && ! $is_cyber_monday ) { | |
| 59 | + return; | |
| 60 | + } | |
| 61 | + | |
| 62 | + $black_friday_menu_label = $is_black_friday ? __( 'Black Friday!', 'formidable' ) : __( 'Cyber Monday!', 'formidable' ); | |
| 63 | + $black_friday_menu_label = '<span class="frm-orange-text">' . esc_html( $black_friday_menu_label ) . '</span>'; | |
| 64 | + | |
| 65 | + add_action( | |
| 66 | + 'admin_menu', | |
| 67 | + function () use ( $black_friday_menu_label ) { | |
| 68 | + add_submenu_page( | |
| 69 | + 'formidable', | |
| 70 | + 'Formidable', | |
| 71 | + $black_friday_menu_label, | |
| 72 | + 'frm_change_settings', | |
| 73 | + 'formidable-black-friday', | |
| 74 | + function () { | |
| 75 | + // This function should do nothing. The redirect is handled earlier to avoid header conflicts. | |
| 76 | + } | |
| 77 | + ); | |
| 78 | + }, | |
| 79 | + 1000 | |
| 80 | + ); | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Black Friday sale is from November 25 to 29. | |
| 85 | + * | |
| 86 | + * @since 6.16 | |
| 87 | + * | |
| 88 | + * @return bool | |
| 89 | + */ | |
| 90 | + private static function is_black_friday() { | |
| 91 | + return self::within_sale_date_range( '2024-11-25', '2024-11-29' ); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Cyber Monday sale rules from November 30 to December 4. | |
| 96 | + * | |
| 97 | + * @since 6.16 | |
| 98 | + * | |
| 99 | + * @return bool | |
| 100 | + */ | |
| 101 | + private static function is_cyber_monday() { | |
| 102 | + return self::within_sale_date_range( '2024-11-30', '2024-12-04' ); | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * Check if the current time is within a sale date range. | |
| 107 | + * Our sales are based on Eastern Time, so we use New York's timezone. | |
| 108 | + * | |
| 109 | + * @since 6.16 | |
| 110 | + * | |
| 111 | + * @param string $from The beginning of the date range. Y-m-d format is expected. | |
| 112 | + * @param string $to The end of the date range. Y-m-d format is expected. | |
| 113 | + * @return bool | |
| 114 | + */ | |
| 115 | + private static function within_sale_date_range( $from, $to ) { | |
| 116 | + $date = new DateTime( 'now', new DateTimeZone( 'America/New_York' ) ); | |
| 117 | + $today = $date->format( 'Y-m-d' ); | |
| 118 | + return $today >= $from && $today <= $to; | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 44 | 122 | * @since 3.0 |
| 45 | 123 | */ |
| 46 | 124 | public static function add_admin_class( $classes ) { |
| 47 | 125 | if ( self::is_white_page() ) { |
| @@ -61,14 +139,20 @@ | ||
| 61 | 139 | $classes .= ' frm-admin-page-' . $page; |
| 62 | 140 | } |
| 63 | 141 | } |
| 64 | 142 | |
| 143 | + if ( self::is_grey_page() ) { | |
| 144 | + $classes .= ' frm-grey-body '; | |
| 145 | + } | |
| 146 | + | |
| 65 | 147 | if ( FrmAppHelper::is_full_screen() ) { |
| 66 | 148 | $full_screen_on = self::get_full_screen_setting(); |
| 67 | - $add_class = ''; | |
| 149 | + $add_class = ''; | |
| 68 | 150 | if ( $full_screen_on ) { |
| 69 | 151 | $add_class = ' frm-full-screen is-fullscreen-mode'; |
| 70 | - wp_enqueue_style( 'wp-edit-post' ); // Load the CSS for .is-fullscreen-mode. | |
| 152 | + | |
| 153 | + // Load the CSS for .is-fullscreen-mode. | |
| 154 | + wp_enqueue_style( 'wp-edit-post' ); | |
| 71 | 155 | } |
| 72 | 156 | $classes .= apply_filters( 'frm_admin_full_screen_class', $add_class ); |
| 73 | 157 | } |
| 74 | 158 | |
| @@ -75,8 +159,12 @@ | ||
| 75 | 159 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 76 | 160 | $classes .= ' frm-lite '; |
| 77 | 161 | } |
| 78 | 162 | |
| 163 | + if ( get_user_setting( 'unfold' ) && 'f' !== get_user_setting( 'mfold' ) ) { | |
| 164 | + $classes .= ' frm-unfold '; | |
| 165 | + } | |
| 166 | + | |
| 79 | 167 | return $classes; |
| 80 | 168 | } |
| 81 | 169 | |
| 82 | 170 | /** |
| @@ -124,9 +212,8 @@ | ||
| 124 | 212 | 'formidable', |
| 125 | 213 | 'formidable-entries', |
| 126 | 214 | 'formidable-views', |
| 127 | 215 | 'formidable-views-editor', |
| 128 | - 'formidable-pro-upgrade', | |
| 129 | 216 | 'formidable-addons', |
| 130 | 217 | 'formidable-import', |
| 131 | 218 | 'formidable-settings', |
| 132 | 219 | 'formidable-styles', |
| @@ -131,20 +218,25 @@ | ||
| 131 | 218 | 'formidable-settings', |
| 132 | 219 | 'formidable-styles', |
| 133 | 220 | 'formidable-styles2', |
| 134 | 221 | 'formidable-inbox', |
| 135 | - 'formidable-welcome', | |
| 136 | - 'formidable-applications', | |
| 222 | + FrmFormTemplatesController::PAGE_SLUG, | |
| 223 | + FrmOnboardingWizardController::PAGE_SLUG, | |
| 137 | 224 | ); |
| 138 | 225 | |
| 139 | - $get_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 140 | - $is_white_page = in_array( $get_page, $white_pages, true ); | |
| 226 | + if ( ! class_exists( 'FrmTransHooksController', false ) && ! FrmTransLiteAppHelper::should_fallback_to_paypal() ) { | |
| 227 | + // Only consider the payments page as a "white page" when the Payments submodule is off. | |
| 228 | + // Otherwise this causes a lot of styling issues when the Stripe add-on (or Authorize.Net) is active. | |
| 141 | 229 | |
| 142 | - if ( ! $is_white_page ) { | |
| 143 | - $screen = get_current_screen(); | |
| 144 | - $is_white_page = ( $screen && strpos( $screen->id, 'frm_display' ) !== false ); | |
| 230 | + // Add an extra check to avoid white page styling on the PayPal "edit" action. | |
| 231 | + // We fallback to the PayPal add on for the "edit" action since Stripe Lite does not have an edit view. | |
| 232 | + if ( ! in_array( FrmAppHelper::simple_get( 'action' ), array( 'edit', 'new' ), true ) || ! is_callable( 'FrmPaymentsController::route' ) ) { | |
| 233 | + $white_pages[] = 'formidable-payments'; | |
| 234 | + } | |
| 145 | 235 | } |
| 146 | 236 | |
| 237 | + $is_white_page = self::is_page_in_list( $white_pages ) || self::is_grey_page() || FrmAppHelper::is_view_builder_page(); | |
| 238 | + | |
| 147 | 239 | /** |
| 148 | 240 | * Allow another add on to style a page as a Formidable "white page", which adds a white background color. |
| 149 | 241 | * |
| 150 | 242 | * @since 5.3 |
| @@ -156,8 +248,45 @@ | ||
| 156 | 248 | return $is_white_page; |
| 157 | 249 | } |
| 158 | 250 | |
| 159 | 251 | /** |
| 252 | + * Add a grey bg instead of white. | |
| 253 | + * | |
| 254 | + * @since 6.8 | |
| 255 | + * | |
| 256 | + * @return bool | |
| 257 | + */ | |
| 258 | + private static function is_grey_page() { | |
| 259 | + $grey_pages = array( | |
| 260 | + 'formidable-applications', | |
| 261 | + 'formidable-dashboard', | |
| 262 | + ); | |
| 263 | + | |
| 264 | + $is_grey_page = self::is_page_in_list( $grey_pages ); | |
| 265 | + | |
| 266 | + /** | |
| 267 | + * Filter to change FF wrapper background to grey. | |
| 268 | + * | |
| 269 | + * @since 6.8 | |
| 270 | + * | |
| 271 | + * @param bool $is_grey_page | |
| 272 | + * @return bool | |
| 273 | + */ | |
| 274 | + return apply_filters( 'frm_is_grey_page', $is_grey_page ); | |
| 275 | + } | |
| 276 | + | |
| 277 | + /** | |
| 278 | + * @since 6.8 | |
| 279 | + * | |
| 280 | + * @param array $pages A list of page names to check. | |
| 281 | + * @return bool | |
| 282 | + */ | |
| 283 | + private static function is_page_in_list( $pages ) { | |
| 284 | + $get_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 285 | + return in_array( $get_page, $pages, true ); | |
| 286 | + } | |
| 287 | + | |
| 288 | + /** | |
| 160 | 289 | * @return void |
| 161 | 290 | */ |
| 162 | 291 | public static function load_wp_admin_style() { |
| 163 | 292 | FrmAppHelper::load_font_style(); |
| @@ -163,10 +292,11 @@ | ||
| 163 | 292 | FrmAppHelper::load_font_style(); |
| 164 | 293 | } |
| 165 | 294 | |
| 166 | 295 | /** |
| 167 | - * @param bool $show_nav | |
| 168 | - * @param string $title | |
| 296 | + * @param int|object $form | |
| 297 | + * @param bool $show_nav | |
| 298 | + * @param string $title | |
| 169 | 299 | * |
| 170 | 300 | * @psalm-param 'hide'|'show' $title |
| 171 | 301 | * |
| 172 | 302 | * @return void |
| @@ -185,9 +315,9 @@ | ||
| 185 | 315 | $id = $form->id; |
| 186 | 316 | $current_page = self::get_current_page(); |
| 187 | 317 | $nav_items = self::get_form_nav_items( $form ); |
| 188 | 318 | |
| 189 | - include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' ); | |
| 319 | + include FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php'; | |
| 190 | 320 | } |
| 191 | 321 | |
| 192 | 322 | /** |
| 193 | 323 | * @return string |
| @@ -241,18 +371,18 @@ | ||
| 241 | 371 | 'permission' => 'frm_view_entries', |
| 242 | 372 | ), |
| 243 | 373 | ); |
| 244 | 374 | |
| 245 | - $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed(); | |
| 375 | + $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed(); | |
| 246 | 376 | |
| 247 | 377 | if ( ! $views_installed ) { |
| 248 | 378 | $nav_items[] = array( |
| 249 | - 'link' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $id ) ), | |
| 250 | - 'label' => __( 'Views', 'formidable' ), | |
| 251 | - 'current' => array(), | |
| 252 | - 'page' => 'formidable-views', | |
| 379 | + 'link' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $id ) ), | |
| 380 | + 'label' => __( 'Views', 'formidable' ), | |
| 381 | + 'current' => array(), | |
| 382 | + 'page' => 'formidable-views', | |
| 253 | 383 | 'permission' => 'frm_view_entries', |
| 254 | - 'atts' => array( | |
| 384 | + 'atts' => array( | |
| 255 | 385 | 'class' => 'frm_noallow', |
| 256 | 386 | ), |
| 257 | 387 | ); |
| 258 | 388 | } |
| @@ -259,14 +389,14 @@ | ||
| 259 | 389 | |
| 260 | 390 | // Let people know reports and views exist. |
| 261 | 391 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 262 | 392 | $nav_items[] = array( |
| 263 | - 'link' => admin_url( 'admin.php?page=formidable&frm_action=lite-reports&form=' . absint( $id ) ), | |
| 264 | - 'label' => __( 'Reports', 'formidable' ), | |
| 265 | - 'current' => array( 'reports' ), | |
| 266 | - 'page' => 'formidable', | |
| 393 | + 'link' => admin_url( 'admin.php?page=formidable&frm_action=lite-reports&form=' . absint( $id ) ), | |
| 394 | + 'label' => __( 'Reports', 'formidable' ), | |
| 395 | + 'current' => array( 'reports' ), | |
| 396 | + 'page' => 'formidable', | |
| 267 | 397 | 'permission' => 'frm_view_entries', |
| 268 | - 'atts' => array( | |
| 398 | + 'atts' => array( | |
| 269 | 399 | 'class' => 'frm_noallow', |
| 270 | 400 | ), |
| 271 | 401 | ); |
| 272 | 402 | } |
| @@ -286,9 +416,10 @@ | ||
| 286 | 416 | public static function settings_link( $links ) { |
| 287 | 417 | $settings = array(); |
| 288 | 418 | |
| 289 | 419 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 290 | - $settings[] = '<a href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-row' ) ) . '" target="_blank" rel="noopener"><b>' . esc_html__( 'Upgrade to Pro', 'formidable' ) . '</b></a>'; | |
| 420 | + $label = FrmAddonsController::is_license_expired() ? __( 'Renew', 'formidable' ) : __( 'Upgrade to Pro', 'formidable' ); | |
| 421 | + $settings[] = '<a href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-row' ) ) . '" target="_blank" rel="noopener"><b style="color:#1da867;font-weight:700;">' . esc_html( $label ) . '</b></a>'; | |
| 291 | 422 | } |
| 292 | 423 | |
| 293 | 424 | $settings[] = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>'; |
| 294 | 425 | |
| @@ -299,9 +430,9 @@ | ||
| 299 | 430 | * @return void |
| 300 | 431 | */ |
| 301 | 432 | public static function pro_get_started_headline() { |
| 302 | 433 | self::review_request(); |
| 303 | - FrmAppHelper::min_pro_version_notice( '4.0' ); | |
| 434 | + FrmAppHelper::min_pro_version_notice( '6.0' ); | |
| 304 | 435 | } |
| 305 | 436 | |
| 306 | 437 | /** |
| 307 | 438 | * Add admin notices as needed for reviews |
| @@ -368,63 +499,26 @@ | ||
| 368 | 499 | $shared_path = $plugin_path . '/classes/views/shared/'; |
| 369 | 500 | |
| 370 | 501 | include $shared_path . 'upgrade_overlay.php'; |
| 371 | 502 | include $shared_path . 'confirm-overlay.php'; |
| 372 | - | |
| 373 | - if ( FrmAppHelper::is_admin_page( 'formidable-welcome' ) || FrmAppHelper::on_form_listing_page() ) { | |
| 374 | - self::new_form_overlay_html(); | |
| 375 | - } | |
| 376 | 503 | } |
| 377 | 504 | |
| 378 | 505 | /** |
| 506 | + * Create a basic form with an email field. | |
| 507 | + * | |
| 508 | + * @param string $form_key | |
| 509 | + * @param string $title | |
| 510 | + * @param string $description | |
| 379 | 511 | * @return void |
| 380 | 512 | */ |
| 381 | - private static function new_form_overlay_html() { | |
| 382 | - FrmFormsController::before_list_templates(); | |
| 383 | - | |
| 384 | - $plugin_path = FrmAppHelper::plugin_path(); | |
| 385 | - $path = $plugin_path . '/classes/views/frm-forms/'; | |
| 386 | - $expired = FrmFormsController::expired(); | |
| 387 | - $expiring = FrmAddonsController::is_license_expiring(); | |
| 388 | - $user = wp_get_current_user(); // $user used in leave-email.php to determine a default value for field | |
| 389 | - $view_path = $path . 'new-form-overlay/'; | |
| 390 | - $modal_class = ''; | |
| 391 | - $upgrade_link = FrmAppHelper::admin_upgrade_link( | |
| 392 | - array( | |
| 393 | - 'medium' => 'new-template', | |
| 394 | - 'content' => 'upgrade', | |
| 395 | - ) | |
| 513 | + public static function api_email_form( $form_key, $title = '', $description = '' ) { | |
| 514 | + $user = wp_get_current_user(); | |
| 515 | + $args = array( | |
| 516 | + 'api_url' => 'https://sandbox.formidableforms.com/api/wp-json/frm/v2/forms/' . $form_key . '?return=html&exclude_script=jquery&exclude_style=formidable-css', | |
| 517 | + 'title' => $title, | |
| 518 | + 'description' => $description, | |
| 396 | 519 | ); |
| 397 | - $renew_link = FrmAppHelper::admin_upgrade_link( | |
| 398 | - array( | |
| 399 | - 'medium' => 'new-template', | |
| 400 | - 'content' => 'renew', | |
| 401 | - ) | |
| 402 | - ); | |
| 403 | - $blocks_to_render = array(); | |
| 404 | - | |
| 405 | - if ( ! FrmAppHelper::pro_is_installed() ) { | |
| 406 | - // avoid rendering the email and code blocks for users who have upgraded or have a free license already | |
| 407 | - $api = new FrmFormTemplateApi(); | |
| 408 | - if ( ! $api->has_free_access() ) { | |
| 409 | - array_push( $blocks_to_render, 'email', 'code' ); | |
| 410 | - } | |
| 411 | - } | |
| 412 | - | |
| 413 | - // avoid rendering the upgrade block for users with elite | |
| 414 | - if ( 'elite' !== FrmAddonsController::license_type() ) { | |
| 415 | - $blocks_to_render[] = 'upgrade'; | |
| 416 | - } | |
| 417 | - | |
| 418 | - // avoid rendering the renew block for users who are not currently expired | |
| 419 | - if ( $expired ) { | |
| 420 | - $blocks_to_render[] = 'renew'; | |
| 421 | - $modal_class = 'frm-expired'; | |
| 422 | - } elseif ( $expiring ) { | |
| 423 | - $modal_class = 'frm-expiring'; | |
| 424 | - } | |
| 425 | - | |
| 426 | - include $path . 'new-form-overlay.php'; | |
| 520 | + require FrmAppHelper::plugin_path() . '/classes/views/form-templates/modals/leave-email-modal.php'; | |
| 427 | 521 | } |
| 428 | 522 | |
| 429 | 523 | /** |
| 430 | 524 | * @return void |
| @@ -472,9 +566,9 @@ | ||
| 472 | 566 | /** |
| 473 | 567 | * Check if the database is outdated |
| 474 | 568 | * |
| 475 | 569 | * @since 2.0.1 |
| 476 | - * @return boolean | |
| 570 | + * @return bool | |
| 477 | 571 | */ |
| 478 | 572 | public static function needs_update() { |
| 479 | 573 | $needs_upgrade = self::compare_for_update( |
| 480 | 574 | array( |
| @@ -521,8 +615,12 @@ | ||
| 521 | 615 | * |
| 522 | 616 | * @return void |
| 523 | 617 | */ |
| 524 | 618 | public static function admin_init() { |
| 619 | + if ( FrmAppHelper::get_param( 'delete_all' ) && FrmAppHelper::is_admin_page( 'formidable' ) && 'trash' === FrmAppHelper::get_param( 'form_type' ) ) { | |
| 620 | + FrmFormsController::delete_all(); | |
| 621 | + } | |
| 622 | + | |
| 525 | 623 | if ( FrmAppHelper::is_admin_page( 'formidable' ) && 'duplicate' === FrmAppHelper::get_param( 'frm_action' ) ) { |
| 526 | 624 | FrmFormsController::duplicate(); |
| 527 | 625 | } |
| 528 | 626 | |
| @@ -530,10 +628,36 @@ | ||
| 530 | 628 | // Hook in earlier than FrmStylesController::route so we can redirect before the headers have been sent. |
| 531 | 629 | FrmStylesController::save_style(); |
| 532 | 630 | } |
| 533 | 631 | |
| 534 | - new FrmPersonalData(); // register personal data hooks | |
| 632 | + if ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) && ! FrmAppHelper::pro_is_installed() && current_user_can( 'frm_view_forms' ) ) { | |
| 633 | + wp_redirect( | |
| 634 | + FrmAppHelper::admin_upgrade_link( | |
| 635 | + array( | |
| 636 | + 'medium' => 'upgrade', | |
| 637 | + 'content' => 'submenu-upgrade', | |
| 638 | + ) | |
| 639 | + ) | |
| 640 | + ); | |
| 641 | + die(); | |
| 642 | + } | |
| 535 | 643 | |
| 644 | + if ( 'formidable-black-friday' === FrmAppHelper::get_param( 'page' ) && current_user_can( 'frm_change_settings' ) ) { | |
| 645 | + wp_redirect( | |
| 646 | + FrmAppHelper::admin_upgrade_link( | |
| 647 | + array( | |
| 648 | + 'medium' => 'black-friday-submenu', | |
| 649 | + 'content' => self::is_cyber_monday() ? 'cyber-monday-submenu' : 'black-friday-submenu', | |
| 650 | + ), | |
| 651 | + 'black-friday' | |
| 652 | + ) | |
| 653 | + ); | |
| 654 | + die(); | |
| 655 | + } | |
| 656 | + | |
| 657 | + // Register personal data hooks. | |
| 658 | + new FrmPersonalData(); | |
| 659 | + | |
| 536 | 660 | if ( ! FrmAppHelper::doing_ajax() && self::needs_update() ) { |
| 537 | 661 | self::network_upgrade_site(); |
| 538 | 662 | } |
| 539 | 663 | |
| @@ -541,82 +665,51 @@ | ||
| 541 | 665 | // don't continue during ajax calls |
| 542 | 666 | self::admin_js(); |
| 543 | 667 | } |
| 544 | 668 | |
| 669 | + self::trigger_page_load_hooks(); | |
| 670 | + | |
| 545 | 671 | if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| 546 | - $action = FrmAppHelper::get_param( 'frm_action' ); | |
| 672 | + // Redirect to the "Form Templates" page if the 'frm_action' parameter matches specific actions. | |
| 673 | + // This provides backward compatibility for old addons that use legacy modal templates. | |
| 674 | + $action = FrmAppHelper::get_param( 'frm_action' ); | |
| 675 | + $trigger_name_modal = FrmAppHelper::get_param( 'triggerNewFormModal' ); | |
| 676 | + if ( $trigger_name_modal || in_array( $action, array( 'add_new', 'list_templates' ), true ) ) { | |
| 677 | + $application_id = FrmAppHelper::simple_get( 'applicationId', 'absint' ); | |
| 678 | + $url_param = $application_id ? '&applicationId=' . $application_id : ''; | |
| 547 | 679 | |
| 548 | - if ( in_array( $action, array( 'add_new', 'list_templates' ), true ) ) { | |
| 549 | - wp_safe_redirect( admin_url( 'admin.php?page=formidable&triggerNewFormModal=1' ) ); | |
| 680 | + wp_safe_redirect( admin_url( 'admin.php?page=' . FrmFormTemplatesController::PAGE_SLUG . $url_param ) ); | |
| 550 | 681 | exit; |
| 551 | 682 | } |
| 552 | 683 | |
| 553 | 684 | FrmInbox::maybe_disable_screen_options(); |
| 554 | 685 | } |
| 555 | - | |
| 556 | - self::maybe_add_ip_warning(); | |
| 557 | 686 | } |
| 558 | 687 | |
| 559 | 688 | /** |
| 560 | - * Show a warning for the IP address setting if it hasn't been set. | |
| 689 | + * Get the current page and check for a possible function to trigger. | |
| 690 | + * If a class name matches the page name, and the class has a load_page() method, trigger it. | |
| 561 | 691 | * |
| 562 | - * @since 6.1 | |
| 692 | + * @since 6.8 | |
| 563 | 693 | * |
| 564 | 694 | * @return void |
| 565 | 695 | */ |
| 566 | - private static function maybe_add_ip_warning() { | |
| 567 | - $settings = FrmAppHelper::get_settings(); | |
| 568 | - if ( false !== $settings->custom_header_ip ) { | |
| 569 | - // The setting has been changed from the false default (to either 1 or 0), so stop showing the message. | |
| 696 | + private static function trigger_page_load_hooks() { | |
| 697 | + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 698 | + if ( strpos( $page, 'formidable-' ) !== 0 ) { | |
| 699 | + // Only trigger hooks on Formidable pages. | |
| 570 | 700 | return; |
| 571 | 701 | } |
| 572 | 702 | |
| 573 | - if ( ! self::is_behind_proxy() ) { | |
| 574 | - // This message is only applicable when using a reverse proxy. | |
| 575 | - return; | |
| 703 | + $page = str_replace( array( 'formidable-', '-' ), array( '', ' ' ), $page ); | |
| 704 | + $page = str_replace( ' ', '', ucwords( $page ) ); | |
| 705 | + $class = 'Frm' . $page . 'Controller'; | |
| 706 | + if ( class_exists( $class ) && method_exists( $class, 'load_page' ) ) { | |
| 707 | + call_user_func( array( $class, 'load_page' ) ); | |
| 576 | 708 | } |
| 577 | - | |
| 578 | - if ( FrmAppHelper::get_post_param( 'frm_action', '', 'sanitize_text_field' ) ) { | |
| 579 | - // Avoid the message on a POST action. We don't want to show the message if we're saving global settings. | |
| 580 | - return; | |
| 581 | - } | |
| 582 | - | |
| 583 | - $global_settings_link = admin_url( 'admin.php?page=formidable-settings' ) . '#frm_custom_header_ip'; | |
| 584 | - $message = sprintf( | |
| 585 | - // Translators: 1: Global Settings Link | |
| 586 | - __( 'IP addresses in form submissions may no longer be accurate! If you are experiencing issues, we recommend going to %1$s and enabling the "Use custom headers when retrieving IPs with form submissions." setting.', 'formidable' ), | |
| 587 | - '<a href="' . esc_url( $global_settings_link ) . '">Global Settings</a>' | |
| 588 | - ); | |
| 589 | - $option_name = 'frm_dismiss_ip_address_notice'; | |
| 590 | - FrmAppHelper::add_dismissable_warning_message( $message, $option_name ); | |
| 591 | 709 | } |
| 592 | 710 | |
| 593 | 711 | /** |
| 594 | - * Check if any reverse proxy headers are set. | |
| 595 | - * | |
| 596 | - * @since 6.1 | |
| 597 | - * | |
| 598 | - * @return bool | |
| 599 | - */ | |
| 600 | - private static function is_behind_proxy() { | |
| 601 | - $custom_headers = FrmAppHelper::get_custom_header_keys_for_ip(); | |
| 602 | - foreach ( $custom_headers as $header ) { | |
| 603 | - if ( 'REMOTE_ADDR' === $header ) { | |
| 604 | - // We want to check every key but REMOTE_ADDR. REMOTE_ATTR is not unique to reverse proxy servers. | |
| 605 | - continue; | |
| 606 | - } | |
| 607 | - | |
| 608 | - $ip = trim( FrmAppHelper::get_server_value( $header ) ); | |
| 609 | - // Return true for anything that isn't empty but ignoring values like ::1. | |
| 610 | - if ( $ip && 0 !== strpos( $ip, '::' ) ) { | |
| 611 | - return true; | |
| 612 | - } | |
| 613 | - } | |
| 614 | - | |
| 615 | - return false; | |
| 616 | - } | |
| 617 | - | |
| 618 | - /** | |
| 619 | 712 | * @return void |
| 620 | 713 | */ |
| 621 | 714 | public static function admin_js() { |
| 622 | 715 | $plugin_url = FrmAppHelper::plugin_url(); |
| @@ -623,8 +716,17 @@ | ||
| 623 | 716 | $version = FrmAppHelper::plugin_version(); |
| 624 | 717 | |
| 625 | 718 | FrmAppHelper::load_admin_wide_js(); |
| 626 | 719 | |
| 720 | + // Register component assets early to ensure they can be enqueued later in controllers. | |
| 721 | + wp_register_style( 'formidable-animations', $plugin_url . '/css/admin/animations.css', array(), $version ); | |
| 722 | + | |
| 723 | + if ( class_exists( 'FrmOverlayController' ) ) { | |
| 724 | + // This should always exist. | |
| 725 | + // But it may not have loaded properly when updating the plugin. | |
| 726 | + FrmOverlayController::register_assets(); | |
| 727 | + } | |
| 728 | + | |
| 627 | 729 | wp_register_style( 'formidable_admin_global', $plugin_url . '/css/admin/frm_admin_global.css', array(), $version ); |
| 628 | 730 | wp_enqueue_style( 'formidable_admin_global' ); |
| 629 | 731 | |
| 630 | 732 | wp_register_style( 'formidable-admin', $plugin_url . '/css/frm_admin.css', array(), $version ); |
| @@ -635,13 +737,10 @@ | ||
| 635 | 737 | self::register_popper1(); |
| 636 | 738 | wp_register_script( 'bootstrap_tooltip', $plugin_url . '/js/bootstrap.min.js', array( 'jquery', 'popper' ), '4.6.1', true ); |
| 637 | 739 | wp_register_script( 'formidable_settings', $plugin_url . '/js/admin/settings.js', array(), $version, true ); |
| 638 | 740 | |
| 639 | - $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 640 | - | |
| 641 | - if ( 'formidable-applications' === $page ) { | |
| 642 | - FrmApplicationsController::load_assets(); | |
| 643 | - return; | |
| 741 | + if ( self::should_show_floating_links() ) { | |
| 742 | + self::enqueue_floating_links( $plugin_url, $version ); | |
| 644 | 743 | } |
| 645 | 744 | |
| 646 | 745 | $dependencies = array( |
| 647 | 746 | 'formidable_admin_global', |
| @@ -651,9 +750,10 @@ | ||
| 651 | 750 | 'jquery-ui-sortable', |
| 652 | 751 | 'bootstrap_tooltip', |
| 653 | 752 | 'bootstrap-multiselect', |
| 654 | 753 | 'wp-i18n', |
| 655 | - 'wp-hooks', // Required in WP versions older than 5.7 | |
| 754 | + // Required in WP versions older than 5.7 | |
| 755 | + 'wp-hooks', | |
| 656 | 756 | 'formidable_dom', |
| 657 | 757 | 'formidable_embed', |
| 658 | 758 | ); |
| 659 | 759 | |
| @@ -670,8 +770,20 @@ | ||
| 670 | 770 | } |
| 671 | 771 | |
| 672 | 772 | wp_register_script( 'bootstrap-multiselect', $plugin_url . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip', 'popper' ), '1.1.1', true ); |
| 673 | 773 | |
| 774 | + if ( ! class_exists( 'FrmTransHooksController', false ) ) { | |
| 775 | + /** | |
| 776 | + * Gateway fields are included for add-on compatibility but we do not want it to be visible. | |
| 777 | + * They do however need to be visible when the payments submodule is active. | |
| 778 | + */ | |
| 779 | + wp_add_inline_style( | |
| 780 | + 'formidable-admin', | |
| 781 | + '#frm_builder_page li[data-ftype="gateway"] { display: none; }' | |
| 782 | + ); | |
| 783 | + } | |
| 784 | + | |
| 785 | + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 674 | 786 | $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ); |
| 675 | 787 | |
| 676 | 788 | global $pagenow; |
| 677 | 789 | if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) { |
| @@ -679,15 +791,18 @@ | ||
| 679 | 791 | wp_enqueue_script( 'admin-widgets' ); |
| 680 | 792 | wp_enqueue_style( 'widgets' ); |
| 681 | 793 | self::maybe_deregister_popper2(); |
| 682 | 794 | wp_enqueue_script( 'formidable_admin' ); |
| 795 | + wp_set_script_translations( 'formidable_admin', 'formidable' ); | |
| 683 | 796 | wp_enqueue_script( 'formidable_embed' ); |
| 797 | + wp_set_script_translations( 'formidable_embed', 'formidable' ); | |
| 684 | 798 | FrmAppHelper::localize_script( 'admin' ); |
| 685 | 799 | |
| 800 | + wp_enqueue_style( 'formidable-animations' ); | |
| 686 | 801 | wp_enqueue_style( 'formidable-admin' ); |
| 687 | 802 | if ( 'formidable-styles' !== $page && 'formidable-styles2' !== $page ) { |
| 688 | 803 | wp_enqueue_style( 'formidable-grids' ); |
| 689 | - wp_enqueue_style( 'formidable-dropzone' ); | |
| 804 | + self::maybe_enqueue_dropzone_css( $page ); | |
| 690 | 805 | } else { |
| 691 | 806 | wp_enqueue_style( 'formidable-grids' ); |
| 692 | 807 | } |
| 693 | 808 | |
| @@ -693,8 +808,12 @@ | ||
| 693 | 808 | |
| 694 | 809 | if ( 'formidable-entries' === $page ) { |
| 695 | 810 | // Load front end js for entries. |
| 696 | 811 | wp_enqueue_script( 'formidable' ); |
| 812 | + | |
| 813 | + // Registers and enqueues the entries page scripts. | |
| 814 | + wp_register_script( 'formidable_entries', $plugin_url . '/js/admin/entries.js', array( 'formidable_admin', 'wp-dom-ready' ), $version, true ); | |
| 815 | + wp_enqueue_script( 'formidable_entries' ); | |
| 697 | 816 | } |
| 698 | 817 | |
| 699 | 818 | do_action( 'frm_enqueue_builder_scripts' ); |
| 700 | 819 | self::include_upgrade_overlay(); |
| @@ -714,10 +833,61 @@ | ||
| 714 | 833 | |
| 715 | 834 | if ( $post_type === 'frm_display' ) { |
| 716 | 835 | self::enqueue_legacy_views_assets(); |
| 717 | 836 | } |
| 837 | + }//end if | |
| 838 | + | |
| 839 | + if ( 'formidable-addons' === $page ) { | |
| 840 | + wp_register_script( 'formidable_addons', $plugin_url . '/js/admin/addons.js', array( 'formidable_admin', 'wp-dom-ready' ), $version, true ); | |
| 841 | + wp_enqueue_script( 'formidable_addons' ); | |
| 718 | 842 | } |
| 843 | + } | |
| 719 | 844 | |
| 845 | + /** | |
| 846 | + * Avoid loading dropzone CSS on the form list page. It isn't required there. | |
| 847 | + * | |
| 848 | + * @since 6.11 | |
| 849 | + * | |
| 850 | + * @param string $page | |
| 851 | + * @return void | |
| 852 | + */ | |
| 853 | + private static function maybe_enqueue_dropzone_css( $page ) { | |
| 854 | + if ( ! FrmAppHelper::pro_is_installed() ) { | |
| 855 | + return; | |
| 856 | + } | |
| 857 | + | |
| 858 | + $should_avoid_loading_dropzone = 'formidable' === $page && ! FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); | |
| 859 | + if ( ! $should_avoid_loading_dropzone ) { | |
| 860 | + wp_enqueue_style( 'formidable-dropzone' ); | |
| 861 | + } | |
| 862 | + } | |
| 863 | + | |
| 864 | + /** | |
| 865 | + * The floating links are not shown on every page. | |
| 866 | + * They are also not shown if white labeling is being used. | |
| 867 | + * | |
| 868 | + * @since 6.8.4 | |
| 869 | + * | |
| 870 | + * @return bool | |
| 871 | + */ | |
| 872 | + private static function should_show_floating_links() { | |
| 873 | + if ( ! FrmAppHelper::is_formidable_branding() ) { | |
| 874 | + return false; | |
| 875 | + } | |
| 876 | + | |
| 877 | + return FrmAppHelper::is_formidable_admin() && | |
| 878 | + ! FrmAppHelper::is_style_editor_page() && | |
| 879 | + ! FrmAppHelper::is_admin_page( 'formidable-views-editor' ) && | |
| 880 | + ! FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); | |
| 881 | + } | |
| 882 | + | |
| 883 | + /** | |
| 884 | + * @since 6.3.2 | |
| 885 | + * | |
| 886 | + * @return void | |
| 887 | + */ | |
| 888 | + public static function admin_enqueue_scripts() { | |
| 889 | + self::load_wp_admin_style(); | |
| 720 | 890 | self::maybe_force_formidable_block_on_gutenberg_page(); |
| 721 | 891 | } |
| 722 | 892 | |
| 723 | 893 | /** |
| @@ -787,12 +957,45 @@ | ||
| 787 | 957 | * |
| 788 | 958 | * @return void |
| 789 | 959 | */ |
| 790 | 960 | private static function register_popper1() { |
| 961 | + if ( ! self::should_register_popper() ) { | |
| 962 | + return; | |
| 963 | + } | |
| 791 | 964 | wp_register_script( 'popper', FrmAppHelper::plugin_url() . '/js/popper.min.js', array( 'jquery' ), '1.16.0', true ); |
| 792 | 965 | } |
| 793 | 966 | |
| 794 | 967 | /** |
| 968 | + * Only register popper on Formidable pages. | |
| 969 | + * This helps to avoid popper conflicts on other plugin pages, including the WP Bakery page editor. | |
| 970 | + * | |
| 971 | + * @since 6.11.1 | |
| 972 | + * | |
| 973 | + * @return bool | |
| 974 | + */ | |
| 975 | + private static function should_register_popper() { | |
| 976 | + global $pagenow; | |
| 977 | + | |
| 978 | + $post_id = FrmAppHelper::simple_get( 'post', 'absint' ); | |
| 979 | + if ( 'post.php' === $pagenow && $post_id && 'frm_display' === get_post_type( $post_id ) ) { | |
| 980 | + return true; | |
| 981 | + } | |
| 982 | + | |
| 983 | + $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ); | |
| 984 | + $is_views_post_type = 'frm_display' === $post_type; | |
| 985 | + if ( in_array( $pagenow, array( 'post-new.php', 'edit.php' ), true ) && $is_views_post_type ) { | |
| 986 | + return true; | |
| 987 | + } | |
| 988 | + | |
| 989 | + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); | |
| 990 | + if ( strpos( $page, 'formidable' ) === 0 ) { | |
| 991 | + return true; | |
| 992 | + } | |
| 993 | + | |
| 994 | + return in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) && FrmAppHelper::simple_get( 'taxonomy' ) === 'frm_application'; | |
| 995 | + } | |
| 996 | + | |
| 997 | + /** | |
| 795 | 998 | * Automatically insert a Formidable block when loading Gutenberg when $_GET['frmForm' is set. |
| 796 | 999 | * |
| 797 | 1000 | * @since 5.2 |
| 798 | 1001 | * |
| @@ -851,10 +1054,10 @@ | ||
| 851 | 1054 | * @return void |
| 852 | 1055 | */ |
| 853 | 1056 | public static function create_rest_routes() { |
| 854 | 1057 | $args = array( |
| 855 | - 'methods' => 'GET', | |
| 856 | - 'callback' => 'FrmAppController::api_install', | |
| 1058 | + 'methods' => 'GET', | |
| 1059 | + 'callback' => 'FrmAppController::api_install', | |
| 857 | 1060 | 'permission_callback' => __CLASS__ . '::can_update_db', |
| 858 | 1061 | ); |
| 859 | 1062 | |
| 860 | 1063 | register_rest_route( 'frm-admin/v1', '/install', $args ); |
| @@ -859,10 +1062,10 @@ | ||
| 859 | 1062 | |
| 860 | 1063 | register_rest_route( 'frm-admin/v1', '/install', $args ); |
| 861 | 1064 | |
| 862 | 1065 | $args = array( |
| 863 | - 'methods' => 'GET', | |
| 864 | - 'callback' => 'FrmAddonsController::install_addon_api', | |
| 1066 | + 'methods' => 'GET', | |
| 1067 | + 'callback' => 'FrmAddonsController::install_addon_api', | |
| 865 | 1068 | 'permission_callback' => 'FrmAddonsController::can_install_addon_api', |
| 866 | 1069 | ); |
| 867 | 1070 | |
| 868 | 1071 | register_rest_route( 'frm-admin/v1', '/install-addon', $args ); |
| @@ -975,9 +1178,9 @@ | ||
| 975 | 1178 | |
| 976 | 1179 | $frmdb = new FrmMigrate(); |
| 977 | 1180 | $frmdb->uninstall(); |
| 978 | 1181 | |
| 979 | - //disable the plugin and redirect after uninstall so the tables don't get added right back | |
| 1182 | + // Disable the plugin and redirect after uninstall so the tables don't get added right back. | |
| 980 | 1183 | $plugins = array( FrmAppHelper::plugin_folder() . '/formidable.php', 'formidable-pro/formidable-pro.php' ); |
| 981 | 1184 | deactivate_plugins( $plugins, false, false ); |
| 982 | 1185 | echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) ); |
| 983 | 1186 | |
| @@ -1007,8 +1210,33 @@ | ||
| 1007 | 1210 | delete_site_option( 'frmpro-authorized' ); |
| 1008 | 1211 | wp_die(); |
| 1009 | 1212 | } |
| 1010 | 1213 | |
| 1214 | + /** | |
| 1215 | + * This is triggered when Formidable is activated. | |
| 1216 | + * | |
| 1217 | + * @return void | |
| 1218 | + */ | |
| 1219 | + public static function handle_activation() { | |
| 1220 | + self::maybe_activate_payment_cron(); | |
| 1221 | + } | |
| 1222 | + | |
| 1223 | + /** | |
| 1224 | + * The payment cron is unscheduled when Formidable is deactivated. | |
| 1225 | + * We need to add it back again on activation if Stripe is configured. | |
| 1226 | + * | |
| 1227 | + * @since 6.5 | |
| 1228 | + * | |
| 1229 | + * @return void | |
| 1230 | + */ | |
| 1231 | + private static function maybe_activate_payment_cron() { | |
| 1232 | + if ( ! FrmStrpLiteConnectHelper::stripe_connect_is_setup() ) { | |
| 1233 | + return; | |
| 1234 | + } | |
| 1235 | + | |
| 1236 | + FrmTransLiteAppController::maybe_schedule_cron(); | |
| 1237 | + } | |
| 1238 | + | |
| 1011 | 1239 | public static function set_footer_text( $text ) { |
| 1012 | 1240 | if ( FrmAppHelper::is_formidable_admin() ) { |
| 1013 | 1241 | $text = ''; |
| 1014 | 1242 | } |
| @@ -1016,20 +1244,122 @@ | ||
| 1016 | 1244 | return $text; |
| 1017 | 1245 | } |
| 1018 | 1246 | |
| 1019 | 1247 | /** |
| 1020 | - * @deprecated 3.0.04 | |
| 1248 | + * Add admin footer links. | |
| 1021 | 1249 | * |
| 1022 | - * @codeCoverageIgnore | |
| 1250 | + * @since 6.4.1 | |
| 1023 | 1251 | * |
| 1024 | 1252 | * @return void |
| 1025 | 1253 | */ |
| 1026 | - public static function activation_install() { | |
| 1027 | - FrmDeprecated::activation_install(); | |
| 1254 | + public static function add_admin_footer_links() { | |
| 1255 | + if ( self::should_show_footer_links() ) { | |
| 1256 | + include FrmAppHelper::plugin_path() . '/classes/views/shared/admin-footer-links.php'; | |
| 1257 | + } | |
| 1028 | 1258 | } |
| 1029 | 1259 | |
| 1030 | 1260 | /** |
| 1031 | - * @deprecated 3.0 | |
| 1261 | + * Check if the footer links should be shown. | |
| 1262 | + * | |
| 1263 | + * @since 6.7 | |
| 1264 | + * | |
| 1265 | + * @return bool | |
| 1266 | + */ | |
| 1267 | + private static function should_show_footer_links() { | |
| 1268 | + $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ); | |
| 1269 | + $is_formidable_page = FrmAppHelper::is_formidable_admin() || 'frm_logs' === $post_type; | |
| 1270 | + $show_footer_links = $is_formidable_page; | |
| 1271 | + if ( FrmAppHelper::is_full_screen() || ! FrmAppHelper::is_formidable_branding() ) { | |
| 1272 | + $show_footer_links = false; | |
| 1273 | + } | |
| 1274 | + | |
| 1275 | + /** | |
| 1276 | + * Filter whether to show the Formidable footer links. | |
| 1277 | + * | |
| 1278 | + * @since 6.7 | |
| 1279 | + * | |
| 1280 | + * @param bool $show_footer_links | |
| 1281 | + * @return bool | |
| 1282 | + */ | |
| 1283 | + return apply_filters( 'frm_show_footer_links', $show_footer_links ); | |
| 1284 | + } | |
| 1285 | + | |
| 1286 | + /** | |
| 1287 | + * Show an error modal and terminate the script execution. | |
| 1288 | + * | |
| 1289 | + * @since 6.7 | |
| 1290 | + * | |
| 1291 | + * @param array $error_args Arguments that control the behavior of the error modal. | |
| 1292 | + * | |
| 1293 | + * @return void | |
| 1294 | + */ | |
| 1295 | + public static function show_error_modal( $error_args ) { | |
| 1296 | + $defaults = array( | |
| 1297 | + 'title' => '', | |
| 1298 | + 'body' => '', | |
| 1299 | + 'cancel_url' => '', | |
| 1300 | + 'cancel_classes' => '', | |
| 1301 | + 'continue_url' => '', | |
| 1302 | + 'continue_classes' => '', | |
| 1303 | + 'icon' => 'frm_lock_simple', | |
| 1304 | + ); | |
| 1305 | + | |
| 1306 | + $error_args = wp_parse_args( $error_args, $defaults ); | |
| 1307 | + if ( ! isset( $error_args['cancel_text'] ) && ! empty( $error_args['cancel_url'] ) ) { | |
| 1308 | + $error_args['cancel_text'] = __( 'Cancel', 'formidable' ); | |
| 1309 | + } | |
| 1310 | + | |
| 1311 | + if ( ! isset( $error_args['continue_text'] ) && ! empty( $error_args['continue_url'] ) ) { | |
| 1312 | + $error_args['continue_text'] = __( 'Continue', 'formidable' ); | |
| 1313 | + } | |
| 1314 | + | |
| 1315 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/error-modal.php'; | |
| 1316 | + } | |
| 1317 | + | |
| 1318 | + /** | |
| 1319 | + * Handles Floating Links' scripts and styles enqueueing. | |
| 1320 | + * | |
| 1321 | + * @since 6.4 | |
| 1322 | + * | |
| 1323 | + * @param string $plugin_url URL of the plugin. | |
| 1324 | + * @param string $version Current version of the plugin. | |
| 1325 | + * @return void | |
| 1326 | + */ | |
| 1327 | + private static function enqueue_floating_links( $plugin_url, $version ) { | |
| 1328 | + if ( ! $plugin_url || ! $version ) { | |
| 1329 | + // If any required parameters are missing, exit early. | |
| 1330 | + return; | |
| 1331 | + } | |
| 1332 | + | |
| 1333 | + // Enqueue the Floating Links styles. | |
| 1334 | + wp_enqueue_style( 's11-floating-links', $plugin_url . '/css/packages/s11-floating-links.css', array(), $version ); | |
| 1335 | + | |
| 1336 | + // Enqueue the Floating Links script. | |
| 1337 | + wp_enqueue_script( 's11-floating-links', $plugin_url . '/js/packages/floating-links/s11-floating-links.js', array( 'formidable_admin' ), $version, true ); | |
| 1338 | + | |
| 1339 | + // Enqueue the config script. | |
| 1340 | + wp_enqueue_script( 's11-floating-links-config', $plugin_url . '/js/packages/floating-links/config.js', array( 'wp-i18n' ), $version, true ); | |
| 1341 | + | |
| 1342 | + if ( function_exists( 'wp_set_script_translations' ) ) { | |
| 1343 | + wp_set_script_translations( 's11-floating-links-config', 's11-' ); | |
| 1344 | + } | |
| 1345 | + | |
| 1346 | + $floating_links_data = array( | |
| 1347 | + 'proIsInstalled' => FrmAppHelper::pro_is_installed(), | |
| 1348 | + ); | |
| 1349 | + wp_localize_script( 's11-floating-links-config', 's11FloatingLinksData', $floating_links_data ); | |
| 1350 | + | |
| 1351 | + /** | |
| 1352 | + * Prompt Pro to load additional floating links scripts. | |
| 1353 | + * This is used to include images in the Inbox SlideIn when Pro is active. | |
| 1354 | + * | |
| 1355 | + * @since 6.8.4 | |
| 1356 | + */ | |
| 1357 | + do_action( 'frm_enqueue_floating_links' ); | |
| 1358 | + } | |
| 1359 | + | |
| 1360 | + /** | |
| 1361 | + * @deprecated 3.0 This is still referenced in https://formidableforms.com/knowledgebase/php-examples/ as of May 8, 2024. | |
| 1032 | 1362 | * @codeCoverageIgnore |
| 1033 | 1363 | */ |
| 1034 | 1364 | public static function page_route( $content ) { |
| 1035 | 1365 | return FrmDeprecated::page_route( $content ); |
| @@ -1035,26 +1365,72 @@ | ||
| 1035 | 1365 | return FrmDeprecated::page_route( $content ); |
| 1036 | 1366 | } |
| 1037 | 1367 | |
| 1038 | 1368 | /** |
| 1039 | - * Include icons on page for Embed Form modal. | |
| 1369 | + * Check if we are in our admin pages. | |
| 1040 | 1370 | * |
| 1041 | - * @since 5.2 | |
| 1371 | + * @return bool | |
| 1372 | + */ | |
| 1373 | + private static function in_our_pages() { | |
| 1374 | + global $current_screen; | |
| 1375 | + return FrmAppHelper::is_formidable_admin() || ( ! empty( $current_screen->post_type ) && 'frm_logs' === $current_screen->post_type ); | |
| 1376 | + } | |
| 1377 | + | |
| 1378 | + /** | |
| 1379 | + * Hide all third-parties admin notices only in our admin pages. | |
| 1042 | 1380 | * |
| 1043 | 1381 | * @return void |
| 1044 | 1382 | */ |
| 1045 | - public static function include_embed_form_icons() { | |
| 1046 | - _deprecated_function( __METHOD__, '5.3' ); | |
| 1383 | + public static function filter_admin_notices() { | |
| 1384 | + if ( ! self::in_our_pages() ) { | |
| 1385 | + return; | |
| 1386 | + } | |
| 1387 | + | |
| 1388 | + $actions = array( | |
| 1389 | + 'admin_notices', | |
| 1390 | + 'network_admin_notices', | |
| 1391 | + 'user_admin_notices', | |
| 1392 | + 'all_admin_notices', | |
| 1393 | + ); | |
| 1394 | + | |
| 1395 | + global $wp_filter; | |
| 1396 | + | |
| 1397 | + foreach ( $actions as $action ) { | |
| 1398 | + if ( empty( $wp_filter[ $action ]->callbacks ) ) { | |
| 1399 | + continue; | |
| 1400 | + } | |
| 1401 | + foreach ( $wp_filter[ $action ]->callbacks as $priority => $callbacks ) { | |
| 1402 | + foreach ( $callbacks as $callback_name => $callback ) { | |
| 1403 | + if ( self::is_our_callback_string( $callback_name ) || self::is_our_callback_array( $callback ) ) { | |
| 1404 | + continue; | |
| 1405 | + } | |
| 1406 | + unset( $wp_filter[ $action ]->callbacks[ $priority ][ $callback_name ] ); | |
| 1407 | + } | |
| 1408 | + } | |
| 1409 | + } | |
| 1047 | 1410 | } |
| 1048 | 1411 | |
| 1049 | 1412 | /** |
| 1050 | - * @deprecated 1.07.05 This is still referenced in the API add on as of v1.13. | |
| 1051 | - * @codeCoverageIgnore | |
| 1413 | + * Validate that the callback name is ours not from third-party. | |
| 1052 | 1414 | * |
| 1053 | - * @param array $atts | |
| 1054 | - * @return string | |
| 1415 | + * @param string $callback_name WordPress callback name. | |
| 1416 | + * | |
| 1417 | + * @return bool | |
| 1055 | 1418 | */ |
| 1056 | - public static function get_form_shortcode( $atts ) { | |
| 1057 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode' ); | |
| 1058 | - return FrmFormsController::get_form_shortcode( $atts ); | |
| 1419 | + private static function is_our_callback_string( $callback_name ) { | |
| 1420 | + return 0 === stripos( $callback_name, 'frm' ); | |
| 1421 | + } | |
| 1422 | + | |
| 1423 | + /** | |
| 1424 | + * Validate that the callback array is ours not from third-party. | |
| 1425 | + * | |
| 1426 | + * @param array $callback WordPress callback array. | |
| 1427 | + * | |
| 1428 | + * @return bool | |
| 1429 | + */ | |
| 1430 | + private static function is_our_callback_array( $callback ) { | |
| 1431 | + return ! empty( $callback['function'] ) && | |
| 1432 | + is_array( $callback['function'] ) && | |
| 1433 | + ! empty( $callback['function'][0] ) && | |
| 1434 | + self::is_our_callback_string( is_object( $callback['function'][0] ) ? get_class( $callback['function'][0] ) : $callback['function'][0] ); | |
| 1059 | 1435 | } |
| 1060 | 1436 | } |