Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!