"deprecating" direct calls to wp-config.php

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

"deprecating" direct calls to wp-config.php

by Stephen Rider :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all --

I just wanted to call a bit of attention to this patch:
<http://core.trac.wordpress.org/ticket/11059>

Per a recent discussion on this list, we should be discouraging  
plugins calling wp-config.php directly.  The patch adds a "deprecated"  
call to wp-config/php that should only fire when it's called  
directly.  (Specifically, it only happens if the file is called and  
ABSPATH is not already defined.)

I wanted to point this out here, but let's keep discussion on the trac  
site itself and not clutter up wp-hackers.  Please reply there.

Regards,
Stephen

--
Stephen Rider
http://striderweb.com/




_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Claudio Simeone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/2 Stephen Rider <wp-hackers@...>:

> I just wanted to call a bit of attention to this patch:
> <http://core.trac.wordpress.org/ticket/11059>
>
> Per a recent discussion on this list, we should be discouraging plugins
> calling wp-config.php directly.

> Regards,
> Stephen

Hi Stephen,

what's the reason, in details, of discouraging direct calls of
wp-config.php (or similar of wp-load.php)?
Sometimes I include wp-load.php in scripts external to WP, so I can
use e.g., database functions etc in those scripts.
Is that correct, or is to be discouraged, and if so, what is the
correct way to use WP environment in external scripts?

thanks in advance.
Claudio
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Otto-19 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 3, 2009 at 9:43 AM, Claudio Simeone <mrbrog@...> wrote:
> what's the reason, in details, of discouraging direct calls of
> wp-config.php (or similar of wp-load.php)?
> Sometimes I include wp-load.php in scripts external to WP, so I can
> use e.g., database functions etc in those scripts.
> Is that correct, or is to be discouraged, and if so, what is the
> correct way to use WP environment in external scripts?

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.

If you're doing AJAX like requests and need access to WordPress
functions, then you could use techniques similar to these:
http://codex.wordpress.org/AJAX_in_Plugins

For most anything else, hooking into the template_redirect function to
produce your custom output is the better way to go.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Jason Benesch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Wordpress now has a 'wp_ajax_nopriv_my_action' in 2.8 for your ajax calls
but following up with what Otto wrote about the template_redirect, here is a
quick example of a way you could go about making ajax requests without
having to call wp-load directly from one of your external script files.
Someone please correct me if you see anything off:


Let's say your plugin name is incredible ajax or inc_ajax

// Create some extra variables to accept when passed through the url
function my_query_vars( $query_vars ) {
    $myvars = array( 'inc_ajax' );
    $query_vars = array_merge( $query_vars, $myvars );
    return $query_vars;
}
add_filter( 'query_vars', 'my_query_vars' );

// Flush your rewrite rules if you want pretty permalinks
function flush_rewrite_rules() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}
add_action( 'init', 'flush_rewrite_rules' );

// Create a rewrite rule if you want pretty permalinks
function add_rewrite_rules( $wp_rewrite ) {
    $wp_rewrite->add_rewrite_tag( "%inc_ajax%", "(.+?)", "inc_ajax=" );

    $urls = array( 'ajax/%inc_ajax%' );
    foreach( $urls as $url ) {
        $rule = $wp_rewrite->generate_rewrite_rules($url, EP_NONE, false,
false, false, false, false);
        $wp_rewrite->rules = array_merge( $rule, $wp_rewrite->rules );
    }
    return $wp_rewrite;
}
add_action( 'generate_rewrite_rules', 'add_rewrite_rules' );

