I've coded a plugin that creates a shortcode, among other things. That shortcode expects a post_id parameter, it extracts the content of that post and it returns the filtered content of that post (e.g. it applies all filters so that any other shortcode in that content is done). Here is a cut down version of the code:
public static function myshortcode($atts = null, $content = "")
{
global $wp_filter, $merged_filters, $wp_current_filter, $post;
if (is_array($atts))
extract($atts, EXTR_OVERWRITE);
$save_wp_filter = $wp_filter;
$save_merged_filters = $merged_filters;
$save_wp_current_filter = $wp_current_filter;
$post = get_post($post_id);
setup_postdata($post);
$content = $post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$wp_filter = $save_wp_filter;
$merged_filters = $save_merged_filters;
$wp_current_filter = $save_wp_current_filter;
return $content;
}
All works great, except that other plugins shortcodes fail to include their own CSS files (e.g. Ultimate Addons for Visual Composer has its own CSS files to include, but it does not include them when called this way). I suspect the problem is that when WP executes the "the_content" hook for my shortcode (not the one I call explicitly, but the hook that WP itself calls in the first place and that leads to my shortcode execution) it is already too late to include CSS files in the page (e.g. the <head> tag is already closed), and Wordpress, at that point, has given a chance to include CSS files only to the plugins it sees as needed for the page (e.g. only my plugin, because the page initially contains only my shortcode).
I could use wp_enqueue_style to explicitly add the required third party CSS files, but the problem is I want to include them in a portable way. Today the problem is Ultimate Addons for VC, tomorrow will be Content Egg or something else. The best solution would be to call the function of WP which makes the decision about what are the required plugins for the page and calls them, handing that function the the actual content the page will have after my shortcode will be executed, instead of the content the page has before my shortcode is done.
Does such WP function exist?
EDIT:
For clarification after comments, yes, my shortcode is like [embed_page id="123"], except I need it the other way around, e.g. [embed_post id="123"] in a page. There's no risk of looping because it is meant to be used only to embed posts into pages, and it's not meant to be used in posts. And finally yes, the embedded content does include other third party shortcodes that should automatically enqueue their own CSS, JS, whatever.
EDIT AFTER THE RECEIVED ANSWERS:
The short answer is no, there doesn't exist such function in Wordpress. The long answer is below. I'd like to reward both @majick and @cjbj for their extensive and detailed answers, but I have to choose one...