| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Events Block |
| 4 |
* Description: Events Gutenberg Block to Create Events Grid In Block Editor. |
| 5 |
* Author: Cool Plugins |
| 6 |
* Author URI: https://coolplugins.net/ |
| 7 |
* Version: 1.0.2 |
| 8 |
* License: GPLv2 or later |
| 9 |
* Text Domain: events-block |
| 10 |
*/ |
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
define( 'EVENTS_BLOCK_VERSION', '1.0.2' ); |
| 13 |
define( 'EVENTS_BLOCK_FILE', __FILE__ ); |
| 14 |
define( 'EVENTS_BLOCK_PATH', plugin_dir_path( __FILE__ ) ); |
| 15 |
define( 'EVENTS_BLOCK_URL', plugin_dir_url( __FILE__ ) ); |
| 16 |
|
| 17 |
final class EVTB_Events_Block { |
| 18 |
private static $instance = null; |
| 19 |
public static function get_instance() { |
| 20 |
if ( ! isset( self::$instance ) ) self::$instance = new self(); |
| 21 |
return self::$instance; |
| 22 |
} |
| 23 |
private function __construct() { |
| 24 |
|
| 25 |
register_activation_hook( EVENTS_BLOCK_FILE, array( $this, 'evtb_plugin_activate' ) ); |
| 26 |
add_action( 'init', array( $this, 'init' ) ); |
| 27 |
add_action( 'enqueue_block_editor_assets', array( $this, 'editor_assets' ) ); |
| 28 |
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_assets' ) ); |
| 29 |
} |
| 30 |
/** |
| 31 |
* Plugin Activation Hook |
| 32 |
* Saves plugin version and install dates |
| 33 |
*/ |
| 34 |
public function evtb_plugin_activate() { |
| 35 |
|
| 36 |
update_option( 'evtb_version', EVENTS_BLOCK_VERSION ); |
| 37 |
update_option( 'evtb_activation_time', gmdate( 'Y-m-d h:i:s' ) ); |
| 38 |
|
| 39 |
if (!get_option( 'evtb_initial_save_version' ) ) { |
| 40 |
add_option( 'evtb_initial_save_version', EVENTS_BLOCK_VERSION ); |
| 41 |
} |
| 42 |
if(!get_option( 'evtb_install_date' ) ) { |
| 43 |
add_option( 'evtb_install_date', gmdate('Y-m-d h:i:s') ); |
| 44 |
} |
| 45 |
} |
| 46 |
public function init() { |
| 47 |
$asset = file_exists( EVENTS_BLOCK_PATH . 'build/index.asset.php' ) ? require EVENTS_BLOCK_PATH . 'build/index.asset.php' : array( 'dependencies' => array(), 'version' => EVENTS_BLOCK_VERSION ); |
| 48 |
wp_register_script( 'evtb-events-blocks', EVENTS_BLOCK_URL . 'build/index.js', $asset['dependencies'], $asset['version'], true ); |
| 49 |
wp_localize_script( 'evtb-events-blocks', 'evtbPluginData', array( 'pluginUrl' => EVENTS_BLOCK_URL, 'images' => array( 'crazyDJ' => EVENTS_BLOCK_URL . 'assets/images/crazy-DJ-experience-santa-cruz.webp', 'rockBand' => EVENTS_BLOCK_URL . 'assets/images/cute-girls-rock-band-performance.webp', 'foodDistribution' => EVENTS_BLOCK_URL . 'assets/images/free-food-distribution-at-mumbai.webp' ) ) ); |
| 50 |
wp_register_style( 'evtb-events-editor', EVENTS_BLOCK_URL . 'editor.css', array(), EVENTS_BLOCK_VERSION ); |
| 51 |
wp_register_style( 'evtb-events-style', EVENTS_BLOCK_URL . 'style.css', array(), EVENTS_BLOCK_VERSION ); |
| 52 |
$blocks_path = EVENTS_BLOCK_PATH . 'blocks/'; |
| 53 |
// Register each block explicitly to ensure the Block Directory recognizes them |
| 54 |
register_block_type( $blocks_path . 'events-grid' ); |
| 55 |
register_block_type( $blocks_path . 'event-item' ); |
| 56 |
register_block_type( $blocks_path . 'event-date-badge' ); |
| 57 |
} |
| 58 |
public function editor_assets() { |
| 59 |
wp_enqueue_style( 'evtb-icons', EVENTS_BLOCK_URL . 'assets/css/evtb-icons.css', array(), EVENTS_BLOCK_VERSION ); |
| 60 |
} |
| 61 |
public function frontend_assets() { |
| 62 |
wp_enqueue_style( 'evtb-icons', EVENTS_BLOCK_URL . 'assets/css/evtb-icons.css', array(), EVENTS_BLOCK_VERSION ); |
| 63 |
wp_enqueue_script( 'evtb-frontend', EVENTS_BLOCK_URL . 'assets/js/frontend.js', array(), EVENTS_BLOCK_VERSION, true ); |
| 64 |
} |
| 65 |
} |
| 66 |
EVTB_Events_Block::get_instance(); |
| 67 |
|
| 68 |
|