mpp_register_status( $args )
Register a new media/gallery status(privacy level)
Description
This function is used to register new privacy level.
Parameters
$args
- key (string) (Required) Unique identifier for this status. Example “private”, “loggedin”,”public” etc.
- label (string) (Required) A name for this status. Example:- “Public”, “Private”, “Logged in Users Only”
- labels (array) (Required ) An associative array with two keys, “singular_name”, “plural_name” the values represent labels.
- description (string) (Optional) A textual description of this status
- callback (Callable) (Required ) A callback which will be called and passed component, component_id and user_id to determine of the current user can access a gallery/media
- activity_privacy (string) (Optional):- Just a compat privacy level if you are planning to make your privacy compatible with BuddyPress Activity privacy plugin
Returns
It does not return anything.
Examples
The code shows how we register the Friends only privacy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | function mpp_register_custom_status() { mpp_register_status( array( 'key' => 'friendsonly', 'label' => __( 'Friends Only', 'mediapress' ), 'labels' => array( 'singular_name' => __( 'Friends Only', 'mediapress' ), 'plural_name' => __( 'Friends Only', 'mediapress' ) ), 'description' => __( 'Friends Only Privacy Type', 'mediapress' ), 'callback' => 'mpp_check_friends_access',//callable, see the below definition for parameters 'activity_privacy' => 'friends',//optional, just for activity privacy compat )); } add_action( 'mpp_setup', 'mpp_register_custom_status', 11 ); |
Here is the callback defined for the above status
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /** * Check if the User Can access friends only gallery/media for the given component and component_id * @param string $component_type the identifier for component to which the current gallery/media is being checked e.g "sitewide", "members", "groups" etc * @param int $component_id id of the component with which the media is associated( can be group id or user id or gallery id based on component) * @param int $user_id * @return boolean true if access is allowed else false */ function mpp_check_friends_access ( $component_type, $component_id, $user_id = null ) { $allow = false; if ( is_super_admin() || $component_id == $user_id || bp_is_active( 'friends' ) && ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $component_id ) ) ) { $allow = true; } return apply_filters( 'mpp_check_friends_access', $allow, $component_type, $component_id, $user_id ); } |
As you might have noticed, the callback gets the component as first parameter. It can be one of the registered component( currently, the 3 components registered in the core are “sitewide”, “members”, “groups”)
$component_id:- It identifies the current owner object. For example, in case of User gallery, It is set to user_id , in case of group gallery, It is the id of the group and in case of the sitewide gallery, It is the gallery id itself.
$user_id:- A numeric id of the user for whom we are checking access to the given component’s(User’s in this case) gallery.
Note:-
It must be used on or after “mpp_setup_core” action.
See also:-
Changelog
- Since 1.0.0
Source
medisapress/core/api/mpp-api.php