You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When calling wp_delete_attachment the Elasticpress plugin will throw the following error: Trying to get property 'ID' of non-object in /app/web/app/plugins/elasticpress/includes/classes/Indexable/Post/Post.php on line 672.
Steps to Reproduce
call wp_delete_attachment with an attachment-ID and force-delete true
check logs
see error
Expected behavior
The attachment should be deleted and the necessary changes should be synced to Elasticsearch.
Additional context
When calling wp_delete_attachment the following code will be called and executed:
// Delete all for any posts.
delete_metadata( 'post', null, '_thumbnail_id', $post_id, true );
As we can see, the second argument passed into the delete_metadata function is null. This parameter references the object_id ("ID of the object metadata is for"). This is done to remove any references to the _thumbnail_id field for all existing posts. Removing the object_id (e.g. setting it to 0) however, will then cause the error above.
Workaround
To fix this issue, I have currently implemented the following filter:
add_filter('ep_skip_post_meta_sync', [$this, 'skipMetaSync'], 10, 5);
public function skipMetaSync($skip, $post, $meta_id, $meta_key, $meta_value): bool
{
if (null === $post) {
return true;
}
return $skip;
}
The text was updated successfully, but these errors were encountered:
Hey @Shrimpstronaut, first of all, thanks for opening the issue!
Instead of simply skipping if $object_id is null, it would be even better if we could honor the $delete_all variable somehow, finding the object IDs that should be updated. The delete_metadata() function does that with this piece of code:
if ( $delete_all ) {
if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) {
$object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s AND meta_value = %s", $meta_key, $meta_value ) );
} else {
$object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) );
}
}
Describe the bug
When calling
wp_delete_attachment
the Elasticpress plugin will throw the following error:Trying to get property 'ID' of non-object in /app/web/app/plugins/elasticpress/includes/classes/Indexable/Post/Post.php on line 672
.Steps to Reproduce
wp_delete_attachment
with an attachment-ID and force-deletetrue
Expected behavior
The attachment should be deleted and the necessary changes should be synced to Elasticsearch.
Logs
Full stack trace of the exception:
Additional context
When calling
wp_delete_attachment
the following code will be called and executed:As we can see, the second argument passed into the
delete_metadata
function isnull
. This parameter references theobject_id
("ID of the object metadata is for"). This is done to remove any references to the_thumbnail_id
field for all existing posts. Removing theobject_id
(e.g. setting it to 0) however, will then cause the error above.Workaround
To fix this issue, I have currently implemented the following filter:
The text was updated successfully, but these errors were encountered: