WPSEO_GSC_Platform_Tabs

Class WPSEO_GSC_Platform_Tabs.

Defined (1)

The class is defined in the following location(s).

/admin/google_search_console/class-gsc-platform-tabs.php  
  1. class WPSEO_GSC_Platform_Tabs { 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. private $current_tab; 
  7.  
  8. /** 
  9. * Return the tabs as a string 
  10. * @return string 
  11. */ 
  12. public function __toString() { 
  13. return $this->platform_tabs(); 
  14.  
  15. /** 
  16. * Getting the current_tab 
  17. * @return string 
  18. */ 
  19. public function current_tab() { 
  20. return $this->current_tab; 
  21.  
  22. /** 
  23. * Loops through the array with all the platforms and convert it into an array 
  24. * @return string 
  25. */ 
  26. private function platform_tabs() { 
  27. $tabs = array( 'settings' => __( 'Settings', 'wordpress-seo' ) ); 
  28.  
  29. $platforms = array( 
  30. 'web' => __( 'Desktop', 'wordpress-seo' ),  
  31. 'smartphone_only' => __( 'Smartphone', 'wordpress-seo' ),  
  32. 'mobile' => __( 'Feature phone', 'wordpress-seo' ),  
  33. ); 
  34.  
  35. if ( WPSEO_GSC_Settings::get_profile() !== '' ) { 
  36. $tabs = array_merge( $platforms, $tabs ); 
  37.  
  38. $admin_link = admin_url( 'admin.php?page=wpseo_search_console&tab=' ); 
  39.  
  40. $this->set_current_tab( $tabs ); 
  41.  
  42. $return = ''; 
  43.  
  44. foreach ( $tabs as $platform_target => $platform_value ) { 
  45. $return .= $this->platform_tab( $platform_target, $platform_value, $admin_link ); 
  46.  
  47. return $return; 
  48.  
  49. /** 
  50. * Setting the current tab 
  51. * @param array $platforms Set of platforms (desktop, mobile, feature phone). 
  52. */ 
  53. private function set_current_tab( array $platforms ) { 
  54. $this->current_tab = key( $platforms ); 
  55. if ( $current_platform = filter_input( INPUT_GET, 'tab' ) ) { 
  56. $this->current_tab = $current_platform; 
  57.  
  58. /** 
  59. * Parses the tab 
  60. * @param string $platform_target Platform (desktop, mobile, feature phone). 
  61. * @param string $platform_value Link anchor. 
  62. * @param string $admin_link Link URL admin base. 
  63. * @return string 
  64. */ 
  65. private function platform_tab( $platform_target, $platform_value, $admin_link ) { 
  66. $active = ''; 
  67. if ( $this->current_tab === $platform_target ) { 
  68. $active = ' nav-tab-active'; 
  69.  
  70. return '<a class="nav-tab ' . $active . '" id="' . $platform_target . '-tab" href="' . $admin_link . $platform_target . '">' . $platform_value . '</a>';