Skip to content

Commit ce9d062

Browse files
committed
Update to 1.3
1 parent 075996b commit ce9d062

259 files changed

Lines changed: 16324 additions & 5249 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ _Updates: 7 August 2023_
2020
* Update: Dynamic content link provided for context loop blocks
2121
* Update: Interaction builder background transitions implemented
2222
* Update: Hover colour added for the search close icon
23-
* Update: Text strings allowed in number inputs
23+
* Update: Text strings disallowed in number inputs
2424
* Update: Repeater functionality implemented
2525
* Fix: Issue with tags and categories links on the editor addressed
2626
* Fix: Styles on Gutenberg's responsive preview improved

core/admin/class-maxi-dashboard.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,9 @@ public function register_maxi_blocks_settings()
11341134
'maxi_rollback_version',
11351135
$args_rollback,
11361136
);
1137+
register_setting('maxi-blocks-settings-group', 'maxi_rollback_version', $args_rollback);
1138+
register_setting('maxi-blocks-settings-group', 'maxi_sc_gutenberg_blocks', $args);
1139+
register_setting('maxi-blocks-settings-group', 'maxi_show_indicators', $args);
11371140
}
11381141

11391142
public function get_folder_size($folder)

core/class-maxi-api.php

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,41 @@ public function mb_register_routes()
230230
return current_user_can('edit_posts');
231231
},
232232
]);
233+
register_rest_route($this->namespace, '/acf/get-field-groups', [
234+
'methods' => 'GET',
235+
'callback' => [$this, 'get_acf_field_groups'],
236+
'permission_callback' => function () {
237+
return current_user_can('edit_posts');
238+
},
239+
]);
240+
register_rest_route($this->namespace, '/acf/get-group-fields/(?P<id>\d+)', [
241+
'methods' => 'GET',
242+
'callback' => [$this, 'get_acf_group_fields'],
243+
'args' => [
244+
'id' => [
245+
'validate_callback' => function ($param) {
246+
return is_numeric($param);
247+
},
248+
],
249+
],
250+
'permission_callback' => function () {
251+
return current_user_can('edit_posts');
252+
},
253+
]);
254+
register_rest_route($this->namespace, '/acf/get-field-value/(?P<field_id>\w+)/(?P<post_id>\d+)', [
255+
'methods' => 'GET',
256+
'callback' => [$this, 'get_acf_field_value'],
257+
'args' => [
258+
'id' => [
259+
'validate_callback' => function ($param) {
260+
return is_numeric($param);
261+
},
262+
],
263+
],
264+
'permission_callback' => function () {
265+
return current_user_can('edit_posts');
266+
},
267+
]);
233268
register_rest_route($this->namespace, '/pro', [
234269
'methods' => 'GET',
235270
'callback' => [$this, 'get_maxi_blocks_pro_status'],
@@ -447,7 +482,6 @@ public function post_maxi_blocks_styles($data, $is_json = true)
447482
}
448483
}
449484

450-
451485
if ((bool) get_option('local_fonts')) {
452486
new MaxiBlocks_Local_Fonts();
453487
}
@@ -759,6 +793,57 @@ public function set_maxi_blocks_current_custom_data($data, $is_json = true)
759793
return $new_custom_data;
760794
}
761795

