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 -114 2.0.0 → 2.3.0 View file →
@@ -1,114 +1,131 @@
1 -<?php
2 -
3 -namespace TableBuilder\Admin;
4 -use TableBuilder\Traits\PluginHelper;
5 -
6 -defined('ABSPATH') || exit;
7 -
8 -/**
9 - * The admin class for TableBuilder
10 - */
11 -class Admin
12 -{
13 - use \TableBuilder\Traits\Singleton;
14 - use PluginHelper;
15 -
16 - /**
17 - * @var string slug of the admin menu
18 - */
19 - private $menu_slug = 'tablebuilder';
20 -
21 - /**
22 - * @var string $menu_link_part Part of the menu link used in the admin panel.
23 - */
24 - private $menu_link_part;
25 -
26 - /**
27 - * Initialize the class
28 - */
29 - public function __construct()
30 - {
31 - $this->menu_link_part = admin_url('admin.php?page=tablebuilder');
32 -
33 - // Register Settings API
34 - new Api\SettingsData();
35 -
36 - add_action('admin_menu', [$this, 'add_admin_menu'], 9);
37 - add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']);
38 - }
39 -
40 - public function add_admin_menu()
41 - {
42 - add_menu_page(
43 - esc_html__('Table Builder', 'table-builder-block'),
44 - esc_html__('Table Builder', 'table-builder-block'),
45 - 'manage_options',
46 - $this->menu_slug,
47 - [$this, 'settings_menu_callback'],
48 - TABLE_BUILDER_BLOCK_PLUGIN_URL . 'assets/icons/admin-menu.svg',
49 - 28
50 - );
51 -
52 - add_submenu_page(
53 - $this->menu_slug,
54 - esc_html__('Welcome', 'table-builder-block'),
55 - esc_html__('Welcome', 'table-builder-block'),
56 - 'manage_options',
57 - $this->menu_link_part . '#welcome',
58 - ''
59 - );
60 -
61 - add_submenu_page(
62 - $this->menu_slug,
63 - esc_html__('Settings', 'table-builder-block'),
64 - esc_html__('Settings', 'table-builder-block'),
65 - 'manage_options',
66 - $this->menu_link_part . '#settings'
67 - );
68 - }
69 -
70 - /**
71 - * Callback for settings submenu
72 - */
73 - public function settings_menu_callback()
74 - {
75 - ?>
76 - <div class="wrap">
77 - <h1><?php esc_html_e('Table Builder Settings', 'table-builder-block'); ?></h1>
78 - <p><?php esc_html_e('Configure the settings for Table Builder.', 'table-builder-block'); ?></p>
79 - </div>
80 - <?php
81 - }
82 -
83 - /**
84 - * Enqueue admin scripts and styles
85 - *
86 - * @param string $hook The current admin page.
87 - */
88 - public function enqueue_admin_scripts($hook)
89 - {
90 - $screen = get_current_screen();
91 -
92 - if ($screen && isset($screen->post_type) && $screen->post_type === 'tablebuilder') {
93 - wp_enqueue_style(
94 - 'table-builder-admin',
95 - TABLE_BUILDER_BLOCK_PLUGIN_URL . 'assets/css/admin.css',
96 - [],
97 - TABLE_BUILDER_BLOCK_PLUGIN_VERSION
98 - );
99 -
100 - wp_localize_script(
101 - 'wp-block-editor',
102 - 'tableBuilderBlock',
103 - [
104 - 'plugin_url' => TABLE_BUILDER_BLOCK_PLUGIN_URL,
105 - 'screen' => $hook,
106 - 'rootUrl' => esc_url(home_url('/')),
107 - 'version' => TABLE_BUILDER_BLOCK_PLUGIN_VERSION,
108 - 'activeTheme' => wp_get_theme()->get('Name'),
109 - ]
110 - );
111 - }
112 - }
113 -
114 -}
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 +}