Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tim71

    (@tim71)

    Ok. I basically did as you suggested and it works great with one exception…

    I need current_user within the function and I cannot get_currentuserinfo() in function produce_my_json. My code is as follows…

    // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
    		if ( is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
    			$_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie'];
    		elseif ( empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
    			$_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie'];
    		if ( empty($_COOKIE[LOGGED_IN_COOKIE]) && !empty($_REQUEST['logged_in_cookie']) )
    			$_COOKIE[LOGGED_IN_COOKIE] = $_REQUEST['logged_in_cookie'];
    
    			unset($current_user);
    			 get_currentuserinfo();

    This works on the standalone page however it does not work within the ajax page as described above ($current_user is empty).

    I did manage to manually set the current user with the following code…

    $user = wp_validate_auth_cookie();
    wp_set_current_user($user);

    So I guess the question is why no $current_user in the ajax function? And is it ok to set it manually with the above code?

    -Tim

    Thread Starter tim71

    (@tim71)

    Thanks for the advice Otto. Much appreciated.

    Thread Starter tim71

    (@tim71)

    Otto,

    I believe what you say and typically do exactly what you advocate however in this case it is being posted to by SWFUpload and I took my cue from WordPress itself as well as NGG_Gallery Code.

    I did get it working using the rightfully dreaded wp-load technique. Does anyone know why wordpress and NGG_Gallery both use wp-load in a standalone page to post to?

    WordPress (async-upload.php):

    <?php
    /**
     * Accepts file uploads from swfupload or other asynchronous upload methods.
     *
     * @package WordPress
     * @subpackage Administration
     */
    
    define('WP_ADMIN', true);
    
    if ( defined('ABSPATH') )
    	require_once(ABSPATH . 'wp-load.php');
    else
    	require_once('../wp-load.php');
    
    ...
Viewing 3 replies - 1 through 3 (of 3 total)