796+
public function get_acf_field_groups()
797+
{
798+
if (!class_exists('ACF')) {
799+
return [];
800+
}
801+
802+
$acf_field_groups = get_posts(array(
803+
'post_type' => 'acf-field-group',
804+
'posts_per_page' => -1,
805+
'post_status' => 'publish',
806+
));
807+
808+
$acf_field_groups = array_map(function ($acf_field_group) {
809+
return array(
810+
'id' => $acf_field_group->ID,
811+
'title' => $acf_field_group->post_title,
812+
);
813+
}, $acf_field_groups);
814+
815+
return json_encode($acf_field_groups);
816+
}
817+
818+
public function get_acf_group_fields($request)
819+
{
820+
if (!class_exists('ACF')) {
821+
return [];
822+
}
823+
824+
$group_id = $request['id'];
825+
$fields = acf_get_fields($group_id);
826+
827+
$fields = array_map(function ($field) {
828+
return array(
829+
'id' => $field['key'],
830+
'title' => $field['label'],
831+
'type' => $field['type'],
832+
);
833+
}, $fields);
834+
835+
return json_encode($fields);
836+
}
837+
838+
public function get_acf_field_value($request)
839+
{
840+
if (!class_exists('ACF')) {
841+
return null;
842+
}
843+
844+
return json_encode(get_field_object($request['field_id'], $request['post_id'])['value']);
845+
}
846+
762847
public function get_maxi_blocks_pro_status()
763848
{
764849
$pro = get_option('maxi_pro');

core/class-maxi-blocks.php

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-style-cards.php';
3+
24
/**
35
* MaxiBlocks Core Class
46
*
@@ -45,6 +47,14 @@ public function __construct()
4547

4648
// Register MaxiBlocks category
4749
add_filter('block_categories_all', [$this, 'maxi_block_category']);
50+
51+
$style_cards = new MaxiBlocks_StyleCards();
52+
$current_style_cards = $style_cards->get_maxi_blocks_active_style_card();
53+
54+
if($current_style_cards && array_key_exists('gutenberg_blocks_status', $current_style_cards) && $current_style_cards['gutenberg_blocks_status']) {
55+
add_filter("render_block", [$this, "maxi_add_sc_native_blocks"], 10, 3);
56+
}
57+
4858
}
4959

5060
public function enqueue_blocks_assets()
@@ -100,7 +110,7 @@ public function maxi_add_image_taxonomy()
100110
'add_new_item' => __('Add New Maxi Image', 'max-blocks'),
101111
'new_item_name' => __('New Maxi Image Name', 'max-blocks'),
102112
);
103-
113+
104114
$args = array(
105115
'labels' => $labels,
106116
'hierarchical' => false,
@@ -111,10 +121,10 @@ public function maxi_add_image_taxonomy()
111121
'show_ui' => false,
112122
'show_in_rest' => true
113123
);
114-
124+
115125
register_taxonomy('maxi-image-type', 'attachment', $args);
116126
}
117-
127+
118128
public function maxi_add_image_taxonomy_term()
119129
{
120130
if (!term_exists(__('Maxi Image', 'max-blocks'), 'maxi-image-type')) {
@@ -141,5 +151,41 @@ public function maxi_block_category($categories)
141151
$categories
142152
);
143153
}
154+
155+
public function maxi_add_sc_native_blocks($block_content, $block, $instance)
156+
{
157+
if (str_contains($block['blockName'], 'core/') && isset($block_content) && !empty($block_content)) {
158+
// We create a new DOMDocument object
159+
$dom = new DOMDocument();
160+
@$dom->loadHTML(mb_convert_encoding($block_content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
161+
162+
// Using XPath to find the elements we want to change
163+
$xpath = new DOMXPath($dom);
164+
165+
// Look for all elements
166+
$elements = $xpath->query('//*');
167+
168+
// Pick the first element
169+
$element = $elements[0];
170+
171+
$classes = $element->getAttribute('class');
172+
173+
if(!str_contains($classes, 'maxi') || !isset($classes) || empty($classes)) {
174+
if(!str_contains($classes, 'maxi-block--use-sc')) {
175+
$element->setAttribute('class', $element->getAttribute('class') . ' maxi-block--use-sc');
176+
}
177+
178+
if(!isset($classes) || empty($classes)) {
179+
$element->setAttribute('class', 'maxi-block--use-sc');
180+
}
181+
}
182+
183+
$block_content = $dom->saveHTML();
184+
185+
return $block_content;
186+
}
187+
188+
return $block_content;
189+
}
144190
}
145191
endif;

core/class-maxi-core.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,26 @@ public function __construct()
4646
// Add All Images - Maxi Images filter to the media library
4747
add_action('wp_enqueue_media', function () {
4848
if (term_exists('maxi-image', 'maxi-image-type')) {
49-
wp_enqueue_script('maxi-media-images-filter', plugin_dir_url(__DIR__) . 'js/mediaFilter.min.js', array( 'media-editor', 'media-views' ));
50-
wp_localize_script('maxi-media-images-filter', 'maxiImagesFilterTerms', array(
51-
'terms' => get_terms('maxi-image-type', array( 'hide_empty' => false )),
52-
));
49+
wp_enqueue_script(
50+
'maxi-media-images-filter',
51+
plugin_dir_url(__DIR__) . 'js/mediaFilter.min.js',
52+
array(
53+
'media-editor',
54+
'media-views'
55+
),
56+
);
57+
wp_localize_script(
58+
'maxi-media-images-filter',
59+
'maxiImagesFilterTerms',
60+
array(
61+
'terms' => get_terms(
62+
'maxi-image-type',
63+
array(
64+
'hide_empty' => false
65+
)
66+
),
67+
)
68+
);
5369
}
5470
});
5571
}
@@ -69,4 +85,4 @@ public function maxi_blocks_body_class($classes)
6985
return $classes;
7086
}
7187
}
72-
endif;
88+
endif;

0 commit comments

Comments
 (0)