[ Index ] |
PHP Cross Reference of BBPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Topic Replies List Table class. 5 * 6 * @package bbPress 7 * @subpackage Administration 8 * @since 2.6.0 9 * @access private 10 * 11 * @see WP_Posts_List_Table 12 */ 13 14 // Include the main list table class if it's not included yet 15 if ( ! class_exists( 'WP_List_Table' ) ) { 16 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; 17 } 18 19 if ( class_exists( 'WP_List_Table' ) ) : 20 /** 21 * Topic replies list table 22 * 23 * This list table is responsible for showing the replies to a topic in a 24 * meta-box, similar to comments in posts and pages. 25 * 26 * @since 2.6.0 bbPress (r5886) 27 */ 28 class BBP_Topic_Replies_List_Table extends WP_List_Table { 29 30 /** 31 * The main constructor method 32 * 33 * @since 2.6.0 bbPress (r5886) 34 */ 35 public function __construct( $args = array() ) { 36 37 // Parse arguments 38 $args = bbp_parse_args( $args, array( 39 'singular' => 'reply', 40 'plural' => 'replies', 41 'ajax' => false 42 ), 'topic_replies_list_table' ); 43 44 // Construct the list table 45 parent::__construct( $args ); } 46 47 /** 48 * Setup the list-table columns 49 * 50 * @since 2.6.0 bbPress (r5886) 51 * 52 * @see WP_List_Table::::single_row_columns() 53 * 54 * @return array An associative array containing column information 55 */ 56 public function get_columns() { 57 return array( 58 //'cb' => '<input type="checkbox" />', 59 'bbp_topic_reply_author' => esc_html__( 'Author', 'bbpress' ), 60 'bbp_reply_content' => esc_html__( 'Content', 'bbpress' ), 61 'bbp_reply_created' => esc_html__( 'Replied', 'bbpress' ), 62 ); 63 } 64 65 /** 66 * Allow `bbp_reply_created` to be sortable 67 * 68 * @since 2.6.0 bbPress (r5886) 69 * 70 * @return array An associative array containing the `bbp_reply_created` column 71 */ 72 public function get_sortable_columns() { 73 return array( 74 'bbp_reply_created' => array( 'bbp_reply_created', false ) 75 ); 76 } 77 78 /** 79 * Setup the bulk actions 80 * 81 * @since 2.6.0 bbPress (r5886) 82 * 83 * @return array An associative array containing all the bulk actions 84 */ 85 public function get_bulk_actions() { 86 return array(); 87 88 // @todo cap checks 89 return array( 90 'unapprove' => esc_html__( 'Unapprove', 'bbpress' ), 91 'spam' => esc_html__( 'Spam', 'bbpress' ), 92 'trash' => esc_html__( 'Trash', 'bbpress' ) 93 ); 94 } 95 96 /** 97 * Output the check-box column for bulk actions (if we implement them) 98 * 99 * @since 2.6.0 bbPress (r5886) 100 */ 101 public function column_cb( $item = '' ) { 102 return sprintf( 103 '<input type="checkbox" name="%1$s[]" value="%2$s" />', 104 $this->_args['singular'], 105 $item->ID 106 ); 107 } 108 109 /** 110 * Output the contents of the `bbp_topic_reply_author` column 111 * 112 * @since 2.6.0 bbPress (r5886) 113 */ 114 public function column_bbp_topic_reply_author( $item = '' ) { 115 bbp_reply_author_avatar( $item->ID, 50 ); 116 bbp_reply_author_display_name( $item->ID ); 117 echo '<br>'; 118 bbp_reply_author_email( $item->ID ); 119 echo '<br>'; 120 bbp_author_ip( array( 'post_id' => $item->ID ) ); 121 } 122 123 /** 124 * Output the contents of the `bbp_reply_created` column 125 * 126 * @since 2.6.0 bbPress (r5886) 127 */ 128 public function column_bbp_reply_created( $item = '' ) { 129 return sprintf( '%1$s <br /> %2$s', 130 esc_attr( get_the_date( '', $item ) ), 131 esc_attr( get_the_time( '', $item ) ) 132 ); 133 } 134 135 /** 136 * Output the contents of the `bbp_reply_content` column 137 * 138 * @since 2.6.0 bbPress (r5886) 139 */ 140 public function column_bbp_reply_content( $item = '' ) { 141 142 // Define actions array 143 $actions = array( 144 'view' => '<a href="' . bbp_get_reply_url( $item->ID ) . '">' . esc_html__( 'View', 'bbpress' ) . '</a>' 145 ); 146 147 // Prepend `edit` link 148 if ( current_user_can( 'edit_reply', $item->ID ) ) { 149 $actions['edit'] = '<a href="' . get_edit_post_link( $item->ID ) . '">' . esc_html__( 'Edit', 'bbpress' ) . '</a>'; 150 $actions = array_reverse( $actions ); 151 } 152 153 // Filter the reply content 154 $reply_content = apply_filters( 'bbp_get_reply_content', $item->post_content, $item->ID ); 155 $reply_actions = $this->row_actions( $actions ); 156 157 // Return content & actions 158 return $reply_content . $reply_actions; 159 } 160 161 /** 162 * Handle bulk action requests 163 * 164 * @since 2.6.0 bbPress (r5886) 165 */ 166 public function process_bulk_action() { 167 switch ( $this->current_action() ) { 168 case 'trash' : 169 break; 170 case 'unapprove' : 171 break; 172 case 'spam' : 173 break; 174 } 175 } 176 177 /** 178 * Prepare the list-table items for display 179 * 180 * @since 2.6.0 bbPress (r5886) 181 */ 182 public function prepare_items( $topic_id = 0 ) { 183 184 // Sanitize the topic ID 185 $topic_id = bbp_get_topic_id( $topic_id ); 186 187 // Set column headers 188 $this->_column_headers = array( 189 $this->get_columns(), 190 array(), 191 $this->get_sortable_columns() 192 ); 193 194 // Handle bulk actions 195 $this->process_bulk_action(); 196 197 // Query parameters 198 $per_page = 5; 199 $current_page = $this->get_pagenum(); 200 $orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_key( $_REQUEST['orderby'] ) : 'date'; 201 $order = ! empty( $_REQUEST['order'] ) ? sanitize_key( $_REQUEST['order'] ) : 'asc'; 202 $statuses = bbp_get_public_reply_statuses(); 203 204 // Maybe add private statuses to query 205 if ( current_user_can( 'edit_others_replies' ) ) { 206 207 // Default view=all statuses 208 $statuses = array_keys( bbp_get_topic_statuses() ); 209 210 // Add support for private status 211 if ( current_user_can( 'read_private_replies' ) ) { 212 $statuses[] = bbp_get_private_status_id(); 213 } 214 } 215 216 // Query for replies 217 $reply_query = new WP_Query( array( 218 'post_type' => bbp_get_reply_post_type(), 219 'post_status' => $statuses, 220 'post_parent' => $topic_id, 221 'posts_per_page' => $per_page, 222 'paged' => $current_page, 223 'orderby' => $orderby, 224 'order' => ucwords( $order ), 225 'hierarchical' => false, 226 'ignore_sticky_posts' => true 227 ) ); 228 229 // Get the total number of replies, for pagination 230 $total_items = bbp_get_topic_reply_count( $topic_id ); 231 232 // Set list table items to queried posts 233 $this->items = $reply_query->posts; 234 235 // Set the pagination arguments 236 $this->set_pagination_args( array( 237 'total_items' => $total_items, 238 'per_page' => $per_page, 239 'total_pages' => ceil( $total_items / $per_page ) 240 ) ); 241 } 242 243 /** 244 * Message to be displayed when there are no items 245 * 246 * @since 2.6.0 bbPress (r5930) 247 */ 248 public function no_items() { 249 esc_html_e( 'No replies to this topic.', 'bbpress' ); 250 } 251 252 /** 253 * Display the list table 254 * 255 * This custom method is necessary because the one in `WP_List_Table` comes 256 * with a nonce and check that we do not need. 257 * 258 * @since 2.6.0 bbPress (r5930) 259 */ 260 public function display() { 261 262 // Top 263 $this->display_tablenav( 'top' ); ?> 264 265 <table id="bbp-reply-list" class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>"> 266 <thead> 267 <tr> 268 <?php $this->print_column_headers(); ?> 269 </tr> 270 </thead> 271 272 <tbody data-wp-lists='list:<?php echo $this->_args['singular']; ?>'> 273 <?php $this->display_rows_or_placeholder(); ?> 274 </tbody> 275 276 <tfoot> 277 <tr> 278 <?php $this->print_column_headers( false ); ?> 279 </tr> 280 </tfoot> 281 </table> 282 283 <?php 284 285 // Bottom 286 $this->display_tablenav( 'bottom' ); 287 } 288 289 /** 290 * Generate the table navigation above or below the table 291 * 292 * This custom method is necessary because the one in `WP_List_Table` comes 293 * with a nonce and check that we do not need. 294 * 295 * @since 2.6.0 bbPress (r5930) 296 * 297 * @param string $which 298 */ 299 protected function display_tablenav( $which = '' ) { 300 ?> 301 302 <div class="tablenav <?php echo esc_attr( $which ); ?>"> 303 <?php 304 $this->extra_tablenav( $which ); 305 $this->pagination( $which ); 306 ?> 307 <br class="clear" /> 308 </div> 309 310 <?php 311 } 312 313 /** 314 * Generates content for a single row of the table 315 * 316 * @since 2.6.0 317 * @access public 318 * 319 * @param object $item The current item 320 */ 321 public function single_row( $item ) { 322 323 // Author 324 $classes = 'author-' . ( get_current_user_id() == $item->post_author ? 'self' : 'other' ); 325 326 // Locked 327 if ( wp_check_post_lock( $item->ID ) ) { 328 $classes .= ' wp-locked'; 329 } 330 331 // Hierarchy 332 if ( ! empty( $item->post_parent ) ) { 333 $count = count( get_post_ancestors( $item->ID ) ); 334 $classes .= ' level-'. $count; 335 } else { 336 $classes .= ' level-0'; 337 } ?> 338 339 <tr id="post-<?php echo esc_attr( $item->ID ); ?>" class="<?php echo implode( ' ', get_post_class( $classes, $item->ID ) ); ?>"> 340 <?php $this->single_row_columns( $item ); ?> 341 </tr> 342 343 <?php 344 } 345 } 346 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Dec 30 01:00:53 2024 | Cross-referenced by PHPXref 0.7.1 |