-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
block-background.php
203 lines (186 loc) · 4.53 KB
/
block-background.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
<?php
/**
* Contributors: lubus, ajitbohra
* Plugin Name: Block Background
* Plugin URI: https://www.lubus.in
* Description: Extend gutenberg blocks with additional background options
* Author: LUBUS
* Author URI: https://lubus.in
* Version: 1.0.4
* Text Domain: blockbg
* Domain Path: /languages
* GitHub Plugin URI: https://github.com/lubusIN/block-background
* Tags: gutenberg, block, background, image, gradient
* Requires at least: 3.0.1
* Tested up to: 5.0.2
* Stable tag: 1.0.4
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package LubusIN_Block_Background
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'LubusIN_Block_Background' ) ) :
/**
* LubusIN_Block_Background Class.
*
* Main Class.
*
* @since 1.0.0
*/
class LubusIN_Block_Background {
/**
* Instance.
*
* @since
* @access private
* @var LubusIN_Block_Background
*/
static private $instance;
/**
* Singleton pattern.
*
* @since
* @access private
*/
private function __construct() {
$this->setup_constants();
$this->init_hooks();
}
/**
* Get instance.
*
* @since
* @access public
* @return LubusIN_Block_Background
*/
public static function get_instance() {
if ( null === static::$instance ) {
self::$instance = new static();
}
return self::$instance;
}
/**
* Hook into actions and filters.
*
* @since 1.0.0
*/
private function init_hooks() {
// Set up localization on init Hook.
add_action( 'init', array( $this, 'load_textdomain' ), 0 );
add_action( 'enqueue_block_editor_assets', array( $this, 'register_block_background' ) );
}
/**
* 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
* @access protected
*
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden.
blockbg_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'blockbg' ), '1.0' );
}
/**
* Disable unserializing of the class
*
* @since 1.0
* @access protected
*
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden.
blockbg_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'blockbg' ), '1.0' );
}
/**
* Setup plugin constants
*
* @since 1.0
* @access private
*
* @return void
*/
private function setup_constants() {
// Plugin version
if ( ! defined( 'BLOCKBG_VERSION' ) ) {
define( 'BLOCKBG_VERSION', '1.0.0' );
}
// Plugin Root File
if ( ! defined( 'BLOCKBG_PLUGIN_FILE' ) ) {
define( 'BLOCKBG_PLUGIN_FILE', __FILE__ );
}
// Plugin Folder Path
if ( ! defined( 'BLOCKBG_PLUGIN_DIR' ) ) {
define( 'BLOCKBG_PLUGIN_DIR', plugin_dir_path( BLOCKBG_PLUGIN_FILE ) );
}
// Plugin Folder URL
if ( ! defined( 'BLOCKBG_PLUGIN_URL' ) ) {
define( 'BLOCKBG_PLUGIN_URL', plugin_dir_url( BLOCKBG_PLUGIN_FILE ) );
}
// Plugin Basename aka: "block-background/block-background.php"
if ( ! defined( 'BLOCKBG_PLUGIN_BASENAME' ) ) {
define( 'BLOCKBG_PLUGIN_BASENAME', plugin_basename( BLOCKBG_PLUGIN_FILE ) );
}
}
/**
* Loads the plugin language files.
*
* @since 1.0.0
* @access public
*
* @return void
*/
public function load_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'blockbg' );
// wp-content/languages/plugin-name/plugin-name-en_EN.mo.
load_textdomain( 'blockbg', trailingslashit( WP_LANG_DIR ) . 'block-background' . '/' . 'block-background' . '-' . $locale . '.mo' );
// wp-content/plugins/plugin-name/languages/plugin-name-en_EN.mo.
load_plugin_textdomain( 'blockbg', false, basename( BLOCKBG_PLUGIN_DIR ) . '/languages/' );
}
/**
* Registers scripts
*
* @since 1.0.0
* @access public
*
* @return void
*/
public function register_block_background(){
$block_js = 'build/script.js';
$block_css = 'build/style.css';
// Script
wp_register_script(
'block-background-js',
BLOCKBG_PLUGIN_URL . $block_js,
array(
'wp-i18n',
'wp-blocks',
'wp-hooks',
'wp-element',
'wp-components',
'wp-editor',
),
filemtime( BLOCKBG_PLUGIN_DIR . $block_js )
);
// Common stlyes
wp_register_style(
'block-background',
BLOCKBG_PLUGIN_URL . $block_css,
array(),
filemtime(BLOCKBG_PLUGIN_DIR . $block_css)
);
wp_enqueue_style( 'block-background' );
wp_enqueue_script( 'block-background-js' );
}
}
endif;
LubusIN_Block_Background::get_instance();
?>