PluginProbe
WebberZone Top 10 — Popular Posts / trunk
WebberZone Top 10 — Popular Posts vtrunk
4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 1.6.2 All 116 releases
top-10 / includes / admin / network / class-statistics.php

class-statistics.php in WebberZone Top 10 — Popular Posts trunk, at includes/admin/network/class-statistics.php

161 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Network Statistics class.
4 *
5 * @package WebberZone\Top_Ten\Admin\Network
6 */
7
8 namespace WebberZone\Top_Ten\Admin\Network;
9
10 // If this file is called directly, abort.
11 if ( ! defined( 'WPINC' ) ) {
12 die;
13 }
14
15 /**
16 * Top_Ten_Network_Statistics class.
17 */
18 class Statistics {
19
20 /**
21 * WP_List_Table object.
22 *
23 * @var \WebberZone\Top_Ten\Admin\Statistics_Table
24 */
25 public $pop_posts_table;
26
27 /**
28 * Parent Menu ID.
29 *
30 * @since 3.3.0
31 *
32 * @var string Parent Menu ID.
33 */
34 public $parent_id;
35
36 /**
37 * Class constructor.
38 *
39 * @access public
40 * @return void
41 */
42 public function __construct() {
43 add_filter( 'set-screen-option', array( __CLASS__, 'set_screen' ), 10, 3 );
44 add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) );
45 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
46 }
47
48 /**
49 * Enqueue scripts in admin area.
50 *
51 * @since 3.0.0
52 *
53 * @param string $hook The current admin page.
54 */
55 public function admin_enqueue_scripts( $hook ) {
56 if ( $hook === $this->parent_id ) {
57 wp_enqueue_script( 'top-ten-admin-js' );
58 wp_enqueue_style( 'top-ten-admin-css' );
59 }
60 }
61
62 /**
63 * Admin Menu.
64 *
65 * @since 3.0.0
66 */
67 public function network_admin_menu() {
68 $this->parent_id = add_submenu_page(
69 'tptn_dashboard',
70 esc_html__( 'Top 10 - Network Popular Posts', 'top-10' ),
71 esc_html__( 'Popular Posts', 'top-10' ),
72 'manage_network_options',
73 'tptn_network_pop_posts_page',
74 array( $this, 'render_page' )
75 );
76
77 add_action( "load-{$this->parent_id}", array( $this, 'screen_option' ) );
78 }
79
80 /**
81 * Set screen.
82 *
83 * @param string $status Status of screen.
84 * @param string $option Option name.
85 * @param string $value Option value.
86 * @return string Value.
87 */
88 public static function set_screen( $status, $option, $value ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
89 return $value;
90 }
91
92 /**
93 * Plugin settings page
94 */
95 public function render_page() {
96
97 $page = '';
98 if ( isset( $_REQUEST['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
99 $page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
100 }
101 ?>
102 <div class="wrap">
103 <h1><?php esc_html_e( 'Top 10 - Network Wide Popular Posts', 'top-10' ); ?></h1>
104 <?php
105 /** This action is documented in includes/admin/class-dashboard.php */
106 do_action( 'tptn_settings_page_header' );
107 ?>
108
109 <div id="poststuff">
110 <div id="post-body" class="metabox-holder columns-2">
111 <div id="post-body-content">
112 <div class="meta-box-sortables ui-sortable">
113 <form method="get">
114 <input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
115 <?php
116 $this->pop_posts_table->prepare_items();
117 $this->hidden_inputs();
118 $this->pop_posts_table->display();
119 ?>
120 </form>
121 </div>
122 </div>
123 <div id="postbox-container-1" class="postbox-container">
124 <div id="side-sortables" class="meta-box-sortables ui-sortable">
125 <?php \WebberZone\Top_Ten\Admin\Admin::display_admin_sidebar(); ?>
126 </div><!-- /side-sortables -->
127 </div><!-- /postbox-container-1 -->
128 </div><!-- /post-body -->
129 <br class="clear" />
130 </div><!-- /poststuff -->
131 </div>
132 <?php
133 }
134
135 /**
136 * Screen options
137 */
138 public function screen_option() {
139 $option = 'per_page';
140 $args = array(
141 'label' => __( 'Popular Posts', 'top-10' ),
142 'default' => 20,
143 'option' => 'pop_posts_per_page',
144 );
145 add_screen_option( $option, $args );
146 $this->pop_posts_table = new \WebberZone\Top_Ten\Admin\Statistics_Table( true );
147 }
148
149 /**
150 * Displays the hidden inputs.
151 */
152 public function hidden_inputs() {
153 if ( ! empty( $_REQUEST['orderby'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
154 echo '<input type="hidden" name="orderby" value="' . esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ) ) . '" />'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
155 }
156 if ( ! empty( $_REQUEST['order'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
157 echo '<input type="hidden" name="order" value="' . esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) ) . '" />'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
158 }
159 }
160 }
161