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