Completed
Push — try/repurpose-masterbar-module ( 47e6c3...e7989f )
by
unknown
15:19 queued 06:28
created

RTL_Admin_Bar   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 0 38 9
1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3
namespace Automattic\Jetpack\Dashboard_Customizations;
4
5
use WP_Admin_Bar;
6
7
if ( ! class_exists( 'WP_Admin_Bar' ) ) {
8
	require_once ABSPATH . '/wp-includes/class-wp-admin-bar.php';
9
}
10
11
/**
12
 * We are using this class to replace core WP_Admin_Bar in cases when
13
 * we need to override the default styles with rtl ones. This is
14
 * achieved by adding 'rtl' class to #wpadminbar div. Apart from that
15
 * the output of render method should be the same as the one of base class.
16
 */
17
class RTL_Admin_Bar extends WP_Admin_Bar {
18
	/**
19
	 * Display the admin bar.
20
	 */
21
	public function render() {
22
		global $is_IE;
23
		$root = $this->_bind();
24
25
		// Add browser and RTL classes.
26
		// We have to do this here since admin bar shows on the front end.
27
		$class = 'nojq nojs rtl';
28
		if ( $is_IE ) {
29
			if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 7' ) ) {
30
				$class .= ' ie7';
31
			} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) ) {
32
				$class .= ' ie8';
33
			} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) ) {
34
				$class .= ' ie9';
35
			}
36
		} elseif ( wp_is_mobile() ) {
37
			$class .= ' mobile';
38
		}
39
40
		?>
41
		<div id="wpadminbar" class="<?php echo esc_attr( $class ); ?>">
42
			<?php if ( ! is_admin() ) : ?>
43
				<a class="screen-reader-shortcut" href="#wp-toolbar" tabindex="1"><?php esc_html_e( 'Skip to toolbar', 'jetpack' ); ?></a>
44
			<?php endif; ?>
45
			<div class="quicklinks" id="wp-toolbar" role="navigation" aria-label="<?php esc_attr_e( 'Toolbar', 'jetpack' ); ?>" tabindex="0">
46
				<?php
47
				foreach ( $root->children as $group ) :
48
					$this->_render_group( $group );
49
				endforeach;
50
				?>
51
			</div>
52
			<?php if ( is_user_logged_in() ) : ?>
53
				<a class="screen-reader-shortcut" href="<?php echo esc_url( wp_logout_url() ); ?>"><?php esc_html_e( 'Log Out', 'jetpack' ); ?></a>
54
			<?php endif; ?>
55
		</div>
56
57
		<?php
58
	}
59
}
60