Velvet Blues Update URLs - Version 3.2.10

Version Description

  • Confirmed compatibility with WordPress 5.2.x, 5.3.x, 5.4.x and 5.5.x releases.
  • Version Update.
Download this release

Release Info

Developer VelvetBlues.com
Plugin Icon wp plugin Velvet Blues Update URLs
Version 3.2.10
Comparing to
See all releases

Code changes from version 3.2.9 to 3.2.10

Files changed (2) hide show
  1. readme.txt +7 -3
  2. velvet-blues-update-urls.php +308 -308
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Velvet Blues Update URLs ===
2
  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: 4.5
6
- Tested up to: 5.1
7
- Stable tag: 3.2.9
8
  License: GPLv2 or later
9
 
10
  Updates all urls and content links in your website.
@@ -64,6 +64,10 @@ Make sure that the plugin is activated and that you are an administrator level u
64
 
65
  == Change Log ==
66
 
 
 
 
 
67
  = 3.2.9 =
68
  * Confirmed compatibility with WordPress 5.1.x releases.
69
  * Version Update.
1
  === Velvet Blues Update URLs ===
2
  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, website migration, migration, site move
5
  Requires at least: 4.5
6
+ Tested up to: 5.5.1
7
+ Stable tag: 3.2.10
8
  License: GPLv2 or later
9
 
10
  Updates all urls and content links in your website.
64
 
65
  == Change Log ==
66
 
67
+ = 3.2.10 =
68
+ * Confirmed compatibility with WordPress 5.2.x, 5.3.x, 5.4.x and 5.5.x releases.
69
+ * Version Update.
70
+
71
  = 3.2.9 =
72
  * Confirmed compatibility with WordPress 5.1.x releases.
73
  * Version Update.
