| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: aBlocks |
| 4 |
* Description: The WordPress plugin for creating beautiful and functional websites using the Gutenberg editor, with a variety of customizable blocks to design website pages. |
| 5 |
* Requires at least: 6.8 |
| 6 |
* Requires PHP: 7.4 |
| 7 |
* Version: 2.11.1 |
| 8 |
* Author: Kodezen LLC |
| 9 |
* Author URI: https://ablocks.pro/ |
| 10 |
* License: GPL-3.0+ |
| 11 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 12 |
* Text Domain: ablocks |
| 13 |
* Domain Path: /languages/ |
| 14 |
*/ |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
final class ABlocks { |
| 21 |
public function __construct() { |
| 22 |
// define constants |
| 23 |
$this->define_constants(); |
| 24 |
$this->load_dependency(); |
| 25 |
// Register the free product with the shared StoreEngine SDK (loaded in |
| 26 |
// load_dependency) so the SDK owns the deactivation popup + opt-in. |
| 27 |
\ABlocks\Admin\StoreLicense::init(); |
| 28 |
$this->load_cli(); |
| 29 |
register_activation_hook( __FILE__, [ $this, 'activate' ] ); |
| 30 |
register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] ); |
| 31 |
$this->set_global_settings(); |
| 32 |
add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ] ); |
| 33 |
add_action( 'ablocks_loaded', [ $this, 'init_plugin' ] ); |
| 34 |
} |
| 35 |
|
| 36 |
public static function init() { |
| 37 |
static $instance = false; |
| 38 |
if ( ! $instance ) { |
| 39 |
$instance = new self(); |
| 40 |
} |
| 41 |
return $instance; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Define the plugin constants |
| 46 |
*/ |
| 47 |
private function define_constants() { |
| 48 |
define( 'ABLOCKS_VERSION', '2.11.1' ); |
| 49 |
define( 'ABLOCKS_PLUGIN_SLUG', 'ablocks' ); |
| 50 |
define( 'ABLOCKS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 51 |
define( 'ABLOCKS_ROOT_URL', plugin_dir_url( __FILE__ ) ); |
| 52 |
define( 'ABLOCKS_ASSETS_URL', ABLOCKS_ROOT_URL . 'assets/' ); |
| 53 |
define( 'ABLOCKS_ROOT_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 54 |
define( 'ABLOCKS_ASSETS_PATH', ABLOCKS_ROOT_DIR_PATH . 'assets/' ); |
| 55 |
define( 'ABLOCKS_INCLUDES_DIR_PATH', ABLOCKS_ROOT_DIR_PATH . 'includes/' ); |
| 56 |
define( 'ABLOCKS_BLOCKS_DIR_PATH', ABLOCKS_ROOT_DIR_PATH . 'includes/blocks/' ); |
| 57 |
define( 'ABLOCKS_ADDONS_DIR_PATH', ABLOCKS_ROOT_DIR_PATH . 'addons/' ); |
| 58 |
define( 'ABLOCKS_BLOCKS_VISIBILITY_SETTINGS_NAME', 'ablocks_blocks' ); |
| 59 |
define( 'ABLOCKS_FONTS_SETTINGS_NAME', 'ablocks_fonts' ); |
| 60 |
define( 'ABLOCKS_REST_NAMESPACE', 'ablocks/v1' ); |
| 61 |
define( 'ABLOCKS_SETTINGS_NAME', 'ablocks_settings' ); |
| 62 |
define( 'ABLOCKS_FRONTEND_DASHBOARD_SUB_PAGES_SETTINGS_NAME', 'ablocks_frontend_dashboard_sub_pages' ); |
| 63 |
define( 'ABLOCKS_ADDONS_SETTINGS_NAME', 'ablocks_addons' ); |
| 64 |
define( 'ABLOCKS_TEMPLATE_LIB_HOST', 'template-kits.com' ); |
| 65 |
} |
| 66 |
|
| 67 |
public function load_dependency() { |
| 68 |
require_once ABLOCKS_INCLUDES_DIR_PATH . 'autoload.php'; |
| 69 |
|
| 70 |
// Load the shared StoreEngine License Management Client SDK. aBlocks (free) |
| 71 |
// owns this version-managed library (Composer package |
| 72 |
// `storeengine/wordpress-sdk`); aBlocks Pro (and any add-on) reuses the |
| 73 |
// already-loaded SDK rather than bundling its own copy. |
| 74 |
if ( file_exists( ABLOCKS_ROOT_DIR_PATH . 'vendor/autoload.php' ) ) { |
| 75 |
require_once ABLOCKS_ROOT_DIR_PATH . 'vendor/autoload.php'; |
| 76 |
} |
| 77 |
|
| 78 |
// Require the SDK bootstrap DIRECTLY, not only through Composer's files |
| 79 |
// autoload. Composer de-dupes the SDK's init.php by a package-stable hash, |
| 80 |
// so when several active plugins each bundle this SDK only the first one's |
| 81 |
// autoloader includes it and the rest never register their version. Loading |
| 82 |
// it here guarantees aBlocks' bundled SDK version always joins the |
| 83 |
// "newest version wins" election regardless of plugin load order. Requiring |
| 84 |
// init.php registers this SDK version and, on `plugins_loaded`, loads |
| 85 |
// functions.php (defining se_license_init()) and the SDK class autoloader. |
| 86 |
if ( file_exists( ABLOCKS_ROOT_DIR_PATH . 'vendor/storeengine/wordpress-sdk/init.php' ) ) { |
| 87 |
require_once ABLOCKS_ROOT_DIR_PATH . 'vendor/storeengine/wordpress-sdk/init.php'; |
| 88 |
} |
| 89 |
} |
| 90 |
public function load_cli() { |
| 91 |
if ( file_exists( ABLOCKS_ROOT_DIR_PATH . 'dev-cli.php' ) ) { |
| 92 |
require_once ABLOCKS_ROOT_DIR_PATH . 'dev-cli.php'; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
public function set_global_settings() { |
| 97 |
$GLOBALS['ablocks_fonts'] = json_decode( get_option( ABLOCKS_FONTS_SETTINGS_NAME, '{}' ), true ); |
| 98 |
$GLOBALS['ablocks_blocks'] = json_decode( get_option( ABLOCKS_BLOCKS_VISIBILITY_SETTINGS_NAME, '{}' ) ); |
| 99 |
$GLOBALS['ablocks_settings'] = json_decode( get_option( ABLOCKS_SETTINGS_NAME, '{}' ) ); |
| 100 |
$GLOBALS['ablocks_addons'] = json_decode( get_option( ABLOCKS_ADDONS_SETTINGS_NAME, '{}' ) ); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* When WP has loaded all plugins, trigger the `ablocks_loaded` hook. |
| 105 |
* |
| 106 |
* This ensures `ablocks_loaded` is called only after all other plugins |
| 107 |
* are loaded, to avoid issues caused by plugin directory naming changing |
| 108 |
* |
| 109 |
* @since 1.0.0 |
| 110 |
*/ |
| 111 |
public function on_plugins_loaded() { |
| 112 |
do_action( 'ablocks_loaded' ); |
| 113 |
} |
| 114 |
|
| 115 |
public function init_plugin() { |
| 116 |
ABlocks\Migration::init(); |
| 117 |
ABlocks\PermalinkRewrite::init(); |
| 118 |
ABlocks\Addons::init(); |
| 119 |
ABlocks\Blocks::init(); |
| 120 |
ABlocks\Assets::init(); |
| 121 |
ABlocks\Classes\CoreFontRegistry::init(); |
| 122 |
ABlocks\Performance\Optimizations::init(); |
| 123 |
ABlocks\Performance\DelayJs::init(); |
| 124 |
ABlocks\Performance\DeferJs::init(); |
| 125 |
ABlocks\Performance\ImageOptimizer::init(); |
| 126 |
ABlocks\Performance\LcpPreload::init(); |
| 127 |
ABlocks\Performance\TouchTargets::init(); |
| 128 |
ABlocks\Performance\PageCache::init(); |
| 129 |
ABlocks\Performance\StyleConsolidator::init(); |
| 130 |
ABlocks\Performance\FragmentCache::init(); |
| 131 |
ABlocks\Performance\TemplateCache::init(); |
| 132 |
ABlocks\Performance\ImageTools::init(); |
| 133 |
ABlocks\Classes\Images\UploadGuard::init(); |
| 134 |
ABlocks\Ajax::init(); |
| 135 |
ABlocks\API::init(); |
| 136 |
if ( is_admin() ) { |
| 137 |
ABlocks\Admin::init(); |
| 138 |
} |
| 139 |
ABlocks\Frontend::init(); |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
public function activate() { |
| 144 |
ABlocks\Installer::init(); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Leave no scheduled work behind when the plugin is switched off. |
| 149 |
* |
| 150 |
* Cached files are deliberately left in place: deactivation is often |
| 151 |
* temporary, and re-activating should not mean rebuilding the whole cache. |
| 152 |
* They are removed on uninstall, or on demand from the Performance tab. |
| 153 |
*/ |
| 154 |
public function deactivate() { |
| 155 |
ABlocks\Classes\PageCache\Scheduler::clear_events(); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Kickoff |
| 161 |
*/ |
| 162 |
|
| 163 |
ABlocks::init(); |
| 164 |
|
| 165 |
|
| 166 |
|