Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to get the colophon back as a string, rather than echoing. #26

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions colophon.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*
* Usage: team51_credits( 'separator= | ' );
*
* @param array{separator?: string, wpcom?: string, pressable?: string} $args The Args passed to the function.
* @param array{separator?: string, wpcom?: string, pressable?: string, return?: boolean} $args The Args passed to the function.
*
* @return void
* @return void|string
*/
function team51_credits( $args = array() ) {
$args = wp_parse_args(
Expand All @@ -29,9 +29,15 @@ function team51_credits( $args = array() ) {
'wpcom' => sprintf( __( 'Proudly powered by %s.', 'team51' ), 'WordPress' ),
/* translators: %s: Pressable. */
'pressable' => sprintf( __( 'Hosted by %s.', 'team51' ), 'Pressable' ),
'return' => false,
)
);

// Protect against folks mistakenly passing 'return' in which would prevent anything from echoing on the action.
if ( doing_action( 'team51_credits' ) ) {
$args['return'] = false;
}

$credit_links = array();
$parsed_url = wp_parse_url( get_site_url(), PHP_URL_HOST );
$partner_domain = $parsed_url ? $parsed_url : 'wpspecialprojects.com';
Expand Down Expand Up @@ -88,10 +94,18 @@ function team51_credits( $args = array() ) {
*/
$credit_links = apply_filters( 'team51_credit_links', $credit_links, $args );

echo implode(
$output = implode(
esc_html( $args['separator'] ),
$credit_links //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, this cant be escaped as it runs through a filter
);

// If we'd rather it be returned, rather than echoed ...
if ( $args['return'] ) {
return wp_kses_post( $output );
}

// Otherwise...
echo esc_attr( $output );
}
add_action( 'team51_credits', 'team51_credits', 10, 1 );
endif;
Expand All @@ -118,9 +132,9 @@ function team51_credits_shortcode( $atts ) {

$atts = shortcode_atts( $pairs, $atts, 'team51-credits' );

ob_start();
team51_credits( $atts );
return ob_get_clean();
$atts['return'] = true;

return team51_credits( $atts );
}
add_action(
'init',
Expand Down
Loading