Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda