Go Live Update URLS - Version 1.3

Version Description

  • Added support for adding subdomains like www
Download this release

Release Info

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

Code changes from version 1.2.1.1 to 1.3

Files changed (4) hide show
  1. go-live-functions.php +98 -19
  2. go-live-update-urls.php +8 -57
  3. readme.txt +12 -1
  4. screenshot-1.png +0 -0
go-live-functions.php CHANGED
@@ -1,44 +1,123 @@
1
  <?php
2
 
3
- # creates a list of checked boxes for each table
4
- function make_checked_boxes(){
5
- global $wpdb, $table_prefix;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  $god_query = "SELECT TABLE_NAME FROM information_schema.TABLES where TABLE_SCHEMA='".$wpdb->dbname."'";
7
-
8
  $all = $wpdb->get_results($god_query);
9
  echo '<br>';
10
  foreach($all as $v){
11
  if($v->TABLE_NAME != $table_prefix .'options'):
12
- printf('<input name="%s" type="checkbox" value="%s" checked /> %s<br>',$v->TABLE_NAME,$v->TABLE_NAME,$v->TABLE_NAME);
13
  else:
14
- printf('<input name="%s" type="checkbox" value="%s" /> %s<br>',$v->TABLE_NAME,$v->TABLE_NAME,$v->TABLE_NAME);
15
-
16
  endif;
17
  }
18
 
19
  }
20
 
21
- #--------------- Updates the database ----------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- function make_the_updates($oldurl, $newurl){
24
- global $wpdb;
25
  foreach($_POST as $v => $i){
26
  if($v != 'submit' && $v != 'oldurl' && $v != 'newurl'){
 
27
  $god_query = "SELECT COLUMN_NAME FROM information_schema.COLUMNS where TABLE_SCHEMA='".$wpdb->dbname."' and TABLE_NAME='".$v."'";
28
  $all = $wpdb->get_results($god_query);
29
-
30
-
31
  foreach($all as $t){
32
  $update_query = "UPDATE ".$v." SET ".$t->COLUMN_NAME." = replace(".$t->COLUMN_NAME.", '".$oldurl."','".$newurl."')";
33
-
34
  $wpdb->query($update_query);
 
 
 
 
 
 
 
35
  }
36
-
37
  }
38
-
39
  }
40
-
41
  }
42
-
43
-
44
- ?>
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
  }
 
119
  }
 
120
  }
121
+ return true;
122
  }
123
+
 
 
go-live-update-urls.php CHANGED
@@ -2,12 +2,13 @@
2
  /*
3
  Plugin Name: Go Live Update URLS
4
  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 channging domains.
6
  Author: Mat Lipe
7
  Author URI: http://lipeimagination/
8
- Version: 1.2.1.1
9
  */
10
- /* Copyright 2011 Mat Lipe (mat@lipeimagination.info);
 
11
 
12
  At Lipe Imagination We believe that information should be free.
13
  Feel free to do whatever you want with this code as long as your do
@@ -16,59 +17,9 @@ Version: 1.2.1.1
16
 
17
  */
18
 
 
 
19
 
20
- /* Functions for the options page */
21
- function add_url_options(){
22
- add_options_page("Go Live Setings", "Go Live", "manage_options", basename(__FILE__), "url_options_page");
23
- }
24
 
25
-
26
- function url_options_page(){
27
- require('go-live-functions.php');
28
-
29
- if( isset( $_POST['submit'] ) ){
30
- $oldurl = $_POST['oldurl'];
31
- $newurl = $_POST['newurl'];
32
- make_the_updates($oldurl, $newurl);
33
- // update_urls($update_links,$oldurl,$newurl);
34
- echo '<div id="message" class="updated fade"><p><strong>URLs have been updated.</p></strong><p>You can now uninstall this plugin.</p></div>';
35
- }
36
-
37
- global $table_prefix;
38
- $pr = strtoupper($table_prefix);
39
-
40
- ?>
41
- <div class="wrap">
42
- <h2>Go Live Update Urls</h2>
43
- <form method="post" action="options-general.php?page=<?php echo basename(__FILE__); ?>">
44
- <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>
45
- <h4> THIS DOES NOT UPDATE THE <?php echo $pr; ?>OPTIONS TABLE BY DEFAULT DUE TO WIDGET ISSUES. <br>
46
- YOU MUST MANUALLY CHANGE YOUR SITES URL IN THE DASHBOARD'S GENERAL SETTINGS BEFORE RUNNING THIS PLUGIN! <br>
47
- IF YOU MUST UPDATE THE <?php echo $pr; ?>OPTIONS TABLE, RUN THIS PLUGIN THEN CLICK SAVE AT THE BOTTOM ON ALL YOUR WIDGETS, <br>
48
- THEN RUN THIS PLUGIN WITH THE <?php echo $pr; ?>OPTIONS BOX CHECKED.</h4>
49
- <em>Like any other database updating tool, you should always perfrom a backup before running.</em><br>
50
- <?php make_checked_boxes(); ?>
51
- <table class="form-table">
52
- <tr>
53
- <th scope="row" style="width:150px;"><b>Old URL</b></th>
54
- <td>
55
- <input name="oldurl" type="text" id="oldurl" value="" style="width:300px;" />
56
- </td>
57
- </tr>
58
- <tr>
59
- <th scope="row" style="width:150px;"><b>New URL</b></th>
60
- <td>
61
- <input name="newurl" type="text" id="newurl" value="" style="width:300px;" />
62
- </td>
63
- </tr>
64
- </table>
65
- <p class="submit">
66
- <input name="submit" value="Make it Happen" type="submit" />
67
- </p>
68
- </form>
69
- <?php
70
-
71
- } // end of the options_page function
72
-
73
- add_action('admin_menu', 'add_url_options');
74
- ?>
2
  /*
3
  Plugin Name: Go Live Update URLS
4
  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.3
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
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypa
4
  Tags: Go Live, Urls, Domain Changes
5
  Requires at least: 3.1
6
  Tested up to: 3.4.1
7
- Stable tag: 1.2.1.1
8
 
9
  == Description ==
10
 
@@ -34,8 +34,16 @@ Under the settings menu in the dashboard there will be a "Go Live" link.
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
  == Changelog ==
38
 
 
 
 
39
  = 1.2.1 =
40
  * Added support for other prefixes besides wp_
41
 
@@ -47,6 +55,9 @@ There are a few plugins out there that use certain values in the wp-options tabl
47
 
48
  == Upgrade Notice ==
49
 
 
 
 
50
  = 1.2.1 =
51
  This Version will uncheck your options table by default for the wp_options as well as other table prefixes.
52
 
4
  Tags: Go Live, Urls, Domain Changes
5
  Requires at least: 3.1
6
  Tested up to: 3.4.1
7
+ Stable tag: 1.3
8
 
9
  == Description ==
10
 
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
+
38
+ == Screenshots ==
39
+
40
+ 1. Screenshot of a tyical settings page. The verbage will change slightly depending on your database structure
41
+
42
  == Changelog ==
43
 
44
+ = 1.3 =
45
+ * Added support for adding subdomains like www
46
+
47
  = 1.2.1 =
48
  * Added support for other prefixes besides wp_
49
 
55
 
56
  == Upgrade Notice ==
57
 
58
+ = 1.3 =
59
+ This Version will allow you to switch to www without having to run it twice
60
+
61
  = 1.2.1 =
62
  This Version will uncheck your options table by default for the wp_options as well as other table prefixes.
63
 
screenshot-1.png CHANGED
Binary file