plugin.php
8.08 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
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
<?php
/**
* Plugin Name: Easy Accordion Gutenberg Block
* Description: A custom Gutenberg Block developed with Gutenberg Native Components.
* Requires at least: 6.0
* Requires PHP: 7.0
* Version: 1.2.5
* Author: Zakaria Binsaifullah
* Author URI: https://makegutenblock.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: easy-accordion-block
*/
/**
* @package Zero Configuration with @wordpress/create-block
* [esab] && [ESAB] ===> Prefix
*/
// Stop Direct Access
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// require admin page
require_once plugin_dir_path( __FILE__ ) . 'admin/class-esab-blocks.php';
/**
* Blocks Final Class
*/
final class ESAB_BLOCKS_CLASS {
public function __construct() {
// define constants
$this->esab_define_constants();
// block initialization
add_action( 'init', [ $this, 'esab_blocks_init' ] );
// blocks category
if( version_compare( $GLOBALS['wp_version'], '5.7', '<' ) ) {
add_filter( 'block_categories', [ $this, 'esab_register_block_category' ], 10, 2 );
} else {
add_filter( 'block_categories_all', [ $this, 'esab_register_block_category' ], 10, 2 );
}
// enqueue block assets
add_action( 'enqueue_block_assets', [ $this, 'esab_external_libraries' ] );
// redirect to admin page after activation
add_action( 'activated_plugin', [ $this, 'esab_redirect_to_admin_page' ] );
}
/**
* Redirect to admin page after activation
*/
public function esab_redirect_to_admin_page( $plugin ) {
if( $plugin == plugin_basename( __FILE__ ) ) {
exit( wp_redirect( admin_url( 'options-general.php?page=esab-accordion' ) ) );
}
}
/**
* Initialize the plugin
*/
public static function init(){
static $instance = false;
if( ! $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Define the plugin constants
*/
private function esab_define_constants() {
define( 'ESAB_VERSION', '1.2.5' );
define( 'ESAB_URL', plugin_dir_url( __FILE__ ) );
define( 'ESAB_LIB_URL', ESAB_URL . 'includes/' );
}
/**
* Blocks Registration
*/
public function esab_register_block( $name, $options = array() ) {
register_block_type( __DIR__ . '/build/blocks/' . $name, $options );
}
/**
* Render Inline CSS
*/
public function esab_render_inline_css( $handle, $css ) {
// register inline style
wp_register_style( $handle, false );
// enqueue inline style
wp_enqueue_style( $handle );
wp_add_inline_style( $handle, $css );
}
/**
* Blocks Initialization
*/
public function esab_blocks_init() {
// register single block
$this->esab_register_block( 'accordion', array(
'render_callback' => [ $this, 'esab_render_accordion_block' ],
));
}
/**
* Render Callback function
*/
public function esab_render_accordion_block( $attributes, $content ) {
$handle = $attributes['uniqueId'];
$custom_css = '';
if(!empty($attributes['zindex'])){
$custom_css .= '.'.$attributes['uniqueId'].' { z-index: '.$attributes['zindex'].'; }';
}
// single accordion
if(!empty($attributes['accordionBorderRadius'])){
$custom_css .= '.'.$attributes['uniqueId'].' .wp-block-esab-accordion-child { border-radius: '.$attributes['accordionBorderRadius'].'px; }';
}
if(!empty($attributes['accordionActiveBorderColor'])){
$custom_css .= '.'.$attributes['uniqueId'].' .wp-block-esab-accordion-child.esab__active_accordion {
border-color: '.$attributes['accordionActiveBorderColor'].' !important;
}';
}
// HEADER
if(!empty($attributes['headerActiveBg'])){
$custom_css .= '.'.$attributes['uniqueId'].' .wp-block-esab-accordion-child.esab__active_accordion .esab__head {
background: '.$attributes['headerActiveBg'].' !important;
}';
}
if(!empty($attributes['headingActiveColor'])){
$custom_css .= '.'.$attributes['uniqueId'].' .wp-block-esab-accordion-child.esab__active_accordion .esab__heading_tag{
color: '.$attributes['headingActiveColor'].' !important;
}';
}
// Body
if(!empty($attributes['activeSeparatorColor'])){
$custom_css .= '.'.$attributes['uniqueId'].' .wp-block-esab-accordion-child.esab__active_accordion .esab__body{
border-color: '.$attributes['activeSeparatorColor'].' !important;
}';
}
if(!empty($attributes['bodyActiveBg'])){
$custom_css .= '.'.$attributes['uniqueId'].' .wp-block-esab-accordion-child.esab__active_accordion .esab__body{
background-color: '.$attributes['bodyActiveBg'].' !important;
}';
}
//icon
$inactiveIconColor = !empty($attributes['inactiveIconColor']) ? $attributes['inactiveIconColor'] : 'inherit';
$activeIconColor = !empty($attributes['activeIconColor']) ? $attributes['activeIconColor'] : 'inherit';
$custom_css .= '.'.$attributes['uniqueId'].' .esab__collapse svg { width: '.$attributes['iconSize'].'px; fill: '.$inactiveIconColor.'; }';
$custom_css .= '.'.$attributes['uniqueId'].' .esab__expand svg { width: '.$attributes['iconSize'].'px; fill: '.$activeIconColor.'; }';
$this->esab_render_inline_css( $handle, $custom_css );
return $content;
}
/**
* Register Block Category
*/
public function esab_register_block_category( $categories, $post ) {
return array_merge(
array(
array(
'slug' => 'esab-blocks',
'title' => __( 'Easy Accordion', 'easy-accordion-block' ),
),
),
$categories
);
}
/**
* Enqueue Block Assets
*/
public function esab_external_libraries() {
// Editor CSS
if( is_admin() ) {
wp_enqueue_style( 'esab-editor-css', ESAB_LIB_URL . 'css/editor.css', array(), ESAB_VERSION );
}
// enqueue JS
if( has_block('esab/accordion') ) {
wp_enqueue_script( 'esab-accordion-js', ESAB_LIB_URL . 'js/accordion.js', array( 'jquery' ), ESAB_VERSION, true );
}
}
}
/**
* Kickoff
*/
ESAB_BLOCKS_CLASS::init();
/**
* SDK Integration
*/
if ( ! function_exists( 'esab_plugin_easy_accordion_block' ) ) {
function esab_plugin_easy_accordion_block() {
// Include DCI SDK.
require_once dirname( __FILE__ ) . '/admin/dci/start.php';
wp_register_style('dci-sdk-easy_accordion_block', plugins_url('admin/dci/assets/css/dci.css', __FILE__), array(), '1.2.1', 'all');
wp_enqueue_style('dci-sdk-easy_accordion_block');
dci_dynamic_init( array(
'sdk_version' => '1.2.1',
'product_id' => 6,
'plugin_name' => 'Easy Accordion Block', // make simple, must not empty
'plugin_title' => 'Easy Accordion Block', // You can describe your plugin title here
'api_endpoint' => 'https://dashboard.codedivo.com/wp-json/dci/v1/data-insights',
'slug' => 'easy-accordion-block', // write 'no-need' if you don't want to use
'core_file' => false,
'plugin_deactivate_id' => false,
'menu' => array(
'slug' => 'esab-accordion',
),
'public_key' => 'pk_2zPuK3VzDOtZ2HEZuT9zBFUu8d2iQw3z',
'is_premium' => false,
'popup_notice' => false,
'deactivate_feedback' => false,
'delay_time' => [
'time' => 3 * DAY_IN_SECONDS,
],
'text_domain' => 'easy-accordion-block',
'plugin_msg' => '
<p>Thank you for using <strong>Easy Accordion Block</strong>! We hope you enjoy using it. If you love <strong>Easy Accordion Block</strong>, please consider leaving us a 5-star review on <a href="https://wordpress.org/support/plugin/easy-accordion-block/reviews/#new-post" target="_blank">WordPress</a> to help us spread the word. </p>
<We>Also, if you need any help, feel free to contact us via our <a href="https://gutenbergkits.com/contact/" target="_blank">support forum</a>. We are always here to help you. We collect some data to improve our product.</p>
',
) );
}
add_action( 'admin_init', 'esab_plugin_easy_accordion_block' );
}