-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwbcom-blocks.php
More file actions
224 lines (201 loc) · 6.09 KB
/
Copy pathwbcom-blocks.php
File metadata and controls
224 lines (201 loc) · 6.09 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
/**
* Wbcom Designs
*
* @package wbcom-blocks
* @author Wbcom Design
* @copyright 2023 Wbcom Design
* @license GPL-2.0-or-later
*
* @wordpress-plugin
* Plugin Name: Wbcom Designs Blocks
* Plugin URI: https://wbcomdesigns.com/
* Description: The Wbcom Designs Blocks Plugin
* Version: 1.0.0
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: Wbcom Design
* Author URI: https://wbcomdesigns.com/
* Text Domain: wbcom-blocks
* License: GPL v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
class WbcomBlocks {
/**
* Singleton instance of the WbcomBlocks class.
*
* This class is responsible for initializing and managing the Wbcom Designs Blocks plugin.
* It provides methods for setting up constants, loading translations, registering custom Gutenberg blocks,
* and adding a custom block category.
*
* @var array
*/
private static $instance = array();
/**
* Absolute path to this plugin directory.
*
* @var string
*/
private $path;
/**
* Absolute url to this plugin directory.
*
* @var string
*/
private $url;
/**
* Plugin basename.
*
* @var string
*/
private $basename;
/**
* Constructor for the WbcomBlocks class.
*
* Initializes the plugin by setting up constants, loading translations,
* registering custom Gutenberg blocks, and adding a custom block category.
*
* @return void
*/
protected function __construct() {
$this->path = plugin_dir_path( __FILE__ );
$this->url = plugin_dir_url( __FILE__ );
$this->basename = plugin_basename( __FILE__ );
$this->wbcom_blocks_init();
$this->include();
}
/**
* The method you use to get the WbcomBlocks's instance.
*/
public static function get_instance(): WbcomBlocks {
$cls = static::class;
if ( ! isset( self::$instance[ $cls ] ) ) {
self::$instance[ $cls ] = new static();
}
return self::$instance[ $cls ];
}
/**
* Initializes the plugin by setting up constants, loading translations,
* registering custom Gutenberg blocks, and adding a custom block category.
*
* This function hooks into several WordPress actions and filters:
* - 'plugins_loaded' to setup constants.
* - 'bp_init' to load translations.
* - 'init' to register custom Gutenberg blocks.
* - 'block_categories_all' to add a custom block category.
*
* @return void
*/
public function wbcom_blocks_init() {
add_action( 'plugins_loaded', array( $this, 'wbcom_blocks_setup_constants' ), 0 );
add_action( 'bp_init', array( $this, 'load_textdomain' ), 2 );
add_action( 'init', array( $this, 'wbcom_blocks_block_init' ) );
add_filter( 'block_categories_all', array( $this, 'wbcom_blocks_add_block_category' ), 10, 2 );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_wbcom_blocks_assets' ) );
}
/**
* Define constans
*/
public function wbcom_blocks_setup_constants() {
define( 'WBCOM_BLOCKS_FILE', __FILE__ );
define( 'WBCOM_BLOCKS_URL', $this->get_url() );
define( 'WBCOM_BLOCKS_PATH', $this->get_path() );
define( 'WBCOM_BLOCKS_TEMPLATE_PATH', $this->get_path() . '/templates/' );
}
/**
* Get plugin url
*/
public function get_url() {
return $this->url;
}
/**
* Get Plugin Path
*/
public function get_path() {
return $this->path;
}
/**
* Includes the necessary API class for BuddyPress birthday related functionality.
*
* This function is responsible for including the 'class-api-buddypress-birthday.php' file
* located in the 'includes/api' directory of the plugin. This file contains the necessary
* functionality for interacting with BuddyPress birthday data.
*
* @return void
*/
public function include() {
require_once $this->get_path() . '/includes/api/class-api-buddypress-birthday.php';
require_once $this->get_path() . '/includes/api/class-api-buddypress-members.php';
}
/**
* Load translation files
*/
public function load_textdomain() {
load_plugin_textdomain( 'wbcom-blocks', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Initializes and registers custom Gutenberg blocks.
*
* This function registers four custom Gutenberg blocks:
* - Flipbox
* - BuddyPress Birthday
* - BuddyPress Members
* - BuddyPress Activity Listing
* - Heading
*
* The blocks are located in the 'build' directory of the plugin.
*
* @return void
*/
public function wbcom_blocks_block_init() {
$blocks = array(
'buddypress-birthday',
'buddypress-members',
'buddypress-activity-listing',
'flipbox',
'heading',
);
foreach ( $blocks as $block ) {
register_block_type( __DIR__ . '/build/blocks/' . $block );
}
}
/**
* Adds a custom block category for the Wbcom Designs plugin.
*
* This function filters the existing block categories and adds a new category for the Wbcom Designs plugin.
* The new category is identified by the slug 'wbcom-designs' and has a title 'Wbcom Designs'.
*
* @param array $block_categories An array of existing block categories.
* @param WP_Block_Editor_Context $block_editor_context The context of the block editor.
*
* @return array The modified array of block categories.
*/
public function wbcom_blocks_add_block_category( $block_categories, $block_editor_context ) {
if ( ! ( $block_editor_context instanceof WP_Block_Editor_Context ) ) {
return $block_categories;
}
return array_merge(
$block_categories,
array(
array(
'slug' => 'wbcom-designs',
'title' => __( 'Wbcom Designs', 'wbcom-blocks' ),
'icon' => 'lightbulb', // Slug of a WordPress Dashicon or custom SVG
),
)
);
}
/**
* Enqueue Swiper.js and related assets for the BuddyPress Members Block.
*/
public function enqueue_wbcom_blocks_assets() {
// Enqueue Swiper CSS.
wp_enqueue_style( 'swiper', 'https://unpkg.com/swiper/swiper-bundle.min.css', array(), '11.1.12' );
// Enqueue Swiper JS.
wp_enqueue_script( 'swiper', 'https://unpkg.com/swiper/swiper-bundle.min.js', array(), '11.1.12', true );
}
}
function wbcom_blocks() {
return WbcomBlocks::get_instance();
}
wbcom_blocks();