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 | static function init() { |
||
16 | if ( is_null( self::$instance ) ) { |
||
17 | self::$instance = new Jetpack_JITM; |
||
18 | } |
||
19 | |||
20 | return self::$instance; |
||
21 | } |
||
22 | |||
23 | private function __construct() { |
||
24 | if ( ! Jetpack::is_active() ) { |
||
25 | return; |
||
26 | } |
||
27 | global $pagenow; |
||
28 | $jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); |
||
29 | $showphoton = empty( $jetpack_hide_jitm['photon'] ) ? 'show' : $jetpack_hide_jitm['photon']; |
||
30 | $showmanage = empty( $jetpack_hide_jitm['manage'] ) ? 'show' : $jetpack_hide_jitm['manage']; |
||
31 | if ( 'media-new.php' == $pagenow && ! Jetpack::is_module_active( 'photon' ) && 'hide' != $showphoton ) { |
||
32 | add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) ); |
||
33 | add_action( 'post-plupload-upload-ui', array( $this, 'photon_msg' ) ); |
||
34 | } |
||
35 | else if ( 'update-core.php' == $pagenow && 'hide' != $showmanage ) { |
||
36 | add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) ); |
||
37 | add_action( 'admin_notices', array( $this, 'manage_msg' ) ); |
||
38 | } |
||
39 | } |
||
40 | |||
41 | |||
42 | /* |
||
43 | * Present Manage just in time activation msg on update-core.php |
||
44 | * |
||
45 | */ |
||
46 | function manage_msg() { |
||
47 | if ( current_user_can( 'jetpack_manage_modules' ) ) { |
||
48 | $normalized_site_url = Jetpack::build_raw_urls( get_home_url() ); |
||
49 | $manage_active = Jetpack::is_module_active( 'manage' ); |
||
0 ignored issues
–
show
|
|||
50 | ?> |
||
51 | <div class="jp-jitm"> |
||
52 | <a href="#" data-module="manage" class="dismiss"><span class="genericon genericon-close"></span></a> |
||
53 | <div class="jp-emblem"> |
||
54 | <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"> |
||
55 | <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"/> |
||
56 | </svg> |
||
57 | </div> |
||
58 | <p class="msg"> |
||
59 | <?php _e( 'Reduce security risks with automated plugin updates.', 'jetpack' ); ?> |
||
60 | </p> |
||
61 | <p> |
||
62 | <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> |
||
63 | </p> |
||
64 | </div> |
||
65 | <?php |
||
66 | //jitm is being viewed, track it |
||
67 | $jetpack = Jetpack::init(); |
||
68 | $jetpack->stat( 'jitm', 'manage-viewed-' . JETPACK__VERSION ); |
||
69 | $jetpack->do_stats( 'server_side' ); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /* |
||
74 | * Present Photon just in time activation msg |
||
75 | * |
||
76 | */ |
||
77 | function photon_msg() { |
||
78 | if ( current_user_can( 'jetpack_manage_modules' ) ) { ?> |
||
79 | <div class="jp-jitm"> |
||
80 | <a href="#" data-module="photon" 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( 'Speed up your photos and save bandwidth costs by using a free content delivery network.', 'jetpack' ); ?> |
||
88 | </p> |
||
89 | <p> |
||
90 | <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> |
||
91 | </p> |
||
92 | </div> |
||
93 | <?php |
||
94 | //jitm is being viewed, track it |
||
95 | $jetpack = Jetpack::init(); |
||
96 | $jetpack->stat( 'jitm', 'photon-viewed-' . JETPACK__VERSION ); |
||
97 | $jetpack->do_stats( 'server_side' ); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /* |
||
102 | * Function to enqueue jitm css and js |
||
103 | */ |
||
104 | function jitm_enqueue_files( $hook ) { |
||
0 ignored issues
–
show
|
|||
105 | |||
106 | $wp_styles = new WP_Styles(); |
||
107 | $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
||
108 | wp_enqueue_style( 'jetpack-jitm-css', plugins_url( "css/jetpack-admin-jitm{$min}.css", JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION . '-201243242' ); |
||
109 | $wp_styles->add_data( 'jetpack-jitm-css', 'rtl', true ); |
||
110 | |||
111 | //Build stats url for tracking manage button |
||
112 | $jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'wordpresstools' ) ); |
||
113 | |||
114 | // Enqueue javascript to handle jitm notice events |
||
115 | wp_enqueue_script( 'jetpack-jitm-js', plugins_url( '_inc/jetpack-jitm.js', JETPACK__PLUGIN_FILE ), |
||
116 | array( 'jquery' ), JETPACK__VERSION, true ); |
||
117 | wp_localize_script( |
||
118 | 'jetpack-jitm-js', |
||
119 | 'jitmL10n', |
||
120 | array( |
||
121 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
||
122 | 'jitm_nonce' => wp_create_nonce( 'jetpack-jitm-nonce' ), |
||
123 | 'photon_msgs' => array( |
||
124 | 'success' => __( 'Success! Photon is now actively optimizing and serving your images for free.', 'jetpack' ), |
||
125 | 'fail' => __( 'We are sorry but unfortunately Photon did not activate.', 'jetpack' ) |
||
126 | ), |
||
127 | 'manage_msgs' => array( |
||
128 | 'success' => __( 'Success! WordPress.com tools are now active.', 'jetpack' ), |
||
129 | 'fail' => __( 'We are sorry but unfortunately Manage did not activate.', 'jetpack' ) |
||
130 | ), |
||
131 | 'jitm_stats_url' => $jitm_stats_url |
||
132 | ) |
||
133 | ); |
||
134 | } |
||
135 | } |
||
136 | /** |
||
137 | * Filter to turn off all just in time messages |
||
138 | * |
||
139 | * @since 3.7.0 |
||
140 | * |
||
141 | * @param bool true Whether to show just in time messages. |
||
142 | */ |
||
143 | if ( apply_filters( 'jetpack_just_in_time_msgs', false ) ) { |
||
144 | Jetpack_JITM::init(); |
||
145 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.