[wp-trac] [WordPress Trac] #11059: Discourage plugin authors calling wp-config.php directly

WordPress Trac wp-trac at lists.automattic.com
Mon Nov 2 14:03:36 UTC 2009


#11059: Discourage plugin authors calling wp-config.php directly
-------------------------+--------------------------------------------------
 Reporter:  strider72    |       Owner:           
     Type:  enhancement  |      Status:  new      
 Priority:  normal       |   Milestone:  3.0      
Component:  General      |     Version:  2.9      
 Severity:  normal       |    Keywords:  has-patch
-------------------------+--------------------------------------------------

Comment(by strider72):

 Replying to [comment:3 xenlab]:
 > With WP_DEBUG set to true, and the patch applied, I created this little
 plugin[...]. No deprecation warnings, and surprisingly no complaint about
 _deprecated_file(), though dd32 is probably correct in saying that its not
 defined, since it lives in wp-includes/functions.php
 >
 > Either way, it doesn't seem to do the trick.

 Generally speaking (though I'm sure there are exceptions) plugins call the
 file directly when they have some "stand alone" PHP file that runs outside
 of WordPress, but they want to access the database.  So calling it from
 directly within a plugin's main file as your test does is not common.

 However, that does point out the obvious point that _deprecated_file()
 will definitely not be defined.  I wonder if we need to minimally recreate
 that function directly instead of trying to call it?  Maybe something
 like:

 if( defined( 'WP_DEBUG' ) && ( true === WP_DEBUG ) ) {
         trigger_error( sprintf( __('%1$s is <strong>deprecated</strong>
 since version %2$s! Use %3$s instead.'), 'Calling wp-config.php directly
 from a plugin', '0.0', 'wp-load.php' ) );
 }


 We don't get the filters or the actions, but of course apply_filters etc.
 won't exist either in these cases.  Still creates a caution to coders,
 which may be useful.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11059#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list