...'`). Instead they * use a custom sanitizer that passes the value through unchanged, the * same trust model WordPress core itself uses for its own Customizer * "Additional CSS" field (`sanitize_callback => 'wp_unslash'` -- raw * passthrough), and with core's same gate: that field needs `edit_css`, * which maps to `unfiltered_html`, so here a user without * `unfiltered_html` (any site admin on multisite, or everyone when * DISALLOW_UNFILTERED_HTML is set) can't change the code -- a save or * settings import keeps the stored value. Otherwise `manage_options` * would be enough to put arbitrary script on every page. */ final class Module implements ModuleInterface { /** * {@inheritDoc} */ public function get_id(): string { return 'custom_code'; } /** * {@inheritDoc} */ public function register(): void { $this->register_settings( aiou()->settings() ); ( new Feature() )->register(); } /** * Register the "Custom Code" tab. * * @param SettingsRegistry $settings The settings registry. * @return void */ private function register_settings( SettingsRegistry $settings ): void { $settings->add_tab( 'custom_code', __( 'Custom Code', 'all-in-one-utilities' ), __( 'Add custom CSS or JavaScript to your site, or custom CSS to wp-admin, without editing your theme.', 'all-in-one-utilities' ), 60 ); $settings->add_section( 'custom_code', 'code', __( 'Custom Code', 'all-in-one-utilities' ), '', 10 ); $raw_sanitize = static function ( string $field_id ): \Closure { return static function ( mixed $value ) use ( $field_id ): string { if ( ! current_user_can( 'unfiltered_html' ) ) { return (string) aiou_get_setting( 'custom_code', 'code', $field_id, '' ); } return is_string( $value ) ? $value : ''; }; }; $settings->add_field( 'custom_code', 'code', new Field( id: 'enabled', label: __( 'Enable custom code', 'all-in-one-utilities' ), type: 'checkbox', default: 0, args: array( 'toggle_label' => __( 'Output the custom code below', 'all-in-one-utilities' ) ), priority: 10 ) ); $settings->add_field( 'custom_code', 'code', new Field( id: 'frontend_css', label: __( 'Frontend CSS', 'all-in-one-utilities' ), type: 'code', default: '', args: array( 'language' => 'css', 'rows' => 14, 'label_above' => true, 'description' => __( 'Added inside a