Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Created October 16, 2018 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/15dda79932a0cd9676b38db346c020ae to your computer and use it in GitHub Desktop.
Save KaineLabs/15dda79932a0cd9676b38db346c020ae to your computer and use it in GitHub Desktop.
Allow Adding/Editing Reviews for Contributers and Amins Only.
<?php
/**
* Allow Adding/Editing Reviews for Contributers and Amins Only.
*/
function yzc_allow_reviews_by_role() {
$can = false;
// Get Current User Data.
$user = wp_get_current_user();
$allowed_roles = array( 'contributor', 'administrator' );
foreach ( $allowed_roles as $role ) {
if ( in_array( $role, (array) $user->roles ) ) {
$can = true;
}
}
return $can;
}
add_filter( 'yz_is_user_can_add_reviews', 'yzc_allow_reviews_by_role' );
add_filter( 'yz_is_user_can_edit_reviews', 'yzc_allow_reviews_by_role' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment