PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | jetpack_vendor/automattic/jetpack-logo/src/class-logo.php +68 -0 16.2 → 16.3 View file →
@@ -118,5 +118,73 @@
118 118 $encoded_logo = base64_encode( $base_logo ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- The encoded version is used as data URI to use the logo in CSS.
119 119
120 120 return 'data:image/svg+xml;base64,' . $encoded_logo;
121 121 }
122 +
123 + /**
124 + * Return a base64 encoded SVG of the Jetpack logo using the current admin menu color.
125 + *
126 + * This mirrors the fallback order in WordPress's wp_color_scheme_settings(), whose
127 + * JavaScript output recolors data URI SVG icons after the page loads.
128 + *
129 + * @since 4.0.1
130 + *
131 + * @param string|null $color_scheme Admin color scheme to use. Defaults to the
132 + * current user's scheme.
133 + *
134 + * @return string
135 + */
136 + public function get_base64_admin_menu_logo( $color_scheme = null ) {
137 + global $_wp_admin_css_colors;
138 +
139 + /*
140 + * WordPress builds the admin menu before admin_init, when its color schemes
141 + * are registered. Refresh the stored menu icon afterward, before output.
142 + */
143 + if (
144 + null === $color_scheme
145 + && function_exists( 'add_action' )
146 + && function_exists( 'did_action' )
147 + && ! did_action( 'admin_init' )
148 + ) {
149 + add_action( 'admin_init', array( __CLASS__, 'set_admin_menu_logo' ), PHP_INT_MAX );
150 + }
151 +
152 + if ( null === $color_scheme ) {
153 + $color_scheme = function_exists( 'get_user_option' ) ? get_user_option( 'admin_color' ) : '';
154 + }
155 +
156 + // It's possible to have a color scheme set that is no longer registered.
157 + if ( empty( $_wp_admin_css_colors[ $color_scheme ] ) ) {
158 + $color_scheme = 'modern';
159 + }
160 +
161 + if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors['base'] ) ) {
162 + $color = $_wp_admin_css_colors[ $color_scheme ]->icon_colors['base'];
163 + } elseif ( ! empty( $_wp_admin_css_colors['modern']->icon_colors['base'] ) ) {
164 + $color = $_wp_admin_css_colors['modern']->icon_colors['base'];
165 + } else {
166 + $color = '#a7aaad';
167 + }
168 +
169 + return $this->get_base64_logo( $color );
170 + }
171 +
172 + /**
173 + * Update the stored Jetpack admin menu item after admin color schemes are registered.
174 + *
175 + * @since 4.0.1
176 + *
177 + * @return void
178 + */
179 + public static function set_admin_menu_logo() {
180 + global $menu;
181 +
182 + foreach ( (array) $menu as $index => $item ) {
183 + if ( isset( $item[2] ) && 'jetpack' === $item[2] ) {
184 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- WordPress stores menu icons in this global array.
185 + $menu[ $index ][6] = ( new static() )->get_base64_admin_menu_logo();
186 + break;
187 + }
188 + }
189 + }
122 190 }