Created
January 3, 2016 15:00
-
-
Save dana-ross/01ec15a2ec066080561e to your computer and use it in GitHub Desktop.
Demonstrates a pure function and a wrapper to deal with impurities
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
/** | |
* Wrapper to deal with global state and pass it to a pure function | |
* IMPURE - references global $post | |
* @return string | |
*/ | |
function capitalize_the_post_title() { | |
global $post; | |
return _capitalize_the_post_title( $post ); | |
// Or return _capitalize_the_post_title( $GLOBALS['post'] ); | |
} | |
/** | |
* Capitalize a post's title | |
* @param WP_Post $post | |
* @return string | |
*/ | |
function _capitalize_the_post_title( $post ) { | |
return strtoupper( $post->post_title ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment