| @@ -142,8 +142,10 @@ | ||
| 142 | 142 | /** |
| 143 | 143 | * Initialize hooks for template page only. |
| 144 | 144 | * |
| 145 | 145 | * @since 6.7 |
| 146 | + * | |
| 147 | + * @return void | |
| 146 | 148 | */ |
| 147 | 149 | public static function load_admin_hooks() { |
| 148 | 150 | self::init_template_resources(); |
| 149 | 151 | |
| @@ -151,13 +153,15 @@ | ||
| 151 | 153 | add_action( 'admin_menu', self::class . '::menu', 14 ); |
| 152 | 154 | add_action( 'admin_footer', self::class . '::render_modal' ); |
| 153 | 155 | add_filter( 'frm_form_nav_list', self::class . '::append_new_template_to_nav', 10, 2 ); |
| 154 | 156 | |
| 155 | - if ( self::is_templates_page() ) { | |
| 156 | - add_action( 'admin_init', self::class . '::set_form_templates_data' ); | |
| 157 | - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 ); | |
| 158 | - add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 157 | + if ( ! self::is_templates_page() ) { | |
| 158 | + return; | |
| 159 | 159 | } |
| 160 | + | |
| 161 | + add_action( 'admin_init', self::class . '::set_form_templates_data' ); | |
| 162 | + add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 ); | |
| 163 | + add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 160 | 164 | } |
| 161 | 165 | |
| 162 | 166 | /** |
| 163 | 167 | * Add Form Templates menu item to sidebar and define index page. |
| @@ -340,8 +344,9 @@ | ||
| 340 | 344 | if ( 'add' === $operation ) { |
| 341 | 345 | self::$favorite_templates[ $key ][] = $template_id; |
| 342 | 346 | } elseif ( 'remove' === $operation ) { |
| 343 | 347 | $position = array_search( $template_id, self::$favorite_templates[ $key ], true ); |
| 348 | + | |
| 344 | 349 | if ( $position !== false ) { |
| 345 | 350 | unset( self::$favorite_templates[ $key ][ $position ] ); |
| 346 | 351 | } |
| 347 | 352 | } |
| @@ -346,9 +351,9 @@ | ||
| 346 | 351 | } |
| 347 | 352 | } |
| 348 | 353 | |
| 349 | 354 | // Update the favorite templates option. |
| 350 | - update_option( self::FAVORITE_TEMPLATES_OPTION, self::$favorite_templates ); | |
| 355 | + update_option( self::FAVORITE_TEMPLATES_OPTION, self::$favorite_templates, false ); | |
| 351 | 356 | |
| 352 | 357 | // Return the updated list of favorite templates. |
| 353 | 358 | wp_send_json_success( self::$favorite_templates ); |
| 354 | 359 | } |
| @@ -371,14 +376,9 @@ | ||
| 371 | 376 | // Get posted data. |
| 372 | 377 | $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' ); |
| 373 | 378 | $new_form_id = FrmForm::duplicate( $form_id, 1, true ); |
| 374 | 379 | |
| 375 | - if ( ! $new_form_id ) { | |
| 376 | - // Send an error response if form duplication fails. | |
| 377 | - $response = array( | |
| 378 | - 'message' => __( 'There was an error creating a template.', 'formidable' ), | |
| 379 | - ); | |
| 380 | - } else { | |
| 380 | + if ( $new_form_id ) { | |
| 381 | 381 | FrmForm::update( $new_form_id, FrmFormsController::get_modal_values() ); |
| 382 | 382 | |
| 383 | 383 | // Send a success response with redirect URL. |
| 384 | 384 | $response = array( |
| @@ -383,8 +383,13 @@ | ||
| 383 | 383 | // Send a success response with redirect URL. |
| 384 | 384 | $response = array( |
| 385 | 385 | 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(), |
| 386 | 386 | ); |
| 387 | + } else { | |
| 388 | + // Send an error response if form duplication fails. | |
| 389 | + $response = array( | |
| 390 | + 'message' => __( 'There was an error creating a template.', 'formidable' ), | |
| 391 | + ); | |
| 387 | 392 | } |
| 388 | 393 | |
| 389 | 394 | // Send response. |
| 390 | 395 | echo wp_json_encode( $response ); |
| @@ -403,9 +408,9 @@ | ||
| 403 | 408 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 404 | 409 | |
| 405 | 410 | $email = FrmAppHelper::get_post_param( 'email', '', 'sanitize_email' ); |
| 406 | 411 | |
| 407 | - if ( empty( $email ) || ! is_email( $email ) ) { | |
| 412 | + if ( ! $email || ! is_email( $email ) ) { | |
| 408 | 413 | wp_send_json_error( |
| 409 | 414 | array( 'message' => __( 'Please enter a valid email address.', 'formidable' ) ), |
| 410 | 415 | WP_Http::BAD_REQUEST |
| 411 | 416 | ); |
| @@ -533,8 +538,9 @@ | ||
| 533 | 538 | |
| 534 | 539 | // Filter out certain and redundant categories. |
| 535 | 540 | // 'PayPal', 'Stripe', and 'Twilio' are included elsewhere and should be ignored in this context. |
| 536 | 541 | $redundant_cats = array_merge( array( 'PayPal', 'Stripe', 'Twilio' ), FrmFormsHelper::get_license_types() ); |
| 542 | + | |
| 537 | 543 | foreach ( $redundant_cats as $redundant_cat ) { |
| 538 | 544 | $category_slug = sanitize_title( $redundant_cat ); |
| 539 | 545 | unset( self::$categories[ $category_slug ] ); |
| 540 | 546 | } |
| @@ -552,8 +558,9 @@ | ||
| 552 | 558 | 'name' => __( 'Custom', 'formidable' ), |
| 553 | 559 | 'count' => count( self::$custom_templates ), |
| 554 | 560 | ), |
| 555 | 561 | ); |
| 562 | + | |
| 556 | 563 | // Add the 'Available Templates' category for non-elite users. |
| 557 | 564 | if ( 'elite' !== FrmAddonsController::license_type() ) { |
| 558 | 565 | $special_categories['available-templates'] = array( |
| 559 | 566 | 'name' => __( 'Available Templates', 'formidable' ), |
| @@ -560,9 +567,10 @@ | ||
| 560 | 567 | // Assigned via JavaScript. |
| 561 | 568 | 'count' => 0, |
| 562 | 569 | ); |
| 563 | 570 | } |
| 564 | - $special_categories['all-items'] = array( | |
| 571 | + | |
| 572 | + $special_categories['all-items'] = array( | |
| 565 | 573 | 'name' => __( 'All Templates', 'formidable' ), |
| 566 | 574 | 'count' => self::get_template_count(), |
| 567 | 575 | ); |
| 568 | 576 | |
| @@ -583,12 +591,14 @@ | ||
| 583 | 591 | * @return void |
| 584 | 592 | */ |
| 585 | 593 | private static function assign_featured_templates() { |
| 586 | 594 | foreach ( self::FEATURED_TEMPLATES_IDS as $key ) { |
| 587 | - if ( isset( self::$templates[ $key ] ) ) { | |
| 588 | - self::$templates[ $key ]['is_featured'] = true; | |
| 589 | - self::$featured_templates[] = self::$templates[ $key ]; | |
| 595 | + if ( ! isset( self::$templates[ $key ] ) ) { | |
| 596 | + continue; | |
| 590 | 597 | } |
| 598 | + | |
| 599 | + self::$templates[ $key ]['is_featured'] = true; | |
| 600 | + self::$featured_templates[] = self::$templates[ $key ]; | |
| 591 | 601 | } |
| 592 | 602 | } |
| 593 | 603 | |
| 594 | 604 | /** |
| @@ -653,8 +663,9 @@ | ||
| 653 | 663 | * @since 6.7 |
| 654 | 664 | * |
| 655 | 665 | * @param array $nav_items Navigation items. |
| 656 | 666 | * @param array $nav_args Additional navigation arguments. |
| 667 | + * | |
| 657 | 668 | * @return array Modified navigation items with 'new_template' query parameter. |
| 658 | 669 | */ |
| 659 | 670 | public static function append_new_template_to_nav( $nav_items, $nav_args ) { |
| 660 | 671 | $is_new_template = FrmAppHelper::simple_get( 'new_template' ); |
| @@ -770,9 +781,9 @@ | ||
| 770 | 781 | * |
| 771 | 782 | * @return int |
| 772 | 783 | */ |
| 773 | 784 | public static function get_template_count() { |
| 774 | - if ( empty( self::$templates ) ) { | |
| 785 | + if ( ! self::$templates ) { | |
| 775 | 786 | self::$form_template_api = new FrmFormTemplateApi(); |
| 776 | 787 | self::retrieve_and_set_templates(); |
| 777 | 788 | } |
| 778 | 789 | return count( self::$templates ); |