Plugin Directory

Changeset 1633859


Ignore:
Timestamp:
04/10/2017 02:57:45 AM (9 years ago)
Author:
factmaven
Message:

Update to v2.1.0

Location:
remove-http
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • remove-http/trunk/readme.txt

    r1624252 r1633859  
    44Tags: cloudflare, http, https, insecure content, mixed content, mixed content warning, partially encrypted, protocol relative url, protocol rewriting, relative protocol, remove http, remove https, rewrite, ssl, url
    55Requires at least: 3.0.0
    6 Tested up to: 4.7.1
    7 Stable tag: 2.0.0
     6Tested up to: 4.7.3
     7Stable tag: 2.1.0
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    5151
    5252== Changelog ==
     53= 2.1.0 =
     54
     55*2017-04-09*
     56
     57* Restored option to ignore external links
     58
    5359= 2.0.0 =
    5460
  • remove-http/trunk/remove-http.php

    r1624252 r1633859  
    44 * Plugin URI: https://wordpress.org/plugins/remove-http/
    55 * Description: Removes both HTTP and HTTPS protocols from links.
    6  * Version: 2.0.0
     6 * Version: 2.1.0
    77 * Author: Fact Maven
    88 * Author URI: https://www.factmaven.com/
     
    1515class Fact_Maven_Remove_HTTP {
    1616
    17     private $option;
     17    private $option, $plugin;
    1818
    1919    public function __construct() {
    20         # Get plugin option
     20        # Call the core Plugin API
     21        require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     22        # Get plugin's metadata
     23        $this->plugin = get_plugin_data( __FILE__ );
     24        # If the plugin version is lower or not defined, remove plugin options
     25        if ( ( get_option( 'factmaven_rhttp_version' ) < $this->plugin['Version'] ) || ! get_option( 'factmaven_rhttp_version' ) ) {
     26            # Remove options with the prefix "factmaven_rhttp_"
     27            foreach ( wp_load_alloptions() as $option => $value ) {
     28                if ( strpos( $option, 'factmaven_rhttp' ) === 0 ) delete_option( $option );
     29            }
     30            # Add options for new plugin version
     31            update_option( 'factmaven_rhttp_version', $this->plugin['Version'] );
     32        }
     33
     34        # Get plugin options
    2135        $this->option = get_option( 'factmaven_rhttp' );
     36        # Set default options
     37        if ( empty( $this->option['format'] ) ) $this->option['format'] = 'protocol-relative';
     38        if ( empty( $this->option['external'] ) ) $this->option['external'] = '0';
    2239        # Add link to plugin settings
    2340        add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 );
     
    4057
    4158    public function settings_field() {
    42         # Register the setting
     59        # Register the settings
    4360        register_setting( 'general', 'factmaven_rhttp' );
    4461        # Add settings field
    45         add_settings_field( 'protocol_relative', 'Site Address Format', array( $this, 'options' ), 'general' );
     62        add_settings_field( 'protocol_relative', 'URL Format', array( $this, 'options' ), 'general' );
    4663    }
    4764
     
    4966        # Insert the settings field after the 'Site Address (URL)'
    5067        ?> <script type="text/javascript">
    51         jQuery( '#protocol-description' ).closest( 'tr' ).insertAfter( jQuery( '#home-description' ).closest( 'tr' ) );
     68        jQuery( '#format-description' ).closest( 'tr' ).insertAfter( jQuery( '#home-description' ).closest( 'tr' ) );
    5269        </script> <?php
    5370    }
    5471
    5572    public function options() {
    56         ?> <fieldset><legend class="screen-reader-text"><span>Site Address Format</span></legend>
    57         <label><input type="radio" name="factmaven_rhttp" value="1" <?php checked( '1', $this->option ); ?> checked="checked"> <span class="date-time-text format-i18n">Protocol-Relative</span><code>//example.com/sample-post/</code></label><br>
    58         <label><input type="radio" name="factmaven_rhttp" value="2" <?php checked( '2', $this->option ); ?>> <span class="date-time-text format-i18n">Relative</span><code>/sample-post/</code></label><br>
    59         <p class="description" id="protocol-description">Selecting Relative will only apply to internal links. External links will become Protocol-Relative.</p></td>
     73        # Display plugin settings field
     74        ?> <fieldset>
     75        <label><input type="radio" name="factmaven_rhttp[format]" value="protocol-relative" <?php checked( 'protocol-relative', $this->option['format'] ); ?> checked="checked"> <span class="date-time-text format-i18n">Protocol-Relative</span><code>//example.com/sample-post/</code></label><br>
     76        <label><input type="radio" name="factmaven_rhttp[format]" value="relative" <?php checked( 'relative', $this->option['format'] ); ?>> <span class="date-time-text format-i18n">Relative</span><code>/sample-post/</code></label><br>
     77        <label><input name="factmaven_rhttp[external]" type="checkbox" value="1" <?php checked( '1', $this->option['external'] ); ?>> Ignore external links</label>
     78        <p class="description" id="format-description">Relative format will only affect internal links.</p>
    6079        </fieldset> <?php
    6180    }
     
    7594            # If the content-type is 'NULL' or 'text/html', apply rewrite
    7695            if ( is_null( $content_type ) || substr( $content_type, 0, 9 ) === 'text/html' ) {
    77                 # If 'Relative' option is selected, remove domain from all internal links
     96                # Get domain without protocol               
     97                $website = preg_replace( '/https?:\/\//', '', home_url() );
     98                # Ignore input tags link tags with 'rel=canonical'
    7899                $exceptions = '<(?:input\b[^<]*\bvalue=[\"\']https?:\/\/|link\b[^<]*?\brel=[\'\"]canonical[\'\"][^<]*?>)(*SKIP)(*F)';
    79                 if ( $this->option == 2 ) {
    80                     $website = preg_replace( '/https?:\/\//', '', home_url() );
    81                     $links = preg_replace( '/' . $exceptions . '|https?:\/\/' . $website . '/', '', $links );
     100                # If 'Ignore external links' is selected, only apply changes to internal links
     101                if ( $this->option['external'] == 1 ) {
     102                    if ( $this->option['format'] == 'relative' ) $links = preg_replace( '/' . $exceptions . '|https?:\/\/' . $website . '/', '', $links );
     103                    else $links = preg_replace( '/' . $exceptions . '|https?:\/\/' . $website . '/', '//$1' . $website, $links );
    82104                }
    83                 # For all external links, remove protocols
    84                 $links = preg_replace( '/' . $exceptions . '|https?:\/\//', '//', $links );
     105                else {
     106                    if ( $this->option['format'] == 'relative' ) $links = preg_replace( '/' . $exceptions . '|https?:\/\/' . $website . '/', '', $links );
     107                    else $links = preg_replace( '/' . $exceptions . '|https?:\/\//', '//', $links );
     108                }
    85109            }
    86110            # Return protocol relative links
Note: See TracChangeset for help on using the changeset viewer.