bp_docs_associated_group_dropdown

Get a dropdown of associable groups for the current user.

Description

bp_docs_associated_group_dropdown( (array) $args = array() ); 

Parameters (1)

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

Usage

  1. if ( !function_exists( 'bp_docs_associated_group_dropdown' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-docs/includes/templatetags.php'; 
  3.  
  4. // The args. 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_docs_associated_group_dropdown($args); 
  9.  

Defined (1)

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

/includes/templatetags.php  
  1. function bp_docs_associated_group_dropdown( $args = array() ) { 
  2. if ( ! bp_is_active( 'groups' ) ) { 
  3. return; 
  4. $r = wp_parse_args( $args, array( 
  5. 'name' => 'associated_group_id',  
  6. 'id' => 'associated_group_id',  
  7. 'selected' => null,  
  8. 'options_only' => false,  
  9. 'echo' => true,  
  10. 'null_option' => true,  
  11. 'include' => null,  
  12. ) ); 
  13.  
  14. $groups_args = array( 
  15. 'per_page' => false,  
  16. 'populate_extras' => false,  
  17. 'type' => 'alphabetical',  
  18. 'update_meta_cache' => false,  
  19. ); 
  20.  
  21. if ( ! bp_current_user_can( 'bp_moderate' ) ) { 
  22. $groups_args['user_id'] = bp_loggedin_user_id(); 
  23.  
  24. if ( ! is_null( $r['include'] ) ) { 
  25. $groups_args['include'] = wp_parse_id_list( $r['include'] ); 
  26.  
  27. ksort( $groups_args ); 
  28. ksort( $r ); 
  29. $cache_key = 'bp_docs_associated_group_dropdown:' . md5( serialize( $groups_args ) . serialize( $r ) ); 
  30. $cached = wp_cache_get( $cache_key, 'bp_docs_nonpersistent' ); 
  31. if ( false !== $cached ) { 
  32. return $cached; 
  33.  
  34. // Populate the $groups_template global, but stash the old one 
  35. // This ensures we don't mess anything up inside the group 
  36. global $groups_template; 
  37. $old_groups_template = $groups_template; 
  38.  
  39. bp_has_groups( $groups_args ); 
  40.  
  41. // Filter out the groups where associate_with permissions forbid 
  42. $removed = 0; 
  43. foreach ( $groups_template->groups as $gtg_key => $gtg ) { 
  44. if ( ! current_user_can( 'bp_docs_associate_with_group', $gtg->id ) ) { 
  45. unset( $groups_template->groups[ $gtg_key ] ); 
  46. $removed++; 
  47.  
  48. // cleanup, if necessary from filter above 
  49. if ( $removed ) { 
  50. $groups_template->groups = array_values( $groups_template->groups ); 
  51. $groups_template->group_count = $groups_template->group_count - $removed; 
  52. $groups_template->total_group_count = $groups_template->total_group_count - $removed; 
  53.  
  54. $html = ''; 
  55.  
  56. if ( ! $r['options_only'] ) { 
  57. $html .= sprintf( '<select name="%s" id="%s">', esc_attr( $r['name'] ), esc_attr( $r['id'] ) ); 
  58.  
  59. if ( $r['null_option'] ) { 
  60. $html .= '<option value="">' . __( 'None', 'bp-docs' ) . '</option>'; 
  61.  
  62. foreach ( $groups_template->groups as $g ) { 
  63. $html .= sprintf( 
  64. '<option value="%s" %s>%s</option>',  
  65. esc_attr( $g->id ),  
  66. selected( $r['selected'], $g->id, false ),  
  67. esc_html( stripslashes( $g->name ) ) 
  68. ); 
  69.  
  70. if ( ! $r['options_only'] ) { 
  71. $html .= '</select>'; 
  72.  
  73. $groups_template = $old_groups_template; 
  74.  
  75. wp_cache_set( $cache_key, $html, 'bp_docs_nonpersistent' ); 
  76.  
  77. if ( false === $r['echo'] ) { 
  78. return $html; 
  79. } else { 
  80. echo $html;