-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathaccordion-toggle.php
More file actions
203 lines (178 loc) · 6.55 KB
/
accordion-toggle.php
File metadata and controls
203 lines (178 loc) · 6.55 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
<?php
/**
* Plugin Name: Accordion Toggle
* Plugin URI: https://essential-blocks.com
* Description: Display Your FAQs & Improve User Experience with Accordion/Toggle block.
* Version: 1.2.7
* Author: WPDeveloper
* Author URI: https://wpdeveloper.net
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: accordion-toggle
*
* @package accordion-toggle
*/
/**
* Registers all block assets so that they can be enqueued through the block editor
* in the corresponding context.
*
* @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'ACCORDION_BLOCK_VERSION', "1.2.7" );
define( 'ACCORDION_BLOCK_ADMIN_URL', plugin_dir_url( __FILE__ ) );
define( 'ACCORDION_BLOCK_ADMIN_PATH', dirname( __FILE__ ) );
class EBAccordionToggle {
protected static $_instance = null;
public static function get_instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
private function __construct() {
// enqueue script and
add_action( 'enqueue_block_editor_assets', [$this, 'enqueue_block_assets'], 100 );
add_action( 'enqueue_block_editor_assets', [$this, 'frontend_backend_assets'], 100 );
add_action( 'wp_enqueue_scripts', [$this, 'frontend_backend_assets'], 100 );
// Load All Block Files
$this->load_block_dependencies();
}
public function enqueue_block_assets() {
global $pagenow;
/**
* Scripts
*/
$controls_dependencies = include_once ACCORDION_BLOCK_ADMIN_PATH . '/dist/controls.asset.php';
wp_register_script(
"eb-accordion-toggle-controls-util",
ACCORDION_BLOCK_ADMIN_URL . '/dist/controls.js',
$controls_dependencies['dependencies'],
$controls_dependencies['version'],
true
);
wp_localize_script( 'eb-accordion-toggle-controls-util', 'EssentialBlocksLocalize', [
'eb_wp_version' => (float) get_bloginfo( 'version' ),
'rest_rootURL' => get_rest_url()
] );
if ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) {
wp_localize_script( 'eb-accordion-toggle-controls-util', 'eb_conditional_localize', [
'editor_type' => 'edit-post'
] );
} else if ( $pagenow == 'site-editor.php' || $pagenow == 'themes.php' ) {
wp_localize_script( 'eb-accordion-toggle-controls-util', 'eb_conditional_localize', [
'editor_type' => 'edit-site'
] );
}
wp_enqueue_style(
'accordion-toggle-editor-css',
ACCORDION_BLOCK_ADMIN_URL . '/dist/controls.css',
[
'fontpicker-material-theme',
'fontpicker-default-theme',
'eb-fontawesome-admin'
],
ACCORDION_BLOCK_VERSION,
'all'
);
$script_asset_path = ACCORDION_BLOCK_ADMIN_PATH . "/dist/index.asset.php";
$script_asset = require $script_asset_path;
$all_dependencies = array_merge( $script_asset['dependencies'], [
'wp-blocks',
'wp-i18n',
'wp-element',
'wp-block-editor',
'eb-accordion-toggle-controls-util',
'essential-blocks-eb-animation'
] );
wp_enqueue_script(
'eb-accordion-toggle-editor',
ACCORDION_BLOCK_ADMIN_URL . '/dist/index.js',
$all_dependencies,
ACCORDION_BLOCK_VERSION,
true
);
}
public function frontend_backend_assets() {
/**
* Enqueue resources for Animation ||Start||
*/
//Animate JS
wp_enqueue_script(
'essential-blocks-eb-animation',
ACCORDION_BLOCK_ADMIN_URL . 'assets/js/eb-animation-load.js',
[],
ACCORDION_BLOCK_VERSION,
true
);
//Animate CSS
wp_enqueue_style(
'essential-blocks-animation',
ACCORDION_BLOCK_ADMIN_URL . 'assets/css/animate.min.css',
[],
ACCORDION_BLOCK_VERSION,
'all'
);
/**
* Enqueue resources for Animation ||End||
*/
//Blocks Common Style from Dist
wp_register_style(
'eb-accordion-toggle-frontend-style',
ACCORDION_BLOCK_ADMIN_URL . 'dist/style.css',
[],
ACCORDION_BLOCK_VERSION,
'all'
);
wp_register_style(
'eb-fontawesome-admin',
ACCORDION_BLOCK_ADMIN_URL . 'assets/css/font-awesome5.css',
[],
ACCORDION_BLOCK_VERSION,
'all'
);
wp_register_style(
'fontpicker-default-theme',
ACCORDION_BLOCK_ADMIN_URL . 'assets/css/fonticonpicker.base-theme.react.css',
[],
ACCORDION_BLOCK_VERSION,
'all'
);
wp_register_style(
'fontpicker-material-theme',
ACCORDION_BLOCK_ADMIN_URL . 'assets/css/fonticonpicker.material-theme.react.css',
[],
ACCORDION_BLOCK_VERSION,
'all'
);
wp_register_style(
'essential-blocks-hover-css',
ACCORDION_BLOCK_ADMIN_URL . 'assets/css/hover-min.css',
[],
ACCORDION_BLOCK_VERSION,
'all'
);
wp_register_style(
'hover-effects-style',
ACCORDION_BLOCK_ADMIN_URL . 'assets/css/hover-effects.css',
[],
ACCORDION_BLOCK_VERSION,
'all'
);
}
private function load_block_dependencies() {
require_once ACCORDION_BLOCK_ADMIN_PATH . '/includes/font-loader.php';
require_once ACCORDION_BLOCK_ADMIN_PATH . '/includes/post-meta.php';
require_once ACCORDION_BLOCK_ADMIN_PATH . '/lib/style-handler/style-handler.php';
require_once ACCORDION_BLOCK_ADMIN_PATH . '/includes/helpers.php';
require_once ACCORDION_BLOCK_ADMIN_PATH . '/includes/class-faq-schema.php';
if ( ! WP_Block_Type_Registry::get_instance()->is_registered( 'essential-blocks/accordion' ) ) {
require_once ACCORDION_BLOCK_ADMIN_PATH . '/blocks/accordion.php';
require_once ACCORDION_BLOCK_ADMIN_PATH . '/blocks/accordion-item.php';
}
}
}
EBAccordionToggle::get_instance();