So, some users have experienced an error while uploading an image: "An error occurred in the upload. Please try again later."
For weeks, we were confused because it was not easily replicable and thought it could be caching rules (which are disabled on this page now) or issues with credentials/permissions. Couldn't nail it to any one of those through rigorous testing.
Here's a server error we encountered in the process of investigating --
2022/01/04 17:18:44 [error] 27235#27235: *1596434 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught InvalidArgumentException: The parent must be a post ID or a WP_Post instance. in /www/electriccycleridercom_223/public/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/public_api/m2m.php:542
Stack trace:
#0 /www/electriccycleridercom_223/public/wp-content/themes/ecr/functions.php(443): toolset_connect_posts('dealer-listing', NULL, 8209)
#1 /www/electriccycleridercom_223/public/wp-includes/class-wp-hook.php(303): connect_listing_to_dealer(8209, Array)
#2 /www/electriccycleridercom_223/public/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#3 /www/electriccycleridercom_223/public/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#4 /www/electriccycleridercom_223/public/wp-content/plugins/cred-frontend-editor/application/models/form/base.php(720): do_action('cred_submit_com...', 8209, Array)
#5 /www/electriccycleridercom_223/public/wp-content/plugins/cred-frontend-editor/application/models/form/base.php(472)" while reading response header from upstream, client: 174.118.194.118, server: electriccyclerider.com, request: "POST /add-a-listing/?_tt=1641316610 HTTP/1.1", upstream: "<em><u>hidden link</u></em>:", host: "electriccyclerider.com:47086", referrer: "<em><u>hidden link</u></em>"
The stack trace led to line 443 on our functions.php file, which is the "toolset_connect_posts" line below. The whole function is:
/**
* Connect Listings to Dealer (Relationship) after listing post is submitted
*/
add_action('cred_submit_complete', 'connect_listing_to_dealer',10,2);
function connect_listing_to_dealer($post_id, $form_data) {
if (in_array($form_data['id'],array(1060,1303,3340,6718))) { // Add a Listing/affiliate Forms
$author_id = get_post_field( 'post_author', $post_id );
$dealerPost = get_author_dealer_post($author_id);
toolset_connect_posts( 'dealer-listing', $dealerPost->ID, $post_id );
}
}
Is this function (toolset_connect_posts) now deprecated? Or, is the "$dealerPost->ID" not setup correctly due to the "NULL" seen in the error log? We're establishing a relationship in this function due to some other custom work we've created in the site. I've included credentials if you'd like to poke around.