← All changes
|
admin/modules/settings/class-wpfnl-settings.php
+33
-176
3.13.1
→
3.13.3
View file →
| @@ -9,9 +9,8 @@ | ||
| 9 | 9 | |
| 10 | 10 | use WPFunnels\Admin\Module\Wpfnl_Admin_Module; |
| 11 | 11 | use WPFunnels\Rollback; |
| 12 | 12 | use WPFunnels\Traits\SingletonTrait; |
| 13 | -use WPFunnels\Wpfnl; | |
| 14 | 13 | use WPFunnels\Wpfnl_functions; |
| 15 | 14 | |
| 16 | 15 | class Module extends Wpfnl_Admin_Module |
| 17 | 16 | { |
| @@ -20,92 +19,10 @@ | ||
| 20 | 19 | protected $validations; |
| 21 | 20 | |
| 22 | 21 | protected $prefix = '_wpfunnels_'; |
| 23 | 22 | |
| 24 | - protected $general_settings; | |
| 25 | - | |
| 26 | - protected $permalink_settings; | |
| 27 | - | |
| 28 | - protected $optin_settings; | |
| 29 | - | |
| 30 | - protected $offer_settings; | |
| 31 | - | |
| 32 | - protected $user_roles; | |
| 33 | - | |
| 34 | - protected $gtm_events; | |
| 35 | - | |
| 36 | - protected $gtm_settings; | |
| 37 | - | |
| 38 | - protected $facebook_pixel_events; | |
| 39 | - | |
| 40 | - protected $facebook_pixel_settings; | |
| 41 | - | |
| 42 | - protected $recaptcha_settings; | |
| 43 | - | |
| 44 | - protected $utm_params; | |
| 45 | - | |
| 46 | - protected $utm_settings; | |
| 47 | - | |
| 48 | - protected $is_allow_sales; | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * User Roles Settings. | |
| 52 | - * | |
| 53 | - * @var array $user_roles_settings An associative array containing user roles settings. | |
| 54 | - */ | |
| 55 | - protected $user_roles_settings; | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Notification Settings. | |
| 59 | - * | |
| 60 | - * @var array $notification_settings An associative array containing notification settings. | |
| 61 | - */ | |
| 62 | - protected $notification_settings; | |
| 63 | - | |
| 64 | - | |
| 65 | - /** | |
| 66 | - * Google Maps API Key. | |
| 67 | - * | |
| 68 | - * This property stores the API key used for accessing Google Maps services. | |
| 69 | - * | |
| 70 | - * @var string $google_map_api_key The Google Maps API key. | |
| 71 | - */ | |
| 72 | - protected $google_map_api_key; | |
| 73 | - | |
| 74 | - /** | |
| 75 | - * Page hooks | |
| 76 | - * | |
| 77 | - * @var array | |
| 78 | - */ | |
| 79 | - private $page_hooks = [ | |
| 80 | - 'toplevel_page_wp_funnels', | |
| 81 | - 'wp-funnels_page_wp_funnel_settings', | |
| 82 | - 'wpfunnels_page_wpfnl_settings', | |
| 83 | - 'wp-funnels_page_edit_funnel', | |
| 84 | - 'wp-funnels_page_create_funnel', | |
| 85 | - 'wp-funnels_page_wpfnl_settings', | |
| 86 | - 'wp-funnels_page_wpf-license', | |
| 87 | - 'wpfunnels_page_email-builder', | |
| 88 | - ]; | |
| 89 | - | |
| 90 | - protected $settings_meta_keys = [ | |
| 91 | - '_wpfunnels_builder' => 'elementor', | |
| 92 | - '_wpfunnels_paypal_reference' => '', | |
| 93 | - '_wpfunnels_order_bump' => '', | |
| 94 | - '_wpfunnels_ab_testing' => '', | |
| 95 | - '_wpfunnels_allow_funnels' => [ | |
| 96 | - 'administrator' => true, | |
| 97 | - ], | |
| 98 | - '_wpfunnels_permalink_settings' => '', | |
| 99 | - '_wpfunnels_optin_settings' => '', | |
| 100 | - '_wpfunnels_permalink_step_base' => 'wpfunnels', | |
| 101 | - '_wpfunnels_permalink_flow_base' => 'step', | |
| 102 | - '_wpfunnels_set_permalink' => 'step', | |
| 103 | - ]; | |
| 104 | - | |
| 105 | 23 | public function __construct() |
| 106 | 24 | { |
| 107 | - add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); | |
| 108 | 25 | add_action('admin_init', [$this, 'after_permalink_settings_saved']); |
| 109 | 26 | add_action( 'admin_post_wpfunnels_rollback', [ $this, 'post_wpfunnels_rollback' ] ); |
| 110 | 27 | add_action( 'wpfunnels_send_revenue_report_email', [ $this, 'send_revenue_report_email' ] ); |
| 111 | 28 | $this->init_ajax(); |
| @@ -110,49 +27,36 @@ | ||
| 110 | 27 | add_action( 'wpfunnels_send_revenue_report_email', [ $this, 'send_revenue_report_email' ] ); |
| 111 | 28 | $this->init_ajax(); |
| 112 | 29 | } |
| 113 | 30 | |
| 114 | - public function is_wc_installed() | |
| 31 | + /** | |
| 32 | + * Render the settings screen. | |
| 33 | + * | |
| 34 | + * The screen is a route of the React admin now — `?page=wpfunnels#/settings` | |
| 35 | + * — which admin_init sends this page to (see | |
| 36 | + * Wpfnl_Menus::maybe_redirect_to_react_admin). Printing the app's root here | |
| 37 | + * keeps the page working for anyone who filters that redirect off; there is | |
| 38 | + * no server-rendered settings markup any more. | |
| 39 | + * | |
| 40 | + * @return void | |
| 41 | + * @since 1.0.0 | |
| 42 | + */ | |
| 43 | + public function get_view() | |
| 115 | 44 | { |
| 116 | - $path = 'woocommerce/woocommerce.php'; | |
| 117 | - $plugins = get_plugins(); | |
| 45 | + /* | |
| 46 | + * The app reads its route from the fragment, which never reaches the | |
| 47 | + * server — so landing here with no fragment would open the dashboard. | |
| 48 | + * The bundle is a footer script, so this still prints before it runs. | |
| 49 | + */ | |
| 50 | + wp_add_inline_script( | |
| 51 | + 'wpfnl-react-admin', | |
| 52 | + "if ( ! window.location.hash ) { window.location.hash = '#/settings'; }", | |
| 53 | + 'before' | |
| 54 | + ); | |
| 118 | 55 | |
| 119 | - return isset($plugins[ $path ]); | |
| 56 | + require WPFNL_ADMIN_DIR . 'views/react-admin.php'; | |
| 120 | 57 | } |
| 121 | 58 | |
| 122 | - public function is_ff_installed() | |
| 123 | - { | |
| 124 | - $path = 'fluentform/fluentform.php'; | |
| 125 | - $plugins = get_plugins(); | |
| 126 | - | |
| 127 | - return isset($plugins[ $path ]); | |
| 128 | - } | |
| 129 | - | |
| 130 | - public function is_elementor_installed() | |
| 131 | - { | |
| 132 | - $path = 'elementor/elementor.php'; | |
| 133 | - $plugins = get_plugins(); | |
| 134 | - | |
| 135 | - return isset($plugins[ $path ]); | |
| 136 | - } | |
| 137 | - | |
| 138 | - | |
| 139 | - public function enqueue_scripts( $hook ) | |
| 140 | - { | |
| 141 | - if ( ! in_array( $hook, $this->page_hooks, true ) ) { | |
| 142 | - return; | |
| 143 | - } | |
| 144 | - wp_enqueue_script('settings', plugin_dir_url(__FILE__) . 'js/settings.js', ['jquery'], WPFNL_VERSION, true); | |
| 145 | - } | |
| 146 | - | |
| 147 | - | |
| 148 | - public function get_view() | |
| 149 | - { | |
| 150 | - $this->init_settings(); | |
| 151 | - $is_pro_activated = Wpfnl_functions::is_wpfnl_pro_activated(); | |
| 152 | - require_once WPFNL_DIR . '/admin/modules/settings/views/view.php'; | |
| 153 | - } | |
| 154 | - | |
| 155 | 59 | /** |
| 156 | 60 | * Init ajax hooks for |
| 157 | 61 | * saving metas |
| 158 | 62 | * |
| @@ -159,8 +63,17 @@ | ||
| 159 | 63 | * @since 1.0.0 |
| 160 | 64 | */ |
| 161 | 65 | public function init_ajax() |
| 162 | 66 | { |
| 67 | + /* | |
| 68 | + * Only the two actions that are still posted to from outside this module | |
| 69 | + * are registered: the Vue template library's sync button | |
| 70 | + * (`clear-templates`) and the setup wizard (`update-general-settings`). | |
| 71 | + * Everything the settings screen itself used to post goes through | |
| 72 | + * wpfunnels/v1/settings/* now — see | |
| 73 | + * includes/core/rest-api/Controllers/class-settings-page-controller.php, | |
| 74 | + * which calls the very same handlers below. | |
| 75 | + */ | |
| 163 | 76 | $this->validations = [ |
| 164 | 77 | 'logged_in' => true, |
| 165 | 78 | 'user_can' => 'wpf_manage_funnels', |
| 166 | 79 | ]; |
| @@ -171,23 +84,8 @@ | ||
| 171 | 84 | wp_ajax_helper()->handle('clear-templates') |
| 172 | 85 | ->with_callback([ $this, 'clear_templates_data' ]) |
| 173 | 86 | ->with_validation($this->validations); |
| 174 | 87 | |
| 175 | - wp_ajax_helper()->handle('clear-transient') | |
| 176 | - ->with_callback([ $this, 'clear_transient_cache_data' ]) | |
| 177 | - ->with_validation($this->validations); | |
| 178 | - | |
| 179 | - wp_ajax_helper()->handle('wpfnl-show-log') | |
| 180 | - ->with_callback([ $this, 'wpfnl_show_log' ]) | |
| 181 | - ->with_validation($this->validations); | |
| 182 | - | |
| 183 | - wp_ajax_helper()->handle('wpfnl-delete-log') | |
| 184 | - ->with_callback([ $this, 'wpfnl_delete_log' ]) | |
| 185 | - ->with_validation($this->validations); | |
| 186 | - | |
| 187 | - wp_ajax_helper()->handle('wpfnl-send-test-notification') | |
| 188 | - ->with_callback([ $this, 'send_test_notification' ]) | |
| 189 | - ->with_validation($this->validations); | |
| 190 | 88 | } |
| 191 | 89 | |
| 192 | 90 | |
| 193 | 91 | /** |
| @@ -551,36 +449,8 @@ | ||
| 551 | 449 | } |
| 552 | 450 | |
| 553 | 451 | |
| 554 | 452 | /** |
| 555 | - * Initialize all the settings value | |
| 556 | - * | |
| 557 | - * @since 1.0.0 | |
| 558 | - */ | |
| 559 | - public function init_settings() | |
| 560 | - { | |
| 561 | - $this->general_settings = Wpfnl_functions::get_general_settings(); | |
| 562 | - $this->is_allow_sales = Wpfnl_functions::maybe_allow_sales_funnel(); | |
| 563 | - $this->permalink_settings = Wpfnl_functions::get_permalink_settings(); | |
| 564 | - $this->optin_settings = Wpfnl_functions::get_optin_settings(); | |
| 565 | - $this->offer_settings = Wpfnl_functions::get_offer_settings(); | |
| 566 | - $this->user_roles = Wpfnl_functions::get_user_roles(); | |
| 567 | - $this->gtm_events = Wpfnl_functions::get_gtm_events(); | |
| 568 | - $this->gtm_settings = Wpfnl_functions::get_gtm_settings(); | |
| 569 | - $this->facebook_pixel_events = Wpfnl_functions::get_facebook_events(); | |
| 570 | - $this->facebook_pixel_settings = Wpfnl_functions::get_facebook_pixel_settings(); | |
| 571 | - $this->utm_params = Wpfnl_functions::get_utm_params(); | |
| 572 | - $this->utm_settings = Wpfnl_functions::get_utm_settings(); | |
| 573 | - $this->recaptcha_settings = Wpfnl_functions::get_recaptcha_settings(); | |
| 574 | - $this->user_roles_settings = Wpfnl_functions::get_user_role_settings(); | |
| 575 | - $this->google_map_api_key = Wpfnl_functions::get_google_map_api_key(); | |
| 576 | - $this->notification_settings = Wpfnl_functions::get_notification_settings(); | |
| 577 | - } | |
| 578 | - | |
| 579 | - | |
| 580 | - | |
| 581 | - | |
| 582 | - /** | |
| 583 | 453 | * Clear saved templates data |
| 584 | 454 | * |
| 585 | 455 | * @param $payload |
| 586 | 456 | * |
| @@ -648,21 +518,8 @@ | ||
| 648 | 518 | } |
| 649 | 519 | } |
| 650 | 520 | } |
| 651 | 521 | |
| 652 | - | |
| 653 | - /** | |
| 654 | - * Get settings by meta key | |
| 655 | - * | |
| 656 | - * @param $key | |
| 657 | - * | |
| 658 | - * @return mixed|string | |
| 659 | - * @since 1.0.0 | |
| 660 | - */ | |
| 661 | - public function get_settings_by_key($key) | |
| 662 | - { | |
| 663 | - return isset($this->settings_meta_keys[$key]) ? $this->settings_meta_keys[$key]: ''; | |
| 664 | - } | |
| 665 | 522 | |
| 666 | 523 | public function get_name() |
| 667 | 524 | { |
| 668 | 525 | return __('settings','wpfnl'); |