Version Description
- Confirmed compatibility with WordPress 4.0.x releases.
- Updated readme file.
Download this release
Release Info
Developer | VelvetBlues.com |
Plugin | ![]() |
Version | 3.2.3 |
Comparing to | |
See all releases |
Code changes from version 3.2.2 to 3.2.3
- readme.txt +7 -3
- velvet-blues-update-urls.php +309 -309
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: VelvetBlues.com
|
|
3 |
Donate link: http://www.velvetblues.com/go/updateurlsdonate/
|
4 |
Tags: permalinks, urls, links, update links, move wordpress, location, update urls, update permalinks, move, link, url, permalink, excerpt, content links, excerpt links, custom field links, meta, post meta
|
5 |
Requires at least: 2.5
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 3.2.
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
Updates all urls and content links in your website.
|
@@ -30,7 +30,7 @@ Installation and uninstallation are extremely simple. You can use WordPress' aut
|
|
30 |
1. Download the package.
|
31 |
2. Extract it to the "plugins" folder of your WordPress directory.
|
32 |
3. In the Admin Panel, go to "Plugins" and activate it.
|
33 |
-
4. Go to
|
34 |
|
35 |
= Uninstalling: =
|
36 |
|
@@ -74,6 +74,10 @@ Get support for this plugin by going to the [Velvet Blues Update URLs plugin pag
|
|
74 |
|
75 |
== Change Log ==
|
76 |
|
|
|
|
|
|
|
|
|
77 |
= 3.2.2 =
|
78 |
* Relocated Update URLs tab to Tools section. It is now found under Tools->Update URLs
|
79 |
* Added additional serialization checks for postmeta.
|
3 |
Donate link: http://www.velvetblues.com/go/updateurlsdonate/
|
4 |
Tags: permalinks, urls, links, update links, move wordpress, location, update urls, update permalinks, move, link, url, permalink, excerpt, content links, excerpt links, custom field links, meta, post meta
|
5 |
Requires at least: 2.5
|
6 |
+
Tested up to: 4.0
|
7 |
+
Stable tag: 3.2.3
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
Updates all urls and content links in your website.
|
30 |
1. Download the package.
|
31 |
2. Extract it to the "plugins" folder of your WordPress directory.
|
32 |
3. In the Admin Panel, go to "Plugins" and activate it.
|
33 |
+
4. Go to Tools -> Update URLs to use it.
|
34 |
|
35 |
= Uninstalling: =
|
36 |
|
74 |
|
75 |
== Change Log ==
|
76 |
|
77 |
+
= 3.2.3 =
|
78 |
+
* Confirmed compatibility with WordPress 4.0.x releases.
|
79 |
+
* Updated readme file.
|
80 |
+
|
81 |
= 3.2.2 =
|
82 |
* Relocated Update URLs tab to Tools section. It is now found under Tools->Update URLs
|
83 |
* Added additional serialization checks for postmeta.
|
velvet-blues-update-urls.php
CHANGED
@@ -1,309 +1,309 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Velvet Blues Update URLs
|
4 |
-
Plugin URI: http://www.velvetblues.com/web-development-blog/wordpress-plugin-update-urls/
|
5 |
-
Description: This plugin <strong>updates all urls in your website</strong> by replacing old urls with new urls. To get started: 1) Click the "Activate" link to the left of this description, and 2) Go to your <a href="tools.php?page=velvet-blues-update-urls.php">Update URLs</a> page to use it.
|
6 |
-
Author: VelvetBlues.com
|
7 |
-
Author URI: http://www.velvetblues.com/
|
8 |
-
Author Email: info@velvetblues.com
|
9 |
-
Version: 3.2.
|
10 |
-
License: GPLv2 or later
|
11 |
-
Text Domain: velvet-blues-update-urls
|
12 |
-
*/
|
13 |
-
/* Copyright
|
14 |
-
|
15 |
-
This program is free software; you can redistribute it and/or
|
16 |
-
modify it under the terms of the GNU General Public License
|
17 |
-
as published by the Free Software Foundation; either version 2
|
18 |
-
of the License, or (at your option) any later version.
|
19 |
-
|
20 |
-
This program is distributed in the hope that it will be useful,
|
21 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
-
GNU General Public License for more details.
|
24 |
-
|
25 |
-
You should have received a copy of the GNU General Public License
|
26 |
-
along with this program; if not, write to the Free Software
|
27 |
-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
-
*/
|
29 |
-
if ( !function_exists( 'add_action' ) ) {
|
30 |
-
?>
|
31 |
-
<h3>Oops! This page cannot be accessed directly.</h3>
|
32 |
-
<p>For support using the Velvet Blues Update URLs plugin, <a href="http://www.velvetblues.com/web-development-blog/wordpress-plugin-update-urls/" title="Velvet Blues Update URLs WordPress plugin">click here</a>.</p>
|
33 |
-
<p>If you are looking for general WordPress assistance, <a href="http://www.velvetblues.com/" title="WordPress Web Development and Services">Velvet Blues can help with that too</a>.</p>
|
34 |
-
<?php
|
35 |
-
exit;
|
36 |
-
}
|
37 |
-
function VelvetBluesUU_add_management_page(){
|
38 |
-
add_management_page("Velvet Blues Update URLs", "Update URLs", "manage_options", basename(__FILE__), "VelvetBluesUU_management_page");
|
39 |
-
}
|
40 |
-
function VelvetBluesUU_load_textdomain(){
|
41 |
-
load_plugin_textdomain( 'velvet-blues-update-urls', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
42 |
-
}
|
43 |
-
function VelvetBluesUU_management_page(){
|
44 |
-
function VB_update_urls($options,$oldurl,$newurl){
|
45 |
-
global $wpdb;
|
46 |
-
$results = array();
|
47 |
-
$queries = array(
|
48 |
-
'content' => array("UPDATE $wpdb->posts SET post_content = replace(post_content, %s, %s)", __('Content Items (Posts, Pages, Custom Post Types, Revisions)','velvet-blues-update-urls') ),
|
49 |
-
'excerpts' => array("UPDATE $wpdb->posts SET post_excerpt = replace(post_excerpt, %s, %s)", __('Excerpts','velvet-blues-update-urls') ),
|
50 |
-
'attachments' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s) WHERE post_type = 'attachment'", __('Attachments','velvet-blues-update-urls') ),
|
51 |
-
'links' => array("UPDATE $wpdb->links SET link_url = replace(link_url, %s, %s)", __('Links','velvet-blues-update-urls') ),
|
52 |
-
'custom' => array("UPDATE $wpdb->postmeta SET meta_value = replace(meta_value, %s, %s)", __('Custom Fields','velvet-blues-update-urls') ),
|
53 |
-
'guids' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s)", __('GUIDs','velvet-blues-update-urls') )
|
54 |
-
);
|
55 |
-
foreach($options as $option){
|
56 |
-
if( $option == 'custom' ){
|
57 |
-
$n = 0;
|
58 |
-
$row_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta" );
|
59 |
-
$page_size = 10000;
|
60 |
-
$pages = ceil( $row_count / $page_size );
|
61 |
-
|
62 |
-
for( $page = 0; $page < $pages; $page++ ) {
|
63 |
-
$current_row = 0;
|
64 |
-
$start = $page * $page_size;
|
65 |
-
$end = $start + $page_size;
|
66 |
-
$pmquery = "SELECT * FROM $wpdb->postmeta WHERE meta_value <> ''";
|
67 |
-
$items = $wpdb->get_results( $pmquery );
|
68 |
-
foreach( $items as $item ){
|
69 |
-
$value = $item->meta_value;
|
70 |
-
if( trim($value) == '' )
|
71 |
-
continue;
|
72 |
-
|
73 |
-
$edited = VB_unserialize_replace( $oldurl, $newurl, $value );
|
74 |
-
|
75 |
-
if( $edited != $value ){
|
76 |
-
$fix = $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '".$edited."' WHERE meta_id = ".$item->meta_id );
|
77 |
-
if( $fix )
|
78 |
-
$n++;
|
79 |
-
}
|
80 |
-
}
|
81 |
-
}
|
82 |
-
$results[$option] = array($n, $queries[$option][1]);
|
83 |
-
}
|
84 |
-
else{
|
85 |
-
$result = $wpdb->query( $wpdb->prepare( $queries[$option][0], $oldurl, $newurl) );
|
86 |
-
$results[$option] = array($result, $queries[$option][1]);
|
87 |
-
}
|
88 |
-
}
|
89 |
-
return $results;
|
90 |
-
}
|
91 |
-
function VB_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
|
92 |
-
try {
|
93 |
-
if ( is_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) {
|
94 |
-
$data = VB_unserialize_replace( $from, $to, $unserialized, true );
|
95 |
-
}
|
96 |
-
elseif ( is_array( $data ) ) {
|
97 |
-
$_tmp = array( );
|
98 |
-
foreach ( $data as $key => $value ) {
|
99 |
-
$_tmp[ $key ] = VB_unserialize_replace( $from, $to, $value, false );
|
100 |
-
}
|
101 |
-
$data = $_tmp;
|
102 |
-
unset( $_tmp );
|
103 |
-
}
|
104 |
-
else {
|
105 |
-
if ( is_string( $data ) )
|
106 |
-
$data = str_replace( $from, $to, $data );
|
107 |
-
}
|
108 |
-
if ( $serialised )
|
109 |
-
return serialize( $data );
|
110 |
-
} catch( Exception $error ) {
|
111 |
-
}
|
112 |
-
return $data;
|
113 |
-
}
|
114 |
-
if ( isset( $_POST['VBUU_settings_submit'] ) && !check_admin_referer('VBUU_submit','VBUU_nonce')){
|
115 |
-
if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
|
116 |
-
if(function_exists('esc_attr')){
|
117 |
-
$vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
|
118 |
-
$vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
|
119 |
-
}else{
|
120 |
-
$vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
|
121 |
-
$vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
|
122 |
-
}
|
123 |
-
}
|
124 |
-
echo '<div id="message" class="error fade"><p><strong>'.__('ERROR','velvet-blues-update-urls').' - '.__('Please try again.','velvet-blues-update-urls').'</strong></p></div>';
|
125 |
-
}
|
126 |
-
elseif( isset( $_POST['VBUU_settings_submit'] ) && !isset( $_POST['VBUU_update_links'] ) ){
|
127 |
-
if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
|
128 |
-
if(function_exists('esc_attr')){
|
129 |
-
$vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
|
130 |
-
$vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
|
131 |
-
}else{
|
132 |
-
$vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
|
133 |
-
$vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
|
134 |
-
}
|
135 |
-
}
|
136 |
-
echo '<div id="message" class="error fade"><p><strong>'.__('ERROR','velvet-blues-update-urls').' - '.__('Your URLs have not been updated.','velvet-blues-update-urls').'</p></strong><p>'.__('Please select at least one checkbox.','velvet-blues-update-urls').'</p></div>';
|
137 |
-
}
|
138 |
-
elseif( isset( $_POST['VBUU_settings_submit'] ) ){
|
139 |
-
$vbuu_update_links = $_POST['VBUU_update_links'];
|
140 |
-
if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
|
141 |
-
if(function_exists('esc_attr')){
|
142 |
-
$vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
|
143 |
-
$vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
|
144 |
-
}else{
|
145 |
-
$vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
|
146 |
-
$vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
|
147 |
-
}
|
148 |
-
}
|
149 |
-
if(($vbuu_oldurl && $vbuu_oldurl != 'http://www.oldurl.com' && trim($vbuu_oldurl) != '') && ($vbuu_newurl && $vbuu_newurl != 'http://www.newurl.com' && trim($vbuu_newurl) != '')){
|
150 |
-
$results = VB_update_urls($vbuu_update_links,$vbuu_oldurl,$vbuu_newurl);
|
151 |
-
$empty = true;
|
152 |
-
$emptystring = '<strong>'.__('Why do the results show 0 URLs updated?','velvet-blues-update-urls').'</strong><br/>'.__('This happens if a URL is incorrect OR if it is not found in the content. Check your URLs and try again.','velvet-blues-update-urls').'<br/><br/><strong>'.__('Want us to do it for you?','velvet-blues-update-urls').'</strong><br/>'.__('Contact us at','velvet-blues-update-urls').' <a href="mailto:info@velvetblues.com?subject=Move%20My%20WP%20Site">info@velvetblues.com</a>. '.__('We will backup your website and move it for $65 OR simply update your URLs for only $29.','velvet-blues-update-urls');
|
153 |
-
|
154 |
-
$resultstring = '';
|
155 |
-
foreach($results as $result){
|
156 |
-
$empty = ($result[0] != 0 || $empty == false)? false : true;
|
157 |
-
$resultstring .= '<br/><strong>'.$result[0].'</strong> '.$result[1];
|
158 |
-
}
|
159 |
-
|
160 |
-
if( $empty ):
|
161 |
-
?>
|
162 |
-
<div id="message" class="error fade">
|
163 |
-
<table>
|
164 |
-
<tr>
|
165 |
-
<td><p><strong>
|
166 |
-
<?php _e('ERROR: Something may have gone wrong.','velvet-blues-update-urls'); ?>
|
167 |
-
</strong><br/>
|
168 |
-
<?php _e('Your URLs have not been updated.','velvet-blues-update-urls'); ?>
|
169 |
-
</p>
|
170 |
-
<?php
|
171 |
-
else:
|
172 |
-
?>
|
173 |
-
<div id="message" class="updated fade">
|
174 |
-
<table>
|
175 |
-
<tr>
|
176 |
-
<td><p><strong>
|
177 |
-
<?php _e('Success! Your URLs have been updated.','velvet-blues-update-urls'); ?>
|
178 |
-
</strong></p>
|
179 |
-
<?php
|
180 |
-
endif;
|
181 |
-
?>
|
182 |
-
<p><u>
|
183 |
-
<?php _e('Results','velvet-blues-update-urls'); ?>
|
184 |
-
</u><?php echo $resultstring; ?></p>
|
185 |
-
<?php echo ($empty)? '<p>'.$emptystring.'</p>' : ''; ?></td>
|
186 |
-
<td width="60"></td>
|
187 |
-
<td align="center"><?php if( !$empty ): ?>
|
188 |
-
<p>
|
189 |
-
<?php //You can now uninstall this plugin.<br/> ?>
|
190 |
-
<?php printf(__('If you found our plugin useful, %s please consider donating','velvet-blues-update-urls'),'<br/>'); ?>.</p>
|
191 |
-
<p><a style="outline:none;" href="http://www.velvetblues.com/go/updateurlsdonate/" target="_blank"><img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" alt="PayPal -<?php _e('The safer, easier way to pay online!','velvet-blues-update-urls'); ?>"></a></p>
|
192 |
-
<?php endif; ?></td>
|
193 |
-
</tr>
|
194 |
-
</table>
|
195 |
-
</div>
|
196 |
-
<?php
|
197 |
-
}
|
198 |
-
else{
|
199 |
-
echo '<div id="message" class="error fade"><p><strong>'.__('ERROR','velvet-blues-update-urls').' - '.__('Your URLs have not been updated.','velvet-blues-update-urls').'</p></strong><p>'.__('Please enter values for both the old url and the new url.','velvet-blues-update-urls').'</p></div>';
|
200 |
-
}
|
201 |
-
}
|
202 |
-
?>
|
203 |
-
<div class="wrap">
|
204 |
-
<h2>Velvet Blues Update URLs</h2>
|
205 |
-
<form method="post" action="tools.php?page=<?php echo basename(__FILE__); ?>">
|
206 |
-
<?php wp_nonce_field('VBUU_submit','VBUU_nonce'); ?>
|
207 |
-
<p><?php printf(__("After moving a website, %s lets you fix old URLs in content, excerpts, links, and custom fields.",'velvet-blues-update-urls'),'<strong>Update URLs</strong>'); ?></p>
|
208 |
-
<p><strong>
|
209 |
-
<?php _e('WE RECOMMEND THAT YOU BACKUP YOUR WEBSITE.','velvet-blues-update-urls'); ?>
|
210 |
-
</strong><br/>
|
211 |
-
<?php _e('You may need to restore it if incorrect URLs are entered in the fields below.','velvet-blues-update-urls'); ?>
|
212 |
-
</p>
|
213 |
-
<h3 style="margin-bottom:5px;">
|
214 |
-
<?php _e('Step'); ?>
|
215 |
-
1:
|
216 |
-
<?php _e('Enter your URLs in the fields below','velvet-blues-update-urls'); ?>
|
217 |
-
</h3>
|
218 |
-
<table class="form-table">
|
219 |
-
<tr valign="middle">
|
220 |
-
<th scope="row" width="140" style="width:140px"><strong>
|
221 |
-
<?php _e('Old URL','velvet-blues-update-urls'); ?>
|
222 |
-
</strong><br/>
|
223 |
-
<span class="description">
|
224 |
-
<?php _e('Old Site Address','velvet-blues-update-urls'); ?>
|
225 |
-
</span></th>
|
226 |
-
<td><input name="VBUU_oldurl" type="text" id="VBUU_oldurl" value="<?php echo (isset($vbuu_oldurl) && trim($vbuu_oldurl) != '')? $vbuu_oldurl : 'http://www.oldurl.com'; ?>" style="width:300px;font-size:20px;" onfocus="if(this.value=='http://www.oldurl.com') this.value='';" onblur="if(this.value=='') this.value='http://www.oldurl.com';" /></td>
|
227 |
-
</tr>
|
228 |
-
<tr valign="middle">
|
229 |
-
<th scope="row" width="140" style="width:140px"><strong>
|
230 |
-
<?php _e('New URL','velvet-blues-update-urls'); ?>
|
231 |
-
</strong><br/>
|
232 |
-
<span class="description">
|
233 |
-
<?php _e('New Site Address','velvet-blues-update-urls'); ?>
|
234 |
-
</span></th>
|
235 |
-
<td><input name="VBUU_newurl" type="text" id="VBUU_newurl" value="<?php echo (isset($vbuu_newurl) && trim($vbuu_newurl) != '')? $vbuu_newurl : 'http://www.newurl.com'; ?>" style="width:300px;font-size:20px;" onfocus="if(this.value=='http://www.newurl.com') this.value='';" onblur="if(this.value=='') this.value='http://www.newurl.com';" /></td>
|
236 |
-
</tr>
|
237 |
-
</table>
|
238 |
-
<br/>
|
239 |
-
<h3 style="margin-bottom:5px;">
|
240 |
-
<?php _e('Step'); ?>
|
241 |
-
2:
|
242 |
-
<?php _e('Choose which URLs should be updated','velvet-blues-update-urls'); ?>
|
243 |
-
</h3>
|
244 |
-
<table class="form-table">
|
245 |
-
<tr>
|
246 |
-
<td><p style="line-height:20px;">
|
247 |
-
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="content" checked="checked" />
|
248 |
-
<label for="VBUU_update_true"><strong>
|
249 |
-
<?php _e('URLs in page content','velvet-blues-update-urls'); ?>
|
250 |
-
</strong> (
|
251 |
-
<?php _e('posts, pages, custom post types, revisions','velvet-blues-update-urls'); ?>
|
252 |
-
)</label>
|
253 |
-
<br/>
|
254 |
-
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="excerpts" />
|
255 |
-
<label for="VBUU_update_true"><strong>
|
256 |
-
<?php _e('URLs in excerpts','velvet-blues-update-urls'); ?>
|
257 |
-
</strong></label>
|
258 |
-
<br/>
|
259 |
-
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="links" />
|
260 |
-
<label for="VBUU_update_true"><strong>
|
261 |
-
<?php _e('URLs in links','velvet-blues-update-urls'); ?>
|
262 |
-
</strong></label>
|
263 |
-
<br/>
|
264 |
-
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="attachments" />
|
265 |
-
<label for="VBUU_update_true"><strong>
|
266 |
-
<?php _e('URLs for attachments','velvet-blues-update-urls'); ?>
|
267 |
-
</strong> (
|
268 |
-
<?php _e('images, documents, general media','velvet-blues-update-urls'); ?>
|
269 |
-
)</label>
|
270 |
-
<br/>
|
271 |
-
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="custom" />
|
272 |
-
<label for="VBUU_update_true"><strong>
|
273 |
-
<?php _e('URLs in custom fields and meta boxes','velvet-blues-update-urls'); ?>
|
274 |
-
</strong></label>
|
275 |
-
<br/>
|
276 |
-
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="guids" />
|
277 |
-
<label for="VBUU_update_true"><strong>
|
278 |
-
<?php _e('Update ALL GUIDs','velvet-blues-update-urls'); ?>
|
279 |
-
</strong> <span class="description" style="color:#f00;">
|
280 |
-
<?php _e('GUIDs for posts should only be changed on development sites.','velvet-blues-update-urls'); ?>
|
281 |
-
</span> <a href="http://www.velvetblues.com/go/guids/" target="_blank">
|
282 |
-
<?php _e('Learn More.','velvet-blues-update-urls'); ?>
|
283 |
-
</a></label>
|
284 |
-
</p></td>
|
285 |
-
</tr>
|
286 |
-
</table>
|
287 |
-
<p>
|
288 |
-
<input class="button-primary" name="VBUU_settings_submit" value="<?php _e('Update URLs NOW','velvet-blues-update-urls'); ?>" type="submit" />
|
289 |
-
</p>
|
290 |
-
</form>
|
291 |
-
<p> <br/>
|
292 |
-
<strong>
|
293 |
-
<?php _e('Need help?','velvet-blues-update-urls'); ?>
|
294 |
-
</strong> <?php printf(__("Get support at the %s plugin page%s.",'velvet-blues-update-urls'),'<a href="http://www.velvetblues.com/web-development-blog/wordpress-plugin-update-urls/" target="_blank">Velvet Blues Update URLs','</a>'); ?>
|
295 |
-
<?php if( !isset( $empty ) ): ?>
|
296 |
-
<br/>
|
297 |
-
<strong>
|
298 |
-
<?php _e('Want us to do it for you?','velvet-blues-update-urls'); ?>
|
299 |
-
</strong>
|
300 |
-
<?php _e('Contact us at','velvet-blues-update-urls'); ?>
|
301 |
-
<a href="mailto:info@velvetblues.com?subject=Move%20My%20WP%20Site">info@velvetblues.com</a>.
|
302 |
-
<?php _e('We will backup your website and move it for $65 OR update your URLs for only $29.','velvet-blues-update-urls'); ?>
|
303 |
-
<?php endif; ?>
|
304 |
-
</p>
|
305 |
-
<?php
|
306 |
-
}
|
307 |
-
add_action('admin_menu', 'VelvetBluesUU_add_management_page');
|
308 |
-
add_action('admin_init','VelvetBluesUU_load_textdomain');
|
309 |
-
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Velvet Blues Update URLs
|
4 |
+
Plugin URI: http://www.velvetblues.com/web-development-blog/wordpress-plugin-update-urls/
|
5 |
+
Description: This plugin <strong>updates all urls in your website</strong> by replacing old urls with new urls. To get started: 1) Click the "Activate" link to the left of this description, and 2) Go to your <a href="tools.php?page=velvet-blues-update-urls.php">Update URLs</a> page to use it.
|
6 |
+
Author: VelvetBlues.com
|
7 |
+
Author URI: http://www.velvetblues.com/
|
8 |
+
Author Email: info@velvetblues.com
|
9 |
+
Version: 3.2.3
|
10 |
+
License: GPLv2 or later
|
11 |
+
Text Domain: velvet-blues-update-urls
|
12 |
+
*/
|
13 |
+
/* Copyright 2014 Velvet Blues Web Design (email : info@velvetblues.com)
|
14 |
+
|
15 |
+
This program is free software; you can redistribute it and/or
|
16 |
+
modify it under the terms of the GNU General Public License
|
17 |
+
as published by the Free Software Foundation; either version 2
|
18 |
+
of the License, or (at your option) any later version.
|
19 |
+
|
20 |
+
This program is distributed in the hope that it will be useful,
|
21 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
GNU General Public License for more details.
|
24 |
+
|
25 |
+
You should have received a copy of the GNU General Public License
|
26 |
+
along with this program; if not, write to the Free Software
|
27 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
+
*/
|
29 |
+
if ( !function_exists( 'add_action' ) ) {
|
30 |
+
?>
|
31 |
+
<h3>Oops! This page cannot be accessed directly.</h3>
|
32 |
+
<p>For support using the Velvet Blues Update URLs plugin, <a href="http://www.velvetblues.com/web-development-blog/wordpress-plugin-update-urls/" title="Velvet Blues Update URLs WordPress plugin">click here</a>.</p>
|
33 |
+
<p>If you are looking for general WordPress assistance, <a href="http://www.velvetblues.com/" title="WordPress Web Development and Services">Velvet Blues can help with that too</a>.</p>
|
34 |
+
<?php
|
35 |
+
exit;
|
36 |
+
}
|
37 |
+
function VelvetBluesUU_add_management_page(){
|
38 |
+
add_management_page("Velvet Blues Update URLs", "Update URLs", "manage_options", basename(__FILE__), "VelvetBluesUU_management_page");
|
39 |
+
}
|
40 |
+
function VelvetBluesUU_load_textdomain(){
|
41 |
+
load_plugin_textdomain( 'velvet-blues-update-urls', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
42 |
+
}
|
43 |
+
function VelvetBluesUU_management_page(){
|
44 |
+
function VB_update_urls($options,$oldurl,$newurl){
|
45 |
+
global $wpdb;
|
46 |
+
$results = array();
|
47 |
+
$queries = array(
|
48 |
+
'content' => array("UPDATE $wpdb->posts SET post_content = replace(post_content, %s, %s)", __('Content Items (Posts, Pages, Custom Post Types, Revisions)','velvet-blues-update-urls') ),
|
49 |
+
'excerpts' => array("UPDATE $wpdb->posts SET post_excerpt = replace(post_excerpt, %s, %s)", __('Excerpts','velvet-blues-update-urls') ),
|
50 |
+
'attachments' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s) WHERE post_type = 'attachment'", __('Attachments','velvet-blues-update-urls') ),
|
51 |
+
'links' => array("UPDATE $wpdb->links SET link_url = replace(link_url, %s, %s)", __('Links','velvet-blues-update-urls') ),
|
52 |
+
'custom' => array("UPDATE $wpdb->postmeta SET meta_value = replace(meta_value, %s, %s)", __('Custom Fields','velvet-blues-update-urls') ),
|
53 |
+
'guids' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s)", __('GUIDs','velvet-blues-update-urls') )
|
54 |
+
);
|
55 |
+
foreach($options as $option){
|
56 |
+
if( $option == 'custom' ){
|
57 |
+
$n = 0;
|
58 |
+
$row_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta" );
|
59 |
+
$page_size = 10000;
|
60 |
+
$pages = ceil( $row_count / $page_size );
|
61 |
+
|
62 |
+
for( $page = 0; $page < $pages; $page++ ) {
|
63 |
+
$current_row = 0;
|
64 |
+
$start = $page * $page_size;
|
65 |
+
$end = $start + $page_size;
|
66 |
+
$pmquery = "SELECT * FROM $wpdb->postmeta WHERE meta_value <> ''";
|
67 |
+
$items = $wpdb->get_results( $pmquery );
|
68 |
+
foreach( $items as $item ){
|
69 |
+
$value = $item->meta_value;
|
70 |
+
if( trim($value) == '' )
|
71 |
+
continue;
|
72 |
+
|
73 |
+
$edited = VB_unserialize_replace( $oldurl, $newurl, $value );
|
74 |
+
|
75 |
+
if( $edited != $value ){
|
76 |
+
$fix = $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '".$edited."' WHERE meta_id = ".$item->meta_id );
|
77 |
+
if( $fix )
|
78 |
+
$n++;
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
$results[$option] = array($n, $queries[$option][1]);
|
83 |
+
}
|
84 |
+
else{
|
85 |
+
$result = $wpdb->query( $wpdb->prepare( $queries[$option][0], $oldurl, $newurl) );
|
86 |
+
$results[$option] = array($result, $queries[$option][1]);
|
87 |
+
}
|
88 |
+
}
|
89 |
+
return $results;
|
90 |
+
}
|
91 |
+
function VB_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
|
92 |
+
try {
|
93 |
+
if ( is_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) {
|
94 |
+
$data = VB_unserialize_replace( $from, $to, $unserialized, true );
|
95 |
+
}
|
96 |
+
elseif ( is_array( $data ) ) {
|
97 |
+
$_tmp = array( );
|
98 |
+
foreach ( $data as $key => $value ) {
|
99 |
+
$_tmp[ $key ] = VB_unserialize_replace( $from, $to, $value, false );
|
100 |
+
}
|
101 |
+
$data = $_tmp;
|
102 |
+
unset( $_tmp );
|
103 |
+
}
|
104 |
+
else {
|
105 |
+
if ( is_string( $data ) )
|
106 |
+
$data = str_replace( $from, $to, $data );
|
107 |
+
}
|
108 |
+
if ( $serialised )
|
109 |
+
return serialize( $data );
|
110 |
+
} catch( Exception $error ) {
|
111 |
+
}
|
112 |
+
return $data;
|
113 |
+
}
|
114 |
+
if ( isset( $_POST['VBUU_settings_submit'] ) && !check_admin_referer('VBUU_submit','VBUU_nonce')){
|
115 |
+
if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
|
116 |
+
if(function_exists('esc_attr')){
|
117 |
+
$vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
|
118 |
+
$vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
|
119 |
+
}else{
|
120 |
+
$vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
|
121 |
+
$vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
|
122 |
+
}
|
123 |
+
}
|
124 |
+
echo '<div id="message" class="error fade"><p><strong>'.__('ERROR','velvet-blues-update-urls').' - '.__('Please try again.','velvet-blues-update-urls').'</strong></p></div>';
|
125 |
+
}
|
126 |
+
elseif( isset( $_POST['VBUU_settings_submit'] ) && !isset( $_POST['VBUU_update_links'] ) ){
|
127 |
+
if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
|
128 |
+
if(function_exists('esc_attr')){
|
129 |
+
$vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
|
130 |
+
$vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
|
131 |
+
}else{
|
132 |
+
$vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
|
133 |
+
$vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
|
134 |
+
}
|
135 |
+
}
|
136 |
+
echo '<div id="message" class="error fade"><p><strong>'.__('ERROR','velvet-blues-update-urls').' - '.__('Your URLs have not been updated.','velvet-blues-update-urls').'</p></strong><p>'.__('Please select at least one checkbox.','velvet-blues-update-urls').'</p></div>';
|
137 |
+
}
|
138 |
+
elseif( isset( $_POST['VBUU_settings_submit'] ) ){
|
139 |
+
$vbuu_update_links = $_POST['VBUU_update_links'];
|
140 |
+
if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
|
141 |
+
if(function_exists('esc_attr')){
|
142 |
+
$vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
|
143 |
+
$vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
|
144 |
+
}else{
|
145 |
+
$vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
|
146 |
+
$vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
|
147 |
+
}
|
148 |
+
}
|
149 |
+
if(($vbuu_oldurl && $vbuu_oldurl != 'http://www.oldurl.com' && trim($vbuu_oldurl) != '') && ($vbuu_newurl && $vbuu_newurl != 'http://www.newurl.com' && trim($vbuu_newurl) != '')){
|
150 |
+
$results = VB_update_urls($vbuu_update_links,$vbuu_oldurl,$vbuu_newurl);
|
151 |
+
$empty = true;
|
152 |
+
$emptystring = '<strong>'.__('Why do the results show 0 URLs updated?','velvet-blues-update-urls').'</strong><br/>'.__('This happens if a URL is incorrect OR if it is not found in the content. Check your URLs and try again.','velvet-blues-update-urls').'<br/><br/><strong>'.__('Want us to do it for you?','velvet-blues-update-urls').'</strong><br/>'.__('Contact us at','velvet-blues-update-urls').' <a href="mailto:info@velvetblues.com?subject=Move%20My%20WP%20Site">info@velvetblues.com</a>. '.__('We will backup your website and move it for $65 OR simply update your URLs for only $29.','velvet-blues-update-urls');
|
153 |
+
|
154 |
+
$resultstring = '';
|
155 |
+
foreach($results as $result){
|
156 |
+
$empty = ($result[0] != 0 || $empty == false)? false : true;
|
157 |
+
$resultstring .= '<br/><strong>'.$result[0].'</strong> '.$result[1];
|
158 |
+
}
|
159 |
+
|
160 |
+
if( $empty ):
|
161 |
+
?>
|
162 |
+
<div id="message" class="error fade">
|
163 |
+
<table>
|
164 |
+
<tr>
|
165 |
+
<td><p><strong>
|
166 |
+
<?php _e('ERROR: Something may have gone wrong.','velvet-blues-update-urls'); ?>
|
167 |
+
</strong><br/>
|
168 |
+
<?php _e('Your URLs have not been updated.','velvet-blues-update-urls'); ?>
|
169 |
+
</p>
|
170 |
+
<?php
|
171 |
+
else:
|
172 |
+
?>
|
173 |
+
<div id="message" class="updated fade">
|
174 |
+
<table>
|
175 |
+
<tr>
|
176 |
+
<td><p><strong>
|
177 |
+
<?php _e('Success! Your URLs have been updated.','velvet-blues-update-urls'); ?>
|
178 |
+
</strong></p>
|
179 |
+
<?php
|
180 |
+
endif;
|
181 |
+
?>
|
182 |
+
<p><u>
|
183 |
+
<?php _e('Results','velvet-blues-update-urls'); ?>
|
184 |
+
</u><?php echo $resultstring; ?></p>
|
185 |
+
<?php echo ($empty)? '<p>'.$emptystring.'</p>' : ''; ?></td>
|
186 |
+
<td width="60"></td>
|
187 |
+
<td align="center"><?php if( !$empty ): ?>
|
188 |
+
<p>
|
189 |
+
<?php //You can now uninstall this plugin.<br/> ?>
|
190 |
+
<?php printf(__('If you found our plugin useful, %s please consider donating','velvet-blues-update-urls'),'<br/>'); ?>.</p>
|
191 |
+
<p><a style="outline:none;" href="http://www.velvetblues.com/go/updateurlsdonate/" target="_blank"><img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" alt="PayPal -<?php _e('The safer, easier way to pay online!','velvet-blues-update-urls'); ?>"></a></p>
|
192 |
+
<?php endif; ?></td>
|
193 |
+
</tr>
|
194 |
+
</table>
|
195 |
+
</div>
|
196 |
+
<?php
|
197 |
+
}
|
198 |
+
else{
|
199 |
+
echo '<div id="message" class="error fade"><p><strong>'.__('ERROR','velvet-blues-update-urls').' - '.__('Your URLs have not been updated.','velvet-blues-update-urls').'</p></strong><p>'.__('Please enter values for both the old url and the new url.','velvet-blues-update-urls').'</p></div>';
|
200 |
+
}
|
201 |
+
}
|
202 |
+
?>
|
203 |
+
<div class="wrap">
|
204 |
+
<h2>Velvet Blues Update URLs</h2>
|
205 |
+
<form method="post" action="tools.php?page=<?php echo basename(__FILE__); ?>">
|
206 |
+
<?php wp_nonce_field('VBUU_submit','VBUU_nonce'); ?>
|
207 |
+
<p><?php printf(__("After moving a website, %s lets you fix old URLs in content, excerpts, links, and custom fields.",'velvet-blues-update-urls'),'<strong>Update URLs</strong>'); ?></p>
|
208 |
+
<p><strong>
|
209 |
+
<?php _e('WE RECOMMEND THAT YOU BACKUP YOUR WEBSITE.','velvet-blues-update-urls'); ?>
|
210 |
+
</strong><br/>
|
211 |
+
<?php _e('You may need to restore it if incorrect URLs are entered in the fields below.','velvet-blues-update-urls'); ?>
|
212 |
+
</p>
|
213 |
+
<h3 style="margin-bottom:5px;">
|
214 |
+
<?php _e('Step'); ?>
|
215 |
+
1:
|
216 |
+
<?php _e('Enter your URLs in the fields below','velvet-blues-update-urls'); ?>
|
217 |
+
</h3>
|
218 |
+
<table class="form-table">
|
219 |
+
<tr valign="middle">
|
220 |
+
<th scope="row" width="140" style="width:140px"><strong>
|
221 |
+
<?php _e('Old URL','velvet-blues-update-urls'); ?>
|
222 |
+
</strong><br/>
|
223 |
+
<span class="description">
|
224 |
+
<?php _e('Old Site Address','velvet-blues-update-urls'); ?>
|
225 |
+
</span></th>
|
226 |
+
<td><input name="VBUU_oldurl" type="text" id="VBUU_oldurl" value="<?php echo (isset($vbuu_oldurl) && trim($vbuu_oldurl) != '')? $vbuu_oldurl : 'http://www.oldurl.com'; ?>" style="width:300px;font-size:20px;" onfocus="if(this.value=='http://www.oldurl.com') this.value='';" onblur="if(this.value=='') this.value='http://www.oldurl.com';" /></td>
|
227 |
+
</tr>
|
228 |
+
<tr valign="middle">
|
229 |
+
<th scope="row" width="140" style="width:140px"><strong>
|
230 |
+
<?php _e('New URL','velvet-blues-update-urls'); ?>
|
231 |
+
</strong><br/>
|
232 |
+
<span class="description">
|
233 |
+
<?php _e('New Site Address','velvet-blues-update-urls'); ?>
|
234 |
+
</span></th>
|
235 |
+
<td><input name="VBUU_newurl" type="text" id="VBUU_newurl" value="<?php echo (isset($vbuu_newurl) && trim($vbuu_newurl) != '')? $vbuu_newurl : 'http://www.newurl.com'; ?>" style="width:300px;font-size:20px;" onfocus="if(this.value=='http://www.newurl.com') this.value='';" onblur="if(this.value=='') this.value='http://www.newurl.com';" /></td>
|
236 |
+
</tr>
|
237 |
+
</table>
|
238 |
+
<br/>
|
239 |
+
<h3 style="margin-bottom:5px;">
|
240 |
+
<?php _e('Step'); ?>
|
241 |
+
2:
|
242 |
+
<?php _e('Choose which URLs should be updated','velvet-blues-update-urls'); ?>
|
243 |
+
</h3>
|
244 |
+
<table class="form-table">
|
245 |
+
<tr>
|
246 |
+
<td><p style="line-height:20px;">
|
247 |
+
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="content" checked="checked" />
|
248 |
+
<label for="VBUU_update_true"><strong>
|
249 |
+
<?php _e('URLs in page content','velvet-blues-update-urls'); ?>
|
250 |
+
</strong> (
|
251 |
+
<?php _e('posts, pages, custom post types, revisions','velvet-blues-update-urls'); ?>
|
252 |
+
)</label>
|
253 |
+
<br/>
|
254 |
+
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="excerpts" />
|
255 |
+
<label for="VBUU_update_true"><strong>
|
256 |
+
<?php _e('URLs in excerpts','velvet-blues-update-urls'); ?>
|
257 |
+
</strong></label>
|
258 |
+
<br/>
|
259 |
+
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="links" />
|
260 |
+
<label for="VBUU_update_true"><strong>
|
261 |
+
<?php _e('URLs in links','velvet-blues-update-urls'); ?>
|
262 |
+
</strong></label>
|
263 |
+
<br/>
|
264 |
+
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="attachments" />
|
265 |
+
<label for="VBUU_update_true"><strong>
|
266 |
+
<?php _e('URLs for attachments','velvet-blues-update-urls'); ?>
|
267 |
+
</strong> (
|
268 |
+
<?php _e('images, documents, general media','velvet-blues-update-urls'); ?>
|
269 |
+
)</label>
|
270 |
+
<br/>
|
271 |
+
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="custom" />
|
272 |
+
<label for="VBUU_update_true"><strong>
|
273 |
+
<?php _e('URLs in custom fields and meta boxes','velvet-blues-update-urls'); ?>
|
274 |
+
</strong></label>
|
275 |
+
<br/>
|
276 |
+
<input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="guids" />
|
277 |
+
<label for="VBUU_update_true"><strong>
|
278 |
+
<?php _e('Update ALL GUIDs','velvet-blues-update-urls'); ?>
|
279 |
+
</strong> <span class="description" style="color:#f00;">
|
280 |
+
<?php _e('GUIDs for posts should only be changed on development sites.','velvet-blues-update-urls'); ?>
|
281 |
+
</span> <a href="http://www.velvetblues.com/go/guids/" target="_blank">
|
282 |
+
<?php _e('Learn More.','velvet-blues-update-urls'); ?>
|
283 |
+
</a></label>
|
284 |
+
</p></td>
|
285 |
+
</tr>
|
286 |
+
</table>
|
287 |
+
<p>
|
288 |
+
<input class="button-primary" name="VBUU_settings_submit" value="<?php _e('Update URLs NOW','velvet-blues-update-urls'); ?>" type="submit" />
|
289 |
+
</p>
|
290 |
+
</form>
|
291 |
+
<p> <br/>
|
292 |
+
<strong>
|
293 |
+
<?php _e('Need help?','velvet-blues-update-urls'); ?>
|
294 |
+
</strong> <?php printf(__("Get support at the %s plugin page%s.",'velvet-blues-update-urls'),'<a href="http://www.velvetblues.com/web-development-blog/wordpress-plugin-update-urls/" target="_blank">Velvet Blues Update URLs','</a>'); ?>
|
295 |
+
<?php if( !isset( $empty ) ): ?>
|
296 |
+
<br/>
|
297 |
+
<strong>
|
298 |
+
<?php _e('Want us to do it for you?','velvet-blues-update-urls'); ?>
|
299 |
+
</strong>
|
300 |
+
<?php _e('Contact us at','velvet-blues-update-urls'); ?>
|
301 |
+
<a href="mailto:info@velvetblues.com?subject=Move%20My%20WP%20Site">info@velvetblues.com</a>.
|
302 |
+
<?php _e('We will backup your website and move it for $65 OR update your URLs for only $29.','velvet-blues-update-urls'); ?>
|
303 |
+
<?php endif; ?>
|
304 |
+
</p>
|
305 |
+
<?php
|
306 |
+
}
|
307 |
+
add_action('admin_menu', 'VelvetBluesUU_add_management_page');
|
308 |
+
add_action('admin_init','VelvetBluesUU_load_textdomain');
|
309 |
+
?>
|