Add action hook for current page type in access settings

This commit is contained in:
champsupertramp
2016-04-16 16:40:14 +08:00
parent 10bc412e24
commit 8791704888
2 changed files with 46 additions and 0 deletions
+5
View File
@@ -144,6 +144,11 @@
$post_id = get_option('woocommerce_shop_page_id');
} else if ( is_archive() || is_front_page() || is_home() || is_search() || in_the_loop() || is_feed() ) {
$current_page_type = um_get_current_page_type();
do_action("um_access_post_type",$current_page_type);
do_action("um_access_post_type_{$current_page_type}");
return;
+41
View File
@@ -1647,3 +1647,44 @@ function um_fetch_user( $user_id ) {
return $lang_code;
}
/**
* Get current page type
* @return string
*/
function um_get_current_page_type() {
global $wp_query;
$loop = 'notfound';
if ( $wp_query->is_page ) {
$loop = is_front_page() ? 'front' : 'page';
} elseif ( $wp_query->is_home ) {
$loop = 'home';
} elseif ( $wp_query->is_single ) {
$loop = ( $wp_query->is_attachment ) ? 'attachment' : 'single';
} elseif ( $wp_query->is_category ) {
$loop = 'category';
} elseif ( $wp_query->is_tag ) {
$loop = 'tag';
} elseif ( $wp_query->is_tax ) {
$loop = 'tax';
} elseif ( $wp_query->is_archive ) {
if ( $wp_query->is_day ) {
$loop = 'day';
} elseif ( $wp_query->is_month ) {
$loop = 'month';
} elseif ( $wp_query->is_year ) {
$loop = 'year';
} elseif ( $wp_query->is_author ) {
$loop = 'author';
} else {
$loop = 'archive';
}
} elseif ( $wp_query->is_search ) {
$loop = 'search';
} elseif ( $wp_query->is_404 ) {
$loop = 'notfound';
}
return $loop;
}