PluginProbe
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables / 2.3.0
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables v2.3.0
2.3.0 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 +131 -74 2.1.1 → 2.3.0 View file →
@@ -1,74 +1,131 @@
1 -<?php
2 -
3 -namespace TableBuilder\Admin;
4 -use TableBuilder\Traits\PluginHelper;
5 -
6 -defined('ABSPATH') || exit;
7 -
8 -//The admin class for TableBuilder
9 -class Admin
10 -{
11 - use \TableBuilder\Traits\Singleton;
12 - use PluginHelper;
13 -
14 - // slug of the admin menu
15 - private $menu_slug = 'tablebuilder';
16 -
17 - // $menu_link_part Part of the menu link used in the admin panel.
18 - private $menu_link_part;
19 -
20 - //Initialize the class
21 - public function __construct()
22 - {
23 - $this->menu_link_part = admin_url('admin.php?page=tablebuilder');
24 -
25 - // Register Settings API
26 - new Api\SettingsData();
27 - add_action('admin_menu', [$this, 'add_admin_menu'], 9);
28 - }
29 -
30 - public function add_admin_menu()
31 - {
32 - add_menu_page(
33 - esc_html__('Table Builder', 'table-builder-block'),
34 - esc_html__('Table Builder', 'table-builder-block'),
35 - 'manage_options',
36 - $this->menu_slug,
37 - [$this, 'settings_menu_callback'],
38 - TABLE_BUILDER_BLOCK_PLUGIN_URL . 'assets/icons/admin-menu.svg',
39 - 26
40 - );
41 -
42 - add_submenu_page(
43 - $this->menu_slug,
44 - esc_html__('Welcome', 'table-builder-block'),
45 - esc_html__('Welcome', 'table-builder-block'),
46 - 'manage_options',
47 - $this->menu_link_part . '#welcome',
48 - '',
49 - 1
50 - );
51 -
52 - add_submenu_page(
53 - $this->menu_slug,
54 - esc_html__('Features', 'table-builder-block'),
55 - esc_html__('Features', 'table-builder-block'),
56 - 'manage_options',
57 - $this->menu_link_part . '#features',
58 - '',
59 - 2
60 - );
61 -
62 - remove_submenu_page($this->menu_slug, $this->menu_slug);
63 - }
64 -
65 - // Callback for settings submenu
66 - public function settings_menu_callback()
67 - {
68 - ?>
69 - <div class="wrap">
70 - <div class="tablebuilder-dashboard"></div>
71 - </div>
72 - <?php
73 - }
74 -}
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 +}