define_hooks(); $this->bootstrap(); } /** * Define plugin hooks. */ private function define_hooks() { add_filter('gutenify_plugin_constants', array($this, 'add_plugin_constants')); add_filter('gutenify_active_blocks', array($this, 'exclude_blocks_still_bundled_in_old_pro')); // Uncomment if you want activation redirect. // add_action( 'activated_plugin', array( $this, 'activation_redirect' ) ); } /** * This plugin's own bootstrap() always requires its own block files * first, then -- only if PRO is already loaded -- calls gutenify_pro(), * which runs PRO's bootstrap and requires PRO's block files too (see * bootstrap() below). PRO versions older than * GUTENIFY_MOVED_BLOCKS_MIN_PRO_VERSION still carry their own copies * of Popup, Hover Card, Hover Card Normal/Hover, and WooCommerce * Product Images Slider under the identical class/function names, so * letting both plugins load their own copies fatals with "Cannot * redeclare class/function ...". * * Deferring to the old PRO's own (already-working, ungated) * registration of these blocks avoids the collision entirely -- PRO * being active is exactly the condition under which these blocks * should be active anyway. * * Relies on GUTENIFY_PRO_VERSION being defined by this point, same as * the version_compare() check in bootstrap() below -- both depend on * PRO's plugin file having already loaded, which is guaranteed by the * standard install flow (PRO's activation hook installs/activates * this plugin, so PRO's entry in `active_plugins` precedes this * plugin's). * * @param array $blocks * @return array */ public function exclude_blocks_still_bundled_in_old_pro($blocks) { $old_pro_still_has_these_blocks = defined('GUTENIFY_PRO_VERSION') && version_compare(GUTENIFY_PRO_VERSION, GUTENIFY_MOVED_BLOCKS_MIN_PRO_VERSION, '<'); if (!$old_pro_still_has_these_blocks) { return $blocks; } return array_diff( $blocks, array('popup', 'hover-card', 'hover-card-normal', 'hover-card-hover', 'wc-product-images-slider') ); } /** * Provide plugin constants merged with args. * * @param array $args * @return array */ public function add_plugin_constants($args) { return wp_parse_args($args, $this->get_constants()); } /** * Get all plugin constants as array. * * @return array */ public function get_constants() { $title = 'Gutenify'; return array( 'title' => $title, 'prefix' => 'gutenify', 'slug' => 'gutenify', 'authorWebSite' => 'https://gutenify.com', 'authorDemoWebSite' => 'https://demo.gutenify.com', 'authorWebSiteProPage' => 'https://gutenify.com/pricing', 'authorWebSiteSupport' => 'https://gutenify.com/product-support', 'plugin_main_slug' => 'gutenify', 'plugin_main_camel_case_name' => 'gutenify', 'plugin_main_function_prefix' => 'gutenify', 'plugin_main_base_url' => GUTENIFY_BASE_URL, 'plugin_main_base_dir' => GUTENIFY_BASE_DIR, 'plugin_main_version' => GUTENIFY_VERSION, 'plugin_main_post_type_prefix' => 'gutenify', 'plugin_main_site_domain' => 'gutenify.com', 'core_base_dir' => GUTENIFY_BASE_DIR . 'core/', 'core_base_url' => GUTENIFY_BASE_URL . 'core/', 'brand_color' => '#2196f3', 'pro_title' => $title . ' Pro', ); } /** * Load bootstrap and pro if available. */ private function bootstrap() { require_once GUTENIFY_BASE_DIR . 'core/inc/bootstrap.php'; if ( function_exists('gutenify_pro') && defined('GUTENIFY_PRO_VERSION') && version_compare(GUTENIFY_PRO_VERSION, '1.1.5', '>') ) { gutenify_pro(); } } /** * Optionally redirect to Gutenify page on plugin activation. * * @param string $plugin Plugin basename. */ public function activation_redirect($plugin) { if (function_exists('get_current_screen')) { $screen = get_current_screen(); if (!empty($screen->id) && 'appearance_page_tgmpa-install-plugins' === $screen->id) { return false; } } if ($plugin === plugin_basename(__FILE__)) { wp_safe_redirect(admin_url('admin.php?page=gutenify')); exit; } } } } /** * Initialize the Gutenify plugin. */ function gutenify() { return Gutenify::instance(); } // Initialize plugin immediately. gutenify();