Changeset 1633859
- Timestamp:
- 04/10/2017 02:57:45 AM (9 years ago)
- Location:
- remove-http
- Files:
-
- 5 added
- 2 edited
-
tags/2.1.0 (added)
-
tags/2.1.0/index.php (added)
-
tags/2.1.0/readme.txt (added)
-
tags/2.1.0/remove-http.php (added)
-
tags/2.1.0/uninstall.php (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/remove-http.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
remove-http/trunk/readme.txt
r1624252 r1633859 4 4 Tags: 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 5 5 Requires at least: 3.0.0 6 Tested up to: 4.7. 17 Stable tag: 2. 0.06 Tested up to: 4.7.3 7 Stable tag: 2.1.0 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 51 51 52 52 == Changelog == 53 = 2.1.0 = 54 55 *2017-04-09* 56 57 * Restored option to ignore external links 58 53 59 = 2.0.0 = 54 60 -
remove-http/trunk/remove-http.php
r1624252 r1633859 4 4 * Plugin URI: https://wordpress.org/plugins/remove-http/ 5 5 * Description: Removes both HTTP and HTTPS protocols from links. 6 * Version: 2. 0.06 * Version: 2.1.0 7 7 * Author: Fact Maven 8 8 * Author URI: https://www.factmaven.com/ … … 15 15 class Fact_Maven_Remove_HTTP { 16 16 17 private $option ;17 private $option, $plugin; 18 18 19 19 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 21 35 $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'; 22 39 # Add link to plugin settings 23 40 add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 ); … … 40 57 41 58 public function settings_field() { 42 # Register the setting 59 # Register the settings 43 60 register_setting( 'general', 'factmaven_rhttp' ); 44 61 # Add settings field 45 add_settings_field( 'protocol_relative', ' Site AddressFormat', array( $this, 'options' ), 'general' );62 add_settings_field( 'protocol_relative', 'URL Format', array( $this, 'options' ), 'general' ); 46 63 } 47 64 … … 49 66 # Insert the settings field after the 'Site Address (URL)' 50 67 ?> <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' ) ); 52 69 </script> <?php 53 70 } 54 71 55 72 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> 60 79 </fieldset> <?php 61 80 } … … 75 94 # If the content-type is 'NULL' or 'text/html', apply rewrite 76 95 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' 78 99 $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 ); 82 104 } 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 } 85 109 } 86 110 # Return protocol relative links
Note: See TracChangeset
for help on using the changeset viewer.