PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / addons / theme-builder / assets.php

assets.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at addons/theme-builder/assets.php

262 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocksThemeBuilder;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Helper as CoreHelper;
9 use ABlocks\Classes\FileUpload;
10 use ABlocks\Assets as CoreAssets;
11
12 class Assets {
13
14 public static function init() {
15 $self = new self();
16 add_filter( 'ablocks/assets/dashboard_scripts_data', array( $self, 'dashboard_scripts_data' ) );
17 add_action( 'wp_enqueue_scripts', [ $self, 'enqueue_frontend_assets' ], 99 );
18 }
19
20 public static function get_post_target_rule_options( $post_type, $taxonomy ) {
21 $post_key = str_replace( ' ', '-', strtolower( $post_type->label ) );
22 $post_label = ucwords( $post_type->label );
23 $post_name = $post_type->name;
24 $options = [];
25
26 $options[] = [
27 'value' => $post_name . '|all',
28 'label' => sprintf( __( 'All %s', 'ablocks' ), $post_label ),
29 ];
30
31 if ( 'pages' !== $post_key ) {
32 $options[] = [
33 'value' => $post_name . '|all|archive',
34 'label' => sprintf( __( 'All %s Archive', 'ablocks' ), $post_label ),
35 ];
36 }
37
38 if ( in_array( $post_type->name, $taxonomy->object_type ) ) {
39 $tax_label = ucwords( $taxonomy->label );
40 $tax_name = $taxonomy->name;
41
42 $options[] = [
43 'value' => $post_name . '|all|taxarchive|' . $tax_name,
44 'label' => sprintf( __( 'All %s Archive', 'ablocks' ), $tax_label ),
45 ];
46 }
47
48 return [
49 'label' => $post_label,
50 'options' => $options,
51 ];
52 }
53
54 public static function get_location_selections() {
55 $args = [
56 'public' => true,
57 '_builtin' => true
58 ];
59 $post_types = get_post_types( $args, 'objects' );
60 unset( $post_types['attachment'] );
61
62 $args['_builtin'] = false;
63 $custom_post_types = get_post_types( $args, 'objects' );
64 $post_types = apply_filters( 'ablocks_theme_builder/location_rule_post_types', array_merge( $post_types, $custom_post_types ) );
65
66 $groups = [];
67
68 // Basic group
69 $groups[] = [
70 'label' => __( 'Basic', 'ablocks' ),
71 'options' => [
72 [
73 'value' => 'basic-global',
74 'label' => __( 'Entire Website', 'ablocks' )
75 ],
76 [
77 'value' => 'basic-singulars',
78 'label' => __( 'All Singulars', 'ablocks' )
79 ],
80 [
81 'value' => 'basic-archives',
82 'label' => __( 'All Archives', 'ablocks' )
83 ],
84 ],
85 ];
86
87 // Special Pages group
88 $special_pages = [
89 [
90 'value' => 'special-404',
91 'label' => __( '404 Page', 'ablocks' )
92 ],
93 [
94 'value' => 'special-search',
95 'label' => __( 'Search Page', 'ablocks' )
96 ],
97 [
98 'value' => 'special-blog',
99 'label' => __( 'Blog / Posts Page', 'ablocks' )
100 ],
101 [
102 'value' => 'special-front',
103 'label' => __( 'Front Page', 'ablocks' )
104 ],
105 [
106 'value' => 'special-date',
107 'label' => __( 'Date Archive', 'ablocks' )
108 ],
109 [
110 'value' => 'special-author',
111 'label' => __( 'Author Archive', 'ablocks' )
112 ],
113 ];
114
115 if ( class_exists( 'WooCommerce' ) ) {
116 $special_pages[] = [
117 'value' => 'special-woo-shop',
118 'label' => __( 'WooCommerce Shop Page', 'ablocks' )
119 ];
120 }
121
122 $groups[] = [
123 'label' => __( 'Special Pages', 'ablocks' ),
124 'options' => $special_pages,
125 ];
126
127 // Custom post types and taxonomies
128 $taxonomies = get_taxonomies( [ 'public' => true ], 'objects' );
129 foreach ( $taxonomies as $taxonomy ) {
130 if ( 'post_format' === $taxonomy->name ) {
131 continue;
132 }
133
134 foreach ( $post_types as $post_type ) {
135 if ( $post_type === 'ablocks_tb' ) {
136 continue;
137 }
138 $group = self::get_post_target_rule_options( $post_type, $taxonomy );
139
140 // Avoid duplicate labels
141 $existing_group = array_filter( $groups, fn( $g) => $g['label'] === $group['label'] );
142 if ( ! empty( $existing_group ) ) {
143 foreach ( $groups as &$g ) {
144 if ( $g['label'] === $group['label'] ) {
145 $merged = array_merge( $g['options'], $group['options'] );
146
147 // Remove duplicate options by unique 'value' field (or 'label', depending on your use case)
148 $unique = [];
149 foreach ( $merged as $option ) {
150 $unique_key = $option['value']; // or use $option['label'] if needed
151 $unique[ $unique_key ] = $option;
152 }
153
154 $g['options'] = array_values( $unique );
155 }
156 }
157 } else {
158 $groups[] = $group;
159 }
160 }//end foreach
161 }//end foreach
162
163 // Specific Target group
164 $groups[] = [
165 'label' => __( 'Specific Target', 'ablocks' ),
166 'options' => [
167 [
168 'value' => 'specifics',
169 'label' => __( 'Specific Pages / Posts / Taxonomies, etc.', 'ablocks' )
170 ],
171 ],
172 ];
173
174 return apply_filters( 'ablocks/theme_builder/display_location_lists', $groups );
175 }
176
177 public static function get_user_selections() {
178 $groups = [];
179
180 // Basic group
181 $groups[] = [
182 'label' => __( 'Basic', 'ablocks' ),
183 'options' => [
184 [
185 'value' => 'all',
186 'label' => __( 'All', 'ablocks' )
187 ],
188 [
189 'value' => 'logged-in',
190 'label' => __( 'Logged In', 'ablocks' )
191 ],
192 [
193 'value' => 'logged-out',
194 'label' => __( 'Logged Out', 'ablocks' )
195 ],
196 ],
197 ];
198
199 // Advanced group
200 $roles = get_editable_roles();
201 $role_options = [];
202
203 foreach ( $roles as $slug => $data ) {
204 $role_options[] = [
205 'value' => $slug,
206 'label' => $data['name'],
207 ];
208 }
209
210 $groups[] = [
211 'label' => __( 'Advanced', 'ablocks' ),
212 'options' => $role_options,
213 ];
214
215 return apply_filters( 'ablocks/theme_builder/user_roles', $groups );
216 }
217
218 public function dashboard_scripts_data( $data ) {
219 $data['theme_builder'] = [
220 'locations' => $this->get_location_selections(),
221 'roles' => $this->get_user_selections(),
222 ];
223 return $data;
224 }
225
226 public function enqueue_frontend_assets() {
227 if ( ! CoreHelper::is_enabled_assets_generation() ) {
228 return;
229 }
230 if ( ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) ) {
231 return;
232 }
233
234 $template_types = [
235 'header',
236 'footer'
237 ];
238
239 $CoreAssets = new CoreAssets();
240 $FileUpload = new FileUpload();
241 foreach ( $template_types as $template_type ) {
242 $post_id = Helper::get_template_id( $template_type );
243 if ( $post_id ) {
244 $css_file_path = $FileUpload->get_file_path( $post_id . '.min.css' );
245 if ( file_exists( $css_file_path ) ) {
246 $css_file_url = $FileUpload->get_file_url( $post_id . '.min.css' );
247 // Enqueue google fonts
248 wp_enqueue_style( 'ablocks-frontend-google-fonts' );
249 // Combine CSS
250 wp_enqueue_style( 'ablocks-blocks-' . $template_type . '-' . $post_id . '-combine-style', $css_file_url, array(), filemtime( $css_file_path ), 'all' );
251 }
252 $js_file_path = $FileUpload->get_file_path( $post_id . '.min.js' );
253 if ( file_exists( $js_file_path ) ) {
254 $js_file_url = $FileUpload->get_file_url( $post_id . '.min.js' );
255 wp_enqueue_script( 'ablocks-blocks-' . $template_type . '-' . $post_id . '-combine-script', $js_file_url, array(), filemtime( $js_file_path ), true );
256 wp_localize_script( 'ablocks-blocks-' . $template_type . '-' . $post_id . '-combine-script', 'ABlocksGlobal', $CoreAssets->get_localize_script_data() );
257 }
258 }
259 }
260 }
261 }
262