| 1 |
<?php |
| 2 |
|
| 3 |
namespace FlyWP\Admin; |
| 4 |
|
| 5 |
use FlyWP\Admin; |
| 6 |
use FlyWP\Optimizations as OptimizationsBase; |
| 7 |
use WeDevs\WpUtils\HookTrait; |
| 8 |
|
| 9 |
class Optimizations { |
| 10 |
|
| 11 |
use HookTrait; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class constructor |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
$this->add_action( 'flywp_admin_tab_content', 'tab_content' ); |
| 18 |
$this->add_action( 'load-' . Admin::SCREEN_NAME, 'save_settings' ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Save settings. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function save_settings() { |
| 27 |
if ( ! isset( $_POST['flywp-optimizations-nonce'] ) ) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
if ( ! wp_verify_nonce( $_POST['flywp-optimizations-nonce'], 'flywp-optimizations-settings' ) ) { |
| 32 |
wp_die( 'Error: Invalid nonce specified in request', 'Invalid Request', 403 ); |
| 33 |
} |
| 34 |
|
| 35 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 36 |
wp_die( 'Error: You are not allowed to perform this action.', 'Unauthorized Access', 403 ); |
| 37 |
} |
| 38 |
|
| 39 |
$options = [ |
| 40 |
'enabled' => isset( $_POST['enabled'] ) ? true : false, |
| 41 |
]; |
| 42 |
|
| 43 |
foreach ( self::options() as $group => $data ) { |
| 44 |
foreach ( $data['fields'] as $field => $field_data ) { |
| 45 |
$options[ $group ][ $field ] = isset( $_POST[ $group ][ $field ] ) ? true : false; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
update_option( OptimizationsBase::OPTION_KEY, $options ); |
| 50 |
|
| 51 |
wp_safe_redirect( add_query_arg( [ |
| 52 |
'tab' => 'optimizations', |
| 53 |
'message' => 'optimizations-settings-saved', |
| 54 |
], flywp()->admin->page_url() ) ); |
| 55 |
exit; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get optimization options. |
| 60 |
* |
| 61 |
* @return array |
| 62 |
*/ |
| 63 |
public static function options() { |
| 64 |
$options = [ |
| 65 |
'general' => [ |
| 66 |
'title' => __( 'General', 'flywp' ), |
| 67 |
'description' => __( 'General optimizations.', 'flywp' ), |
| 68 |
'fields' => [ |
| 69 |
'emoji' => [ |
| 70 |
'label' => __( 'Disable Emojis', 'flywp' ), |
| 71 |
'description' => __( 'Remove extra JavaScript that adds support for emojis in older browsers. Native emoji\'s will still work.', 'flywp' ), |
| 72 |
], |
| 73 |
'oembed' => [ |
| 74 |
'label' => __( 'Disable Embeds', 'flywp' ), |
| 75 |
'description' => __( 'Prevent others from embedding your site.', 'flywp' ), |
| 76 |
], |
| 77 |
'self_ping' => [ |
| 78 |
'label' => __( 'Disable Self Pingbacks', 'flywp' ), |
| 79 |
'description' => __( 'Disable self pingbacks from your own site.', 'flywp' ), |
| 80 |
], |
| 81 |
'comments' => [ |
| 82 |
'label' => __( 'Disable Comments', 'flywp' ), |
| 83 |
'description' => __( 'Disable comments from the site.', 'flywp' ), |
| 84 |
], |
| 85 |
'jquery_migrate' => [ |
| 86 |
'label' => __( 'Disable jQuery Migrate', 'flywp' ), |
| 87 |
'description' => __( 'Disable jQuery Migrate from the site frontend and admin panel.', 'flywp' ), |
| 88 |
], |
| 89 |
'clean_nav_menu' => [ |
| 90 |
'label' => __( 'Clean Navigation Menu', 'flywp' ), |
| 91 |
'description' => __( 'Remove unnecessary classes from the navigation menu.', 'flywp' ), |
| 92 |
], |
| 93 |
'rss_feed' => [ |
| 94 |
'label' => __( 'Disable RSS Feed', 'flywp' ), |
| 95 |
'description' => __( 'Disable the RSS and Atom feeds from the site.', 'flywp' ), |
| 96 |
], |
| 97 |
'xmlrpc' => [ |
| 98 |
'label' => __( 'Disable XML-RPC', 'flywp' ), |
| 99 |
'description' => __( 'Disable XML-RPC from the site.', 'flywp' ), |
| 100 |
], |
| 101 |
], |
| 102 |
], |
| 103 |
'admin' => [ |
| 104 |
'title' => __( 'Admin', 'flywp' ), |
| 105 |
'description' => __( 'Customize the WordPress admin area.', 'flywp' ), |
| 106 |
'fields' => [ |
| 107 |
'wp_logo' => [ |
| 108 |
'label' => __( 'Remove WordPress Logo', 'flywp' ), |
| 109 |
'description' => __( 'Remove the WordPress logo from the admin bar.', 'flywp' ), |
| 110 |
], |
| 111 |
'login_logo' => [ |
| 112 |
'label' => __( 'Show Login Logo', 'flywp' ), |
| 113 |
'description' => __( 'Show the site logo on the login page.', 'flywp' ), |
| 114 |
], |
| 115 |
'dashboard_widgets' => [ |
| 116 |
'label' => __( 'Remove Dashboard Widgets', 'flywp' ), |
| 117 |
'description' => __( 'Remove all default dashboard widgets from the WordPress admin.', 'flywp' ), |
| 118 |
], |
| 119 |
], |
| 120 |
], |
| 121 |
'header' => [ |
| 122 |
'title' => __( 'Site Header', 'flywp' ), |
| 123 |
'description' => __( 'Customize the site header.', 'flywp' ), |
| 124 |
'fields' => [ |
| 125 |
'feed_links' => [ |
| 126 |
'label' => __( 'Remove Feed Links', 'flywp' ), |
| 127 |
'description' => __( 'Remove the RSS and Atom feed links from the site header.', 'flywp' ), |
| 128 |
], |
| 129 |
'rsd_link' => [ |
| 130 |
'label' => __( 'Remove RSD Link', 'flywp' ), |
| 131 |
'description' => __( 'Remove the RSD link from the site header.', 'flywp' ), |
| 132 |
], |
| 133 |
'generator' => [ |
| 134 |
'label' => __( 'Remove WP Version Number', 'flywp' ), |
| 135 |
'description' => __( 'Remove the WordPress version from the site header. It helps improving the site security by not exposing your current WordPress version number.', 'flywp' ), |
| 136 |
], |
| 137 |
'rest_api' => [ |
| 138 |
'label' => __( 'Remove REST API Links', 'flywp' ), |
| 139 |
'description' => __( 'Remove the REST API links from the site header.', 'flywp' ), |
| 140 |
], |
| 141 |
'shortlink' => [ |
| 142 |
'label' => __( 'Remove Shortlink', 'flywp' ), |
| 143 |
'description' => __( 'Remove the shortlink tag from the site header.', 'flywp' ), |
| 144 |
], |
| 145 |
'oembed' => [ |
| 146 |
'label' => __( 'Remove oEmbed Discovery Links', 'flywp' ), |
| 147 |
'description' => __( 'Remove the oEmbed discovery links from the site header.', 'flywp' ), |
| 148 |
], |
| 149 |
], |
| 150 |
], |
| 151 |
]; |
| 152 |
|
| 153 |
return $options; |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Tab content. |
| 158 |
* |
| 159 |
* @param string $current_tab current tab |
| 160 |
* |
| 161 |
* @return void |
| 162 |
*/ |
| 163 |
public function tab_content( $current_tab ) { |
| 164 |
if ( 'optimizations' !== $current_tab ) { |
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
require_once FLYWP_PLUGIN_DIR . '/views/optimizations.php'; |
| 169 |
} |
| 170 |
} |
| 171 |
|