Ajax 500 error on custom plugin with certain theme (Divi)

I am having trouble debugging an issue with a plugin that I created. The general functionality where the issue I am having is:

The user clicks a button
This button click triggers an Ajax request
The Ajax function creates a new post and adds some post meta data

The original code I have works most of the time apart from when using the Divi theme. When using this theme it gives my browser console a 500 error. The PHP error log shows:

PHP Fatal error: Uncaught Error: Call to undefined method stdClass::in_admin()

The error comes from my plugin’s call on the “update_post_meta” function. Higher up the stack trace it happens in:

/themes/Divi/epanel/custom_functions.php(2087): is_admin()

/wp-includes/class-wp-hook.php(286): et_uc_theme_name(‘post_id’, ‘post_id’)

As this works on all other themes that I’ve tested I’m not sure how to debug this as I don’t want to put a fix on the theme code but my plugin. The code where this happens is similar to the following:

//Create a post
$cpt_id = wp_insert_post( array(
‘post_title’=> $title,
‘post_type’=> ‘my_cpt’,
‘post_content’ => ”,
‘post_status’ => ‘publish’ )

//Save post meta to the newly created post
update_post_meta( $cpt_id, ‘my_meta_key’, $data_to_save );

//$title and $data_to_save are values passed from Ajax

What is the best way to debug the errors I’m getting when the original code that I’m using works on all other themes that I’ve tested?

When testing this I am using a fresh WordPress install with only the Divi theme and my plugin activated to ensure no other plugins are conflicting.

Thanks in advance for all suggestions.

Read more here:: Ajax 500 error on custom plugin with certain theme (Divi)

Leave a Reply

Your email address will not be published. Required fields are marked *