wordpress if checkbox is checked code example

Example: wordpress check to see if checkbox has been checked

/*
* Choose if you want Coming Soon page or not
*/

function creative_checkbox_field_1_render() { 
  $options = get_option( 'creative_settings' );?>
  <input type='checkbox' name='creative_settings[creative_checkbox_field_1]' <?php checked( $options['creative_checkbox_field_1'], 1 ); ?> value='1'>
  <?php
}

  // If is checked, activate function to display coming soon page
  if( $options['creative_checkbox_field_1'] == '1' ) { 
      add_action('get_header', 'coming_soon_mode');
  } 
  else { 
      //do nothing
  }

/*
* Display Coming soon Page
*/

function coming_soon_mode() {
  if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
      wp_die('Ce site est en cours de création. Revenez-vite nous voir !');
  }
}

Tags:

Misc Example