[wp-hackers] "deprecating" direct calls to wp-config.php
Claudio Simeone
mrbrog at gmail.com
Tue Nov 3 20:08:39 UTC 2009
Otto wrote:
>> The correct way depends on what exactly you're doing. However, there's
>> never any real reason to include wp-config or wp-load directly. Doing
>> so is.. not wrong, exactly... just a bit sloppy. It's error-prone,
>> more likely to break things.
[...]
>> For most anything else, hooking into the template_redirect function to
>> produce your custom output is the better way to go.
Stephen Rider wrote:
> A little more specifically, as of WP 2.6, wp-config.php may be one directory
> up from where you expect it, which can break things. Not only will you
> plugin be looking for a file that isn't there, but if a moved wp-config.php
> sets ABSPATH, ABSPATH will be *wrong*.
>
> Thus if you absolutely must call one of these directly, call wp-load.php as
> it doesn't ever move.
>
> Beyond that, Otto's advice is good. :)
Thank you all for your answers. Maybe I didn't explain well myself,
and I apologize for this :)
When I need to extend my WP, I do that in the clean way, writing
plugins, using built-in hooks and filters, the correct ajax calls, and
everything goes all right.
So my question was more related to a scenario in which I need to
"import" all WP functions, into another - external - script, that is
not directly connected with my WP installation, or it is not inside my
installation.
Let's say I have another CMS and I want to retrieve some info from the
database (making a sort of integration), for example the last 3 posts
(I know that I can get these informations via the RSS Feed, but this
is only an example), it's very easy to me to create a ph script
'last_posts.php' and make something like:
<?php
include_once('wordpress/wp-load.php'); // or wherever it is
$lastposts = get_posts('numberposts=3');
foreach($lastposts as $post) :
setup_postdata($post);
?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endforeach; ?>
with this trick I can use the Loop in an external file, and very
important, I can use all WP functions, instead to reinvent the wheel
using php mysql functions and "classic" code, and writing new
functions from scratch for example to get the post permalinks.
I know that is as Otto says, sloppy, but it's my way to "use" WP
system in external scripts.
So I asked if this is a wrong way of using WP and if there is a right
way to achieve the same result.
thanks again
Claudio
More information about the wp-hackers
mailing list