Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great
Created January 22, 2015 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bappi-d-great/ba5575ad4063ae2e66ad to your computer and use it in GitHub Desktop.
Save bappi-d-great/ba5575ad4063ae2e66ad to your computer and use it in GitHub Desktop.
Add custom post type quota for different Pro Sites level
<?php
/*
*
* You just need to configure the $limits array. The elements are level ID - 1. So, if your level ID 1, the index will be 0.
* Then for product index add the limit
*
*/
$limits = array(
'0' => array(
'product' => 2
),
'1' => array(
'product' => 3
),
'2' => array(
'product' => 4
),
'3' => array(
'product' => 5
),
);
add_filter( 'user_has_cap', 'check_pro_limit', 999, 3 );
function check_pro_limit( $allcaps, $caps, $args ) {
$id = get_current_blog_id();
global $psts, $limits;
if( $id != 1 ){
$level = $psts->get_level($id);
if( is_array( $limits[$level - 1] ) )
foreach ($limits[$level - 1] as $post_type => $settings) {
if ( wp_count_posts($post_type)->publish >= $settings ) {
$pt_obj = get_post_type_object($post_type);
unset($allcaps[$pt_obj->cap->publish_posts]);
}
}
}
return $allcaps;
}
add_action( 'admin_notices', 'message_notice' );
function message_notice() {
$id = get_current_blog_id();
global $psts, $limits;
if( $id != 1 ){
$level = $psts->get_level($id);
$screen = get_current_screen();
switch( $screen->post_type ){
case 'product':
$published_posts = wp_count_posts( 'product' )->publish;
if( $published_posts >= $limits[$level - 1]['post'] ){
?>
<div class='error'>
<p>Please upgrade to publish more products.</p>
</div>
<?php
}
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment