WordPress has a user capability called unfiltered_html
. Any user with the unfiltered_html
capability can post any HTML they want, including <script>
tags.
If you need to add the unfiltered_html
capability to a non-(Super-)Admin user, you can use WP_User::add_cap()
to add it to a user:
add_action( 'admin_init', 'wpse_393657_grant_user_unfiltered_html' );
function wpse_393657_grant_user_unfiltered_html() {
$user = get_user_by( 'login', 'my_username' );
if ( ! user_can( $user, 'unfiltered_html' ) ) {
$user->add_cap( 'unfiltered_html', true );
}
}
…or WP_Role::add_cap()
to add it to a Role (eg, Editor).
add_action( 'admin_init', 'wpse_393657_grant_role_unfiltered_html' );
function wpse_393657_grant_role_unfiltered_html() {
$role = get_role( 'editor' );
if ( ! $role->has_cap( 'unfiltered_html' ) ) {
$role->add_cap( 'unfiltered_html', true );
}
}
(These code snippets are untested, and are meant to provide a starting point for you.)
Note that the capability assignments are permanent (ie, written to the database), and that the user or role will retain the unfiltered_html
capability until/unless you revoke it.