tag.
* - jetpack-logo__icon-circle: the circle of the Jetpack mark.
* - jetpack-logo__icon-triangle: two shapes that correspond to each triangle in the Jetpack mark.
* - jetpack-logo__icon-text: the Jetpack lettering.
*
* @var string
*/
const JETPACK_LOGO_SVG = '
';
/**
* Create and render a Jetpack logo.
*/
class Logo {
/**
* Return the Jetpack logo.
*
* @return string The Jetpack logo.
*/
public function render() {
return JETPACK_LOGO_SVG;
}
/**
* Return string containing the Jetpack logo.
*
* @since 1.1.4
* @since-jetpack 7.5.0
*
* @param bool $logotype Should we use the full logotype (logo + text). Default to false.
*
* @return string
*/
public function get_jp_emblem( $logotype = false ) {
$logo_text = $this->get_jp_logo_parts();
return sprintf(
'',
( true === $logotype ? '118' : '32' ),
( true === $logotype ? $logo_text['logo'] . $logo_text['text'] : $logo_text['logo'] )
);
}
/**
* Return string containing the Jetpack logo in a slightly larger format than get_jp_emblem().
*
* @since 1.1.4
* @param bool $logotype Should we use the full logotype (logo + text). Default to false.
* @return string
*/
public function get_jp_emblem_larger( $logotype = false ) {
$logo_text = $this->get_jp_logo_parts();
return sprintf(
'',
( true === $logotype ? '118' : '32' ),
( true === $logotype ? $logo_text['logo'] . $logo_text['text'] : $logo_text['logo'] )
);
}
/**
* Return array containing the Jetpack logo and text
*
* @since 1.6.0 - Added $color parameter.
*
* @param string $color The color of the logo.
*
* @return array
*/
private function get_jp_logo_parts( $color = '#069e08' ) {
return array(
'logo' => '',
'text' => '',
);
}
/**
* Return a base64 encoded SVG of the Jetpack logo.
* Can be used as a data URI to use the logo inline in CSS.
*
* @since 1.6.0
*
* @param string $color The color of the logo.
*
* @return string
*/
public function get_base64_logo( $color = '#ffffff' ) {
$logo_text = $this->get_jp_logo_parts( $color );
$base_logo = sprintf(
'',
$logo_text['logo']
);
$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.
return 'data:image/svg+xml;base64,' . $encoded_logo;
}
/**
* Return a base64 encoded SVG of the Jetpack logo using the current admin menu color.
*
* This mirrors the fallback order in WordPress's wp_color_scheme_settings(), whose
* JavaScript output recolors data URI SVG icons after the page loads.
*
* @since 4.0.1
*
* @param string|null $color_scheme Admin color scheme to use. Defaults to the
* current user's scheme.
*
* @return string
*/
public function get_base64_admin_menu_logo( $color_scheme = null ) {
global $_wp_admin_css_colors;
/*
* WordPress builds the admin menu before admin_init, when its color schemes
* are registered. Refresh the stored menu icon afterward, before output.
*/
if (
null === $color_scheme
&& function_exists( 'add_action' )
&& function_exists( 'did_action' )
&& ! did_action( 'admin_init' )
) {
add_action( 'admin_init', array( __CLASS__, 'set_admin_menu_logo' ), PHP_INT_MAX );
}
if ( null === $color_scheme ) {
$color_scheme = function_exists( 'get_user_option' ) ? get_user_option( 'admin_color' ) : '';
}
// It's possible to have a color scheme set that is no longer registered.
if ( empty( $_wp_admin_css_colors[ $color_scheme ] ) ) {
$color_scheme = 'modern';
}
if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors['base'] ) ) {
$color = $_wp_admin_css_colors[ $color_scheme ]->icon_colors['base'];
} elseif ( ! empty( $_wp_admin_css_colors['modern']->icon_colors['base'] ) ) {
$color = $_wp_admin_css_colors['modern']->icon_colors['base'];
} else {
$color = '#a7aaad';
}
return $this->get_base64_logo( $color );
}
/**
* Update the stored Jetpack admin menu item after admin color schemes are registered.
*
* @since 4.0.1
*
* @return void
*/
public static function set_admin_menu_logo() {
global $menu;
foreach ( (array) $menu as $index => $item ) {
if ( isset( $item[2] ) && 'jetpack' === $item[2] ) {
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- WordPress stores menu icons in this global array.
$menu[ $index ][6] = ( new static() )->get_base64_admin_menu_logo();
break;
}
}
}
}