Please add role hook
-
This plugin is great. I would like to be able to add roles without modifying your code. Can you please update the following code for a future version, to allow modifying access to other user roles, as our authors do not have the ‘manage_options’ capability but still want to use the frontend tools.
Thanks!
<?php
/*
Plugin Name: WP Tota11y
Plugin URI: https://wordpress.org/plugins/wp-tota11y/
Description: WP Tota11y is an accessibility visualization toolkit. It can point out many common problems regarding accessibility.
Version: 1.2.0
Author: Marcel Pol
Author URI: https://timelord.nl
License: GPLv2 or later
*/
/*
Copyright 2015 - 2021 Marcel Pol (email: marcel@timelord.nl)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Load JavaScript.
*
* @return void
*/
function wp_tota11y_js() {
$allowed_roles = array( 'administrator' );
// allow other plugins to modify these in a filter
$allowed_roles = apply_filters( 'wp_tota11y_allowed_roles', $allowed_roles );
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$user_roles = $user->roles;
foreach ( $user_roles as $role ) {
if ( in_array( $role, $allowed_roles, true ) ) {
$is_allowed = true;
break;
}
}
if ( $is_allowed ) {
// Always load jQuery.
wp_enqueue_script( 'jquery' );
// Load Tota11y.js
wp_enqueue_script( 'wp-tota11y-js', plugins_url( '/js/tota11y.min.js', __FILE__ ), 'jquery', '1.2.0', true );
}
}
}
// Frontend
add_action( 'wp_enqueue_scripts', 'wp_tota11y_js' );
// Admin
add_action( 'admin_menu', 'wp_tota11y_js' );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.