semantic_comments

Semantic_comments() - Generates semantic classes for each comment

  • element.

  • Description

    semantic_comments( (array) $classes = array() ); 

    Parameters (1)

    0. $classes — Optional. (array) => array()
    The classes.

    Usage

    1. if ( !function_exists( 'semantic_comments' ) ) { 
    2. require_once '/library/extensions/semantic-classes.php'; 
    3.  
    4. // The classes. 
    5. $classes = array(); 
    6.  
    7. // NOTICE! Understand what this does before running. 
    8. $result = semantic_comments($classes); 
    9.  

    Defined (1)

    The function is defined in the following location(s).

    /library/extensions/semantic-classes.php  
    1. function semantic_comments($classes = array()) { 
    2. global $comment, $post, $wpdb, $current_user, $comment_first_class, $semantic_comment_alt; 
    3.  
    4. // Collects the comment type (comment, trackback) 
    5. $classes[] = get_comment_type(); 
    6. if (isset($classes[0]) && $classes[0] != 'comment') { 
    7. $classes[] = 'comment'; 
    8.  
    9. // add css class to first comment 
    10. if ($comment_first_class == 0) 
    11. $classes[] = 'first-comment'; 
    12. $comment_first_class = 1; 
    13.  
    14. // add css class to last comment 
    15. if ($comment->comment_ID == semantic_last_class('comment') and ! $comment_first_class) 
    16. $classes[] = 'last-comment'; 
    17.  
    18. // Show commenter's capabilities 
    19. if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) { 
    20. $capabilities = $user->{$wpdb->prefix . 'capabilities'}; // hat tip to Justin Tadlock http://www.themehybrid.com 
    21.  
    22. if (array_key_exists('administrator', $capabilities)) 
    23. $classes[] = 'administrator administrator-' . $user->user_login; 
    24. elseif (array_key_exists('editor', $capabilities)) 
    25. $classes[] = 'editor editor-' . $user->user_login; 
    26. elseif (array_key_exists('author', $capabilities)) 
    27. $classes[] = 'author author-' . $user->user_login; 
    28. elseif (array_key_exists('contributor', $capabilities)) 
    29. $classes[] = 'contributor contributor-' . $user->user_login; 
    30. elseif (array_key_exists('subscriber', $capabilities)) 
    31. $classes[] = 'subscriber subscriber-' . $user->user_login; 
    32. } else 
    33. $classes[] = 'reader reader-' . str_replace(' ', '-', strtolower($comment->comment_author)); 
    34.  
    35. // http://microid.org 
    36. $email = get_comment_author_email(); 
    37. $uri = get_comment_author_url(); 
    38. if (!empty($email) && !empty($uri)) { 
    39. if (preg_match('/https:\/\//i', $uri)) 
    40. $protocal = 'https'; 
    41. elseif (preg_match('/http:\/\//i', $uri)) 
    42. $protocal = 'http'; 
    43. $microid = "microid-mailto+{$protocal}:sha1:" . sha1(sha1('mailto:' . $email) . sha1($uri)); 
    44. $classes[] = $microid; 
    45.  
    46. // If it's the other to the every, then add 'alt' class; collects time- and date-based classes 
    47.  
    48.  
    49. $classes = join(' ', apply_filters('semantic_comments', $classes)); // Available filter: semantic_comments 
    50. $print = apply_filters('semantic_comments_print', false); // Available filter: semantic_comments_print 
    51. // And tada! 
    52. if (!$print) 
    53. echo $classes; 
    54. else 
    55. return $classes;