Created
March 30, 2017 15:51
-
-
Save strangerstudios/8f0ff4e526c72392cf56986e708565a1 to your computer and use it in GitHub Desktop.
Add a "Requires Membership" column to the Categories dashboard page to show what levels are required to view.
This file contains hidden or 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 | |
//add a new column to the categories view | |
function requires_membership_categories_columns_head( $defaults ) { | |
$defaults['requires_membership'] = 'Requires Membership'; | |
return $defaults; | |
} | |
//get the column data | |
function requires_membership_categories_columns_content( $content, $column_name, $term_id ) { | |
if ($column_name == 'requires_membership') { | |
global $membership_levels, $wpdb; | |
$protected_levels = array(); | |
foreach($membership_levels as $level) | |
{ | |
$protectedcategories = $wpdb->get_col("SELECT category_id FROM $wpdb->pmpro_memberships_categories WHERE membership_id = $level->id"); | |
if( in_array( $term_id, $protectedcategories ) ) { | |
$protected_levels[] = $level->name; | |
} | |
} | |
echo implode( ', ', $protected_levels); | |
} | |
} | |
add_filter( 'manage_edit-category_columns', 'requires_membership_categories_columns_head' ); | |
add_action( 'manage_category_custom_column', 'requires_membership_categories_columns_content', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Show a Post, Page or Category’s Required Membership Levels in the Dashboard “All” Views" at Paid Memberships Pro here: https://www.paidmembershipspro.com/show-post-page-categorys-required-membership-levels-dashboard-views/