| 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>'. $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: ' . $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( "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 |
define('DB_NAME', $_ENV['DB_NAME']); |
| 106 |
|
| 107 |
/** MySQL database username */ |
| 108 |
define('DB_USER', $_ENV['DB_USER']); |
| 109 |
|
| 110 |
/** MySQL database password */ |
| 111 |
define('DB_PASSWORD', $_ENV['DB_PASSWORD']); |
| 112 |
|
| 113 |
/** MySQL hostname; on Pantheon this includes a specific port number. */ |
| 114 |
define('DB_HOST', $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT']); |
| 115 |
} |
| 116 |
|
| 117 |
$config_files = array( |
| 118 |
dirname( $wp_config_dir_path ) . '/wp-config-local.php', |
| 119 |
dirname( $wp_config_dir_path ) . '/wp-config-hosting.php', |
| 120 |
$wp_config_dir_path, |
| 121 |
); |
| 122 |
$attempts = array( |
| 123 |
'standard', |
| 124 |
'normalize', |
| 125 |
); |
| 126 |
$methods = array( |
| 127 |
'php-define', |
| 128 |
'php-define-double-quote', |
| 129 |
'php-unquoted', |
| 130 |
); |
| 131 |
|
| 132 |
foreach ($config_files as $key => $config_file_path) { |
| 133 |
if ( !file_exists( $config_file_path ) ) { |
| 134 |
continue; |
| 135 |
} |
| 136 |
|
| 137 |
foreach ($attempts as $key => $attempt) { |
| 138 |
if ( $attempt === 'normalize' ) { |
| 139 |
$config_file = new PDT_Config( $config_file_path, true ); |
| 140 |
} else { |
| 141 |
$config_file = new PDT_Config( $config_file_path ); |
| 142 |
} |
| 143 |
foreach ($methods as $key => $method) { |
| 144 |
$config_file->set_type( $method ); |
| 145 |
if ( empty( $DB_USER ) ) { |
| 146 |
$DB_USER = $config_file->get_key( 'DB_USER' ); |
| 147 |
} |
| 148 |
if ( empty( $DB_NAME ) ) { |
| 149 |
$DB_NAME = $config_file->get_key( 'DB_NAME' ); |
| 150 |
} |
| 151 |
if ( empty( $DB_PASSWORD ) ) { |
| 152 |
$DB_PASSWORD = $config_file->get_key( 'DB_PASSWORD' ); |
| 153 |
} |
| 154 |
if ( empty( $DB_HOST ) ) { |
| 155 |
$DB_HOST = $config_file->get_key( 'DB_HOST' ); |
| 156 |
} |
| 157 |
if ( empty( $WP_CONTENT_DIR ) ) { |
| 158 |
$WP_CONTENT_DIR = $config_file->get_key( 'WP_CONTENT_DIR' ); |
| 159 |
} |
| 160 |
if ( empty( $WP_CONTENT_URL ) ) { |
| 161 |
$WP_CONTENT_URL = $config_file->get_key( 'WP_CONTENT_URL' ); |
| 162 |
} |
| 163 |
|
| 164 |
if ( !empty( $DB_USER ) ) { |
| 165 |
break; |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
if ( empty( $DB_USER ) ) { |
| 172 |
echo '<h3>Unable to read database credentials from wp-config.php</h3>'; |
| 173 |
echo '<h5>They should be formatted like this in your wp-config.php file:</h5>'; |
| 174 |
echo "<pre> |
| 175 |
// ** MySQL settings - You can get this info from your web host ** // |
| 176 |
define( 'DB_NAME', 'database_name_here' ); |
| 177 |
|
| 178 |
/** MySQL database username */ |
| 179 |
define( 'DB_USER', 'username_here' ); |
| 180 |
|
| 181 |
/** MySQL database password */ |
| 182 |
define( 'DB_PASSWORD', 'password_here' ); |
| 183 |
|
| 184 |
/** MySQL hostname */ |
| 185 |
define( 'DB_HOST', 'localhost' ); |
| 186 |
</pre>"; |
| 187 |
echo '<h5>If you are still having trouble connecting, please contact us by emailing support@tylerdigital.com with a copy of your file (you may want to remove any sensitive data first)</h5>'; |
| 188 |
exit(); |
| 189 |
} |
| 190 |
|
| 191 |
$DB_USER = str_replace( '");', '', $DB_USER ); |
| 192 |
$DB_USER = ( strpos( $DB_USER, '"' ) === 0 ) ? substr( $DB_USER, 1 ) : $DB_USER; |
| 193 |
$DB_USER = str_replace( '\');', '', $DB_USER ); |
| 194 |
$DB_USER = ( strpos( $DB_USER, '\'' ) === 0 ) ? substr( $DB_USER, 1 ) : $DB_USER; |
| 195 |
|
| 196 |
|
| 197 |
$DB_NAME = str_replace( '");', '', $DB_NAME ); |
| 198 |
$DB_NAME = ( strpos( $DB_NAME, '"' ) === 0 ) ? substr( $DB_NAME, 1 ) : $DB_NAME; |
| 199 |
$DB_NAME = str_replace( '\');', '', $DB_NAME ); |
| 200 |
$DB_NAME = ( strpos( $DB_NAME, '\'' ) === 0 ) ? substr( $DB_NAME, 1 ) : $DB_NAME; |
| 201 |
|
| 202 |
|
| 203 |
$DB_PASSWORD = str_replace( '");', '', $DB_PASSWORD ); |
| 204 |
$DB_PASSWORD = ( strpos( $DB_PASSWORD, '"' ) === 0 ) ? substr( $DB_PASSWORD, 1 ) : $DB_PASSWORD; |
| 205 |
$DB_PASSWORD = str_replace( '\');', '', $DB_PASSWORD ); |
| 206 |
$DB_PASSWORD = ( strpos( $DB_PASSWORD, '\'' ) === 0 ) ? substr( $DB_PASSWORD, 1 ) : $DB_PASSWORD; |
| 207 |
|
| 208 |
|
| 209 |
$DB_HOST = str_replace( '");', '', $DB_HOST ); |
| 210 |
$DB_HOST = ( strpos( $DB_HOST, '"' ) === 0 ) ? substr( $DB_HOST, 1 ) : $DB_HOST; |
| 211 |
$DB_HOST = str_replace( '\');', '', $DB_HOST ); |
| 212 |
$DB_HOST = ( strpos( $DB_HOST, '\'' ) === 0 ) ? substr( $DB_HOST, 1 ) : $DB_HOST; |
| 213 |
|
| 214 |
if ( !defined( 'DB_USER' ) ) { |
| 215 |
define( 'DB_USER', $DB_USER ); |
| 216 |
} |
| 217 |
if ( !defined( 'DB_NAME' ) ) { |
| 218 |
define( 'DB_NAME', $DB_NAME ); |
| 219 |
} |
| 220 |
if ( !defined( 'DB_PASSWORD' ) ) { |
| 221 |
define( 'DB_PASSWORD', $DB_PASSWORD ); |
| 222 |
} |
| 223 |
if ( !defined( 'DB_HOST' ) ) { |
| 224 |
define( 'DB_HOST', $DB_HOST ); |
| 225 |
} |
| 226 |
|
| 227 |
if ( !empty( $WP_CONTENT_DIR ) ) { |
| 228 |
define( 'WP_CONTENT_DIR', $WP_CONTENT_DIR ); |
| 229 |
} |
| 230 |
|
| 231 |
if ( !empty( $WP_CONTENT_URL ) ) { |
| 232 |
define( 'WP_CONTENT_URL', $WP_CONTENT_URL ); |
| 233 |
} |
| 234 |
|
| 235 |
$config_file->set_type( 'php-variable' ); |
| 236 |
global $table_prefix; |
| 237 |
$table_prefix = $config_file->get_key( 'table_prefix' ); |
| 238 |
$GLOBALS['table_prefix'] = $table_prefix; |
| 239 |
|
| 240 |
if ( !defined('WP_CONTENT_DIR') ) |
| 241 |
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down |
| 242 |
|
| 243 |
// Add define('WP_DEBUG', true); to wp-config.php to enable display of notices during development. |
| 244 |
if ( !defined('WP_DEBUG') ) |
| 245 |
define( 'WP_DEBUG', false ); |
| 246 |
|
| 247 |
// Add define('WP_DEBUG_DISPLAY', null); to wp-config.php use the globally configured setting for |
| 248 |
// display_errors and not force errors to be displayed. Use false to force display_errors off. |
| 249 |
if ( !defined('WP_DEBUG_DISPLAY') ) |
| 250 |
define( 'WP_DEBUG_DISPLAY', true ); |
| 251 |
|
| 252 |
// Add define('WP_DEBUG_LOG', true); to enable error logging to wp-content/debug.log. |
| 253 |
if ( !defined('WP_DEBUG_LOG') ) |
| 254 |
define('WP_DEBUG_LOG', false); |
| 255 |
|
| 256 |
if ( !defined('WP_CACHE') ) |
| 257 |
define('WP_CACHE', false); |
| 258 |
|
| 259 |
// Start of run timestamp. |
| 260 |
if ( ! defined( 'WP_START_TIMESTAMP' ) ) { |
| 261 |
define( 'WP_START_TIMESTAMP', microtime( true ) ); |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* Private |
| 266 |
*/ |
| 267 |
if ( !defined('MEDIA_TRASH') ) |
| 268 |
define('MEDIA_TRASH', false); |
| 269 |
|
| 270 |
if ( !defined('SHORTINIT') ) |
| 271 |
define('SHORTINIT', false); |
| 272 |
|
| 273 |
/** |
| 274 |
* Allows for the plugins directory to be moved from the default location. |
| 275 |
* |
| 276 |
* @since 2.6.0 |
| 277 |
*/ |
| 278 |
if ( !defined('WP_PLUGIN_DIR') ) |
| 279 |
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // full path, no trailing slash |
| 280 |
|
| 281 |
/** |
| 282 |
* Allows for the plugins directory to be moved from the default location. |
| 283 |
* |
| 284 |
* @since 2.1.0 |
| 285 |
* @deprecated |
| 286 |
*/ |
| 287 |
if ( !defined('PLUGINDIR') ) |
| 288 |
define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH. For back compat. |
| 289 |
|
| 290 |
/** |
| 291 |
* Allows for the mu-plugins directory to be moved from the default location. |
| 292 |
* |
| 293 |
* @since 2.8.0 |
| 294 |
*/ |
| 295 |
if ( !defined('WPMU_PLUGIN_DIR') ) |
| 296 |
define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); // full path, no trailing slash |
| 297 |
|
| 298 |
/** |
| 299 |
* Allows for the mu-plugins directory to be moved from the default location. |
| 300 |
* |
| 301 |
* @since 2.8.0 |
| 302 |
* @deprecated |
| 303 |
*/ |
| 304 |
if ( !defined( 'MUPLUGINDIR' ) ) |
| 305 |
define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // Relative to ABSPATH. For back compat. |
| 306 |
|
| 307 |
|
| 308 |
} |
| 309 |
|
| 310 |
} |
| 311 |
|