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 / table-builder-block.php

table-builder-block.php in TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables trunk, at table-builder-block.php

221 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: TableKit
4 * Plugin URI: https://wpmet.com/plugin/gutenkit/
5 * Description: Powerful Table Builder for Gutenberg block editor.
6 * Version: 2.2.13
7 * Requires at least: 6.1
8 * Requires PHP: 7.4
9 * Author: Wpmet
10 * Author URI: https://wpmet.com/
11 * License: GPL-3.0-or-later
12 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
13 * Text Domain: table-builder-block
14 * Domain Path: /languages
15 *
16 * @package TableKit
17 */
18
19 // Exit if accessed directly.
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 /**
25 * Main plugin bootstrap class for TableKit.
26 */
27 final class TableBuilder {
28 const VERSION = '2.2.13';
29
30 /**
31 * Singleton instance.
32 *
33 * @var TableBuilder|null
34 */
35 private static $instance = null;
36
37 /**
38 * Gets (and lazily creates) the singleton plugin instance.
39 *
40 * @return TableBuilder
41 */
42 public static function get_instance(): TableBuilder {
43 if ( null === self::$instance ) {
44 self::$instance = new self();
45 }
46 return self::$instance;
47 }
48
49 /**
50 * Defines plugin constants and registers the plugin's core hooks.
51 */
52 private function __construct() {
53 $this->define_constants();
54
55 // Prevent redirects during programmatic plugin activation.
56 // This hook runs very early to intercept activation redirects from other plugins.
57 add_action( 'admin_init', array( $this, 'prevent_activation_redirect' ), 1 );
58
59 // Make sure ADD AUTOLOAD is scoped/deps/scoper-autoload.php file.
60 require_once TABLE_BUILDER_BLOCK_PLUGIN_DIR . '/scoped/deps/scoper-autoload.php';
61 require_once TABLE_BUILDER_BLOCK_INC_DIR . 'Elementor/TablekitElementor.php';
62
63 // Fires after initialization of the GutenKit plugin.
64 add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ) );
65 add_action( 'admin_init', array( $this, 'maybe_redirect_to_onboard' ) );
66
67 // Load translated strings for PHP (.mo). JS/React strings are handled
68 // separately per-script via wp_set_script_translations() in Enqueue.php.
69 add_action( 'init', array( $this, 'load_textdomain' ) );
70 }
71
72 /**
73 * Loads the plugin's PHP translation file.
74 *
75 * WordPress 5.9+ can auto-discover this from the "Text Domain"/"Domain Path"
76 * plugin headers, but declaring it explicitly is the standard, version-safe
77 * pattern and is required for translations shipped under
78 * wp-content/languages/plugins/ instead of this plugin's own /languages folder.
79 */
80 public function load_textdomain(): void {
81 // phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- kept for translation delivery outside the WordPress.org directory (e.g. wp-content/languages/table-builder-block/ or a bundled distribution); WordPress.org itself auto-loads by slug since 4.6 and doesn't need this call.
82 load_plugin_textdomain(
83 'table-builder-block',
84 false,
85 dirname( plugin_basename( __FILE__ ) ) . '/languages'
86 );
87 }
88
89 /**
90 * Plugin activation callback: records the install time and, on first
91 * activation, primes the transients that trigger the onboarding redirect.
92 *
93 * @return void
94 */
95 public static function activate(): void {
96 if ( ! get_option( 'tablebuilder_installed_time' ) ) {
97 add_option( 'tablebuilder_installed_time', time() );
98 }
99
100 if ( get_transient( 'tablekit_skip_activation_redirect' ) ) {
101 return;
102 }
103
104 if ( ! get_option( 'tablebuilder_onboard_completed', false ) ) {
105 set_transient( 'tablebuilder_show_onboard', 1, DAY_IN_SECONDS );
106 set_transient( 'tablebuilder_do_activation_redirect', 1, MINUTE_IN_SECONDS );
107 }
108 }
109
110 /**
111 * Defines the plugin's path/URL/version constants.
112 *
113 * @return void
114 */
115 private function define_constants(): void {
116 define( 'TABLE_BUILDER_BLOCK_PLUGIN_VERSION', self::VERSION );
117 define( 'TABLE_BUILDER_BLOCK_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
118 define( 'TABLE_BUILDER_BLOCK_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
119 define( 'TABLE_BUILDER_BLOCK_INC_DIR', TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'includes/' );
120 define( 'TABLE_BUILDER_BLOCK_STYLE_DIR', TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'build/styles/' );
121 define( 'TABLE_BUILDER_BLOCK_DIR', TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'build/blocks/' );
122 }
123
124
125 /**
126 * Prevents activation redirects when plugins are activated programmatically.
127 * Intercepts wp_redirect/wp_safe_redirect during REST API activation.
128 *
129 * @return void
130 */
131 public function prevent_activation_redirect(): void {
132 if ( get_transient( 'tablekit_skip_activation_redirect' ) ) {
133 add_filter( 'wp_redirect', '__return_empty_string', 999 );
134 add_filter( 'wp_safe_redirect_fallback', '__return_empty_string', 999 );
135 }
136 }
137
138 /**
139 * Boots the plugin's core classes once all plugins have loaded.
140 *
141 * @return void
142 */
143 public function on_plugins_loaded(): void {
144 /**
145 * Fires right before TableKit's core classes are instantiated, on "plugins_loaded".
146 *
147 * @since Unknown
148 */
149 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- slash-namespaced hook name is this plugin's established public API (used by the Pro add-on); renaming would be a breaking change.
150 do_action( 'tablebuilder/before_init' );
151
152 // Note: translations are already loaded via load_textdomain(), hooked to 'init'
153 // in the constructor above (which runs before the 'init' callbacks registered
154 // by the classes below) — no need to call load_plugin_textdomain() again here.
155
156 TableBuilder\Hooks\AssetGenerator::instance();
157 TableBuilder\Core\ScriptTranslationMerger::instance();
158 TableBuilder\Core\Enqueue::instance();
159 TableBuilder\Core\RestApi::instance();
160 TableBuilder\Config\CPT\TableCPT::instance();
161 TableBuilder\Config\Blocks::instance();
162 TableBuilder\Shortcode\Shortcode::instance();
163 TableBuilder\Admin\Admin::instance();
164 TableKit_Elementor::init();
165
166 // Receive deactivation reason data from the plugins-page modal.
167 new TableBuilder\Routes\DeactivationFeedback();
168
169 if ( is_admin() ) {
170 TableBuilder\Libs\UtilityPackages::instance();
171 }
172
173 // Data migration.
174 // TODO:: Will be removed in next upcoming version.
175 ( new TableBuilder\Core\DataMigration() );
176
177 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_link' ) );
178 }
179
180 /**
181 * Redirects to the onboarding screen right after activation, when eligible.
182 *
183 * @return void
184 */
185 public function maybe_redirect_to_onboard(): void {
186 if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
187 return;
188 }
189
190 if ( ! get_transient( 'tablebuilder_do_activation_redirect' ) ) {
191 return;
192 }
193
194 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check (same pattern WP core uses internally) to skip a redirect during bulk activation; no state change.
195 if ( isset( $_GET['activate-multi'] ) ) {
196 delete_transient( 'tablebuilder_do_activation_redirect' );
197 return;
198 }
199
200 delete_transient( 'tablebuilder_do_activation_redirect' );
201 wp_safe_redirect( admin_url( 'admin.php?page=tablebuilder&onboard=1' ) );
202 exit;
203 }
204
205 /**
206 * Filter callback for the plugin's row action links (currently a no-op passthrough).
207 *
208 * @param array $plugin_actions Existing action links.
209 * @return array Unmodified action links.
210 */
211 public function plugin_action_link( array $plugin_actions ): array {
212 return $plugin_actions;
213 }
214 }
215
216 if ( class_exists( 'TableBuilder' ) ) {
217 TableBuilder::get_instance();
218 }
219
220 register_activation_hook( __FILE__, array( 'TableBuilder', 'activate' ) );
221