I am trying to execute a function only if its called from a particular parent (or grandparent function, or great-grandparent, etc). I can achieve what I want to do using debug_backtrace, but I feel like this is not the correct way to do this. Take this for example:
function savethepost($post_id) {
$parent = debug_backtrace();
if ($parent[5]['function'] == 'bulk_edit_posts') {
if ( isset( $_REQUEST['post_format'] ) && $_REQUEST['post_format'] != -1 ) {
set_post_format($post_id, $_REQUEST['post_format']);
}
}
}
This is using backtrace in Wordpress function to execute the set_post_format function only if the savethepost function is called from the bulk_edit_posts function, which is what I trying to achieve. But since this method is meant for debugging, is okay to use it this way? If not, how else could I achieve calling a function if only coming from a certain parent function?