Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#40474 closed defect (bug) (invalid)

wp_ajax_(action) hook doesn't work in media gallery

Reported by: hoandang's profile hoandang Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.3
Component: Media Keywords:
Focuses: Cc:

Description (last modified by johnbillion)

Step to reproduce:

  1. Open an image in Grid view mode
  2. Change image title
  3. Add this hook in functions.php
    <?php
    add_action('wp_ajax_save-attachment', function($array, $int) {
        var_dump('save-attachment');
    }, 10, 2);
    

Expected: A var_dump result in http network.
Actual: http always responses {"success":true}

https://i.imgur.com/pGF8Rku.png

Change History (5)

#1 follow-up: @bhargavbhandari90
8 years ago

Hi @hoandang

Not able to see anything from the url you provided. Is there something you want to point out by that url

#2 in reply to: ↑ 1 @hoandang
8 years ago

Sorry, I can't see the button to edit my post. Please see the fixed image http://i.imgur.com/pGF8Rku.png

Just to elaborate the bug, the ajax request comes from media gallery not from my custom ajax request. The hook works fine with "wp_ajax_save-attachment-compat" but "wp_ajax_save-attachment"

Replying to bhargavbhandari90:

Hi @hoandang

Not able to see anything from the url you provided. Is there something you want to point out by that url

Last edited 8 years ago by hoandang (previous) (diff)

#3 follow-up: @subrataemfluence
8 years ago

@hoandang where and how are you getting the var_dump output?

#4 in reply to: ↑ 3 @hoandang
8 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Just double-checked the doc and it states that the "wp_ajax_(action)" hook works only with custom ajax requests, so that explains the builtin wordpress ajax requests such as "save-attachment" don't work.

The issue seems to be a missing feature in wordpress, it is not really a bug.

#5 @johnbillion
8 years ago

  • Component changed from HTTP API to Media
  • Description modified (diff)
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.