BP_Avatar_Suggestions_List_Table

List table class for avatar suggestions settings page.

Defined (1)

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

/includes/bp-avatar-suggestions-list-table.php  
  1. class BP_Avatar_Suggestions_List_Table extends WP_List_Table { 
  2.  
  3. /** 
  4. * Suggestion counts. 
  5. * @since 1.2.0 
  6. * @access public 
  7. * @var int 
  8. */ 
  9. public $suggestion_counts = 0; 
  10.  
  11. /** 
  12. * Constructor. 
  13. * @since 1.2.0 
  14. */ 
  15. public function __construct() { 
  16. // Define singular and plural labels, as well as whether we support AJAX. 
  17. parent::__construct( array( 
  18. 'ajax' => false,  
  19. 'plural' => 'suggestions',  
  20. 'singular' => 'suggestion',  
  21. ) ); 
  22.  
  23. /** 
  24. * Set up items for display in the list table. 
  25. * @since 1.2.0 
  26. */ 
  27. public function prepare_items() { 
  28. $suggestions_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 
  29. $paged = $this->get_pagenum(); 
  30. $post_parent = buddypress()->extend->avatar_suggestions->avatar_post_id; 
  31.  
  32. if ( ! empty( $post_parent ) ) { 
  33. $args = array( 
  34. 'offset' => ( $paged - 1 ) * $suggestions_per_page,  
  35. 'posts_per_page' => $suggestions_per_page,  
  36. 'orderby' => 'ID',  
  37. 'order' => 'DESC',  
  38. 'post_type' => 'attachment',  
  39. 'post_parent' => $post_parent,  
  40. 'post_status' => 'inherit',  
  41. ); 
  42.  
  43. if ( ! empty( $_REQUEST['avatar_type'] ) && 1 !== (int) $_REQUEST['avatar_type'] ) { 
  44. $args['meta_key'] = '_bpas_avatar_type'; 
  45. $args['meta_value'] = (int) $_REQUEST['avatar_type']; 
  46.  
  47. if ( isset( $_REQUEST['orderby'] ) ) { 
  48. $args['orderby'] = $_REQUEST['orderby']; 
  49.  
  50. if ( isset( $_REQUEST['order'] ) ) { 
  51. $args['order'] = $_REQUEST['order']; 
  52.  
  53. $suggestions = new WP_Query( $args ); 
  54.  
  55. $this->items = $suggestions->posts; 
  56. $this->suggestion_counts = $suggestions->found_posts; 
  57. } else { 
  58. $this->items = array(); 
  59. $this->suggestion_counts = 0; 
  60.  
  61. $this->set_pagination_args( array( 
  62. 'total_items' => $this->suggestion_counts,  
  63. 'per_page' => $suggestions_per_page,  
  64. ) ); 
  65.  
  66. /** 
  67. * Get the views (the links above the WP List Table). 
  68. * @since 1.2.0 
  69. */ 
  70. public function get_views() { 
  71. $views = array(); 
  72.  
  73. $base_arg = array( 
  74. 'page' => 'bp-avatar-suggestions',  
  75. ); 
  76.  
  77. $type = 0; 
  78. if ( isset( $_REQUEST['avatar_type'] ) ) { 
  79. $type = (int) $_REQUEST['avatar_type']; 
  80.  
  81. $views['all'] = sprintf( 
  82. '<a href="%1$s" class="%2$s">%3$s</a>',  
  83. add_query_arg( $base_arg, bp_get_admin_url( 'admin.php' ) ),  
  84. ( empty( $type ) || 1 == $type ) ? 'current' : false,  
  85. _x( 'All', 'All avatar suggestions type', 'bp-avatar-suggestions' ) 
  86. ); 
  87.  
  88. if ( bp_is_active( 'xprofile' ) ) { 
  89. $users_arg = array_merge( $base_arg, array( 'avatar_type' => 2 ) ); 
  90.  
  91. $views['users'] = sprintf( 
  92. '<a href="%1$s" class="%2$s">%3$s</a>',  
  93. add_query_arg( $users_arg, bp_get_admin_url( 'admin.php' ) ),  
  94. ( ! empty( $type ) && 2 == $type ) ? 'current' : false,  
  95. _x( 'Users', 'Users avatar suggestions type', 'bp-avatar-suggestions' ) 
  96. ); 
  97.  
  98. if ( bp_is_active( 'groups' ) ) { 
  99. $groups_arg = array_merge( $base_arg, array( 'avatar_type' => 3 ) ); 
  100.  
  101. $views['groups'] = sprintf( 
  102. '<a href="%1$s" class="%2$s">%3$s</a>',  
  103. add_query_arg( $groups_arg, bp_get_admin_url( 'admin.php' ) ),  
  104. ( ! empty( $type ) && 3 == $type ) ? 'current' : false,  
  105. _x( 'Groups', 'Groups avatar suggestions type', 'bp-avatar-suggestions' ) 
  106. ); 
  107.  
  108. return apply_filters( 'bp_avatar_suggestions_get_views', $views ); 
  109.  
  110. /** 
  111. * Set the suggestion type 
  112. * @since 1.2.0 
  113. */ 
  114. public function extra_tablenav( $which ) { 
  115. if ( 'top' != $which ) { 
  116. return; 
  117.  
  118. if ( ! bp_is_active( 'xprofile' ) && ! bp_is_active( 'groups' ) ) { 
  119. return; 
  120. ?> 
  121. <div class="alignleft actions"> 
  122. <?php if ( bp_current_user_can( 'bp_moderate' ) ) : ?> 
  123. <label class="screen-reader-text" for="avatar_suggestions_type"><?php _e( 'Change avatar type to…', 'bp-avatar-suggestions' ) ?></label> 
  124. <select name="avatar_suggestions_type" id="avatar_suggestions_type"> 
  125. <option value=""><?php _e( 'Change avatar type to…', 'bp-avatar-suggestions' ) ?></option> 
  126. <option value="1"><?php _e( 'All', 'bp-avatar-suggestions' ) ?></option> 
  127.  
  128. <?php if ( bp_is_active( 'xprofile' ) ) : ?> 
  129. <option value="2"><?php _e( 'Users', 'bp-avatar-suggestions' ) ?></option> 
  130. <?php endif; ?> 
  131.  
  132. <?php if ( bp_is_active( 'groups' ) ) : ?> 
  133. <option value="3"><?php _e( 'Groups', 'bp-avatar-suggestions' ) ?></option> 
  134. <?php endif; ?> 
  135.  
  136. </select> 
  137. <?php 
  138. submit_button( __( 'Change' ), 'button', 'changeit', false ); 
  139. endif; 
  140.  
  141. do_action( 'bp_avatar_suggestions_set_avatar_type' ); 
  142. echo '</div>'; 
  143.  
  144. /** 
  145. * Specific avatar suggestions columns 
  146. * @since 1.2.0 
  147. */ 
  148. public function get_columns() { 
  149.  
  150. $columns = array( 
  151. 'cb' => '<input type="checkbox" />',  
  152. 'avatar' => '',  
  153. 'filename' => __( 'File', 'bp-avatar-suggestions' ),  
  154. ); 
  155.  
  156. if ( bp_is_active( 'groups' ) || bp_is_active( 'xprofile' ) ) { 
  157. $columns['type'] = __( 'Type', 'bp-avatar-suggestions' ); 
  158.  
  159. return apply_filters( 'bp_avatar_suggestions_manage_columns', $columns ); 
  160.  
  161. /** 
  162. * Bulk actions for suggestions. 
  163. * @since 1.2.0 
  164. */ 
  165. public function get_bulk_actions() { 
  166. $actions = array(); 
  167.  
  168. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  169. $actions['delete'] = __( 'Delete', 'bp-avatar-suggestions' ); 
  170.  
  171. return $actions; 
  172.  
  173. /** 
  174. * The text shown when no items are found. 
  175. * @since 1.2.0 
  176. */ 
  177. public function no_items() { 
  178. esc_html_e( 'No avatar suggestions found.', 'bp-avatar-suggestions' ); 
  179.  
  180. /** 
  181. * The columns suggestions can be reordered with. 
  182. * @since 1.2.0 
  183. */ 
  184. public function get_sortable_columns() { 
  185. return array(); 
  186.  
  187. /** 
  188. * Display suggestions rows. 
  189. * @since 1.2.0 
  190. */ 
  191. public function display_rows() { 
  192. $style = ''; 
  193. foreach ( $this->items as $id => $suggestion_object ) { 
  194. $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 
  195. echo "\n\t" . $this->single_row( $suggestion_object, $style ); 
  196.  
  197. /** 
  198. * Display an avatar suggestion row. 
  199. * @since 1.2.0 
  200. */ 
  201. public function single_row( $suggestion_object = null, $style = '' ) { 
  202. echo '<tr' . $style . ' id="suggestion-' . esc_attr( $suggestion_object->ID ) . '">'; 
  203. echo $this->single_row_columns( $suggestion_object ); 
  204. echo '</tr>'; 
  205.  
  206. /** 
  207. * Markup for the checkbox used to select items for bulk actions. 
  208. * @since 1.2.0 
  209. */ 
  210. public function column_cb( $suggestion_object = null ) { 
  211. ?> 
  212. <label class="screen-reader-text" for="suggestion_<?php echo intval( $suggestion_object->ID ); ?>"><?php printf( esc_html__( 'Select %s', 'bp-avatar-suggestions' ), $suggestion_object->post_title ); ?></label> 
  213. <input type="checkbox" id="suggestion_<?php echo intval( $suggestion_object->ID ) ?>" name="allsuggestions[]" value="<?php echo esc_attr( $suggestion_object->ID ) ?>" /> 
  214. <?php 
  215.  
  216. /** 
  217. * The avatar suggestion thumbnail 
  218. * @since 1.2.0 
  219. */ 
  220. public function column_avatar( $suggestion_object = null ) { 
  221. $avatar = wp_get_attachment_image( $suggestion_object->ID, array( 80, 60 ), true ); 
  222.  
  223. if ( ! empty( $avatar ) ) { 
  224. echo $avatar; 
  225.  
  226. /** 
  227. * Display filename, if any. 
  228. * @since 1.2.0 
  229. */ 
  230. public function column_filename( $suggestion_object = null ) { 
  231. // No action to set on the attachment title 
  232. ?> 
  233. <strong><?php echo esc_html( $suggestion_object->post_title ); ?></strong> 
  234.  
  235. <p> 
  236. <?php if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $suggestion_object->ID ), $matches ) ) : 
  237. echo esc_html( strtoupper( $matches[1] ) ); 
  238. else : 
  239. echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) ); 
  240. endif; ?> 
  241. </p> 
  242.  
  243. <?php 
  244. $actions = array(); 
  245.  
  246. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  247. // Build the delete link 
  248. $delete_link = wp_nonce_url( add_query_arg( 
  249. array( 
  250. 'page' => 'bp-avatar-suggestions',  
  251. 'suggestion_id' => $suggestion_object->ID,  
  252. 'action' => 'delete',  
  253. ),  
  254. bp_get_admin_url( 'admin.php' ) 
  255. ), 'bulk-suggestions' ); 
  256.  
  257. $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), __( 'Delete', 'bp-avatar-suggestions' ) ); 
  258.  
  259. $actions = apply_filters( 'bp_avatar_suggestions_row_actions', $actions, $suggestion_object ); 
  260.  
  261. echo $this->row_actions( $actions ); 
  262.  
  263. /** 
  264. * Display the avatar type 
  265. * @since BuddyPress (2.0.0) 
  266. */ 
  267. public function column_type( $suggestion_object = null ) { 
  268. $type_key = (int) get_post_meta( $suggestion_object->ID, '_bpas_avatar_type', true ); 
  269.  
  270. if ( 1 == $type_key ) { 
  271. $type = _x( 'All', 'All avatar suggestions type', 'bp-avatar-suggestions' ); 
  272. } else if ( 2 == $type_key ) { 
  273. $type = _x( 'Users', 'Users avatar suggestions type', 'bp-avatar-suggestions' ); 
  274. } else if ( 3 == $type_key ) { 
  275. $type = _x( 'Groups', 'Groups avatar suggestions type', 'bp-avatar-suggestions' ); 
  276. } else { 
  277. $type = __( 'Unknown', 'bp-avatar-suggestions' ); 
  278.  
  279. echo esc_html( $type ); 
  280.  
  281. /** 
  282. * Allow plugins to add their custom column. 
  283. * @since 1.2.0 
  284. */ 
  285. function column_default( $suggestion_object = null, $column_name = '' ) { 
  286. return apply_filters( 'bp_avatar_suggestions_custom_column', '', $column_name, $suggestion_object );