| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Classes; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
use WPAdminify\Inc\Admin\AdminSettings; |
| 7 |
use WPAdminify\Inc\Admin\AdminSettingsModel; |
| 8 |
|
| 9 |
// no direct access allowed |
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* @package WP Adminify |
| 16 |
* @author: Jewel Theme<support@jeweltheme.com> |
| 17 |
*/ |
| 18 |
|
| 19 |
class Tweaks extends AdminSettingsModel |
| 20 |
{ |
| 21 |
|
| 22 |
public $redirect_status = 301; |
| 23 |
|
| 24 |
public function __construct() |
| 25 |
{ |
| 26 |
$this->options = (array) AdminSettings::get_instance()->get(); |
| 27 |
$this->tweaks_init(); |
| 28 |
$this->jltwp_adminify_cleanup(); |
| 29 |
$this->http_response_cleanup(); |
| 30 |
$this->wp_json_api_cleanup(); |
| 31 |
$this->comments_cleanup(); |
| 32 |
$this->archives_cleanup(); |
| 33 |
$this->attachments_cleanup(); |
| 34 |
$this->performance_cleanup(); |
| 35 |
$this->remove_try_gutenberg_panel(); |
| 36 |
$this->jltwp_adminify_customize_admin_bar(); |
| 37 |
|
| 38 |
add_action('wp_dashboard_setup', [$this, 'remove_welcome_panel'], 999); |
| 39 |
} |
| 40 |
|
| 41 |
public function tweaks_init() |
| 42 |
{ |
| 43 |
/* Disable Self Pings */ |
| 44 |
if (!empty($this->options['self_ping'])) { |
| 45 |
add_action('pre_ping', [$this, 'jltwp_adminify_no_self_ping']); |
| 46 |
} |
| 47 |
|
| 48 |
/** Remove Dashicons from Admin Bar for non logged in users */ |
| 49 |
if (!empty($this->options['remove_dashicons'])) { |
| 50 |
add_action('wp_print_styles', [$this, 'jltwp_adminify_remove_dashicons'], 100); |
| 51 |
} |
| 52 |
|
| 53 |
/** Disable REST API */ |
| 54 |
// if (!empty($this->options['disable_rest_api'])) { |
| 55 |
// $this->disable_all_api(); |
| 56 |
|
| 57 |
// // Filters for WP-API version 1.x |
| 58 |
// add_filter('json_enabled', '__return_false'); |
| 59 |
// add_filter('json_jsonp_enabled', '__return_false'); |
| 60 |
|
| 61 |
// // Filters for WP-API version 2.x |
| 62 |
// // add_filter('rest_enabled', '__return_false'); |
| 63 |
// add_filter('rest_jsonp_enabled', '__return_false'); |
| 64 |
// } |
| 65 |
|
| 66 |
/** Control Interval Heartbeat API */ |
| 67 |
if (!empty($this->options['control_heartbeat_api'])) { |
| 68 |
add_filter('heartbeat_settings', [$this, 'jltwp_adminify_control_heartbeat']); |
| 69 |
} |
| 70 |
|
| 71 |
/** Remove Version Query Strings from Scripts/Styles */ |
| 72 |
if (!empty($this->options['remove_version_strings'])) { |
| 73 |
add_filter('script_loader_src', [$this, 'jltwp_adminify_remove_script_version'], 15, 1); |
| 74 |
add_filter('style_loader_src', [$this, 'jltwp_adminify_remove_script_version'], 15, 1); |
| 75 |
} |
| 76 |
|
| 77 |
/** Remove Version Query Strings from Scripts/Styles */ |
| 78 |
if (!empty($this->options['remove_canonical'])) { |
| 79 |
remove_action('embed_head', 'rel_canonical'); |
| 80 |
add_filter('wpseo_canonical', '__return_false'); |
| 81 |
} |
| 82 |
|
| 83 |
/** Remove Capital P Dangit */ |
| 84 |
if (!empty($this->options['remove_capital_p_dangit'])) { |
| 85 |
remove_filter('the_title', 'capital_P_dangit', 11); |
| 86 |
remove_filter('the_content', 'capital_P_dangit', 11); |
| 87 |
remove_filter('comment_text', 'capital_P_dangit', 31); |
| 88 |
} |
| 89 |
|
| 90 |
/** Disable PDF Thumbnails Preview */ |
| 91 |
if (!empty($this->options['disable_pdf_thumbnail'])) { |
| 92 |
add_filter('fallback_intermediate_image_sizes', [$this, 'jltwp_adminify_disable_pdf_previews']); |
| 93 |
} |
| 94 |
|
| 95 |
/** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer */ |
| 96 |
if (!empty($this->options['defer_parsing_js_footer'])) { |
| 97 |
add_filter('script_loader_tag', [$this, 'jltwp_adminify_defer_parsing_of_js'], 10, 2); |
| 98 |
} |
| 99 |
|
| 100 |
/* Remove Gravatar Query Strings */ |
| 101 |
if (!empty($this->options['gravatar_query_strings'])) { |
| 102 |
add_filter('get_avatar_url', [$this, 'jltwp_adminify_avatar_remove_querystring']); |
| 103 |
} |
| 104 |
|
| 105 |
// Add Custom Default Gravatar Image |
| 106 |
if (!empty($this->options['enable_custom_gravatar'])) { |
| 107 |
add_filter('avatar_defaults', [$this, 'jltwp_adminify_add_custom_gravatar']); |
| 108 |
} |
| 109 |
|
| 110 |
/* Add Featured Image or Post Thumbnail to RSS Feed */ |
| 111 |
if (!empty($this->options['thumbnails_rss_feed'])) { |
| 112 |
add_filter('the_excerpt_rss', [$this, 'jltwp_adminify_rss_post_thumbnail']); |
| 113 |
add_filter('the_content_feed', [$this, 'jltwp_adminify_rss_post_thumbnail']); |
| 114 |
} |
| 115 |
|
| 116 |
// tag and category hooks |
| 117 |
if (!empty($this->options['display_last_modified_date'])) { |
| 118 |
add_filter('the_content', [$this, 'jltwp_adminify_last_updated_date'], 10, 1); |
| 119 |
add_filter('wp_head', [$this, 'jltwp_adminify_last_updated_date_style']); |
| 120 |
} |
| 121 |
|
| 122 |
if (!empty($this->options['remove_image_link'])) { |
| 123 |
add_action('admin_init', [$this, 'jltwp_adminify_imagelink'], 10); |
| 124 |
} |
| 125 |
|
| 126 |
/** Browser Cache Expires & GZIP Compression */ |
| 127 |
if (!empty($this->options['cache_gzip_compression'])) { |
| 128 |
register_activation_hook(__FILE__, [$this, 'jltwp_adminify_htaccess']); |
| 129 |
} |
| 130 |
/** |
| 131 |
* We run the function that ckecks here |
| 132 |
* if there are $lineas content between: |
| 133 |
* # BEGIN WP Adminify by Jewel Theme |
| 134 |
* and... |
| 135 |
* # END WP Adminify by Jewel Theme |
| 136 |
* If exist and it's the same we don't do anything, |
| 137 |
* if has changed, we update it to the new one |
| 138 |
* if it doesn't exist we write it. |
| 139 |
*/ |
| 140 |
register_deactivation_hook(__FILE__, [$this, 'jltwp_adminify_delete_tweaks_htaccess']); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
// Remove Items from Admin bar |
| 145 |
public function jltwp_adminify_customize_admin_bar() |
| 146 |
{ |
| 147 |
// add_action('admin_bar_menu', [$this, 'remove_from_admin_bar'], 999); |
| 148 |
// add_action('admin_bar_menu', [$this, 'clear_node_title'], 999); |
| 149 |
add_filter('admin_bar_menu', [$this, 'jltma_adminify_change_howdy_text'], 25); |
| 150 |
} |
| 151 |
|
| 152 |
/* |
| 153 |
* Change Howdy Text |
| 154 |
*/ |
| 155 |
public function jltma_adminify_change_howdy_text($wp_admin_bar) |
| 156 |
{ |
| 157 |
$admin_bar_howdy_text = !empty($this->options['admin_bar_settings']['admin_bar_howdy_text']) ? $this->options['admin_bar_settings']['admin_bar_howdy_text'] : ''; |
| 158 |
if (!empty($admin_bar_howdy_text)) { |
| 159 |
$my_account = $wp_admin_bar->get_node('my-account'); |
| 160 |
$changed_howdy_text = str_replace('Howdy,', wp_kses_post($admin_bar_howdy_text), $my_account->title); |
| 161 |
$wp_admin_bar->add_node( |
| 162 |
[ |
| 163 |
'id' => 'my-account', |
| 164 |
'title' => wp_kses_post($changed_howdy_text), |
| 165 |
] |
| 166 |
); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
// Clear the node titles |
| 173 |
// This will only work if the node is using a :before element for the icon |
| 174 |
public function clear_node_title($wp_admin_bar) |
| 175 |
{ |
| 176 |
$all_toolbar_nodes = $wp_admin_bar->get_nodes(); |
| 177 |
// Create an array of node ID's we'd like to remove |
| 178 |
$clear_titles = [ |
| 179 |
'site-name', |
| 180 |
'customize', |
| 181 |
]; |
| 182 |
|
| 183 |
foreach ($all_toolbar_nodes as $node) { |
| 184 |
|
| 185 |
// Run an if check to see if a node is in the array to clear_titles |
| 186 |
if (in_array($node->id, $clear_titles)) { |
| 187 |
// use the same node's properties |
| 188 |
$args = $node; |
| 189 |
|
| 190 |
// make the node title a blank string |
| 191 |
$args->title = ''; |
| 192 |
|
| 193 |
// update the Toolbar node |
| 194 |
$wp_admin_bar->add_node($args); |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
// Remove items from the admin bar |
| 200 |
public function remove_from_admin_bar($wp_admin_bar) |
| 201 |
{ |
| 202 |
/* |
| 203 |
* Placing items in here will only remove them from admin bar |
| 204 |
* when viewing the fronte end of the site |
| 205 |
*/ |
| 206 |
if (!is_admin()) { |
| 207 |
// Example of removing item generated by plugin. Full ID is #wp-admin-bar-si_menu |
| 208 |
$wp_admin_bar->remove_node('si_menu'); |
| 209 |
|
| 210 |
// WordPress Core Items (uncomment to remove) |
| 211 |
$wp_admin_bar->remove_node('updates'); |
| 212 |
$wp_admin_bar->remove_node('comments'); |
| 213 |
$wp_admin_bar->remove_node('new-content'); |
| 214 |
// $wp_admin_bar->remove_node('wp-logo'); |
| 215 |
// $wp_admin_bar->remove_node('site-name'); |
| 216 |
// $wp_admin_bar->remove_node('my-account'); |
| 217 |
// $wp_admin_bar->remove_node('search'); |
| 218 |
// $wp_admin_bar->remove_node('customize'); |
| 219 |
} |
| 220 |
|
| 221 |
/* |
| 222 |
* Items placed outside the if statement will remove it from both the frontend |
| 223 |
* and backend of the site |
| 224 |
*/ |
| 225 |
$wp_admin_bar->remove_node('wp-logo'); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
/** |
| 230 |
* Remove Welcome Panel |
| 231 |
*/ |
| 232 |
public function remove_welcome_panel() |
| 233 |
{ |
| 234 |
if (!empty($this->options['remove_welcome_panel'])) { |
| 235 |
remove_action('welcome_panel', 'wp_welcome_panel'); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
/** |
| 241 |
* Remove "Try Gutenberg Panel" |
| 242 |
*/ |
| 243 |
public function remove_try_gutenberg_panel() |
| 244 |
{ |
| 245 |
if (!empty($this->options['remove_try_gutenberg_panel'])) { |
| 246 |
remove_action('try_gutenberg_panel', 'wp_try_gutenberg_panel'); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
// Custom Avatars |
| 252 |
public function jltwp_adminify_add_custom_gravatar($avatar_defaults) |
| 253 |
{ |
| 254 |
if (!empty($this->options['custom_gravatar_image'])) { |
| 255 |
foreach ($this->options['custom_gravatar_image'] as $key => $value) { |
| 256 |
$avatar_url = esc_url_raw($value['avatar_image']['url']); |
| 257 |
$avatar_defaults[$avatar_url] = $value['avatar_name']; |
| 258 |
} |
| 259 |
} |
| 260 |
return $avatar_defaults; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
// Cleanup Hooks |
| 265 |
public function jltwp_adminify_cleanup() |
| 266 |
{ |
| 267 |
|
| 268 |
// Hide Admin bar |
| 269 |
if (!empty($this->options['show_admin_bar'])) { |
| 270 |
add_filter('show_admin_bar', '__return_false'); |
| 271 |
} |
| 272 |
|
| 273 |
// Remove Admin Footer Version Number |
| 274 |
if (!empty($this->options['admin_footer_default_wp_version'])) { |
| 275 |
add_action('admin_menu', [$this, 'remove_admin_footer_version']); |
| 276 |
} |
| 277 |
|
| 278 |
// Remove WordPress Version Number |
| 279 |
if (!empty($this->options['generator_wp_version'])) { |
| 280 |
remove_action('wp_head', 'wp_generator'); // Remove WordPress Generator Version |
| 281 |
add_filter('the_generator', '__return_false'); // Remove Generator Name From Rss Feeds. |
| 282 |
} |
| 283 |
|
| 284 |
// Remove Revolution Slider generator version |
| 285 |
if (!empty($this->options['remove_revslider_generator'])) { |
| 286 |
add_filter('revslider_meta_generator', '__return_empty_string'); |
| 287 |
} |
| 288 |
|
| 289 |
// Remove woocommerce generator version |
| 290 |
if (!empty($this->options['remove_wc_generator'])) { |
| 291 |
remove_action('wp_head', 'wc_generator_tag'); |
| 292 |
} |
| 293 |
|
| 294 |
// Remove wpml meta generator tag |
| 295 |
if (!empty($this->options['remove_wpml_generator'])) { |
| 296 |
add_action('wp_head', [$this, '_remove_wpml_generator'], 0); |
| 297 |
} |
| 298 |
|
| 299 |
// Remove wpbakery visual_composer meta generator tag |
| 300 |
if (!empty($this->options['remove_visual_composer_generator'])) { |
| 301 |
add_action('wp_head', [$this, 'jltwp_adminify_remove_visual_composer_generator'], 1); |
| 302 |
} |
| 303 |
|
| 304 |
// Remove Yoast SEO meta generator tag |
| 305 |
if (!empty($this->options['remove_yoast_generator'])) { |
| 306 |
add_filter('wpseo_debug_markers', '__return_false'); |
| 307 |
} |
| 308 |
|
| 309 |
// Remove WordPress.org Dns-prefetch. |
| 310 |
if (!empty($this->options['remove_dns_prefetch'])) { |
| 311 |
remove_action('wp_head', 'wp_resource_hints', 2); |
| 312 |
} |
| 313 |
|
| 314 |
// REMOVE wlwmanifest.xml. |
| 315 |
if (!empty($this->options['remove_wlwmanifest'])) { |
| 316 |
remove_action('wp_head', 'wlwmanifest_link'); |
| 317 |
} |
| 318 |
|
| 319 |
// Remove Really Simple Discovery Link. |
| 320 |
if (!empty($this->options['remove_rsd'])) { |
| 321 |
remove_action('wp_head', 'rsd_link'); |
| 322 |
} |
| 323 |
|
| 324 |
// Remove Shortlink Url |
| 325 |
if (!empty($this->options['remove_shortlink'])) { |
| 326 |
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); |
| 327 |
remove_action('template_redirect', 'wp_shortlink_header', 11); |
| 328 |
} |
| 329 |
|
| 330 |
// Remove Emoji Styles and Scripts |
| 331 |
if (!empty($this->options['remove_emoji'])) { |
| 332 |
remove_action('wp_head', 'print_emoji_detection_script', 7); // Remove Emoji's Styles and Scripts. |
| 333 |
remove_action('embeded_head', 'print_emoji_detection_script'); |
| 334 |
remove_action('admin_print_scripts', 'print_emoji_detection_script'); // Remove Emoji's Styles and Scripts. |
| 335 |
remove_action('wp_print_styles', 'print_emoji_styles'); // Remove Emoji's Styles and Scripts. |
| 336 |
remove_action('admin_print_styles', 'print_emoji_styles'); // Remove Emoji's Styles and Scripts. |
| 337 |
remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); |
| 338 |
remove_filter('the_content_feed', 'wp_staticize_emoji'); |
| 339 |
remove_filter('comment_text_rss', 'wp_staticize_emoji'); |
| 340 |
add_filter('tiny_mce_plugins', [$this, 'disable_emojicons_tinymce']); |
| 341 |
add_filter('emoji_svg_url', '__return_false'); |
| 342 |
} |
| 343 |
|
| 344 |
$this->remove_feed(); |
| 345 |
$this->redirect_feed(); |
| 346 |
|
| 347 |
// Remove Link to Home Page. |
| 348 |
if (!empty($this->options['remove_link_url'])) { |
| 349 |
remove_action('wp_head', 'index_rel_link'); |
| 350 |
} |
| 351 |
|
| 352 |
// Remove Prev/Next Link from Head |
| 353 |
if (!empty($this->options['remove_prev_next'])) { |
| 354 |
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10); // Remove Prev-next Links From Header -not From Post-. |
| 355 |
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // Remove Prev-next Links. |
| 356 |
remove_action('wp_head', 'start_post_rel_link', 10, 0); // Remove Random Link Post. |
| 357 |
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Remove Parent Post Link. |
| 358 |
} |
| 359 |
|
| 360 |
// Remove styles for .recentcomments |
| 361 |
if (!empty($this->options['remove_recentcomments'])) { |
| 362 |
add_action('widgets_init', [$this, 'jltwp_adminify_remove_recent_comments_style']); |
| 363 |
} |
| 364 |
|
| 365 |
// Remove styles for .recentcomments |
| 366 |
if (!empty($this->options['disable_xmlrpc'])) { |
| 367 |
add_action('wp_default_scripts', [$this, 'jltwp_adminify_disable_xmlrpc'], 9999); |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
// Remove styles for .recentcomments |
| 372 |
public function jltwp_adminify_remove_recent_comments_style() |
| 373 |
{ |
| 374 |
global $wp_widget_factory; |
| 375 |
remove_action('wp_head', [$wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style']); |
| 376 |
} |
| 377 |
|
| 378 |
// Remove Visual Composer Generator |
| 379 |
public function jltwp_adminify_remove_visual_composer_generator() |
| 380 |
{ |
| 381 |
if (class_exists('Vc_Manager')) { |
| 382 |
remove_action('wp_head', [visual_composer(), 'addMetaData']); |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
// Remove WPML Generator |
| 387 |
public function _remove_wpml_generator() |
| 388 |
{ |
| 389 |
if (!empty($GLOBALS['sitepress'])) { |
| 390 |
remove_action(current_filter(), [$GLOBALS['sitepress'], 'meta_generator_tag']); |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
/** |
| 395 |
* Disable XML-RPC |
| 396 |
* |
| 397 |
* @access public |
| 398 |
* @since 1.0.0 |
| 399 |
* @return void |
| 400 |
*/ |
| 401 |
public function jltwp_adminify_disable_xmlrpc() |
| 402 |
{ |
| 403 |
add_filter('xmlrpc_enabled', '__return_false'); |
| 404 |
} |
| 405 |
|
| 406 |
/** |
| 407 |
* Disable WP emojicons from TinyMCE |
| 408 |
* |
| 409 |
* @access public |
| 410 |
* @since 1.0.0 |
| 411 |
* @return void |
| 412 |
*/ |
| 413 |
public function disable_emojicons_tinymce($plugins) |
| 414 |
{ |
| 415 |
if (is_array($plugins)) { |
| 416 |
return array_diff($plugins, ['wpemoji']); |
| 417 |
} else { |
| 418 |
return []; |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
// HTTP Response Cleanup |
| 424 |
public function http_response_cleanup() |
| 425 |
{ |
| 426 |
// Remove Link rel=shortlink from http |
| 427 |
if (!empty($this->options['remove_http_shortlink'])) { |
| 428 |
remove_action('template_redirect', 'wp_shortlink_header', 11); |
| 429 |
} |
| 430 |
|
| 431 |
// Remove X-Pingback |
| 432 |
if (!empty($this->options['remove_pingback'])) { |
| 433 |
add_filter('wp_headers', [$this, 'jltwp_adminify_remove_pingback_head']); |
| 434 |
add_action('wp', [$this, 'jltwp_adminify_remove_pingback']); |
| 435 |
} |
| 436 |
|
| 437 |
// Remove X-Powered-By |
| 438 |
if (!empty($this->options['remove_powered'])) { |
| 439 |
add_action('wp', [$this, 'jltwp_adminify_remove_powered']); |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
public function jltwp_adminify_remove_powered() |
| 444 |
{ |
| 445 |
if (function_exists('header_remove')) { |
| 446 |
header_remove('x-powered-by'); |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
public function jltwp_adminify_remove_pingback_head($headers) |
| 451 |
{ |
| 452 |
if (isset($headers['X-Pingback'])) { |
| 453 |
unset($headers['X-Pingback']); |
| 454 |
} |
| 455 |
|
| 456 |
return $headers; |
| 457 |
} |
| 458 |
|
| 459 |
public function jltwp_adminify_remove_pingback() |
| 460 |
{ |
| 461 |
if (function_exists('header_remove')) { |
| 462 |
header_remove('X-Pingback'); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
// WP JSON API Cleanup |
| 467 |
public function wp_json_api_cleanup() |
| 468 |
{ |
| 469 |
if (!empty($this->options['remove_api_head'])) { |
| 470 |
$this->remove_api_head(); |
| 471 |
} |
| 472 |
|
| 473 |
if (!empty($this->options['remove_api_server'])) { |
| 474 |
$this->remove_api_server(); |
| 475 |
} |
| 476 |
} |
| 477 |
public function remove_api_server() |
| 478 |
{ |
| 479 |
remove_action('template_redirect', 'rest_output_link_header', 11); |
| 480 |
} |
| 481 |
|
| 482 |
public function disable_json_api() |
| 483 |
{ |
| 484 |
// Filters for WP-API version 1.x |
| 485 |
add_filter('json_enabled', '__return_false'); |
| 486 |
add_filter('json_jsonp_enabled', '__return_false'); |
| 487 |
|
| 488 |
// Filters for WP-API version 2.x |
| 489 |
// add_filter('rest_enabled', '__return_false'); |
| 490 |
add_filter('rest_jsonp_enabled', '__return_false'); |
| 491 |
} |
| 492 |
|
| 493 |
public function disable_all_api() |
| 494 |
{ |
| 495 |
$this->remove_api_head(); |
| 496 |
$this->remove_api_server(); |
| 497 |
$this->disable_json_api(); |
| 498 |
|
| 499 |
// More REST API Hooks |
| 500 |
remove_action('rest_api_init', 'wp_oembed_register_route'); // Remove the REST API endpoint. |
| 501 |
remove_action('wp_head', 'wp_oembed_add_host_js'); // Remove oEmbed-specific JavaScript from the front-end and back-end. |
| 502 |
add_filter('embed_oembed_discover', '__return_false'); // Turn off oEmbed auto discovery. |
| 503 |
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); // Remove filter oEmbed results. |
| 504 |
add_filter('rewrite_rules_array', [$this, 'adminify_disable_embeds_rewrites']); // Remove all embeds rewrite rules. |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
/** |
| 509 |
* Remove all rewrite rules related to embeds. |
| 510 |
* |
| 511 |
* @param array $rules WordPress rewrite rules. |
| 512 |
* @return array Rewrite rules without embeds rules. |
| 513 |
*/ |
| 514 |
public function adminify_disable_embeds_rewrites($rules) |
| 515 |
{ |
| 516 |
foreach ($rules as $rule => $rewrite) { |
| 517 |
if (false !== strpos($rewrite, 'embed=true')) { |
| 518 |
unset($rules[$rule]); |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
return $rules; |
| 523 |
} |
| 524 |
|
| 525 |
public function remove_api_head() |
| 526 |
{ |
| 527 |
remove_action('wp_head', 'rest_output_link_wp_head'); |
| 528 |
remove_action('wp_head', 'wp_oembed_add_discovery_links'); |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
// Comments Cleanup |
| 533 |
public function comments_cleanup() |
| 534 |
{ |
| 535 |
// Remove Comments Website/URL field |
| 536 |
if (!empty($this->options['remove_comments_url'])) { |
| 537 |
add_filter('comment_form_default_fields', [$this, 'jltwp_adminify_remove_comments_url']); |
| 538 |
} |
| 539 |
|
| 540 |
// Remove comment notes |
| 541 |
if (!empty($this->options['remove_comments_notes'])) { |
| 542 |
add_filter('comment_form_defaults', [$this, 'jltwp_adminify_remove_comments_notes']); |
| 543 |
} |
| 544 |
|
| 545 |
// Remove comment author link |
| 546 |
if (!empty($this->options['remove_comments_author_link'])) { |
| 547 |
add_filter('get_comment_author_link', [$this, 'jltwp_adminify_remove_comments_author_link']); |
| 548 |
} |
| 549 |
|
| 550 |
// Remove comments autolinking |
| 551 |
if (!empty($this->options['remove_comments_autolinking'])) { |
| 552 |
remove_filter('comment_text', 'make_clickable', 9); |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
public function jltwp_adminify_remove_comments_author_link($author_link) |
| 557 |
{ |
| 558 |
return strip_tags($author_link); |
| 559 |
} |
| 560 |
|
| 561 |
public function jltwp_adminify_remove_comments_notes($defaults) |
| 562 |
{ |
| 563 |
$defaults['comment_notes_before'] = ''; |
| 564 |
|
| 565 |
return $defaults; |
| 566 |
} |
| 567 |
|
| 568 |
public function jltwp_adminify_remove_comments_url($fields) |
| 569 |
{ |
| 570 |
if (isset($fields['url'])) { |
| 571 |
unset($fields['url']); |
| 572 |
} |
| 573 |
|
| 574 |
return $fields; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
// Archives Cleanup |
| 579 |
public function archives_cleanup() |
| 580 |
{ |
| 581 |
// Remove date archives |
| 582 |
if (!empty($this->options['remove_archives_date'])) { |
| 583 |
add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_date']); |
| 584 |
} |
| 585 |
|
| 586 |
// Remove Author archives |
| 587 |
if (!empty($this->options['remove_archives_author'])) { |
| 588 |
add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_author']); |
| 589 |
} |
| 590 |
|
| 591 |
// Remove tag archives |
| 592 |
if (!empty($this->options['remove_archives_tag'])) { |
| 593 |
add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_tag']); |
| 594 |
} |
| 595 |
|
| 596 |
// Remove category archives |
| 597 |
if (!empty($this->options['remove_archives_category'])) { |
| 598 |
add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_category']); |
| 599 |
} |
| 600 |
|
| 601 |
// Remove archives post formats |
| 602 |
if (!empty($this->options['remove_archives_postformat'])) { |
| 603 |
add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_postformat']); |
| 604 |
} |
| 605 |
|
| 606 |
// Remove search page |
| 607 |
if (!empty($this->options['remove_archives_search'])) { |
| 608 |
add_action('template_redirect', [$this, 'jltwp_adminify_remove_archives_search']); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
public function jltwp_adminify_remove_archives_date() |
| 613 |
{ |
| 614 |
if (is_date()) { |
| 615 |
$this->redirect(); |
| 616 |
} |
| 617 |
} |
| 618 |
|
| 619 |
public function jltwp_adminify_remove_archives_author() |
| 620 |
{ |
| 621 |
if (is_author()) { |
| 622 |
$this->redirect(); |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
public function jltwp_adminify_remove_archives_tag() |
| 627 |
{ |
| 628 |
if (is_tag()) { |
| 629 |
$this->redirect(); |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
public function jltwp_adminify_remove_archives_category() |
| 634 |
{ |
| 635 |
if (is_category()) { |
| 636 |
$this->redirect(); |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
public function jltwp_adminify_remove_archives_postformat() |
| 641 |
{ |
| 642 |
if (is_tax('post_format')) { |
| 643 |
$this->redirect(); |
| 644 |
} |
| 645 |
} |
| 646 |
|
| 647 |
public function jltwp_adminify_remove_archives_search() |
| 648 |
{ |
| 649 |
if (is_search()) { |
| 650 |
$this->redirect(); |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
public function attachments_cleanup() |
| 655 |
{ |
| 656 |
// Remove attachments |
| 657 |
if (!empty($this->options['remove_attachment'])) { |
| 658 |
add_action('template_redirect', [$this, 'jltwp_adminify_remove_attachment']); |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
public function jltwp_adminify_remove_attachment() |
| 663 |
{ |
| 664 |
if (is_attachment()) { |
| 665 |
global $post; |
| 666 |
|
| 667 |
$url = get_the_permalink($post->post_parent); |
| 668 |
|
| 669 |
$this->redirect($url); |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
// Redirect function |
| 674 |
public function redirect($url = false) |
| 675 |
{ |
| 676 |
if ($url) { |
| 677 |
$target = $url; |
| 678 |
} else { |
| 679 |
$target = get_option('siteurl'); |
| 680 |
} |
| 681 |
|
| 682 |
$target = apply_filters('wp_adminify_redirect_target', $target); |
| 683 |
$status = apply_filters('wp_adminify_redirect_status', $this->redirect_status); |
| 684 |
|
| 685 |
wp_redirect($target, $status); |
| 686 |
die(); |
| 687 |
} |
| 688 |
|
| 689 |
// Disable Feeds |
| 690 |
public function redirect_feed() |
| 691 |
{ |
| 692 |
$this->remove_feed(); |
| 693 |
} |
| 694 |
|
| 695 |
public function _redirect_feed() |
| 696 |
{ |
| 697 |
$this->redirect(); |
| 698 |
} |
| 699 |
|
| 700 |
// Remove Feed Links |
| 701 |
public function remove_feed() |
| 702 |
{ |
| 703 |
if (!empty($this->options['remove_feed'])) { |
| 704 |
add_action('do_feed', [$this, '_redirect_feed'], 1); |
| 705 |
add_action('do_feed_rdf', [$this, '_redirect_feed'], 1); |
| 706 |
add_action('do_feed_rss', [$this, '_redirect_feed'], 1); |
| 707 |
add_action('do_feed_rss2', [$this, '_redirect_feed'], 1); |
| 708 |
add_action('do_feed_atom', [$this, '_redirect_feed'], 1); |
| 709 |
remove_action('wp_head', 'feed_links_extra', 3); // Remove Every Extra Links to Rss Feeds. |
| 710 |
remove_action('wp_head', 'feed_links', 2); |
| 711 |
remove_action('wp_head', 'wc_products_rss_feed'); |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
public function remove_admin_footer_version() |
| 716 |
{ |
| 717 |
// Remove WordPress Version except Admin |
| 718 |
if (!current_user_can('manage_options')) { |
| 719 |
remove_filter('update_footer', 'core_update_footer'); |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
/* Add Featured Image or Post Thumbnail to RSS Feed */ |
| 725 |
public function jltwp_adminify_rss_post_thumbnail($content) |
| 726 |
{ |
| 727 |
global $post; |
| 728 |
if (has_post_thumbnail($post->ID)) { |
| 729 |
$content = '<p>' . get_the_post_thumbnail($post->ID) . |
| 730 |
'</p>' . get_the_content(); |
| 731 |
} |
| 732 |
return $content; |
| 733 |
} |
| 734 |
|
| 735 |
// Display Last Updated Date of Your Posts |
| 736 |
public function jltwp_adminify_last_updated_date($content) |
| 737 |
{ |
| 738 |
if (!is_single()) { |
| 739 |
return $content; |
| 740 |
} |
| 741 |
|
| 742 |
$u_time = get_the_time('U'); |
| 743 |
$u_modified_time = get_the_modified_time('U'); |
| 744 |
|
| 745 |
if ($u_modified_time >= $u_time + 86400) { |
| 746 |
$custom_content = sprintf( |
| 747 |
__('<div class="wp-adminify-last-updated"><p>%1$s</p><p>%2$s %3$s</p></div>', 'adminify'), |
| 748 |
esc_html__('Last Updated on', 'adminify'), |
| 749 |
get_the_modified_time('F jS, Y'), |
| 750 |
get_the_modified_time('h:i a') |
| 751 |
); |
| 752 |
return $custom_content . $content; |
| 753 |
} |
| 754 |
|
| 755 |
return $content; |
| 756 |
} |
| 757 |
|
| 758 |
public function jltwp_adminify_last_updated_date_style() |
| 759 |
{ |
| 760 |
echo '<style>.last-updated{ border: 1px dashed red; padding: 5px 10px;}</style>'; |
| 761 |
} |
| 762 |
|
| 763 |
|
| 764 |
// Remove Default Image Links typeremove_image_link |
| 765 |
public function jltwp_adminify_imagelink() |
| 766 |
{ |
| 767 |
$image_set = get_option('image_default_link_type'); |
| 768 |
|
| 769 |
if ($image_set !== 'none') { |
| 770 |
update_option('image_default_link_type', 'none'); |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
/* Disable Self Pings */ |
| 776 |
public function jltwp_adminify_no_self_ping(&$links) |
| 777 |
{ |
| 778 |
$home = get_option('home'); |
| 779 |
|
| 780 |
foreach ($links as $l => $link) { |
| 781 |
if (0 === strpos($link, $home)) { |
| 782 |
unset($links[$l]); |
| 783 |
} |
| 784 |
} |
| 785 |
} |
| 786 |
|
| 787 |
|
| 788 |
/** Remove Dashicons from Admin Bar for non logged in users **/ |
| 789 |
public function jltwp_adminify_remove_dashicons() |
| 790 |
{ |
| 791 |
$dequeue = !(bool) apply_filters('wp_adminify_skip_removing_dashicons', false); |
| 792 |
|
| 793 |
if (is_admin_bar_showing() || is_customize_preview()) { |
| 794 |
$dequeue = false; |
| 795 |
} |
| 796 |
|
| 797 |
if ($dequeue) { |
| 798 |
wp_dequeue_style('dashicons'); |
| 799 |
wp_deregister_style('dashicons'); |
| 800 |
} |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
/** Control Interval Heartbeat API **/ |
| 805 |
public function jltwp_adminify_control_heartbeat($settings) |
| 806 |
{ |
| 807 |
$settings['interval'] = 60; |
| 808 |
return $settings; |
| 809 |
} |
| 810 |
|
| 811 |
/** Remove Query Strings from Scripts/Styles **/ |
| 812 |
public function jltwp_adminify_remove_script_version($src) |
| 813 |
{ |
| 814 |
$parts = explode('?ver', $src); |
| 815 |
|
| 816 |
return $parts[0]; |
| 817 |
} |
| 818 |
|
| 819 |
/* Remove Gravatar Query Strings */ |
| 820 |
public function jltwp_adminify_avatar_remove_querystring($url) |
| 821 |
{ |
| 822 |
$url_parts = explode('?', $url); |
| 823 |
return $url_parts[0]; |
| 824 |
} |
| 825 |
|
| 826 |
/** Disable PDF Thumbnails Preview **/ |
| 827 |
public function jltwp_adminify_disable_pdf_previews() |
| 828 |
{ |
| 829 |
$fallbacksizes = []; |
| 830 |
return $fallbacksizes; |
| 831 |
} |
| 832 |
|
| 833 |
/** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer **/ |
| 834 |
public function jltwp_adminify_defer_parsing_of_js($tag, $handle) |
| 835 |
{ |
| 836 |
$skip = apply_filters('wp_adminify_defer_skip', false, $tag, $handle); |
| 837 |
|
| 838 |
if ($skip) { |
| 839 |
return $tag; |
| 840 |
} |
| 841 |
|
| 842 |
if (is_admin()) { |
| 843 |
return $tag; |
| 844 |
} |
| 845 |
if (strpos($tag, '/wp-includes/js/jquery/jquery')) { |
| 846 |
return $tag; |
| 847 |
} |
| 848 |
if (isset($_SERVER['HTTP_USER_AGENT']) && strpos(sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])), 'MSIE 9.') !== false) { |
| 849 |
return $tag; |
| 850 |
} else { |
| 851 |
return str_replace(' src', ' defer src', $tag); |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
/** Browser Cache Expires & GZIP Compression **/ |
| 856 |
public function jltwp_adminify_htaccess() |
| 857 |
{ |
| 858 |
// We get the main WordPress .htaccess filepath. |
| 859 |
$ruta_htaccess = get_home_path() . '.htaccess'; // https://codex.wordpress.org/Function_Reference/get_home_path ! |
| 860 |
|
| 861 |
$lineas = []; |
| 862 |
$lineas[] = '<IfModule mod_expires.c>'; |
| 863 |
$lineas[] = '# Activar caducidad de contenido'; |
| 864 |
$lineas[] = 'ExpiresActive On'; |
| 865 |
$lineas[] = '# Directiva de caducidad por defecto'; |
| 866 |
$lineas[] = 'ExpiresDefault "access plus 1 month"'; |
| 867 |
$lineas[] = '# Para el favicon'; |
| 868 |
$lineas[] = 'ExpiresByType image/x-icon "access plus 1 year"'; |
| 869 |
$lineas[] = '# Imagenes'; |
| 870 |
$lineas[] = 'ExpiresByType image/gif "access plus 1 month"'; |
| 871 |
$lineas[] = 'ExpiresByType image/png "access plus 1 month"'; |
| 872 |
$lineas[] = 'ExpiresByType image/jpg "access plus 1 month"'; |
| 873 |
$lineas[] = 'ExpiresByType image/jpeg "access plus 1 month"'; |
| 874 |
$lineas[] = '# CSS'; |
| 875 |
$lineas[] = 'ExpiresByType text/css "access 1 month"'; |
| 876 |
$lineas[] = '# Javascript'; |
| 877 |
$lineas[] = 'ExpiresByType application/javascript "access plus 1 year"'; |
| 878 |
$lineas[] = '</IfModule>'; |
| 879 |
$lineas[] = '<IfModule mod_deflate.c>'; |
| 880 |
$lineas[] = '# Activar compresión de contenidos estáticos'; |
| 881 |
$lineas[] = 'AddOutputFilterByType DEFLATE text/plain text/html'; |
| 882 |
$lineas[] = 'AddOutputFilterByType DEFLATE text/xml application/xml application/xhtml+xml application/xml-dtd'; |
| 883 |
$lineas[] = 'AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml image/svg+xml'; |
| 884 |
$lineas[] = 'AddOutputFilterByType DEFLATE text/css text/javascript application/javascript application/x-javascript'; |
| 885 |
$lineas[] = 'AddOutputFilterByType DEFLATE font/otf font/opentype application/font-otf application/x-font-otf'; |
| 886 |
$lineas[] = 'AddOutputFilterByType DEFLATE font/ttf font/truetype application/font-ttf application/x-font-ttf'; |
| 887 |
$lineas[] = '</IfModule>'; |
| 888 |
|
| 889 |
insert_with_markers($ruta_htaccess, 'WP Adminify by Jewel Theme', $lineas); // https://developer.wordpress.org/reference/functions/insert_with_markers/ ! |
| 890 |
} |
| 891 |
|
| 892 |
public function jltwp_adminify_delete_tweaks_htaccess() |
| 893 |
{ |
| 894 |
// We get the mail WordPress .htaccess filepath. |
| 895 |
$ruta_htaccess = get_home_path() . '.htaccess'; // https://codex.wordpress.org/Function_Reference/get_home_path ! |
| 896 |
|
| 897 |
$lineas = []; |
| 898 |
|
| 899 |
$lineas[] = '# Optimizaciones eliminadas al desactivar el plugin'; |
| 900 |
|
| 901 |
insert_with_markers($ruta_htaccess, 'WP Adminify by Jewel Theme', $lineas); // https://developer.wordpress.org/reference/functions/insert_with_markers/ ! |
| 902 |
} |
| 903 |
|
| 904 |
/** |
| 905 |
* Performance Cleanup |
| 906 |
* |
| 907 |
* @access public |
| 908 |
* @since 1.0.0 |
| 909 |
* @return void |
| 910 |
*/ |
| 911 |
public function performance_cleanup() |
| 912 |
{ |
| 913 |
// Remove jQuery Migrate |
| 914 |
if (!empty($this->options['remove_jquery_migrate'])) { |
| 915 |
add_action('wp_default_scripts', [$this, 'jltwp_adminify_remove_jquery_migrate'], 9999); |
| 916 |
} |
| 917 |
|
| 918 |
// Remove Gutenberg scrips |
| 919 |
if (!empty($this->options['remove_gutenberg_scripts'])) { |
| 920 |
add_action('wp_default_scripts', [$this, 'jltwp_adminify_remove_gutenberg_scripts'], 9999); |
| 921 |
} |
| 922 |
} |
| 923 |
|
| 924 |
public function jltwp_adminify_remove_jquery_migrate($scripts) |
| 925 |
{ |
| 926 |
if (!is_admin() && isset($scripts->registered['jquery'])) { |
| 927 |
$script = $scripts->registered['jquery']; |
| 928 |
if ($script->deps) { // Check whether the script has any dependencies |
| 929 |
$script->deps = array_diff( |
| 930 |
$script->deps, |
| 931 |
[ |
| 932 |
'jquery-migrate', |
| 933 |
] |
| 934 |
); |
| 935 |
} |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
// Remove all scripts and styles added by Gutenberg |
| 940 |
public function jltwp_adminify_remove_gutenberg_scripts($scripts) |
| 941 |
{ |
| 942 |
add_action('wp_enqueue_scripts', [$this, 'jltwp_adminify_remove_block_scripts_action']); |
| 943 |
remove_action('enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles'); |
| 944 |
} |
| 945 |
|
| 946 |
// Dequeue all scripts and styles added by Gutenberg |
| 947 |
public function jltwp_adminify_remove_block_scripts_action() |
| 948 |
{ |
| 949 |
wp_dequeue_style('wp-block-library'); |
| 950 |
wp_dequeue_style('wc-block-style'); |
| 951 |
} |
| 952 |
} |
| 953 |
|