Skip to content

Instantly share code, notes, and snippets.

@dana-ross
Created January 3, 2016 15:00
Show Gist options
  • Save dana-ross/01ec15a2ec066080561e to your computer and use it in GitHub Desktop.
Save dana-ross/01ec15a2ec066080561e to your computer and use it in GitHub Desktop.
Demonstrates a pure function and a wrapper to deal with impurities
/**
* 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