PluginProbe
Patchstack – WordPress & Plugins Security / 2.1.23
Patchstack – WordPress & Plugins Security v2.1.23
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
patchstack / includes / admin / multisite-table.php

multisite-table.php in Patchstack – WordPress & Plugins Security 2.1.23, at includes/admin/multisite-table.php

179 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Do not allow the file to be called directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 // WP_List_Table is not loaded automatically so we need to load it in our application
9 if ( ! class_exists( 'WP_List_Table' ) ) {
10 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
11 }
12
13 /**
14 * Create a new table class that will extend the WP_List_Table.
15 */
16 class Patchstack_Network_Sites_Table extends WP_List_Table {
17
18 /**
19 * Prepare the items for the table to process
20 *
21 * @return Void
22 */
23 public function prepare_items() {
24 $columns = $this->get_columns();
25 $hidden = $this->get_hidden_columns();
26 $sortable = $this->get_sortable_columns();
27 $data = $this->table_data();
28
29 usort( $data, array( &$this, 'sort_data' ) );
30 $per_page = 10;
31 $current_page = $this->get_pagenum();
32 $total_items = count( $data );
33
34 $this->set_pagination_args(
35 array(
36 'total_items' => $total_items,
37 'per_page' => $per_page,
38 )
39 );
40
41 $data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
42 $this->_column_headers = array( $columns, $hidden, $sortable );
43 $this->items = $data;
44 }
45
46 /**
47 * Override the parent columns method. Defines the columns to use in your listing table
48 *
49 * @return Array
50 */
51 public function get_columns() {
52 return array(
53 'id' => 'ID',
54 'title' => 'Title',
55 'url' => 'URL',
56 'activated' => 'License Status',
57 'firewall_status' => 'Firewall Status',
58 'edit' => 'Manage',
59 );
60 }
61
62 /**
63 * Define which columns are hidden
64 *
65 * @return Array
66 */
67 public function get_hidden_columns() {
68 return array();
69 }
70
71 /**
72 * Define the sortable columns
73 *
74 * @return Array
75 */
76 public function get_sortable_columns() {
77 return array( 'title' => array( 'title', false ) );
78 }
79
80 /**
81 * Get the table data
82 *
83 * @return Array
84 */
85 private function table_data() {
86 $data = array();
87 $free = get_option( 'patchstack_license_free', 0 ) == 1;
88
89 $blogs_ids = get_sites();
90 foreach ( $blogs_ids as $b ) {
91 $site_info = get_blog_details( $b->blog_id );
92
93 // Search functionality
94 $match = false;
95 if ( isset( $_GET['s'] ) ) {
96 if ( strpos( $b->blog_id, $_GET['s'] ) ) {
97 $match = true;
98 }
99
100 if ( strpos( $b->blogname, $_GET['s'] ) ) {
101 $match = true;
102 }
103
104 if ( strpos( $site_info->siteurl, $_GET['s'] ) ) {
105 $match = true;
106 }
107 }
108
109 if ( ! isset( $_GET['s'] ) || $match ) {
110 $is_firewall_enabled = get_blog_option( $b->blog_id, 'patchstack_basic_firewall' );
111 $is_activated = get_blog_option( $b->blog_id, 'patchstack_clientid', '' ) != '';
112
113 $data[] = array(
114 'id' => (int) $b->blog_id,
115 'title' => esc_html( $b->blogname ),
116 'url' => '<a href="' . esc_url( $site_info->siteurl ). '">' . esc_url( $site_info->siteurl ) . '</a>',
117 'activated' => $is_activated ? 'Activated' : 'Deactivated',
118 'firewall_status' => $is_firewall_enabled && ! $free ? 'Enabled' : 'Disabled',
119 'edit' => $is_activated ? '<a href="' . esc_url( get_admin_url( $b->blog_id ) ) . 'options-general.php?page=patchstack">Edit Settings</a>' : '',
120 );
121 }
122 }
123 return $data;
124 }
125
126 /**
127 * Define what data to show on each column of the table
128 *
129 * @param Array $item Data
130 * @param String $column_name - Current column name
131 *
132 * @return Mixed
133 */
134 public function column_default( $item, $column_name ) {
135 switch ( $column_name ) {
136 case 'id':
137 case 'title':
138 case 'url':
139 case 'activated':
140 case 'firewall_status':
141 case 'edit':
142 return $item[ $column_name ];
143 default:
144 return print_r( $item, true );
145 }
146 }
147
148 /**
149 * Allows you to sort the data by the variables set in the $_GET
150 *
151 * @param Array $a
152 * @param Array $b
153 * @return Mixed
154 */
155 private function sort_data( $a, $b ) {
156 // Set defaults
157 $orderby = 'id';
158 $order = 'asc';
159 $columns = $this->get_columns();
160
161 // If orderby is set, use this as the sort column
162 if ( isset( $_GET['orderby'] ) && ! empty( $_GET['orderby'] ) && isset( $columns[$_GET['orderby']] ) ) {
163 $orderby = wp_filter_nohtml_kses( $_GET['orderby'] );
164 }
165
166 // If order is set use this as the order
167 if ( isset( $_GET['order'] ) && ! empty( $_GET['order'] ) && $_GET['order'] != 'asc' ) {
168 $order = 'desc';
169 }
170
171 $result = strcmp( $a[ $orderby ], $b[ $orderby ] );
172 if ( $order === 'asc' ) {
173 return $result;
174 }
175
176 return -$result;
177 }
178 }
179