Jetpack_Network_Sites_List_Table

The Jetpack by WordPress.com Jetpack Network Sites List Table class.

Defined (1)

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

/class.jetpack-network-sites-list-table.php  
  1. class Jetpack_Network_Sites_List_Table extends WP_List_Table { 
  2.  
  3.  
  4. public function get_columns() { 
  5. // site name, status, username connected under 
  6. $columns = array( 
  7. 'cb' => '<input type="checkbox" />',  
  8. 'blogname' => __( 'Site Name', 'jetpack' ),  
  9. 'blog_path' => __( 'Path', 'jetpack' ),  
  10. 'connected' => __( 'Connected', 'jetpack' ),  
  11. ); 
  12.  
  13. return $columns; 
  14.  
  15. public function prepare_items() { 
  16. $jpms = Jetpack_Network::init(); 
  17.  
  18. // Deal with bulk actions if any were requested by the user 
  19. $this->process_bulk_action(); 
  20.  
  21. // Get sites 
  22. $sites = $jpms->wp_get_sites( array( 'exclude_blogs' => array( 1 ) ) ); 
  23.  
  24. // Setup pagination 
  25. $per_page = 25; 
  26. $current_page = $this->get_pagenum(); 
  27. $total_items = count( $sites ); 
  28. $sites = array_slice( $sites, ( ( $current_page-1 ) * $per_page ), $per_page ); 
  29. $this->set_pagination_args( array( 
  30. 'total_items' => $total_items,  
  31. 'per_page' => $per_page 
  32. ) ); 
  33.  
  34. $columns = $this->get_columns(); 
  35. $hidden = array(); 
  36. $sortable = array(); 
  37. $this->_column_headers = array( $columns, $hidden, $sortable ); 
  38. $this->items = $sites; 
  39.  
  40. public function column_blogname( $item ) { 
  41. // http://jpms/wp-admin/network/site-info.php?id=1 
  42. switch_to_blog( $item->blog_id ); 
  43. $jp_url = admin_url( 'admin.php?page=jetpack' ); 
  44. restore_current_blog(); 
  45.  
  46. $actions = array( 
  47. 'edit' => '<a href="' . network_admin_url( 'site-info.php?id=' . $item->blog_id ) . '">' . __( 'Edit', 'jetpack' ) . '</a>',  
  48. 'dashboard' => '<a href="' . get_admin_url( $item->blog_id, '', 'admin' ) . '">Dashboard</a>',  
  49. 'view' => '<a href="' . get_site_url( $item->blog_id, '', 'admin' ) . '">View</a>',  
  50. 'jetpack-' . $item->blog_id => '<a href="' . $jp_url . '">Jetpack</a>',  
  51. ); 
  52.  
  53. return sprintf('%1$s %2$s', '<strong>' . get_blog_option( $item->blog_id, 'blogname' ) . '</strong>', $this->row_actions($actions) ); 
  54.  
  55. public function column_blog_path( $item ) { 
  56. return 
  57. '<a href="' . 
  58. get_site_url( $item->blog_id, '', 'admin' ) . 
  59. '">' . 
  60. str_replace( array( 'http://', 'https://' ), '', get_site_url( $item->blog_id, '', 'admin' ) ) . 
  61. '</a>'; 
  62.  
  63. public function column_connected( $item ) { 
  64. $jpms = Jetpack_Network::init(); 
  65. $jp = Jetpack::init(); 
  66.  
  67. switch_to_blog( $item->blog_id ); 
  68. if( $jp->is_active() ) { 
  69. // Build url for disconnecting 
  70. $url = $jpms->get_url( array( 
  71. 'name' => 'subsitedisconnect',  
  72. 'site_id' => $item->blog_id,  
  73.  
  74. ) ); 
  75. restore_current_blog(); 
  76. return '<a href="' . $url . '">Disconnect</a>'; 
  77. restore_current_blog(); 
  78.  
  79. // Build URL for connecting 
  80. $url = $jpms->get_url( array( 
  81. 'name' => 'subsiteregister',  
  82. 'site_id' => $item->blog_id,  
  83. ) ); 
  84. return '<a href="' . $url . '">Connect</a>'; 
  85.  
  86. public function get_bulk_actions() { 
  87. $actions = array( 
  88. 'connect' => 'Connect',  
  89. 'disconnect' => 'Disconnect' 
  90. ); 
  91.  
  92. return $actions; 
  93.  
  94. function column_cb($item) { 
  95. return sprintf( 
  96. '<input type="checkbox" name="bulk[]" value="%s" />', $item->blog_id 
  97. ); 
  98.  
  99. public function process_bulk_action() { 
  100. if( !isset( $_POST['bulk'] ) || empty ( $_POST['bulk'] ) ) 
  101. return; // Thou shall not pass! There is nothing to do 
  102.  
  103.  
  104. $jpms = Jetpack_Network::init(); 
  105.  
  106. $action = $this->current_action(); 
  107. switch ( $action ) { 
  108.  
  109. case 'connect': 
  110. foreach( $_POST['bulk'] as $k => $site ) { 
  111. $jpms->do_subsiteregister( $site ); 
  112. break; 
  113. case 'disconnect': 
  114. foreach( $_POST['bulk'] as $k => $site ) { 
  115. $jpms->do_subsitedisconnect( $site ); 
  116. break; 
  117. } // end h