|
1
|
|
|
<?php |
|
2
|
|
|
include_once( 'class.jetpack-admin-page.php' ); |
|
3
|
|
|
|
|
4
|
|
|
// Builds the landing page and its menu |
|
5
|
|
|
class Jetpack_Landing_Page extends Jetpack_Admin_Page { |
|
6
|
|
|
protected $dont_show_if_not_active = false; |
|
7
|
|
|
|
|
8
|
|
|
function get_page_hook() { |
|
9
|
|
|
$title = _x( 'Jetpack', 'The menu item label', 'jetpack' ); |
|
10
|
|
|
|
|
11
|
|
|
list( $jetpack_version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
|
12
|
|
|
if ( |
|
13
|
|
|
$jetpack_version |
|
14
|
|
|
&& |
|
15
|
|
|
$jetpack_version != JETPACK__VERSION |
|
16
|
|
|
&& |
|
17
|
|
|
( $new_modules = Jetpack::get_default_modules( $jetpack_version, JETPACK__VERSION ) ) |
|
|
|
|
|
|
18
|
|
|
&& |
|
19
|
|
|
is_array( $new_modules ) |
|
20
|
|
|
&& |
|
21
|
|
|
( $new_modules_count = count( $new_modules ) ) |
|
22
|
|
|
&& |
|
23
|
|
|
( Jetpack::is_active() || Jetpack::is_development_mode() ) |
|
24
|
|
|
) { |
|
25
|
|
|
$new_count_i18n = number_format_i18n( $new_modules_count ); |
|
26
|
|
|
$span_title = esc_attr( sprintf( _n( 'One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack' ), $new_count_i18n ) ); |
|
27
|
|
|
$format = _x( 'Jetpack %s', 'The menu item label with a new module count as %s', 'jetpack' ); |
|
28
|
|
|
$update_markup = "<span class='update-plugins count-{$new_modules_count}' title='$span_title'><span class='update-count'>$new_count_i18n</span></span>"; |
|
29
|
|
|
$title = sprintf( $format, $update_markup ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
// Add the main admin Jetpack menu with possible information about new |
|
33
|
|
|
// modules |
|
34
|
|
|
add_menu_page( 'Jetpack', $title, 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), 'div' ); |
|
35
|
|
|
// also create the submenu |
|
36
|
|
|
return add_submenu_page( 'jetpack', $title, $title, 'jetpack_admin_page', 'jetpack' ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function add_page_actions( $hook ) { |
|
40
|
|
|
// Add landing page specific underscore templates |
|
41
|
|
|
/** |
|
42
|
|
|
* Filters the js_templates callback value |
|
43
|
|
|
* |
|
44
|
|
|
* @since 3.6.0 |
|
45
|
|
|
* |
|
46
|
|
|
* @param array array( $this, 'js_templates' ) js_templates callback. |
|
47
|
|
|
* @param string $hook Specific admin page. |
|
48
|
|
|
*/ |
|
49
|
|
|
add_action( "admin_footer-$hook", apply_filters( 'jetpack_landing_page_js_templates_callback', array( $this, 'js_templates' ), $hook ) ); |
|
50
|
|
|
/** This action is documented in class.jetpack.php */ |
|
51
|
|
|
do_action( 'jetpack_admin_menu', $hook ); |
|
52
|
|
|
|
|
53
|
|
|
// Place the Jetpack menu item on top and others in the order they |
|
54
|
|
|
// appear |
|
55
|
|
|
add_filter( 'custom_menu_order', '__return_true' ); |
|
56
|
|
|
add_filter( 'menu_order', array( $this, 'jetpack_menu_order' ) ); |
|
57
|
|
|
|
|
58
|
|
|
add_action( 'jetpack_notices_update_settings', array( $this, 'show_notices_update_settings' ), 10, 1 ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/* |
|
62
|
|
|
* Build an array of a specific module tag. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string Name of the module tag |
|
65
|
|
|
* @return array The module slug, config url, and name of each Jump Start module |
|
66
|
|
|
*/ |
|
67
|
|
|
function jumpstart_module_tag( $tag ) { |
|
68
|
|
|
$modules = Jetpack_Admin::init()->get_modules(); |
|
69
|
|
|
|
|
70
|
|
|
$module_info = array(); |
|
71
|
|
|
foreach ( $modules as $module => $value ) { |
|
72
|
|
|
if ( in_array( $tag, $value['feature'] ) ) { |
|
73
|
|
|
$module_info[] = array( |
|
74
|
|
|
'module_slug' => $value['module'], |
|
75
|
|
|
'module_name' => $value['name'], |
|
76
|
|
|
'configure_url' => $value['configure_url'], |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
return $module_info; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/* |
|
84
|
|
|
* Only show Jump Start on first activation. |
|
85
|
|
|
* Any option 'jumpstart' other than 'new connection' will hide it. |
|
86
|
|
|
* |
|
87
|
|
|
* The option can be of 4 things, and will be stored as such: |
|
88
|
|
|
* new_connection : Brand new connection - Show |
|
89
|
|
|
* jumpstart_activated : Jump Start has been activated - dismiss |
|
90
|
|
|
* jetpack_action_taken: Manual activation of a module already happened - dismiss |
|
91
|
|
|
* jumpstart_dismissed : Manual dismissal of Jump Start - dismiss |
|
92
|
|
|
* |
|
93
|
|
|
* @return bool | show or hide |
|
94
|
|
|
*/ |
|
95
|
|
|
function jetpack_show_jumpstart() { |
|
96
|
|
|
$jumpstart_option = Jetpack_Options::get_option( 'jumpstart' ); |
|
97
|
|
|
|
|
98
|
|
|
$hide_options = array( |
|
99
|
|
|
'jumpstart_activated', |
|
100
|
|
|
'jetpack_action_taken', |
|
101
|
|
|
'jumpstart_dismissed' |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
if ( ! $jumpstart_option || in_array( $jumpstart_option, $hide_options ) ) { |
|
105
|
|
|
return false; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return true; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/* |
|
112
|
|
|
* List of recommended modules for the Jump Start paragraph text. |
|
113
|
|
|
* Will only show up in the paragraph if they are not active. |
|
114
|
|
|
* |
|
115
|
|
|
* @return string | comma-separated recommended modules that are not active |
|
116
|
|
|
*/ |
|
117
|
|
|
function jumpstart_list_modules() { |
|
118
|
|
|
$jumpstart_recommended = $this->jumpstart_module_tag( 'Jumpstart' ); |
|
119
|
|
|
|
|
120
|
|
|
$module_name = array(); |
|
121
|
|
|
foreach ( $jumpstart_recommended as $module => $val ) { |
|
122
|
|
|
if ( ! Jetpack::is_module_active( $val['module_slug'] ) ) { |
|
123
|
|
|
$module_name[] = $val['module_name']; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return $module_name; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
View Code Duplication |
function jetpack_menu_order( $menu_order ) { |
|
131
|
|
|
$jp_menu_order = array(); |
|
132
|
|
|
|
|
133
|
|
|
foreach ( $menu_order as $index => $item ) { |
|
134
|
|
|
if ( $item != 'jetpack' ) |
|
135
|
|
|
$jp_menu_order[] = $item; |
|
136
|
|
|
|
|
137
|
|
|
if ( $index == 0 ) |
|
138
|
|
|
$jp_menu_order[] = 'jetpack'; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
return $jp_menu_order; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
function js_templates() { |
|
145
|
|
|
Jetpack::init()->load_view( 'admin/landing-page-templates.php' ); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
function page_render() { |
|
149
|
|
|
// Handle redirects to configuration pages |
|
150
|
|
|
if ( ! empty( $_GET['configure'] ) ) { |
|
151
|
|
|
return $this->render_nojs_configurable(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
global $current_user; |
|
155
|
|
|
|
|
156
|
|
|
$is_connected = Jetpack::is_active(); |
|
157
|
|
|
$user_token = Jetpack_Data::get_access_token( $current_user->ID ); |
|
158
|
|
|
$is_user_connected = $user_token && ! is_wp_error( $user_token ); |
|
159
|
|
|
$is_master_user = $current_user->ID == Jetpack_Options::get_option( 'master_user' ); |
|
160
|
|
|
|
|
161
|
|
|
if ( Jetpack::is_development_mode() ) { |
|
162
|
|
|
$is_connected = true; |
|
163
|
|
|
$is_user_connected = true; |
|
164
|
|
|
$is_master_user = false; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
// Set template data for the admin page template |
|
168
|
|
|
$data = array( |
|
169
|
|
|
'is_connected' => $is_connected, |
|
170
|
|
|
'is_user_connected' => $is_user_connected, |
|
171
|
|
|
'is_master_user' => $is_master_user, |
|
172
|
|
|
'show_jumpstart' => $this->jetpack_show_jumpstart(), |
|
173
|
|
|
'jumpstart_list' => $this->jumpstart_list_modules(), |
|
174
|
|
|
'recommended_list' => $this->jumpstart_module_tag( 'Recommended' ), |
|
175
|
|
|
); |
|
176
|
|
|
Jetpack::init()->load_view( 'admin/admin-page.php', $data ); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Shows a notice message to users after they save Module config settings |
|
181
|
|
|
* @param string $module_id |
|
182
|
|
|
* @return null |
|
183
|
|
|
*/ |
|
184
|
|
|
function show_notices_update_settings( $module_id ) { |
|
185
|
|
|
$state = Jetpack::state( 'message' ); |
|
186
|
|
|
|
|
187
|
|
|
switch( $state ) { |
|
188
|
|
|
case 'module_activated' : |
|
189
|
|
|
if ( $module = Jetpack::get_module( Jetpack::state( 'module' ) ) ) { |
|
190
|
|
|
$message = sprintf( __( '<strong>%s Activated!</strong> You can change the setting of it here.', 'jetpack' ), $module['name'] ); |
|
191
|
|
|
} |
|
192
|
|
|
break; |
|
193
|
|
|
case 'module_configured': |
|
194
|
|
|
$message = __( '<strong>Module settings were saved.</strong> ', 'jetpack' ); |
|
195
|
|
|
break; |
|
196
|
|
|
case 'no_message' : |
|
197
|
|
|
break; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
if ( isset( $message ) ) { |
|
201
|
|
|
?> |
|
202
|
|
|
<div id="message" class="jetpack-message"> |
|
203
|
|
|
<div class="squeezer"> |
|
204
|
|
|
<h2><?php echo wp_kses( $message, array( 'strong' => array(), 'a' => array( 'href' => true ), 'br' => true ) ); ?></h2> |
|
205
|
|
|
<?php |
|
206
|
|
|
/** |
|
207
|
|
|
* Fires within the displayed message when a feature configuation is updated. |
|
208
|
|
|
* |
|
209
|
|
|
* This is a dynamic hook with `$module_id` being the slug of the module being updated. |
|
210
|
|
|
* |
|
211
|
|
|
* @since 3.4.0 |
|
212
|
|
|
*/ |
|
213
|
|
|
do_action( 'jetpack_notices_update_settings_' . $module_id ); ?> |
|
214
|
|
|
</div> |
|
215
|
|
|
</div> |
|
216
|
|
|
<?php |
|
217
|
|
|
} |
|
218
|
|
|
add_action( 'jetpack_notices', array( Jetpack::init(), 'admin_notices' ) ); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
// Render the configuration page for the module if it exists and an error |
|
222
|
|
|
// screen if the module is not configurable |
|
223
|
|
View Code Duplication |
function render_nojs_configurable() { |
|
224
|
|
|
echo '<div class="clouds-sm"></div>'; |
|
225
|
|
|
echo '<div class="wrap configure-module">'; |
|
226
|
|
|
|
|
227
|
|
|
$module_name = preg_replace( '/[^\da-z\-]+/', '', $_GET['configure'] ); |
|
228
|
|
|
if ( Jetpack::is_module( $module_name ) && current_user_can( 'jetpack_configure_modules' ) ) { |
|
229
|
|
|
Jetpack::admin_screen_configure_module( $module_name ); |
|
230
|
|
|
} else { |
|
231
|
|
|
echo '<h2>' . esc_html__( 'Error, bad module.', 'jetpack' ) . '</h2>'; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
echo '</div><!-- /wrap -->'; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/* |
|
238
|
|
|
* Build an array of Jump Start stats urls. |
|
239
|
|
|
* requires the build URL args passed as an array |
|
240
|
|
|
* |
|
241
|
|
|
* @param array $jumpstart_stats |
|
242
|
|
|
* @return (array) of built stats urls |
|
243
|
|
|
*/ |
|
244
|
|
|
function build_jumpstart_stats_urls( $jumpstart_stats ) { |
|
245
|
|
|
$jumpstart_urls = array(); |
|
246
|
|
|
|
|
247
|
|
|
foreach ( $jumpstart_stats as $value) { |
|
248
|
|
|
$jumpstart_urls[$value] = Jetpack::build_stats_url( array( 'x_jetpack-jumpstart' => $value ) ); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
return $jumpstart_urls; |
|
252
|
|
|
|
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/* |
|
256
|
|
|
* Build an array of NUX admin stats urls. |
|
257
|
|
|
* requires the build URL args passed as an array |
|
258
|
|
|
* |
|
259
|
|
|
* @param array $nux_admin_stats |
|
260
|
|
|
* @return (array) of built stats urls |
|
261
|
|
|
*/ |
|
262
|
|
|
function build_nux_admin_stats_urls( $nux_admin_stats ) { |
|
263
|
|
|
$nux_admin_urls = array(); |
|
264
|
|
|
|
|
265
|
|
|
foreach ( $nux_admin_stats as $value) { |
|
266
|
|
|
$nux_admin_urls[ $value ] = Jetpack::build_stats_url( array( 'x_jetpack-nux' => $value ) ); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
return $nux_admin_urls; |
|
270
|
|
|
|
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
function page_admin_scripts() { |
|
274
|
|
|
// Enqueue jp.js and localize it |
|
275
|
|
|
wp_enqueue_script( 'jetpack-js', plugins_url( '_inc/jp.js', JETPACK__PLUGIN_FILE ), |
|
276
|
|
|
array( 'jquery', 'wp-util' ), JETPACK__VERSION . '-20121111' ); |
|
277
|
|
|
wp_localize_script( |
|
278
|
|
|
'jetpack-js', |
|
279
|
|
|
'jetpackL10n', |
|
280
|
|
|
array( |
|
281
|
|
|
'ays_disconnect' => __( "This will deactivate all Jetpack modules.\nAre you sure you want to disconnect?", 'jetpack' ), |
|
282
|
|
|
'ays_unlink' => __( "This will prevent user-specific modules such as Publicize, Notifications and Post By Email from working.\nAre you sure you want to unlink?", 'jetpack' ), |
|
283
|
|
|
'ays_dismiss' => __( "This will deactivate Jetpack.\nAre you sure you want to deactivate Jetpack?", 'jetpack' ), |
|
284
|
|
|
'view_all_features' => __( 'View all Jetpack features', 'jetpack' ), |
|
285
|
|
|
'no_modules_found' => sprintf( __( 'Sorry, no modules were found for the search term "%s"', 'jetpack' ), '{term}' ), |
|
286
|
|
|
'modules' => Jetpack::get_translated_modules( array_values( Jetpack_Admin::init()->get_modules() ) ), |
|
287
|
|
|
'currentVersion' => JETPACK__VERSION, |
|
288
|
|
|
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
289
|
|
|
'show_jumpstart' => $this->jetpack_show_jumpstart(), |
|
290
|
|
|
'activate_nonce' => wp_create_nonce( 'jetpack-jumpstart-nonce' ), |
|
291
|
|
|
'admin_nonce' => wp_create_nonce( 'jetpack-admin-nonce' ), |
|
292
|
|
|
'jumpstart_stats_urls' => $this->build_jumpstart_stats_urls( array( 'dismiss', 'jumpstarted', 'learnmore', 'viewed', 'manual' ) ), |
|
293
|
|
|
'admin_stats_urls' => $this->build_nux_admin_stats_urls( array( 'enabled', 'deactivated', 'learnmore' ) ), |
|
294
|
|
|
'site_url_manage' => Jetpack::build_raw_urls( get_site_url() ), |
|
295
|
|
|
) |
|
296
|
|
|
); |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: