WordPress.org

Ready to get started?Download WordPress

Forums

calling filters via ajax (2 posts)

  1. jesse.t
    Member
    Posted 1 year ago #

    I've created my WP ajax following the codex: http://codex.wordpress.org/AJAX_in_Plugins. I am trying to call specific filters based on user's interaction with my admin section. Unfortunately, I haven't been able to turn up anything on here or google about using ajax like this. Basically, when a user clicks a button, I need to set some filters to restrict upload types, among other things for the Media Upload box (Thickbox, ie tb_show()). What I have done so far is:

    click function:

    jQuery.post(
       ajaxurl,
       {action:'handlePDFUpload',
        ajaxNonce:hsciAjax.ajaxNonce},
       success: function() {
          tb_show('Please Select Your Completed Work Plan PDF', 'media-upload.php?type=file&TB_iframe=true&file=xxx&page=xxx');
       }
    );

    (return false to stop form submission)

    And the action handlePDF

    add_action( 'wp_ajax_handlePDFUpload', 'handlePDFUpload' );
    function handlePDFUpload() {
    	add_filter('media_upload_tabs', 'remove_media_library_tab');
    	$response = json_encode(array('success' => true));
    	header("Content-Type: application/json");
    	echo $response;
    	exit;
    }

    Removed nonce stuff so I don't exceed the code guidelines.

    Once this is handled, I would use the tb_close or tb_remove function to remove the filters at hand. The reason for this is I have 3 different upload button in which I need the users to upload very specific files. However, the filters are completely ignored when clicked. Any help would be greatly appreciated.

  2. jesse.t
    Member
    Posted 1 year ago #

    /bump? After searching for what seemed like forever on Google, I was able to confirm my suspicions that filters will not function if called via Ajax. It's kind of sad as that could remove some weird restrictions.

    This leads me to another question, since filters are set across the board, how would one go about doing stuff such as, When this button is clicked, save filename whatever_the_user_uploads.pdf to very_specific_name.pdf, any other time, save other files as normal?

    It seems the Media Upload Box (Pre 3.5) is extremely limited on functions.

Topic Closed

This topic has been closed to new replies.

About this Topic