agm_define_constants(); // block initialization add_action('init', [$this, 'agm_blocks_init']); // blocks category if (version_compare($GLOBALS['wp_version'], '5.7', '<')) { add_filter('block_categories', [$this, 'agm_register_block_category'], 10, 2); } else { add_filter('block_categories_all', [$this, 'agm_register_block_category'], 10, 2); } // enqueue block assets // add_action('enqueue_block_assets', [$this, 'agm_external_libraries']); } /** * Initialize the plugin */ public static function init() { static $instance = false; if (!$instance) { $instance = new self(); } return $instance; } /** * Define the plugin constants */ private function agm_define_constants() { define('AGM_VERSION', '1.0.0'); define('AGM_URL', plugin_dir_url(__FILE__)); define('AGM_INC_URL', AGM_URL . 'includes/'); } /** * Blocks Registration */ public function agm_register_block($name, $options = array()) { register_block_type(__DIR__ . '/build/blocks/' . $name, $options); } /** * Blocks Initialization */ public function agm_blocks_init() { // register single block // $this->agm_register_block('gmap'); $this->agm_register_block('google-map'); } /** * Register Block Category */ public function agm_register_block_category($categories, $post) { return array_merge( array( array( 'slug' => 'advanced-google-map-block', 'title' => __('Advanced google map block', 'advanced-google-map-block'), ), ), $categories, ); } /** * Enqueue Block Assets */ public function agm_external_libraries() { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; // enqueue JS wp_register_script('gmap-api', '//maps.googleapis.com/maps/api/js?sensor=true', ['jquery'], null, true); wp_enqueue_script('gmap-js', AGM_INC_URL . 'js/gmaps' . $suffix . '.js', null, AGM_VERSION, true); wp_enqueue_script('agm-lib', AGM_INC_URL . 'js/plugin.js', null, AGM_VERSION, true); } } /** * Kickoff */ AdvancedGoogleMap::init();