Go Live Update URLS - Version 5.0.0

Version Description

  • Bring back PHP 5.2 support
  • Restructure entire codebase
  • Greatly improve security
  • Improve performance
  • UI improvements
  • Use strict WP coding standards
Download this release

Release Info

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

Code changes from version 4.0.1 to 5.0.0

go-live-update-urls.php CHANGED
@@ -1,27 +1,54 @@
1
- <?php
2
- /*
3
- Plugin Name: Go Live Update URLS
4
- Plugin URI: https://matlipe.com/go-live-update-urls/
5
- Description: 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: https://matlipe.com/
8
- Version: 4.0.1
9
- Text Domain: go-live-update-urls
10
- */
11
- define( 'GLUU_VERSION', "4.0.1" );
12
-
13
- define( 'GLUU_VIEWS_DIR', plugin_dir_path(__FILE__) . 'views/' );
14
- define( 'GLUU_URL_VIEWS_DIR', plugins_url('go-live-update-urls').'/views/' );
15
-
16
- require( plugin_dir_path( __FILE__ ) . '/src/GoLiveUpdateUrls.php' );
17
-
18
- add_action('plugins_loaded', 'gluu_load' );
19
- function gluu_load(){
20
- load_plugin_textdomain( 'go-live-update-urls', false, 'go-live-update-urls/languages' );
21
-
22
- GoLiveUpdateUrls::init();
23
-
24
- //backward compatibility
25
- global $GoLiveUpdateUrls;
26
- $GoLiveUpdateUrls = GoLiveUpdateUrls::get_instance();
27
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Go Live Update URLS
4
+ Plugin URI: https://matlipe.com/go-live-update-urls/
5
+ Description: 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: https://matlipe.com/
8
+ Version: 5.0.0
9
+ Text Domain: go-live-update-urls
10
+ */
11
+
12
+ define( 'GO_LIVE_UPDATE_URLS_VERSION', '5.0.0' );
13
+
14
+ /** Deprecated to be removed 6/1/18 */
15
+ require plugin_dir_path( __FILE__ ) . '/src/GoLiveUpdateUrls.php';
16
+
17
+ function go_live_update_urls_load() {
18
+ load_plugin_textdomain( 'go-live-update-urls', false, 'go-live-update-urls/languages' );
19
+
20
+ Go_Live_Update_Urls_Admin_Page::init();
21
+ }
22
+
23
+ /**
24
+ * Autoload classes from PSR4 src directory
25
+ * Mirrored after Composer dump-autoload for performance
26
+ *
27
+ * @param string $class
28
+ *
29
+ * @since 5.0.0
30
+ *
31
+ * @return void
32
+ */
33
+ function go_live_update_urls_autoload( $class ) {
34
+ $classes = array(
35
+ //core
36
+ 'Go_Live_Update_Urls_PHP_5_2_Mock_Class' => 'PHP_5_2_Mock_Class.php',
37
+ 'Go_Live_Update_Urls_Admin_Page' => 'Admin_Page.php',
38
+ 'Go_Live_Update_Urls_Core' => 'Core.php',
39
+ 'Go_Live_Update_Urls_Database' => 'Database.php',
40
+ //updaters
41
+ 'Go_Live_Update_Urls__Updaters__Abstract' => 'Updaters/Abstract.php',
42
+ 'Go_Live_Update_Urls__Updaters__JSON' => 'Updaters/JSON.php',
43
+ 'Go_Live_Update_Urls__Updaters__Repo' => 'Updaters/Repo.php',
44
+
45
+
46
+ );
47
+ if ( isset( $classes[ $class ] ) ) {
48
+ require dirname( __FILE__ ) . '/src/' . $classes[ $class ];
49
+ }
50
+ }
51
+
52
+ spl_autoload_register( 'go_live_update_urls_autoload' );
53
+
54
+ add_action( 'plugins_loaded', 'go_live_update_urls_load' );
languages/go-live-update-urls.pot CHANGED
@@ -1,121 +1,121 @@
1
- #, fuzzy
2
- msgid ""
3
- msgstr ""
4
- "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
5
- "Project-Id-Version: Go Live Update URLS\n"
6
- "POT-Creation-Date: 2016-05-15 10:48-0400\n"
7
- "PO-Revision-Date: 2016-05-15 10:47-0400\n"
8
- "Last-Translator: \n"
9
- "Language-Team: \n"
10
- "MIME-Version: 1.0\n"
11
- "Content-Type: text/plain; charset=UTF-8\n"
12
- "Content-Transfer-Encoding: 8bit\n"
13
- "X-Generator: Poedit 1.8.7\n"
14
- "X-Poedit-Basepath: ..\n"
15
- "X-Poedit-WPHeader: go-live-update-urls.php\n"
16
- "X-Poedit-SourceCharset: UTF-8\n"
17
- "X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
18
- "esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
19
- "_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
20
- "X-Poedit-SearchPath-0: .\n"
21
- "X-Poedit-SearchPathExcluded-0: *.js\n"
22
-
23
- #: src/GoLiveUpdateUrls.php:51
24
- msgid "Ouch! That hurt! You should not be here!"
25
- msgstr ""
26
-
27
- #: src/GoLiveUpdateUrls.php:74
28
- msgid "The URLS in the checked tables have been updated."
29
- msgstr ""
30
-
31
- #: src/GoLiveUpdateUrls.php:85
32
- msgid "You must fill out both boxes to make the update!."
33
- msgstr ""
34
-
35
- #: src/GoLiveUpdateUrls.php:203
36
- msgid "Serialized Safe"
37
- msgstr ""
38
-
39
- #: views/admin-tools-page.php:17
40
- #, php-format
41
- msgctxt "{<strong>}"
42
- msgid ""
43
- "This will replace all occurrences %sin the entire database%s of the Old URL "
44
- "with the New URL."
45
- msgstr ""
46
-
47
- #: views/admin-tools-page.php:22
48
- msgid ""
49
- "Like any other database updating tool, you should always perform a backup "
50
- "before running."
51
- msgstr ""
52
-
53
- #: views/admin-tools-page.php:34
54
- msgid "WordPress Core Tables"
55
- msgstr ""
56
-
57
- #: views/admin-tools-page.php:37
58
- msgid ""
59
- "These tables are safe to update with the basic version of this plugin (the "
60
- "version you are currently using)."
61
- msgstr ""
62
-
63
- #: views/admin-tools-page.php:44 views/admin-tools-page.php:45
64
- #: views/admin-tools-page.php:69
65
- msgid "un-check all"
66
- msgstr ""
67
-
68
- #: views/admin-tools-page.php:46 views/admin-tools-page.php:68
69
- #: views/admin-tools-page.php:70
70
- msgid "check all"
71
- msgstr ""
72
-
73
- #: views/admin-tools-page.php:58
74
- msgid "Tables Created By Plugins"
75
- msgstr ""
76
-
77
- #: views/admin-tools-page.php:61
78
- #, php-format
79
- msgctxt "{<br />}{<a>}{</a>}"
80
- msgid ""
81
- "These tables are probably NOT SAFE to update with the basic version of this "
82
- "plugin. %sTo support tables created by plugins use the %sPro Version%s."
83
- msgstr ""
84
-
85
- #: views/admin-tools-page.php:82 views/admin-tools-page.php:85
86
- msgid "Old URL"
87
- msgstr ""
88
-
89
- #: views/admin-tools-page.php:90 views/admin-tools-page.php:93
90
- msgid "New URL"
91
- msgstr ""
92
-
93
- #: views/admin-tools-page.php:100
94
- msgid "Only the checked tables will be updated."
95
- msgstr ""
96
-
97
- #: views/admin-tools-page.php:104
98
- msgid "Make It Happen"
99
- msgstr ""
100
-
101
- #. Plugin Name of the plugin/theme
102
- msgid "Go Live Update URLS"
103
- msgstr ""
104
-
105
- #. Plugin URI of the plugin/theme
106
- msgid "https://matlipe.com/go-live-update-urls/"
107
- msgstr ""
108
-
109
- #. Description of the plugin/theme
110
- msgid ""
111
- "Updates all the URLs in the database to point to the new URL when making "
112
- "your site live or changing domains."
113
- msgstr ""
114
-
115
- #. Author of the plugin/theme
116
- msgid "Mat Lipe"
117
- msgstr ""
118
-
119
- #. Author URI of the plugin/theme
120
- msgid "https://matlipe.com/"
121
- msgstr ""
1
+ #, fuzzy
2
+ msgid ""
3
+ msgstr ""
4
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
5
+ "Project-Id-Version: Go Live Update URLS\n"
6
+ "POT-Creation-Date: 2016-05-15 10:48-0400\n"
7
+ "PO-Revision-Date: 2016-05-15 10:47-0400\n"
8
+ "Last-Translator: \n"
9
+ "Language-Team: \n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "X-Generator: Poedit 1.8.7\n"
14
+ "X-Poedit-Basepath: ..\n"
15
+ "X-Poedit-WPHeader: go-live-update-urls.php\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
18
+ "esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
19
+ "_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
20
+ "X-Poedit-SearchPath-0: .\n"
21
+ "X-Poedit-SearchPathExcluded-0: *.js\n"
22
+
23
+ #: src/GoLiveUpdateUrls.php:51
24
+ msgid "Ouch! That hurt! You should not be here!"
25
+ msgstr ""
26
+
27
+ #: src/GoLiveUpdateUrls.php:74
28
+ msgid "The URLS in the checked tables have been updated."
29
+ msgstr ""
30
+
31
+ #: src/GoLiveUpdateUrls.php:85
32
+ msgid "You must fill out both boxes to make the update!."
33
+ msgstr ""
34
+
35
+ #: src/GoLiveUpdateUrls.php:203
36
+ msgid "Serialized Safe"
37
+ msgstr ""
38
+
39
+ #: views/admin-tools-page.php:17
40
+ #, php-format
41
+ msgctxt "{<strong>}"
42
+ msgid ""
43
+ "This will replace all occurrences %sin the entire database%s of the Old URL "
44
+ "with the New URL."
45
+ msgstr ""
46
+
47
+ #: views/admin-tools-page.php:22
48
+ msgid ""
49
+ "Like any other database updating tool, you should always perform a backup "
50
+ "before running."
51
+ msgstr ""
52
+
53
+ #: views/admin-tools-page.php:34
54
+ msgid "WordPress Core Tables"
55
+ msgstr ""
56
+
57
+ #: views/admin-tools-page.php:37
58
+ msgid ""
59
+ "These tables are safe to update with the basic version of this plugin (the "
60
+ "version you are currently using)."
61
+ msgstr ""
62
+
63
+ #: views/admin-tools-page.php:44 views/admin-tools-page.php:45
64
+ #: views/admin-tools-page.php:69
65
+ msgid "un-check all"
66
+ msgstr ""
67
+
68
+ #: views/admin-tools-page.php:46 views/admin-tools-page.php:68
69
+ #: views/admin-tools-page.php:70
70
+ msgid "check all"
71
+ msgstr ""
72
+
73
+ #: views/admin-tools-page.php:58
74
+ msgid "Tables Created By Plugins"
75
+ msgstr ""
76
+
77
+ #: views/admin-tools-page.php:61
78
+ #, php-format
79
+ msgctxt "{<br />}{<a>}{</a>}"
80
+ msgid ""
81
+ "These tables are probably NOT SAFE to update with the basic version of this "
82
+ "plugin. %sTo support tables created by plugins use the %sPro Version%s."
83
+ msgstr ""
84
+
85
+ #: views/admin-tools-page.php:82 views/admin-tools-page.php:85
86
+ msgid "Old URL"
87
+ msgstr ""
88
+
89
+ #: views/admin-tools-page.php:90 views/admin-tools-page.php:93
90
+ msgid "New URL"
91
+ msgstr ""
92
+
93
+ #: views/admin-tools-page.php:100
94
+ msgid "Only the checked tables will be updated."
95
+ msgstr ""
96
+
97
+ #: views/admin-tools-page.php:104
98
+ msgid "Make It Happen"
99
+ msgstr ""
100
+
101
+ #. Plugin Name of the plugin/theme
102
+ msgid "Go Live Update URLS"
103
+ msgstr ""
104
+
105
+ #. Plugin URI of the plugin/theme
106
+ msgid "https://matlipe.com/go-live-update-urls/"
107
+ msgstr ""
108
+
109
+ #. Description of the plugin/theme
110
+ msgid ""
111
+ "Updates all the URLs in the database to point to the new URL when making "
112
+ "your site live or changing domains."
113
+ msgstr ""
114
+
115
+ #. Author of the plugin/theme
116
+ msgid "Mat Lipe"
117
+ msgstr ""
118
+
119
+ #. Author URI of the plugin/theme
120
+ msgid "https://matlipe.com/"
121
+ msgstr ""
readme.txt CHANGED
@@ -1,147 +1,166 @@
1
- === Plugin Name ===
2
- 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: 4.5.2
7
- Stable tag: 4.0.1
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
- <h3>Want a smarter, easier to use plugin with better support?</h3>
14
- <strong><big><a href="https://matlipe.com/product/go-live-update-urls-pro/">Go Pro!</a></big></strong>
15
-
16
-
17
- Works on both multi-site and single site installs.
18
-
19
- Some of the features this plugin offers:
20
-
21
- * Database table by table selection in case of issues
22
- * Supports serialized data in options and meta tables
23
- * Very easy to use admin page - which may be found under Tools
24
-
25
- Updates Entire Site including:
26
-
27
- * Posts
28
- * Pages
29
- * Image urls
30
- * Excerpts
31
- * Post Meta data
32
- * Custom Post Types
33
- * Widgets and widget data
34
- * Site settings
35
- * And much more
36
-
37
- The admin screen is extend-able for developers familiar with using filters or template overrides.
38
-
39
- Additional Serialized Safe tables may be adding using the 'go-live-update-urls-serialized-tables' filter.
40
-
41
- To contribute send pull requests:
42
- https://github.com/lipemat/go-live-update-urls/
43
-
44
- == Installation ==
45
-
46
- Use the standard WordPress plugins search and installer.
47
- Activate the plugin.
48
- Use the plugin under the Tools menu in the WordPress admin
49
-
50
- Manual Installation
51
-
52
- 1. Upload the `go-live-upload-urls` folder to the `/wp-content/plugins/` directory
53
- 2. Activate the plugin through the 'Plugins' menu in WordPress
54
-
55
-
56
- == Frequently Asked Questions ==
57
-
58
- = Where do you use this plugin? =
59
-
60
- Under the Tools menu in the dashboard there will be a "Go Live" link.
61
-
62
- = Why does updating the domain break some plugins? =
63
-
64
- Some plugins will store the data in the database serialized which does not allow for easy updating of the data. You may un-check tables used by such plugins to avoid breakage and then update the urls manually for those plugins. Currently the options, postmeta, usermeta, commentmeta, and sitemeta tables are serialization safe.
65
-
66
- = How do I know which tables I should not update? =
67
-
68
- 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, un-check tables in sections, and rerun this until you find the culprit. If you find you are running into issues often with custom table you may want to check out the Pro version of this plugin which works with any table.
69
-
70
-
71
- == Screenshots ==
72
-
73
- 1. Screenshot of a typical settings page. The verbiage will change slightly depending on your database structure
74
-
75
- == Changelog ==
76
- = 4.0.0 =
77
- * Restructure admin page to separate WP Core from custom tables
78
- * Remove custom styles in admin
79
- * Improved js structure
80
- * Improved actions and filters
81
- * Improved verbiage with admin
82
-
83
- = 3.1 =
84
- * Add support for serialized term meta
85
-
86
- = 3.0 =
87
- * Greatly improve security
88
- * Improve code organization
89
- * Remove misleading UI messages
90
- * Clears cache when finished
91
-
92
- = 2.4 =
93
- * Added multi-site support
94
- * Added an un-check all tables button
95
- * Enhanced Security
96
-
97
- = 2.3 =
98
- * Added Post Meta to Serialized Safe to coincide with Simple Links Version 2.0
99
-
100
- = 2.2 =
101
- * Added Gravity Forms Support to Serialized Safe
102
- * Added a filter for additional serialized safe tables
103
-
104
- = 2.0 =
105
- * Made updating the options table serialized safe *
106
- * Add extending ability of views and css *
107
- * Moved the Admin page to the Tools Section *
108
- * Improved the structure to allow for future changes *
109
-
110
- = 1.5 =
111
- * Added support for automatically keeping email addresses intact when switching to a subdomain like www
112
-
113
- = 1.3 =
114
- * Added support for adding subdomains like www
115
-
116
- = 1.2.1 =
117
- * Added support for other prefixes besides wp_
118
-
119
- = 1.2 =
120
- * Added the wp_options to the available tables to be updated and unchecked the table by default.
121
-
122
- = 1.1 =
123
- * Removed the wp-options table from the tables to be updated.
124
-
125
- == Upgrade Notice ==
126
- = 3.1 =
127
- Upgrade to support WP 4.4's term meta.
128
-
129
- = 2.4 =
130
- This Version works properly on mulit-site
131
- Enhanced Security - you should probably update
132
-
133
- = 1.5 -
134
- This Version will automatically keep email addresses intact when switch to a sub-domain like www
135
-
136
- = 1.3 =
137
- This Version will allow you to switch to www without having to run it twice
138
-
139
- = 1.2.1 =
140
- This Version will un-check your options table by default for the wp_options as well as other table prefixes.
141
-
142
- = 1.2 =
143
- This Version will add the wp_options to the available tables and uncheck the table by default.
144
-
145
- = 1.1 =
146
- This version will remove the wp_options from the available tables.
147
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: Mat Lipe
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paypal%40matlipe%2ecom&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: 4.5.0
6
+ Tested up to: 4.9.1
7
+ Requires PHP: 5.2.4
8
+ Stable tag: 5.0.0
9
+
10
+ == Description ==
11
+
12
+ Goes through entire site and replaces all instances of an old url with a new one. Used to change the domain of a site. Works on both multi-site and single site installs.
13
+
14
+ <strong>Check out <a href="https://matlipe.com/product/go-live-update-urls-pro/" target="_blank">Go Live Update Urls Pro</a> for more features including priority support, the ability to test a URL before running, updating of tables created by plugins, and so much more!</strong>
15
+
16
+ <blockquote><a href="https://matlipe.com/product/go-live-update-urls-pro/" target="_blank">Pro version 2.0.3</a> just dropped with lots of great new stuff!</blockquote>
17
+
18
+
19
+ <h4>Features</h4>
20
+ * Database table by table selection.
21
+ * Updates serialized data in core tables.
22
+ * Very easy to use admin page - which may be found under Tools.
23
+
24
+
25
+ <h4>Updates Entire Site including</h4>
26
+ * Posts
27
+ * Pages
28
+ * Image urls
29
+ * Excerpts
30
+ * Post Meta data
31
+ * Custom Post Types
32
+ * Widgets and widget data
33
+ * Options and settings
34
+ * And much more
35
+
36
+ <h4>Pro Features</h4>
37
+ * Updates database tables created by plugins without fear of issues.
38
+ * Database tables are organized into understandable sections.
39
+ * Updates serialized data across any table.
40
+ * Priority support.
41
+ * Improved admin page.
42
+ * Ability to test URL changes before running them. **NEW**
43
+ * URL testing report is provided for peace of mind. **NEW**
44
+ * Optionally fix common mistakes when entering a URL automatically. **NEW**
45
+
46
+ <h4>Contribute</h4>
47
+ Send pull requests via the <a href="https://github.com/lipemat/go-live-update-urls/">Github Repo</a>
48
+
49
+ == Installation ==
50
+
51
+ Use the standard WordPress plugins search and installer.
52
+ Activate the plugin.
53
+ Use the plugin under the Tools menu in the WordPress admin
54
+
55
+ Manual Installation
56
+
57
+ 1. Upload the `go-live-upload-urls` folder to the `/wp-content/plugins/` directory
58
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
59
+
60
+
61
+ == Frequently Asked Questions ==
62
+
63
+ = Where do you use this plugin? =
64
+
65
+ Under the Tools menu in the dashboard there will be a "Go Live" link.
66
+
67
+ = Why does updating the domain break some plugins? =
68
+
69
+ Some plugins will store the data in the database serialized which does not allow for easy updating of the data. You may un-check tables used by such plugins to avoid breakage and then update the urls manually for those plugins. Currently the options, postmeta, usermeta, commentmeta, and sitemeta tables are serialization safe. The <a href="https://matlipe.com/product/go-live-update-urls-pro/" target="_blank">Pro Version</a> supports updating these tables created by plugins.
70
+
71
+ = How do I know which tables I should not update? =
72
+
73
+ Most tables will be just fine to update. This plugin will tell you which ones not to update.
74
+ If you wish to try to update tables mentioned as not safe anyway, you may make a backup of your database, run this on all tables and if you run into trouble, restore your database, un-check tables in sections, and rerun this until you find the culprit. If you find you are running into issues often with custom table you may want to check out the <a href="https://matlipe.com/product/go-live-update-urls-pro/" target="_blank">Pro Version</a> of this plugin which works with any table.
75
+
76
+ == Screenshots ==
77
+
78
+ 1. Typical settings page. The verbiage will change slightly depending on your database structure
79
+
80
+ == Changelog ==
81
+ = 5.0.0 =
82
+ * Bring back PHP 5.2 support
83
+ * Restructure entire codebase
84
+ * Greatly improve security
85
+ * Improve performance
86
+ * UI improvements
87
+ * Use strict WP coding standards
88
+
89
+ = 4.1.0 =
90
+ * Drop PHP 5.2 support in favor of PHP 5.3
91
+ * Support updating JSON urls
92
+ * Support Revolution Sliders
93
+ * Add custom updaters support
94
+
95
+ = 4.0.0 =
96
+ * Restructure admin page to separate WP Core from custom tables
97
+ * Remove custom styles in admin
98
+ * Improved js structure
99
+ * Improved actions and filters
100
+ * Improved verbiage with admin
101
+
102
+ = 3.1 =
103
+ * Add support for serialized term meta
104
+
105
+ = 3.0 =
106
+ * Greatly improve security
107
+ * Improve code organization
108
+ * Remove misleading UI messages
109
+ * Clears cache when finished
110
+
111
+ = 2.4 =
112
+ * Added multi-site support
113
+ * Added an un-check all tables button
114
+ * Enhanced Security
115
+
116
+ = 2.3 =
117
+ * Added Post Meta to Serialized Safe to coincide with Simple Links Version 2.0
118
+
119
+ = 2.2 =
120
+ * Added Gravity Forms Support to Serialized Safe
121
+ * Added a filter for additional serialized safe tables
122
+
123
+ = 2.0 =
124
+ * Made updating the options table serialized safe *
125
+ * Add extending ability of views and css *
126
+ * Moved the Admin page to the Tools Section *
127
+ * Improved the structure to allow for future changes *
128
+
129
+ = 1.5 =
130
+ * Added support for automatically keeping email addresses intact when switching to a subdomain like www
131
+
132
+ = 1.3 =
133
+ * Added support for adding subdomains like www
134
+
135
+ = 1.2.1 =
136
+ * Added support for other prefixes besides wp_
137
+
138
+ = 1.2 =
139
+ * Added the wp_options to the available tables to be updated and unchecked the table by default.
140
+
141
+ = 1.1 =
142
+ * Removed the wp-options table from the tables to be updated.
143
+
144
+ == Upgrade Notice ==
145
+ = 3.1 =
146
+ Upgrade to support WP 4.4's term meta.
147
+
148
+ = 2.4 =
149
+ This Version works properly on mulit-site
150
+ Enhanced Security - you should probably update
151
+
152
+ = 1.5 -
153
+ This Version will automatically keep email addresses intact when switch to a sub-domain like www
154
+
155
+ = 1.3 =
156
+ This Version will allow you to switch to www without having to run it twice
157
+
158
+ = 1.2.1 =
159
+ This Version will un-check your options table by default for the wp_options as well as other table prefixes.
160
+
161
+ = 1.2 =
162
+ This Version will add the wp_options to the available tables and uncheck the table by default.
163
+
164
+ = 1.1 =
165
+ This version will remove the wp_options from the available tables.
166
+
resources/js/admin-page.js CHANGED
@@ -1,26 +1,22 @@
1
- (function( $ ){
2
- var go_live_update_urls = {
3
- init : function(){
4
- $( '.gluu-tables-button' ).click( this._un_check_tables );
5
- },
6
-
7
- _un_check_tables : function(){
8
- var el = $( this );
9
- if( el.hasClass( 'checked' ) ){
10
- el.removeClass( 'checked' );
11
- el.val( el.data( 'un-checked' ) );
12
- $( '[data-list="' + el.data( 'list' ) +'"] .gluu-wp-core-table' ).attr( 'checked', false );
13
- } else {
14
- el.addClass( 'checked' );
15
- el.val( el.data( 'checked' ) );
16
- $( '[data-list="' + el.data( 'list' ) +'"] .gluu-wp-core-table' ).attr( 'checked', true );
17
- }
18
- }
19
- };
20
-
21
- $( function(){
22
- go_live_update_urls.init();
23
- } );
24
-
25
-
26
- })( jQuery );
1
+ (function( $ ){
2
+ var go_live_update_urls = {
3
+ init : function(){
4
+ $( '[data-js="go-live-update-urls/checkboxes/check-all"]' ).click( this._un_check_tables );
5
+ },
6
+
7
+ _un_check_tables : function(){
8
+ var el = $( this );
9
+ if( el.prop( 'checked' ) ){
10
+ $( '[data-list="' + el.data( 'list' ) +'"] input' ).prop( 'checked', true );
11
+ } else {
12
+ $( '[data-list="' + el.data( 'list' ) +'"] input' ).prop( 'checked', false );
13
+ }
14
+ }
15
+ };
16
+
17
+ $( function(){
18
+ go_live_update_urls.init();
19
+ } );
20
+
21
+
22
+ })( jQuery );
 
 
 
 
src/Admin_Page.php ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Go_Live_Update_Urls_Admin_Page
5
+ *
6
+ * @author Mat Lipe
7
+ * @since 5.0.0
8
+ *
9
+ */
10
+ class Go_Live_Update_Urls_Admin_Page {
11
+ const NONCE = 'go-live-update-urls/nonce/update-tables';
12
+ const TABLE_INPUT_NAME = 'go-live-update-urls/input/database-table';
13
+ const SUBMIT = 'go-live-update-urls/input/submit';
14
+
15
+ //@todo change these to snake-case after 6/1/18
16
+ const OLD_URL = 'oldurl';
17
+ const NEW_URL = 'newurl';
18
+
19
+
20
+ protected function hook() {
21
+ if ( ! empty( $_POST[ self::SUBMIT ] ) ) {
22
+ add_action( 'init', array( $this, 'validate_update_submission' ) );
23
+ }
24
+
25
+ add_action( 'admin_menu', array( $this, 'register_admin_page' ) );
26
+ }
27
+
28
+
29
+ /**
30
+ * Validate and trigger an update submission
31
+ *
32
+ * @since 5.0.0
33
+ *
34
+ * @return void
35
+ */
36
+ public function validate_update_submission() {
37
+ if ( ! wp_verify_nonce( sanitize_text_field( $_POST[ self::NONCE ] ), self::NONCE ) ) {
38
+ wp_die( esc_html__( 'Ouch! That hurt! You should not be here!', 'go-live-update-urls' ) );
39
+ }
40
+
41
+ $old_url = trim( sanitize_text_field( $_POST[ self::OLD_URL ] ) );
42
+ $new_url = trim( sanitize_text_field( $_POST[ self::NEW_URL ] ) );
43
+ if ( empty( $old_url ) || empty( $new_url ) ) {
44
+ add_action( 'admin_notices', array( $this, 'epic_fail' ) );
45
+ return;
46
+ }
47
+
48
+ $tables = array_map( 'sanitize_text_field', $_POST[ self::TABLE_INPUT_NAME ] );
49
+
50
+ if ( has_action( 'gluu-before-make-update' ) ) {
51
+ _deprecated_hook( 'gluu-before-make-update', '5.0.0', 'go-live-update-urls/admin-page/before-update' );
52
+ $this->tables = $tables;
53
+ do_action( 'gluu-before-make-update', $this );
54
+ }
55
+
56
+ do_action( 'go-live-update-urls/admin-page/before-update', $old_url, $new_url, $tables );
57
+
58
+ if ( Go_Live_Update_Urls_Database::instance()->update_the_database( $old_url, $new_url, $tables ) ) {
59
+ add_action( 'admin_notices', array( $this, 'success' ) );
60
+ }
61
+ }
62
+
63
+
64
+ public function success() {
65
+ $message = apply_filters( 'go-live-update-urls-success-message', __( 'The URLS in the checked tables have been updated.', 'go-live-update-urls' ) );
66
+ ?>
67
+ <div id="message" class="updated fade">
68
+ <p>
69
+ <strong>
70
+ <?php echo esc_html( $message ); ?>
71
+ </strong>
72
+ </p>
73
+ </div>
74
+ <?php
75
+ }
76
+
77
+
78
+ public function epic_fail() {
79
+ ?>
80
+ <div id="message" class="error fade">
81
+ <p>
82
+ <strong><?php esc_html_e( 'You must fill out both boxes to make the update!.', 'go-live-update-urls' ); ?></strong>
83
+ </p>
84
+ </div>
85
+ <?php
86
+
87
+ }
88
+
89
+
90
+ /**
91
+ * Menu Under Tools Menu
92
+ *
93
+ * @since 5.0.0
94
+ */
95
+ public function register_admin_page() {
96
+ add_management_page( 'go-live-update-urls-setting', 'Go Live', 'manage_options', 'go-live-update-urls-settings', array(
97
+ $this,
98
+ 'admin_page',
99
+ ) );
100
+ }
101
+
102
+
103
+ /**
104
+ * Output the Admin Page for using this plugin
105
+ *
106
+ * @since 5.0.0
107
+ *
108
+ */
109
+ public function admin_page() {
110
+ wp_enqueue_script( 'go-live-update-urls-admin-page', Go_Live_Update_Urls_Core::plugin_url( 'resources/js/admin-page.js' ), array( 'jquery' ), GO_LIVE_UPDATE_URLS_VERSION );
111
+
112
+ require Go_Live_Update_Urls_Core::instance()->get_view_file( 'admin-tools-page.php' );
113
+ }
114
+
115
+
116
+ /**
117
+ * Creates a list of checkboxes for each table
118
+ *
119
+ * @since 5.0.0
120
+ *
121
+ * @param array $tables
122
+ * @param string $list - uses by js to separate lists
123
+ * @param bool $checked
124
+ *
125
+ * @return void
126
+ *
127
+ */
128
+ public function render_check_boxes( $tables, $list, $checked = true ) {
129
+ $serialized_tables = Go_Live_Update_Urls_Database::instance()->get_serialized_tables();
130
+ ?>
131
+ <ul class="go-live-update-urls/checkboxes go-live-update-urls/checkboxes/<?php echo esc_attr( $list ); ?>"
132
+ data-list="<?php echo esc_attr( $list ); ?>">
133
+ <?php
134
+
135
+ foreach ( $tables as $_table ) {
136
+ ?>
137
+ <li>
138
+ <input
139
+ name="<?php echo esc_attr( self::TABLE_INPUT_NAME ); ?>[<?php echo esc_attr( $_table ); ?>]"
140
+ type="checkbox"
141
+ value="1"
142
+ class="go-live-update-urls/checkboxes/checkbox" <?php checked( $checked ); ?>/>
143
+ <?php
144
+ echo esc_html( $_table );
145
+ if ( isset( $serialized_tables[ $_table ] ) ) {
146
+ ?>
147
+ - <strong>
148
+ <em>
149
+ <?php esc_html_e( 'Serialized', 'go-live-update-urls' ); ?>
150
+ </em>
151
+ </strong>
152
+ <?php
153
+ }
154
+ ?>
155
+ </li>
156
+ <?php
157
+ }
158
+
159
+ ?>
160
+ </ul>
161
+ <?php
162
+
163
+
164
+ }
165
+
166
+ //********** SINGLETON **********/
167
+
168
+
169
+ /**
170
+ * Instance of this class for use as singleton
171
+ *
172
+ * @var self
173
+ */
174
+ protected static $instance;
175
+
176
+
177
+ /**
178
+ * Create the instance of the class
179
+ *
180
+ * @static
181
+ * @return void
182
+ */
183
+ public static function init() {
184
+ self::instance()->hook();
185
+ }
186
+
187
+
188
+ /**
189
+ * Get (and instantiate, if necessary) the instance of the
190
+ * class
191
+ *
192
+ * @static
193
+ * @return self
194
+ */
195
+ public static function instance() {
196
+ if ( ! is_a( self::$instance, __CLASS__ ) ) {
197
+ self::$instance = new self();
198
+ }
199
+
200
+ return self::$instance;
201
+ }
202
+ }
src/Core.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Go_Live_Update_Urls_Core
5
+ *
6
+ * @author Mat Lipe
7
+ * @since 5.0.0
8
+ *
9
+ */
10
+ class Go_Live_Update_Urls_Core {
11
+
12
+
13
+ protected function hook() {
14
+
15
+ }
16
+
17
+ /**
18
+ * Get a view file from the theme first then this plugin
19
+ *
20
+ * @since 5.0.0
21
+ *
22
+ * @param string $file
23
+ *
24
+ * @return string
25
+ */
26
+ public function get_view_file( $file ) {
27
+ $theme_file = locate_template( array( 'go-live-update-urls/' . $file ) );
28
+ if ( empty( $theme_file ) ) {
29
+ $theme_file = self::plugin_path( 'views/' . $file );
30
+ }
31
+
32
+ return $theme_file;
33
+
34
+ }
35
+
36
+
37
+
38
+ /**************** static ****************************/
39
+
40
+ /**
41
+ * Used along with self::plugin_path() to return path to this plugins files
42
+ *
43
+ * @var string
44
+ */
45
+ private static $plugin_path = false;
46
+
47
+ /**
48
+ * To keep track of this plugins root dir
49
+ * Used along with self::plugin_url() to return url to plugin files
50
+ *
51
+ * @var string
52
+ */
53
+ private static $plugin_url;
54
+
55
+
56
+ /**
57
+ * Retrieve the path this plugins dir
58
+ *
59
+ * @param string [$append] - optional path file or name to add
60
+ *
61
+ * @return string
62
+ */
63
+ public static function plugin_path( $append = '' ) {
64
+
65
+ if ( ! self::$plugin_path ) {
66
+ self::$plugin_path = trailingslashit( dirname( dirname( __FILE__ ) ) );
67
+ }
68
+
69
+ return self::$plugin_path . $append;
70
+ }
71
+
72
+
73
+ /**
74
+ * Retrieve the url this plugins dir
75
+ *
76
+ * @param string [$append] - optional path file or name to add
77
+ *
78
+ * @return string
79
+ */
80
+ public static function plugin_url( $append = '' ) {
81
+
82
+ if ( ! self::$plugin_url ) {
83
+ self::$plugin_url = trailingslashit( plugins_url( basename( self::plugin_path() ), dirname( dirname( __FILE__ ) ) ) );
84
+ }
85
+
86
+ return self::$plugin_url . $append;
87
+ }
88
+
89
+
90
+
91
+ //********** SINGLETON **********/
92
+
93
+
94
+ /**
95
+ * Instance of this class for use as singleton
96
+ *
97
+ * @var self
98
+ */
99
+ protected static $instance;
100
+
101
+
102
+ /**
103
+ * Create the instance of the class
104
+ *
105
+ * @static
106
+ * @return void
107
+ */
108
+ public static function init() {
109
+ self::instance()->hook();
110
+ }
111
+
112
+
113
+ /**
114
+ * Get (and instantiate, if necessary) the instance of the
115
+ * class
116
+ *
117
+ * @static
118
+ * @return self
119
+ */
120
+ public static function instance() {
121
+ if ( ! is_a( self::$instance, __CLASS__ ) ) {
122
+ self::$instance = new self();
123
+ }
124
+
125
+ return self::$instance;
126
+ }
127
+ }
src/Database.php ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Go_Live_Update_Urls_Database
5
+ *
6
+ * @author Mat Lipe
7
+ * @since 2/1/2018
8
+ *
9
+ */
10
+ class Go_Live_Update_Urls_Database {
11
+ protected $old_url = false;
12
+
13
+ protected $new_url = false;
14
+
15
+ public $double_subdomain = false; //keep track if going to a subdomain
16
+
17
+
18
+ /**
19
+ * Get list of tables we treat as serialized when updating
20
+ *
21
+ * @since 5.0.0
22
+ *
23
+ * @return array( %table_name% => %table_column% )
24
+ */
25
+ public function get_serialized_tables() {
26
+ global $wpdb;
27
+ //default tables with serialized data
28
+ $serialized_tables = array(
29
+ $wpdb->options => 'option_value',
30
+ $wpdb->postmeta => 'meta_value',
31
+ $wpdb->commentmeta => 'meta_value',
32
+ $wpdb->termmeta => 'meta_value',
33
+ );
34
+
35
+ //we are not going to update user meta if we are not on main blog
36
+ if ( is_multisite() ) {
37
+ $serialized_tables[ $wpdb->sitemeta ] = 'meta_value';
38
+ if ( 1 === (int) $wpdb->blogid ) {
39
+ $serialized_tables[ $wpdb->usermeta ] = 'meta_value';
40
+ }
41
+ } else {
42
+ $serialized_tables[ $wpdb->usermeta ] = 'meta_value';
43
+ }
44
+
45
+ $tables = apply_filters( 'go-live-update-urls-serialized-tables', $serialized_tables );
46
+
47
+ return $tables;
48
+ }
49
+
50
+
51
+ /**
52
+ * Get the list of tables that were not create by WP core
53
+ *
54
+ * @return array
55
+ */
56
+ public function get_custom_plugin_tables() {
57
+ $core_tables = $this->get_core_tables();
58
+ $all_tables = wp_list_pluck( $this->get_all_tables(), 'TABLE_NAME' );
59
+ $all_tables = array_flip( $all_tables );
60
+ foreach ( $core_tables as $_table ) {
61
+ unset( $all_tables[ $_table ] );
62
+ }
63
+
64
+ return apply_filters( 'go_live_update_urls_plugin_tables', array_keys( $all_tables ) );
65
+ }
66
+
67
+
68
+ /**
69
+ * Get the list of WP core tables
70
+ *
71
+ * @since 4.0.0
72
+ *
73
+ * @return array
74
+ */
75
+ public function get_core_tables() {
76
+ global $wpdb;
77
+
78
+ //Pre WP 4.4
79
+ if ( ! isset( $wpdb->termmeta ) ) {
80
+ $wpdb->termmeta = false;
81
+ }
82
+
83
+ $tables = array(
84
+ $wpdb->posts,
85
+ $wpdb->comments,
86
+ $wpdb->links,
87
+ $wpdb->options,
88
+ $wpdb->postmeta,
89
+ $wpdb->terms,
90
+ $wpdb->term_taxonomy,
91
+ $wpdb->term_relationships,
92
+ $wpdb->termmeta,
93
+ $wpdb->commentmeta,
94
+ $wpdb->users,
95
+ $wpdb->usermeta,
96
+ );
97
+
98
+ if ( isset( $wpdb->termmeta ) ) {
99
+ $tables[] = $wpdb->termmeta;
100
+ }
101
+ if ( is_multisite() ) {
102
+ $tables[] = $wpdb->blogs;
103
+ $tables[] = $wpdb->signups;
104
+ $tables[] = $wpdb->site;
105
+ $tables[] = $wpdb->sitemeta;
106
+ $tables[] = $wpdb->sitecategories;
107
+ $tables[] = $wpdb->registration_log;
108
+ $tables[] = $wpdb->blog_versions;
109
+ }
110
+
111
+ return apply_filters( 'go_live_update_urls_core_tables', $tables );
112
+ }
113
+
114
+
115
+ /**
116
+ * Get a list of all database table for current install
117
+ * Includes custom and standard tables
118
+ *
119
+ * @static
120
+ *
121
+ * @return mixed
122
+ */
123
+ public function get_all_tables() {
124
+ global $wpdb;
125
+
126
+ $query = "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='" . $wpdb->dbname . "' AND TABLE_NAME LIKE '" . $wpdb->prefix . "%'";
127
+
128
+ //Done this way because like wp_% will return all other tables as well such as wp_2
129
+ //so we exclude all the possibles e.g. wp_2, wp_3, wp_4 up to 9
130
+ $not_like = null;
131
+ if ( 1 === (int) $wpdb->blogid && is_multisite() ) {
132
+ for ( $i = 1; $i <= 9; $i ++ ) {
133
+ $not_like .= "'" . $wpdb->prefix . $i . "',";
134
+ }
135
+ $not_like = substr( $not_like, 0, - 1 );
136
+ $query .= ' AND SUBSTRING(TABLE_NAME,1,4) NOT IN (' . $not_like . ')';
137
+ }
138
+
139
+ return $wpdb->get_results( $query );
140
+ }
141
+
142
+
143
+ /**
144
+ * Make the actual changes to the database
145
+ *
146
+ * @since 5.0.0
147
+ *
148
+ * @param string $old_url
149
+ * @param string $new_url
150
+ * @param array $tables
151
+ *
152
+ * @return bool
153
+ */
154
+ public function update_the_database( $old_url, $new_url, array $tables ) {
155
+ global $wpdb;
156
+ $this->old_url = $old_url;
157
+ $this->new_url = $new_url;
158
+
159
+
160
+ @set_time_limit( 0 );
161
+ @ini_set( 'memory_limit', '256M' );
162
+ @ini_set( 'max_input_time', '-1' );
163
+
164
+ $updaters = (array) Go_Live_Update_Urls__Updaters__Repo::instance()->get_updaters();
165
+
166
+ // If the new domain is the old one with a new sub-domain like www
167
+ if ( strpos( $this->new_url, $this->old_url ) !== false ) {
168
+ list( $subdomain ) = explode( '.', $this->new_url );
169
+ $this->double_subdomain = $subdomain . '.' . $this->new_url;
170
+ }
171
+
172
+ $serialized_tables = $this->get_serialized_tables();
173
+ $tables = apply_filters( 'go-live-update-urls/database/update-tables', $tables, $this );
174
+
175
+ //Go through each table sent to be updated
176
+ foreach ( array_keys( $tables ) as $table ) {
177
+ if ( isset( $serialized_tables[ $table ] ) ) {
178
+ if ( is_array( $serialized_tables[ $table ] ) ) {
179
+ foreach ( $serialized_tables[ $table ] as $column ) {
180
+ $this->update_serialized_table( $table, $column );
181
+ }
182
+ } else {
183
+ $this->update_serialized_table( $table, $serialized_tables[ $table ] );
184
+ }
185
+ }
186
+
187
+ $column_query = "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='" . $wpdb->dbname . "' AND TABLE_NAME='" . $table . "'";
188
+ $columns = $wpdb->get_col( $column_query );
189
+
190
+ foreach ( $columns as $_column ) {
191
+ $update_query = 'UPDATE ' . $table . ' SET ' . $_column . ' = replace(' . $_column . ', %s, %s)';
192
+ $wpdb->query( $wpdb->prepare( $update_query, array( $this->old_url, $this->new_url ) ) );
193
+
194
+
195
+ //Run each updater
196
+ //@todo convert all the steps to their own updater class
197
+ foreach ( $updaters as $_updater_class ) {
198
+ if ( class_exists( $_updater_class ) ) {
199
+ /** @var Go_Live_Update_Urls__Updaters__Abstract $_updater */
200
+ $_updater = new $_updater_class( $table, $_column, $this->old_url, $this->new_url );
201
+ $_updater->update_data();
202
+ //run each updater through double sub-domain if applicable
203
+ if ( $this->double_subdomain ) {
204
+ $_updater = new $_updater_class( $table, $_column, $this->double_subdomain, $this->new_url );
205
+ $_updater->update_data();
206
+ }
207
+ }
208
+ }
209
+
210
+
211
+ //Fix the dub dubs if this was the old domain with a new sub
212
+ if ( $this->double_subdomain ) {
213
+ $wpdb->query( $wpdb->prepare( $update_query, array(
214
+ $this->double_subdomain,
215
+ $this->new_url,
216
+ ) ) );
217
+ //Fix the emails breaking by being appended the new subdomain
218
+ $wpdb->query( $wpdb->prepare( $update_query, array(
219
+ '@' . $this->new_url,
220
+ '@' . $this->old_url,
221
+ ) ) );
222
+ }
223
+ }
224
+ }
225
+
226
+ wp_cache_flush();
227
+
228
+ return true;
229
+ }
230
+
231
+
232
+ /**
233
+ * Goes through a table line by line and updates it
234
+ *
235
+ * @uses for tables which may contain serialized arrays
236
+ *
237
+ * @since 5.0.0
238
+ *
239
+ * @param string $table the table
240
+ * @param string $column to column in the table
241
+ *
242
+ * @return void
243
+ */
244
+ protected function update_serialized_table( $table, $column ) {
245
+ global $wpdb;
246
+ $pk = $wpdb->get_results( "SHOW KEYS FROM $table WHERE Key_name = 'PRIMARY'" );
247
+ if ( empty( $pk[0] ) ) {
248
+ $pk = $wpdb->get_results( "SHOW KEYS FROM $table" );
249
+ if ( empty( $pk[0] ) ) {
250
+ //fail
251
+ return;
252
+ }
253
+ }
254
+
255
+ $primary_key_column = $pk[0]->Column_name;
256
+
257
+ //Get all the Serialized Rows and Replace them properly
258
+ $rows = $wpdb->get_results( "SELECT $primary_key_column, $column FROM $table WHERE $column LIKE 'a:%' OR $column LIKE 'O:%'" );
259
+
260
+ foreach ( $rows as $row ) {
261
+ if ( ! is_serialized( $row->{$column} ) ) {
262
+ continue;
263
+ }
264
+
265
+ if ( strpos( $row->{$column}, $this->old_url ) === false ) {
266
+ continue;
267
+ }
268
+
269
+ $data = @unserialize( $row->{$column} );
270
+
271
+ $clean = $this->replace_tree( $data, $this->old_url, $this->new_url );
272
+ //If we switch to a submain we have to run this again to remove the doubles
273
+ if ( $this->double_subdomain ) {
274
+ $clean = $this->replace_tree( $clean, $this->double_subdomain, $this->new_url );
275
+ }
276
+
277
+ $clean = @serialize( $clean );
278
+
279
+ $wpdb->query( $wpdb->prepare( "UPDATE $table SET $column=%s WHERE $primary_key_column=%s", $clean, $row->{$primary_key_column} ) );
280
+
281
+ }
282
+ }
283
+
284
+
285
+ /**
286
+ * Replaces all the occurrences of a string in a multi-dimensional array or Object
287
+ *
288
+ * @uses itself to call each level of the array
289
+ *
290
+ * @param iterable|string $data to change
291
+ * @param string $old the old string
292
+ * @param string $new the new string
293
+ *
294
+ * @since 5.0.0
295
+ *
296
+ * @return mixed
297
+ *
298
+ */
299
+ protected function replace_tree( $data, $old, $new ) {
300
+ if ( is_string( $data ) ) {
301
+ return trim( str_replace( $old, $new, $data ) );
302
+ }
303
+
304
+ if ( ! is_array( $data ) && ! is_object( $data ) ) {
305
+ return $data;
306
+ }
307
+
308
+ foreach ( $data as $key => $item ) {
309
+ if ( is_array( $data ) ) {
310
+ $data[ $key ] = $this->replace_tree( $item, $old, $new );
311
+ } else {
312
+ $data->{$key} = $this->replace_tree( $item, $old, $new );
313
+ }
314
+ }
315
+
316
+ return $data;
317
+ }
318
+
319
+
320
+ protected function hook() {
321
+
322
+ }
323
+
324
+ //********** SINGLETON **********/
325
+
326
+
327
+ /**
328
+ * Instance of this class for use as singleton
329
+ *
330
+ * @var self
331
+ */
332
+ protected static $instance;
333
+
334
+
335
+ /**
336
+ * Create the instance of the class
337
+ *
338
+ * @static
339
+ * @return void
340
+ */
341
+ public static function init() {
342
+ self::instance()->hook();
343
+ }
344
+
345
+
346
+ /**
347
+ * Get (and instantiate, if necessary) the instance of the
348
+ * class
349
+ *
350
+ * @static
351
+ * @return self
352
+ */
353
+ public static function instance() {
354
+ if ( ! is_a( self::$instance, __CLASS__ ) ) {
355
+ self::$instance = new self();
356
+ }
357
+
358
+ return self::$instance;
359
+ }
360
+ }
src/GoLiveUpdateUrls.php CHANGED
@@ -1,567 +1,49 @@
1
- <?php
2
- /**
3
- * Methods for the Go Live Update Urls Plugin
4
- *
5
- * @author Mat Lipe
6
- * @since 2.2
7
- *
8
- */
9
- class GoLiveUpdateUrls {
10
- const NONCE = 'gluu-update-tables';
11
- const TABLE_INPUT_NAME = 'gluu_table';
12
-
13
- public $oldurl = false;
14
-
15
- public $newurl = false;
16
-
17
- public $double_subdomain = false; //keep track if going to a subdomain
18
-
19
- /*
20
- * serialized_tables
21
- *
22
- * keys are table names
23
- * values are table columns
24
- *
25
- * @var array
26
- */
27
- public $serialized_tables = array();
28
-
29
- /**
30
- * tables
31
- *
32
- * Tables to update, set during self::maybe_make_updates()
33
- *
34
- * @var array
35
- */
36
- public $tables = array();
37
-
38
-
39
- private function hooks(){
40
- //If the Form has been submitted make the updates
41
- if( !empty( $_POST[ 'gluu-submit' ] ) ){
42
- add_action( 'init', array( $this, 'maybe_run_updates' ) );
43
- }
44
-
45
- add_action( 'admin_menu', array( $this, 'gluu_add_url_options' ) );
46
- }
47
-
48
-
49
- public function maybe_run_updates(){
50
- if( !wp_verify_nonce( $_POST[ self::NONCE ], self::NONCE ) ){
51
- wp_die( __('Ouch! That hurt! You should not be here!', 'go-live-update-urls' ) );
52
- }
53
-
54
- $this->oldurl = trim( strip_tags( $_POST[ 'oldurl' ] ) );
55
- $this->newurl = trim( strip_tags( $_POST[ 'newurl' ] ) );
56
-
57
- //backward compatibility with Pro
58
- if( empty( $_POST[ self::TABLE_INPUT_NAME ] ) ){
59
- $this->tables = $_POST;
60
- } else {
61
- $this->tables = $_POST[ self::TABLE_INPUT_NAME ];
62
- }
63
-
64
- do_action( 'gluu-before-make-update', $this );
65
-
66
- if( $this->makeTheUpdates() ){
67
- add_action( 'admin_notices', array( $this, 'success' ) );
68
- } else {
69
- add_action( 'admin_notices', array( $this, 'epic_fail' ) );
70
- }
71
-
72
- }
73
-
74
-
75
- public function success(){
76
- $message = apply_filters( 'go-live-update-urls-success-message', __( 'The URLS in the checked tables have been updated.', 'go-live-update-urls' ) );
77
- ?>
78
- <div id="message" class="updated fade">
79
- <p>
80
- <strong>
81
- <?php echo $message; ?>
82
- </strong>
83
- </p>
84
- </div>
85
- <?php
86
- }
87
-
88
-
89
- public function epic_fail(){
90
- ?>
91
- <div id="message" class="error fade">
92
- <p>
93
- <strong><?php _e( 'You must fill out both boxes to make the update!.', 'go-live-update-urls' ); ?></strong>
94
- </p>
95
- </div>
96
- <?php
97
-
98
- }
99
-
100
-
101
- /**
102
- * Retrieve filtered list of serialized safe database tables
103
- *
104
- * @since 2.4.0
105
- *
106
- * @filters go-live-update-urls-serialized-tables - affects tables treated as serialized and checkbox
107
- *
108
- * @return array( %table_name% => %table_column% )
109
- */
110
- function getSerializedTables(){
111
- if( empty( $this->serialized_tables ) ){
112
- global $wpdb;
113
- //default tables with serialized data
114
- $this->serialized_tables = array(
115
- $wpdb->options => 'option_value', //WP options
116
- $wpdb->postmeta => 'meta_value', //post meta - since 2.3.0
117
- $wpdb->commentmeta => 'meta_value', //comment meta since 2.5.0
118
- );
119
-
120
- //term meta since WP 4.4
121
- if( isset( $wpdb->termmeta ) ){
122
- $this->serialized_tables[ $wpdb->termmeta ] = 'meta_value';
123
- }
124
-
125
- //we are not going to update user meta if we are not on main blog
126
- if( is_multisite() ){
127
- $this->serialized_tables[ $wpdb->sitemeta ] = 'meta_value';
128
- if( 1 === (int) $wpdb->blogid ){
129
- $this->serialized_tables[ $wpdb->usermeta ] = 'meta_value';
130
- }
131
- }
132
- }
133
-
134
- //@deprecated
135
- $tables = apply_filters( 'gluu-seralized-tables', $this->serialized_tables );
136
-
137
- //use this filter
138
- $tables = apply_filters( 'go-live-update-urls-serialized-tables', $tables );
139
-
140
- return $tables;
141
- }
142
-
143
-
144
- /**
145
- * Menu Under Tools Menu
146
- *
147
- * @since 2.0
148
- */
149
- function gluu_add_url_options(){
150
- add_management_page( "go-live-setting", "Go Live", "manage_options", basename( __FILE__ ), array(
151
- $this,
152
- "adminToolsPage"
153
- ) );
154
- }
155
-
156
-
157
- /**
158
- * Output the Admin Page for using this plugin
159
- *
160
- * @since 2.0
161
- *
162
- */
163
- function adminToolsPage(){
164
-
165
- wp_enqueue_script( 'gluu-admin-page', self::plugin_url( 'resources/js/admin-page.js'), array( 'jquery'), GLUU_VERSION );
166
-
167
- require( $this->fileHyercy( 'admin-tools-page.php' ) );
168
- }
169
-
170
-
171
- /**
172
- * Allows for Overwriting files in the child theme
173
- *
174
- * @since 2.0
175
- *
176
- * @since 10.22.13
177
- *
178
- * @param string $file the name of the file to overwrite
179
- */
180
- function fileHyercy( $file ){
181
- if( !$theme_file = locate_template( array( 'go-live-update-urls/' . $file ) ) ){
182
- $theme_file = GLUU_VIEWS_DIR . $file;
183
- }
184
-
185
- return $theme_file;
186
-
187
- }
188
-
189
-
190
- /**
191
- * Creates a list of checkboxes for each table
192
- *
193
- * @since 2.2
194
- *
195
- * @param array $tables
196
- * @param string $list - uses by js to separate lists
197
- * @param bool $checked
198
- *
199
- * @return string;
200
- *
201
- */
202
- function makeCheckBoxes( $tables, $list, $checked = true ){
203
-
204
- $output = '<ul id="gluu-checkboxes" data-list="' . $list . '">';
205
-
206
- $serialized_tables = $this->getSerializedTables();
207
-
208
- foreach( $tables as $_table ){
209
- $output .= sprintf( '<li><input name="%s[%s]" type="checkbox" value="%s" class="gluu-wp-core-table" %s/> %s', self::TABLE_INPUT_NAME, $_table, $_table, checked( $checked, true, false), $_table );
210
- if( in_array( $_table, array_keys( $serialized_tables ) ) ){
211
- $output .= sprintf( ' - <strong><em>%s</strong></em>', __( 'Serialized Safe', 'go-live-update-urls' ) );
212
- }
213
- $output .= '</li>';
214
- }
215
-
216
- $output .= '</ul>';
217
-
218
- return $output;
219
-
220
- }
221
-
222
-
223
- /**
224
- * Get the list of tables that were not create by WP core
225
- *
226
- * @return array
227
- */
228
- public function get_custom_plugin_tables(){
229
- $core_tables = $this->get_core_tables();
230
- $all_tables = wp_list_pluck( self::get_all_tables(), 'TABLE_NAME' );
231
- $all_tables = array_flip( $all_tables );
232
- foreach( $core_tables as $_table ){
233
- unset( $all_tables[ $_table ] );
234
- }
235
-
236
- return apply_filters( 'go_live_update_urls_plugin_tables' , array_keys( $all_tables ) );
237
- }
238
-
239
-
240
- /**
241
- * Get the list of WP core tables
242
- *
243
- * @since 4.0.0
244
- *
245
- * @return array
246
- */
247
- public function get_core_tables(){
248
- global $wpdb;
249
-
250
- //Pre WP 4.4
251
- if( !isset( $wpdb->termmeta ) ){
252
- $wpdb->termmeta = false;
253
- }
254
-
255
- $tables = array(
256
- $wpdb->posts,
257
- $wpdb->comments,
258
- $wpdb->links,
259
- $wpdb->options,
260
- $wpdb->postmeta,
261
- $wpdb->terms,
262
- $wpdb->term_taxonomy,
263
- $wpdb->term_relationships,
264
- $wpdb->termmeta,
265
- $wpdb->commentmeta,
266
- $wpdb->users,
267
- $wpdb->usermeta,
268
- );
269
-
270
- if( isset( $wpdb->termmeta ) ){
271
- $tables[] = $wpdb->termmeta;
272
- }
273
- if( is_multisite() ){
274
- $tables[] = $wpdb->blogs;
275
- $tables[] = $wpdb->signups;
276
- $tables[] = $wpdb->site;
277
- $tables[] = $wpdb->sitemeta;
278
- $tables[] = $wpdb->sitecategories;
279
- $tables[] = $wpdb->registration_log;
280
- $tables[] = $wpdb->blog_versions;
281
- }
282
-
283
- return apply_filters( 'go_live_update_urls_core_tables', $tables );
284
- }
285
-
286
-
287
- /**
288
- * get_all_tables
289
- *
290
- * Get a list of all database table for current install
291
- * Includes custom and standard tables
292
- *
293
- * @static
294
- *
295
- * @return mixed
296
- */
297
- public static function get_all_tables(){
298
- global $wpdb;
299
-
300
- $god_query = "SELECT TABLE_NAME FROM information_schema.TABLES where TABLE_SCHEMA='" . $wpdb->dbname . "' AND TABLE_NAME LIKE '" . $wpdb->prefix . "%'";
301
-
302
- //Done this way because like wp_% will return all other tables as well such as wp_2
303
- //so we exclude all the possibles e.g. wp_2, wp_3, wp_4 up to 9
304
- $not_like = null;
305
- if( is_multisite() && $wpdb->blogid == 1 ){
306
- for( $i = 1; $i <= 9; $i ++ ){
307
- $not_like .= "'" . $wpdb->prefix . $i . "',";
308
- }
309
- $not_like = substr( $not_like, 0, - 1 );
310
- $god_query .= ' AND SUBSTRING(TABLE_NAME,1,4) NOT IN (' . $not_like . ')';
311
- }
312
-
313
- return $wpdb->get_results( $god_query );
314
- }
315
-
316
-
317
- /**
318
- * Updates the datbase
319
- *
320
- * @uses the oldurl and newurl set above
321
- *
322
-
323
- */
324
- function makeTheUpdates(){
325
- global $wpdb;
326
-
327
- if( empty( $this->oldurl ) || empty( $this->newurl ) ){
328
- return false;
329
- }
330
-
331
- @set_time_limit( 0 );
332
- @ini_set( 'memory_limit', '256M' );
333
- @ini_set( 'max_input_time', '-1' );
334
-
335
- // If the new domain is the old one with a new sub-domain like www
336
- if( strpos( $this->newurl, $this->oldurl ) !== false ){
337
- list( $subdomain ) = explode( '.', $this->newurl );
338
- $this->double_subdomain = $subdomain . '.' . $this->newurl;
339
- }
340
-
341
- $serialized_tables = $this->getSerializedTables();
342
-
343
- //Go through each table sent to be updated
344
- foreach( array_keys( $this->tables ) as $table ){
345
- //backward compatibility with pro
346
- if( $table == 'submit' && $table == 'oldurl' && $table == 'newurl' ){
347
- continue;
348
- }
349
-
350
- if( in_array( $table, array_keys( $serialized_tables ) ) ){
351
- if( is_array( $serialized_tables[ $table ] ) ){
352
- foreach( $serialized_tables[ $table ] as $column ){
353
- $this->UpdateSeralizedTable( $table, $column );
354
- }
355
- } else {
356
- $this->UpdateSeralizedTable( $table, $serialized_tables[ $table ] );
357
- }
358
- }
359
-
360
- $column_query = "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='" . $wpdb->dbname . "' AND TABLE_NAME='" . $table . "'";
361
- $columns = $wpdb->get_col( $column_query );
362
-
363
- foreach( $columns as $_column ){
364
- $update_query = "UPDATE " . $table . " SET " . $_column . " = replace(" . $_column . ", %s, %s)";
365
- $wpdb->query( $wpdb->prepare( $update_query, array( $this->oldurl, $this->newurl ) ) );
366
-
367
- //Fix the dub dubs if this was the old domain with a new sub
368
- if( $this->double_subdomain ){
369
- $wpdb->query( $wpdb->prepare( $update_query, array(
370
- $this->double_subdomain,
371
- $this->newurl,
372
- ) ) );
373
- //Fix the emails breaking by being appended the new subdomain
374
- $wpdb->query( $wpdb->prepare( $update_query, array(
375
- "@" . $this->newurl,
376
- "@" . $this->oldurl,
377
- ) ) );
378
- }
379
- }
380
-
381
- }
382
-
383
- wp_cache_flush();
384
-
385
- return true;
386
- }
387
-
388
-
389
- /**
390
- * Goes through a table line by line and updates it
391
- *
392
- * @uses for tables which may contain seralized arrays
393
- * @since 2.1
394
- *
395
- * @param string $table the table to go through
396
- * @param string $column to column in the table to go through
397
- *
398
- *
399
- */
400
- function UpdateSeralizedTable( $table, $column = false ){
401
- global $wpdb;
402
- $pk = $wpdb->get_results( "SHOW KEYS FROM $table WHERE Key_name = 'PRIMARY'" );
403
- if( empty( $pk[ 0 ] ) ){
404
- $pk = $wpdb->get_results( "SHOW KEYS FROM $table" );
405
- if( empty( $pk[ 0 ] ) ){
406
- //fail
407
- return;
408
- }
409
- }
410
-
411
- $primary_key_column = $pk[ 0 ]->Column_name;
412
-
413
- //Get all the Seralized Rows and Replace them properly
414
- $rows = $wpdb->get_results( "SELECT $primary_key_column, $column FROM $table WHERE $column LIKE 'a:%' OR $column LIKE 'O:%'" );
415
-
416
- foreach( $rows as $row ){
417
- if( !is_serialized( $row->{$column} ) ){
418
- continue;
419
- }
420
-
421
- if( strpos( $row->{$column}, $this->oldurl ) === false ){
422
- continue;
423
- }
424
-
425
- $data = @unserialize( $row->{$column} );
426
-
427
- $clean = $this->replaceTree( $data, $this->oldurl, $this->newurl );
428
- //If we switch to a submain we have to run this again to remove the doubles
429
- if( $this->double_subdomain ){
430
- $clean = $this->replaceTree( $clean, $this->double_subdomain, $this->newurl );
431
- }
432
-
433
- $clean = @serialize( $clean );
434
-
435
- $wpdb->query( $wpdb->prepare( "UPDATE $table SET $column=%s WHERE $primary_key_column=%s", $clean, $row->{$primary_key_column} ) );
436
-
437
- }
438
- }
439
-
440
-
441
- /**
442
- * Replaces all the occurances of a string in a multi dementional array or Object
443
- *
444
- * @uses itself to call each level of the array
445
- * @since 2.1
446
- *
447
- * @param array|object|string $data to change
448
- * @param string $old the old string
449
- * @param string $new the new string
450
- * @param bool [optional] $changeKeys to replace string in keys as well - defaults to false
451
- *
452
- * @since 3.26.13
453
- *
454
- */
455
- function replaceTree( $data, $old, $new, $changeKeys = false ){
456
-
457
- if( is_string( $data ) ){
458
- return trim( str_replace( $old, $new, $data ) );
459
- }
460
-
461
- if( !is_array( $data ) && !is_object( $data ) ){
462
- return $data;
463
- }
464
-
465
- foreach( $data as $key => $item ){
466
-
467
- if( $changeKeys ){
468
- $key = str_replace( $old, $new, $key );
469
- }
470
-
471
- if( is_array( $data ) ){
472
- $data[ $key ] = $this->replaceTree( $item, $old, $new );
473
- } else {
474
- $data->{$key} = $this->replaceTree( $item, $old, $new );
475
- }
476
- }
477
-
478
- return $data;
479
- }
480
-
481
- /**************** static ****************************/
482
-
483
- /**
484
- * Used along with self::plugin_path() to return path to this plugins files
485
- *
486
- * @var string
487
- */
488
- private static $plugin_path = false;
489
-
490
- /**
491
- * To keep track of this plugins root dir
492
- * Used along with self::plugin_url() to return url to plugin files
493
- *
494
- * @var string
495
- */
496
- private static $plugin_url;
497
-
498
-
499
- /**
500
- * Retrieve the path this plugins dir
501
- *
502
- * @param string [$append] - optional path file or name to add
503
- *
504
- * @return string
505
- */
506
- public static function plugin_path( $append = '' ){
507
-
508
- if( !self::$plugin_path ){
509
- self::$plugin_path = trailingslashit( dirname( dirname( __FILE__ ) ) );
510
- }
511
-
512
- return self::$plugin_path . $append;
513
- }
514
-
515
-
516
- /**
517
- * Retrieve the url this plugins dir
518
- *
519
- * @param string [$append] - optional path file or name to add
520
- *
521
- * @return string
522
- */
523
- public static function plugin_url( $append = '' ){
524
-
525
- if( !self::$plugin_url ){
526
- self::$plugin_url = trailingslashit( plugins_url( basename( self::plugin_path() ), dirname( dirname( __FILE__ ) ) ) );
527
- }
528
-
529
- return self::$plugin_url . $append;
530
- }
531
-
532
-
533
- //********** SINGLETON FUNCTIONS **********/
534
-
535
- /**
536
- * Instance of this class for use as singleton
537
- */
538
- private static $instance;
539
-
540
-
541
- /**
542
- * Create the instance of the class
543
- *
544
- * @static
545
- * @return void
546
- */
547
- public static function init(){
548
- self::get_instance()->hooks();
549
- }
550
-
551
-
552
- /**
553
- * Get (and instantiate, if necessary) the instance of the
554
- * class
555
- *
556
- * @static
557
- * @return self
558
- */
559
- public static function get_instance(){
560
- if( !is_a( self::$instance, __CLASS__ ) ){
561
- self::$instance = new self();
562
- }
563
-
564
- return self::$instance;
565
- }
566
-
567
- }
1
+ <?php
2
+
3
+ /**
4
+ * deprecated 5.0.0
5
+ *
6
+ */
7
+ class GoLiveUpdateUrls {
8
+ const TABLE_INPUT_NAME = Go_Live_Update_Urls_Admin_Page::TABLE_INPUT_NAME;
9
+
10
+ protected function __construct() {
11
+ _deprecated_constructor( 'GoLiveUpdateUrls', '5.0.0' );
12
+ }
13
+
14
+
15
+ /**
16
+ * @deprecated 5.0.0 in favor of Go_Live_Update_Urls_Database::get_all_tables()
17
+ * @see Go_Live_Update_Urls_Database::get_all_tables()
18
+ */
19
+ public static function get_all_tables() {
20
+ _deprecated_function( 'GoLiveUpdateUrls::get_all_tables', '5.0.0', 'Go_Live_Update_Urls_Database::get_all_tables' );
21
+
22
+ return Go_Live_Update_Urls_Database::instance()->get_all_tables();
23
+ }
24
+
25
+ //********** SINGLETON FUNCTIONS **********/
26
+
27
+
28
+ /**
29
+ * Instance of this class for use as singleton
30
+ */
31
+ private static $instance;
32
+
33
+
34
+ /**
35
+ * Get (and instantiate, if necessary) the instance of the
36
+ * class
37
+ *
38
+ * @static
39
+ * @return self
40
+ */
41
+ public static function get_instance() {
42
+ if ( ! is_a( self::$instance, __CLASS__ ) ) {
43
+ self::$instance = new self();
44
+ }
45
+
46
+ return self::$instance;
47
+ }
48
+
49
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/Updaters/Abstract.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * _Updater
5
+ *
6
+ * @author Mat Lipe
7
+ * @since 5.0.0
8
+ *
9
+ */
10
+ abstract class Go_Live_Update_Urls__Updaters__Abstract {
11
+ protected $table;
12
+
13
+ protected $column;
14
+
15
+ protected $old;
16
+
17
+ protected $new;
18
+
19
+
20
+ public function __construct( $table, $column, $old, $new ) {
21
+ $this->table = $table;
22
+ $this->column = $column;
23
+ $this->old = $old;
24
+ $this->new = $new;
25
+ }
26
+
27
+
28
+ abstract public function update_data();
29
+ }
src/Updaters/JSON.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * JSON
5
+ *
6
+ * When a url is entered into the db using json_encode it
7
+ * get's extra \/ at each slash
8
+ *
9
+ * This updater simulates the same slashes and replaces matches
10
+ *
11
+ * If the url either new or old has a slash we run this
12
+ *
13
+ * Because there is no real good way to detect this which is any lighter
14
+ * than just doing the update we run it on each column
15
+ *
16
+ *
17
+ * @author Mat Lipe
18
+ * @since 5.0.0
19
+ *
20
+ * @package Gluu\Updates
21
+ */
22
+ class Go_Live_Update_Urls__Updaters__JSON extends Go_Live_Update_Urls__Updaters__Abstract {
23
+
24
+ public function update_data() {
25
+ if ( ! strpos( $this->new, '/' ) && ! strpos( $this->old, '/' ) ) {
26
+ return false;
27
+ }
28
+
29
+ global $wpdb;
30
+ $old = substr( wp_json_encode( $this->old ), 1, - 1 );
31
+ $new = substr( wp_json_encode( $this->new ), 1, - 1 );
32
+
33
+ $update_query = "UPDATE " . $this->table . " SET " . $this->column . " = replace(" . $this->column . ", %s, %s)";
34
+ $wpdb->query( $wpdb->prepare( $update_query, array( $old, $new ) ) );
35
+
36
+ return true;
37
+ }
38
+
39
+ }
src/Updaters/Repo.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Register
5
+ *
6
+ * @author Mat Lipe
7
+ * @since 5.0.0
8
+ *
9
+ * @package Go_Live_Update_Urls\Updates
10
+ */
11
+ class Go_Live_Update_Urls__Updaters__Repo {
12
+ /**
13
+ * Get all registered updaters by classname
14
+ * This list will grow over time as things are converted over
15
+ *
16
+ * @filter go_live_update_urls_updaters
17
+ *
18
+ * @return array
19
+ */
20
+ public function get_updaters() {
21
+ $updaters['json'] = 'Go_Live_Update_Urls__Updaters__JSON';
22
+ $updaters = apply_filters( 'go_live_update_urls_updaters', $updaters );
23
+ if ( ! is_array( $updaters ) ) {
24
+ return array();
25
+ }
26
+
27
+ return $updaters;
28
+ }
29
+
30
+
31
+
32
+ //********** SINGLETON **********/
33
+
34
+
35
+ /**
36
+ * Instance of this class for use as singleton
37
+ *
38
+ * @var self
39
+ */
40
+ protected static $instance;
41
+
42
+
43
+
44
+ /**
45
+ * Get (and instantiate, if necessary) the instance of the
46
+ * class
47
+ *
48
+ * @static
49
+ * @return self
50
+ */
51
+ public static function instance() {
52
+ if ( ! is_a( self::$instance, __CLASS__ ) ) {
53
+ self::$instance = new self();
54
+ }
55
+
56
+ return self::$instance;
57
+ }
58
+ }
views/admin-tools-page.php CHANGED
@@ -1,106 +1,145 @@
1
- <?php
2
- /**
3
- * Main Admin screen view
4
- *
5
- * @author Mat Lipe
6
- *
7
- * @uses may be overridden in your theme by putting a copy of this file inside a go-live-update-urls folder
8
- */
9
-
10
- $gluu = GoLiveUpdateUrls::get_instance();
11
-
12
- ?>
13
- <div id="gluu" class="wrap">
14
- <h2>Go Live Update Urls</h2>
15
-
16
- <p class="description">
17
- <?php printf( _x( 'This will replace all occurrences %sin the entire database%s of the Old URL with the New URL.', '{<strong>}', '{/strong}', 'go-live-update-urls' ), '<strong>', '</strong>' ); ?>
18
- </p>
19
-
20
- <strong>
21
- <em style="color:red">
22
- <?php _e( "Like any other database updating tool, you should always perform a backup before running.", 'go-live-update-urls' ); ?>
23
- </em>
24
- </strong>
25
- <hr />
26
-
27
- <form method="post" id="gluu-checkbox-form">
28
- <?php
29
- wp_nonce_field( GoLiveUpdateUrls::NONCE, GoLiveUpdateUrls::NONCE );
30
-
31
- do_action( 'gluu_before_checkboxes', $gluu );
32
-
33
- if( apply_filters( 'gluu-use-default_checkboxes', true ) ){
34
- ?>
35
- <h2>
36
- <?php _e( 'WordPress Core Tables', 'go-live-update-urls' ); ?>
37
- </h2>
38
- <p class="description">
39
- <?php _e( 'These tables are safe to update with the basic version of this plugin (the version you are currently using).', 'go-live-update-urls' ); ?>
40
- </p>
41
- <p>
42
- <input
43
- type="button"
44
- class="button-secondary checked gluu-tables-button"
45
- data-list="wp-core"
46
- value="<?php _e( 'un-check all', 'go-live-update-urls' ); ?>"
47
- data-checked="<?php _e( 'un-check all', 'go-live-update-urls' ); ?>"
48
- data-un-checked="<?php _e( 'check all', 'go-live-update-urls' ); ?>" />
49
- </p>
50
- <?php
51
- echo $gluu->makeCheckBoxes( $gluu->get_core_tables(), "wp-core" );
52
- ?>
53
-
54
- <hr />
55
-
56
- <h2>
57
- <?php _e( 'Tables Created By Plugins', 'go-live-update-urls' ); ?>
58
- </h2>
59
- <p class="description" style="color:red">
60
- <strong><?php printf( _x( 'These tables are probably NOT SAFE to update with the basic version of this plugin. %sTo support tables created by plugins use the %sPro Version%s.', '{<br />}{<a>}{</a>}', 'go-live-update-urls' ), '<br />', '<a href="https://matlipe.com/product/go-live-update-urls-pro/" target="_blank">', '</a>' ); ?></strong>
61
- </p>
62
- <p>
63
- <input
64
- type="button"
65
- class="button-secondary gluu-tables-button"
66
- data-list="custom-plugins"
67
- value="<?php _e( 'check all', 'go-live-update-urls' ); ?>"
68
- data-checked="<?php _e( 'un-check all', 'go-live-update-urls' ); ?>"
69
- data-un-checked="<?php _e( 'check all', 'go-live-update-urls' ); ?>" />
70
- </p>
71
- <?php
72
- echo $gluu->makeCheckBoxes( $gluu->get_custom_plugin_tables(), "custom-plugins", false );
73
- }
74
-
75
- do_action( 'gluu_after_checkboxes', $gluu );
76
-
77
- ?>
78
- <hr />
79
- <table class="form-table">
80
- <tr>
81
- <th scope="row" style="width:150px;">
82
- <b><?php _e( 'Old URL', 'go-live-update-urls' ); ?></b>
83
- </th>
84
- <td>
85
- <input name="oldurl" type="text" id="oldurl" value="" style="width:300px;" title="<?php _e( 'Old URL', 'go-live-update-urls' ); ?>"/>
86
- </td>
87
- </tr>
88
- <tr>
89
- <th scope="row" style="width:150px;">
90
- <b><?php _e( 'New URL', 'go-live-update-urls' ); ?></b>
91
- </th>
92
- <td>
93
- <input name="newurl" type="text" id="newurl" value="" style="width:300px;" title="<?php _e( 'New URL', 'go-live-update-urls' ); ?>"/>
94
- </td>
95
- </tr>
96
- </table>
97
- <p class="description">
98
- <strong>
99
- <?php
100
- echo apply_filters( 'gluu-uncheck-message', __( 'Only the checked tables will be updated.', 'go-live-update-urls' ) );
101
- ?>
102
- </strong>
103
- </p>
104
- <?php submit_button( __( 'Make It Happen', 'go-live-update-urls' ), 'primary', 'gluu-submit' ); ?>
105
- </form>
106
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Main Admin screen view
4
+ *
5
+ * @since 5.0.0
6
+ *
7
+ * @uses may be overridden in your theme by putting a copy of this file inside a go-live-update-urls folder
8
+ */
9
+
10
+ $db = Go_Live_Update_Urls_Database::instance();
11
+ $admin = Go_Live_Update_Urls_Admin_Page::instance();
12
+
13
+ ?>
14
+ <div id="go-live-update-urls/admin-page" class="wrap">
15
+ <h2>
16
+ <?php esc_html_e( 'Go Live Update Urls', 'go-live-update-urls' ); ?>
17
+ </h2>
18
+
19
+ <p class="description">
20
+ <?php
21
+ /* translators: <strong></strong> */
22
+ printf( esc_html_x( 'This will replace all occurrences %1$sin the entire database%2$s of the Old URL with the New URL.', '{<strong>} {</strong>}', 'go-live-update-urls' ), '<strong>', '</strong>' ); ?>
23
+ </p>
24
+
25
+ <strong>
26
+ <em style="color:red">
27
+ <?php esc_html_e( 'Like any other database updating tool, you should always perform a backup before running.', 'go-live-update-urls' ); ?>
28
+ </em>
29
+ </strong>
30
+ <hr/>
31
+
32
+ <form method="post" id="go-live-update-urls/checkbox-form">
33
+ <?php
34
+ wp_nonce_field( Go_Live_Update_Urls_Admin_Page::NONCE, Go_Live_Update_Urls_Admin_Page::NONCE );
35
+
36
+ do_action( 'gluu_before_checkboxes', $db );
37
+
38
+ if ( apply_filters( 'gluu-use-default_checkboxes', true ) ) {
39
+ ?>
40
+ <h2>
41
+ <?php esc_html_e( 'WordPress Core Tables', 'go-live-update-urls' ); ?>
42
+ </h2>
43
+ <p class="description" style="color:green">
44
+ <strong>
45
+ <?php esc_attr_e( 'These tables are safe to update with the basic version of this plugin.', 'go-live-update-urls' ); ?>
46
+ </strong>
47
+ </p>
48
+ <p>
49
+ <input
50
+ type="checkbox"
51
+ class="go-live-update-urls/checkboxes/check-all"
52
+ data-list="wp-core"
53
+ data-js="go-live-update-urls/checkboxes/check-all"
54
+ checked
55
+ />
56
+ <hr />
57
+ </p>
58
+ <?php $admin->render_check_boxes( $db->get_core_tables(), 'wp-core' );
59
+
60
+ $custom_tables = $db->get_custom_plugin_tables();
61
+ if ( ! empty( $custom_tables ) ) {
62
+ ?>
63
+ <hr/>
64
+
65
+ <h2>
66
+ <?php esc_html_e( 'Tables Created By Plugins', 'go-live-update-urls' ); ?>
67
+ </h2>
68
+ <p class="description" style="color:red">
69
+ <strong>
70
+ <?php
71
+ /* translators: <br /> <a> </a> */
72
+ printf( esc_html_x( 'These tables are probably NOT SAFE to update with the basic version of this plugin. %1$sTo support tables created by plugins use the %2$sPro Version%3$s.', '{<br />}{<a>}{</a>}', 'go-live-update-urls' ), '<br />', '<a href="https://matlipe.com/product/go-live-update-urls-pro/" target="_blank">', '</a>' ); ?></strong>
73
+ </p>
74
+ <p>
75
+ <input
76
+ type="checkbox"
77
+ class="go-live-update-urls/checkboxes/check-all"
78
+ data-list="custom-plugins"
79
+ data-js="go-live-update-urls/checkboxes/check-all"/>
80
+ <hr />
81
+ </p>
82
+ <?php $admin->render_check_boxes( $custom_tables, 'custom-plugins', false );
83
+ }
84
+ }
85
+
86
+ do_action( 'gluu_after_checkboxes', $db );
87
+
88
+ ?>
89
+ <hr/>
90
+ <table class="form-table" id="go-live-update-urls/url-fields">
91
+ <tr>
92
+ <th scope="row" style="width:150px;">
93
+ <label for="old_url">
94
+ <?php esc_html_e( 'Old URL', 'go-live-update-urls' ); ?>
95
+ </label>
96
+ </th>
97
+ <td>
98
+ <input
99
+ name="<?php echo esc_attr( Go_Live_Update_Urls_Admin_Page::OLD_URL ); ?>"
100
+ type="text"
101
+ id="old_url"
102
+ value=""
103
+ style="width:300px;"
104
+ title="<?php esc_attr_e( 'Old URL', 'go-live-update-urls' ); ?>"/>
105
+ </td>
106
+ </tr>
107
+ <tr>
108
+ <th scope="row" style="width:150px;">
109
+ <label for="new_url">
110
+ <?php esc_attr_e( 'New URL', 'go-live-update-urls' ); ?>
111
+ </label>
112
+ </th>
113
+ <td>
114
+ <input
115
+ name="<?php echo esc_attr( Go_Live_Update_Urls_Admin_Page::NEW_URL ); ?>"
116
+ type="text"
117
+ id="new_url"
118
+ value=""
119
+ style="width:300px;"
120
+ title="<?php esc_attr_e( 'New URL', 'go-live-update-urls' ); ?>"/>
121
+ </td>
122
+ </tr>
123
+ </table>
124
+ <p class="description">
125
+ <strong>
126
+ <?php
127
+ echo esc_html( apply_filters( 'gluu-uncheck-message', __( 'Only the checked tables will be updated.', 'go-live-update-urls' ) ) );
128
+ ?>
129
+ </strong>
130
+ </p>
131
+ <?php
132
+ if ( ! defined( 'GO_LIVE_UPDATE_URLS_PRO_VERSION' ) ) {
133
+ ?>
134
+ <p class="description" style="color:#23282d">
135
+ <strong>
136
+ <?php
137
+ /* translators: <a></a> */
138
+ printf( esc_html_x( 'To test this change before running it, use %1$sPro Version 2.0.0+%1$s.', '{<a>}{</a>}', 'go-live-update-urls' ), '<a href="https://matlipe.com/product/go-live-update-urls-pro/" target="_blank">', '</a>' ); ?></strong>
139
+ </p>
140
+ <?php
141
+ }
142
+ ?>
143
+ <?php submit_button( __( 'Make It Happen', 'go-live-update-urls' ), 'primary', Go_Live_Update_Urls_Admin_Page::SUBMIT ); ?>
144
+ </form>
145
+ </div>