PluginProbe
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables / 2.2.14
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables v2.2.14
2.2.14 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
← All changes | includes/Admin/Admin.php +105 -74 2.2.82.2.14 View file →
@@ -1,100 +1,131 @@
1 1 <?php
2 +/**
3 + * Admin dashboard and menu registration for TableKit
4 + *
5 + * @package TableKit
6 + */
2 7
3 8 namespace TableBuilder\Admin;
9 +
4 10 use TableBuilder\Traits\PluginHelper;
5 11
6 -defined('ABSPATH') || exit;
12 +defined( 'ABSPATH' ) || exit;
7 13
8 -//The admin class for TableBuilder
9 -class Admin
10 -{
11 - use \TableBuilder\Traits\Singleton;
12 - use PluginHelper;
14 +/**
15 + * The admin class for TableBuilder.
16 + */
17 +class Admin {
13 18
14 - // slug of the admin menu
15 - private $menu_slug = 'tablebuilder';
19 + use \TableBuilder\Traits\Singleton;
20 + use PluginHelper;
16 21
17 - // $menu_link_part Part of the menu link used in the admin panel.
18 - private $menu_link_part;
22 + /**
23 + * Slug of the admin menu.
24 + *
25 + * @var string
26 + */
27 + private $menu_slug = 'tablebuilder';
19 28
20 - //Initialize the class
21 - public function __construct()
22 - {
23 - $this->menu_link_part = admin_url('admin.php?page=tablebuilder');
29 + /**
30 + * Part of the menu link used in the admin panel.
31 + *
32 + * @var string
33 + */
34 + private $menu_link_part;
24 35
25 - // Register Settings API
26 - new Api\SettingsData();
27 - new Api\OnboardData();
28 - new Api\ChangelogData();
29 - add_action('admin_menu', [$this, 'add_admin_menu'], 9);
30 - }
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' );
31 41
32 - public function add_admin_menu()
33 - {
34 - add_menu_page(
35 - esc_html__('TableKit', 'table-builder-block'),
36 - esc_html__('TableKit', 'table-builder-block'),
37 - 'manage_options',
38 - $this->menu_slug,
39 - [$this, 'settings_menu_callback'],
40 - TABLE_BUILDER_BLOCK_PLUGIN_URL . 'assets/icons/admin-menu.svg',
41 - 26
42 - );
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 + }
43 48
44 - add_submenu_page(
45 - $this->menu_slug,
46 - esc_html__('TableKit', 'table-builder-block'),
47 - esc_html__('TableKit', 'table-builder-block'),
48 - 'manage_options',
49 - admin_url('admin.php?page=tablebuilder&onboard=1'),
50 - '',
51 - 1
52 - );
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 + );
53 65
54 - add_submenu_page(
55 - $this->menu_slug,
56 - esc_html__('Welcome', 'table-builder-block'),
57 - esc_html__('Welcome', 'table-builder-block'),
58 - 'manage_options',
59 - $this->menu_link_part . '#welcome',
60 - '',
61 - 2
62 - );
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 + );
63 75
64 - add_submenu_page(
76 + add_submenu_page(
65 77 $this->menu_slug,
66 - esc_html__('Features', 'table-builder-block'),
67 - esc_html__('Features', 'table-builder-block'),
78 + esc_html__( 'Welcome', 'table-builder-block' ),
79 + esc_html__( 'Welcome', 'table-builder-block' ),
68 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',
69 91 $this->menu_link_part . '#features',
70 92 '',
71 93 3
72 94 );
73 95
74 - remove_submenu_page($this->menu_slug, $this->menu_slug);
75 - }
96 + remove_submenu_page( $this->menu_slug, $this->menu_slug );
97 + }
76 98
77 - private function should_show_onboard(): bool
78 - {
79 - if ( get_option( 'tablebuilder_onboard_completed', false ) ) {
80 - return false;
81 - }
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 + }
82 109
83 - if ( isset( $_GET['onboard'] ) && '1' === sanitize_text_field( wp_unslash( $_GET['onboard'] ) ) ) {
84 - return true;
85 - }
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 + }
86 114
87 - return (bool) get_transient( 'tablebuilder_show_onboard' );
88 - }
115 + return (bool) get_transient( 'tablebuilder_show_onboard' );
116 + }
89 117
90 - // Callback for settings submenu
91 - public function settings_menu_callback()
92 - {
93 - $admin_mode = $this->should_show_onboard() ? 'onboard' : 'dashboard';
94 - ?>
95 - <div class="wrap">
96 - <div class="tablebuilder-dashboard" data-admin="<?php echo esc_attr( $admin_mode ); ?>"></div>
97 - </div>
98 - <?php
99 - }
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 + }
100 131 }