/** * Store Settings page input, call for checking BooXtream connection and BooXtream accounts * @return bool on success or failure */ public function process_admin_options() { if (parent::process_admin_options()) { // make sure we have most recent settings $this->get_settings(); if (0 === strlen($this->contractname) && 0 === strlen($this->contractpassword)) { // @todo: handle error, admin notice? $this->show_notice('woocommerce_settings_saved', 'error', 'No contractname or password given.'); // Ter info: // "Save changes" komt uit wp-content/plugins/woocommerce/includes/admin/views/html-admin-settings.php update_option($this->plugin_id . $this->id . '_accounts', array()); return false; } // succesfully saved, check connection to booxtream $response = $this->connect_booxtream(); // check for response with valid credentials if (!is_array($response)) { switch ($response) { case 401: $this->show_notice('woocommerce_settings_saved', 'error', 'No valid contractname or password given.'); break; default: $this->show_notice('woocommerce_settings_saved', 'error', 'Unable to connect to BooXtream.'); break; } // set connected status to false update_option($this->plugin_id . $this->id . '_connected', '0'); $this->connected = false; $this->accounts = array(); // @todo: besides removing accounts array we also may need to remove saved account? update_option($this->plugin_id . $this->id . '_accounts', array()); $this->init_form_fields(); return false; } // set connected status to true update_option($this->plugin_id . $this->id . '_connected', '1'); $this->connected = true; // try to retrieve and save accounts $this->get_accounts(); $this->init_form_fields(); return true; } return false; }