PluginProbe
WebberZone Top 10 — Popular Posts / 4.3.1
WebberZone Top 10 — Popular Posts v4.3.1
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 / class-statistics.php

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

156 lines 3.8 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_submenu_page(
79 'tptn_dashboard',
80 __( 'Top 10 Daily Popular Posts', 'top-10' ),
81 __( 'Daily Popular Posts', 'top-10' ),
82 'manage_options',
83 'tptn_popular_posts&orderby=daily_count&order=desc',
84 array( $this, 'render_page' )
85 );
86
87 add_action( "load-{$this->parent_id}", array( $this, 'screen_option' ) );
88 }
89
90 /**
91 * Set screen options.
92 *
93 * @param string $status Status of screen.
94 * @param string $option Option name.
95 * @param string $value Option value.
96 * @return string Value.
97 */
98 public static function set_screen( $status, $option, $value ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
99 return $value;
100 }
101
102 /**
103 * Plugin settings page
104 */
105 public function render_page() {
106
107 $page = '';
108 if ( isset( $_REQUEST['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
109 $page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
110 }
111 ?>
112 <div class="wrap">
113 <h1><?php esc_html_e( 'Top 10 Popular Posts', 'top-10' ); ?></h1>
114 <?php do_action( 'tptn_settings_page_header' ); ?>
115
116 <div id="poststuff">
117 <div id="post-body" class="metabox-holder columns-2">
118 <div id="post-body-content">
119 <div class="meta-box-sortables ui-sortable">
120 <form method="get">
121 <input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
122 <?php
123 $this->pop_posts_table->prepare_items();
124 $this->pop_posts_table->search_box( __( 'Search Popular Posts', 'top-10' ), 'top-10' );
125 $this->pop_posts_table->display();
126 ?>
127 </form>
128 </div>
129 </div>
130 <div id="postbox-container-1" class="postbox-container">
131 <div id="side-sortables" class="meta-box-sortables ui-sortable">
132 <?php \WebberZone\Top_Ten\Admin\Admin::display_admin_sidebar(); ?>
133 </div><!-- /side-sortables -->
134 </div><!-- /postbox-container-1 -->
135 </div><!-- /post-body -->
136 <br class="clear" />
137 </div><!-- /poststuff -->
138 </div>
139 <?php
140 }
141
142 /**
143 * Screen options
144 */
145 public function screen_option() {
146 $option = 'per_page';
147 $args = array(
148 'label' => __( 'Popular Posts', 'top-10' ),
149 'default' => 20,
150 'option' => 'pop_posts_per_page',
151 );
152 add_screen_option( $option, $args );
153 $this->pop_posts_table = new Statistics_Table();
154 }
155 }
156