I have a list of functions that perform a fairly deep procedure to determine which post_id to get its content and display it on the site interface.
When this function returns its contents, I want it to be wrapped in an html wrapper. I want this html shell to load only when the function returns the result.
In the example, I have the following ...
public static function output_*() {
In full explanation, I have the following ...
If one of these functions returns output , I want it to be wrapped in an html wrapper, so in theory I'm trying to do something like this ...
public static function begin_header_wrapper() { // This only returns true if an output function below returns content, // which for me is other than an empty return; include(self::$begin_header_wrapper); } public static function output_above_header() { // my routines that check for content to output precede here // if there is content to return it will end in the following statement // otherwise it will end in return; include($begin_markup); // This is the BEGIN html wrapper for this specifc output // It is, so let get this option post id number, extract its content, // run any needed filters and output our user selected content $selected_content = get_post($this_option); $extracted_content = kc_raw_content($selected_content); $content = kc_do_shortcode($extracted_content); echo $content; include($end_markup); // This is the END html wrapper for this specifc output } public static function output_header() { // the same routine as above but for the header output } public static function output_below_header() { // the same routine as above but for the below header output } public static function end_header_wrapper() { // This only returns true if an output function above returns content, // which for me is other than an empty return; include(self::$end_header_wrapper); }
I know right now, ahead of time I donβt want to determine twice (once at the beginning and once at the end) if one of the output functions has an output, when there should be a way to do this with one check, but I would like to start working on this rabbit hole and figure out the best way to determine if my function returns something or not.
Or, if there is a completely better way to approach this, go through everything, lol and let me know.
I watched this article online and others @ Find out if there is a function with php output
So in the end, I just wanted to find out if there is a better way to approach this and what is actually the BEST way you think to check if my functions have output to return, so I can run my html shell based on these conditions?
Would it be better ob_get_length ? When I looked at the ob targets, this one seemed the best and most simplified, but I wanted to get advice, feedback. Or maybe I can check if my $content variable is being returned? Thank you I really appreciate it!