diff --git a/admin/core/um-admin-actions.php b/admin/core/um-admin-actions.php index 3f7e4fe8..c628d2f3 100644 --- a/admin/core/um-admin-actions.php +++ b/admin/core/um-admin-actions.php @@ -49,12 +49,29 @@ * Add access settings to category * **/ - - 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; diff --git a/core/um-actions-access.php b/core/um-actions-access.php index 20c618c9..bf9f0d12 100644 --- a/core/um-actions-access.php +++ b/core/um-actions-access.php @@ -67,13 +67,23 @@ if( is_front_page() || is_home() ){ 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'] ) ) { @@ -127,26 +137,29 @@ add_action('um_access_post_settings','um_access_post_settings'); function um_access_post_settings() { global $post, $ultimatemember; - + // woo commerce shop ID if( function_exists('is_shop') && is_shop() ) { $post_id = get_option('woocommerce_shop_page_id'); - + } else if ( is_archive() || is_front_page() || is_home() || is_search() || in_the_loop() ) { return; } else { - + if ( !get_post_type() || !isset($post->ID) ) return; } + + 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: @@ -215,5 +229,5 @@ $ultimatemember->access->redirect_handler = $redirect_to; } } - + } \ No newline at end of file