Skip to content

Instantly share code, notes, and snippets.

@imranrbx
Last active November 21, 2019 12:45
Show Gist options
  • Save imranrbx/494ba0951793e39b2a991fcd1e9ab610 to your computer and use it in GitHub Desktop.
Save imranrbx/494ba0951793e39b2a991fcd1e9ab610 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Pwspk Plugin
* Description: Description
* Plugin URI: http...
* Author: Author
* Author URI: http...
* Version: 1.0
* License: GPL2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: Text Domain
* Domain Path: Domain Path
* Network: false
*/
defined( 'ABSPATH' ) || exit;
register_activation_hook( __FILe__, 'register_option_func' );
function register_option_func(){
$tmp = get_option( 'section_settings' );
if(!$tmp){
$arr = array();
}
update_option( 'section_settings' , $arr);
}
add_action("admin_init", "demo_settings_page");
add_action('admin_menu' , 'qrc_admin_menu');
function qrc_admin_menu(){
add_menu_page( 'Check box setting', 'CheckBox Settings', 'manage_options', 'qr_composer', 'qrc_option_func');
$post_types = get_post_types();
$options = get_option( 'section_settings' );
if($options):
foreach($options as $option){
if(strtolower($option) == 'post'){
remove_menu_page('edit.php');
}else{
remove_menu_page('edit.php?post_type='.$option);
}
}
endif;
}
function demo_settings_page()
{
register_setting("section_settings", "section_settings" ,'validate_section_text_field');
add_settings_section("section_setting", "Settings Section", null, __FILE__);
add_settings_field("demo-checkbox", "Hide Post type", "demo_checkbox_display", __FILE__, "section_setting");
}
function demo_checkbox_display()
{
$post_types = get_post_types();
foreach ($post_types as $post_type) {
$options = get_option( 'section_settings' );
$checked = isset($options[$post_type]) ? 'checked' : '';
?>
<input type="checkbox" value="<?php echo $post_type; ?>" name="<?php echo "section_settings[{$post_type}]"; ?>" <?php echo ($checked); ?>>
<label><?php echo $post_type; ?></label></br>
<?php
}
}
function qrc_option_func()
{
?>
<div class="wrap">
<h1>Checkbox Settings</h1>
<form method="post" action="options.php">
<?php
settings_fields("section_settings");
do_settings_sections(__FILE__);
submit_button();
?>
</form>
</div>
<?php
}
@sharabindu
Copy link

Great! Its, really awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment