These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Jetpack just in time messaging through out the admin |
||
5 | * |
||
6 | * @since 3.7.0 |
||
7 | */ |
||
8 | class Jetpack_JITM { |
||
9 | |||
10 | /** |
||
11 | * @var Jetpack_JITM |
||
12 | **/ |
||
13 | private static $instance = null; |
||
14 | |||
15 | /** |
||
16 | * Get user dismissed messages. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | private static $jetpack_hide_jitm = array(); |
||
21 | |||
22 | static function init() { |
||
23 | if ( is_null( self::$instance ) ) { |
||
24 | self::$instance = new Jetpack_JITM; |
||
25 | } |
||
26 | |||
27 | return self::$instance; |
||
28 | } |
||
29 | |||
30 | private function __construct() { |
||
31 | if ( ! Jetpack::is_active() ) { |
||
32 | return; |
||
33 | } |
||
34 | add_action( 'current_screen', array( $this, 'prepare_jitms' ) ); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Prepare actions according to screen and post type. |
||
39 | * |
||
40 | * @since 3.8.2 |
||
41 | * |
||
42 | * @param object $screen |
||
43 | */ |
||
44 | function prepare_jitms( $screen ) { |
||
45 | global $pagenow; |
||
46 | // Only show auto update JITM if auto updates are allowed in this installation |
||
47 | $auto_updates_disabled = defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED; |
||
48 | // The option returns false when nothing was dismissed |
||
49 | self::$jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); |
||
50 | // so if it's not an array, it means no JITM was dismissed |
||
51 | if ( ! is_array( self::$jetpack_hide_jitm ) ) { |
||
52 | if ( 'media-new.php' == $pagenow && ! Jetpack::is_module_active( 'photon' ) ) { |
||
53 | add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) ); |
||
54 | add_action( 'post-plupload-upload-ui', array( $this, 'photon_msg' ) ); |
||
55 | } |
||
56 | else if ( 'update-core.php' == $pagenow && ! $auto_updates_disabled && ! Jetpack::is_module_active( 'manage' ) ) { |
||
57 | add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) ); |
||
58 | add_action( 'admin_notices', array( $this, 'manage_msg' ) ); |
||
59 | } |
||
60 | elseif ( 'plugins.php' == $pagenow && ! $auto_updates_disabled && isset( $_GET['activate'] ) && 'true' === $_GET['activate'] ) { |
||
61 | add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) ); |
||
62 | add_action( 'pre_current_active_plugins', array( $this, 'manage_pi_msg' ) ); |
||
63 | } |
||
64 | elseif ( 'post-new.php' == $pagenow && in_array( $screen->post_type, array( 'post', 'page' ) ) ) { |
||
65 | add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) ); |
||
66 | add_action( 'admin_notices', array( $this, 'editor_msg' ) ); |
||
67 | } |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /* |
||
72 | * Present Manage just in time activation msg on update-core.php |
||
73 | * |
||
74 | */ |
||
75 | function manage_msg() { |
||
76 | if ( current_user_can( 'jetpack_manage_modules' ) ) { |
||
77 | $normalized_site_url = Jetpack::build_raw_urls( get_home_url() ); |
||
78 | ?> |
||
79 | <div class="jp-jitm"> |
||
80 | <a href="#" data-module="manage" class="dismiss"><span class="genericon genericon-close"></span></a> |
||
81 | <div class="jp-emblem"> |
||
82 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0" y="0" viewBox="0 0 172.9 172.9" enable-background="new 0 0 172.9 172.9" xml:space="preserve"> |
||
83 | <path d="M86.4 0C38.7 0 0 38.7 0 86.4c0 47.7 38.7 86.4 86.4 86.4s86.4-38.7 86.4-86.4C172.9 38.7 134.2 0 86.4 0zM83.1 106.6l-27.1-6.9C49 98 45.7 90.1 49.3 84l33.8-58.5V106.6zM124.9 88.9l-33.8 58.5V66.3l27.1 6.9C125.1 74.9 128.4 82.8 124.9 88.9z"/> |
||
84 | </svg> |
||
85 | </div> |
||
86 | <p class="msg"> |
||
87 | <?php _e( 'Reduce security risks with automated plugin updates.', 'jetpack' ); ?> |
||
88 | </p> |
||
89 | <p> |
||
90 | <img class="j-spinner hide" src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>" alt="Loading ..." /><a href="#" data-module="manage" class="activate button <?php if( Jetpack::is_module_active( 'manage' ) ) { echo 'hide'; } ?>"><?php esc_html_e( 'Activate Now', 'jetpack' ); ?></a><a href="<?php echo esc_url( 'https://wordpress.com/plugins/' . $normalized_site_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Go to WordPress.com to try these features', 'jetpack' ); ?>" id="jetpack-wordpressdotcom" class="button button-jetpack <?php if( ! Jetpack::is_module_active( 'manage' ) ) { echo 'hide'; } ?>"><?php esc_html_e( 'Go to WordPress.com', 'jetpack' ); ?></a> |
||
91 | </p> |
||
92 | </div> |
||
93 | <?php |
||
94 | //jitm is being viewed, track it |
||
95 | $jetpack = Jetpack::init(); |
||
96 | $jetpack->stat( 'jitm', 'manage-viewed-' . JETPACK__VERSION ); |
||
97 | $jetpack->do_stats( 'server_side' ); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /* |
||
102 | * Present Photon just in time activation msg |
||
103 | * |
||
104 | */ |
||
105 | function photon_msg() { |
||
106 | if ( current_user_can( 'jetpack_manage_modules' ) ) { ?> |
||
107 | <div class="jp-jitm"> |
||
108 | <a href="#" data-module="photon" class="dismiss"><span class="genericon genericon-close"></span></a> |
||
109 | <div class="jp-emblem"> |
||
110 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0" y="0" viewBox="0 0 172.9 172.9" enable-background="new 0 0 172.9 172.9" xml:space="preserve"> |
||
111 | <path d="M86.4 0C38.7 0 0 38.7 0 86.4c0 47.7 38.7 86.4 86.4 86.4s86.4-38.7 86.4-86.4C172.9 38.7 134.2 0 86.4 0zM83.1 106.6l-27.1-6.9C49 98 45.7 90.1 49.3 84l33.8-58.5V106.6zM124.9 88.9l-33.8 58.5V66.3l27.1 6.9C125.1 74.9 128.4 82.8 124.9 88.9z"/> |
||
112 | </svg> |
||
113 | </div> |
||
114 | <p class="msg"> |
||
115 | <?php _e( 'Speed up your photos and save bandwidth costs by using a free content delivery network.', 'jetpack' ); ?> |
||
116 | </p> |
||
117 | <p> |
||
118 | <img class="j-spinner hide" style="margin-top: 13px;" width="17" height="17" src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>" alt="Loading ..." /><a href="#" data-module="photon" class="activate button button-jetpack"><?php esc_html_e( 'Activate Photon', 'jetpack' ); ?></a> |
||
119 | </p> |
||
120 | </div> |
||
121 | <?php |
||
122 | //jitm is being viewed, track it |
||
123 | $jetpack = Jetpack::init(); |
||
124 | $jetpack->stat( 'jitm', 'photon-viewed-' . JETPACK__VERSION ); |
||
125 | $jetpack->do_stats( 'server_side' ); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Display message prompting user to enable auto-updates in WordPress.com. |
||
131 | * |
||
132 | * @since 3.8.2 |
||
133 | */ |
||
134 | function manage_pi_msg() { |
||
135 | if ( current_user_can( 'jetpack_manage_modules' ) ) { |
||
136 | $normalized_site_url = Jetpack::build_raw_urls( get_home_url() ); |
||
137 | $manage_active = Jetpack::is_module_active( 'manage' ); |
||
138 | /** This filter is documented in wp-admin/includes/class-wp-upgrader.php */ |
||
139 | /*+ TODO: pass correct second parameter to filter */ |
||
0 ignored issues
–
show
Coding Style
Best Practice
introduced
by
![]() |
|||
140 | $auto_update_plugin = apply_filters( 'auto_update_plugin', true, null ); |
||
141 | if ( ! $manage_active && $auto_update_plugin ) : |
||
142 | ?> |
||
143 | <div class="jp-jitm"> |
||
144 | <a href="#" data-module="manage-pi" class="dismiss"><span class="genericon genericon-close"></span></a> |
||
145 | <div class="jp-emblem"> |
||
146 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0" y="0" viewBox="0 0 172.9 172.9" enable-background="new 0 0 172.9 172.9" xml:space="preserve"> |
||
147 | <path d="M86.4 0C38.7 0 0 38.7 0 86.4c0 47.7 38.7 86.4 86.4 86.4s86.4-38.7 86.4-86.4C172.9 38.7 134.2 0 86.4 0zM83.1 106.6l-27.1-6.9C49 98 45.7 90.1 49.3 84l33.8-58.5V106.6zM124.9 88.9l-33.8 58.5V66.3l27.1 6.9C125.1 74.9 128.4 82.8 124.9 88.9z"/> |
||
148 | </svg> |
||
149 | </div> |
||
150 | <?php if ( ! $manage_active ) : ?> |
||
151 | <p class="msg"> |
||
152 | <?php _e( 'Save time with automated plugin updates.', 'jetpack' ); ?> |
||
153 | </p> |
||
154 | <p> |
||
155 | <img class="j-spinner hide" src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>" alt="<?php echo esc_attr__( 'Loading...', 'jetpack' ); ?>" /><a href="#" data-module="manage" data-module-success="<?php esc_attr_e( 'Success!', 'jetpack' ); ?>" class="activate button"><?php esc_html_e( 'Activate remote management', 'jetpack' ); ?></a> |
||
156 | </p> |
||
157 | <?php elseif ( $manage_active ) : ?> |
||
158 | <p> |
||
159 | <?php esc_html_e( 'Save time with auto updates on WordPress.com', 'jetpack' ); ?> |
||
160 | </p> |
||
161 | <?php endif; // manage inactive ?> |
||
162 | <p class="show-after-enable <?php echo $manage_active ? '' : 'hide' ; ?>"> |
||
163 | <a href="<?php echo esc_url( 'https://wordpress.com/plugins/' . $normalized_site_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Go to WordPress.com to enable auto-updates for plugins', 'jetpack' ); ?>" data-module="manage-pi" class="button button-jetpack launch show-after-enable"><?php if ( ! $manage_active ) : ?><?php esc_html_e( 'Enable auto-updates on WordPress.com', 'jetpack' ); ?><?php elseif ( $manage_active ) : ?><?php esc_html_e( 'Enable auto-updates', 'jetpack' ); ?><?php endif; // manage inactive ?></a> |
||
164 | </p> |
||
165 | </div> |
||
166 | <?php |
||
167 | //jitm is being viewed, track it |
||
168 | $jetpack = Jetpack::init(); |
||
169 | $jetpack->stat( 'jitm', 'manage-pi-viewed-' . JETPACK__VERSION ); |
||
170 | $jetpack->do_stats( 'server_side' ); |
||
171 | endif; // manage inactive |
||
172 | } |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Display message in editor prompting user to compose entry in WordPress.com. |
||
177 | * |
||
178 | * @since 3.8.2 |
||
179 | */ |
||
180 | function editor_msg() { |
||
181 | global $typenow; |
||
182 | if ( current_user_can( 'jetpack_manage_modules' ) && current_user_can( 'manage_options' ) ) { |
||
183 | $normalized_site_url = Jetpack::build_raw_urls( get_home_url() ); |
||
184 | $editor_dismissed = isset( self::$jetpack_hide_jitm['editor'] ); |
||
185 | if ( ! $editor_dismissed ) : |
||
186 | ?> |
||
187 | <div class="jp-jitm"> |
||
188 | <a href="#" data-module="editor" class="dismiss"><span class="genericon genericon-close"></span></a> |
||
189 | <div class="jp-emblem"> |
||
190 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0" y="0" viewBox="0 0 172.9 172.9" enable-background="new 0 0 172.9 172.9" xml:space="preserve"> |
||
191 | <path d="M86.4 0C38.7 0 0 38.7 0 86.4c0 47.7 38.7 86.4 86.4 86.4s86.4-38.7 86.4-86.4C172.9 38.7 134.2 0 86.4 0zM83.1 106.6l-27.1-6.9C49 98 45.7 90.1 49.3 84l33.8-58.5V106.6zM124.9 88.9l-33.8 58.5V66.3l27.1 6.9C125.1 74.9 128.4 82.8 124.9 88.9z"/> |
||
192 | </svg> |
||
193 | </div> |
||
194 | <p class="msg"> |
||
195 | <?php esc_html_e( 'Try the brand new editor.', 'jetpack' ); ?> |
||
196 | </p> |
||
197 | <p> |
||
198 | <a href="<?php echo esc_url( 'https://wordpress.com/' . $typenow . '/' . $normalized_site_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Write on WordPress.com', 'jetpack' ); ?>" data-module="editor" class="button button-jetpack launch show-after-enable"><?php esc_html_e( 'Write on WordPress.com', 'jetpack' ); ?></a> |
||
199 | </p> |
||
200 | </div> |
||
201 | <?php |
||
202 | //jitm is being viewed, track it |
||
203 | $jetpack = Jetpack::init(); |
||
204 | $jetpack->stat( 'jitm', 'editor-viewed-' . JETPACK__VERSION ); |
||
205 | $jetpack->do_stats( 'server_side' ); |
||
206 | endif; // manage or editor inactive |
||
207 | } |
||
208 | } |
||
209 | |||
210 | /* |
||
211 | * Function to enqueue jitm css and js |
||
212 | */ |
||
213 | function jitm_enqueue_files( $hook ) { |
||
214 | |||
215 | $wp_styles = new WP_Styles(); |
||
216 | $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
||
217 | wp_enqueue_style( 'jetpack-jitm-css', plugins_url( "css/jetpack-admin-jitm{$min}.css", JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION . '-201243242' ); |
||
218 | $wp_styles->add_data( 'jetpack-jitm-css', 'rtl', true ); |
||
219 | |||
220 | //Build stats url for tracking manage button |
||
221 | $jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'wordpresstools' ) ); |
||
222 | |||
223 | // Enqueue javascript to handle jitm notice events |
||
224 | wp_enqueue_script( 'jetpack-jitm-js', plugins_url( '_inc/jetpack-jitm.js', JETPACK__PLUGIN_FILE ), |
||
225 | array( 'jquery' ), JETPACK__VERSION, true ); |
||
226 | wp_localize_script( |
||
227 | 'jetpack-jitm-js', |
||
228 | 'jitmL10n', |
||
229 | array( |
||
230 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
||
231 | 'jitm_nonce' => wp_create_nonce( 'jetpack-jitm-nonce' ), |
||
232 | 'photon_msgs' => array( |
||
233 | 'success' => __( 'Success! Photon is now actively optimizing and serving your images for free.', 'jetpack' ), |
||
234 | 'fail' => __( 'We are sorry but unfortunately Photon did not activate.', 'jetpack' ) |
||
235 | ), |
||
236 | 'manage_msgs' => array( |
||
237 | 'success' => __( 'Success! WordPress.com tools are now active.', 'jetpack' ), |
||
238 | 'fail' => __( 'We are sorry but unfortunately Manage did not activate.', 'jetpack' ) |
||
239 | ), |
||
240 | 'jitm_stats_url' => $jitm_stats_url |
||
241 | ) |
||
242 | ); |
||
243 | } |
||
244 | } |
||
245 | /** |
||
246 | * Filter to turn off all just in time messages |
||
247 | * |
||
248 | * @since 3.7.0 |
||
249 | * |
||
250 | * @param bool true Whether to show just in time messages. |
||
251 | */ |
||
252 | if ( apply_filters( 'jetpack_just_in_time_msgs', false ) ) { |
||
253 | Jetpack_JITM::init(); |
||
254 | } |