- action
- filter
Created
February 18, 2021 06:34
-
-
Save qichunren/0e9516430ef6b11fd81172ec8f0186e7 to your computer and use it in GitHub Desktop.
wordpress notes
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
function print_initials( $name ) { | |
if ( ! is_string( $name ) ) { | |
return; | |
} | |
$fragments = explode( ' ', $name ); | |
/** | |
* Filter wether to print initials in reverse order. | |
* | |
* @param bool $reverse Print initials in reverse order? | |
*/ | |
if ( apply_filters( 'reverse_initials', FALSE ) ) { | |
$fragments = array_reverse( $fragments ); | |
} | |
foreach ( $fragments as $f ) { | |
echo substr( $f, 0, 1 ); | |
} | |
} | |
print_initials( 'Some Guy' ); // outputs: SG | |
add_filter( 'reverse_initials', '__return_true' ); | |
print_initials( 'Some Guy' ); // outputs: GS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment