rtl-admin-bar.php 1.6 KB

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