• Resolved virtuosicmedia

    (@virtuosicmedia)


    Howdy folks,

    I’m trying to use Javascript to hide some panels in the Customizer based on user role. I’d like to accomplish this the same way I do in the Block editor and admin interface, by adding a class to the body tag.

    Using the admin_body_class filter does not add the classes to the Customizer. Using the body_class filter adds the class to the Customizer preview, inside the iFrame, but that doesn’t allow me to target sections within the Customizer itself.

    Is there a filter to add classes to the Customizer? Or do you have to use the Customizer API and conditionally unload panels based on role? That seems a rather heavy solution for my usecase.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I assume you are aware your proposed javascript solution is has no security, i.e. just cosmetic?

    I’d be inclined to bite the bullet and do it the secure way.

    Otherwise you can use the action customize-theme-controls which is just inside the </head>

    sort of like

    add_action( 
       'customize-theme-control', 
       function() { 
           // do stuff to detect role 
           // and to echo your javascript to hide sections
       },
       10
    )
    Thread Starter virtuosicmedia

    (@virtuosicmedia)

    Yes, I’m aware. It’s specifically to hide things from the client until they elevate their own permissions. The screen as it is is overwhelming, and I’m a pretty big believer in training wheels.

    Thank you, I’ll look into this.

    Thread Starter virtuosicmedia

    (@virtuosicmedia)

    Thank you again.

    I was not able to get that to work, but a search for customize-theme-controls led me to customize_controls_enqueue_scripts, which will allow me to conditionally enqueue a script based on role.

    I’d still be curious if anyone knows a way to add body classes to the Customizer, but I’ll mark this as resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding body classes to Customizer’ is closed to new replies.