PluginProbe
Plugin Detective – Troubleshooting Conflicts / 1.1.2
Plugin Detective – Troubleshooting Conflicts v1.1.2
1.2.33 1.2.32 1.2.31 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2 1.2.1 1.2.10 1.2.12 1.2.13 1.2.14 1.2.16 1.2.19 1.2.20 1.2.22 1.2.23 1.2.24 1.2.25 All 53 releases
plugin-detective / troubleshoot / includes / class-constants.php

class-constants.php in Plugin Detective – Troubleshooting Conflicts 1.1.2, at troubleshoot/includes/class-constants.php

300 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 support@tylerdigital.com 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 }
300