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

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

147 lines 3.5 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 do_action( 'tptn_settings_page_header' ); ?>
106
107 <div id="poststuff">
108 <div id="post-body" class="metabox-holder columns-2">
109 <div id="post-body-content">
110 <div class="meta-box-sortables ui-sortable">
111 <form method="get">
112 <input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
113 <?php
114 $this->pop_posts_table->prepare_items();
115 $this->pop_posts_table->search_box( __( 'Search Popular Posts', 'top-10' ), 'top-10' );
116 $this->pop_posts_table->display();
117 ?>
118 </form>
119 </div>
120 </div>
121 <div id="postbox-container-1" class="postbox-container">
122 <div id="side-sortables" class="meta-box-sortables ui-sortable">
123 <?php \WebberZone\Top_Ten\Admin\Admin::display_admin_sidebar(); ?>
124 </div><!-- /side-sortables -->
125 </div><!-- /postbox-container-1 -->
126 </div><!-- /post-body -->
127 <br class="clear" />
128 </div><!-- /poststuff -->
129 </div>
130 <?php
131 }
132
133 /**
134 * Screen options
135 */
136 public function screen_option() {
137 $option = 'per_page';
138 $args = array(
139 'label' => __( 'Popular Posts', 'top-10' ),
140 'default' => 20,
141 'option' => 'pop_posts_per_page',
142 );
143 add_screen_option( $option, $args );
144 $this->pop_posts_table = new Statistics_Table();
145 }
146 }
147