/**
  * Update the role settings.
  *
  * @access private
  * @since 0.7.5
  * @uses current_user_can()
  * @uses check_admin_referer()
  * @uses wp_redirect()
  * @uses get_admin_url()
  * @uses get_current_blog_id()
  * @return void
  */
 public static function updateRoleCapabilities()
 {
     /** @var $wp_roles WP_Roles */
     global $wp_roles;
     $form = new cnFormObjects();
     /*
      * Check whether user can edit roles
      */
     if (current_user_can('connections_change_roles')) {
         check_admin_referer($form->getNonce('update_role_settings'), '_cn_wpnonce');
         if (isset($_POST['roles'])) {
             // Cycle thru each role available because checkboxes do not report a value when not checked.
             foreach ($wp_roles->get_names() as $role => $name) {
                 if (!isset($_POST['roles'][$role])) {
                     continue;
                 }
                 foreach ($_POST['roles'][$role]['capabilities'] as $capability => $grant) {
                     // the administrator should always have all capabilities
                     if ($role == 'administrator') {
                         continue;
                     }
                     if ($grant == 'true') {
                         cnRole::add(esc_attr($role), esc_attr($capability));
                     } else {
                         cnRole::remove(esc_attr($role), esc_attr($capability));
                     }
                 }
             }
         }
         if (isset($_POST['reset'])) {
             cnRole::reset(array_map('esc_attr', $_POST['reset']));
         }
         if (isset($_POST['reset_all'])) {
             cnRole::reset();
         }
         cnMessage::set('success', 'role_settings_updated');
         wp_redirect(get_admin_url(get_current_blog_id(), 'admin.php?page=connections_roles'));
         exit;
     } else {
         cnMessage::set('error', 'capability_roles');
     }
 }
 /**
  * During activation this will initiate the options.
  */
 private function initOptions()
 {
     $version = $this->options->getVersion();
     switch (TRUE) {
         /** @noinspection PhpMissingBreakStatementInspection */
         case version_compare($version, '0.7.3', '<'):
             /*
              * Retrieve the settings stored prior to 0.7.3 and migrate them
              * so they will be accessible in the structure supported by the
              * Connections WordPress Settings API Wrapper Class.
              */
             if (FALSE !== get_option('connections_options')) {
                 $options = get_option('connections_options');
                 if (FALSE === get_option('connections_login')) {
                     update_option('connections_login', array('required' => $options['settings']['allow_public'], 'message' => 'Please login to view the directory.'));
                 }
                 if (FALSE === get_option('connections_visibility')) {
                     update_option('connections_visibility', array('allow_public_override' => $options['settings']['allow_public_override'], 'allow_private_override' => $options['settings']['allow_private_override']));
                 }
                 if (FALSE === get_option('connections_image_thumbnail')) {
                     update_option('connections_image_thumbnail', array('quality' => $options['settings']['image']['thumbnail']['quality'], 'width' => $options['settings']['image']['thumbnail']['x'], 'height' => $options['settings']['image']['thumbnail']['y'], 'ratio' => $options['settings']['image']['thumbnail']['crop']));
                 }
                 if (FALSE === get_option('connections_image_medium')) {
                     update_option('connections_image_medium', array('quality' => $options['settings']['image']['entry']['quality'], 'width' => $options['settings']['image']['entry']['x'], 'height' => $options['settings']['image']['entry']['y'], 'ratio' => $options['settings']['image']['entry']['crop']));
                 }
                 if (FALSE === get_option('connections_image_large')) {
                     update_option('connections_image_large', array('quality' => $options['settings']['image']['profile']['quality'], 'width' => $options['settings']['image']['profile']['x'], 'height' => $options['settings']['image']['profile']['y'], 'ratio' => $options['settings']['image']['profile']['crop']));
                 }
                 if (FALSE === get_option('connections_image_logo')) {
                     update_option('connections_image_logo', array('quality' => $options['settings']['image']['logo']['quality'], 'width' => $options['settings']['image']['logo']['x'], 'height' => $options['settings']['image']['logo']['y'], 'ratio' => $options['settings']['image']['logo']['crop']));
                 }
                 if (FALSE === get_option('connections_compatibility')) {
                     update_option('connections_compatibility', array('google_maps_api' => $options['settings']['advanced']['load_google_maps_api'], 'javascript_footer' => $options['settings']['advanced']['load_javascript_footer']));
                 }
                 if (FALSE === get_option('connections_debug')) {
                     update_option('connections_debug', array('debug_messages' => $options['debug']));
                 }
                 unset($options);
             }
             /** @noinspection PhpMissingBreakStatementInspection */
         /** @noinspection PhpMissingBreakStatementInspection */
         case version_compare($version, '0.7.4', '<'):
             /*
              * The option to disable keyword search was added in version 0.7.4. Set this option to be enabled by default.
              */
             $options = get_option('connections_search');
             $options['keyword_enabled'] = 1;
             update_option('connections_search', $options);
             unset($options);
             /** @noinspection PhpMissingBreakStatementInspection */
         /** @noinspection PhpMissingBreakStatementInspection */
         case version_compare($version, '0.8', '<'):
             /*
              * The option to disable keyword search was added in version 0.7.4. Set this option to be enabled by default.
              */
             $options = get_option('connections_compatibility');
             $options['css'] = 1;
             update_option('connections_compatibility', $options);
             unset($options);
             $options = get_option('connections_display_results');
             $options['search_message'] = 1;
             update_option('connections_display_results', $options);
             unset($options);
     }
     if (NULL === $this->options->getDefaultTemplatesSet()) {
         $this->options->setDefaultTemplates();
     }
     // Class used for managing role capabilities.
     if (!class_exists('cnRole')) {
         require_once CN_PATH . 'includes/admin/class.capabilities.php';
     }
     if (TRUE != $this->options->getCapabilitiesSet()) {
         cnRole::reset();
         $this->options->defaultCapabilitiesSet(TRUE);
     }
     // Increment the version number.
     $this->options->setVersion(CN_CURRENT_VERSION);
     // Save the options
     $this->options->saveOptions();
     /*
      * This option is added for a check that will force a flush_rewrite() in connectionsLoad::adminInit() once.
      * Should save the user from having to "save" the permalink settings.
      */
     update_option('connections_flush_rewrite', '1');
 }