PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 3.0.0
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v3.0.0
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
blockspare / admin / rest-request.php

rest-request.php in BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites 3.0.0, at admin/rest-request.php

143 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_action( 'rest_api_init', 'blockspare_register_rest_controller');
4
5 function blockspare_register_rest_controller(){
6 register_rest_route('blockspare-dashboard/v1', '/blocksettings', array(
7
8 //Endpoint to get settings
9 [
10 'methods' => \WP_REST_Server::READABLE,
11 'callback'=>function($request){
12 $aligncenter_size =get_option('blocksapre_general_settings_aligncenter_size',[]);
13 $alignwide_size =get_option('blocksapre_general_settings_alignwide_size',[]);
14 $tablet_breakpoint =get_option('blocksapre_general_settings_tablet_breakpoint',[]);
15 $mobile_breakpoint =get_option('blocksapre_general_settings_mobile_breakpoint',[]);
16 return rest_ensure_response([
17 'aligncenter_size'=>$aligncenter_size,
18 'alignwide_size'=>$alignwide_size,
19 'tablet_breakpoint'=>$tablet_breakpoint,
20 'mobile_breakpoint'=>$mobile_breakpoint,
21 ],200);
22 },
23 'permission_callback'=>function(){
24 return current_user_can('manage_options');
25 }
26 ],
27
28 ));
29
30 register_rest_route('blockspare-dashboard/v1', '/updateblocksettings',
31 array(
32 //Endpoint to Update settings
33 [
34 'methods'=>\WP_REST_Server::EDITABLE,
35 'callback'=>function($request){
36 $settings = $request->get_params('data');
37 update_option('blocksapre_general_settings_aligncenter_size',$settings['aligncenter_size']);
38 update_option('blocksapre_general_settings_alignwide_size',$settings['alignwide_size']);
39 update_option('blocksapre_general_settings_tablet_breakpoint',$settings['tablet_breakpoint']);
40 update_option('blocksapre_general_settings_mobile_breakpoint',$settings['mobile_breakpoint']);
41 return rest_ensure_response([
42 'success'=>'success'
43 ],201);
44
45 },
46 'permission_callback'=>function(){
47 return current_user_can('manage_options');
48 }
49 ]
50 ));
51 //color settings
52 register_rest_route('blockspare-dashboard/v1', '/getcolorsettings', array(
53
54 //Endpoint to get settings
55 [
56 'methods' => \WP_REST_Server::READABLE,
57 'callback'=>function($request){
58 $primary =get_option('blocksapre_general_color_primary',[]);
59 $secondary =get_option('blocksapre_general_color_secondary',[]);
60
61 return rest_ensure_response([
62 'primary'=>$primary,
63 'secondary'=>$secondary,
64
65 ],200);
66 },
67 'permission_callback'=>function(){
68 return current_user_can('manage_options');
69 }
70 ],
71
72 ));
73
74 //updatecolor settings
75 register_rest_route('blockspare-dashboard/v1', '/updatecolorsettings', array(
76
77 //Endpoint to get settings
78 [
79 'methods'=>\WP_REST_Server::EDITABLE,
80 'callback'=>function($request){
81 $settings = $request->get_params('data');
82 if($settings['name']=='primary'){
83 update_option('blocksapre_general_color_primary',$settings['primary']);
84 }
85 if($settings['name']=='secondary'){
86 update_option('blocksapre_general_color_secondary',$settings['secondary']);
87 }
88
89
90 return rest_ensure_response([
91 'success'=>'success'
92 ],201);
93
94 },
95 'permission_callback'=>function(){
96 return current_user_can('manage_options');
97 }
98 ]
99
100 ));
101
102
103 //Typo settings
104 register_rest_route('blockspare-dashboard/v1', '/gettyposettings', array(
105
106 //Endpoint to get settings
107 [
108 'methods' => \WP_REST_Server::READABLE,
109 'callback'=>function($request){
110 $primary =get_option('blocksapre_general_primary_font',[]);
111 return rest_ensure_response([
112 'primaryFonts'=>($primary)?$primary:['value'=>'','label'=>'Default','Weight'=>[],'google'=>false],
113
114 ],200);
115 },
116 'permission_callback'=>function(){
117 return current_user_can('manage_options');
118 }
119 ],
120
121 ));
122 //update typo settings
123 register_rest_route('blockspare-dashboard/v1', '/updatetypoettings', array(
124
125 //Endpoint to get settings
126 [
127 'methods'=>\WP_REST_Server::EDITABLE,
128 'callback'=>function($request){
129 $settings = $request->get_params('data');
130 update_option('blocksapre_general_primary_font',$settings['primaryFonts']);
131
132 return rest_ensure_response([
133 'primaryFonts'=>$settings,
134 ],201);
135
136 },
137 'permission_callback'=>function(){
138 return current_user_can('manage_options');
139 }
140 ]
141
142 ));
143 }