Support » Plugins » Hacks » calling filters via ajax

  • I’ve created my WP ajax following the codex: 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:
       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;

    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.

Viewing 1 replies (of 1 total)
  • /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.

Viewing 1 replies (of 1 total)
  • The topic ‘calling filters via ajax’ is closed to new replies.