-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color-palette-block.php
185 lines (169 loc) · 4.02 KB
/
color-palette-block.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
<?php
/**
* Contributors: lubus, ajitbohra
* Plugin Name: Color Palette Block
* Plugin URI: https://www.lubus.in
* Description: Add color palettes to your website
* Author: LUBUS
* Author URI: https://lubus.in
* Version: 1.1.0
* Text Domain: cpb
* Domain Path: /languages
* GitHub Plugin URI: https://github.com/lubusIN/color-palette-block
* Tags: gutenberg, block, animation
* Requires at least: 3.0.1
* Tested up to: 4.9.4
* Stable tag: 1.1.0
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package lubusIN_Color_Palette_Block
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'lubusIN_Color_Palette_Block' ) ) :
/**
* lubusIN_Color_Palette_Block Class.
*
* Main Class.
*
* @since 1.0.0
*/
class lubusIN_Color_Palette_Block {
/**
* Instance.
*
* @since
* @access private
* @var lubusIN_Color_Palette_Block
*/
static private $instance;
/**
* Singleton pattern.
*
* @since
* @access private
*/
private function __construct() {
$this->setup_constants();
$this->init_hooks();
}
/**
* Get instance.
*
* @since
* @access public
* @return lubusIN_Color_Palette_Block
*/
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( 'init', array( $this, 'register_color_palette' ) );
}
/**
* Setup plugin constants
*
* @since 1.0
* @access private
*
* @return void
*/
private function setup_constants() {
// Plugin version
if ( ! defined( 'CPB_VERSION' ) ) {
define( 'CPB_VERSION', '1.0.0' );
}
// Plugin Root File
if ( ! defined( 'CPB_PLUGIN_FILE' ) ) {
define( 'CPB_PLUGIN_FILE', __FILE__ );
}
// Plugin Folder Path
if ( ! defined( 'CPB_PLUGIN_DIR' ) ) {
define( 'CPB_PLUGIN_DIR', plugin_dir_path( CPB_PLUGIN_FILE ) );
}
// Plugin Folder URL
if ( ! defined( 'CPB_PLUGIN_URL' ) ) {
define( 'CPB_PLUGIN_URL', plugin_dir_url( CPB_PLUGIN_FILE ) );
}
// Plugin Basename aka: "color-palette-block/color-palette-block.php"
if ( ! defined( 'CPB_PLUGIN_BASENAME' ) ) {
define( 'CPB_PLUGIN_BASENAME', plugin_basename( CPB_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(), 'cpb' );
// wp-content/languages/plugin-name/plugin-name-en_EN.mo.
load_textdomain( 'cpb', trailingslashit( WP_LANG_DIR ) . 'color-palette-block' . '/' . 'cpb' . '-' . $locale . '.mo' );
// wp-content/plugins/plugin-name/languages/plugin-name-en_EN.mo.
load_plugin_textdomain( 'cpb', false, basename( CPB_PLUGIN_DIR ) . '/languages/' );
}
/**
* Registers scripts
*
* @since 1.0.0
* @access public
*
* @return void
*/
public function register_color_palette(){
$block_js = 'build/script.js';
$block_css = 'build/style.css';
$editor_css = 'build/editor.css';
// Script
wp_register_script(
'color-palette-block-js',
CPB_PLUGIN_URL . $block_js,
array(
'wp-blocks',
'wp-element',
'wp-components',
'wp-i18n',
),
filemtime( CPB_PLUGIN_DIR . $block_js )
);
// Common
wp_register_style(
'color-palette-block',
CPB_PLUGIN_URL . $block_css,
array(),
filemtime(CPB_PLUGIN_DIR . $block_css)
);
// Editor
wp_register_style(
'color-palette-block-editor',
CPB_PLUGIN_URL . $editor_css,
array(),
filemtime(CPB_PLUGIN_DIR . $editor_css)
);
// Register block type
register_block_type('lubus/color-palette-block', array(
'style' => 'color-palette-block',
'editor_style' => 'color-palette-block-editor',
'script' => 'color-palette-block-js',
));
}
}
endif;
lubusIN_Color_Palette_Block::get_instance();
?>