velvet-blues-update-urls.php CHANGED
@@ -1,308 +1,308 @@
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.9
10
- License: GPLv2 or later
11
- Text Domain: velvet-blues-update-urls
12
- */
13
- /* Copyright 2019 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' ) ) { exit;
30
- }
31
- function VelvetBluesUU_add_management_page(){
32
- add_management_page("Velvet Blues Update URLs", "Update URLs", "manage_options", basename(__FILE__), "VelvetBluesUU_management_page");
33
- }
34
- function VelvetBluesUU_load_textdomain(){
35
- load_plugin_textdomain( 'velvet-blues-update-urls', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
36
- }
37
- function VelvetBluesUU_management_page(){
38
- if ( !function_exists( 'VB_update_urls' ) ) {
39
- function VB_update_urls($options,$oldurl,$newurl){
40
- global $wpdb;
41
- $results = array();
42
- $queries = array(
43
- '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') ),
44
- 'excerpts' => array("UPDATE $wpdb->posts SET post_excerpt = replace(post_excerpt, %s, %s)", __('Excerpts','velvet-blues-update-urls') ),
45
- 'attachments' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s) WHERE post_type = 'attachment'", __('Attachments','velvet-blues-update-urls') ),
46
- 'links' => array("UPDATE $wpdb->links SET link_url = replace(link_url, %s, %s)", __('Links','velvet-blues-update-urls') ),
47
- 'custom' => array("UPDATE $wpdb->postmeta SET meta_value = replace(meta_value, %s, %s)", __('Custom Fields','velvet-blues-update-urls') ),
48
- 'guids' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s)", __('GUIDs','velvet-blues-update-urls') )
49
- );
50
- foreach($options as $option){
51
- if( $option == 'custom' ){
52
- $n = 0;
53
- $row_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta" );
54
- $page_size = 10000;
55
- $pages = ceil( $row_count / $page_size );
56
-
57
- for( $page = 0; $page < $pages; $page++ ) {
58
- $current_row = 0;
59
- $start = $page * $page_size;
60
- $end = $start + $page_size;
61
- $pmquery = "SELECT * FROM $wpdb->postmeta WHERE meta_value <> ''";
62
- $items = $wpdb->get_results( $pmquery );
63
- foreach( $items as $item ){
64
- $value = $item->meta_value;
65
- if( trim($value) == '' )
66
- continue;
67
-
68
- $edited = VB_unserialize_replace( $oldurl, $newurl, $value );
69
-
70
- if( $edited != $value ){
71
- $fix = $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '".$edited."' WHERE meta_id = ".$item->meta_id );
72
- if( $fix )
73
- $n++;
74
- }
75
- }
76
- }
77
- $results[$option] = array($n, $queries[$option][1]);
78
- }
79
- else{
80
- $result = $wpdb->query( $wpdb->prepare( $queries[$option][0], $oldurl, $newurl) );
81
- $results[$option] = array($result, $queries[$option][1]);
82
- }
83
- }
84
- return $results;
85
- }
86
- }
87
- if ( !function_exists( 'VB_unserialize_replace' ) ) {
88
- function VB_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
89
- try {
90
- if ( false !== is_serialized( $data ) ) {
91
- $unserialized = unserialize( $data );
92
- $data = VB_unserialize_replace( $from, $to, $unserialized, true );
93
- }
94
- elseif ( is_array( $data ) ) {
95
- $_tmp = array( );
96
- foreach ( $data as $key => $value ) {
97
- $_tmp[ $key ] = VB_unserialize_replace( $from, $to, $value, false );
98
- }
99
- $data = $_tmp;
100
- unset( $_tmp );
101
- }
102
- else {
103
- if ( is_string( $data ) )
104
- $data = str_replace( $from, $to, $data );
105
- }
106
- if ( $serialised )
107
- return serialize( $data );
108
- } catch( Exception $error ) {
109
- }
110
- return $data;
111
- }
112
- }
113
- if ( isset( $_POST['VBUU_settings_submit'] ) && !check_admin_referer('VBUU_submit','VBUU_nonce')){
114
- if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
115
- if(function_exists('esc_attr')){
116
- $vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
117
- $vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
118
- }else{
119
- $vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
120
- $vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
121
- }
122
- }
123
- echo '<div id="message" class="error fade"><p><strong>'.__('ERROR','velvet-blues-update-urls').' - '.__('Please try again.','velvet-blues-update-urls').'</strong></p></div>';
124
- }
125
- elseif( isset( $_POST['VBUU_settings_submit'] ) && !isset( $_POST['VBUU_update_links'] ) ){
126
- if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
127
- if(function_exists('esc_attr')){
128
- $vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
129
- $vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
130
- }else{
131
- $vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
132
- $vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
133
- }
134
- }
135
- 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>';
136
- }
137
- elseif( isset( $_POST['VBUU_settings_submit'] ) ){
138
- $vbuu_update_links = $_POST['VBUU_update_links'];
139
- if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
140
- if(function_exists('esc_attr')){
141
- $vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
142
- $vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
143
- }else{
144
- $vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
145
- $vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
146
- }
147
- }
148
- if(($vbuu_oldurl && $vbuu_oldurl != 'http://www.oldurl.com' && trim($vbuu_oldurl) != '') && ($vbuu_newurl && $vbuu_newurl != 'http://www.newurl.com' && trim($vbuu_newurl) != '')){
149
- $results = VB_update_urls($vbuu_update_links,$vbuu_oldurl,$vbuu_newurl);
150
- $empty = true;
151
- $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 $75 OR simply update your URLs for only $39.','velvet-blues-update-urls');
152
-
153
- $resultstring = '';
154
- foreach($results as $result){
155
- $empty = ($result[0] != 0 || $empty == false)? false : true;
156
- $resultstring .= '<br/><strong>'.$result[0].'</strong> '.$result[1];
157
- }
158
-
159
- if( $empty ):
160
- ?>
161
- <div id="message" class="error fade">
162
- <table>
163
- <tr>
164
- <td><p><strong>
165
- <?php _e('ERROR: Something may have gone wrong.','velvet-blues-update-urls'); ?>
166
- </strong><br/>
167
- <?php _e('Your URLs have not been updated.','velvet-blues-update-urls'); ?>
168
- </p>
169
- <?php
170
- else:
171
- ?>
172
- <div id="message" class="updated fade">
173
- <table>
174
- <tr>
175
- <td><p><strong>
176
- <?php _e('Success! Your URLs have been updated.','velvet-blues-update-urls'); ?>
177
- </strong></p>
178
- <?php
179
- endif;
180
- ?>
181
- <p><u>
182
- <?php _e('Results','velvet-blues-update-urls'); ?>
183
- </u><?php echo $resultstring; ?></p>
184
- <?php echo ($empty)? '<p>'.$emptystring.'</p>' : ''; ?></td>
185
- <td width="60"></td>
186
- <td align="center"><?php if( !$empty ): ?>
187
- <p>
188
- <?php //You can now uninstall this plugin.<br/> ?>
189
- <?php printf(__('If you found our plugin useful, %s please consider donating','velvet-blues-update-urls'),'<br/>'); ?>.</p>
190
- <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>
191
- <?php endif; ?></td>
192
- </tr>
193
- </table>
194
- </div>
195
- <?php
196
- }
197
- else{
198
- 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>';
199
- }
200
- }
201
- ?>
202
- <div class="wrap">
203
- <h2>Velvet Blues Update URLs</h2>
204
- <form method="post" action="tools.php?page=<?php echo basename(__FILE__); ?>">
205
- <?php wp_nonce_field('VBUU_submit','VBUU_nonce'); ?>
206
- <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>
207
- <p><strong>
208
- <?php _e('WE RECOMMEND THAT YOU BACKUP YOUR WEBSITE.','velvet-blues-update-urls'); ?>
209
- </strong><br/>
210
- <?php _e('You may need to restore it if incorrect URLs are entered in the fields below.','velvet-blues-update-urls'); ?>
211
- </p>
212
- <h3 style="margin-bottom:5px;">
213
- <?php _e('Step'); ?>
214
- 1:
215
- <?php _e('Enter your URLs in the fields below','velvet-blues-update-urls'); ?>
216
- </h3>
217
- <table class="form-table">
218
- <tr valign="middle">
219
- <th scope="row" width="140" style="width:140px"><strong>
220
- <?php _e('Old URL','velvet-blues-update-urls'); ?>
221
- </strong><br/>
222
- <span class="description">
223
- <?php _e('Old Site Address','velvet-blues-update-urls'); ?>
224
- </span></th>
225
- <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>
226
- </tr>
227
- <tr valign="middle">
228
- <th scope="row" width="140" style="width:140px"><strong>
229
- <?php _e('New URL','velvet-blues-update-urls'); ?>
230
- </strong><br/>
231
- <span class="description">
232
- <?php _e('New Site Address','velvet-blues-update-urls'); ?>
233
- </span></th>
234
- <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>
235
- </tr>
236
- </table>
237
- <br/>
238
- <h3 style="margin-bottom:5px;">
239
- <?php _e('Step'); ?>
240
- 2:
241
- <?php _e('Choose which URLs should be updated','velvet-blues-update-urls'); ?>
242
- </h3>
243
- <table class="form-table">
244
- <tr>
245
- <td><p style="line-height:20px;">
246
- <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="content" checked="checked" />
247
- <label for="VBUU_update_true"><strong>
248
- <?php _e('URLs in page content','velvet-blues-update-urls'); ?>
249
- </strong> (
250
- <?php _e('posts, pages, custom post types, revisions','velvet-blues-update-urls'); ?>
251
- )</label>
252
- <br/>
253
- <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true1" value="excerpts" />
254
- <label for="VBUU_update_true1"><strong>
255
- <?php _e('URLs in excerpts','velvet-blues-update-urls'); ?>
256
- </strong></label>
257
- <br/>
258
- <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true2" value="links" />
259
- <label for="VBUU_update_true2"><strong>
260
- <?php _e('URLs in links','velvet-blues-update-urls'); ?>
261
- </strong></label>
262
- <br/>
263
- <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true3" value="attachments" />
264
- <label for="VBUU_update_true3"><strong>
265
- <?php _e('URLs for attachments','velvet-blues-update-urls'); ?>
266
- </strong> (
267
- <?php _e('images, documents, general media','velvet-blues-update-urls'); ?>
268
- )</label>
269
- <br/>
270
- <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true4" value="custom" />
271
- <label for="VBUU_update_true4"><strong>
272
- <?php _e('URLs in custom fields and meta boxes','velvet-blues-update-urls'); ?>
273
- </strong></label>
274
- <br/>
275
- <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true5" value="guids" />
276
- <label for="VBUU_update_true5"><strong>
277
- <?php _e('Update ALL GUIDs','velvet-blues-update-urls'); ?>
278
- </strong> <span class="description" style="color:#f00;">
279
- <?php _e('GUIDs for posts should only be changed on development sites.','velvet-blues-update-urls'); ?>
280
- </span> <a href="http://codex.wordpress.org/Changing_The_Site_URL#Important_GUID_Note" target="_blank">
281
- <?php _e('Learn More.','velvet-blues-update-urls'); ?>
282
- </a></label>
283
- </p></td>
284
- </tr>
285
- </table>
286
- <p>
287
- <input class="button-primary" name="VBUU_settings_submit" value="<?php _e('Update URLs NOW','velvet-blues-update-urls'); ?>" type="submit" />
288
- </p>
289
- </form>
290
- <p>&nbsp;<br/>
291
- <strong>
292
- <?php _e('Need help?','velvet-blues-update-urls'); ?>
293
- </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>'); ?>
294
- <?php if( !isset( $empty ) ): ?>
295
- <br/>
296
- <strong>
297
- <?php _e('Want us to do it for you?','velvet-blues-update-urls'); ?>
298
- </strong>
299
- <?php _e('Contact us at','velvet-blues-update-urls'); ?>
300
- <a href="mailto:info@velvetblues.com?subject=Move%20My%20WP%20Site">info@velvetblues.com</a>.
301
- <?php _e('We will backup your website and move it for $75 OR update your URLs for only $29.','velvet-blues-update-urls'); ?>
302
- <?php endif; ?>
303
- </p>
304
- <?php
305
- }
306
- add_action('admin_menu', 'VelvetBluesUU_add_management_page');
307
- add_action('admin_init','VelvetBluesUU_load_textdomain');
308
- ?>
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
10
+ License: GPLv2 or later
11
+ Text Domain: velvet-blues-update-urls
12
+ */
13
+ /* Copyright 2020 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' ) ) { exit;
30
+ }
31
+ function VelvetBluesUU_add_management_page(){
32
+ add_management_page("Velvet Blues Update URLs", "Update URLs", "manage_options", basename(__FILE__), "VelvetBluesUU_management_page");
33
+ }
34
+ function VelvetBluesUU_load_textdomain(){
35
+ load_plugin_textdomain( 'velvet-blues-update-urls', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
36
+ }
37
+ function VelvetBluesUU_management_page(){
38
+ if ( !function_exists( 'VB_update_urls' ) ) {
39
+ function VB_update_urls($options,$oldurl,$newurl){
40
+ global $wpdb;
41
+ $results = array();
42
+ $queries = array(
43
+ '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') ),
44
+ 'excerpts' => array("UPDATE $wpdb->posts SET post_excerpt = replace(post_excerpt, %s, %s)", __('Excerpts','velvet-blues-update-urls') ),
45
+ 'attachments' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s) WHERE post_type = 'attachment'", __('Attachments','velvet-blues-update-urls') ),
46
+ 'links' => array("UPDATE $wpdb->links SET link_url = replace(link_url, %s, %s)", __('Links','velvet-blues-update-urls') ),
47
+ 'custom' => array("UPDATE $wpdb->postmeta SET meta_value = replace(meta_value, %s, %s)", __('Custom Fields','velvet-blues-update-urls') ),
48
+ 'guids' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s)", __('GUIDs','velvet-blues-update-urls') )
49
+ );
50
+ foreach($options as $option){
51
+ if( $option == 'custom' ){
52
+ $n = 0;
53
+ $row_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta" );
54
+ $page_size = 10000;
55
+ $pages = ceil( $row_count / $page_size );
56
+
57
+ for( $page = 0; $page < $pages; $page++ ) {
58
+ $current_row = 0;
59
+ $start = $page * $page_size;
60
+ $end = $start + $page_size;
61
+ $pmquery = "SELECT * FROM $wpdb->postmeta WHERE meta_value <> ''";
62
+ $items = $wpdb->get_results( $pmquery );
63
+ foreach( $items as $item ){
64
+ $value = $item->meta_value;
65
+ if( trim($value) == '' )
66
+ continue;
67
+
68
+ $edited = VB_unserialize_replace( $oldurl, $newurl, $value );
69
+
70
+ if( $edited != $value ){
71
+ $fix = $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '".$edited."' WHERE meta_id = ".$item->meta_id );
72
+ if( $fix )
73
+ $n++;
74
+ }
75
+ }
76
+ }
77
+ $results[$option] = array($n, $queries[$option][1]);
78
+ }
79
+ else{
80
+ $result = $wpdb->query( $wpdb->prepare( $queries[$option][0], $oldurl, $newurl) );
81
+ $results[$option] = array($result, $queries[$option][1]);
82
+ }
83
+ }
84
+ return $results;
85
+ }
86
+ }
87
+ if ( !function_exists( 'VB_unserialize_replace' ) ) {
88
+ function VB_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
89
+ try {
90
+ if ( false !== is_serialized( $data ) ) {
91
+ $unserialized = unserialize( $data );
92
+ $data = VB_unserialize_replace( $from, $to, $unserialized, true );
93
+ }
94
+ elseif ( is_array( $data ) ) {
95
+ $_tmp = array( );
96
+ foreach ( $data as $key => $value ) {
97
+ $_tmp[ $key ] = VB_unserialize_replace( $from, $to, $value, false );
98
+ }
99
+ $data = $_tmp;
100
+ unset( $_tmp );
101
+ }
102
+ else {
103
+ if ( is_string( $data ) )
104
+ $data = str_replace( $from, $to, $data );
105
+ }
106
+ if ( $serialised )
107
+ return serialize( $data );
108
+ } catch( Exception $error ) {
109
+ }
110
+ return $data;
111
+ }
112
+ }
113
+ if ( isset( $_POST['VBUU_settings_submit'] ) && !check_admin_referer('VBUU_submit','VBUU_nonce')){
114
+ if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
115
+ if(function_exists('esc_attr')){
116
+ $vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
117
+ $vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
118
+ }else{
119
+ $vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
120
+ $vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
121
+ }
122
+ }
123
+ echo '<div id="message" class="error fade"><p><strong>'.__('ERROR','velvet-blues-update-urls').' - '.__('Please try again.','velvet-blues-update-urls').'</strong></p></div>';
124
+ }
125
+ elseif( isset( $_POST['VBUU_settings_submit'] ) && !isset( $_POST['VBUU_update_links'] ) ){
126
+ if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
127
+ if(function_exists('esc_attr')){
128
+ $vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
129
+ $vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
130
+ }else{
131
+ $vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
132
+ $vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
133
+ }
134
+ }
135
+ 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>';
136
+ }
137
+ elseif( isset( $_POST['VBUU_settings_submit'] ) ){
138
+ $vbuu_update_links = $_POST['VBUU_update_links'];
139
+ if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){
140
+ if(function_exists('esc_attr')){
141
+ $vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl']));
142
+ $vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl']));
143
+ }else{
144
+ $vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl']));
145
+ $vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl']));
146
+ }
147
+ }
148
+ if(($vbuu_oldurl && $vbuu_oldurl != 'http://www.oldurl.com' && trim($vbuu_oldurl) != '') && ($vbuu_newurl && $vbuu_newurl != 'http://www.newurl.com' && trim($vbuu_newurl) != '')){
149
+ $results = VB_update_urls($vbuu_update_links,$vbuu_oldurl,$vbuu_newurl);
150
+ $empty = true;
151
+ $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 $75 OR simply update your URLs for only $39.','velvet-blues-update-urls');
152
+
153
+ $resultstring = '';
154
+ foreach($results as $result){
155
+ $empty = ($result[0] != 0 || $empty == false)? false : true;
156
+ $resultstring .= '<br/><strong>'.$result[0].'</strong> '.$result[1];
157
+ }
158
+
159
+ if( $empty ):
160
+ ?>
161
+ <div id="message" class="error fade">
162
+ <table>
163
+ <tr>
164
+ <td><p><strong>
165
+ <?php _e('ERROR: Something may have gone wrong.','velvet-blues-update-urls'); ?>
166
+ </strong><br/>
167
+ <?php _e('Your URLs have not been updated.','velvet-blues-update-urls'); ?>
168
+ </p>
169
+ <?php
170
+ else:
171
+ ?>
172
+ <div id="message" class="updated fade">
173
+ <table>
174
+ <tr>
175
+ <td><p><strong>
176
+ <?php _e('Success! Your URLs have been updated.','velvet-blues-update-urls'); ?>
177
+ </strong></p>
178
+ <?php
179
+ endif;
180
+ ?>
181
+ <p><u>
182
+ <?php _e('Results','velvet-blues-update-urls'); ?>
183
+ </u><?php echo $resultstring; ?></p>
184
+ <?php echo ($empty)? '<p>'.$emptystring.'</p>' : ''; ?></td>
185
+ <td width="60"></td>
186
+ <td align="center"><?php if( !$empty ): ?>
187
+ <p>
188
+ <?php //You can now uninstall this plugin.<br/> ?>
189
+ <?php printf(__('If you found our plugin useful, %s please consider donating','velvet-blues-update-urls'),'<br/>'); ?>.</p>
190
+ <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>
191
+ <?php endif; ?></td>
192
+ </tr>
193
+ </table>
194
+ </div>
195
+ <?php
196
+ }
197
+ else{
198
+ 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>';
199
+ }
200
+ }
201
+ ?>
202
+ <div class="wrap">
203
+ <h2>Velvet Blues Update URLs</h2>
204
+ <form method="post" action="tools.php?page=<?php echo basename(__FILE__); ?>">
205
+ <?php wp_nonce_field('VBUU_submit','VBUU_nonce'); ?>
206
+ <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>
207
+ <p><strong>
208
+ <?php _e('WE RECOMMEND THAT YOU BACKUP YOUR WEBSITE.','velvet-blues-update-urls'); ?>
209
+ </strong><br/>
210
+ <?php _e('You may need to restore it if incorrect URLs are entered in the fields below.','velvet-blues-update-urls'); ?>
211
+ </p>
212
+ <h3 style="margin-bottom:5px;">
213
+ <?php _e('Step'); ?>
214
+ 1:
215
+ <?php _e('Enter your URLs in the fields below','velvet-blues-update-urls'); ?>
216
+ </h3>
217
+ <table class="form-table">
218
+ <tr valign="middle">
219
+ <th scope="row" width="140" style="width:140px"><strong>
220
+ <?php _e('Old URL','velvet-blues-update-urls'); ?>
221
+ </strong><br/>
222
+ <span class="description">
223
+ <?php _e('Old Site Address','velvet-blues-update-urls'); ?>
224
+ </span></th>
225
+ <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>
226
+ </tr>
227
+ <tr valign="middle">
228
+ <th scope="row" width="140" style="width:140px"><strong>
229
+ <?php _e('New URL','velvet-blues-update-urls'); ?>
230
+ </strong><br/>
231
+ <span class="description">
232
+ <?php _e('New Site Address','velvet-blues-update-urls'); ?>
233
+ </span></th>
234
+ <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>
235
+ </tr>
236
+ </table>
237
+ <br/>
238
+ <h3 style="margin-bottom:5px;">
239
+ <?php _e('Step'); ?>
240
+ 2:
241
+ <?php _e('Choose which URLs should be updated','velvet-blues-update-urls'); ?>
242
+ </h3>
243
+ <table class="form-table">
244
+ <tr>
245
+ <td><p style="line-height:20px;">
246
+ <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true" value="content" checked="checked" />
247
+ <label for="VBUU_update_true"><strong>
248
+ <?php _e('URLs in page content','velvet-blues-update-urls'); ?>
249
+ </strong> (
250
+ <?php _e('posts, pages, custom post types, revisions','velvet-blues-update-urls'); ?>
251
+ )</label>
252
+ <br/>
253
+ <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true1" value="excerpts" />
254
+ <label for="VBUU_update_true1"><strong>
255
+ <?php _e('URLs in excerpts','velvet-blues-update-urls'); ?>
256
+ </strong></label>
257
+ <br/>
258
+ <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true2" value="links" />
259
+ <label for="VBUU_update_true2"><strong>
260
+ <?php _e('URLs in links','velvet-blues-update-urls'); ?>
261
+ </strong></label>
262
+ <br/>
263
+ <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true3" value="attachments" />
264
+ <label for="VBUU_update_true3"><strong>
265
+ <?php _e('URLs for attachments','velvet-blues-update-urls'); ?>
266
+ </strong> (
267
+ <?php _e('images, documents, general media','velvet-blues-update-urls'); ?>
268
+ )</label>
269
+ <br/>
270
+ <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true4" value="custom" />
271
+ <label for="VBUU_update_true4"><strong>
272
+ <?php _e('URLs in custom fields and meta boxes','velvet-blues-update-urls'); ?>
273
+ </strong></label>
274
+ <br/>
275
+ <input name="VBUU_update_links[]" type="checkbox" id="VBUU_update_true5" value="guids" />
276
+ <label for="VBUU_update_true5"><strong>
277
+ <?php _e('Update ALL GUIDs','velvet-blues-update-urls'); ?>
278
+ </strong> <span class="description" style="color:#f00;">
279
+ <?php _e('GUIDs for posts should only be changed on development sites.','velvet-blues-update-urls'); ?>
280
+ </span> <a href="http://codex.wordpress.org/Changing_The_Site_URL#Important_GUID_Note" target="_blank">
281
+ <?php _e('Learn More.','velvet-blues-update-urls'); ?>
282
+ </a></label>
283
+ </p></td>
284
+ </tr>
285
+ </table>
286
+ <p>
287
+ <input class="button-primary" name="VBUU_settings_submit" value="<?php _e('Update URLs NOW','velvet-blues-update-urls'); ?>" type="submit" />
288
+ </p>
289
+ </form>
290
+ <p>&nbsp;<br/>
291
+ <strong>
292
+ <?php _e('Need help?','velvet-blues-update-urls'); ?>
293
+ </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>'); ?>
294
+ <?php if( !isset( $empty ) ): ?>
295
+ <br/>
296
+ <strong>
297
+ <?php _e('Want us to do it for you?','velvet-blues-update-urls'); ?>
298
+ </strong>
299
+ <?php _e('Contact us at','velvet-blues-update-urls'); ?>
300
+ <a href="mailto:info@velvetblues.com?subject=Move%20My%20WP%20Site">info@velvetblues.com</a>.
301
+ <?php _e('We will backup your website and move it for $75 OR update your URLs for only $29.','velvet-blues-update-urls'); ?>
302
+ <?php endif; ?>
303
+ </p>
304
+ <?php
305
+ }
306
+ add_action('admin_menu', 'VelvetBluesUU_add_management_page');
307
+ add_action('admin_init','VelvetBluesUU_load_textdomain');
308
+ ?>