Skip to content

Commit

Permalink
Improve the Performance of the Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
samiahmedsiddiqui committed Jul 27, 2017
1 parent 9829d10 commit 0ae72d0
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 203 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This plugin can remove the links, scripts, styles and some other meta from the w

All the above headers can be removed from this plugin. You can select them from the settings page.

*Make sure to check the settings Page*
= Make sure to check the settings Page =

## Installation

Expand All @@ -32,6 +32,6 @@ All the above headers can be removed from this plugin. You can select them from

A. Installing this plugin is the easiest way to remove unwanted links, scripts, styles and some other meta from the header.

**Q. May i select the removing items?**
** Q. May i select the removing items?**

A. Yes, You can select the items you want to remove.
167 changes: 167 additions & 0 deletions admin/class.remove-links-scripts-admin.php
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>';
}

}
4 changes: 4 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
/**
* Silence is golden
*/
File renamed without changes.
1 change: 1 addition & 0 deletions css/admin-style.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions frontend/class.remove-links-scripts-frontend.php
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' );
}

}
4 changes: 4 additions & 0 deletions frontend/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
/**
* Silence is golden
*/
4 changes: 4 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
/**
* Silence is golden
*/
13 changes: 8 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
=== Remove Links and Scripts ===
Contributors: aliya-yasir, sasiddiqui
Contributors: aliya-yasir, sasiddiqui, yasglobal
Donate link: https://www.paypal.me/yasglobal
Tags: shortlink, rsd_link, wlwmanifest_link, feed_links, emoji_scripts, wp_embed, wp_json, emoji_styles, generator, rel_link
Requires at least: 3.5
Tested up to: 4.8
Stable tag: 0.1
Stable tag: 0.2
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.html

Expand Down Expand Up @@ -36,10 +36,9 @@ All the above headers can be removed from this plugin. You can select them from
2. Activate the Remove Links and Scripts plugin through the `Plugins` menu in WordPress.
3. Configure the plugin by going to the menu `Remove Links and Scripts` that appears in your admin menu


== Screenshots ==

* YOu can select the options from the settings page ([here](http://www.example.com/wp-admin/admin.php?page=remove-links-scripts-settings)).
* You can select the options from the settings page ([here](http://www.example.com/wp-admin/admin.php?page=remove-links-scripts-settings)).

== Frequently Asked Questions ==

Expand All @@ -51,6 +50,10 @@ A. Yes, You can select the items you want to remove.

== Changelog ==

= 0.2 =

* Improve the Performance of the Plugin

= 0.1 =

* First release on wordpress.org.
* First release on wordpress.org.
45 changes: 45 additions & 0 deletions remove-links-scripts-main.php
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;
}
Loading

0 comments on commit 0ae72d0

Please sign in to comment.