# patchstack/2.1.18/includes/admin/multisite-table.php

Patchstack – WordPress &amp; Plugins Security, version 2.1.18. 178 lines.

- Page: https://pluginprobe.com/plugins/patchstack/2.1.18/code/includes/admin/multisite-table.php
- Raw: https://pluginprobe.com/plugins/patchstack/2.1.18/raw/includes/admin/multisite-table.php
- Modified: 2021-11-01T08:59:56+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/patchstack/2.1.18/code/includes/admin/multisite-table.php#L10-L20`.

```php
<?php

// Do not allow the file to be called directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// WP_List_Table is not loaded automatically so we need to load it in our application
if ( ! class_exists( 'WP_List_Table' ) ) {
	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}

/**
 * Create a new table class that will extend the WP_List_Table.
 */
class Patchstack_Network_Sites_Table extends WP_List_Table {

	/**
	 * Prepare the items for the table to process
	 *
	 * @return Void
	 */
	public function prepare_items() {
		$columns  = $this->get_columns();
		$hidden   = $this->get_hidden_columns();
		$sortable = $this->get_sortable_columns();
		$data     = $this->table_data();

		usort( $data, array( &$this, 'sort_data' ) );
		$per_page     = 10;
		$current_page = $this->get_pagenum();
		$total_items  = count( $data );

		$this->set_pagination_args(
			array(
				'total_items' => $total_items,
				'per_page'    => $per_page,
			)
		);

		$data                  = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
		$this->_column_headers = array( $columns, $hidden, $sortable );
		$this->items           = $data;
	}

	/**
	 * Override the parent columns method. Defines the columns to use in your listing table
	 *
	 * @return Array
	 */
	public function get_columns() {
		return array(
			'id'              => 'ID',
			'title'           => 'Title',
			'url'             => 'URL',
			'activated'       => 'License Status',
			'firewall_status' => 'Firewall Status',
			'edit'            => 'Manage',
		);
	}

	/**
	 * Define which columns are hidden
	 *
	 * @return Array
	 */
	public function get_hidden_columns() {
		return array();
	}

	/**
	 * Define the sortable columns
	 *
	 * @return Array
	 */
	public function get_sortable_columns() {
		return array( 'title' => array( 'title', false ) );
	}

	/**
	 * Get the table data
	 *
	 * @return Array
	 */
	private function table_data() {
		$data = array();

		$blogs_ids = get_sites();
		foreach ( $blogs_ids as $b ) {
			$site_info = get_blog_details( $b->blog_id );

			// Search functionality
			$match = false;
			if ( isset( $_GET['s'] ) ) {
				if ( strpos( $b->blog_id, $_GET['s'] ) ) {
					$match = true;
				}

				if ( strpos( $b->blogname, $_GET['s'] ) ) {
					$match = true;
				}

				if ( strpos( $site_info->siteurl, $_GET['s'] ) ) {
					$match = true;
				}
			}

			if ( ! isset( $_GET['s'] ) || $match ) {
				$is_firewall_enabled = get_blog_option( $b->blog_id, 'patchstack_basic_firewall' );
				$is_activated        = get_blog_option( $b->blog_id, 'patchstack_clientid', '' ) != '';

				$data[] = array(
					'id'              => (int) $b->blog_id,
					'title'           => esc_html( $b->blogname ),
					'url'             => '<a href="' . esc_url( $site_info->siteurl ). '">' . esc_url( $site_info->siteurl ) . '</a>',
					'activated'       => $is_activated ? 'Activated' : 'Deactivated',
					'firewall_status' => $is_firewall_enabled ? 'Enabled' : 'Disabled',
					'edit'            => $is_activated ? '<a href="' . esc_url( get_admin_url( $b->blog_id ) ) . 'options-general.php?page=patchstack">Edit Settings</a>' : '',
				);
			}
		}
		return $data;
	}

	/**
	 * Define what data to show on each column of the table
	 *
	 * @param  Array  $item Data
	 * @param  String $column_name - Current column name
	 *
	 * @return Mixed
	 */
	public function column_default( $item, $column_name ) {
		switch ( $column_name ) {
			case 'id':
			case 'title':
			case 'url':
			case 'activated':
			case 'firewall_status':
			case 'edit':
				return $item[ $column_name ];
			default:
				return print_r( $item, true );
		}
	}

	/**
	 * Allows you to sort the data by the variables set in the $_GET
	 *
	 * @param Array $a
	 * @param Array $b
	 * @return Mixed
	 */
	private function sort_data( $a, $b ) {
		// Set defaults
		$orderby = 'id';
		$order   = 'asc';
		$columns = $this->get_columns();

		// If orderby is set, use this as the sort column
		if ( isset( $_GET['orderby'] ) && ! empty( $_GET['orderby'] ) && isset( $columns[$_GET['orderby']] ) ) {
			$orderby = wp_filter_nohtml_kses( $_GET['orderby'] );
		}

		// If order is set use this as the order
		if ( isset( $_GET['order'] ) && ! empty( $_GET['order'] ) && $_GET['order'] != 'asc' ) {
			$order = 'desc';
		}

		$result = strcmp( $a[ $orderby ], $b[ $orderby ] );
		if ( $order === 'asc' ) {
			return $result;
		}

		return -$result;
	}
}

```
