bhalash

Parse 'yes' to bool

Oct 7th, 2014
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. function parse_columnist_role($author_id) {
  2.     /* See author_is_columnist, below.
  3.  
  4.     This function takes the string 'yes' or no' and parses it.
  5.     I probably go overboard in sanitization, but I've seen the dedication
  6.     of our local users.
  7.  
  8.     parse_columnist_role returns true if the string parses to 'yes' */
  9.     $meta_tag = get_the_author_meta('columnist', $author_id);
  10.     $is_columnist = false;
  11.  
  12.     if (!empty($meta_tag)) {
  13.         $meta_tag = strtolower($meta_tag);
  14.         $meta_tag = strip_tags($meta_tag);
  15.  
  16.         if (strpos('yes', $meta_tag) != -1) {
  17.             $meta_tag = preg_replace('/([^yes].*$)/', '', $meta_tag);
  18.         } else {
  19.             $meta_tag = preg_replace('/([^no].*$)/', '', $meta_tag);
  20.         }
  21.  
  22.         if ($meta_tag === 'yes') {
  23.             $is_columnist = true;
  24.         }
  25.     }
  26.  
  27.     return $is_columnist;
  28. }
  29.  
  30. function author_is_columnist() {
  31.     /* We've (currently unused) added a flag to each user in order to indicate
  32.     that they have a serial column.
  33.  
  34.     parse_columnist_role parses the variable string.
  35.     author_is_columnist returns true or false. */
  36.     $id = get_the_author_meta('ID');
  37.     return parse_columnist_role($id);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment