Created
September 30, 2017 14:24
-
-
Save sbrajesh/928d36128afe48cd6cdf29a47a232abb to your computer and use it in GitHub Desktop.
for Margrita
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter on the gallery creation permission. | |
* | |
* @param bool $can can create. | |
* @param string $component component name. | |
* @param string $component_id component id. | |
* | |
* @return bool | |
*/ | |
function mpp_custom_limit_gallery_creation( $can, $component, $component_id ) { | |
// non logged in user's don't have permissions and admin's don't have restrictions. | |
if ( ! is_user_logged_in() || is_super_admin() ) { | |
return $can; | |
} | |
$user_id = get_current_user_id(); | |
// How many galleries? | |
$allowed_gallery_count = 1; // 0 = no restriction. | |
if ( ! $allowed_gallery_count ) { | |
// No restrictions when someone sets it to zero zero. | |
return $can; | |
} | |
// only limit if crossed the limit. | |
if ( mpp_get_user_gallery_count( $user_id ) >= $allowed_gallery_count ) { | |
$can = false; | |
} | |
return $can; | |
} | |
add_filter( 'mpp_user_can_create_gallery', 'mpp_custom_limit_gallery_creation', 10, 3 ); | |
/** | |
* Filter on the media upload permission. | |
* | |
* @param bool $can can create. | |
* @param string $component component name. | |
* @param string $component_id component id. | |
* @param MPP_Gallery $gallery gallery object. | |
* | |
* @return bool | |
*/ | |
function mpp_custom_limit_media_upload( $can, $component, $component_id, $gallery ) { | |
// non logged in user's don't have permissions and admin's don't have restrictions. | |
if ( ! is_user_logged_in() || is_super_admin() ) { | |
return $can; | |
} | |
$user_id = get_current_user_id(); | |
// How Many media is allowed? | |
$allowed_media_count = 2; // 0 = no limit. | |
if ( ! $allowed_media_count ) { | |
// No restrictions when zero. | |
return $can; | |
} | |
// only limit if crossed the limit. | |
if ( mpp_get_user_media_count( $user_id ) >= $allowed_media_count ) { | |
$can = false; | |
} | |
return $can; | |
} | |
add_filter( 'mpp_user_can_upload', 'mpp_custom_limit_media_upload', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment