@@ -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 ' );
0 commit comments