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

Adds filter to get the credits link as string #25

Closed
wants to merge 8 commits into from
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ for more graceful degradation to implement via actions.
<?php do_action( 'team51_credits', array() ); ?>
```

If we need just the final credits link returned as string we can also use

```php
<?php apply_filters( 'team51_credits_filter', '', array() ); ?>
```

Parameters can be passed in --

* `separator` -- defaults to a single space.
Expand Down Expand Up @@ -146,3 +152,4 @@ Then we create a pull request as needed and integrate it as above.
### Updates

* v1.2.0 Add a new shortcode for showing the copyright year.
* v1.3.0 Adds a new filter that returns the credits link string instead of echoing it.
24 changes: 21 additions & 3 deletions colophon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
Plugin Name: Colophon
Plugin URI: https://github.com/a8cteam51/colophon
Description: Sets Team 51 footer links to WordPress.com and Pressable.
Version: 1.2.0
Version: 1.3.0
Author: WordPress.com Special Projects
Author URI: https://wpspecialprojects.wordpress.com/
License: GPLv3
*/

if ( ! function_exists( 'team51_credits' ) ) :


/**
* A colophon-generating method for WordPress Special Projects Sites.
* A wrapper to the colophon generating method for WordPress Special Projects Sites.
* Echoes a the resulting credit links
*
* Usage: team51_credits( 'separator= | ' );
*
Expand All @@ -21,6 +23,20 @@
* @return void
*/
function team51_credits( $args = array() ) {
echo apply_filters( 'team51_credits_filter', '', $args ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
* A colophon-generating method for WordPress Special Projects Sites.
*
* Usage: team51_credits( 'separator= | ' );
*
* @param string $str The string that will be used for the filter. Will be overriden
* @param array{separator?: string, wpcom?: string, pressable?: string} $args The Args passed to the function.
*
* @return string the resulting credits link
*/
function team51_credits_filter( $str = '', $args = array() ) {
$args = wp_parse_args(
$args,
array(
Expand Down Expand Up @@ -88,12 +104,14 @@ function team51_credits( $args = array() ) {
*/
$credit_links = apply_filters( 'team51_credit_links', $credit_links, $args );

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

add_action( 'team51_credits', 'team51_credits', 10, 1 );
add_filter( 'team51_credits_filter', 'team51_credits_filter', 10, 2 );
endif;

if ( ! function_exists( 'team51_credits_shortcode' ) ) :
Expand Down
Loading