Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
Wordpress settings page how to add a disabled field using add_settings_field conditionally?

I'm creating my settings page for a Wordpress plug-in, here is one of the fields to make a quick example:

add_settings_field(
    'stwc_ft_oosn_0',
    'Enable',
    array( $this, 'stwc_ft_oosn_0_callback' ),
    'settings-admin',
    'stwc_ft_oosn_section'
);

Now in this case the field is a checkbox, how do I disable this conditionally? For example how do I disable it (not uncheck) depending on the value of another setting? Maybe using javascript? Is it safe?

I did this test but it is not working, I'm not sure if I'm moving in the right direction:

<script type="text/javascript">
    jQuery(document).ready(function(){          
        document.addEventListener('click', UpdateFields(), false);

        function UpdateFields(){
            if ( !document.getElementById('stwc_ft_oosn_0').checked ) {
               document.getElementById('stwc_ft_oosn_notice_1').setAttribute("disabled","disabled");
            } else {
               document.getElementById('stwc_ft_oosn_notice_1').removeAttribute("disabled");
            }
            //add other checks here
        }
                
    });                         
</script>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda