PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
← All changes | app/Assist/Admin.php +119 -78 0.10.2 → 3.2.2 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 /**
3 4 * Admin.
4 5 */
5 6
@@ -4,24 +5,23 @@
4 5 */
5 6
6 7 namespace Extendify\Assist;
7 8
9 +defined('ABSPATH') || die('No direct access.');
10 +
11 +use Extendify\Assist\Controllers\GlobalsController;
12 +use Extendify\Assist\Controllers\RouterController;
13 +use Extendify\Assist\Controllers\TasksController;
8 14 use Extendify\Config;
15 +use Extendify\PartnerData;
9 16
10 17 /**
11 18 * This class handles any file loading for the admin area.
12 19 */
20 +
13 21 class Admin
14 22 {
15 -
16 23 /**
17 - * The instance
18 - *
19 - * @var $instance
20 - */
21 - public static $instance = null;
22 -
23 - /**
24 24 * Adds various actions to set up the page
25 25 *
26 26 * @return self|void
27 27 */
@@ -26,96 +26,137 @@
26 26 * @return self|void
27 27 */
28 28 public function __construct()
29 29 {
30 - if (self::$instance) {
31 - return self::$instance;
32 - }
33 -
34 - self::$instance = $this;
35 - $this->loadScripts();
36 - if (Config::$environment === 'PRODUCTION') {
37 - $this->hideSubmenus();
38 - }
30 + \add_action('admin_enqueue_scripts', [$this, 'loadPageScripts']);
39 31 }
40 32
41 33 /**
42 - * Adds scripts to the admin
34 + * Adds scripts to the main admin page
43 35 *
44 36 * @return void
45 37 */
46 - public function loadScripts()
38 + public function loadPageScripts()
47 39 {
48 - \add_action(
49 - 'admin_enqueue_scripts',
50 - function () {
51 - if (!current_user_can(Config::$requiredCapability)) {
52 - return;
53 - }
40 + $version = constant('EXTENDIFY_DEVMODE') ? uniqid() : Config::$version;
41 + $scriptAssetPath = EXTENDIFY_PATH . 'public/build/' . Config::$assetManifest['extendify-assist-page.php'];
42 + $fallback = [
43 + 'dependencies' => [],
44 + 'version' => $version,
45 + ];
46 + $scriptAsset = file_exists($scriptAssetPath) ? require $scriptAssetPath : $fallback;
54 47
55 - if (!Config::$showAssist) {
56 - return;
57 - }
48 + foreach ($scriptAsset['dependencies'] as $style) {
49 + \wp_enqueue_style($style);
50 + }
58 51
59 - $version = Config::$environment === 'PRODUCTION' ? Config::$version : uniqid();
52 + \wp_enqueue_script(
53 + Config::$slug . '-assist-page-scripts',
54 + EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-assist-page.js'],
55 + array_merge([Config::$slug . '-shared-scripts'], $scriptAsset['dependencies']),
56 + $scriptAsset['version'],
57 + true
58 + );
60 59
61 - \wp_enqueue_script(
62 - Config::$slug . '-assist-scripts',
63 - EXTENDIFY_BASE_URL . 'public/build/extendify-assist.js',
64 - [
65 - 'wp-components',
66 - 'wp-element',
67 - 'wp-data',
68 - 'wp-core-data',
69 - 'wp-html-entities',
70 - 'wp-i18n',
71 - 'wp-polyfill',
72 - ],
73 - $version,
74 - true
75 - );
76 - \wp_add_inline_script(
77 - Config::$slug . '-assist-scripts',
78 - 'window.extAssistData = ' . wp_json_encode([
79 - 'devbuild' => \esc_attr(Config::$environment === 'DEVELOPMENT'),
80 - 'root' => \esc_url_raw(\rest_url(Config::$slug . '/' . Config::$apiVersion)),
81 - 'nonce' => \wp_create_nonce('wp_rest'),
82 - 'adminUrl' => \esc_url_raw(\admin_url()),
83 - ]),
84 - 'before'
85 - );
60 + \wp_add_inline_script(
61 + Config::$slug . '-assist-page-scripts',
62 + 'window.extAssistData = ' . \wp_json_encode([
63 + 'launchCompleted' => (bool) Config::$launchCompleted,
64 + 'hasCustomizer' => (bool) \has_action('customize_register'),
65 + 'domainsSuggestionSettings' => [
66 + 'showBanner' => (bool) PartnerData::setting('showDomainBanner'),
67 + 'showTask' => (bool) PartnerData::setting('showDomainTask'),
68 + 'showSecondaryBanner' => (bool) PartnerData::setting('showSecondaryDomainBanner'),
69 + 'showSecondaryTask' => (bool) PartnerData::setting('showSecondaryDomainTask'),
70 + 'stagingSites' => array_map('esc_attr', PartnerData::setting('stagingSites')),
71 + 'searchUrl' => \esc_attr(PartnerData::setting('domainSearchURL')),
72 + ],
73 + 'userData' => [
74 + 'taskData' => \wp_json_encode(TasksController::get()->get_data()),
75 + 'globalData' => \wp_json_encode(GlobalsController::get()->get_data()),
76 + 'routerData' => \wp_json_encode(RouterController::get()->get_data()),
77 + 'recommendationData' => \wp_json_encode(RouterController::get()->get_data()),
78 + 'tasksDependencies' => \wp_json_encode($this->getTasksDependencies()),
79 + 'domainsRecommendationsActivities' => \wp_json_encode(
80 + get_option('extendify_domains_recommendations_activities', null)
81 + ),
82 + ],
83 + 'canSeeRestartLaunch' => (bool) $this->canRunLaunchAgain(),
84 + 'editSiteNavigationMenuLink' => \current_theme_supports('menus')
85 + ? \esc_url(\admin_url('nav-menus.php'))
86 + : \esc_url(\admin_url('site-editor.php?path=%2Fnavigation')),
87 + ]),
88 + 'before'
89 + );
86 90
87 - \wp_set_script_translations(Config::$slug . '-assist-scripts', 'extendify');
91 + \wp_set_script_translations(
92 + Config::$slug . '-assist-page-scripts',
93 + 'extendify-local',
94 + EXTENDIFY_PATH . 'languages/js'
95 + );
88 96
89 - \wp_enqueue_style(
90 - Config::$slug . '-assist-styles',
91 - EXTENDIFY_BASE_URL . 'public/build/extendify-assist.css',
92 - [],
93 - $version,
94 - 'all'
95 - );
96 - }
97 + \wp_enqueue_style(
98 + Config::$slug . '-assist-page-styles',
99 + EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-assist-page.css'],
100 + [],
101 + Config::$version,
102 + 'all'
97 103 );
98 104 }
99 105
100 106 /**
101 - * Hide Extendify 'Welcome' and 'Assist' submenus on all admin pages.
107 + * Check to see if the user can re-run Launch
102 108 *
103 - * @return void
109 + * @return boolean
104 110 */
105 - public function hideSubmenus()
111 + public function canRunLaunchAgain()
106 112 {
107 - add_action('admin_head', function () {
108 - echo '<style>
109 - #toplevel_page_extendify-assist .wp-submenu,
110 - #toplevel_page_extendify-welcome .wp-submenu {
111 - display:none!important;
112 - }
113 - #toplevel_page_extendify-assist::after,
114 - #toplevel_page_extendify-welcome::after {
115 - content:none!important;
116 - }
117 - </style>';
118 - });
113 + $launchCompleted = \get_option('extendify_onboarding_completed', false);
114 + return (!$launchCompleted || $launchCompleted === 'false') ? false : true;
119 115 }
120 116
117 + /**
118 + * Check to see if specific tasks are completed or not.
119 + *
120 + * @return array
121 + */
122 + public function getTasksDependencies()
123 + {
124 + $give = \get_option('give_onboarding', false);
125 + $completedSetupGivewp = isset($give['form_id']) && $give['form_id'] > 0;
126 +
127 + $woo = \get_option('woocommerce_onboarding_profile', false);
128 + $completedWoocommerceStore = (
129 + isset($woo['completed']) && $woo['completed']
130 + ) || (
131 + isset($woo['skipped']) && $woo['skipped']
132 + );
133 +
134 + $aioseo = \get_option('aioseo_blc_options_internal', false);
135 + $completedSetupAIOSeo = false;
136 + if ($aioseo) {
137 + $aioseo = \json_decode($aioseo, true);
138 + $completedSetupAIOSeo = isset($aioseo['internal'])
139 + && array_key_exists('firstActivated', $aioseo['internal']);
140 + }
141 +
142 + $completedWPFormsLite = (bool) \get_option('wpforms_forms_first_created', false)
143 + || (bool) (\wp_count_posts('wpforms')->publish ?? 0);
144 +
145 + // The two extra keys that will be added after connecting the store
146 + // are the `admin_menu` and `hide_out_of_stock`.
147 + $yourWebShop = \get_option('ecwid_plugin_data', false);
148 + $completedYourWebShop = isset($yourWebShop['admin_menu']) && $yourWebShop['admin_menu'];
149 +
150 + $monsterInsightsSiteProfile = \get_option('monsterinsights_site_profile', false);
151 + $completedMonsterInsights = isset($monsterInsightsSiteProfile['token']) && $monsterInsightsSiteProfile['token'];
152 +
153 + return compact(
154 + 'completedSetupGivewp',
155 + 'completedWoocommerceStore',
156 + 'completedSetupAIOSeo',
157 + 'completedWPFormsLite',
158 + 'completedYourWebShop',
159 + 'completedMonsterInsights'
160 + );
161 + }
121 162 }