Completed
Push — master-stable ( 2f6b36...784ad3 )
by
unknown
21:53 queued 13:33
created

class.jetpack-network-sites-list-table.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
if( ! class_exists( 'WP_List_Table' ) ) {
4
    require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5
}
6
7
class Jetpack_Network_Sites_List_Table extends WP_List_Table {
8
9
10
	public function get_columns() {
11
		// site name, status, username connected under
12
		$columns = array(
13
			'cb'        => '<input type="checkbox" />',
14
			'blogname' => __( 'Site Name', 'jetpack'  ),
15
			'blog_path' => __( 'Path', 'jetpack' ),
16
			'connected' => __( 'Connected', 'jetpack' ),
17
		);
18
19
		return $columns;
20
	}
21
22
	public function prepare_items() {
23
		$jpms = Jetpack_Network::init();
0 ignored issues
show
$jpms is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
24
25
		// Deal with bulk actions if any were requested by the user
26
		$this->process_bulk_action();
27
28
		$sites = get_sites( array( 
29
			'site__not_in' => array( get_current_blog_id() ),
30
			'archived' => false,
31
		) );
32
33
		// Setup pagination
34
		$per_page = 25;
35
		$current_page = $this->get_pagenum();
36
		$total_items = count( $sites );
37
		$sites = array_slice( $sites, ( ( $current_page-1 ) * $per_page ), $per_page );
38
		$this->set_pagination_args( array(
39
			'total_items' => $total_items,
40
			'per_page'    => $per_page
41
		) );
42
43
		$columns = $this->get_columns();
44
		$hidden = array();
45
		$sortable = array();
46
		$this->_column_headers = array( $columns, $hidden, $sortable );
47
		$this->items = $sites;
48
	}
49
50
	public function column_blogname( $item ) {
51
		// http://jpms/wp-admin/network/site-info.php?id=1
52
		switch_to_blog( $item->blog_id );
53
		$jp_url = admin_url( 'admin.php?page=jetpack' );
54
		restore_current_blog();
55
56
		$actions = array(
57
			'edit'      => '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $item->blog_id ) )  .  '">' . esc_html__( 'Edit', 'jetpack' ) . '</a>',
58
			'dashboard' => '<a href="' . esc_url( get_admin_url( $item->blog_id, '', 'admin' ) ) . '">' . esc_html__( 'Dashboard', 'jetpack' ) . '</a>',
59
			'view'      => '<a href="' . esc_url( get_site_url( $item->blog_id, '', 'admin' ) ) . '">' . esc_html__( 'View', 'jetpack' ) . '</a>',
60
			'jetpack-' . $item->blog_id => '<a href="' . esc_url( $jp_url ) . '">Jetpack</a>',
61
		);
62
63
  		return sprintf('%1$s %2$s', '<strong>' . get_blog_option( $item->blog_id, 'blogname' ) . '</strong>', $this->row_actions($actions) );
64
	}
65
66
	public function column_blog_path( $item ) {
67
		return
68
                         '<a href="' .
69
                         get_site_url( $item->blog_id, '', 'admin' ) .
70
                         '">' .
71
                         str_replace( array( 'http://', 'https://' ), '', get_site_url( $item->blog_id, '', 'admin' ) ) .
72
                         '</a>';
73
	}
74
75
	public function column_connected( $item ) {
76
		$jpms = Jetpack_Network::init();
77
		$jp = Jetpack::init();
78
79
		switch_to_blog( $item->blog_id );
80
81
		if ( ! is_plugin_active( 'jetpack/jetpack.php' ) ) {
82
			$title = __( 'Jetpack is not active on this site.', 'jetpack' );
83
			$action = array(
84
				'manage-plugins' => '<a href="' . get_admin_url( $item->blog_id, 'plugins.php', 'admin' ) . '">' . __( 'Manage Plugins', 'jetpack' ) . '</a>',
85
			);
86
			restore_current_blog();
87
			return sprintf( '%1$s %2$s', $title, $this->row_actions( $action ) );
88
		}
89
90
		if( $jp->is_active() ) {
91
		   // Build url for disconnecting
92
		    $url = $jpms->get_url( array(
93
			'name'	    => 'subsitedisconnect',
94
			'site_id'   => $item->blog_id,
95
96
		    ) );
97
		    restore_current_blog();
98
		    return '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Disconnect', 'jetpack' ) . '</a>';
99
		}
100
		restore_current_blog();
101
102
		// Build URL for connecting
103
		$url = $jpms->get_url( array(
104
		    'name'	=> 'subsiteregister',
105
		    'site_id'	=> $item->blog_id,
106
		) );
107
		return '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Connect', 'jetpack' ) . '</a>';
108
	}
109
110
	public function get_bulk_actions() {
111
	    $actions = array(
112
		'connect'    => esc_html__( 'Connect', 'jetpack' ),
113
		'disconnect' => esc_html__( 'Disconnect', 'jetpack' )
114
	    );
115
116
	    return $actions;
117
	}
118
119
	function column_cb($item) {
120
        	return sprintf(
121
            		'<input type="checkbox" name="bulk[]" value="%s" />', $item->blog_id
122
        	);
123
    	}
124
125
	public function process_bulk_action() {
126
		if( !isset( $_POST['bulk'] ) || empty ( $_POST['bulk'] ) )
127
			return; // Thou shall not pass! There is nothing to do
128
129
130
		$jpms = Jetpack_Network::init();
131
132
		$action = $this->current_action();
133
		switch ( $action ) {
134
135
            		case 'connect':
136
                		foreach( $_POST['bulk'] as $k => $site ) {
137
							$jpms->do_subsiteregister( $site );
138
						}
139
				break;
140
            		case 'disconnect':
141
                		foreach( $_POST['bulk'] as $k => $site ) {
142
							$jpms->do_subsitedisconnect( $site );
143
						}
144
				break;
145
		}
146
	}
147
} // end h
148