| @@ -1,97 +1,220 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Plugin Name: Table Builder Block | |
| 4 | - * Description: Powerful table builder block for Gutenberg block editor. | |
| 5 | - * Requires at least: 6.1 | |
| 6 | - * Requires PHP: 7.4 | |
| 7 | - * Plugin URI: https://wpmet.com/plugin/gutenkit/ | |
| 8 | - * Author: Wpmet | |
| 9 | - * Version: 2.1.0 | |
| 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 | - * | |
| 14 | - * Text Domain: table-builder-block | |
| 15 | - * Domain Path: /languages | |
| 16 | - */ | |
| 17 | - | |
| 18 | -// Exit if accessed directly. | |
| 19 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 20 | - exit; | |
| 21 | -} | |
| 22 | - | |
| 23 | -final class TableBuilder { | |
| 24 | - /** | |
| 25 | - * plugin version | |
| 26 | - * | |
| 27 | - * @var string | |
| 28 | - */ | |
| 29 | - const VERSION = '2.1.0'; | |
| 30 | - | |
| 31 | - private static $instance = null; | |
| 32 | - | |
| 33 | - public static function get_instance(): TableBuilder { | |
| 34 | - if ( null === self::$instance ) { | |
| 35 | - self::$instance = new self(); | |
| 36 | - } | |
| 37 | - return self::$instance; | |
| 38 | - } | |
| 39 | - | |
| 40 | - private function __construct() { | |
| 41 | - /** | |
| 42 | - * Plugins helper constants | |
| 43 | - * | |
| 44 | - * @return void | |
| 45 | - * @since 1.0.0 | |
| 46 | - */ | |
| 47 | - $this->define_constants(); | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * Make sure ADD AUTOLOAD is scoped/vendor/scoper-autoload.php file | |
| 51 | - * | |
| 52 | - * @return void | |
| 53 | - * @since 2.0.1 | |
| 54 | - */ | |
| 55 | - require_once TABLE_BUILDER_BLOCK_PLUGIN_DIR . '/scoped/vendor/scoper-autoload.php'; | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Fires after initialization of the GutenKit plugin | |
| 59 | - * | |
| 60 | - * @return void | |
| 61 | - * @since 1.0.0 | |
| 62 | - */ | |
| 63 | - add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ] ); | |
| 64 | - } | |
| 65 | - | |
| 66 | - private function define_constants(): void { | |
| 67 | - define( 'TABLE_BUILDER_BLOCK_PLUGIN_VERSION', self::VERSION ); | |
| 68 | - define( 'TABLE_BUILDER_BLOCK_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) ); | |
| 69 | - define( 'TABLE_BUILDER_BLOCK_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) ); | |
| 70 | - define( 'TABLE_BUILDER_BLOCK_INC_DIR', TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'includes/' ); | |
| 71 | - define( 'TABLE_BUILDER_BLOCK_STYLE_DIR', TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'build/styles/' ); | |
| 72 | - define( 'TABLE_BUILDER_BLOCK_DIR', TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'build/blocks/' ); | |
| 73 | - } | |
| 74 | - | |
| 75 | - public function on_plugins_loaded(): void { | |
| 76 | - do_action( 'tablebuilder/before_init' ); | |
| 77 | - | |
| 78 | - TableBuilder\Hooks\AssetGenerator::instance(); | |
| 79 | - TableBuilder\Core\Enqueue::instance(); | |
| 80 | - TableBuilder\Config\Blocks::instance(); | |
| 81 | - TableBuilder\Admin\Admin::instance(); | |
| 82 | - | |
| 83 | - // Data migration | |
| 84 | - // TODO:: WIll be removed in next upcoming version | |
| 85 | - (new TableBuilder\Core\DataMigration()); | |
| 86 | - | |
| 87 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'plugin_action_link' ] ); | |
| 88 | - } | |
| 89 | - | |
| 90 | - public function plugin_action_link( array $plugin_actions ): array { | |
| 91 | - return $plugin_actions; | |
| 92 | - } | |
| 93 | -} | |
| 94 | - | |
| 95 | -if ( class_exists( 'TableBuilder' ) ) { | |
| 96 | - TableBuilder::get_instance(); | |
| 97 | -} | |
| 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.3.0 | |
| 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.3.0'; | |
| 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' ) ); | |