title: Assign a user role capability through a CheckBox
body: <p>I am creating a mini plugin on user role capability. I am trying to assign capability through a <code>CheckBox</code> for that I have saved custom capability in the <code>wp_option</code> table, but I am facing a problem:<br>
  How can I fetch this custom capability from the <code>wp_option</code> table and assign it to role with <code>CheckBox</code>. </p>
  
  <p><strong>Here is my PHP code:</strong>  </p>
  
  <pre><code>&lt;?php
      /*
       Plugin Name: Custom Role
       Plugin URI: www.customroleandcapability.com
       Description: A custom role plugin
       Version: 1.0.0
       Author: jai
       Author URI:  www.customroleandcapability.com
      */    
       register_activation_hook(__FILE__,'activation');
        function activation(){
          add_role('teacher', __('Teacher'),
          array( ));
      }
  
      add_action('admin_menu', 'my_menu_pages');
      function my_menu_pages(){
  
          add_menu_page('Custom Role', 'Custom Role', 'manage_options', 'my_menu', 'my_menu_output' );   
      }
  
      function my_menu_output(  ) {
  
        global $wp_roles;
  
        if(isset($_POST['submit'])){
            unset($_POST['submit']);
  
            echo "&lt;pre&gt;"; 
            print_r($_POST); 
            echo "&lt;/pre&gt;";
  
          $args = array('Administrator_read_posts','Administrator_edit_posts','Administrator_delete_posts','Editor_read_posts', 'Editor_edit_posts','Editor_delete_posts','Author_read_posts','Author_edit_posts','Author_delete_posts',                 'Subscriber_read_posts','Subscriber_edit_posts','Subscriber_delete_posts','Administrator_read_pages',                    'Administrator_edit_pages','Administrator_delete_pages','Editor_read_pages','Editor_edit_pages','Editor_delete_pages',   'Author_read_pages','Author_edit_pages','Author_delete_pages','Subscriber_read_pages','Subscriber_edit_pages',           'Subscriber_delete_pages','Administrator_read_media','Administrator_edit_media','Administrator_delete_media',            'Editor_read_media','Editor_edit_media','Editor_delete_media','Author_read_media','Author_edit_media',                   'Author_delete_media','Subscriber_read_media','Subscriber_edit_media','Subscriber_delete_media','Contributor_read_posts',
            'Contributor_edit_posts','Contributor_delete_posts','Contributor_read_pages','Contributor_edit_pages',                   'Contributor_delete_pages','Contributor_read_media','Contributor_edit_media','Contributor_delete_media','Teacher_read_posts','Teacher_edit_posts','Teacher_delete_posts','Teacher_read_pages','Teacher_edit_pages','Teacher_delete_pages','Teacher_read_media','Teacher_edit_media','Teacher_delete_media');
  
  
  
              foreach($args as $key =&gt; $val){
  
                  if(!empty($_POST[$val]) &amp;&amp; ($_POST[$val] == 1)){
                      update_site_option( $val, $_POST[$val] );
                  }else{
                      update_site_option( $val, '0' );
                      }      
                  }
                      echo get_site_option('read_posts'); 
  
  
  
                    $current_user = wp_get_current_user();
                    $user_id = $current_user-&gt;ID;
                    echo 'User ID: ' . $user_id . '&lt;br /&gt;';
                    if ( 0 == $current_user-&gt;ID) {
                        echo "Not logged in";
                    } else {
                        echo "Logged in";
                    }
  
                }       
            ?&gt;
  </code></pre>
  
  <p><strong>Here is the HTML code:</strong>  </p>
  
  <pre><code>  &lt;div class="wrap" &gt;
       &lt;h1&gt;Edit Role &lt;a class="page-title-action" href="my_menu.php"&gt;Add New &lt;/a&gt;&lt;/h1&gt;
         &lt;form name="simple_form" method="post" action="admin.php?page=my_menu" enctype="multipart/form-data" &gt;
          &lt;table class="wp-list-table widefat fixed "&gt;
           &lt;thead&gt;
             &lt;tr&gt;  
             &lt;th class="column-cap"&gt;Capability&lt;/th&gt;
             &lt;?php foreach ( $wp_roles-&gt;roles as $key=&gt;$value ): ?&gt;
             &lt;th&gt;&lt;a href=" " &gt;&lt;?php echo $value['name'];  ?&gt;&lt;/a&gt;&lt;/th&gt;
            &lt;?php endforeach; ?&gt;
           &lt;/tr&gt;
          &lt;/thead&gt;  
       &lt;h1 id="menu_setting" class="handle"&gt;User Role &amp; Capabilities&lt;/h1&gt;&lt;br&gt;
      &lt;table class=" wp-list-table widefat fixed"&gt;
    &lt;thead style="background-color:white;"&gt;
    &lt;tr&gt;
  
    &lt;td&gt;
      &lt;a&gt;&lt;i class="dashicons dashicons-admin-post"&gt;&lt;/i&gt;  
        &lt;span class="label"&gt;Posts&lt;/span&gt;&lt;/a&gt;
         &lt;/td&gt;
           &lt;?php foreach ( $wp_roles-&gt;roles as $key=&gt;$value ): ?&gt;     
            &lt;td&gt; 
             &lt;input id="CheckboxId" name="&lt;?php echo $value['name'];  ?&gt;_read_posts" type="checkbox" value="1"
             &lt;?php if(get_site_option($key.'_'.'read_posts')=="1"){echo "checked='checked'";} ?&gt; /&gt;read&lt;br&gt;
  
             &lt;input id="CheckboxId" name="&lt;?php echo $value['name'];  ?&gt;_edit_posts" type="checkbox" value="1"
             &lt;?php if(get_site_option($key.'_'.'edit_posts')=="1"){ echo "checked='checked'";} ?&gt; /&gt;edit&lt;br&gt;
  
            &lt;input id="CheckboxId" name="&lt;?php echo $value['name'];  ?&gt;_delete_posts" type="checkbox" value="1"
          &lt;?php if(get_site_option($key.'_'.'delete_posts')=="1"){echo "checked='checked'";} ?&gt;  /&gt;delete
        &lt;/td&gt;
      &lt;?php endforeach; ?&gt;
       &lt;/tr&gt;  
  
    &lt;tr&gt;
      &lt;td&gt;
        &lt;a&gt;&lt;i class="dashicons dashicons-admin-page"&gt;&lt;/i&gt;
         &lt;span class="label"&gt;Pages&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;?php foreach ( $wp_roles-&gt;roles as $key=&gt;$value ): ?&gt;
           &lt;td&gt;
            &lt;input id="CheckboxId" name="&lt;?php echo $value['name'];  ?&gt;_read_pages" type="checkbox" value="1"
             &lt;?php if(get_site_option($key.'_'.'read_pages')=="1"){echo "checked";} ?&gt; /&gt;read &lt;br&gt;
  
             &lt;input id="CheckboxId" name="&lt;?php echo $value['name'];  ?&gt;_edit_pages" type="checkbox" value="1"
             &lt;?php if(get_site_option($key.'_'.'edit_pages')=="1"){echo "checked";} ?&gt; /&gt;edit&lt;br&gt;
  
            &lt;input id="CheckboxId" name="&lt;?php echo $value['name'];  ?&gt;_delete_pages" type="checkbox" value="1"
          &lt;?php if(get_site_option($key.'_'.'delete_pages')=="1"){echo "checked";} ?&gt; &gt;delete
         &lt;/td&gt;  
       &lt;?php endforeach; ?&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td&gt;
        &lt;a&gt;&lt;i class="dashicons dashicons-admin-media"&gt;&lt;/i&gt;
          &lt;span class="label"&gt;Media&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
            &lt;?php foreach ( $wp_roles-&gt;roles as $key=&gt;$value ): ?&gt; 
              &lt;td&gt;
                &lt;input id="CheckboxId" name="&lt;?php echo $value['name'];  ?&gt;_read_media" type="checkbox" value="1"
                &lt;?php if(get_site_option($key.'_'.'read_media')=="1"){echo "checked";} ?&gt; /&gt;read &lt;br&gt;
  
                &lt;input id="CheckboxId" name="&lt;?php echo $value['name'];  ?&gt;_edit_media" type="checkbox" value="1"
                &lt;?php if(get_site_option($key.'_'.'edit_media')=="1"){echo "checked";} ?&gt; /&gt;edit&lt;br&gt;
  
                &lt;input id="CheckboxId" name="&lt;?php echo $value['name'];  ?&gt;_delete_media" type="checkbox" value="1"
                &lt;?php if(get_site_option($key.'_'.'delete_media')=="1"){echo "checked";} ?&gt; &gt;delete      
              &lt;/td&gt;
            &lt;?php endforeach; ?&gt;  
         &lt;/tr&gt;
  
        &lt;/table&gt;
          &lt;br&gt;
            &lt;input class="button button-primary" type="submit" id="submit" name="submit" value="Submit"&gt;
              &lt;/thead&gt;
              &lt;/table&gt;
            &lt;/form&gt;      
         &lt;script&gt; 
       &lt;/script&gt;
     &lt;?php } 
  </code></pre>