forked from godaddy-wordpress/block-gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-block-gallery.php
259 lines (239 loc) · 7.31 KB
/
class-block-gallery.php
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
/**
* Plugin Name: Block Gallery
* Plugin URI: https://wpblockgallery.com
* Description: The most advanced suite of gallery blocks for the Gutenberg block editor. Create stunning <strong>masonry</strong>, <strong>carousel</strong> and <strong>stacked</strong> galleries in seconds, with the brilliantly intuitive interface. Block Gallery is absolutely the best collection of native editor gallery blocks in the world.
* Author: Rich Tabor
* Author URI: https://richtabor.com
* Version: 1.1.6
* Text Domain: @@textdomain
* Domain Path: languages
* Tested up to: @@pkg.tested_up_to
*
* Block Gallery is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* Block Gallery is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with @@pkg.title. If not, see <http://www.gnu.org/licenses/>.
*
* @package @@pkg.title
* @author @@pkg.author
* @link @@pkg.author_uri
* @license @@pkg.license
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Block_Gallery' ) ) :
/**
* Main Block_Gallery Class.
*
* @since 1.0.0
*/
final class Block_Gallery {
/**
* This plugin's instance.
*
* @var Block_Gallery
* @since 1.0.0
*/
private static $instance;
/**
* Main Block_Gallery Instance.
*
* Insures that only one instance of Block_Gallery exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 1.0.0
* @static
* @uses Block_Gallery::constants() Setup the constants needed.
* @uses Block_Gallery::includes() Include the required files.
* @see WIDGETOPTS()
* @return object|Block_Gallery The one true Block_Gallery
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Block_Gallery ) ) {
self::$instance = new Block_Gallery();
self::$instance->init();
self::$instance->constants();
self::$instance->asset_suffix();
self::$instance->includes();
}
return self::$instance;
}
/**
* Throw error on object clone.
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @since 1.0.0
* @access protected
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheating huh?', '@@textdomain' ), '1.0' );
}
/**
* Disable unserializing of the class.
*
* @since 1.0.0
* @access protected
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheating huh?', '@@textdomain' ), '1.0' );
}
/**
* Setup plugin constants.
*
* @access private
* @since 1.0.0
* @return void
*/
private function constants() {
$this->define( 'BLOCKGALLERY_DEBUG', true );
$this->define( 'BLOCKGALLERY_VERSION', '@@pkg.version' );
$this->define( 'BLOCKGALLERY_HAS_PRO', false );
$this->define( 'BLOCKGALLERY_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
$this->define( 'BLOCKGALLERY_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
$this->define( 'BLOCKGALLERY_PLUGIN_FILE', __FILE__ );
$this->define( 'BLOCKGALLERY_PLUGIN_BASE', plugin_basename( __FILE__ ) );
$this->define( 'BLOCKGALLERY_SHOP_URL', 'https://wpblockgallery.com/' );
$this->define( 'BLOCKGALLERY_REVIEW_URL', 'https://wordpress.org/support/plugin/block-gallery/reviews/' );
}
/**
* Define constant if not already set.
*
* @param string|string $name Name of the definition.
* @param string|bool $value Default value.
*/
private function define( $name, $value ) {
if ( ! defined( $name ) ) {
define( $name, $value );
}
}
/**
* Include required files.
*
* @access private
* @since 1.0.0
* @return void
*/
private function includes() {
require_once BLOCKGALLERY_PLUGIN_DIR . 'includes/class-block-gallery-block-assets.php';
require_once BLOCKGALLERY_PLUGIN_DIR . 'includes/class-block-gallery-body-classes.php';
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
require_once BLOCKGALLERY_PLUGIN_DIR . 'includes/admin/class-block-gallery-url-generator.php';
require_once BLOCKGALLERY_PLUGIN_DIR . 'includes/admin/class-block-gallery-action-links.php';
require_once BLOCKGALLERY_PLUGIN_DIR . 'includes/admin/class-block-gallery-footer-text.php';
require_once BLOCKGALLERY_PLUGIN_DIR . 'includes/admin/class-block-gallery-feedback.php';
}
}
/**
* Load actions
*
* @return void
*/
private function init() {
add_action( 'init', array( $this, 'load_textdomain' ) );
}
/**
* Change the plugin's minified or src file name, based on debug mode.
*
* @since 1.0.0
*/
public function asset_suffix() {
if ( true === BLOCKGALLERY_DEBUG ) {
define( 'BLOCKGALLERY_ASSET_SUFFIX', null );
} else {
define( 'BLOCKGALLERY_ASSET_SUFFIX', '.min' );
}
}
/**
* If debug is on, serve unminified source assets.
*
* @since 1.0.0
* @param string|string $type The type of resource.
* @param string|string $directory Any extra directories needed.
*/
public function asset_source( $type = 'js', $directory = null ) {
if ( 'js' === $type ) {
if ( true === BLOCKGALLERY_DEBUG ) {
return BLOCKGALLERY_PLUGIN_URL . 'src/' . $type . '/' . $directory . '/';
} else {
return BLOCKGALLERY_PLUGIN_URL . 'dist/' . $type . '/' . $directory . '/';
}
} else {
return BLOCKGALLERY_PLUGIN_URL . 'dist/css/' . $directory;
}
}
/**
* Check if pro exists.
*
* @access public
*/
public function has_pro() {
if ( true === BLOCKGALLERY_HAS_PRO ) {
return true;
} else {
return false;
}
}
/**
* Check if pro is activated.
*
* @access public
*/
public function is_pro() {
if ( class_exists( 'Block_Gallery_Pro' ) ) {
return true;
} else {
return false;
}
}
/**
* Loads the plugin language files.
*
* @access public
* @since 1.0.0
* @return void
*/
public function load_textdomain() {
load_plugin_textdomain( '@@textdomain', false, dirname( plugin_basename( BLOCKGALLERY_PLUGIN_DIR ) ) . '/languages/' );
}
}
endif;
/**
* The main function for that returns Block_Gallery
*
* The main function responsible for returning the one true Block_Gallery
* Instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $blockgallery = Block_Gallery(); ?>
*
* @since 1.0.0
* @return object|Block_Gallery The one true Block_Gallery Instance.
*/
function block_gallery() {
return Block_Gallery::instance();
}
// Get the plugin running. Load on plugins_loaded action to avoid issue on multisite.
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
add_action( 'plugins_loaded', 'block_gallery', 90 );
} else {
block_gallery();
}