Plugin Directory

Changeset 2116546


Ignore:
Timestamp:
07/02/2019 11:56:49 PM (7 years ago)
Author:
edesac
Message:

version 1.0.2

Location:
relative-url-for-img-and-a-tags/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • relative-url-for-img-and-a-tags/trunk/readme.txt

    r2116538 r2116546  
    33Contributors: edesac
    44Requires at least: 4.5.3
    5 Tested up to: 4.5.3
    6 Stable tag: 1.0.1
     5Tested up to: 5.2.2
     6Stable tag: 1.0.2
    77Tags: remove root URL from image & link tags, relative links, relative image source
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 This plugin will filter the content of your posts and pages to remove the root of the domain from links and image sources. This is useful if you are installing your wordpress website on a subfolder which you will move on the main domain.
     11This plugin will filter the content of your posts and pages to remove the root of the domain from links and image sources.
    1212
    1313== Description ==
    1414
    15 This plugin will filter the content of your posts and pages to remove the root of the domain from links and image sources. This means that it will leave the relative URL on your image and links. This is useful if you are installing your wordpress website on a subfolder which you will move on the main domain.
     15This plugin will remove the root of the domain from links and image sources. This means that it will leave the relative URL on your image and links. This is useful if you are installing your wordpress website on a subfolder which you will move on the main domain.
    1616
    17 Features:
     17You can move your site to a different subdomain, subfolder, parent folder, etc., without having to edit image sources and link URLs.
     18
     19So, **http://webdev-tuts.com/wp-content/uploads/2016/05/svggraph-pie-graph.jpg** would become **/wp-content/uploads/2016/05/svggraph-pie-graph.jpg**
     20
     21Note: We haven't tested the plugin on any page builder yet.
     22
     23== Features ==
    1824
    1925*   removes the the domain name on links for internal links
    2026*   removes domain from on image sources for images located in the server
    21 
    22 Sample Results:
    23 
    24 <img src="http://webdev-tuts.com/wp-content/uploads/2016/05/svggraph-pie-graph.jpg" /> to <img src="/wp-content/uploads/2016/05/svggraph-pie-graph.jpg" />
    25 
    26 Supported Page Builders
    27 
    28 (We haven't tested the plugin on any page builder yet.)
    29 
    30 Benefits:
    31 
    32 * You can move your site from subdomain to main domain and vise versa without any trouble with internal links and image sources.
    33 * You can move your site from subfolder to main folder and vise versa without any trouble with internal links and image sources.
    3427
    3528== Installation ==
     
    3730This section describes how to install the plugin and get it working.
    3831
    39 1. Activate the plugin through the 'Plugins' menu in WordPress
     321. Back up database before activating and installing the plugin.
     332. Activate the plugin through the 'Plugins' menu in WordPress.
     343. If you have installed a cache plugin, clear it, then view an old post that contains an image and check if the image or link renders properly.
    4035
    4136== Changelog ==
    4237
    4338= 1.0.0 =
    44 * Initial
     39* Initial upload
    4540
    4641= 1.0.1 =
    4742* Fix problem on url in case the site is moved to subfolder to parent folder and vise versa
     43
     44= 1.0.2 =
     45* Remove content filter because it's no longer necessary
     46* Improve codes
  • relative-url-for-img-and-a-tags/trunk/relative-url-for-img-and-a-tags.php

    r1446913 r2116546  
    44 * Description: This plugin will filter the content of your posts and pages to remove the root of the domain from links and image sources.
    55 * Author: EdesaC
    6  * Version: 1.0.1
     6 * Version: 1.0.2
    77**/
    88 
     
    1818        $this->_plugin_url = plugin_dir_url($file);
    1919        $this->_plugin_folder = basename(dirname($file));
    20 
    21         add_filter('the_content', array($this, 'myFilterContent'));
    22         add_action('wp_insert_post_data', array($this, 'filterURLOnUpdate'), 99, 2);
    23 
    24         register_activation_hook($file, array($this, 'removeOnDB'));
    25 
    26         //    add_action('admin_enqueue_scripts', array($this, 'load_admin_scripts_css'));
    27         //    add_action('wp_footer', array($this, 'load_website_scripts_css'));
    2820       
    2921        $url = get_bloginfo('wpurl');
     
    3224       
    3325        $opt = get_option('relative-url-img-a-tags');
     26
    3427        if ($opt['subfolder'] != $subfolder) {
    35             $this->changeSubfolderDB($opt['subfolder'], $subfolder);
     28            $this->_changeSubfolderDB($opt['subfolder'], $subfolder);
    3629                   
    3730            $opt['subfolder'] = $subfolder;
    3831            update_option('relative-url-img-a-tags', $opt);           
    39         }       
    40     }   
     32        }
     33       
     34        add_action('wp_insert_post_data', array($this, 'filterURLOnUpdate'), 99, 2);
     35        register_activation_hook($file, array($this, 'removeOnDB'));       
     36    }
    4137   
     38    /**
     39     * remove root url from src and href upon saving a post or page.
     40     * @action wp_insert_post_data
     41     * @param array $data
     42     * @param array $postarr
     43     * @return type array
     44     */
    4245    function filterURLOnUpdate($data , $postarr = array()){
    4346        $content = htmlentities($data['post_content']);
     
    5861    }
    5962
    60     public function changeSubfolderDB($old_subfolder, $new_subfolder) {
     63    /**
     64     * If the plugin detects that the wp installation is moved to a new subfolder, it will update the database
     65     * @global type $wpdb
     66     * @param type $old_subfolder
     67     * @param type $new_subfolder
     68     */
     69    protected function _changeSubfolderDB($old_subfolder, $new_subfolder) {
    6170        global $wpdb;
    6271        $url = get_bloginfo('wpurl');
     
    8089    }
    8190
     91    /**
     92     * Removes the root of the url in image and link tags from posts table
     93     * @global type $wpdb
     94     */
    8295    public function removeOnDB() {
    8396        global $wpdb;
     
    102115        $wpdb->query($query2);               
    103116    }
    104 
    105     function myFilterContent($content) {
    106         $url = get_bloginfo('wpurl');
    107 
    108         $parse = parse_url($url);
    109         $root = $parse['scheme'] . '://' . $parse['host'];
    110        
    111         $new_content = str_replace('href="' . $root, 'href="', $content);
    112         $new_content = str_replace('src="' . $root, 'src="', $new_content);
    113 
    114         return $new_content;
    115     }
    116 
    117     function load_website_scripts_css() {
    118     //    wp_enqueue_script($this->_plugin_folder . '-wp-scripts', $this->_plugin_url . '/scripts/wp-scripts.js');
    119     //    wp_enqueue_style($this->_plugin_folder . '-wp-styles', $this->_plugin_url . '/styles/wp-styles.css');
    120     }
    121 
    122     final function load_admin_scripts_css() {
    123     //    wp_enqueue_media();
    124     //    wp_enqueue_script('jquery');
    125     //    wp_enqueue_script($this->_plugin_folder . '-admin-scripts', $this->_plugin_url . 'scripts/admin-scripts.js');
    126     //    wp_enqueue_style($this->_plugin_folder . '-admin-styles', $this->_plugin_url . 'styles/admin-styles.css');
    127     }
    128117} // end of class
    129118
Note: See TracChangeset for help on using the changeset viewer.