PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 3.0.2
WP STAGING – WordPress Backups, Restore, Migration & Clone v3.0.2
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Traits / DatabaseSearchReplaceTrait.php
wp-staging / Framework / Traits Last commit date
ArrayableTrait.php 5 years ago BenchmarkTrait.php 3 years ago BooleanTransientTrait.php 5 years ago DatabaseSearchReplaceTrait.php 5 years ago DbRowsGeneratorTrait.php 4 years ago DeveloperTimerTrait.php 4 years ago FileScanToCacheTrait.php 3 years ago HydrateTrait.php 3 years ago MaintenanceTrait.php 5 years ago MySQLRowsGeneratorTrait.php 3 years ago NoticesTrait.php 3 years ago PropertyConstructor.php 5 years ago ResourceTrait.php 3 years ago
DatabaseSearchReplaceTrait.php
101 lines
1 <?php
2
3 namespace WPStaging\Framework\Traits;
4
5 use WPStaging\Core\Utils\Helper;
6 use WPStaging\Core\WPStaging;
7 use WPStaging\Framework\Staging\Sites;
8
9 /**
10 * Trait DatabaseSearchReplaceTrait
11 *
12 * This trait puts together some common functionality for database search and replace
13 * used both by Cloning and Backups. This is not ideal, and should be refactored in the future
14 * for a more robust and proper architecture.
15 *
16 * @package WPStaging\Framework\Traits
17 */
18 trait DatabaseSearchReplaceTrait
19 {
20 private $excludedStrings = [
21 'Admin_custome_login_Slidshow',
22 'Admin_custome_login_Social',
23 'Admin_custome_login_logo',
24 'Admin_custome_login_text',
25 'Admin_custome_login_login',
26 'Admin_custome_login_top',
27 'Admin_custome_login_dashboard',
28 'Admin_custome_login_Version',
29 'upload_path',
30 'wpstg_existing_clones_beta',
31 'wpstg_existing_clones',
32 Sites::STAGING_SITES_OPTION,
33 'wpstg_settings',
34 'wpstg_license_status',
35 'wpstg_tmp_data',
36 'siteurl',
37 'home'
38 ];
39
40 public function excludedStrings()
41 {
42 return $this->excludedStrings;
43 }
44
45 /**
46 * Prepend the following characters to string: %2F%2F, \/\/, //
47 * This is to make sure that only valid hostnames are replaced
48 * @param $string
49 * @return string[]
50 */
51 public function generateHostnamePatterns($string)
52 {
53 return [
54 '%2F%2F' . str_replace('/', '%2F', $string), // HTML entity for WP Backery Page Builder Plugin
55 '\/\/' . str_replace('/', '\/', $string), // Escaped \/ used by revslider and several visual editors
56 '//' . $string // //example.com
57 ];
58 }
59
60 private function getSourceHostname()
61 {
62 $helper = WPStaging::getInstance()->getContainer()->make(Helper::class);
63
64 if ($this->isSubDir()) {
65 return trailingslashit($helper->getHomeUrlWithoutScheme()) . $this->getSubDir();
66 }
67
68 return $helper->getHomeUrlWithoutScheme();
69 }
70
71 /**
72 * Check if WP is installed in subdir
73 * @return boolean
74 */
75 private function isSubDir()
76 {
77 // Compare names without scheme to bypass cases where siteurl and home have different schemes http / https
78 // This is happening much more often than you would expect
79 $siteurl = preg_replace('#^https?://#', '', rtrim(get_option('siteurl'), '/'));
80 $home = preg_replace('#^https?://#', '', rtrim(get_option('home'), '/'));
81
82 return $home !== $siteurl;
83 }
84
85 /**
86 * Get the install sub directory if WP is installed in sub directory
87 * @return string
88 */
89 private function getSubDir()
90 {
91 $home = get_option('home');
92 $siteurl = get_option('siteurl');
93
94 if (empty($home) || empty($siteurl)) {
95 return '';
96 }
97
98 return str_replace([$home, '/'], '', $siteurl);
99 }
100 }
101