Add custom taxonomy content restrictions

This commit is contained in:
champsupertramp
2016-01-07 10:41:49 +08:00
parent 2dd1003ec6
commit cf95130497
2 changed files with 45 additions and 14 deletions
+21 -4
View File
@@ -50,10 +50,27 @@
*
**/
add_action( 'category_add_form_fields', 'um_category_access_fields_create' );
add_action( 'category_edit_form_fields', 'um_category_access_fields_edit' );
add_action( 'create_category', 'um_category_access_fields_save' );
add_action( 'edited_category', 'um_category_access_fields_save' );
$exclude_taxonomies = array(
'post_tag',
'nav_menu',
'link_category',
'post_format',
'um_user_tag',
'um_hashtag',
);
$taxonomies = get_taxonomies();
foreach ($taxonomies as $key => $taxonomy) {
if( ! in_array( $key , $exclude_taxonomies ) ){
add_action( $taxonomy.'_add_form_fields', 'um_category_access_fields_create' );
add_action( $taxonomy.'_edit_form_fields', 'um_category_access_fields_edit' );
add_action( 'create_'.$taxonomy, 'um_category_access_fields_save' );
add_action( 'edited_'.$taxonomy, 'um_category_access_fields_save' );
}
}
function um_category_access_fields_create( $term ){
global $ultimatemember;
+18 -4
View File
@@ -68,12 +68,22 @@
return;
}
if ( is_single() || get_the_category() ) {
if ( is_single() || get_post_taxonomies( $post ) ) {
$categories = get_the_category();
foreach( $categories as $cat ) {
$term_id = $cat->term_id;
$taxonomies = get_post_taxonomies( $post );
$categories_ids = array();
foreach ($taxonomies as $key => $value) {
$term_list = wp_get_post_terms($post->ID, $value, array("fields" => "ids"));
foreach( $term_list as $term_id ){
array_push( $categories_ids , $term_id);
}
}
foreach( $categories_ids as $term => $term_id ) {
$opt = get_option("category_$term_id");
if ( isset( $opt['_um_accessible'] ) ) {
@@ -143,10 +153,13 @@
}
if ( !isset( $post_id ) )
$post_id = $post->ID;
$args = $ultimatemember->access->get_meta( $post_id );
extract($args);
if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) {
@@ -171,6 +184,7 @@
case 0:
$ultimatemember->access->allow_access = true;
$ultimatemember->access->redirect_handler = false; // open to everyone
break;
case 1: