Opened 7 years ago
Closed 7 years ago
#45302 closed defect (bug) (fixed)
AJAX post but only got a 500 error - WP5.0 Beta 3
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 5.0 | Priority: | normal |
| Severity: | normal | Version: | 5.0 |
| Component: | Editor | Keywords: | has-patch commit fixed-5.0 |
| Focuses: | Cc: |
Description
My theme includes a page builder, it disables Gutenberg (use 'use_block_editor_for_post' filter) for some specified pages. It needs to connect the backend via AJAX when editing these pages, but everytime I opened the builder and only got a 500 error.
Error logs:
POST http://localhost/xampp/test/wp5.0/wp-admin/admin-ajax.php 500 (Internal Server Error)
[07-Nov-2018 01:09:58 UTC] PHP Fatal error: Uncaught Error: Call to a member function is_block_editor() on null in D:\xampp\htdocs\xampp\test\wp5.0\wp-includes\script-loader.php:2228
Stack trace:
#0 D:\xampp\htdocs\xampp\test\wp5.0\wp-includes\class-wp-hook.php(286): wp_common_block_scripts_and_styles('')
#1 D:\xampp\htdocs\xampp\test\wp5.0\wp-includes\class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
#2 D:\xampp\htdocs\xampp\test\wp5.0\wp-includes\plugin.php(453): WP_Hook->do_action(Array)
#3 D:\xampp\htdocs\xampp\test\wp5.0\wp-includes\script-loader.php(2074): do_action('wp_enqueue_scri...')
#4 D:\xampp\htdocs\xampp\test\wp5.0\wp-includes\class-wp-hook.php(286): wp_enqueue_scripts('')
#5 D:\xampp\htdocs\xampp\test\wp5.0\wp-includes\class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
How to show this problem again?
- Add these PHP code to functions.php to disable the gutenberg:
<?php if( !function_exists('pinetree_disable_gutenberg') ) { function pinetree_disable_gutenberg( $is_enabled, $post_data ) { if( $post_data->post_type === 'page' ) { return false; } return $is_enabled; } } add_filter('use_block_editor_for_post', 'pinetree_disable_gutenberg', 10, 2);
- Add this JavaScript when dom is ready or just simply enter them into console panel:
jQuery.ajax({
url: ajaxurl,
success: function(data){
console.log('success');
}
});
- Now you will see the error from the console (I used Chrome 70).
Hope this can help.
Attachments (1)
Change History (10)
#2
@
7 years ago
- Component changed from General to Editor
- Milestone changed from Awaiting Review to 5.0
#3
@
7 years ago
- Keywords has-patch commit added
- Owner set to pento
- Status changed from new to reviewing
Hello @foreverpinetree, welcome to WordPress Trac!
Thanks for your report. I noticed the same error on wordpress.org on sites with o2 enabled. 45302.patch removes the unnecessary is_admin() check and checks for a valid $current_screen variable.
#4
@
7 years ago
I've tweaked 45302.patch a little:
- Using the global
$current_screen, asget_current_screen()isn't available for front end. - Applied the same fix to
wp_common_block_scripts_and_styles().
Note: See
TracTickets for help on using
tickets.
Edit:
I just found that even I didn't disable the gutenberg, AJAX post would get the 500 error too.