1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\entities\routing\handlers\admin; |
4
|
|
|
|
5
|
|
|
use DomainException; |
6
|
|
|
use EE_Dependency_Map; |
7
|
|
|
use EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData; |
8
|
|
|
use EventEspresso\core\domain\services\assets\EspressoCoreAppAssetManager; |
9
|
|
|
use EventEspresso\core\domain\values\assets\JavascriptAsset; |
10
|
|
|
use EventEspresso\core\services\assets\AssetCollection; |
11
|
|
|
use EventEspresso\core\services\routing\Route; |
12
|
|
|
use EventEspresso\core\domain\entities\routing\data_nodes\domains\WordPressPluginsPageData; |
13
|
|
|
use EventEspresso\core\domain\services\admin\PluginUpsells; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class WordPressPluginsPage |
17
|
|
|
* detects and executes logic for the WordPress Plugins admin page |
18
|
|
|
* |
19
|
|
|
* @package EventEspresso\core\domain\entities\routing\handlers\admin |
20
|
|
|
* @author Brent Christensen |
21
|
|
|
* @since $VID:$ |
22
|
|
|
*/ |
23
|
|
|
class WordPressPluginsPage extends Route |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* returns true if the current request matches this route |
28
|
|
|
* |
29
|
|
|
* @return bool |
30
|
|
|
* @since $VID:$ |
31
|
|
|
*/ |
32
|
|
|
public function matchesCurrentRequest() |
33
|
|
|
{ |
34
|
|
|
global $pagenow; |
35
|
|
|
return $this->request->isAdmin() && $pagenow && $pagenow === 'plugins.php'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @since $VID:$ |
41
|
|
|
*/ |
42
|
|
|
protected function registerDependencies() |
43
|
|
|
{ |
44
|
|
|
$this->dependency_map->registerDependencies( |
45
|
|
|
'EventEspresso\core\domain\entities\routing\data_nodes\domains\WordPressPluginsPageData', |
46
|
|
|
[ |
47
|
|
|
'EventEspresso\core\domain\services\admin\ExitModal' => EE_Dependency_Map::load_from_cache, |
48
|
|
|
'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
49
|
|
|
] |
50
|
|
|
); |
51
|
|
|
$this->dependency_map->registerDependencies( |
52
|
|
|
'EventEspresso\core\domain\services\admin\ExitModal', |
53
|
|
|
['EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache] |
54
|
|
|
); |
55
|
|
|
$this->dependency_map->registerDependencies( |
56
|
|
|
'EventEspresso\core\domain\services\admin\PluginUpsells', |
57
|
|
|
['EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache] |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
/** @var EventEspressoData $primary_data_node */ |
61
|
|
|
$primary_data_node = $this->loader->getShared( |
62
|
|
|
'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData' |
63
|
|
|
); |
64
|
|
|
$primary_data_node->setTargetScript(EspressoCoreAppAssetManager::JS_HANDLE_EDITOR); |
65
|
|
|
/** @var WordPressPluginsPageData $data_node */ |
66
|
|
|
$data_node = $this->loader->getShared( |
67
|
|
|
'EventEspresso\core\domain\entities\routing\data_nodes\domains\WordPressPluginsPageData' |
68
|
|
|
); |
69
|
|
|
$this->setDataNode($data_node); |
70
|
|
|
/** @var PluginUpsells $plugin_upsells */ |
71
|
|
|
$plugin_upsells = $this->loader->getShared('EventEspresso\core\domain\services\admin\PluginUpsells'); |
72
|
|
|
$plugin_upsells->decafUpsells(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* implements logic required to run during request |
78
|
|
|
* |
79
|
|
|
* @return bool |
80
|
|
|
* @since $VID:$ |
81
|
|
|
*/ |
82
|
|
|
protected function requestHandler() |
83
|
|
|
{ |
84
|
|
|
/** @var EspressoCoreAppAssetManager $asset_manager */ |
85
|
|
|
$this->asset_manager = $this->loader->getShared( |
86
|
|
|
'EventEspresso\core\domain\services\assets\EspressoCoreAppAssetManager' |
87
|
|
|
); |
88
|
|
|
add_action('admin_enqueue_scripts', [$this, 'addDependencies'], 3); |
89
|
|
|
add_action('admin_enqueue_scripts', [$this->asset_manager, 'enqueueBrowserAssets'], 100); |
90
|
|
|
wp_enqueue_style('wp-components'); |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* EspressoCoreAppAssetManager sets 'wp-i18n' as the only dependency for its scripts, |
97
|
|
|
* but the ExitSurvey uses additional WP core assets, so this method retrieves the |
98
|
|
|
* 'eventespresso-core-app' script and updates its dependencies accordingly |
99
|
|
|
* |
100
|
|
|
* @since $VID:$ |
101
|
|
|
*/ |
102
|
|
|
public function addDependencies() |
103
|
|
|
{ |
104
|
|
|
if (! $this->asset_manager instanceof EspressoCoreAppAssetManager) { |
105
|
|
|
throw new DomainException( |
106
|
|
|
esc_html__('Invalid or missing EspressoCoreAppAssetManager!', 'event_espresso') |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
$assets = $this->asset_manager->getAssets(); |
110
|
|
|
if (! $assets instanceof AssetCollection) { |
111
|
|
|
throw new DomainException( |
112
|
|
|
esc_html__('Invalid or missing AssetCollection!', 'event_espresso') |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
$appJs = $assets->getJavascriptAsset(EspressoCoreAppAssetManager::JS_HANDLE_EDITOR); |
116
|
|
|
if (! $appJs instanceof JavascriptAsset) { |
117
|
|
|
throw new DomainException( |
118
|
|
|
sprintf( |
119
|
|
|
esc_html__('Invalid or missing JavascriptAsset! Expected', 'event_espresso'), |
120
|
|
|
EspressoCoreAppAssetManager::JS_HANDLE_EDITOR |
121
|
|
|
) |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
$appJs->addDependencies(['wp-components', 'wp-url']); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|