| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: MaxiBlocks |
| 5 |
* Plugin URI: https://maxiblocks.com/ |
| 6 |
* Description: A powerful page builder for WordPress Gutenberg with a vast library of free web templates, icons & patterns. Open source and free to build. Anything you create with MaxiBlocks is yours to keep. There's no lock-in, no domain restrictions or license keys to keep track of. All blocks and features are free to use. Save time, get advanced designs & more with the Pro cloud library upgrade. |
| 7 |
* Author: MaxiBlocks |
| 8 |
* Author URI: https://maxiblocks.com/go/plugin-author |
| 9 |
* Version: 2.2.3 |
| 10 |
* Requires at least: 6.3 |
| 11 |
* Requires PHP: 8.0 |
| 12 |
* License: GPLv3 or later |
| 13 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt |
| 14 |
* Text Domain: maxi-blocks |
| 15 |
* Domain Path: /languages |
| 16 |
*/ |
| 17 |
|
| 18 |
// Exit if accessed directly. |
| 19 |
if (!defined('ABSPATH')) { |
| 20 |
exit(); |
| 21 |
} |
| 22 |
|
| 23 |
define('MAXI_PLUGIN_DIR_PATH', plugin_dir_path(__FILE__)); |
| 24 |
define('MAXI_PLUGIN_DIR_FILE', __FILE__); |
| 25 |
define('MAXI_PLUGIN_URL_PATH', plugin_dir_url(__FILE__)); |
| 26 |
define( |
| 27 |
'MAXI_PLUGIN_VERSION', |
| 28 |
get_file_data(__FILE__, ['Version' => 'Version'], false)['Version'], |
| 29 |
); |
| 30 |
// Define the required MySQL version. |
| 31 |
define('REQUIRED_MYSQL_VERSION', '8.0'); |
| 32 |
define('REQUIRED_MARIADB_VERSION', '10.4'); |
| 33 |
|
| 34 |
// Load Composer dependencies when available. |
| 35 |
$maxi_autoload_path = MAXI_PLUGIN_DIR_PATH . 'vendor/autoload.php'; |
| 36 |
if (file_exists($maxi_autoload_path)) { |
| 37 |
require_once $maxi_autoload_path; |
| 38 |
} |
| 39 |
|
| 40 |
//====================================================================== |
| 41 |
// Translations |
| 42 |
//====================================================================== |
| 43 |
add_action('init', 'maxi_load_textdomain'); |
| 44 |
|
| 45 |
function maxi_load_textdomain() |
| 46 |
{ |
| 47 |
// phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- required to load bundled .mo translation files not hosted on WordPress.org |
| 48 |
load_plugin_textdomain( |
| 49 |
'maxi-blocks', |
| 50 |
false, |
| 51 |
dirname(plugin_basename(__FILE__)) . '/languages', |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
function maxi_load_translations($mofile, $domain) |
| 56 |
{ |
| 57 |
if ('maxi-blocks' === $domain) { |
| 58 |
$locale = apply_filters('plugin_locale', determine_locale(), $domain); |
| 59 |
|
| 60 |
$mofile_new = |
| 61 |
WP_PLUGIN_DIR . |
| 62 |
'/' . |
| 63 |
dirname(plugin_basename(__FILE__)) . |
| 64 |
'/languages/' . |
| 65 |
$domain . |
| 66 |
'-' . |
| 67 |
$locale . |
| 68 |
'.mo'; |
| 69 |
|
| 70 |
// Check if the new MO file exists |
| 71 |
if (file_exists($mofile_new)) { |
| 72 |
return $mofile_new; |
| 73 |
} |
| 74 |
} |
| 75 |
return $mofile; |
| 76 |
} |
| 77 |
add_filter('load_textdomain_mofile', 'maxi_load_translations', 10, 2); |
| 78 |
|
| 79 |
//====================================================================== |
| 80 |
// Plugin action links |
| 81 |
//====================================================================== |
| 82 |
function maxi_blocks_add_settings_link($links) |
| 83 |
{ |
| 84 |
$settings_url = is_network_admin() |
| 85 |
? network_admin_url('admin.php?page=maxi-blocks-dashboard') |
| 86 |
: admin_url('admin.php?page=maxi-blocks-dashboard&tab=maxi_blocks_settings'); |
| 87 |
$settings_link = |
| 88 |
'<a href="' . |
| 89 |
esc_url($settings_url) . |
| 90 |
'">' . |
| 91 |
esc_html__('Settings', 'maxi-blocks') . |
| 92 |
'</a>'; |
| 93 |
|
| 94 |
array_unshift($links, $settings_link); |
| 95 |
|
| 96 |
return $links; |
| 97 |
} |
| 98 |
add_filter( |
| 99 |
'plugin_action_links_' . plugin_basename(__FILE__), |
| 100 |
'maxi_blocks_add_settings_link', |
| 101 |
); |
| 102 |
|
| 103 |
//====================================================================== |
| 104 |
// Database version check |
| 105 |
//====================================================================== |
| 106 |
// Hook for checking the database version in the admin area |
| 107 |
add_action('admin_init', 'maxi_check_database_version'); |
| 108 |
|
| 109 |
/** |
| 110 |
* Check the required database version during admin initialization |
| 111 |
*/ |
| 112 |
function maxi_check_database_version() |
| 113 |
{ |
| 114 |
global $wpdb; |
| 115 |
|
| 116 |
// Check if the database is MariaDB |
| 117 |
$isMariaDB = strpos(strtolower($wpdb->db_server_info()), 'maria') !== false; |
| 118 |
$requiredVersion = $isMariaDB |
| 119 |
? REQUIRED_MARIADB_VERSION |
| 120 |
: REQUIRED_MYSQL_VERSION; |
| 121 |
|
| 122 |
// Compare the current database version with the required version |
| 123 |
if (version_compare($wpdb->db_version(), $requiredVersion, '<')) { |
| 124 |
$plugin_file = plugin_basename(__FILE__); |
| 125 |
add_action( |
| 126 |
"after_plugin_row_{$plugin_file}", |
| 127 |
'maxi_show_database_version_notice', |
| 128 |
10, |
| 129 |
3, |
| 130 |
); |
| 131 |
add_action( |
| 132 |
'admin_enqueue_scripts', |
| 133 |
'maxi_blocks_enqueue_notice_scripts', |
| 134 |
); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Enqueue JavaScript for the admin notice |
| 140 |
*/ |
| 141 |
function maxi_blocks_enqueue_notice_scripts() |
| 142 |
{ |
| 143 |
wp_enqueue_script( |
| 144 |
'maxi-blocks-admin-notice', |
| 145 |
plugins_url('/core/admin/notices.js', __FILE__), |
| 146 |
[], |
| 147 |
MAXI_PLUGIN_VERSION, |
| 148 |
true, |
| 149 |
); |
| 150 |
|
| 151 |
// Localize script with REST API URL and nonce |
| 152 |
wp_localize_script('maxi-blocks-admin-notice', 'maxiBlocks', [ |
| 153 |
'rest_url' => rest_url('maxi-blocks/v1/dismiss-notice'), |
| 154 |
'nonce' => wp_create_nonce('wp_rest'), |
| 155 |
]); |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Show an admin notice under the plugin's name if the required database version is not met |
| 160 |
*/ |
| 161 |
function maxi_show_database_version_notice() |
| 162 |
{ |
| 163 |
if (get_option('maxi_blocks_db_notice_dismissed') === 'yes') { |
| 164 |
return; |
| 165 |
} |
| 166 |
|
| 167 |
global $wpdb; |
| 168 |
$isMariaDB = strpos(strtolower($wpdb->db_server_info()), 'maria') !== false; |
| 169 |
$requiredVersion = $isMariaDB |
| 170 |
? REQUIRED_MARIADB_VERSION |
| 171 |
: REQUIRED_MYSQL_VERSION; |
| 172 |
$databaseType = $isMariaDB ? 'MariaDB' : 'MySQL'; |
| 173 |
$message = |
| 174 |
sprintf( |
| 175 |
/* translators: %1$s: database type, %2$s: required version, %3$s: link URL */ |
| 176 |
esc_html__( |
| 177 |
'Highly recommend to update to %1$s %2$s+ for enhanced security, better performance, and full feature compatibility.', |
| 178 |
'maxi-blocks', |
| 179 |
), |
| 180 |
esc_html($databaseType), |
| 181 |
esc_html($requiredVersion), |
| 182 |
) . |
| 183 |
' <a href="' . |
| 184 |
esc_url('https://maxiblocks.com/go/database-version-requirements') . |
| 185 |
'" target="_blank">' . |
| 186 |
esc_html__('Learn more', 'maxi-blocks') . |
| 187 |
'</a>'; |
| 188 |
|
| 189 |
echo '<tr class="plugin-update-tr active maxi-blocks-db-notice" data-slug="maxi-blocks" data-plugin="maxi-blocks/plugin.php">'; |
| 190 |
echo '<td colspan="4" class="plugin-update colspanchange">'; |
| 191 |
echo '<div class="update-message notice inline notice-warning notice-alt is-dismissible"><p>'; |
| 192 |
echo wp_kses_post($message); |
| 193 |
echo '</p></div></td></tr>'; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Register REST API endpoint for dismissing the notice |
| 198 |
*/ |
| 199 |
function maxi_blocks_register_rest_route() |
| 200 |
{ |
| 201 |
register_rest_route('maxi-blocks/v1', '/dismiss-notice', [ |
| 202 |
'methods' => 'POST', |
| 203 |
'callback' => 'maxi_blocks_dismiss_notice', |
| 204 |
'permission_callback' => function () { |
| 205 |
return current_user_can('manage_options'); |
| 206 |
}, |
| 207 |
]); |
| 208 |
} |
| 209 |
add_action('rest_api_init', 'maxi_blocks_register_rest_route'); |
| 210 |
|
| 211 |
/** |
| 212 |
* Dismiss the notice and update the option in the database |
| 213 |
*/ |
| 214 |
function maxi_blocks_dismiss_notice() |
| 215 |
{ |
| 216 |
update_option('maxi_blocks_db_notice_dismissed', 'yes'); |
| 217 |
return new WP_REST_Response(null, 204); |
| 218 |
} |
| 219 |
|
| 220 |
function maxi_blocks_after_update($upgrader_object, $options) |
| 221 |
{ |
| 222 |
// Check if required keys exist in the options array |
| 223 |
if ( |
| 224 |
!isset($options['action']) || |
| 225 |
!isset($options['type']) || |
| 226 |
!isset($options['plugins']) |
| 227 |
) { |
| 228 |
return; |
| 229 |
} |
| 230 |
// Check if it's an update of plugins |
| 231 |
if ($options['action'] == 'update' && $options['type'] == 'plugin') { |
| 232 |
// Check if YOUR plugin is in the list of updated plugins |
| 233 |
foreach ($options['plugins'] as $plugin) { |
| 234 |
if ($plugin == plugin_basename(__FILE__)) { |
| 235 |
// Reset the dismissal option |
| 236 |
update_option('maxi_blocks_db_notice_dismissed', 'no'); |
| 237 |
break; |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
add_action('upgrader_process_complete', 'maxi_blocks_after_update', 10, 2); |
| 243 |
|
| 244 |
//====================================================================== |
| 245 |
// Init |
| 246 |
//====================================================================== |
| 247 |
|
| 248 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/admin/maxi-allowed-html-tags.php'; |
| 249 |
|
| 250 |
// remove noopener noreferrer from gutenberg links |
| 251 |
function maxi_links_control($rel, $link) |
| 252 |
{ |
| 253 |
return false; |
| 254 |
} |
| 255 |
add_filter('wp_targeted_link_rel', 'maxi_links_control', 10, 2); |
| 256 |
add_action('wp_ajax_maxi_get_option', 'maxi_get_option', 9, 1); |
| 257 |
|
| 258 |
//====================================================================== |
| 259 |
// MaxiBlocks Core |
| 260 |
//====================================================================== |
| 261 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-core.php'; |
| 262 |
if (class_exists('MaxiBlocks_Core')) { |
| 263 |
MaxiBlocks_Core::register(); |
| 264 |
} |
| 265 |
|
| 266 |
//====================================================================== |
| 267 |
// MaxiBlocks Custom Scripts |
| 268 |
//====================================================================== |
| 269 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-custom-scripts.php'; |
| 270 |
if (class_exists('MaxiBlocks_Custom_Scripts')) { |
| 271 |
MaxiBlocks_Custom_Scripts::register(); |
| 272 |
} |
| 273 |
|
| 274 |
//====================================================================== |
| 275 |
// MaxiBlocks DB |
| 276 |
//====================================================================== |
| 277 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-db.php'; |
| 278 |
if (class_exists('MaxiBlocks_DB')) { |
| 279 |
MaxiBlocks_DB::register(); |
| 280 |
} |
| 281 |
|
| 282 |
//====================================================================== |
| 283 |
// MaxiBlocks Blocks |
| 284 |
//====================================================================== |
| 285 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-blocks.php'; |
| 286 |
if (class_exists('MaxiBlocks_Blocks')) { |
| 287 |
MaxiBlocks_Blocks::register(); |
| 288 |
} |
| 289 |
|
| 290 |
//====================================================================== |
| 291 |
// MaxiBlocks Styles |
| 292 |
//====================================================================== |
| 293 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-styles.php'; |
| 294 |
if (class_exists('MaxiBlocks_Styles')) { |
| 295 |
MaxiBlocks_Styles::register(); |
| 296 |
} |
| 297 |
|
| 298 |
//====================================================================== |
| 299 |
// MaxiBlocks Style Cards |
| 300 |
//====================================================================== |
| 301 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-style-cards.php'; |
| 302 |
if (class_exists('MaxiBlocks_StyleCards')) { |
| 303 |
MaxiBlocks_StyleCards::register(); |
| 304 |
} |
| 305 |
|
| 306 |
//====================================================================== |
| 307 |
// MaxiBlocks Custom Fonts |
| 308 |
//====================================================================== |
| 309 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-custom-fonts.php'; |
| 310 |
|
| 311 |
//====================================================================== |
| 312 |
// MaxiBlocks Image Crop |
| 313 |
//====================================================================== |
| 314 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-image-crop.php'; |
| 315 |
if (class_exists('MaxiBlocks_ImageCrop')) { |
| 316 |
MaxiBlocks_ImageCrop::register(); |
| 317 |
} |
| 318 |
|
| 319 |
//====================================================================== |
| 320 |
// MaxiBlocks API |
| 321 |
//====================================================================== |
| 322 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-api.php'; |
| 323 |
MaxiBlocks_API::register(); |
| 324 |
if (class_exists('MaxiBlocks_API')) { |
| 325 |
add_action('plugins_loaded', ['MaxiBlocks_API', 'register']); |
| 326 |
} |
| 327 |
|
| 328 |
//====================================================================== |
| 329 |
// MaxiBlocks Page Template |
| 330 |
//====================================================================== |
| 331 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-page-template.php'; |
| 332 |
if (class_exists('MaxiBlocks_PageTemplate')) { |
| 333 |
add_action('plugins_loaded', ['MaxiBlocks_PageTemplate', 'register']); |
| 334 |
} |
| 335 |
|
| 336 |
//====================================================================== |
| 337 |
// MaxiBlocks Dashboard |
| 338 |
//====================================================================== |
| 339 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/admin/class-maxi-dashboard.php'; |
| 340 |
if (class_exists('MaxiBlocks_Dashboard')) { |
| 341 |
MaxiBlocks_Dashboard::register(); |
| 342 |
} |
| 343 |
|
| 344 |
//====================================================================== |
| 345 |
// MaxiBlocks Dynamic Content |
| 346 |
//====================================================================== |
| 347 |
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-dynamic-content.php'; |
| 348 |
if (class_exists('MaxiBlocks_DynamicContent')) { |
| 349 |
MaxiBlocks_DynamicContent::register(); |
| 350 |
} |
| 351 |
|
| 352 |
//====================================================================== |
| 353 |
// MaxiBlocks Go |
| 354 |
//====================================================================== |
| 355 |
if (get_template() === 'maxiblocks-go') { |
| 356 |
$theme_version = wp_get_theme('maxiblocks-go')->get('Version'); |
| 357 |
|
| 358 |
if (version_compare($theme_version, '1.2.1', '>=')) { |
| 359 |
require_once MAXI_PLUGIN_DIR_PATH . |
| 360 |
'core/maxiblocks-go/maxiblocks-go.php'; |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
//====================================================================== |
| 365 |
// MaxiBlocks Onboarding |
| 366 |
//====================================================================== |
| 367 |
// Check if we're in a test environment using .env file |
| 368 |
$is_test_environment = false; |
| 369 |
$env_file = dirname(__FILE__) . '/.env'; |
| 370 |
|
| 371 |
if (file_exists($env_file)) { |
| 372 |
$env_config = @parse_ini_file($env_file); |
| 373 |
if ($env_config !== false) { |
| 374 |
$is_test_environment = |
| 375 |
isset($env_config['GITHUB_ENV_TEST']) && |
| 376 |
in_array( |
| 377 |
$env_config['GITHUB_ENV_TEST'], |
| 378 |
[1, '1', true, 'true'], |
| 379 |
true, |
| 380 |
); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
if (!$is_test_environment) { |
| 385 |
require_once MAXI_PLUGIN_DIR_PATH . |
| 386 |
'core/class-maxi-quick-start-register.php'; |
| 387 |
if (class_exists('MaxiBlocks_QuickStart_Register')) { |
| 388 |
MaxiBlocks_QuickStart_Register::register(); |
| 389 |
|
| 390 |
// Register activation hook |
| 391 |
register_activation_hook(__FILE__, [ |
| 392 |
'MaxiBlocks_QuickStart_Register', |
| 393 |
'activate', |
| 394 |
]); |
| 395 |
|
| 396 |
// Handle redirect after activation |
| 397 |
add_action('admin_init', function () { |
| 398 |
if (get_transient('maxi_blocks_activation_redirect')) { |
| 399 |
delete_transient('maxi_blocks_activation_redirect'); |
| 400 |
if (!isset($_GET['activate-multi'])) { |
| 401 |
wp_safe_redirect( |
| 402 |
admin_url('admin.php?page=maxi-blocks-quick-start'), |
| 403 |
); |
| 404 |
exit(); |
| 405 |
} |
| 406 |
} |
| 407 |
}); |
| 408 |
} |
| 409 |
} |
| 410 |
|