예제 #1
0
 /**
  * Activate plugin
  *
  * @access public
  * @return void
  */
 public function activate()
 {
     global $wpdb;
     require CX_PATH . '/core/fn.upgrade.php';
     // Get license key
     $license = !empty($this->opts['license_key']) ? $this->opts['license_key'] : null;
     // Upgrade plugin
     cx_upgrade($license);
     // Update operator role
     cx_update_op_role('editor');
     /**
      * Administration role
      */
     $admin_role = get_role('administrator');
     $admin_role->add_cap('answer_visitors');
     /**
      * Chat Operator role
      */
     $op_role = get_role('cx_op');
     $op_role->add_cap('answer_visitors');
 }
예제 #2
0
 /**
  * Action to save/reset options
  */
 function manage_options()
 {
     // Check this is settings page
     if (!$this->is_settings() or empty($_REQUEST['action'])) {
         return;
     }
     // ACTION: RESET
     if ($_GET['action'] == 'reset') {
         // Remove lc
         delete_option('cx_c9f1a6384b1c466d4612f513bd8e13ea');
         delete_option('cx_error');
         // Prepare variables
         $new_options = array();
         // Prepare data
         foreach ($this->options as $value) {
             @($new_options[$value['id']] = $value['std']);
         }
         // Save new options
         if (update_option($this->option, $new_options)) {
             // Redirect
             wp_redirect($this->admin_url . '&message=1');
             exit;
         } else {
             // Redirect
             wp_redirect($this->admin_url . '&message=2');
             exit;
         }
     } elseif ($_POST['action'] == 'save') {
         // Prepare vars
         $new_options = array();
         // Prepare data
         foreach ($this->options as $value) {
             // Check api
             if ($value['id'] == 'license_key') {
                 cx_api($_POST[$value['id']], true);
             }
             // Update operator default role
             if ($value['id'] == 'op_role') {
                 cx_update_op_role($_POST[$value['id']]);
             }
             // Update operator additional role
             if ($value['id'] == 'op_add_role') {
                 cx_update_op_role($_POST[$value['id']], true);
             }
             if (is_array($_POST[$value['id']])) {
                 $new_options[$value['id']] = $_POST[$value['id']];
             } else {
                 $str = $_POST[$value['id']];
                 // Sanitize option
                 switch ($value['type']) {
                     case 'textarea':
                         if (!empty($value['html'])) {
                             $str = str_replace("\n", '<br/>', $str);
                         }
                         break;
                 }
                 $new_options[$value['id']] = $str;
             }
         }
         // Save new options
         if (update_option($this->option, $new_options)) {
             // Redirect
             wp_redirect($this->admin_url . '&message=3');
             exit;
         } else {
             // Redirect
             wp_redirect($this->admin_url . '&message=4');
             exit;
         }
     }
 }