| @@ -21,17 +21,25 @@ | ||
| 21 | 21 | require_once HOSTINGER_ABSPATH . 'includes/class-hostinger-helper.php'; |
| 22 | 22 | require_once HOSTINGER_ABSPATH . 'includes/class-hostinger-errors.php'; |
| 23 | 23 | require_once HOSTINGER_ABSPATH . 'includes/class-hostinger-settings.php'; |
| 24 | 24 | require_once HOSTINGER_ABSPATH . 'includes/requests/class-hostinger-requests-client.php'; |
| 25 | - require_once HOSTINGER_ABSPATH . 'includes/amplitude/class-hostinger-amplitude-actions.php'; | |
| 26 | - require_once HOSTINGER_ABSPATH . 'includes/amplitude/class-hostinger-amplitude.php'; | |
| 27 | - require_once HOSTINGER_ABSPATH . 'includes/surveys/class-hostinger-surveys-questions.php'; | |
| 28 | - require_once HOSTINGER_ABSPATH . 'includes/surveys/class-hostinger-surveys.php'; | |
| 25 | + | |
| 26 | + if ( ! empty( Hostinger_Helper::get_api_token() ) ) { | |
| 27 | + require_once HOSTINGER_ABSPATH . 'includes/amplitude/class-hostinger-amplitude-actions.php'; | |
| 28 | + require_once HOSTINGER_ABSPATH . 'includes/amplitude/class-hostinger-amplitude.php'; | |
| 29 | + require_once HOSTINGER_ABSPATH . 'includes/surveys/class-hostinger-surveys-questions.php'; | |
| 30 | + require_once HOSTINGER_ABSPATH . 'includes/surveys/Rest/class-hostinger-surveys-rest.php'; | |
| 31 | + require_once HOSTINGER_ABSPATH . 'includes/surveys/class-hostinger-surveys.php'; | |
| 32 | + } | |
| 33 | + | |
| 29 | 34 | $this->load_onboarding_dependencies(); |
| 35 | + $this->load_public_dependencies(); | |
| 30 | 36 | |
| 31 | 37 | if ( is_admin() ) { |
| 32 | 38 | $this->load_admin_dependencies(); |
| 33 | - $this->define_admin_hooks(); | |
| 39 | + if ( ! empty( Hostinger_Helper::get_api_token() ) ) { | |
| 40 | + $this->define_admin_surveys(); | |
| 41 | + } | |
| 34 | 42 | } |
| 35 | 43 | |
| 36 | 44 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 37 | 45 | require_once HOSTINGER_ABSPATH . 'includes/class-hostinger-cli.php'; |
| @@ -47,34 +55,66 @@ | ||
| 47 | 55 | private function set_locale() { |
| 48 | 56 | |
| 49 | 57 | $plugin_i18n = new Hostinger_i18n(); |
| 50 | 58 | $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
| 51 | - | |
| 52 | 59 | } |
| 53 | 60 | |
| 54 | 61 | private function load_admin_dependencies(): void { |
| 55 | 62 | require_once HOSTINGER_ABSPATH . 'includes/admin/class-hostinger-admin-assets.php'; |
| 63 | + require_once HOSTINGER_ABSPATH . 'includes/admin/class-hostinger-admin-hooks.php'; | |
| 56 | 64 | require_once HOSTINGER_ABSPATH . 'includes/admin/class-hostinger-admin-menu.php'; |
| 57 | - require_once HOSTINGER_ABSPATH . 'includes/admin/class-hostinger-affiliates.php'; | |
| 58 | 65 | require_once HOSTINGER_ABSPATH . 'includes/admin/class-hostinger-admin-ajax.php'; |
| 59 | 66 | require_once HOSTINGER_ABSPATH . 'includes/admin/class-hostinger-admin-redirect.php'; |
| 60 | 67 | } |
| 61 | 68 | |
| 62 | - private function define_admin_hooks(): void { | |
| 63 | - $hostinger_affiliate = new Hostinger_Affiliates(); | |
| 69 | + private function define_admin_surveys(): void { | |
| 70 | + $settings = new Hostinger_Settings(); | |
| 71 | + $helper = new Hostinger_Helper(); | |
| 72 | + $config_handler = new Hostinger_Config(); | |
| 73 | + $survey_questions = new Hostinger_Surveys_Questions(); | |
| 74 | + $client = new Hostinger_Requests_Client( | |
| 75 | + $config_handler->get_config_value( 'base_rest_uri', HOSTINGER_REST_URI ), | |
| 76 | + array( | |
| 77 | + Hostinger_Config::TOKEN_HEADER => $helper::get_api_token(), | |
| 78 | + Hostinger_Config::DOMAIN_HEADER => $helper->get_host_info(), | |
| 79 | + ) | |
| 80 | + ); | |
| 81 | + $rest = new Hostinger_Surveys_Rest( $client ); | |
| 82 | + $surveys = new Hostinger_Surveys( $settings, $helper, $config_handler, $survey_questions, $rest ); | |
| 64 | 83 | |
| 65 | - $this->loader->add_filter( 'astra_get_pro_url', $hostinger_affiliate, 'astra_pro_affiliate_link', 10, 2 ); | |
| 66 | - $this->loader->add_filter( 'optinmonster_sas_id', $hostinger_affiliate, 'affiliate_monsterinsights' ); | |
| 67 | - $this->loader->add_filter( 'monsterinsights_shareasale_id', $hostinger_affiliate, 'affiliate_monsterinsights' ); | |
| 68 | - $this->loader->add_filter( 'wpforms_upgrade_link', $hostinger_affiliate, 'wpforms_upgrade_link' ); | |
| 69 | - $this->loader->add_filter( 'aioseo_upgrade_link', $hostinger_affiliate, 'aioseo_upgrade_link' ); | |
| 84 | + switch (true) { | |
| 85 | + case $surveys->is_woocommerce_survey_enabled(): | |
| 86 | + $survey_function = 'customer_csat_survey'; | |
| 87 | + break; | |
| 88 | + | |
| 89 | + case $surveys->is_ai_onboarding_survey_enabled(): | |
| 90 | + $survey_function = 'customer_ai_csat_survey'; | |
| 91 | + break; | |
| 92 | + | |
| 93 | + case $surveys->is_content_generation_survey_enabled(): | |
| 94 | + $survey_function = 'ai_plugin_survey'; | |
| 95 | + break; | |
| 96 | + | |
| 97 | + case $surveys->is_affiliate_survey_enabled(): | |
| 98 | + $survey_function = 'affiliate_plugin_survey'; | |
| 99 | + break; | |
| 100 | + | |
| 101 | + default: | |
| 102 | + return; // No survey enabled | |
| 103 | + } | |
| 104 | + | |
| 105 | + $this->loader->add_action('admin_footer', $surveys, $survey_function, 10); | |
| 70 | 106 | } |
| 71 | 107 | |
| 108 | + private function load_public_dependencies(): void { | |
| 109 | + require_once HOSTINGER_ABSPATH . 'includes/public/class-hostinger-public-assets.php'; | |
| 110 | + } | |
| 111 | + | |
| 72 | 112 | private function load_onboarding_dependencies(): void { |
| 73 | 113 | require_once HOSTINGER_ABSPATH . 'includes/admin/class-hostinger-admin-actions.php'; |
| 74 | 114 | require_once HOSTINGER_ABSPATH . 'includes/admin/onboarding/class-hostinger-onboarding-settings.php'; |
| 75 | 115 | |
| 76 | - if( ! Hostinger_Onboarding_Settings::all_steps_completed() ) { | |
| 116 | + if ( ! Hostinger_Onboarding_Settings::all_steps_completed() ) { | |
| 77 | 117 | require_once HOSTINGER_ABSPATH . 'includes/admin/onboarding/class-hostinger-autocomplete-steps.php'; |
| 78 | 118 | } |
| 79 | 119 | } |
| 80 | 120 | } |