1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\Pollux; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\Pollux\Application; |
6
|
|
|
use GeminiLabs\Pollux\Config\Config; |
7
|
|
|
use GeminiLabs\Pollux\Helper; |
8
|
|
|
use GeminiLabs\Pollux\PostType\Archive; |
9
|
|
|
use GeminiLabs\Pollux\Settings\Settings; |
10
|
|
|
use WP_Screen; |
11
|
|
|
|
12
|
|
|
class Controller |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Application |
16
|
|
|
*/ |
17
|
|
|
protected $app; |
18
|
|
|
|
19
|
|
|
public function __construct( Application $app ) |
20
|
|
|
{ |
21
|
|
|
$this->app = $app; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return array |
26
|
|
|
* @filter plugin_action_links_pollux/pollux.php |
27
|
|
|
*/ |
28
|
|
|
public function filterPluginLinks( array $links ) |
29
|
|
|
{ |
30
|
|
|
$settings_url = admin_url( sprintf( 'options-general.php?page=%s', $this->app->id )); |
31
|
|
|
$links[] = $this->app->config->disable_config |
32
|
|
|
? sprintf( '<span class="network_only">%s</span>', __( 'Settings Disabled', 'pollux' )) |
33
|
|
|
: sprintf( '<a href="%s">%s</a>', $settings_url, __( 'Settings', 'pollux' )); |
34
|
|
|
return $links; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return void |
39
|
|
|
* @filter admin_footer_text |
40
|
|
|
*/ |
41
|
|
|
public function filterWordPressFooter( $text ) |
42
|
|
|
{ |
43
|
|
|
if( $this->app->config->remove_wordpress_footer )return; |
44
|
|
|
return $text; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return void |
49
|
|
|
* @action admin_enqueue_scripts |
50
|
|
|
*/ |
51
|
|
|
public function registerAssets() |
52
|
|
|
{ |
53
|
|
|
$screen = ( new Helper )->getCurrentScreen(); |
54
|
|
|
|
55
|
|
|
$this->registerArchiveAssets( $screen ); |
56
|
|
|
$this->registerCodemirrorAssets( $screen ); |
57
|
|
|
$this->registerSettingsAssets( $screen ); |
58
|
|
|
|
59
|
|
|
wp_enqueue_style( 'pollux/main.css', |
60
|
|
|
$this->app->url( 'assets/main.css' ), |
61
|
|
|
apply_filters( 'pollux/enqueue/css/deps', [] ), |
62
|
|
|
$this->app->version |
63
|
|
|
); |
64
|
|
|
wp_enqueue_script( 'pollux/main.js', |
65
|
|
|
$this->app->url( 'assets/main.js' ), |
66
|
|
|
apply_filters( 'pollux/enqueue/js/deps', [] ), |
67
|
|
|
$this->app->version |
68
|
|
|
); |
69
|
|
|
wp_localize_script( 'pollux/main.js', |
70
|
|
|
apply_filters( 'pollux/enqueue/js/localize/name', $this->app->id ), |
71
|
|
|
apply_filters( 'pollux/enqueue/js/localize/variables', [] ) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return void |
77
|
|
|
* @action admin_init |
78
|
|
|
*/ |
79
|
|
|
public function removeDashboardWidgets() |
80
|
|
|
{ |
81
|
|
|
if( !$this->app->config->remove_dashboard_widgets )return; |
82
|
|
|
$widgets = apply_filters( 'pollux/dashoard/widgets', [ |
83
|
|
|
'dashboard_quick_press', |
84
|
|
|
]); |
85
|
|
|
foreach( $widgets as $widget ) { |
86
|
|
|
remove_meta_box( $widget, 'dashboard', 'normal' ); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return void |
92
|
|
|
* @action wp_before_admin_bar_render |
93
|
|
|
*/ |
94
|
|
|
public function removeWordPressMenu() |
95
|
|
|
{ |
96
|
|
|
if( !$this->app->config->remove_wordpress_menu )return; |
97
|
|
|
global $wp_admin_bar; |
98
|
|
|
$wp_admin_bar->remove_menu( 'wp-logo' ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return void |
103
|
|
|
*/ |
104
|
|
|
protected function registerArchiveAssets( WP_Screen $screen ) |
105
|
|
|
{ |
106
|
|
|
if(( new Helper )->endsWith( '_archive', $screen->id ) && $screen->pagenow == 'edit.php' ) { |
107
|
|
|
wp_enqueue_script( 'common' ); |
108
|
|
|
wp_enqueue_script( 'editor-expand' ); |
109
|
|
|
wp_enqueue_script( 'post' ); |
110
|
|
|
wp_enqueue_script( 'postbox' ); |
111
|
|
|
wp_enqueue_script( 'wp-lists' ); |
112
|
|
|
if( wp_is_mobile() ) { |
113
|
|
|
wp_enqueue_script( 'jquery-touch-punch' ); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return void |
120
|
|
|
*/ |
121
|
|
|
protected function registerCodemirrorAssets( WP_Screen $screen ) |
122
|
|
|
{ |
123
|
|
|
if( $screen->id == 'settings_page_pollux' && $screen->pagenow == 'options-general.php' ) { |
124
|
|
|
wp_enqueue_style( 'pollux/codemirror.css', |
125
|
|
|
$this->app->url( 'assets/codemirror.css' ), |
126
|
|
|
[], |
127
|
|
|
$this->app->version |
128
|
|
|
); |
129
|
|
|
wp_enqueue_script( 'pollux/codemirror.js', |
130
|
|
|
$this->app->url( 'assets/codemirror.js' ), |
131
|
|
|
['pollux/main.js'], |
132
|
|
|
$this->app->version |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return void |
139
|
|
|
*/ |
140
|
|
|
protected function registerSettingsAssets( WP_Screen $screen ) |
141
|
|
|
{ |
142
|
|
|
if( $screen->id == sprintf( 'toplevel_page_%s', Settings::id() )) { |
143
|
|
|
wp_enqueue_script( 'common' ); |
144
|
|
|
wp_enqueue_script( 'postbox' ); |
145
|
|
|
wp_enqueue_script( 'wp-lists' ); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|