[wp-trac] [WordPress Trac] #9444: Allow to read wp-config.php without loading WP

WordPress Trac noreply at wordpress.org
Sun Feb 15 04:08:08 UTC 2015


#9444: Allow to read wp-config.php without loading WP
--------------------------------------------------+----------------------
 Reporter:  hakre                                 |       Owner:
     Type:  defect (bug)                          |      Status:  closed
 Priority:  normal                                |   Milestone:
Component:  General                               |     Version:  2.7.1
 Severity:  normal                                |  Resolution:  wontfix
 Keywords:  has-patch tested commit dev-feedback  |     Focuses:
--------------------------------------------------+----------------------

Comment (by rpayne7264):

 That is unacceptable. I am writing plug-ins that deal with oAuth. I can't
 instruct users of my plug-in to modify/create core php files. And because
 I am having to call the core wp_load.php file to get access to the
 database so my plug-in works correctly on WPEngine, it is not being
 accepted into the plug-in repository.

 I have a possible solution that will require loading wp_includes/wp-db.php
 & wp-includes/option.php so I can get the database access I need. But, I
 don't know if that will cause another decline of my plug-in being accepted
 into the repository.

 I can use something like the following code to gather the necessary
 credentials to instantiate an wpdb class and assign it to global variable
 $wpdb, and then use the WP Transient API, I think.

 $array = file("wp-config.php");
 $dbArray = array();
 $x = array('DB_NAME','DB_USER','DB_PASSWORD','DB_HOST');
 foreach ( $array as $line ) {
         $matches=array();
     if (preg_match('/DEFINE\(\'(.*?)\',\s*\'(.*)\'\);/i', $line,
 $matches)) {
         $name=$matches[1];
         $value=$matches[2];
         if(in_array( $name, $x ))$dbArray[$name]= $value;
     }
 }

--
Ticket URL: <https://core.trac.wordpress.org/ticket/9444#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list