| @@ -1,299 +1,328 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Troubleshoot Constants. | |
| 4 | - * | |
| 5 | - * @since 0.0.0 | |
| 6 | - * @package Troubleshoot | |
| 7 | - */ | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * Troubleshoot Constants. | |
| 11 | - * | |
| 12 | - * @since 0.0.0 | |
| 13 | - */ | |
| 14 | -class PDT_Constants { | |
| 15 | - /** | |
| 16 | - * Parent plugin class. | |
| 17 | - * | |
| 18 | - * @since 0.0.0 | |
| 19 | - * | |
| 20 | - * @var Troubleshoot | |
| 21 | - */ | |
| 22 | - protected $plugin = null; | |
| 23 | - | |
| 24 | - /** | |
| 25 | - * Constructor. | |
| 26 | - * | |
| 27 | - * @since 0.0.0 | |
| 28 | - * | |
| 29 | - * @param Troubleshoot $plugin Main plugin object. | |
| 30 | - */ | |
| 31 | - public function __construct( $plugin ) { | |
| 32 | - $this->plugin = $plugin; | |
| 33 | - $this->define_constants(); | |
| 34 | - } | |
| 35 | - | |
| 36 | - public function define_constants() { | |
| 37 | - // Define the directory seperator if it isn't already | |
| 38 | - if( !defined( 'DS' ) ) { | |
| 39 | - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { | |
| 40 | - define('DS', '\\'); | |
| 41 | - } | |
| 42 | - else { | |
| 43 | - define('DS', '/'); | |
| 44 | - } | |
| 45 | - } | |
| 46 | - | |
| 47 | - // Include plugin-detective-config.php if it exists | |
| 48 | - $path_to_pd_config = dirname( dirname( dirname ( $this->plugin->dir() ) ) ) . '/' . 'plugin-detective-config.php'; | |
| 49 | - if ( @file_exists( $path_to_pd_config ) ) { | |
| 50 | - include_once( $path_to_pd_config ); | |
| 51 | - } | |
| 52 | - | |
| 53 | - | |
| 54 | - // Define ABSPATH | |
| 55 | - if ( !defined('ABSPATH') ) { | |
| 56 | - $ABSPATH = dirname( dirname( dirname ( $this->plugin->dir() ) ) ) . '/'; | |
| 57 | - | |
| 58 | - for ($i=0; $i < 3; $i++) { | |
| 59 | - if ( @file_exists( $ABSPATH . 'wp-settings.php' ) ) { | |
| 60 | - define('ABSPATH', $ABSPATH ); | |
| 61 | - break; | |
| 62 | - } else if ( @file_exists( $ABSPATH . 'wp/wp-settings.php' ) ) { | |
| 63 | - define('ABSPATH', $ABSPATH . 'wp/' ); | |
| 64 | - break; | |
| 65 | - } | |
| 66 | - | |
| 67 | - $ABSPATH = dirname( $ABSPATH ) . '/'; | |
| 68 | - } | |
| 69 | - | |
| 70 | - if ( !defined( 'ABSPATH' ) ) { | |
| 71 | - echo '<p>It\'s possible you have an unusual directory structure, and we can\'t find the path to the root of your WordPress install.'.'</p>'; | |
| 72 | - echo '<p>You can tell Plugin Detective about your install by creating a config file here:</p>'; | |
| 73 | - echo '<pre>'. $path_to_pd_config .'</pre>'; | |
| 74 | - echo '<p>where you define the path to your WP install</p>'; | |
| 75 | - echo '<code>'. "define( 'ABSPATH', '/path/to/wordpress/install/' );" .'</code>'; | |
| 76 | - echo '<p>You may want to define other customized values like <code>WP_CONTENT_DIR</code>, <code>WP_CONTENT_URL</code> or other values from your wp-config.php file that are unique to your install</p>'; | |
| 77 | - echo '<p>Error details: <code>Couldn\'t find ABSPATH from plugin path: ' . $this->plugin->dir() . '</code></p>'; | |
| 78 | - echo '<style>code { color: #333; background-color: #ccc; padding: 5px; }</style>'; | |
| 79 | - exit(); | |
| 80 | - } | |
| 81 | - } | |
| 82 | - | |
| 83 | - // Search for wp-config.php | |
| 84 | - $wp_config_dir_path = ABSPATH . 'wp-config.php'; | |
| 85 | - if ( ! @file_exists( $wp_config_dir_path ) ) { | |
| 86 | - $wp_config_dir_path = dirname( ABSPATH ) . '/' . 'wp-config.php'; | |
| 87 | - | |
| 88 | - if ( ! @file_exists( $wp_config_dir_path ) ) { | |
| 89 | - $wp_config_dir_path = ABSPATH . 'wp' . '/' . 'wp-config.php'; | |
| 90 | - | |
| 91 | - if ( ! @file_exists( $wp_config_dir_path ) ) { | |
| 92 | - die( "Unable to locate wp-config.php file: \n" . ABSPATH. 'wp-config.php' . "\n OR \n" . dirname( ABSPATH ) . '/' . 'wp-config.php' ); | |
| 93 | - } | |
| 94 | - } | |
| 95 | - } | |
| 96 | - | |
| 97 | - | |
| 98 | - if ( isset($_ENV['PANTHEON_ENVIRONMENT']) ) { | |
| 99 | - define('DB_NAME', $_ENV['DB_NAME']); | |
| 100 | - | |
| 101 | - /** MySQL database username */ | |
| 102 | - define('DB_USER', $_ENV['DB_USER']); | |
| 103 | - | |
| 104 | - /** MySQL database password */ | |
| 105 | - define('DB_PASSWORD', $_ENV['DB_PASSWORD']); | |
| 106 | - | |
| 107 | - /** MySQL hostname; on Pantheon this includes a specific port number. */ | |
| 108 | - define('DB_HOST', $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT']); | |
| 109 | - } | |
| 110 | - | |
| 111 | - $config_files = array( | |
| 112 | - dirname( $wp_config_dir_path ) . '/wp-config-local.php', | |
| 113 | - dirname( $wp_config_dir_path ) . '/wp-config-hosting.php', | |
| 114 | - $wp_config_dir_path, | |
| 115 | - ); | |
| 116 | - $attempts = array( | |
| 117 | - 'standard', | |
| 118 | - 'normalize', | |
| 119 | - ); | |
| 120 | - $methods = array( | |
| 121 | - 'php-define', | |
| 122 | - 'php-define-double-quote', | |
| 123 | - 'php-unquoted', | |
| 124 | - ); | |
| 125 | - | |
| 126 | - foreach ($config_files as $key => $config_file_path) { | |
| 127 | - if ( !file_exists( $config_file_path ) ) { | |
| 128 | - continue; | |
| 129 | - } | |
| 130 | - | |
| 131 | - foreach ($attempts as $key => $attempt) { | |
| 132 | - if ( $attempt === 'normalize' ) { | |
| 133 | - $config_file = new PDT_Config( $config_file_path, true ); | |
| 134 | - } else { | |
| 135 | - $config_file = new PDT_Config( $config_file_path ); | |
| 136 | - } | |
| 137 | - foreach ($methods as $key => $method) { | |
| 138 | - $config_file->set_type( $method ); | |
| 139 | - if ( empty( $DB_USER ) ) { | |
| 140 | - $DB_USER = $config_file->get_key( 'DB_USER' ); | |
| 141 | - } | |
| 142 | - if ( empty( $DB_NAME ) ) { | |
| 143 | - $DB_NAME = $config_file->get_key( 'DB_NAME' ); | |
| 144 | - } | |
| 145 | - if ( empty( $DB_PASSWORD ) ) { | |
| 146 | - $DB_PASSWORD = $config_file->get_key( 'DB_PASSWORD' ); | |
| 147 | - } | |
| 148 | - if ( empty( $DB_HOST ) ) { | |
| 149 | - $DB_HOST = $config_file->get_key( 'DB_HOST' ); | |
| 150 | - } | |
| 151 | - if ( empty( $WP_CONTENT_DIR ) ) { | |
| 152 | - $WP_CONTENT_DIR = $config_file->get_key( 'WP_CONTENT_DIR' ); | |
| 153 | - } | |
| 154 | - if ( empty( $WP_CONTENT_URL ) ) { | |
| 155 | - $WP_CONTENT_URL = $config_file->get_key( 'WP_CONTENT_URL' ); | |
| 156 | - } | |
| 157 | - | |
| 158 | - if ( !empty( $DB_USER ) ) { | |
| 159 | - break; | |
| 160 | - } | |
| 161 | - } | |
| 162 | - } | |
| 163 | - } | |
| 164 | - | |
| 165 | - if ( empty( $DB_USER ) ) { | |
| 166 | - echo '<h3>Unable to read database credentials from wp-config.php</h3>'; | |
| 167 | - echo '<h5>They should be formatted like this in your wp-config.php file:</h5>'; | |
| 168 | - echo "<pre> | |
| 169 | -// ** MySQL settings - You can get this info from your web host ** // | |
| 170 | -define( 'DB_NAME', 'database_name_here' ); | |
| 171 | - | |
| 172 | -/** MySQL database username */ | |
| 173 | -define( 'DB_USER', 'username_here' ); | |
| 174 | - | |
| 175 | -/** MySQL database password */ | |
| 176 | -define( 'DB_PASSWORD', 'password_here' ); | |
| 177 | - | |
| 178 | -/** MySQL hostname */ | |
| 179 | -define( 'DB_HOST', 'localhost' ); | |
| 180 | -</pre>"; | |
| 181 | - echo '<h5>If you are still having trouble connecting, please contact us by emailing [email protected] with a copy of your file (you may want to remove any sensitive data first)</h5>'; | |
| 182 | - exit(); | |
| 183 | - } | |
| 184 | - | |
| 185 | - $DB_USER = str_replace( '");', '', $DB_USER ); | |
| 186 | - $DB_USER = ( strpos( $DB_USER, '"' ) === 0 ) ? substr( $DB_USER, 1 ) : $DB_USER; | |
| 187 | - $DB_USER = str_replace( '\');', '', $DB_USER ); | |
| 188 | - $DB_USER = ( strpos( $DB_USER, '\'' ) === 0 ) ? substr( $DB_USER, 1 ) : $DB_USER; | |
| 189 | - | |
| 190 | - | |
| 191 | - $DB_NAME = str_replace( '");', '', $DB_NAME ); | |
| 192 | - $DB_NAME = ( strpos( $DB_NAME, '"' ) === 0 ) ? substr( $DB_NAME, 1 ) : $DB_NAME; | |
| 193 | - $DB_NAME = str_replace( '\');', '', $DB_NAME ); | |
| 194 | - $DB_NAME = ( strpos( $DB_NAME, '\'' ) === 0 ) ? substr( $DB_NAME, 1 ) : $DB_NAME; | |
| 195 | - | |
| 196 | - | |
| 197 | - $DB_PASSWORD = str_replace( '");', '', $DB_PASSWORD ); | |
| 198 | - $DB_PASSWORD = ( strpos( $DB_PASSWORD, '"' ) === 0 ) ? substr( $DB_PASSWORD, 1 ) : $DB_PASSWORD; | |
| 199 | - $DB_PASSWORD = str_replace( '\');', '', $DB_PASSWORD ); | |
| 200 | - $DB_PASSWORD = ( strpos( $DB_PASSWORD, '\'' ) === 0 ) ? substr( $DB_PASSWORD, 1 ) : $DB_PASSWORD; | |
| 201 | - | |
| 202 | - | |
| 203 | - $DB_HOST = str_replace( '");', '', $DB_HOST ); | |
| 204 | - $DB_HOST = ( strpos( $DB_HOST, '"' ) === 0 ) ? substr( $DB_HOST, 1 ) : $DB_HOST; | |
| 205 | - $DB_HOST = str_replace( '\');', '', $DB_HOST ); | |
| 206 | - $DB_HOST = ( strpos( $DB_HOST, '\'' ) === 0 ) ? substr( $DB_HOST, 1 ) : $DB_HOST; | |
| 207 | - | |
| 208 | - if ( !defined( 'DB_USER' ) ) { | |
| 209 | - define( 'DB_USER', $DB_USER ); | |
| 210 | - } | |
| 211 | - if ( !defined( 'DB_NAME' ) ) { | |
| 212 | - define( 'DB_NAME', $DB_NAME ); | |
| 213 | - } | |
| 214 | - if ( !defined( 'DB_PASSWORD' ) ) { | |
| 215 | - define( 'DB_PASSWORD', $DB_PASSWORD ); | |
| 216 | - } | |
| 217 | - if ( !defined( 'DB_HOST' ) ) { | |
| 218 | - define( 'DB_HOST', $DB_HOST ); | |
| 219 | - } | |
| 220 | - | |
| 221 | - if ( !empty( $WP_CONTENT_DIR ) ) { | |
| 222 | - define( 'WP_CONTENT_DIR', $WP_CONTENT_DIR ); | |
| 223 | - } | |
| 224 | - | |
| 225 | - if ( !empty( $WP_CONTENT_URL ) ) { | |
| 226 | - define( 'WP_CONTENT_URL', $WP_CONTENT_URL ); | |
| 227 | - } | |
| 228 | - | |
| 229 | - $config_file->set_type( 'php-variable' ); | |
| 230 | - global $table_prefix; | |
| 231 | - $table_prefix = $config_file->get_key( 'table_prefix' ); | |
| 232 | - $GLOBALS['table_prefix'] = $table_prefix; | |
| 233 | - | |
| 234 | - if ( !defined('WP_CONTENT_DIR') ) | |
| 235 | - define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down | |
| 236 | - | |
| 237 | - // Add define('WP_DEBUG', true); to wp-config.php to enable display of notices during development. | |
| 238 | - if ( !defined('WP_DEBUG') ) | |
| 239 | - define( 'WP_DEBUG', false ); | |
| 240 | - | |
| 241 | - // Add define('WP_DEBUG_DISPLAY', null); to wp-config.php use the globally configured setting for | |
| 242 | - // display_errors and not force errors to be displayed. Use false to force display_errors off. | |
| 243 | - if ( !defined('WP_DEBUG_DISPLAY') ) | |
| 244 | - define( 'WP_DEBUG_DISPLAY', true ); | |
| 245 | - | |
| 246 | - // Add define('WP_DEBUG_LOG', true); to enable error logging to wp-content/debug.log. | |
| 247 | - if ( !defined('WP_DEBUG_LOG') ) | |
| 248 | - define('WP_DEBUG_LOG', false); | |
| 249 | - | |
| 250 | - if ( !defined('WP_CACHE') ) | |
| 251 | - define('WP_CACHE', false); | |
| 252 | - | |
| 253 | - /** | |
| 254 | - * Private | |
| 255 | - */ | |
| 256 | - if ( !defined('MEDIA_TRASH') ) | |
| 257 | - define('MEDIA_TRASH', false); | |
| 258 | - | |
| 259 | - if ( !defined('SHORTINIT') ) | |
| 260 | - define('SHORTINIT', false); | |
| 261 | - | |
| 262 | - /** | |
| 263 | - * Allows for the plugins directory to be moved from the default location. | |
| 264 | - * | |
| 265 | - * @since 2.6.0 | |
| 266 | - */ | |
| 267 | - if ( !defined('WP_PLUGIN_DIR') ) | |
| 268 | - define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // full path, no trailing slash | |
| 269 | - | |
| 270 | - /** | |
| 271 | - * Allows for the plugins directory to be moved from the default location. | |
| 272 | - * | |
| 273 | - * @since 2.1.0 | |
| 274 | - * @deprecated | |
| 275 | - */ | |
| 276 | - if ( !defined('PLUGINDIR') ) | |
| 277 | - define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH. For back compat. | |
| 278 | - | |
| 279 | - /** | |
| 280 | - * Allows for the mu-plugins directory to be moved from the default location. | |
| 281 | - * | |
| 282 | - * @since 2.8.0 | |
| 283 | - */ | |
| 284 | - if ( !defined('WPMU_PLUGIN_DIR') ) | |
| 285 | - define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); // full path, no trailing slash | |
| 286 | - | |
| 287 | - /** | |
| 288 | - * Allows for the mu-plugins directory to be moved from the default location. | |
| 289 | - * | |
| 290 | - * @since 2.8.0 | |
| 291 | - * @deprecated | |
| 292 | - */ | |
| 293 | - if ( !defined( 'MUPLUGINDIR' ) ) | |
| 294 | - define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // Relative to ABSPATH. For back compat. | |
| 295 | - | |
| 296 | - | |
| 297 | - } | |
| 298 | - | |
| 299 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Troubleshoot Constants. | |
| 4 | + * | |
| 5 | + * @since 0.0.0 | |
| 6 | + * @package Troubleshoot | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Troubleshoot Constants. | |
| 11 | + * | |
| 12 | + * @since 0.0.0 | |
| 13 | + */ | |
| 14 | +class PDT_Constants { | |
| 15 | + /** | |
| 16 | + * Parent plugin class. | |
| 17 | + * | |
| 18 | + * @since 0.0.0 | |
| 19 | + * | |
| 20 | + * @var Troubleshoot | |
| 21 | + */ | |
| 22 | + protected $plugin = null; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * Constructor. | |
| 26 | + * | |
| 27 | + * @since 0.0.0 | |
| 28 | + * | |
| 29 | + * @param Troubleshoot $plugin Main plugin object. | |
| 30 | + */ | |
| 31 | + public function __construct( $plugin ) { | |
| 32 | + $this->plugin = $plugin; | |
| 33 | + $this->define_constants(); | |
| 34 | + } | |
| 35 | + | |
| 36 | + public function define_constants() { | |
| 37 | + // Define the directory seperator if it isn't already | |
| 38 | + if( !defined( 'DS' ) ) { | |
| 39 | + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { | |
| 40 | + define('DS', '\\'); | |
| 41 | + } | |
| 42 | + else { | |
| 43 | + define('DS', '/'); | |
| 44 | + } | |
| 45 | + } | |
| 46 | + | |
| 47 | + // Include plugin-detective-config.php if it exists | |
| 48 | + $path_to_pd_config = dirname( dirname( dirname ( $this->plugin->dir() ) ) ) . '/' . 'plugin-detective-config.php'; | |
| 49 | + if ( @file_exists( $path_to_pd_config ) ) { | |
| 50 | + include_once( $path_to_pd_config ); | |
| 51 | + } | |
| 52 | + | |
| 53 | + | |
| 54 | + // Define ABSPATH | |
| 55 | + if ( !defined('ABSPATH') ) { | |
| 56 | + $ABSPATH = dirname( dirname( dirname ( $this->plugin->dir() ) ) ) . '/'; | |
| 57 | + | |
| 58 | + for ($i=0; $i < 3; $i++) { | |
| 59 | + if ( @file_exists( $ABSPATH . 'wp-settings.php' ) ) { | |
| 60 | + define('ABSPATH', $ABSPATH ); | |
| 61 | + break; | |
| 62 | + } else if ( @file_exists( $ABSPATH . 'wp/wp-settings.php' ) ) { | |
| 63 | + define('ABSPATH', $ABSPATH . 'wp/' ); | |
| 64 | + break; | |
| 65 | + } else if ( @file_exists( $ABSPATH . 'wp-load.php' ) ) { | |
| 66 | + define('ABSPATH', $ABSPATH . 'wp/' ); | |
| 67 | + break; | |
| 68 | + } else if ( @file_exists( $ABSPATH . 'wp/wp-load.php' ) ) { | |
| 69 | + define('ABSPATH', $ABSPATH . 'wp/' ); | |
| 70 | + break; | |
| 71 | + } | |
| 72 | + | |
| 73 | + $ABSPATH = dirname( $ABSPATH ) . '/'; | |
| 74 | + } | |
| 75 | + | |
| 76 | + if ( !defined( 'ABSPATH' ) ) { | |
| 77 | + echo '<p>It\'s possible you have an unusual directory structure, and we can\'t find the path to the root of your WordPress install.'.'</p>'; | |
| 78 | + echo '<p>You can tell Plugin Detective about your install by creating a config file here:</p>'; | |
| 79 | + echo '<pre>'. esc_html( $path_to_pd_config ) .'</pre>'; | |
| 80 | + echo '<p>where you define the path to your WP install</p>'; | |
| 81 | + echo '<code>'. "define( 'ABSPATH', '/path/to/wordpress/install/' );" .'</code>'; | |
| 82 | + echo '<p>You may want to define other customized values like <code>WP_CONTENT_DIR</code>, <code>WP_CONTENT_URL</code> or other values from your wp-config.php file that are unique to your install</p>'; | |
| 83 | + echo '<p>Error details: <code>Couldn\'t find ABSPATH from plugin path: ' . esc_html( $this->plugin->dir() ) . '</code></p>'; | |
| 84 | + echo '<style>code { color: #333; background-color: #ccc; padding: 5px; }</style>'; | |
| 85 | + exit(); | |
| 86 | + } | |
| 87 | + } | |
| 88 | + | |
| 89 | + // Search for wp-config.php | |
| 90 | + $wp_config_dir_path = ABSPATH . 'wp-config.php'; | |
| 91 | + if ( ! @file_exists( $wp_config_dir_path ) ) { | |
| 92 | + $wp_config_dir_path = dirname( ABSPATH ) . '/' . 'wp-config.php'; | |
| 93 | + | |
| 94 | + if ( ! @file_exists( $wp_config_dir_path ) ) { | |
| 95 | + $wp_config_dir_path = ABSPATH . 'wp' . '/' . 'wp-config.php'; | |
| 96 | + | |
| 97 | + if ( ! @file_exists( $wp_config_dir_path ) ) { | |
| 98 | + die( esc_html( "Unable to locate wp-config.php file: \n" . ABSPATH . 'wp-config.php' . "\n OR \n" . dirname( ABSPATH ) . '/' . 'wp-config.php' ) ); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + } | |
| 102 | + | |
| 103 | + | |
| 104 | + if ( isset($_ENV['PANTHEON_ENVIRONMENT']) ) { | |
| 105 | + // phpcs:disable WordPress.Security.ValidatedSanitizedInput -- Reading platform-provided database credentials from the Pantheon environment, not user input. | |
| 106 | + define('DB_NAME', $_ENV['DB_NAME']); | |
| 107 | + | |
| 108 | + /** MySQL database username */ | |
| 109 | + define('DB_USER', $_ENV['DB_USER']); | |
| 110 | + | |
| 111 | + /** MySQL database password */ | |
| 112 | + define('DB_PASSWORD', $_ENV['DB_PASSWORD']); | |
| 113 | + | |
| 114 | + /** MySQL hostname; on Pantheon this includes a specific port number. */ | |
| 115 | + define('DB_HOST', $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT']); | |
| 116 | + // phpcs:enable WordPress.Security.ValidatedSanitizedInput | |
| 117 | + } | |
| 118 | + | |
| 119 | + $config_files = array( | |
| 120 | + dirname( $wp_config_dir_path ) . '/wp-config-local.php', | |
| 121 | + dirname( $wp_config_dir_path ) . '/wp-config-hosting.php', | |
| 122 | + dirname( $wp_config_dir_path ) . '/wp-config-ddev.php', | |
| 123 | + $wp_config_dir_path, | |
| 124 | + ); | |
| 125 | + $attempts = array( | |
| 126 | + 'standard', | |
| 127 | + 'normalize', | |
| 128 | + ); | |
| 129 | + $methods = array( | |
| 130 | + 'php-define', | |
| 131 | + 'php-define-double-quote', | |
| 132 | + 'php-unquoted', | |
| 133 | + ); | |
| 134 | + | |
| 135 | + foreach ($config_files as $key => $config_file_path) { | |
| 136 | + if ( !file_exists( $config_file_path ) ) { | |
| 137 | + continue; | |
| 138 | + } | |
| 139 | + | |
| 140 | + foreach ($attempts as $key => $attempt) { | |
| 141 | + if ( $attempt === 'normalize' ) { | |
| 142 | + $config_file = new PDT_Config( $config_file_path, true ); | |
| 143 | + } else { | |
| 144 | + $config_file = new PDT_Config( $config_file_path ); | |
| 145 | + } | |
| 146 | + foreach ($methods as $key => $method) { | |
| 147 | + $config_file->set_type( $method ); | |
| 148 | + if ( empty( $DB_USER ) ) { | |
| 149 | + $DB_USER = $config_file->get_key( 'DB_USER' ); | |
| 150 | + } | |
| 151 | + if ( empty( $DB_NAME ) ) { | |
| 152 | + $DB_NAME = $config_file->get_key( 'DB_NAME' ); | |
| 153 | + } | |
| 154 | + if ( empty( $DB_PASSWORD ) ) { | |
| 155 | + $DB_PASSWORD = $config_file->get_key( 'DB_PASSWORD' ); | |
| 156 | + } | |
| 157 | + if ( empty( $DB_HOST ) ) { | |
| 158 | + $DB_HOST = $config_file->get_key( 'DB_HOST' ); | |
| 159 | + } | |
| 160 | + if ( empty( $WP_CONTENT_DIR ) ) { | |
| 161 | + $WP_CONTENT_DIR = $config_file->get_key( 'WP_CONTENT_DIR' ); | |
| 162 | + } | |
| 163 | + if ( empty( $WP_CONTENT_URL ) ) { | |
| 164 | + $WP_CONTENT_URL = $config_file->get_key( 'WP_CONTENT_URL' ); | |
| 165 | + } | |
| 166 | + | |
| 167 | + if ( !empty( $DB_USER ) ) { | |
| 168 | + break; | |
| 169 | + } | |
| 170 | + } | |
| 171 | + } | |
| 172 | + } | |
| 173 | + | |
| 174 | + if ( empty( $DB_USER ) ) { | |
| 175 | + echo '<h3>Unable to read database credentials from wp-config.php</h3>'; | |
| 176 | + echo '<h5>They should be formatted like this in your wp-config.php file:</h5>'; | |
| 177 | + echo "<pre> | |
| 178 | +// ** MySQL settings - You can get this info from your web host ** // | |
| 179 | +define( 'DB_NAME', 'database_name_here' ); | |
| 180 | + | |
| 181 | +/** MySQL database username */ | |
| 182 | +define( 'DB_USER', 'username_here' ); | |
| 183 | + | |
| 184 | +/** MySQL database password */ | |
| 185 | +define( 'DB_PASSWORD', 'password_here' ); | |
| 186 | + | |
| 187 | +/** MySQL hostname */ | |
| 188 | +define( 'DB_HOST', 'localhost' ); | |
| 189 | +</pre>"; | |
| 190 | + echo '<h5>If you are still having trouble connecting, please contact us by emailing [email protected] with a copy of your file (you may want to remove any sensitive data first)</h5>'; | |
| 191 | + exit(); | |
| 192 | + } | |
| 193 | + | |
| 194 | + $DB_USER = str_replace( '");', '', $DB_USER ); | |
| 195 | + $DB_USER = ( strpos( $DB_USER, '"' ) === 0 ) ? substr( $DB_USER, 1 ) : $DB_USER; | |
| 196 | + $DB_USER = str_replace( '\');', '', $DB_USER ); | |
| 197 | + $DB_USER = ( strpos( $DB_USER, '\'' ) === 0 ) ? substr( $DB_USER, 1 ) : $DB_USER; | |
| 198 | + | |
| 199 | + | |
| 200 | + $DB_NAME = str_replace( '");', '', $DB_NAME ); | |
| 201 | + $DB_NAME = ( strpos( $DB_NAME, '"' ) === 0 ) ? substr( $DB_NAME, 1 ) : $DB_NAME; | |
| 202 | + $DB_NAME = str_replace( '\');', '', $DB_NAME ); | |
| 203 | + $DB_NAME = ( strpos( $DB_NAME, '\'' ) === 0 ) ? substr( $DB_NAME, 1 ) : $DB_NAME; | |
| 204 | + | |
| 205 | + | |
| 206 | + $DB_PASSWORD = str_replace( '");', '', $DB_PASSWORD ); | |
| 207 | + $DB_PASSWORD = ( strpos( $DB_PASSWORD, '"' ) === 0 ) ? substr( $DB_PASSWORD, 1 ) : $DB_PASSWORD; | |
| 208 | + $DB_PASSWORD = str_replace( '\');', '', $DB_PASSWORD ); | |
| 209 | + $DB_PASSWORD = ( strpos( $DB_PASSWORD, '\'' ) === 0 ) ? substr( $DB_PASSWORD, 1 ) : $DB_PASSWORD; | |
| 210 | + | |
| 211 | + | |
| 212 | + $DB_HOST = str_replace( '");', '', $DB_HOST ); | |
| 213 | + $DB_HOST = ( strpos( $DB_HOST, '"' ) === 0 ) ? substr( $DB_HOST, 1 ) : $DB_HOST; | |
| 214 | + $DB_HOST = str_replace( '\');', '', $DB_HOST ); | |
| 215 | + $DB_HOST = ( strpos( $DB_HOST, '\'' ) === 0 ) ? substr( $DB_HOST, 1 ) : $DB_HOST; | |
| 216 | + | |
| 217 | + if ( !defined( 'DB_USER' ) ) { | |
| 218 | + define( 'DB_USER', $DB_USER ); | |
| 219 | + } | |
| 220 | + if ( !defined( 'DB_NAME' ) ) { | |
| 221 | + define( 'DB_NAME', $DB_NAME ); | |
| 222 | + } | |
| 223 | + if ( !defined( 'DB_PASSWORD' ) ) { | |
| 224 | + define( 'DB_PASSWORD', $DB_PASSWORD ); | |
| 225 | + } | |
| 226 | + if ( !defined( 'DB_HOST' ) ) { | |
| 227 | + define( 'DB_HOST', $DB_HOST ); | |
| 228 | + } | |
| 229 | + | |
| 230 | + if ( !empty( $WP_CONTENT_DIR ) ) { | |
| 231 | + define( 'WP_CONTENT_DIR', $WP_CONTENT_DIR ); | |
| 232 | + } | |
| 233 | + | |
| 234 | + if ( !empty( $WP_CONTENT_URL ) ) { | |
| 235 | + define( 'WP_CONTENT_URL', $WP_CONTENT_URL ); | |
| 236 | + } | |
| 237 | + | |
| 238 | + // Search every config file for $table_prefix, not just whichever one | |
| 239 | + // was last assigned by the DB_* loop above. Split-config layouts | |
| 240 | + // (DDEV, LocalWP, etc.) place credentials and $table_prefix in | |
| 241 | + // different files. | |
| 242 | + global $table_prefix; | |
| 243 | + $table_prefix = ''; | |
| 244 | + foreach ( $config_files as $config_file_path ) { | |
| 245 | + if ( ! file_exists( $config_file_path ) ) { | |
| 246 | + continue; | |
| 247 | + } | |
| 248 | + $config_file = new PDT_Config( $config_file_path ); | |
| 249 | + $config_file->set_type( 'php-variable' ); | |
| 250 | + $value = $config_file->get_key( 'table_prefix' ); | |
| 251 | + if ( ! empty( $value ) ) { | |
| 252 | + $table_prefix = $value; | |
| 253 | + break; | |
| 254 | + } | |
| 255 | + } | |
| 256 | + $GLOBALS['table_prefix'] = $table_prefix; | |
| 257 | + | |
| 258 | + if ( !defined('WP_CONTENT_DIR') ) | |
| 259 | + define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down | |
| 260 | + | |
| 261 | + // Add define('WP_DEBUG', true); to wp-config.php to enable display of notices during development. | |
| 262 | + if ( !defined('WP_DEBUG') ) | |
| 263 | + define( 'WP_DEBUG', false ); | |
| 264 | + | |
| 265 | + // Add define('WP_DEBUG_DISPLAY', null); to wp-config.php use the globally configured setting for | |
| 266 | + // display_errors and not force errors to be displayed. Use false to force display_errors off. | |
| 267 | + if ( !defined('WP_DEBUG_DISPLAY') ) | |
| 268 | + define( 'WP_DEBUG_DISPLAY', true ); | |
| 269 | + | |
| 270 | + // Add define('WP_DEBUG_LOG', true); to enable error logging to wp-content/debug.log. | |
| 271 | + if ( !defined('WP_DEBUG_LOG') ) | |
| 272 | + define('WP_DEBUG_LOG', false); | |
| 273 | + | |
| 274 | + if ( !defined('WP_CACHE') ) | |
| 275 | + define('WP_CACHE', false); | |
| 276 | + | |
| 277 | + // Start of run timestamp. | |
| 278 | + if ( ! defined( 'WP_START_TIMESTAMP' ) ) { | |
| 279 | + define( 'WP_START_TIMESTAMP', microtime( true ) ); | |
| 280 | + } | |
| 281 | + | |
| 282 | + /** | |
| 283 | + * Private | |
| 284 | + */ | |
| 285 | + if ( !defined('MEDIA_TRASH') ) | |
| 286 | + define('MEDIA_TRASH', false); | |
| 287 | + | |
| 288 | + if ( !defined('SHORTINIT') ) | |
| 289 | + define('SHORTINIT', false); | |
| 290 | + | |
| 291 | + /** | |
| 292 | + * Allows for the plugins directory to be moved from the default location. | |
| 293 | + * | |
| 294 | + * @since 2.6.0 | |
| 295 | + */ | |
| 296 | + if ( !defined('WP_PLUGIN_DIR') ) | |
| 297 | + define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // full path, no trailing slash | |
| 298 | + | |
| 299 | + /** | |
| 300 | + * Allows for the plugins directory to be moved from the default location. | |
| 301 | + * | |
| 302 | + * @since 2.1.0 | |
| 303 | + * @deprecated | |
| 304 | + */ | |
| 305 | + if ( !defined('PLUGINDIR') ) | |
| 306 | + define( 'PLUGINDIR', 'wp-content/plugins' ); // phpcs:ignore WordPress.WP.DiscouragedConstants.PLUGINDIRDeclarationFound -- Standalone bootstrap mirrors wp-settings.php and re-creates this back-compat core constant. | |
| 307 | + | |
| 308 | + /** | |
| 309 | + * Allows for the mu-plugins directory to be moved from the default location. | |
| 310 | + * | |
| 311 | + * @since 2.8.0 | |
| 312 | + */ | |
| 313 | + if ( !defined('WPMU_PLUGIN_DIR') ) | |
| 314 | + define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); // full path, no trailing slash | |
| 315 | + | |
| 316 | + /** | |
| 317 | + * Allows for the mu-plugins directory to be moved from the default location. | |
| 318 | + * | |
| 319 | + * @since 2.8.0 | |
| 320 | + * @deprecated | |
| 321 | + */ | |
| 322 | + if ( !defined( 'MUPLUGINDIR' ) ) | |
| 323 | + define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // phpcs:ignore WordPress.WP.DiscouragedConstants.MUPLUGINDIRDeclarationFound -- Standalone bootstrap mirrors wp-settings.php and re-creates this back-compat core constant. | |
| 324 | + | |
| 325 | + | |
| 326 | + } | |
| 327 | + | |
| 328 | +} | |