Skip to content

Instantly share code, notes, and snippets.

@hivepress
Created November 27, 2024 23:52
Show Gist options
  • Save hivepress/80adf61d27021a49f85de7a4058555ae to your computer and use it in GitHub Desktop.
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
<?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