#42840 closed defect (bug) (worksforme)
New plugin / theme editor wp_ajax_ save hook not working or inexistent
| Reported by: | cristianuibar | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Editor | Version: | 4.9.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
Hello,
We are trying to use a hook using: https://developer.wordpress.org/reference/hooks/wp_ajax__requestaction/
for the new Code Editor in Plugins and Theme.
Add any of these hooks using add_action(), and they will not work.
Neighter
wp_ajax_edit_theme_plugin_file, nor
wp_ajax_edit-theme-plugin-file
works.
I expected the hooks to work and they didn't.
We tried an alternative using the 'wp_doing_ajax' hook, but it executes twice per request, even though we were checking for:
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit-theme-plugin-file')
Best,
Cristian Uibar
Change History (3)
#2
@
9 years ago
- Milestone Awaiting Review
- Resolution → worksforme
- Status new → closed
Hi @cristianuibar
As @birgire alluded to, this is because your action is hooked later than when the core action runs, you'll need to hook in at priority 0 or lower: edit: I originally said 9, but that doesn't work, use 0 or -1 and it will work.
add_action( 'wp_ajax_edit-theme-plugin-file', function() {
// Returns a failure for all edit attempts
die( '-1' );
}, 0 );
I'm marking this as worksforme as the above code works as expected.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
@cristianuibar Welcome to trac
How did you test it? Do you have a test example?
I think you need to use priority <= 1, because the default callback for the
wp_ajax_edit-theme-plugin-fileaction has priority 1 and callswp_send_json_success()(orwp_send_json_error()), that implicitly callsdie().