Last active
January 10, 2024 10:19
-
-
Save mehul0810/180632d0fa15a7b1ab122ac07d2aae77 to your computer and use it in GitHub Desktop.
Allow Script Tags to be added in content for specific user roles. Works will multisite as well.
This file contains hidden or 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 | |
/** | |
* Allow Script Tags to be used in editor for Administrator user role. | |
* | |
* @author Mehul Gohil <[email protected]> | |
*/ | |
function allow_unfiltered_html_for_administrators( $allowed_tags ) { | |
// Bailout, if the logged-in user role is not `administrator`. | |
if ( ! current_user_can( 'administrator' ) ) { | |
return $allowed_tags; | |
} | |
$allowed_tags['script'] = array( | |
'src' => true, | |
'height' => true, | |
'width' => true, | |
'charset' => true, | |
'async' => true | |
); | |
return $allowed_tags; | |
} | |
add_filter( 'wp_kses_allowed_html', 'allow_unfiltered_html_for_administrators' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment