PluginProbe
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables / trunk
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables vtrunk
2.2.13 2.2.12 2.2.11 2.2.10 2.2.9 2.2.8 2.2.7 2.2.6 2.2.5 2.2.4 2.2.3 trunk 1.0.0 1.0.1 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2
table-builder-block / includes / Admin / Admin.php

Admin.php in TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables trunk, at includes/Admin/Admin.php

132 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin dashboard and menu registration for TableKit
4 *
5 * @package TableKit
6 */
7
8 namespace TableBuilder\Admin;
9
10 use TableBuilder\Traits\PluginHelper;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * The admin class for TableBuilder.
16 */
17 class Admin {
18
19 use \TableBuilder\Traits\Singleton;
20 use PluginHelper;
21
22 /**
23 * Slug of the admin menu.
24 *
25 * @var string
26 */
27 private $menu_slug = 'tablebuilder';
28
29 /**
30 * Part of the menu link used in the admin panel.
31 *
32 * @var string
33 */
34 private $menu_link_part;
35
36 /**
37 * Sets up the admin REST routes and registers the admin menu.
38 */
39 public function __construct() {
40 $this->menu_link_part = admin_url( 'admin.php?page=tablebuilder' );
41
42 // Register Settings API.
43 new Api\SettingsData();
44 new Api\OnboardData();
45 new Api\ChangelogData();
46 add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 9 );
47 }
48
49 /**
50 * Registers the TableKit top-level admin menu page and its submenu entries
51 * (onboard/welcome/features), hooked to "admin_menu".
52 *
53 * @return void
54 */
55 public function add_admin_menu() {
56 add_menu_page(
57 esc_html__( 'TableKit', 'table-builder-block' ),
58 esc_html__( 'TableKit', 'table-builder-block' ),
59 'manage_options',
60 $this->menu_slug,
61 array( $this, 'settings_menu_callback' ),
62 TABLE_BUILDER_BLOCK_PLUGIN_URL . 'assets/icons/admin-menu.svg',
63 26
64 );
65
66 add_submenu_page(
67 $this->menu_slug,
68 esc_html__( 'TableKit', 'table-builder-block' ),
69 esc_html__( 'TableKit', 'table-builder-block' ),
70 'manage_options',
71 admin_url( 'admin.php?page=tablebuilder&onboard=1' ),
72 '',
73 1
74 );
75
76 add_submenu_page(
77 $this->menu_slug,
78 esc_html__( 'Welcome', 'table-builder-block' ),
79 esc_html__( 'Welcome', 'table-builder-block' ),
80 'manage_options',
81 $this->menu_link_part . '#welcome',
82 '',
83 2
84 );
85
86 add_submenu_page(
87 $this->menu_slug,
88 esc_html__( 'Features', 'table-builder-block' ),
89 esc_html__( 'Features', 'table-builder-block' ),
90 'manage_options',
91 $this->menu_link_part . '#features',
92 '',
93 3
94 );
95
96 remove_submenu_page( $this->menu_slug, $this->menu_slug );
97 }
98
99 /**
100 * Whether the admin dashboard should render the onboarding flow instead
101 * of the main dashboard.
102 *
103 * @return bool
104 */
105 private function should_show_onboard(): bool {
106 if ( get_option( 'tablebuilder_onboard_completed', false ) ) {
107 return false;
108 }
109
110 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only view toggle (which admin screen to render), not a state-changing action.
111 if ( isset( $_GET['onboard'] ) && '1' === sanitize_text_field( wp_unslash( $_GET['onboard'] ) ) ) {
112 return true;
113 }
114
115 return (bool) get_transient( 'tablebuilder_show_onboard' );
116 }
117
118 /**
119 * Renders the admin page container that the React dashboard mounts into.
120 *
121 * @return void
122 */
123 public function settings_menu_callback() {
124 $admin_mode = $this->should_show_onboard() ? 'onboard' : 'dashboard';
125 ?>
126 <div class="wrap">
127 <div class="tablebuilder-dashboard" data-admin="<?php echo esc_attr( $admin_mode ); ?>"></div>
128 </div>
129 <?php
130 }
131 }
132