update_group_media_privacy

Update the group media privacy according to the group privacy settings when group settings are changed.

Description

update_group_media_privacy( (int) $group_id ); 

Parameters (1)

0. $group_id (int)
The group id.

Usage

  1. if ( !function_exists( 'update_group_media_privacy' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'rtmedia-for-wordpress-buddypress-and-bbpress/app/main/controllers/template/rtmedia-actions.php'; 
  3.  
  4. // The group id. 
  5. $group_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = update_group_media_privacy($group_id); 
  9.  

Defined (1)

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

/app/main/controllers/template/rtmedia-actions.php  
  1. function update_group_media_privacy( $group_id ) { 
  2.  
  3. if ( ! empty( $group_id ) && function_exists( 'groups_get_group' ) ) { 
  4. //get the buddybress group 
  5. $group = groups_get_group( array( 
  6. 'group_id' => $group_id,  
  7. ) ); 
  8.  
  9. if ( isset( $group->status ) ) { 
  10. global $wpdb; 
  11.  
  12. $model = new RTMediaModel(); 
  13.  
  14. if ( 'public' !== $group->status ) { 
  15. // when group settings are updated and is private/hidden, set media privacy to 20 
  16. $update_sql = $wpdb->prepare( "UPDATE {$model->table_name} SET privacy = '20' where context='group' AND context_id=%d AND privacy <> 80 ", $group_id ); // @codingStandardsIgnoreLine 
  17. } else { 
  18. // when group settings are updated and is private/hidden, set media privacy to 0 
  19. $update_sql = $wpdb->prepare( "UPDATE {$model->table_name} SET privacy = '0' where context='group' AND context_id=%d AND privacy <> 80 ", $group_id ); // @codingStandardsIgnoreLine 
  20.  
  21. //update the medias 
  22. $wpdb->query( $update_sql ); // @codingStandardsIgnoreLine 
  23.