Fatal error when gathering meta on post deletion
-
Hi there
I am facing a fatal error while performing some logic in a plugin of mine. The test scenario is quite simple.
- Include a callback to the
before_delete_post
action, that will be feeded with the post ID. - Inside the callback, gather the post meta with whatever key, and expect it to return the right data according to core documentation.
- Create a donation with the plugin and then delete it.
add_action( 'before_delete_post', 'before_delete_post_callback' ); function before_delete_post_callback( $post_id ) { $meta = get_post_meta( $post_id, 'foobar' ); if ( count( $meta ) > 0 ) { ... } }
According to the documentation on
get_pòst_meta
, it should return an array as long as the post ID matches an existing post and the third, optional parameter, is not passed astrue
. However, when the hook is fired while deleting a donation, the function is returning another thing, but not an array.Checking the plugin, it seems that
Give_DB_Meta::get_meta
might be returning a string regardless the value of the$single
parameter when the flag forraw_result
istrue
.I am not sure if it is a good idea to modify the expected output of a core function, even if you restrict it to just using it on your own object types.
Hope that you can find a solution to this problem.
Regards.
- Include a callback to the
- The topic ‘Fatal error when gathering meta on post deletion’ is closed to new replies.