-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-modal-block.php
More file actions
142 lines (127 loc) · 4.69 KB
/
Copy pathcustom-modal-block.php
File metadata and controls
142 lines (127 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Plugin Name: AZ Custom Modular Modal
* Plugin URI: https://github.com/code-qtzl/azblocks-modular-modal
* Description: A custom Gutenberg block that creates a button with an optional modal window for ACF integration and customizable form content.
* Version: 1.0.0
* Author: Andres Zepeda
* Author URI: https://azepeda.dev
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: azblocks-modular-modal
* Domain Path: /languages
* Requires at least: 6.0
* Tested up to: 6.6
* Requires PHP: 7.4
*
* @package AZBlocks_Modular_Modal
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('AZBLOCKS_MODULAR_MODAL_VERSION', '1.0.0');
define('AZBLOCKS_MODULAR_MODAL_PLUGIN_FILE', __FILE__);
define('AZBLOCKS_MODULAR_MODAL_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('AZBLOCKS_MODULAR_MODAL_PLUGIN_URL', plugin_dir_url(__FILE__));
define('AZBLOCKS_MODULAR_MODAL_BUILD_DIR', AZBLOCKS_MODULAR_MODAL_PLUGIN_DIR . 'build/');
define('AZBLOCKS_MODULAR_MODAL_BUILD_URL', AZBLOCKS_MODULAR_MODAL_PLUGIN_URL . 'build/');
/**
* Registers the block using a `blocks-manifest.php` file, which improves the performance of block type registration.
* Behind the scenes, it also registers all assets so they can be enqueued
* through the block editor in the corresponding context.
*/
function azblocks_modular_modal_block_init() {
/**
* Registers the block(s) metadata from the `blocks-manifest.php` and registers the block type(s)
* based on the registered block metadata.
* Added in WordPress 6.8 to simplify the block metadata registration process added in WordPress 6.7.
*/
if ( function_exists( 'wp_register_block_types_from_metadata_collection' ) ) {
wp_register_block_types_from_metadata_collection( __DIR__ . '/build', __DIR__ . '/build/blocks-manifest.php' );
return;
}
/**
* Registers the block(s) metadata from the `blocks-manifest.php` file.
* Added to WordPress 6.7 to improve the performance of block type registration.
*/
if ( function_exists( 'wp_register_block_metadata_collection' ) ) {
wp_register_block_metadata_collection( __DIR__ . '/build', __DIR__ . '/build/blocks-manifest.php' );
}
/**
* Registers the block type(s) in the `blocks-manifest.php` file.
*/
$manifest_data = require __DIR__ . '/build/blocks-manifest.php';
foreach ( array_keys( $manifest_data ) as $block_type ) {
register_block_type( __DIR__ . "/build/{$block_type}" );
}
}
add_action( 'init', 'azblocks_modular_modal_block_init' );
/**
* Main plugin class
*/
class AZBlocks_Modular_Modal {
/**
* Initialize the plugin
*/
public function __construct() {
add_action('plugins_loaded', array($this, 'load_textdomain'));
// Include required files
$this->includes();
// Register activation and deactivation hooks
register_activation_hook(__FILE__, array($this, 'activate'));
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
}
/**
* Include required files
*/
private function includes() {
require_once AZBLOCKS_MODULAR_MODAL_PLUGIN_DIR . 'inc/acf-integration.php';
require_once AZBLOCKS_MODULAR_MODAL_PLUGIN_DIR . 'inc/assets.php';
}
/**
* Initialize ACF and Assets components
*/
public function init() {
// Initialize ACF integration and assets
new AZBlocks_Modular_Modal_ACF();
new AZBlocks_Modular_Modal_Assets();
}
/**
* Load plugin textdomain for translations
*/
public function load_textdomain() {
load_plugin_textdomain(
'azblocks-modular-modal',
false,
dirname(plugin_basename(__FILE__)) . '/languages/'
);
}
/**
* Plugin activation hook
*/
public function activate() {
// Check WordPress version
if (version_compare(get_bloginfo('version'), '6.0', '<')) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die(__('This plugin requires WordPress 6.0 or higher.', 'azblocks-modular-modal'));
}
// Check PHP version
if (version_compare(PHP_VERSION, '7.4', '<')) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die(__('This plugin requires PHP 7.4 or higher.', 'azblocks-modular-modal'));
}
// Flush rewrite rules
flush_rewrite_rules();
}
/**
* Plugin deactivation hook
*/
public function deactivate() {
// Flush rewrite rules
flush_rewrite_rules();
}
}
// Initialize the plugin
new AZBlocks_Modular_Modal();