Last active
September 14, 2020 09:22
-
-
Save gregrickaby/8a71cc2303e63d1c4cc7f5880b4a937e to your computer and use it in GitHub Desktop.
Output Buffer Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Create the hero markup based on arguments. | |
| * | |
| * @param array $args The hero arguments | |
| * @return string The hero markup | |
| * @author Greg Rickaby | |
| */ | |
| function wds_client_get_hero( $args = array() ) { | |
| // Set hero defaults. | |
| $defaults = array( | |
| 'background_id' => '', | |
| 'title_id' => '', | |
| 'paragraph_text' => '', | |
| ); | |
| // Parse args. | |
| $args = wp_parse_args( $args, $defaults ); | |
| // Start hero markup. | |
| ob_start(); ?> | |
| <div class="savor-area image-as-background" style="background-image: url( <?php echo wp_get_attachment_url( $args['background_id'] ); ?> );" role="dialog" aria-labelledby="hero-title" aria-describedby="hero-description"> | |
| <div class="savor-content-area"> | |
| <div class="savor-title-area"> | |
| <img class="savor-title" src="<?php echo wp_get_attachment_url( $args['title_id'] ); ?>" alt="<?php esc_html_e( 'Weekly Savor', 'centralmarket' ); ?>"> | |
| </div> | |
| <p class="savor-paragraph"><?php echo wp_kses_post( $args['paragraph_text'] ); ?></p> | |
| <a class="button savor-button" href="#" title="<?php esc_attr_e( 'Select Your Store', 'centralmarket' ); ?>"><?php esc_html_e( 'Select Your Store', 'centralmarket' ); ?></a> | |
| </div><!-- .savor-content --> | |
| </div><!-- .savor-area --> | |
| <?php | |
| // Return hero markup. | |
| return ob_get_clean(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * INCORRECT! | |
| */ | |
| function wds_client_get_hero( $args = array() ) { | |
| // Set hero defaults. | |
| $defaults = array( | |
| 'background_id' => '', | |
| 'title_id' => '', | |
| 'paragraph_text' => '', | |
| ); | |
| // Parse args. | |
| $args = wp_parse_args( $args, $defaults ); | |
| // Start hero markup. | |
| $output = ''; | |
| $output .= '<div class="savor-area image-as-background" style="background-image: url(' . wp_get_attachment_url( $args['background_id'] ) . ');" role="dialog" aria-labelledby="hero-title" aria-describedby="hero-description">'; | |
| $output .= '<div class="savor-content-area">'; | |
| $output .= '<div class="savor-title-area">'; | |
| $output .= '<img class="savor-title" src="' . wp_get_attachment_url( $args['title_id'] ) . '" alt="' . esc_html__( 'Weekly Savor', 'centralmarket' ) . '">'; | |
| $output .= '</div>'; | |
| $output .= '<p class="savor-paragraph">' . wp_kses_post( $args['paragraph_text'] ) . '</p>'; | |
| $output .= '<a class="button savor-button" href="#" title="' . esc_attr__( 'Select Your Store', 'centralmarket' ) . '">' . esc_html__( 'Select Your Store', 'centralmarket' ) . '</a>'; | |
| $output .= '</div><!-- .savor-content -->'; | |
| $output .= '</div><!-- .savor-area -->'; | |
| // Return hero markup. | |
| return $output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment