Go Live Update URLS - Version 2.0

Version Description

  • Made updating the options table seralized safe *
  • Add extending ability of views and css *
  • Moved the Admin page to the Tools Section *
  • Improved the structure to allow for future changes *
Download this release

Release Info

Developer Mat Lipe
Plugin Icon 128x128 Go Live Update URLS
Version 2.0
Comparing to
See all releases

Code changes from version 1.5 to 2.0

go-live-functions.php DELETED
@@ -1,128 +0,0 @@
1
- <?php
2
-
3
-
4
- /**
5
- * options page
6
- */
7
- function gluu_add_url_options(){
8
- add_options_page("Go Live Setings", "Go Live", "manage_options", basename(__FILE__), "gluu_url_options_page");
9
- }
10
-
11
- function gluu_url_options_page(){
12
- global $table_prefix;
13
-
14
- //If the Form has been submitted make the updates
15
- if( isset( $_POST['submit'] ) ){
16
- $oldurl = trim( strip_tags( $_POST['oldurl'] ) );
17
- $newurl = trim( strip_tags( $_POST['newurl'] ) );
18
-
19
- if( gluu_make_the_updates($oldurl, $newurl) ){
20
- echo '<div id="message" class="updated fade"><p><strong>URLs have been updated.</p></strong></div>';
21
- } else {
22
- echo '<div class="error"><p><strong>You must fill out both boxes to make the update!</p></strong></div>';
23
- }
24
- }
25
- $pr = strtoupper($table_prefix);
26
-
27
- ?>
28
- <div class="wrap">
29
- <h2>Go Live Update Urls</h2>
30
- <form method="post" action="options-general.php?page=<?php echo basename(__FILE__); ?>">
31
- <p>This will replace all occurrences "in the entire database" of the old URL with the New URL. <br />Uncheck any tables that you would not like to update.</p>
32
- <h4> THIS DOES NOT UPDATE THE <?php echo $pr; ?>OPTIONS TABLE BY DEFAULT DUE TO WIDGET ISSUES. <br>
33
- YOU MUST MANUALLY CHANGE YOUR SITES URL IN THE DASHBOARD'S GENERAL SETTINGS BEFORE RUNNING THIS PLUGIN! <br>
34
- IF YOU MUST UPDATE THE <?php echo $pr; ?>OPTIONS TABLE, RUN THIS PLUGIN THEN CLICK SAVE AT THE BOTTOM ON ALL YOUR WIDGETS, <br>
35
- THEN RUN THIS PLUGIN WITH THE <?php echo $pr; ?>OPTIONS BOX CHECKED.</h4>
36
- <em>Like any other database updating tool, you should always perfrom a backup before running.</em><br>
37
-
38
- <?php
39
- //Make the boxes to select tables
40
- gluu_make_checked_boxes();
41
- ?>
42
- <table class="form-table">
43
- <tr>
44
- <th scope="row" style="width:150px;"><b>Old URL</b></th>
45
- <td><input name="oldurl" type="text" id="oldurl" value="" style="width:300px;" /></td>
46
- </tr>
47
- <tr>
48
- <th scope="row" style="width:150px;"><b>New URL</b></th>
49
- <td><input name="newurl" type="text" id="newurl" value="" style="width:300px;" /></td>
50
- </tr>
51
- </table>
52
- <p class="submit">
53
- <input name="submit" value="Make it Happen" type="submit" />
54
- </p>
55
- </form>
56
- <?php
57
-
58
- } // end of the options_page function
59
-
60
-
61
-
62
-
63
- /**
64
- * Creates a list of checkboxes for each table
65
- */
66
- function gluu_make_checked_boxes(){
67
- global $wpdb, $table_prefix;
68
- $god_query = "SELECT TABLE_NAME FROM information_schema.TABLES where TABLE_SCHEMA='".$wpdb->dbname."'";
69
- $all = $wpdb->get_results($god_query);
70
- echo '<br>';
71
- foreach($all as $v){
72
- if($v->TABLE_NAME != $table_prefix .'options'):
73
- printf('<input name="%s" type="checkbox" value="%s" checked /> %s<br>',$v->TABLE_NAME,$v->TABLE_NAME,$v->TABLE_NAME);
74
- else:
75
- printf('<input name="%s" type="checkbox" value="%s" /> %s<br>',$v->TABLE_NAME,$v->TABLE_NAME,$v->TABLE_NAME);
76
- endif;
77
- }
78
-
79
- }
80
-
81
- /**
82
- * Updates the datbase
83
- * @param string $oldurl the old domain
84
- * @param string $newurl the new domain
85
- * @since 7/20/12
86
- */
87
- function gluu_make_the_updates($oldurl, $newurl){
88
- global $wpdb;
89
- //If a box was empty
90
- if( $oldurl == '' || $newurl == '' ){
91
- return false;
92
- }
93
-
94
- // If the new domain is the old one with a new subdomain like www
95
- if( strpos($newurl, $oldurl) != false) {
96
- list( $subdomain ) = explode( '.', $newurl );
97
- $double_subdomain = $subdomain . '.' . $newurl; //Create a match to what the broken one will be
98
- }
99
-
100
-
101
- //Go throuch each table sent to be updated
102
- foreach($_POST as $v => $i){
103
- if($v != 'submit' && $v != 'oldurl' && $v != 'newurl'){
104
-
105
- $god_query = "SELECT COLUMN_NAME FROM information_schema.COLUMNS where TABLE_SCHEMA='".$wpdb->dbname."' and TABLE_NAME='".$v."'";
106
- $all = $wpdb->get_results($god_query);
107
- foreach($all as $t){
108
- $update_query = "UPDATE ".$v." SET ".$t->COLUMN_NAME." = replace(".$t->COLUMN_NAME.", '".$oldurl."','".$newurl."')";
109
- //Run the query
110
- $wpdb->query($update_query);
111
-
112
- //Fix the dub dubs if this was the old domain with a new sub
113
- if( isset( $double_subdomain ) ){
114
- $update_query = "UPDATE ".$v." SET ".$t->COLUMN_NAME." = replace(".$t->COLUMN_NAME.", '".$double_subdomain."','".$newurl."')";
115
- //Run the query
116
- $wpdb->query($update_query);
117
-
118
- //Fix the emails breaking by being appended the new subdomain
119
- $update_query = "UPDATE ".$v." SET ".$t->COLUMN_NAME." = replace(".$t->COLUMN_NAME.", '@".$newurl."','@".$oldurl."')";
120
- $wpdb->query($update_query);
121
- }
122
-
123
- }
124
- }
125
- }
126
- return true;
127
- }
128
-
go-live-update-urls.php CHANGED
@@ -5,21 +5,15 @@ Plugin URI: http://lipeimagination.info/
5
Description: This Plugin Updates all the URLs in the database to point to the new URL when making your site live or changing domains.
6
Author: Mat Lipe
7
Author URI: http://lipeimagination/
8
- Version: 1.5
9
*/
10
- /*
11
- Mat Lipe (mat@lipeimagination.info);
12
13
- At Lipe Imagination We believe that information should be free.
14
- Feel free to do whatever you want with this code as long as your do
15
- not replicate the name of the Plugin or try to pass off something else
16
- as an actual Lipe Imagination Script.
17
-
18
- */
19
-
20
- //Bring in the functions
21
- require('go-live-functions.php');
22
23
- //Add the settings to the admin menu
24
- add_action('admin_menu', 'gluu_add_url_options');
25
5
Description: This Plugin Updates all the URLs in the database to point to the new URL when making your site live or changing domains.
6
Author: Mat Lipe
7
Author URI: http://lipeimagination/
8
+ Version: 2.0
9
*/
10
11
+ define( 'GLUU_VIEWS_DIR', plugin_dir_path(__FILE__) . 'views/' );
12
+ define( 'GLUU_URL_VIEWS_DIR', plugins_url('go-live-update-urls').'/views/' );
13
+ ;
14
15
+ require('lib/GoLiveUpdateUrls.php');
16
17
+
18
+ $GoLiveUpdateUrls = new GoLiveUpdateUrls();
19
+
lib/GoLiveUpdateUrls.php ADDED
@@ -0,0 +1,253 @@
1
+ <?php
2
+ /**
3
+ * Methods for the Go Live Update Urls Plugin
4
+ * @author Mat Lipe
5
+ * @since 2.0
6
+ *
7
+ * @TODO Cleanup the Names and formatting
8
+ */
9
+ class GoLiveUpdateUrls{
10
+ var $oldurl = false;
11
+ var $newurl = false;
12
+ var $double_subdomain = false; //keep track if going to a subdomain
13
+
14
+ /**
15
+ * @since 2.0
16
+ */
17
+ function __construct(){
18
+ //Add the settings to the admin menu
19
+ add_action('admin_menu', array( $this,'gluu_add_url_options') );
20
+
21
+ //Add the CSS
22
+ add_action( 'admin_head', array( $this,'css') );
23
+ }
24
+
25
+ /**
26
+ * For adding Css to the admin
27
+ *
28
+ * @since 2.0
29
+ */
30
+ function css(){
31
+ ?><style type="text/css"><?php
32
+ include( $this->fileHyercy('go-live-update-urls.css') );
33
+ ?></style><?php
34
+
35
+ }
36
+
37
+
38
+ /**
39
+ * Menu Under Tools Menu
40
+ *
41
+ * @since 2.0
42
+ */
43
+ function gluu_add_url_options(){
44
+ add_management_page("go-live-setting", "Go Live", "manage_options", basename(__FILE__), array( $this,"adminToolsPage") );
45
+ }
46
+
47
+
48
+
49
+
50
+ /**
51
+ * Output the Admin Page for using this plugin
52
+ *
53
+ * @since 2.0
54
+ *
55
+ */
56
+ function adminToolsPage(){
57
+ global $table_prefix;
58
+
59
+ //If the Form has been submitted make the updates
60
+ if( isset( $_POST['gluu-submit'] ) ){
61
+ $this->oldurl = trim( strip_tags( $_POST['oldurl'] ) );
62
+ $this->newurl = trim( strip_tags( $_POST['newurl'] ) );
63
+
64
+ if( $this->gluu_make_the_updates() ){
65
+ echo '<div id="message" class="updated fade"><p><strong>URLs have been updated.</p></strong></div>';
66
+ } else {
67
+ echo '<div class="error"><p><strong>You must fill out both boxes to make the update!</p></strong></div>';
68
+ }
69
+ }
70
+
71
+ require( $this->fileHyercy('admin-tools-page.php') );
72
+ }
73
+
74
+
75
+ /**
76
+ * Allows for Overwritting files in the child theme
77
+ * @since 2.0
78
+ * @param string $file the name of the file to overwrite
79
+ *
80
+ * @param bool $url if the file is being used for a url
81
+ */
82
+ function fileHyercy( $file , $url = false){
83
+ if ( !$theme_file = locate_template(array('go-live-update-urls/'.$file)) ) {
84
+ $theme_file = GLUU_VIEWS_DIR . $file;
85
+ }
86
+ return $theme_file;
87
+
88
+ }
89
+
90
+
91
+
92
+ /**
93
+ * Creates a list of checkboxes for each table
94
+ *
95
+ * @since 2.0
96
+ * @uses by the view admin-tools-page.php
97
+ *
98
+ * @filter 'gluu_table_checkboxes' with 2 param
99
+ * * $output - the html formatted checkboxes
100
+ * * $tables - the complete tables object
101
+ *
102
+ *
103
+ */
104
+ function makeCheckBoxes(){
105
+ global $wpdb;
106
+ $god_query = "SELECT TABLE_NAME FROM information_schema.TABLES where TABLE_SCHEMA='".$wpdb->dbname."'";
107
+ $tables = $wpdb->get_results($god_query);
108
+
109
+ $output = '<ul id="gluu-checkboxes">';
110
+ foreach($tables as $v){
111
+ if($v->TABLE_NAME == $wpdb->options):
112
+ $output .= sprintf('<li><input name="%s" type="checkbox" value="%s" checked /> %s - <strong><em>Seralized Safe</strong></em></li>',$v->TABLE_NAME,$v->TABLE_NAME,$v->TABLE_NAME);
113
+ else:
114
+ $output .= sprintf('<li><input name="%s" type="checkbox" value="%s" checked /> %s</li>',$v->TABLE_NAME,$v->TABLE_NAME,$v->TABLE_NAME);
115
+ endif;
116
+ }
117
+
118
+ $output .= '</ul>';
119
+
120
+ return apply_filters('gluu_table_checkboxes', $output, $tables );
121
+
122
+
123
+ }
124
+
125
+ /**
126
+ * Updates the datbase
127
+ *
128
+ * @uses the oldurl and newurl set above
129
+ * @since 2.27.13
130
+ */
131
+ function gluu_make_the_updates(){
132
+ global $wpdb;
133
+
134
+ $oldurl = $this->oldurl;
135
+ $newurl = $this->newurl;
136
+
137
+ //If a box was empty
138
+ if( $oldurl == '' || $newurl == '' ){
139
+ return false;
140
+ }
141
+
142
+ // If the new domain is the old one with a new subdomain like www
143
+ if( strpos($newurl, $oldurl) != false) {
144
+ list( $subdomain ) = explode( '.', $newurl );
145
+ $this->double_subdomain = $subdomain . '.' . $newurl; //Create a match to what the broken one will be
146
+ }
147
+
148
+
149
+ //Go throuch each table sent to be updated
150
+ foreach($_POST as $v => $i){
151
+
152
+ //Send the options table through the seralized safe Update
153
+ if( $v == $wpdb->options ){
154
+ $this->UpdateSeralizedTable($wpdb->options, 'option_value');
155
+ }
156
+
157
+ if($v != 'submit' && $v != 'oldurl' && $v != 'newurl'){
158
+
159
+ $god_query = "SELECT COLUMN_NAME FROM information_schema.COLUMNS where TABLE_SCHEMA='".$wpdb->dbname."' and TABLE_NAME='".$v."'";
160
+ $all = $wpdb->get_results($god_query);
161
+ foreach($all as $t){
162
+ $update_query = "UPDATE ".$v." SET ".$t->COLUMN_NAME." = replace(".$t->COLUMN_NAME.", '".$oldurl."','".$newurl."')";
163
+ //Run the query
164
+ $wpdb->query($update_query);
165
+
166
+ //Fix the dub dubs if this was the old domain with a new sub
167
+ if( isset( $this->double_subdomain ) ){
168
+ $update_query = "UPDATE ".$v." SET ".$t->COLUMN_NAME." = replace(".$t->COLUMN_NAME.", '".$this->double_subdomain."','".$newurl."')";
169
+ //Run the query
170
+ $wpdb->query($update_query);
171
+
172
+ //Fix the emails breaking by being appended the new subdomain
173
+ $update_query = "UPDATE ".$v." SET ".$t->COLUMN_NAME." = replace(".$t->COLUMN_NAME.", '@".$newurl."','@".$oldurl."')";
174
+ $wpdb->query($update_query);
175
+ }
176
+
177
+ }
178
+ }
179
+ }
180
+ return true;
181
+ }
182
+
183
+
184
+ /**
185
+ * Goes through a table line by line and updates it
186
+ *
187
+ * @uses for tables which may contain seralized arrays
188
+ * @since 2.0
189
+ *
190
+ * @param string $table the table to go through
191
+ * @param string $column to column in the table to go through
192
+ *
193
+ */
194
+ function UpdateSeralizedTable( $table, $column = false ){
195
+ global $wpdb;
196
+ $pk = $wpdb->get_results("SHOW KEYS FROM $table WHERE Key_name = 'PRIMARY'");
197
+ $primary_key_column = $pk[0]->Column_name;
198
+
199
+ //Get all the Seralized Rows and Replace them properly
200
+ $rows = $wpdb->get_results("SELECT $primary_key_column, $column FROM $table WHERE $column LIKE 'a:%' OR $column LIKE 'o:%'");
201
+
202
+ foreach( $rows as $row ){
203
+ if( is_bool($data = @unserialize($row->{$column})) ) continue;
204
+
205
+ $clean = $this->replaceTree($data, $this->oldurl, $this->newurl);
206
+ //If we switch to a submain we have to run this again to remove the doubles
207
+ if( $this->double_subdomain ){
208
+ $clean = $this->replaceTree($clean, $this->double_subdomain, $this->newurl);
209
+ }
210
+
211
+ //Add the newly seralized array back into the database
212
+ $wpdb->query("UPDATE $table SET $column='".serialize($clean)."' WHERE $primary_key_column='".$row->{$primary_key_column}."'");
213
+
214
+ }
215
+ }
216
+
217
+
218
+
219
+ /**
220
+ * Replaces all the occurances of a string in a multi dementional array or Object
221
+ *
222
+ * @uses itself to call each level of the array
223
+ * @since 2.0
224
+ *
225
+ * @param array|object|string $data to change
226
+ * @param string $old the old string
227
+ * @param string $new the new string
228
+ * @param bool [optional] $changeKeys to replace string in keys as well - defaults to false
229
+ *
230
+ */
231
+ function replaceTree( $data, $old, $new, $changeKeys = false ){
232
+ if( !($is_array = is_array( $data )) && !is_object( $data) ){
233
+ return str_replace( $old, $new, $data );
234
+ }
235
+
236
+ foreach( $data as $key => $item ){
237
+ if( $changeKeys ){
238
+ $key = str_replace( $old, $new, $key );
239
+ }
240
+
241
+ if( $is_array ){
242
+ $data[$key] = $this->replaceTree($item, $old, $new);
243
+ } else {
244
+ $data->{$key} = $this->replaceTree($item, $old, $new);
245
+ }
246
+ }
247
+ return $data;
248
+ }
249
+
250
+
251
+
252
+
253
+ }
readme.txt CHANGED
@@ -3,14 +3,33 @@ Contributors: Mat Lipe
3
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40lipeimagination%2einfo&lc=US&item_name=Go%20Live%20Update%20Urls&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
4
Tags: Go Live, Urls, Domain Changes
5
Requires at least: 3.1
6
- Tested up to: 3.4.1
7
- Stable tag: 1.5
8
9
== Description ==
10
11
- Goes through the entire database and replaces all instances of the test domain at Go Live time. Can also be used to replace all instances when changing domains.
12
13
- Allows table by table selection for any issues with widgets/plugins and such.
14
15
16
== Installation ==
@@ -27,11 +46,19 @@ e.g.
27
28
= Where do you use this plugin? =
29
30
- Under the settings menu in the dashboard there will be a "Go Live" link.
31
32
- = Why does this one uncheck the wp_options table by default? =
33
34
- There are a few plugins out there that use certain values in the wp-options table which will break of they are changed manually in the database. Sometimes widgets will disappear. If you have some values that must be changed in the wp_options, I have found that you can prevent the disappearing widget problem by going through all of your widgets and clicking save on the bottom of them after you have changed the domain in general settings. You may then run the Update with the wp_options checked. This method is not fool proof, but it has worked on a few instances I have seen an actual need for updated the wp_options table manually.
35
36
37
@@ -40,6 +67,11 @@ There are a few plugins out there that use certain values in the wp-options tabl
40
1. Screenshot of a tyical settings page. The verbage will change slightly depending on your database structure
41
42
== Changelog ==
43
44
= 1.5 =
45
* Added support for automatically keeping email addresses intact when switching to a subdomain like www
3
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40lipeimagination%2einfo&lc=US&item_name=Go%20Live%20Update%20Urls&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest
4
Tags: Go Live, Urls, Domain Changes
5
Requires at least: 3.1
6
+ Tested up to: 3.5.1
7
+ Stable tag: 2.0
8
9
== Description ==
10
11
+ Goes through entire site and replaces all instances of and old url with a new one. Used to change the domain of a site.
12
13
+ Some of the features this plugin offers:
14
+
15
+ * Database table by table selection in case of issues
16
+ * Supports seralized data in the options table
17
+ * Very easy to use admin page - which may be found under Tools
18
+
19
+ Updates Entire Site including:
20
+
21
+ * Posts
22
+ * Pages
23
+ * Image urls
24
+ * Excerpts
25
+ * Post Meta data
26
+ * Custom Post Types
27
+ * Widgets and widget data
28
+ * Site settings
29
+ * And much more
30
+
31
+ The admin screen is extendable for developers familiar with using filters or template overrides.
32
+
33
34
35
== Installation ==
46
47
= Where do you use this plugin? =
48
49
+ Under the Tools menu in the dashboard there will be a "Go Live" link.
50
+
51
+ = Why does updating the domain break some plugins? =
52
+
53
+ Some plugins will store the data in the database seralized which does not allow for easy updating of the data. You may uncheck tables used by such plugins to avoid breakage and then update the urls manually for those plugins. There are future plans to allow for seralized safe updating via table by table selection but currently the only table that is safe is the options table
54
+
55
+ = How do I know which tables I should not update? =
56
+
57
+ Most tables will be just fine to update. You may make a backup of your database, run this on all tables and if you run into trouble, restore your database, uncheck tables in sections, and rerun this until you find the culpurit. If you find a particular table gives you trouble, let me know and I will add it to the urgent list for seralized safe updating.
58
+
59
+
60
61
62
63
64
67
1. Screenshot of a tyical settings page. The verbage will change slightly depending on your database structure
68
69
== Changelog ==
70
+ = 2.0 =
71
+ * Made updating the options table seralized safe *
72
+ * Add extending ability of views and css *
73
+ * Moved the Admin page to the Tools Section *
74
+ * Improved the structure to allow for future changes *
75
76
= 1.5 =
77
* Added support for automatically keeping email addresses intact when switching to a subdomain like www
views/admin-tools-page.php ADDED
@@ -0,0 +1,34 @@
1
+ <div id="gluu" class="wrap">
2
+ <?php screen_icon('options-general'); ?>
3
+ <h2>Go Live Update Urls</h2>
4
+
5
+ <h4> This will replace all occurrences "in the entire database" of the old URL with the New URL.
6
+ <br />
7
+ Uncheck any tables that you would not like to update. </h4>
8
+ <div class="error fade"><h4> Please Uncheck any Tables which may contain seralized data. The only table which is currently seralized data safe when using this plugin is <?php echo $table_prefix; ?>options.</h4></div>
9
+ <strong><em>Like any other database updating tool, you should always perfrom a backup before running.</em></strong>
10
+ <br>
11
+
12
+ <form method="post">
13
+ <?php //Make the boxes to select tables
14
+ echo $this->makeCheckBoxes();
15
+ ?>
16
+ <table class="form-table">
17
+ <tr>
18
+ <th scope="row" style="width:150px;"><b>Old URL</b></th>
19
+ <td>
20
+ <input name="oldurl" type="text" id="oldurl" value="" style="width:300px;" />
21
+ </td>
22
+ </tr>
23
+ <tr>
24
+ <th scope="row" style="width:150px;"><b>New URL</b></th>
25
+ <td>
26
+ <input name="newurl" type="text" id="newurl" value="" style="width:300px;" />
27
+ </td>
28
+ </tr>
29
+ </table>
30
+ <p class="submit">
31
+ <?php submit_button('Make it Happen', 'primary', 'gluu-submit'); ?>
32
+ </p>
33
+ </form>
34
+ </div>
views/go-live-update-urls.css ADDED
@@ -0,0 +1,36 @@
1
+ #gluu{
2
+ background: black;
3
+ padding: 25px;
4
+ width: 520px;
5
+ border-radius: 20px;
6
+ color: white;
7
+ -moz-box-shadow: 0 0 5px 5px #888;
8
+ -webkit-box-shadow: 0 0 5px 5px#888;
9
+ box-shadow: 0 0 5px 5px #888;
10
+ margin: 40px 0 0 40px;
11
+ }
12
+
13
+ #gluu .error{
14
+ color: #000000;
15
+ }
16
+
17
+ #gluu h2{
18
+ color: white;
19
+ text-shadow: blue 0 1px 0;
20
+ }
21
+
22
+ #gluu .form-table b{
23
+ font-size: 16px;
24
+ color: white;
25
+ text-shadow: blue 0 1px 0;
26
+ }
27
+
28
+ #gluu input[type="text"]{
29
+ font-weight: bold;
30
+ padding: 6px;
31
+ }
32
+
33
+ #gluu .updated{
34
+ color: black;
35
+ }
36
+