| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Admin\Options; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
use WPAdminify\Inc\Admin\AdminSettingsModel; |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
die; |
| 10 |
} // Cannot access directly. |
| 11 |
|
| 12 |
class Tweaks_WP_JSON_API extends AdminSettingsModel |
| 13 |
{ |
| 14 |
public function __construct() |
| 15 |
{ |
| 16 |
$this->tweaks_wp_json_api_settings(); |
| 17 |
} |
| 18 |
|
| 19 |
public function get_defaults() |
| 20 |
{ |
| 21 |
return [ |
| 22 |
'disable_rest_api' => false, |
| 23 |
'control_heartbeat_api' => false, |
| 24 |
'remove_api_head' => false, |
| 25 |
'remove_powered' => false, |
| 26 |
'remove_api_server' => false, |
| 27 |
'disable_all_api' => false, |
| 28 |
]; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
public function tweaks_json_api_fields(&$json_api_fields) |
| 33 |
{ |
| 34 |
|
| 35 |
$json_api_fields[] = array( |
| 36 |
'type' => 'subheading', |
| 37 |
'content' => Utils::adminfiy_help_urls( |
| 38 |
__('Cleanup your site from WP JSON API features.', 'adminify'), |
| 39 |
'https://wpadminify.com/kb/wp-adminify-tweaks/', |
| 40 |
'https://www.youtube.com/playlist?list=PLqpMw0NsHXV-EKj9Xm1DMGa6FGniHHly8', |
| 41 |
'https://www.facebook.com/groups/jeweltheme', |
| 42 |
'https://wpadminify.com/support/' |
| 43 |
) |
| 44 |
); |
| 45 |
|
| 46 |
$json_api_fields[] = array( |
| 47 |
'id' => 'disable_rest_api', |
| 48 |
'type' => 'switcher', |
| 49 |
'title' => __('Disable REST API', 'adminify'), |
| 50 |
'text_on' => __('Yes', 'adminify'), |
| 51 |
'text_off' => __('No', 'adminify'), |
| 52 |
'text_width' => 80, |
| 53 |
'default' => $this->get_default_field('disable_rest_api'), |
| 54 |
); |
| 55 |
|
| 56 |
$json_api_fields[] = array( |
| 57 |
'id' => 'control_heartbeat_api', |
| 58 |
'type' => 'switcher', |
| 59 |
'title' => __('Control Heartbeat API', 'adminify'), |
| 60 |
'text_on' => __('Yes', 'adminify'), |
| 61 |
'text_off' => __('No', 'adminify'), |
| 62 |
'text_width' => 80, |
| 63 |
'default' => $this->get_default_field('control_heartbeat_api'), |
| 64 |
); |
| 65 |
|
| 66 |
$json_api_fields[] = array( |
| 67 |
'id' => 'remove_api_head', |
| 68 |
'type' => 'switcher', |
| 69 |
'title' => __('Remove WP API Links and Scripts', 'adminify'), |
| 70 |
'subtitle' => __('Remove all WP JSON API links and scripts from head section', 'adminify'), |
| 71 |
'label' => __('This option does not disable WP API, just cleans head section from these links.', 'adminify'), |
| 72 |
'text_on' => __('Yes', 'adminify'), |
| 73 |
'text_off' => __('No', 'adminify'), |
| 74 |
'text_width' => 80, |
| 75 |
'default' => $this->get_default_field('remove_api_head'), |
| 76 |
); |
| 77 |
|
| 78 |
$json_api_fields[] = array( |
| 79 |
'id' => 'remove_api_server', |
| 80 |
'type' => 'switcher', |
| 81 |
'title' => __('Remove WP API Link from HTTP Headers', 'adminify'), |
| 82 |
'subtitle' => __('Remove "Link:<...>; rel=https://api.w.org/" from server response HTTP headers', 'adminify'), |
| 83 |
'label' => __('This option does not disable WP API, just cleans HTTP headers.', 'adminify'), |
| 84 |
'text_on' => __('Yes', 'adminify'), |
| 85 |
'text_off' => __('No', 'adminify'), |
| 86 |
'text_width' => 80, |
| 87 |
'default' => $this->get_default_field('remove_api_server'), |
| 88 |
); |
| 89 |
|
| 90 |
$json_api_fields[] = array( |
| 91 |
'id' => 'disable_all_api', |
| 92 |
'type' => 'switcher', |
| 93 |
'title' => __('Totally Disable WP API Feature', 'adminify'), |
| 94 |
'subtitle' => __('Disable WP JSON API functionality on your site', 'adminify'), |
| 95 |
'label' => __('WordPress API is used by external apps to get data from your site. If you are not using this feature you can disable this.', 'adminify'), |
| 96 |
'text_on' => __('Yes', 'adminify'), |
| 97 |
'text_off' => __('No', 'adminify'), |
| 98 |
'text_width' => 80, |
| 99 |
'default' => $this->get_default_field('disable_all_api'), |
| 100 |
); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
public function tweaks_wp_json_api_settings() |
| 105 |
{ |
| 106 |
|
| 107 |
if (!class_exists('ADMINIFY')) { |
| 108 |
return; |
| 109 |
} |
| 110 |
|
| 111 |
$json_api_fields = []; |
| 112 |
$this->tweaks_json_api_fields($json_api_fields); |
| 113 |
|
| 114 |
\ADMINIFY::createSection( |
| 115 |
$this->prefix, |
| 116 |
array( |
| 117 |
'title' => __('WP JSON API', 'adminify'), |
| 118 |
'parent' => 'tweaks_performance', |
| 119 |
'icon' => 'fas fa-file-code', |
| 120 |
'fields' => $json_api_fields |
| 121 |
) |
| 122 |
); |
| 123 |
} |
| 124 |
} |
| 125 |
|