-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
52 lines (48 loc) · 1.42 KB
/
functions.php
File metadata and controls
52 lines (48 loc) · 1.42 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
<?php
declare(strict_types = 1);
/**
* Headless
* Headless theme, for headless WordPress instances.
* @author Vecode
* @copyright Copyright (c) 2023 Vecode. All rights reserved.
*/
# Disable ReST API
add_filter( 'rest_authentication_errors', function($access) {
$disable = get_theme_mod('headless_disable_rest', true);
if ($disable) {
return new WP_Error('rest_disabled', __('The WordPress REST API has been disabled.'), [
'status' => rest_authorization_required_code()
]);
}
});
# Customizer
add_action( 'customize_register', function($wp_customize) {
$wp_customize->add_section( 'headless_options' , [
'title' => __('Options'),
'priority' => 30,
]);
$wp_customize->add_setting( 'headless_disable_rest' , [
'default' => true,
'transport' => 'refresh',
]);
$wp_customize->add_control('headless_disable_rest', [
'label' => __('ReST API'),
'section' => 'headless_options',
'settings' => 'headless_disable_rest',
'type' => 'radio',
'choices' => [
true => __('Disabled'),
false => __('Enabled'),
],
]);
$wp_customize->add_setting( 'headless_redirect_url' , [
'default' => null,
'transport' => 'refresh',
]);
$wp_customize->add_control('headless_redirect_url', [
'label' => __('Redirect URL'),
'section' => 'headless_options',
'settings' => 'headless_redirect_url',
'type' => 'url'
]);
});