-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the Performance of the Plugin
- Loading branch information
1 parent
9829d10
commit 0ae72d0
Showing
11 changed files
with
332 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?php | ||
|
||
/** | ||
* @package RemoveLinksScripts\Admin | ||
*/ | ||
|
||
class Remove_Links_Scripts_Admin { | ||
|
||
/** | ||
* Initializes WordPress hooks | ||
*/ | ||
function __construct() { | ||
add_action( 'admin_menu', array($this, 'remove_links_scripts_menu') ); | ||
} | ||
|
||
/** | ||
* Add Settings Page in Menu | ||
*/ | ||
function remove_links_scripts_menu() { | ||
add_menu_page('Remove Links and Scripts Settings', 'Remove Links and Scripts', 'administrator', 'remove-links-scripts-settings', array($this, 'remove_links_scripts_settings_page')); | ||
} | ||
|
||
/** | ||
* Settings Page where user can choose their settings for remove links and scripts | ||
*/ | ||
public function remove_links_scripts_settings_page() { | ||
if ( !current_user_can( 'administrator' ) ) { | ||
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); | ||
} | ||
if (isset($_POST['submit'])) { | ||
$remove_settings = array( | ||
'shortlink' => $_POST['shortlink'], | ||
'rsd_link' => $_POST['rsd_link'], | ||
'wlwmanifest_link' => $_POST['wlwmanifest_link'], | ||
'feed_links' => $_POST['feed_links'], | ||
'emoji_scripts' => $_POST['emoji_scripts'], | ||
'wp_embed' => $_POST['wp_embed'], | ||
'wp_json' => $_POST['wp_json'], | ||
'emoji_styles' => $_POST['emoji_styles'], | ||
'generator' => $_POST['generator'], | ||
'rel_link' => $_POST['rel_link'], | ||
); | ||
update_option('remove_links_scripts', serialize( $remove_settings ) ); | ||
} | ||
$remove_settings = unserialize( get_option('remove_links_scripts') ); | ||
$remove_settings_shortlink_checked = ''; | ||
$remove_settings_rsd_link_checked = ''; | ||
$remove_settings_wlwmanifest_link_checked = ''; | ||
$remove_settings_feed_links_checked = ''; | ||
$remove_settings_emoji_scripts_checked = ''; | ||
$remove_settings_wp_embed_checked = ''; | ||
$remove_settings_wp_json_checked = ''; | ||
$remove_settings_emoji_styles_checked = ''; | ||
$remove_settings_generator_checked = ''; | ||
$remove_settings_rel_link_checked = ''; | ||
|
||
if ( isset($remove_settings) ) { | ||
|
||
if ( esc_attr( $remove_settings['shortlink'] ) == 'on' ) { | ||
$remove_settings_shortlink_checked = 'checked'; | ||
} | ||
|
||
if ( esc_attr( $remove_settings['rsd_link'] ) == 'on' ) { | ||
$remove_settings_rsd_link_checked = 'checked'; | ||
} | ||
|
||
if ( esc_attr( $remove_settings['wlwmanifest_link'] ) == 'on' ) { | ||
$remove_settings_wlwmanifest_link_checked = 'checked'; | ||
} | ||
|
||
if ( esc_attr( $remove_settings['feed_links'] ) == 'on' ) { | ||
$remove_settings_feed_links_checked = 'checked'; | ||
} | ||
|
||
if ( esc_attr( $remove_settings['emoji_scripts'] ) == 'on' ) { | ||
$remove_settings_emoji_scripts_checked = 'checked'; | ||
} | ||
|
||
if ( esc_attr( $remove_settings['wp_embed'] ) == 'on' ) { | ||
$remove_settings_wp_embed_checked = 'checked'; | ||
} | ||
|
||
if ( esc_attr( $remove_settings['wp_json'] ) == 'on' ) { | ||
$remove_settings_wp_json_checked = 'checked'; | ||
} | ||
|
||
if ( esc_attr( $remove_settings['emoji_styles'] ) == 'on' ) { | ||
$remove_settings_emoji_styles_checked = 'checked'; | ||
} | ||
|
||
if ( esc_attr( $remove_settings['generator'] ) == 'on' ) { | ||
$remove_settings_generator_checked = 'checked'; | ||
} | ||
|
||
if ( esc_attr( $remove_settings['rel_link'] ) == 'on' ) { | ||
$remove_settings_rel_link_checked = 'checked'; | ||
} | ||
} | ||
wp_enqueue_style( 'style', plugins_url('../css/admin-style.min.css', __FILE__) ); | ||
|
||
echo '<div class="wrap">'; | ||
echo '<h2>Remove Links and Scripts Settings</h2>'; | ||
echo '<div>Change settings to remove unwanted links and scripts from the wordpress.</div>'; | ||
echo '<form enctype="multipart/form-data" action="" method="POST" id="remove-links-scripts">'; | ||
?> | ||
|
||
<table class="remove-links-scripts"> | ||
<caption>Remove Links</caption> | ||
<tbody> | ||
<tr> | ||
<td><input type="checkbox" name="shortlink" value="on" <?php echo $remove_settings_shortlink_checked; ?> /><strong>Remove Shortlink</strong></td> | ||
</tr> | ||
<tr> | ||
<td><input type="checkbox" name="rsd_link" value="on" <?php echo $remove_settings_rsd_link_checked; ?> /><strong>Remove RSD Links</strong></td> | ||
</tr> | ||
<tr> | ||
<td><input type="checkbox" name="wlwmanifest_link" value="on" <?php echo $remove_settings_wlwmanifest_link_checked; ?> /><strong>Remove WLW Manifest Links</strong></td> | ||
</tr> | ||
<tr> | ||
<td><input type="checkbox" name="feed_links" value="on" <?php echo $remove_settings_feed_links_checked; ?> /><strong>Remove RSS Links</strong></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<table class="remove-links-scripts"> | ||
<caption>Remove Scripts</caption> | ||
<tbody> | ||
<tr> | ||
<td><input type="checkbox" name="emoji_scripts" value="on" <?php echo $remove_settings_emoji_scripts_checked; ?> /><strong>Remove Emoji Scripts</strong></td> | ||
</tr> | ||
<tr> | ||
<td><input type="checkbox" name="wp_embed" value="on" <?php echo $remove_settings_wp_embed_checked; ?> /><strong>Remove Oembed(json + xml)</strong></td> | ||
</tr> | ||
<tr> | ||
<td><input type="checkbox" name="wp_json" value="on" <?php echo $remove_settings_wp_json_checked; ?> /><strong>Remove wp_json</strong></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<table class="remove-links-scripts"> | ||
<caption>Remove Styles</caption> | ||
<tbody> | ||
<tr> | ||
<td><input type="checkbox" name="emoji_styles" value="on" <?php echo $remove_settings_emoji_styles_checked; ?> /><strong>Remove Emoji Styles</strong></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<table class="remove-links-scripts"> | ||
<caption>Remove Meta</caption> | ||
<tbody> | ||
<tr> | ||
<td><input type="checkbox" name="generator" value="on" <?php echo $remove_settings_generator_checked; ?> /><strong>Remove WordPress Generator Meta</strong></td> | ||
</tr> | ||
<tr> | ||
<td><input type="checkbox" name="rel_link" value="on" <?php echo $remove_settings_rel_link_checked; ?> /><strong>Remove Ajacent Relational Links (Next + Prev)</strong></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<?php | ||
submit_button(); | ||
echo '</form>'; | ||
echo '</div>'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
/** | ||
* Silence is golden | ||
*/ |
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/** | ||
* @package RemoveLinksScripts\Frontend | ||
*/ | ||
|
||
class Remove_Links_Scripts_Frontend { | ||
|
||
/** | ||
* Initialize WordPress init Hook | ||
*/ | ||
public function init() { | ||
add_filter( 'init', array($this, 'remove_links_scripts') ); | ||
} | ||
|
||
/** | ||
* Remove Links and Scripts according to the User/'s Settings | ||
*/ | ||
public function remove_links_scripts() { | ||
$remove_settings = unserialize( get_option('remove_links_scripts') ); | ||
|
||
if ( esc_attr( $remove_settings['shortlink'] ) == 'on' ) { | ||
remove_action('wp_head', 'wp_shortlink_wp_head'); | ||
remove_action( 'template_redirect', 'wp_shortlink_header', 11 ); | ||
} | ||
|
||
if ( esc_attr( $remove_settings['rsd_link'] ) == 'on' ) { | ||
remove_action( 'wp_head', 'rsd_link' ); | ||
} | ||
|
||
if ( esc_attr( $remove_settings['wlwmanifest_link'] ) == 'on' ) { | ||
remove_action( 'wp_head', 'wlwmanifest_link' ); | ||
} | ||
|
||
if ( esc_attr( $remove_settings['feed_links'] ) == 'on' ) { | ||
remove_action( 'wp_head', 'feed_links', 2 ); | ||
remove_action('wp_head','feed_links_extra', 3); | ||
} | ||
|
||
if ( esc_attr( $remove_settings['emoji_scripts'] ) == 'on' ) { | ||
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | ||
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | ||
} | ||
|
||
if ( esc_attr( $remove_settings['wp_embed'] ) == 'on' ) { | ||
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); | ||
add_action( 'wp_footer', array($this, 'remove_links_scripts_deregister') ); | ||
} | ||
|
||
if ( esc_attr( $remove_settings['emoji_styles'] ) == 'on' ) { | ||
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | ||
remove_action( 'admin_print_styles', 'print_emoji_styles' ); | ||
} | ||
|
||
if ( esc_attr( $remove_settings['wp_json'] ) == 'on' ) { | ||
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); | ||
remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 ); | ||
} | ||
|
||
if ( esc_attr( $remove_settings['generator'] ) == 'on' ) { | ||
remove_action('wp_head', 'wp_generator'); | ||
} | ||
|
||
if ( esc_attr( $remove_settings['rel_link'] ) == 'on' ) { | ||
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Remove/Deregister wp-embed script | ||
*/ | ||
function remove_links_scripts_deregister() { | ||
wp_deregister_script( 'wp-embed' ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
/** | ||
* Silence is golden | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
/** | ||
* Silence is golden | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* @package RemoveLinksScripts\Main | ||
*/ | ||
|
||
// Make sure we don't expose any info if called directly | ||
if ( !defined('ABSPATH') ) { | ||
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.'; | ||
exit; | ||
} | ||
|
||
if ( !function_exists("add_action") || !function_exists("add_filter") ) { | ||
header( 'Status: 403 Forbidden' ); | ||
header( 'HTTP/1.1 403 Forbidden' ); | ||
exit(); | ||
} | ||
|
||
define('REMOVE_LINKS_SCRIPTS_PLUGIN_VERSION', '0.2'); | ||
|
||
if ( !defined('REMOVE_LINKS_SCRIPTS_PATH') ) { | ||
define('REMOVE_LINKS_SCRIPTS_PATH', plugin_dir_path( __FILE__ )); | ||
} | ||
|
||
require_once(REMOVE_LINKS_SCRIPTS_PATH.'frontend/class.remove-links-scripts-frontend.php'); | ||
|
||
$remove_links_scripts_frontend = new Remove_Links_Scripts_Frontend(); | ||
$remove_links_scripts_frontend->init(); | ||
|
||
if ( is_admin() ) { | ||
require_once(REMOVE_LINKS_SCRIPTS_PATH.'admin/class.remove-links-scripts-admin.php'); | ||
new Remove_Links_Scripts_Admin(); | ||
|
||
$plugin = plugin_basename( REMOVE_LINKS_SCRIPTS_FILE ); | ||
add_filter( "plugin_action_links_$plugin", 'remove_links_scripts_settings_link' ); | ||
} | ||
|
||
/** | ||
* Plugin Settings Page Link on the Plugin Page under the Plugin Name | ||
*/ | ||
function remove_links_scripts_settings_link($links) { | ||
$settings_link = '<a href="admin.php?page=remove-links-scripts-settings">Settings</a>'; | ||
array_unshift($links, $settings_link); | ||
return $links; | ||
} |
Oops, something went wrong.