PluginProbe
WebberZone Top 10 — Popular Posts / 4.3.2
WebberZone Top 10 — Popular Posts v4.3.2
4.5.1 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 All 117 releases
top-10 / includes / admin / network / class-statistics.php

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

158 lines 4.2 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 do_action( 'tptn_settings_page_header' ); ?>
105
106 <div id="poststuff">
107 <div id="post-body" class="metabox-holder columns-2">
108 <div id="post-body-content">
109 <div class="meta-box-sortables ui-sortable">
110 <form method="get">
111 <input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
112 <?php
113 $this->pop_posts_table->prepare_items();
114 $this->hidden_inputs();
115 $this->pop_posts_table->display();
116 ?>
117 </form>
118 </div>
119 </div>
120 <div id="postbox-container-1" class="postbox-container">
121 <div id="side-sortables" class="meta-box-sortables ui-sortable">
122 <?php \WebberZone\Top_Ten\Admin\Admin::display_admin_sidebar(); ?>
123 </div><!-- /side-sortables -->
124 </div><!-- /postbox-container-1 -->
125 </div><!-- /post-body -->
126 <br class="clear" />
127 </div><!-- /poststuff -->
128 </div>
129 <?php
130 }
131
132 /**
133 * Screen options
134 */
135 public function screen_option() {
136 $option = 'per_page';
137 $args = array(
138 'label' => __( 'Popular Posts', 'top-10' ),
139 'default' => 20,
140 'option' => 'pop_posts_per_page',
141 );
142 add_screen_option( $option, $args );
143 $this->pop_posts_table = new \WebberZone\Top_Ten\Admin\Statistics_Table( true );
144 }
145
146 /**
147 * Displays the hidden inputs.
148 */
149 public function hidden_inputs() {
150 if ( ! empty( $_REQUEST['orderby'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
151 echo '<input type="hidden" name="orderby" value="' . esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ) ) . '" />'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
152 }
153 if ( ! empty( $_REQUEST['order'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
154 echo '<input type="hidden" name="order" value="' . esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) ) . '" />'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
155 }
156 }
157 }
158