roles as $role ) { if ( false !== array_search( $role, self::ROLE_HIERARCHY ) && array_search( $role, self::ROLE_HIERARCHY ) <= $most_permissive_role_index ) { $most_permissive_role_index = array_search( $role, self::ROLE_HIERARCHY ); $most_permissive_role = $role; } } if ( empty( $most_permissive_role ) ) { return $all_caps; } $custom_caps = self::get_caps_for( $most_permissive_role ); // create "enabled capabilities" style array $caps_to_merge = array(); foreach ( $custom_caps as $cap ) { $caps_to_merge[ $cap ] = 1; } return array_merge( $all_caps, $caps_to_merge ); } public static function current_user_can_or_die( $perm, ...$args ) { if ( ! current_user_can( $perm, ...$args ) ) { wp_die( '
' . esc_html__( 'Sorry, you are not allowed to do this action.', 'videopress-hq' ) . '
', 403 ); } } private static function get_caps_for( $role_name ) { $all_caps = array( self::CAP_EDIT_VIDEO, self::CAP_EDIT_VIDEOS, self::CAP_EDIT_OTHERS_VIDEOS, self::CAP_EDIT_PUBLISHED_VIDEOS, self::CAP_READ_VIDEO, self::CAP_READ_PRIVATE_VIDEOS, self::CAP_DELETE_VIDEO, self::CAP_DELETE_VIDEOS, self::CAP_DELETE_PUBLISHED_VIDEO, self::CAP_DELETE_PUBLISHED_VIDEOS, self::CAP_PUBLISH_VIDEO, self::CAP_PUBLISH_VIDEOS, self::CAP_EDIT_PLAYLIST, self::CAP_EDIT_PLAYLISTS, self::CAP_EDIT_OTHERS_PLAYLISTS, self::CAP_EDIT_PUBLISHED_PLAYLISTS, self::CAP_READ_PLAYLIST, self::CAP_READ_PRIVATE_PLAYLISTS, self::CAP_DELETE_PLAYLIST, self::CAP_DELETE_PLAYLISTS, self::CAP_DELETE_PUBLISHED_PLAYLIST, self::CAP_DELETE_PUBLISHED_PLAYLISTS, self::CAP_PUBLISH_PLAYLIST, self::CAP_PUBLISH_PLAYLISTS, self::CAP_READ_DASHBOARD, ); switch ( $role_name ) { case 'administrator': return $all_caps; case 'editor': return $all_caps; case 'author': return array( self::CAP_EDIT_VIDEO, self::CAP_EDIT_VIDEOS, self::CAP_READ_VIDEO, self::CAP_DELETE_VIDEO, self::CAP_EDIT_PLAYLIST, self::CAP_EDIT_PLAYLISTS, self::CAP_READ_PLAYLIST, self::CAP_DELETE_PLAYLIST, self::CAP_READ_DASHBOARD, ); case 'contributor': return array( self::CAP_EDIT_VIDEO, self::CAP_EDIT_VIDEOS, self::CAP_READ_VIDEO, self::CAP_EDIT_PLAYLIST, self::CAP_EDIT_PLAYLISTS, self::CAP_READ_PLAYLIST, self::CAP_READ_DASHBOARD, ); case 'subscriber': return array( self::CAP_READ_VIDEO, self::CAP_READ_PLAYLIST, ); default: return array(); } } }