BP_Document_Privacy
BuddyBoss Document Privacy.
Description
Handles document privacy information.
Source
File: bp-document/classes/class-bp-document-privacy.php
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | class BP_Document_Privacy { private function __construct() {} /** * Get the instance of this class. * * @return BP_Document_Privacy|null */ public static function instance() { static $instance = null; if ( null === $instance ) { $instance = new BP_Document_Privacy(); } return $instance ; } /** * get options for visibility. * * @since BuddyBoss 1.4.0 * @param bool $is_group * @return array */ function get_visibility_options( $is_group = false ) { $options = array ( 'public' => __( 'Everyone' , 'buddyboss' ), 'loggedin' => __( 'Logged In Users' , 'buddyboss' ), 'onlyme' => __( 'Only Me' , 'buddyboss' ), 'friends' => __( 'My Connections' , 'buddyboss' ), ); if ( $is_group && bp_is_active( 'groups' ) ) { $options [ 'grouponly' ] = __( 'Group Members' , 'buddyboss' ); } return $options ; } /** * Get visibility of document * * @since BuddyBoss 1.4.0 * @param $document_id * * @return WP_Error */ function get_visibility( $document_id ) { $result = bp_document_get_specific( array ( 'document_ids' => $document_id ) ); if ( empty ( $result [ 'documents' ] ) || empty ( $result [ 'documents' ][0] ) ) { return new WP_Error( 'no_document' , __( 'There is no document.' , 'buddyboss' ), array ( 'status' => 500 ) ); } return $result [ 'documents' ][0]->privacy; } /** * Check if document is visible or not to the logged in user * * @since BuddyBoss 1.4.0 * @param bool $document_id * * @return bool|mixed|WP_Error */ public function is_document_visible( $document_id = false ) { $result = bp_document_get_specific( array ( 'document_ids' => $document_id ) ); if ( empty ( $result [ 'documents' ] ) || empty ( $result [ 'documents' ][0] ) ) { return new WP_Error( 'no_document' , __( 'There is no document.' , 'buddyboss' ), array ( 'status' => 500 ) ); } $document = $result [ 'documents' ][0]; $visibility = $document ->privacy; $visible = true; if ( bp_loggedin_user_id() != $document ->user_id ) { switch ( $visibility ) { // Logged in users. case 'loggedin' : if ( ! bp_loggedin_user_id() ) { $visible = false; } break ; // My friends. case 'friends' : if ( bp_is_active( 'friends' ) ) { $is_friend = friends_check_friendship( bp_loggedin_user_id(), $document ->user_id ); if ( ! $is_friend ) { $visible = false; } } break ; // Only group members. case 'grouponly' : if ( bp_is_active( 'groups' ) ) { $group_is_user_member = groups_is_user_member( bp_loggedin_user_id(), $document ->activity_id ); if ( ! $group_is_user_member ) { $visible = false; } } break ; // Only Me. case 'onlyme' : if ( bp_loggedin_user_id() != $document ->user_id ) { $visible = false; } break ; default : // public. break ; } } if ( is_super_admin() ) { $visible = true; } return apply_filters( 'bp_document_is_document_visible' , $visible , $visibility , $document_id ); } } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.4.0 | Introduced. |
Methods
- __construct
- get_visibility — Get visibility of document
- get_visibility_options — get options for visibility.
- instance — Get the instance of this class.
- is_document_visible — Check if document is visible or not to the logged in user
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.