Changeset 2116546
- Timestamp:
- 07/02/2019 11:56:49 PM (7 years ago)
- Location:
- relative-url-for-img-and-a-tags/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
relative-url-for-img-and-a-tags.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
relative-url-for-img-and-a-tags/trunk/readme.txt
r2116538 r2116546 3 3 Contributors: edesac 4 4 Requires at least: 4.5.3 5 Tested up to: 4.5.36 Stable tag: 1.0. 15 Tested up to: 5.2.2 6 Stable tag: 1.0.2 7 7 Tags: remove root URL from image & link tags, relative links, relative image source 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 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.11 This plugin will filter the content of your posts and pages to remove the root of the domain from links and image sources. 12 12 13 13 == Description == 14 14 15 This plugin will filter the content of your posts and pages toremove 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.15 This 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. 16 16 17 Features: 17 You can move your site to a different subdomain, subfolder, parent folder, etc., without having to edit image sources and link URLs. 18 19 So, **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 21 Note: We haven't tested the plugin on any page builder yet. 22 23 == Features == 18 24 19 25 * removes the the domain name on links for internal links 20 26 * 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 Builders27 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.34 27 35 28 == Installation == … … 37 30 This section describes how to install the plugin and get it working. 38 31 39 1. Activate the plugin through the 'Plugins' menu in WordPress 32 1. Back up database before activating and installing the plugin. 33 2. Activate the plugin through the 'Plugins' menu in WordPress. 34 3. 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. 40 35 41 36 == Changelog == 42 37 43 38 = 1.0.0 = 44 * Initial 39 * Initial upload 45 40 46 41 = 1.0.1 = 47 42 * 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 4 4 * Description: This plugin will filter the content of your posts and pages to remove the root of the domain from links and image sources. 5 5 * Author: EdesaC 6 * Version: 1.0. 16 * Version: 1.0.2 7 7 **/ 8 8 … … 18 18 $this->_plugin_url = plugin_dir_url($file); 19 19 $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'));28 20 29 21 $url = get_bloginfo('wpurl'); … … 32 24 33 25 $opt = get_option('relative-url-img-a-tags'); 26 34 27 if ($opt['subfolder'] != $subfolder) { 35 $this-> changeSubfolderDB($opt['subfolder'], $subfolder);28 $this->_changeSubfolderDB($opt['subfolder'], $subfolder); 36 29 37 30 $opt['subfolder'] = $subfolder; 38 31 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 } 41 37 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 */ 42 45 function filterURLOnUpdate($data , $postarr = array()){ 43 46 $content = htmlentities($data['post_content']); … … 58 61 } 59 62 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) { 61 70 global $wpdb; 62 71 $url = get_bloginfo('wpurl'); … … 80 89 } 81 90 91 /** 92 * Removes the root of the url in image and link tags from posts table 93 * @global type $wpdb 94 */ 82 95 public function removeOnDB() { 83 96 global $wpdb; … … 102 115 $wpdb->query($query2); 103 116 } 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 }128 117 } // end of class 129 118
Note: See TracChangeset
for help on using the changeset viewer.