| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Events Block |
| 5 |
* Description: Events Gutenberg Block to Create Events Grid In Block Editor. |
| 6 |
* Author: Cool Plugins |
| 7 |
* Author URI: https://coolplugins.net/ |
| 8 |
* Version: 1.0.7 |
| 9 |
* License: GPLv2 or later |
| 10 |
* Text Domain: events-block |
| 11 |
*/ |
| 12 |
defined('ABSPATH') || exit; |
| 13 |
define('EVENTS_BLOCK_VERSION', '1.0.7'); |
| 14 |
define('EVENTS_BLOCK_FILE', __FILE__); |
| 15 |
define('EVENTS_BLOCK_PATH', plugin_dir_path(__FILE__)); |
| 16 |
define('EVENTS_BLOCK_URL', plugin_dir_url(__FILE__)); |
| 17 |
define('EVENTS_BLOCK_FEEDBACK_API', 'https://feedback.coolplugins.net/'); |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
final class EVTB_Events_Block |
| 22 |
{ |
| 23 |
private static $instance = null; |
| 24 |
public static function get_instance() |
| 25 |
{ |
| 26 |
if (! isset(self::$instance)) self::$instance = new self(); |
| 27 |
return self::$instance; |
| 28 |
} |
| 29 |
private function __construct() |
| 30 |
{ |
| 31 |
|
| 32 |
register_activation_hook(EVENTS_BLOCK_FILE, array($this, 'evtb_plugin_activate')); |
| 33 |
add_action('init', array($this, 'init')); |
| 34 |
add_action('enqueue_block_editor_assets', array($this, 'editor_assets')); |
| 35 |
add_action('wp_enqueue_scripts', array($this, 'frontend_assets')); |
| 36 |
add_action('plugins_loaded', array($this, 'evtb_load_admin_files')); |
| 37 |
} |
| 38 |
/** |
| 39 |
* Plugin Activation Hook |
| 40 |
* Saves plugin version and install dates |
| 41 |
*/ |
| 42 |
public function evtb_plugin_activate() |
| 43 |
{ |
| 44 |
|
| 45 |
update_option('evtb_version', EVENTS_BLOCK_VERSION); |
| 46 |
update_option('evtb_activation_time', gmdate('Y-m-d h:i:s')); |
| 47 |
|
| 48 |
if (!get_option('evtb_initial_save_version')) { |
| 49 |
add_option('evtb_initial_save_version', EVENTS_BLOCK_VERSION); |
| 50 |
} |
| 51 |
if (!get_option('evtb_install_date')) { |
| 52 |
add_option('evtb_install_date', gmdate('Y-m-d h:i:s')); |
| 53 |
} |
| 54 |
if (!get_option('evtb_ratingDiv')) { |
| 55 |
add_option('evtb_ratingDiv', 'no'); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
public function init() |
| 60 |
{ |
| 61 |
$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); |
| 62 |
wp_register_script('evtb-events-blocks', EVENTS_BLOCK_URL . 'build/index.js', $asset['dependencies'], $asset['version'], true); |
| 63 |
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'))); |
| 64 |
wp_register_style('evtb-events-editor', EVENTS_BLOCK_URL . 'editor.css', array(), EVENTS_BLOCK_VERSION); |
| 65 |
wp_register_style('evtb-events-style', EVENTS_BLOCK_URL . 'style.css', array(), EVENTS_BLOCK_VERSION); |
| 66 |
if (is_dir(EVENTS_BLOCK_PATH . 'blocks/')) { |
| 67 |
foreach (glob(EVENTS_BLOCK_PATH . 'blocks/*/block.json') as $block) register_block_type(dirname($block)); |
| 68 |
} |
| 69 |
} |
| 70 |
public function editor_assets() |
| 71 |
{ |
| 72 |
wp_enqueue_style('evtb-icons', EVENTS_BLOCK_URL . 'assets/css/evtb-icons.css', array(), EVENTS_BLOCK_VERSION); |
| 73 |
} |
| 74 |
public function frontend_assets() |
| 75 |
{ |
| 76 |
wp_enqueue_style('evtb-icons', EVENTS_BLOCK_URL . 'assets/css/evtb-icons.css', array(), EVENTS_BLOCK_VERSION); |
| 77 |
wp_enqueue_script('evtb-frontend', EVENTS_BLOCK_URL . 'assets/js/frontend.js', array(), EVENTS_BLOCK_VERSION, true); |
| 78 |
} |
| 79 |
|
| 80 |
public function evtb_load_admin_files() { |
| 81 |
if (is_admin()) { |
| 82 |
require_once EVENTS_BLOCK_PATH . 'admin/feedback/admin-feedback-form.php'; |
| 83 |
require_once EVENTS_BLOCK_PATH . 'admin/feedback-notice/evtb-feedback-notice.php'; |
| 84 |
|
| 85 |
new evtbFeedbackNotice(); |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
EVTB_Events_Block::get_instance(); |
| 90 |
|