// Let's echo out the content we are looking to dynamically grab before we
load any template files
function ajax_template() {
    global $wp, $wpdb;
    if( isset( $wp->query_vars['inc_ajax'] ) && !empty(
$wp->query_vars['inc_ajax'] ) ) {
        switch( $wp->query_vars['inc_ajax'] ) {
            case 'all_users':
                $all_users = $wpdb->get_results("SELECT * FROM
{$wpdb->users}");
                echo json_encode($all_users);
                exit;
            break;
            case 'some_users':
                $some_users = $wpdb->get_results( $wpdb->prepare( "SELECT *
FROM {$wpdb->users} WHERE id = %s", $_POST['user_id'] ) );
                echo json_encode($some_users);
                exit;
            break;
            default:
                echo 'You really shouldn't be here...';
                exit;
            break;
        }
    }
}
add_action( 'template_redirect', 'ajax_template' );




So now from your theme file, here is an example of an ajax request using
jQuery:

jQuery(function($) {
    $('#some_button').click(function(){
        $.post( "http://mywpdomain.com/ajax/all_users",
            function( data ) {
                console.log(data);
            }, json );
    });
});


My point being, you now have created an ajax request url for your blog.

You can obviously elaborate on this and you should probably use the WP
'wp_ajax_nopriv_my_action' action hook in 2.8...

But this is just an example of how you could avoid using loading the
wp-load, or wp-config from external scripts in your plugin.

Hope it helps sombody!




On Tue, Nov 3, 2009 at 9:05 AM, Otto <otto@...> wrote:

> On Tue, Nov 3, 2009 at 9:43 AM, Claudio Simeone <mrbrog@...> wrote:
> > what's the reason, in details, of discouraging direct calls of
> > wp-config.php (or similar of wp-load.php)?
> > Sometimes I include wp-load.php in scripts external to WP, so I can
> > use e.g., database functions etc in those scripts.
> > Is that correct, or is to be discouraged, and if so, what is the
> > correct way to use WP environment in external scripts?
>
> 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.
>
> If you're doing AJAX like requests and need access to WordPress
> functions, then you could use techniques similar to these:
> http://codex.wordpress.org/AJAX_in_Plugins
>
> For most anything else, hooking into the template_redirect function to
> produce your custom output is the better way to go.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



--
Jason Benesch

Real Estate Tomato
Co-owner
www.realestatetomato.com
(619) 770-1950
jason@...

ListingPress
Owner, Founder
www.listingpress.com
(619) 955-7465
jason@...
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Stephen Rider :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Nov 3, 2009, at 11:05 AM, Otto wrote:

> On Tue, Nov 3, 2009 at 9:43 AM, Claudio Simeone <mrbrog@...>  
> wrote:
>> Sometimes I include wp-load.php in scripts external to WP....
>> Is that correct, or is to be discouraged, and if so, what is the
>> correct way to use WP environment in external scripts?
>
> 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.

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. :)

> For most anything else, hooking into the template_redirect function to
> produce your custom output is the better way to go.

Stephen

--
Stephen Rider
http://striderweb.com/

_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Claudio Simeone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Ken Newman-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11/3/2009 3:08 PM, Claudio Simeone wrote:

> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>    
For integrating php apps with WordPress, you could use what is suggested
on bbpress.og [
http://bbpress.org/documentation/integration-with-wordpress/ ] which is
|require_once('path/to/wp-blog-header.php');| in your app. Hope this helps.
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Otto-19 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 3, 2009 at 2:08 PM, Claudio Simeone <mrbrog@...> wrote:
> 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.

From anything outside to WordPress itself, you should probably include
the wp-blog-header.php file. You can include wp-load.php, and it'll be
slightly faster, but not all the query stuff will get initialized
because wp() won't get called.

-Otto
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Claudio Simeone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/3 Otto <otto@...>:

> On Tue, Nov 3, 2009 at 2:08 PM, Claudio Simeone <mrbrog@...> wrote:
>> 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.
>
> From anything outside to WordPress itself, you should probably include
> the wp-blog-header.php file. You can include wp-load.php, and it'll be
> slightly faster, but not all the query stuff will get initialized
> because wp() won't get called.

Ken and Otto, thank you VERY much, especially for explaining the
difference between wp-load.php and wp-blog-header.php!

Claudio
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Parent Message unknown Re: "deprecating" direct calls to wp-config.php

by Stephen Rider :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That bit is copied straight from the existing _deprecated_file()  
function.

So if that is a problem, then it is also a bug in existing WP Core code.

Stephen

On Nov 4, 2009, at 9:59 AM, Andrew Nacin wrote:

> I haven't started to comment on Trac tickets yet, so I figured I'd  
> just drop you an e-mail. In your most recent patch in #11059, you  
> use true === WP_DEBUG. Really, it should be true == WP_DEBUG, as  
> that's the same check that is made in wp-settings.php. Otherwise,  
> someone using define('WP_DEBUG', 1) would get all debug notices  
> except for this proposed one.
>
> On Sun, Nov 1, 2009 at 21:56, Stephen Rider <wp-
> hackers@...> wrote:
> Hi all --
>
> I just wanted to call a bit of attention to this patch:
> <http://core.trac.wordpress.org/ticket/11059>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Eric Marden-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov 4, 2009, at 10:07 PM, Stephen Rider wrote:

>> Otherwise, someone using define('WP_DEBUG', 1)

The docs say to use a boolean value: http://codex.wordpress.org/Editing_wp-config.php#Debug

Just because 1 and 0 evaluate the same in many cases, they are still  
not bool values.


- Eric Marden
__________________________________
http://xentek.net/code/wordpress/





_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Autre Monde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I saw this subject so I tried to adapt my plugins but no luck so far :
(
I have used the example provided on the CoDex.

So I have removed the require_once wp-config.php
Then I have encapsulated all my js/jQuery ajax code into a php
function. Then I have hooked my function on admin_header and added a
require_once for the file including my ajax function into my main
plugin file but no luck, it doesn't work, the code is apparently not
hit :(

One issue I see about this change is that my ajax code will be loaded
on every admin page while right now it was loaded only for the
specific page it was intended to (thanks to the admin_print_scripts
hook) so it will be a performance degradation.

Isn't there any way to make everybody happy (ie finding a way to
properly locate the wp-config.php whatever the installation path is?).

Thanks!

Olivier
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Otto-19 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sounds like you're doing it wrong.

Where you load your javascript code is irrelevant. Load it on any page
you like, however you like.

The place where you load wp-config.php can be replaced by putting your
code in an action triggered by wp_ajax_whatever. That's the
difference.

And no, there is no reliable way to find and/or load wp-config. That's
simply the wrong way to do things, every single time. It's always been
the wrong way. And there's absolutely no guarantee that the method
will continue to work in the future.

-Otto



On Tue, Nov 17, 2009 at 8:33 AM, Olivier <autremonde75@...> wrote:

> Hello,
>
> I saw this subject so I tried to adapt my plugins but no luck so far :
> (
> I have used the example provided on the CoDex.
>
> So I have removed the require_once wp-config.php
> Then I have encapsulated all my js/jQuery ajax code into a php
> function. Then I have hooked my function on admin_header and added a
> require_once for the file including my ajax function into my main
> plugin file but no luck, it doesn't work, the code is apparently not
> hit :(
>
> One issue I see about this change is that my ajax code will be loaded
> on every admin page while right now it was loaded only for the
> specific page it was intended to (thanks to the admin_print_scripts
> hook) so it will be a performance degradation.
>
> Isn't there any way to make everybody happy (ie finding a way to
> properly locate the wp-config.php whatever the installation path is?).
>
> Thanks!
>
> Olivier
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Eric Marden-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> Isn't there any way to make everybody happy (ie finding a way to
> properly locate the wp-config.php whatever the installation path is?).


Doing it the right way will make everybody happy. :)

You DO NOT need to include wp-config.php for ajax in the admin nor the  
front-end, nor for just about anything else you might want to do in  
WordPress.

Your processing function should look like this:

add_action('wp_ajax_myhook','my_ajax_function');
function my_ajax_function()
{
   // do stuff and echo results
   exit;
}

Your ajax js should pass action=myhook somewhere in its request  
payload, and post to wp-admin/admin-ajax.php...  <?php echo  
admin_url("admin-ajax.php"); ?> is your friend here.

More Info: http://codex.wordpress.org/AJAX_in_Plugins

Add your script using a function that calls wp_enqueue_script:
http://codex.wordpress.org/Function_Reference/wp_enqueue_script

This function should hook in on admin_print_scripts. If you want to  
limit it to a certain page you can use the "admin_print_scripts-*"  
hook, where * is the page hook.

Briefly explained here: http://codex.wordpress.org/Plugin_API/Action_Reference#Administrative_Actions 
  and here: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head-%28plugin_page%29



Bottom line is that if your functionality is encapsulated properly in  
a plugin, you'll have full access to all of WordPress's API and there  
is almost nothing that you won't be able to accomplish. Plugin  
Development can be a departure from what you're used to doing as PHP  
Developer. I spent many years as a developer and never even considered  
using a callback (http://en.wikipedia.org/wiki/Callback_%28computer_science%29 
), but WordPress makes extensive use of them, because as a language  
construct they are incredibly powerful ways to let plugins do their  
thing during various stages of the WP execution life cycle.


HTH,


- Eric Marden
__________________________________
http://xentek.net/code/wordpress/
tw: @xentek




_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Autre Monde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Otto,

Thanks for your prompt answer! I don't really understand your
statment :
"The place where you load wp-config.php can be replaced by putting
your code in an action triggered by wp_ajax_whatever. That's the
difference."
I guess you are talking about some kind of action hook like
add_action('admin_header','my_ajax_function');
Right? Do I place this action hook in the same file as the ajax
function, no matter where is the hook?

How do I link my include ajax function code into the plugin? By
enqueuing the script through an admin_print_scripts callback function?
Or rather by a require_once in the plugin master file?

Sorry if this is obvious for you but it is really not for. I have
tried several things and I am not able to find a solution to remove
the wp-config.php :(

Eric,

Thanks as well for your point. The admin_url is a function that
requires the wp-config.php to be loaded (until I find a solution to
bypass it).

Thanks again!

Olivier
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Otto-19 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Have you read the codex article? I thought it was perfectly clear.
http://codex.wordpress.org/AJAX_in_Plugins

I'll try to as simple as possible here:

1. You have some code that you want to call via an AJAX request. That
code will go in a plugin, like this:

add_action('wp_ajax_whatever', 'whatever_callback');
function whatever_callback() {
// do anything you like here
// check $_POST, whatever you want, All WordPress is available to you
// echo out whatever you like to return back to the AJAX call, then
die();
}

That is the server side code. That is what you will be calling. That's
what replaces the need for you to load wp-config.php at all.

The trick to this is that you won't call yourfile.php directly from
your javascript any more. Instead, your javascript will call the
admin-ajax.php file. The exact URL your javascript needs to call can
be generated using admin_url("admin-ajax.php"). So, when you're
outputting your javascript (and this can be anywhere you like, mind
you, not just in admin_header), then you'll use that as the point to
which you make the request.

For example, in jQuery, you'd do something like this:

jQuery(document).ready(function($) {
        var data = {
                action: 'whatever',
                anything: 'you like here'
        };
        jQuery.post(<?php echo admin_url("admin-ajax.php"); ?>, data,
function(response) {
                alert('Got this from the server: ' + response);
        });
});


See? It's making a POST request to the admin-ajax file. The "action"
of "whatever" is what triggers that call to the wp_ajax_whatever
action hook, which then runs your server side code within the
WordPress context.

No need for calling wp-config.php anywhere.

-Otto



On Tue, Nov 17, 2009 at 10:29 AM, Olivier <autremonde75@...> wrote:

> Otto,
>
> Thanks for your prompt answer! I don't really understand your
> statment :
> "The place where you load wp-config.php can be replaced by putting
> your code in an action triggered by wp_ajax_whatever. That's the
> difference."
> I guess you are talking about some kind of action hook like
> add_action('admin_header','my_ajax_function');
> Right? Do I place this action hook in the same file as the ajax
> function, no matter where is the hook?
>
> How do I link my include ajax function code into the plugin? By
> enqueuing the script through an admin_print_scripts callback function?
> Or rather by a require_once in the plugin master file?
>
> Sorry if this is obvious for you but it is really not for. I have
> tried several things and I am not able to find a solution to remove
> the wp-config.php :(
>
> Eric,
>
> Thanks as well for your point. The admin_url is a function that
> requires the wp-config.php to be loaded (until I find a solution to
> bypass it).
>
> Thanks again!
>
> Olivier
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Autre Monde :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Otto,

Yes I have read the Codex.

I think I haven't explained clearly enough where my problem was, sorry
for that.

The issue isn't with the Ajax callback. I am able to have this working
properly without any problem.

The issue is with the javascript/jQuery code (client side). If I
remove the call the wp-config.php, then when the JS code is generated
and added into the html file sent to the client, this php part won't
be resolved : <?php echo admin_url("admin-ajax.php"); ?> potentially
because admin_url is a function known through the core...

That's it, no issue with the server side ajax handling, I don't have
anything to change on that front as I am already using the admin-ajax
hooking style. The issue is really with the client side and providing
the right URL to call which I can't if I don't have a way to get the
admin_url resolved.

Sorry for the confusion...

Olivier
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Otto-19 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 17, 2009 at 10:44 AM, Olivier <autremonde75@...> wrote:

> The issue is with the javascript/jQuery code (client side). If I
> remove the call the wp-config.php, then when the JS code is generated
> and added into the html file sent to the client, this php part won't
> be resolved : <?php echo admin_url("admin-ajax.php"); ?> potentially
> because admin_url is a function known through the core...
>
> That's it, no issue with the server side ajax handling, I don't have
> anything to change on that front as I am already using the admin-ajax
> hooking style. The issue is really with the client side and providing
> the right URL to call which I can't if I don't have a way to get the
> admin_url resolved.

Okay, but that makes no particular sense to me. If you're in a plugin
context, then you don't have to include wp-config. You're already
running inside WordPress.

Why are you having to include the wp-config.php there? Are you
generating this through a separate PHP file or something?

How, exactly, are you generating this Javascript right now? How does
it get included onto the page in question?

-Otto
Sent from Memphis, TN, United States
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Tiago Relvao :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You already have a js var defined for that: ajaxurl
You just have to use it as yout url.

Tiago


Otto wrote:

> On Tue, Nov 17, 2009 at 10:44 AM, Olivier <autremonde75@...> wrote:
>  
>> The issue is with the javascript/jQuery code (client side). If I
>> remove the call the wp-config.php, then when the JS code is generated
>> and added into the html file sent to the client, this php part won't
>> be resolved : <?php echo admin_url("admin-ajax.php"); ?> potentially
>> because admin_url is a function known through the core...
>>
>> That's it, no issue with the server side ajax handling, I don't have
>> anything to change on that front as I am already using the admin-ajax
>> hooking style. The issue is really with the client side and providing
>> the right URL to call which I can't if I don't have a way to get the
>> admin_url resolved.
>>    
>
> Okay, but that makes no particular sense to me. If you're in a plugin
> context, then you don't have to include wp-config. You're already
> running inside WordPress.
>
> Why are you having to include the wp-config.php there? Are you
> generating this through a separate PHP file or something?
>
> How, exactly, are you generating this Javascript right now? How does
> it get included onto the page in question?
>
> -Otto
> Sent from Memphis, TN, United States
> _______________________________________________
> wp-hackers mailing list
> wp-hackers@...
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>  
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: "deprecating" direct calls to wp-config.php

by Eric Marden-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Nov 17, 2009, at 11:29 AM, Olivier wrote:

> Sorry if this is obvious for you but it is really not for. I have
> tried several things and I am not able to find a solution to remove
> the wp-config.php :(


I just walked you through the entire process. What you're missing is  
that your code is obviously not inside a plugin, else you'd have  
access to the WP API. Either way, you're still doing it wrong.


- Eric Marden
__________________________________
http://xentek.net/code/wordpress/
tw: @xentek




_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers
< Prev | 1 - 2 | Next >