Guest User

Untitled

a guest
Jun 10th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. <?php
  2. class td_block_authors extends td_block {
  3.  
  4.  
  5. /**
  6. * Disable loop block features. This block does not use a loop and it dosn't need to run a query.
  7. */
  8. function __construct() {
  9. parent::disable_loop_block_features();
  10. }
  11.  
  12.  
  13.  
  14. function render($atts, $content = null) {
  15. parent::render($atts);
  16. global $wpdb;
  17.  
  18. $sort = '';
  19.  
  20. extract(shortcode_atts(
  21. array(
  22. 'roles' => '',
  23. 'sort' => '',
  24. 'exclude' => '',
  25. 'include' => ''
  26. ), $atts));
  27.  
  28.  
  29.  
  30. //print_r($atts);
  31. //die;
  32.  
  33. $get_users_array = array();
  34.  
  35. if (!empty($exclude)) {
  36. $exclude_array = explode(',', $exclude);
  37. $get_users_array['exclude'] = $exclude_array;
  38. }
  39.  
  40. if (!empty($include)) {
  41. $include_array = explode(',', $include);
  42. $get_users_array['include'] = $include_array;
  43. }
  44.  
  45.  
  46. if (empty($sort)) {
  47. $get_users_array['orderby'] = 'display_name';
  48. //$td_authors = get_users(array('orderby' => 'display_name'));
  49. } else {
  50. $get_users_array['orderby'] = 'post_count';
  51. $get_users_array['order'] = 'DESC';
  52. //$td_authors = get_users(array('orderby' => 'post_count', 'order' => 'DESC'));
  53. }
  54.  
  55. if (!empty($roles)) {
  56. $roles_in = array();
  57. $roles_buffer = explode(',', $roles);
  58. foreach ($roles_buffer as $role) {
  59. //clear the empty space
  60. $roles_in[] = trim($role);
  61. }
  62. //role__in was added in wp 4.4
  63. $get_users_array['role__in'] = $roles_in;
  64. }
  65.  
  66. $td_authors = get_users($get_users_array);
  67.  
  68.  
  69. $buffy = '';
  70. $author_count = 0;
  71. $buffy .= '<div class="' . $this->get_block_classes(array('td_top_authors')) . '" ' . $this->get_block_html_atts() . '>';
  72.  
  73. //get the block js
  74. $buffy .= $this->get_block_css();
  75.  
  76. $buffy .= $this->get_block_title();
  77.  
  78. if (!empty($td_authors)) {
  79. foreach ($td_authors as $td_author) {
  80. $author_count++;
  81. if ($author_count <= 3) {
  82. $current_author_class = '';
  83. if (!empty(td_global::$current_author_obj->ID) and td_global::$current_author_obj->ID == $td_author->ID) {
  84. $current_author_class = ' td-active';
  85. }
  86. $buffy .= '<div class="td_mod_wrap td-pb-padding-side' . $current_author_class . '">';
  87. $buffy .= '<a href="' . get_author_posts_url($td_author->ID) . '">' . get_avatar($td_author->user_email, '70') . '</a>';
  88. $buffy .= '<div class="item-details">';
  89.  
  90. $buffy .= '<div class="td-authors-name">';
  91. $buffy .= '<a href="' . get_author_posts_url($td_author->ID) . '">' . $td_author->display_name . '</a>';
  92. $buffy .= '</div>';
  93.  
  94.  
  95. $buffy .= '<span class="td-author-post-count">';
  96. $buffy .= count_user_posts($td_author->ID) . ' ' . __td('POSTS');
  97. $buffy .= '</span>';
  98.  
  99. $buffy .= '<span class="td-author-comments-count">';
  100. $comment_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) AS total FROM $wpdb->comments WHERE comment_approved = 1 AND user_id = %d", $td_author->ID));
  101. $buffy .= $comment_count . ' ' . __td('COMMENTS');
  102. $buffy .= '</span>';
  103.  
  104. $buffy .= '<div class="td-authors-url">';
  105. $buffy .= '<a href="' . $td_author->user_url . '">' . $td_author->user_url . '</a>';
  106. $buffy .= '</div>';
  107.  
  108. $buffy .= '</div>';
  109.  
  110. $buffy .= '</div>';
  111. }
  112. }
  113. }
  114.  
  115.  
  116.  
  117. $buffy .= '</div>';
  118.  
  119.  
  120. return $buffy;
  121.  
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment