PluginProbe
Quick Download Button / trunk
Quick Download Button vtrunk
trunk 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.4.0
quick-download-button / admin / class-qdbp-admin.php

class-qdbp-admin.php in Quick Download Button trunk, at admin/class-qdbp-admin.php

155 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || exit;
3
4 /**
5 * Admin panel.
6 *
7 * Registers sub-menu pages under a top-level "QDB" menu.
8 * Each page is a thin wrapper that loads the corresponding view template.
9 */
10 class QDBP_Admin {
11
12 public static function init() {
13 require_once QDBN__PLUGIN_DIR . 'admin/class-qdbp-analytics-table.php';
14 require_once QDBN__PLUGIN_DIR . 'admin/class-qdbp-leads-table.php';
15
16 add_action( 'admin_menu', array( __CLASS__, 'register_menus' ) );
17 add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
18 add_action( 'admin_init', array( __CLASS__, 'handle_early_actions' ) );
19 }
20
21 public static function handle_early_actions() {
22 // CSV export runs before headers are sent
23 QDBP_Leads_Table::maybe_export_csv();
24 }
25
26 public static function register_menus() {
27 add_menu_page(
28 __( 'Quick Download Button', 'quick-download-button' ),
29 __( 'Quick Download', 'quick-download-button' ),
30 'manage_options',
31 'qdbp-dashboard',
32 array( __CLASS__, 'render_overview' ),
33 'dashicons-download',
34 81
35 );
36
37 add_submenu_page(
38 'qdbp-dashboard',
39 __( 'Overview', 'quick-download-button' ),
40 __( 'Overview', 'quick-download-button' ),
41 'manage_options',
42 'qdbp-dashboard',
43 array( __CLASS__, 'render_overview' )
44 );
45
46 add_submenu_page(
47 'qdbp-dashboard',
48 __( 'Download Log', 'quick-download-button' ),
49 __( 'Download Log', 'quick-download-button' ),
50 'manage_options',
51 'qdbp-log',
52 array( __CLASS__, 'render_log' )
53 );
54
55 add_submenu_page(
56 'qdbp-dashboard',
57 __( 'Leads', 'quick-download-button' ),
58 __( 'Leads', 'quick-download-button' ),
59 'manage_options',
60 'qdbp-leads',
61 array( __CLASS__, 'render_leads' )
62 );
63
64 add_submenu_page(
65 'qdbp-dashboard',
66 __( 'Shortcode Builder', 'quick-download-button' ),
67 __( 'Shortcode Builder', 'quick-download-button' ),
68 'manage_options',
69 'qdbp-builder',
70 array( __CLASS__, 'render_builder' )
71 );
72
73 add_submenu_page(
74 'qdbp-dashboard',
75 __( 'Settings', 'quick-download-button' ),
76 __( 'Settings', 'quick-download-button' ),
77 'manage_options',
78 'qdbp-settings',
79 array( __CLASS__, 'render_settings' )
80 );
81 }
82
83 public static function render_overview() {
84 require_once QDBN__PLUGIN_DIR . 'admin/views/overview.php';
85 }
86
87 public static function render_log() {
88 require_once QDBN__PLUGIN_DIR . 'admin/views/analytics.php';
89 }
90
91 public static function render_leads() {
92 require_once QDBN__PLUGIN_DIR . 'admin/views/leads.php';
93 }
94
95 public static function render_builder() {
96 require_once QDBN__PLUGIN_DIR . 'admin/views/shortcode-builder.php';
97 }
98
99 public static function render_settings() {
100 require_once QDBN__PLUGIN_DIR . 'admin/views/settings.php';
101 }
102
103 /**
104 * Render the analytics section tab navigation.
105 *
106 * @param string $active 'overview' or 'log'
107 */
108 public static function analytics_nav( $active ) {
109 $tabs = array(
110 'overview' => array(
111 'label' => __( 'Overview', 'quick-download-button' ),
112 'url' => admin_url( 'admin.php?page=qdbp-dashboard' ),
113 ),
114 'log' => array(
115 'label' => __( 'Download Log', 'quick-download-button' ),
116 'url' => admin_url( 'admin.php?page=qdbp-log' ),
117 ),
118 );
119 echo '<nav class="qdbp-analytics-nav">';
120 foreach ( $tabs as $key => $tab ) {
121 $class = ( $key === $active ) ? ' qdbp-analytics-nav__tab--active' : '';
122 printf(
123 '<a href="%s" class="qdbp-analytics-nav__tab%s">%s</a>',
124 esc_url( $tab['url'] ),
125 esc_attr( $class ),
126 esc_html( $tab['label'] )
127 );
128 }
129 echo '</nav>';
130 }
131
132 public static function enqueue_assets( $hook ) {
133 if ( strpos( $hook, 'qdbp' ) === false ) return;
134
135 wp_enqueue_style(
136 'qdbp-admin',
137 QDBN__PLUGIN_URI . 'assets/css/pro-admin.css',
138 array(),
139 QDBN__VERSION
140 );
141
142 wp_enqueue_script(
143 'qdbp-admin',
144 QDBN__PLUGIN_URI . 'assets/js/pro-admin.js',
145 array( 'jquery' ),
146 QDBN__VERSION,
147 true
148 );
149
150 if ( strpos( $hook, 'qdbp-builder' ) !== false ) {
151 wp_enqueue_media();
152 }
153 }
154 }
155