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 / class-statistics.php

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

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