WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to put the WP Pluploader into a meta box on my posts page - as per Plupload Intergration in a meta-box? and http://www.krishnakantsharma.com/2012/01/image-uploads-on-wordpress-admin-screens-using-jquery-and-new-plupload/

I got it all working as in the example in the second link. However, I want to put it all into a class file. It stops working if I wrap it all into a Class. And it's all because of:

function g_plupload_action()
    // check ajax noonce
    $imgid = $_POST["imgid"];
    check_ajax_referer($imgid . 'pluploadan');

    // handle file upload
    $status = wp_handle_upload($_FILES[$imgid . 'async-upload'], array('test_form' => true, 'action' => 'plupload_action'));

    // send the uploaded file url in response
    echo $status['url'];

It works if this function is outside the Class and called through:

add_action('wp_ajax_plupload_action', "g_plupload_action");

But inside the Class and called with:

add_action('wp_ajax_plupload_action', array($this, 'g_plupload_action'));

and the return data is 0.

What do I need to do in function g_plupload_action() to make it work?

share|improve this question
up vote 2 down vote accepted

Aha, the problem as that I was calling the wp_ajax_plupload_action from within my page conditional check like so:

function __construct()
    global $pagenow;

    $pages = array('post.php', 'post-new.php');

    if (in_array($pagenow, $pages)) :

        add_action('add_meta_boxes', array($this, 'dhf_video_meta_box'));
        add_action('admin_print_scripts', array($this, 'video_meta_js'));
        add_action('admin_head', array($this, 'plupload_admin_head'));
        add_action('admin_print_scripts', array($this, 'video_meta_css'));
        add_action('wp_ajax_plupload_action', array($this, 'plupload_action'));


You don't want to do it like that. Take the add_action('wp_ajax_plupload_action', array($this, 'plupload_action')); outside of that check and everything works again.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.