Created
November 27, 2024 23:52
-
-
Save hivepress/80adf61d27021a49f85de7a4058555ae to your computer and use it in GitHub Desktop.
Redirect request pages if the current user is not vendor or the request author #hivepress #requests
This file contains 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_action( | |
'template_redirect', | |
function() { | |
$url = home_url(); | |
$route = hivepress()->router->get_current_route_name(); | |
if ( 'request_view_page' === $route ) { | |
$post = get_queried_object(); | |
if ( get_current_user_id() !== absint( $post->post_author ) && ! current_user_can( 'edit_posts' ) ) { | |
wp_safe_redirect( $url ); | |
} | |
} elseif ( 'requests_view_page' === $route && ! current_user_can( 'edit_posts' ) ) { | |
wp_safe_redirect( $url ); | |
} | |
}, | |
1000 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment