| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: TableKit |
| 4 |
* Description: Powerful Table Builder 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.2.6 |
| 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 |
const VERSION = '2.2.6'; |
| 25 |
|
| 26 |
private static $instance = null; |
| 27 |
|
| 28 |
public static function get_instance(): TableBuilder { |
| 29 |
if ( null === self::$instance ) { |
| 30 |
self::$instance = new self(); |
| 31 |
} |
| 32 |
return self::$instance; |
| 33 |
} |
| 34 |
|
| 35 |
private function __construct() { |
| 36 |
$this->define_constants(); |
| 37 |
|
| 38 |
// Prevent redirects during programmatic plugin activation |
| 39 |
// This hook runs very early to intercept activation redirects from other plugins |
| 40 |
add_action( 'admin_init', [ $this, 'prevent_activation_redirect' ], 1 ); |
| 41 |
|
| 42 |
// Make sure ADD AUTOLOAD is scoped/vendor/scoper-autoload.php file |
| 43 |
require_once TABLE_BUILDER_BLOCK_PLUGIN_DIR . '/scoped/vendor/scoper-autoload.php'; |
| 44 |
require_once TABLE_BUILDER_BLOCK_INC_DIR . 'Elementor/TablekitElementor.php'; |
| 45 |
|
| 46 |
// Fires after initialization of the GutenKit plugin |
| 47 |
add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ] ); |
| 48 |
add_action( 'admin_init', [ $this, 'maybe_redirect_to_onboard' ] ); |
| 49 |
} |
| 50 |
|
| 51 |
public static function activate(): void { |
| 52 |
if ( get_transient( 'tablekit_skip_activation_redirect' ) ) { |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
if ( ! get_option( 'tablebuilder_onboard_completed', false ) ) { |
| 57 |
set_transient( 'tablebuilder_show_onboard', 1, DAY_IN_SECONDS ); |
| 58 |
set_transient( 'tablebuilder_do_activation_redirect', 1, MINUTE_IN_SECONDS ); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
private function define_constants(): void { |
| 63 |
define( 'TABLE_BUILDER_BLOCK_PLUGIN_VERSION', self::VERSION ); |
| 64 |
define( 'TABLE_BUILDER_BLOCK_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) ); |
| 65 |
define( 'TABLE_BUILDER_BLOCK_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) ); |
| 66 |
define( 'TABLE_BUILDER_BLOCK_INC_DIR', TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'includes/' ); |
| 67 |
define( 'TABLE_BUILDER_BLOCK_STYLE_DIR', TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'build/styles/' ); |
| 68 |
define( 'TABLE_BUILDER_BLOCK_DIR', TABLE_BUILDER_BLOCK_PLUGIN_DIR . 'build/blocks/' ); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
// Prevent activation redirects when plugins are activated programmatically. |
| 73 |
// Intercepts wp_redirect/wp_safe_redirect during REST API activation. |
| 74 |
public function prevent_activation_redirect(): void { |
| 75 |
if ( get_transient( 'tablekit_skip_activation_redirect' ) ) { |
| 76 |
add_filter( 'wp_redirect', '__return_empty_string', 999 ); |
| 77 |
add_filter( 'wp_safe_redirect_fallback', '__return_empty_string', 999 ); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
public function on_plugins_loaded(): void { |
| 82 |
do_action( 'tablebuilder/before_init' ); |
| 83 |
|
| 84 |
TableBuilder\Hooks\AssetGenerator::instance(); |
| 85 |
TableBuilder\Core\Enqueue::instance(); |
| 86 |
TableBuilder\Core\RestApi::instance(); |
| 87 |
TableBuilder\Config\CPT\TableCPT::instance(); |
| 88 |
TableBuilder\Config\Blocks::instance(); |
| 89 |
TableBuilder\Shortcode\Shortcode::instance(); |
| 90 |
TableBuilder\Admin\Admin::instance(); |
| 91 |
TableKit_Elementor::init(); |
| 92 |
|
| 93 |
if ( is_admin() ) { |
| 94 |
TableBuilder\Libs\UtilityPackages::instance(); |
| 95 |
} |
| 96 |
|
| 97 |
// Data migration |
| 98 |
// TODO:: WIll be removed in next upcoming version |
| 99 |
(new TableBuilder\Core\DataMigration()); |
| 100 |
|
| 101 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'plugin_action_link' ] ); |
| 102 |
} |
| 103 |
|
| 104 |
public function maybe_redirect_to_onboard(): void { |
| 105 |
if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) { |
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
if ( ! get_transient( 'tablebuilder_do_activation_redirect' ) ) { |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
if ( isset( $_GET['activate-multi'] ) ) { |
| 114 |
delete_transient( 'tablebuilder_do_activation_redirect' ); |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
delete_transient( 'tablebuilder_do_activation_redirect' ); |
| 119 |
wp_safe_redirect( admin_url( 'admin.php?page=tablebuilder&onboard=1' ) ); |
| 120 |
exit; |
| 121 |
} |
| 122 |
|
| 123 |
public function plugin_action_link( array $plugin_actions ): array { |
| 124 |
return $plugin_actions; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
if ( class_exists( 'TableBuilder' ) ) { |
| 129 |
TableBuilder::get_instance(); |
| 130 |
} |
| 131 |
|
| 132 |
register_activation_hook( __FILE__, [ 'TableBuilder', 'activate' ] ); |
| 133 |
|