If checkbox is checked, do function (Admin Menu Option Page for a plugin)
-
Hi everyone,
I’m in the process of developing a small plugin that would provide some basic function, like activate custom post if they are needed, or a coming soon page.
I developed an option page in the backoffice with checkboxes, and I am desperatly trying to put condition to do things if these checkboxes are checked or not.Here is my actual code :
/* * 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 !'); } }
I must precise that in the BO, when I check or uncheck my checkboxes, the option is saved.
I tried multiple version of the code above, without any success.
I read a lot of thread and forums without finding any solutions or what is actually wrong in my code ??
The coming soon page function is working like a charm by it’s own (I tested it).The above code is not getting me any error, it just seems to not do anything…
I want to use the same process for my other fields on my option page (but of course activating other functions).Any help would be highly appreciated, thanks ! ??
- The topic ‘If checkbox is checked, do function (Admin Menu Option Page for a plugin)’ is closed to new replies.