Last active
April 29, 2020 16:59
-
-
Save vfontjr/09deeaf709902523fc431f5cd45328fc to your computer and use it in GitHub Desktop.
Source code for Understanding Genesis Dynamic apply_filters()—Part 1
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 | |
add_filter( 'genesis_structural_wrap-header', 'add_additional_container_to_structural_wrap', 10, 2); | |
function add_additional_container_to_structural_wrap( $output, $original_output ) { | |
if ( 'open' == $original_output ) | |
$output .= '<div class="wrap-inner">'; | |
elseif ( 'close' == $original_output ) | |
$output .= '</div>'; | |
return $output; | |
} |
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 | |
//* Add support for structural wraps | |
add_theme_support( 'genesis-structural-wraps', array( | |
'header', | |
'site-tagline', | |
'nav', | |
'subnav', | |
'home-featured', | |
'site-inner', | |
'footer-widgets', | |
'footer' | |
) ); |
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 | |
//* Add support for structural wraps | |
add_theme_support( 'genesis-structural-wraps', array( | |
'header', | |
'menu-primary', | |
'menu-secondary', | |
'site-inner', | |
'footer-widgets', | |
'footer' | |
) ); |
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 | |
//* Add the site tagline section | |
add_action( 'genesis_after_header', 'minimum_site_tagline' ); | |
function minimum_site_tagline() { | |
printf( '<div %s>', genesis_attr( 'site-tagline' ) ); | |
genesis_structural_wrap( 'site-tagline' ); | |
printf( '<div %s>', genesis_attr( 'site-tagline-left' ) ); | |
printf( '<p %s>%s</p>', genesis_attr( 'site-description' ), esc_html( get_bloginfo( 'description' ) ) ); | |
echo '</div>'; | |
printf( '<div %s>', genesis_attr( 'site-tagline-right' ) ); | |
genesis_widget_area( 'site-tagline-right' ); | |
echo '</div>'; | |
genesis_structural_wrap( 'site-tagline', 'close' ); | |
echo '</div>'; | |
} |
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 | |
add_filter( 'genesis_structural_wrap-header', 'change_structural_wrap_to_span', 10, 2); | |
function change_structural_wrap_to_span( $output, $original_output ) { | |
if ( 'open' == $original_output ) | |
$output = '<span class="wrap">'; | |
elseif ( 'close' == $original_output ) | |
$output = '</span>'; | |
return $output; | |
} |
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 | |
function genesis_header_markup_open() { | |
genesis_markup( array( | |
'open' => '<header %s>', | |
'context' => 'site-header', | |
) ); | |
genesis_structural_wrap( 'header' ); | |
} | |
function genesis_header_markup_close() { | |
genesis_structural_wrap( 'header', 'close' ); | |
genesis_markup( array( | |
'close' => '</header>', | |
'context' => 'site-header', | |
) ); | |
} |
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
<header class="site-header" itemscope="" itemtype="http://schema.org/WPHeader"> | |
<div class="wrap"> | |
<div class="title-area"> | |
<h1 class="site-title" itemprop="headline"><a href="http://localhost/public_html/">Sandbox</a></h1> | |
<h2 class="site-description" itemprop="description">Just another WordPress site</h2> | |
</div> | |
</div> | |
</header> |
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 | |
function genesis_structural_wrap( $context = '', $output = 'open', $echo = true ) { | |
d('------- passed params -------'); | |
d($context); | |
d($output); | |
d($echo); | |
$wraps = get_theme_support( 'genesis-structural-wraps' ); | |
d('------- theme supported wraps -------'); | |
d($wraps); | |
// If theme doesn't support structural wraps, bail. | |
if ( ! $wraps ) | |
return; | |
// Map of old $contexts to new $contexts. | |
$map = array( | |
'nav' => 'menu-primary', | |
'subnav' => 'menu-secondary', | |
'inner' => 'site-inner', | |
); | |
// Make the swap, if necessary. | |
if ( $swap = array_search( $context, $map ) ) { | |
if ( in_array( $swap, $wraps[0] ) ) | |
$wraps[0] = str_replace( $swap, $map[ $swap ], $wraps[0] ); | |
} | |
if ( ! in_array( $context, (array) $wraps[0] ) ) | |
return ''; | |
// Save original output param. | |
$original_output = $output; | |
switch ( $output ) { | |
case 'open': | |
$output = sprintf( '<div %s>', genesis_attr( 'structural-wrap' ) ); | |
break; | |
case 'close': | |
$output = '</div>'; | |
break; | |
} | |
$output = apply_filters( "genesis_structural_wrap-{$context}", $output, $original_output ); | |
d('------- output -------'); | |
d($output); | |
if ( $echo ) | |
echo $output; | |
else | |
return $output; | |
} |
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 | |
function genesis_structural_wrap( $context = '', $output = 'open', $echo = true ) { | |
$wraps = get_theme_support( 'genesis-structural-wraps' ); | |
// If theme doesn't support structural wraps, bail. | |
if ( ! $wraps ) | |
return; | |
// Map of old $contexts to new $contexts. | |
$map = array( | |
'nav' => 'menu-primary', | |
'subnav' => 'menu-secondary', | |
'inner' => 'site-inner', | |
); | |
// Make the swap, if necessary. | |
if ( $swap = array_search( $context, $map ) ) { | |
if ( in_array( $swap, $wraps[0] ) ) | |
$wraps[0] = str_replace( $swap, $map[ $swap ], $wraps[0] ); | |
} | |
if ( ! in_array( $context, (array) $wraps[0] ) ) | |
return ''; | |
// Save original output param. | |
$original_output = $output; | |
switch ( $output ) { | |
case 'open': | |
$output = sprintf( '<div %s>', genesis_attr( 'structural-wrap' ) ); | |
break; | |
case 'close': | |
$output = '</div>'; | |
break; | |
} | |
$output = apply_filters( "genesis_structural_wrap-{$context}", $output, $original_output ); | |
if ( $echo ) | |
echo $output; | |
else | |
return $output; | |
} |
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 | |
//* Add support for structural wraps | |
add_theme_support( 'genesis-structural-wraps', array( | |
'header', | |
'menu-primary', | |
'menu-secondary', | |
'footer-widgets' | |
) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment