* //JavaScript Ajax Request * Duplicator.UI.SaveViewState('dup-pack-archive-panel', 1); * * //Call PHP Code * $view_state = DUP_UI_ViewState::getValue('dup-pack-archive-panel'); * $ui_css_archive = ($view_state == 1) ? 'display:block' : 'display:none'; * */ public function SaveViewState($post) { DUP_Handler::init_error_handler(); check_ajax_referer('DUP_CTRL_UI_SaveViewState', 'nonce'); DUP_Util::hasCapability('export'); $post = $this->postParamMerge($post); $result = new DUP_CTRL_Result($this); try { //CONTROLLER LOGIC $post = stripslashes_deep($_POST); if (!empty($post['states'])) { $view_state = DUP_UI_ViewState::getArray(); foreach ($post['states'] as $state) { $key = sanitize_text_field($state['key']); $value = sanitize_text_field($state['value']); $view_state[$key] = $value; } $success = DUP_UI_ViewState::setArray($view_state); } else { $key = sanitize_text_field($post['key']); $value = sanitize_text_field($post['value']); $success = DUP_UI_ViewState::save($key, $value); } $payload = array(); $payload['key'] = esc_html($key); $payload['value'] = esc_html($value); $payload['update-success'] = $success; //RETURN RESULT $test = ($success) ? DUP_CTRL_Status::SUCCESS : DUP_CTRL_Status::FAILED; return $result->process($payload, $test); } catch (Exception $exc) { $result->processError($exc); } } /** * Returns a JSON list of all saved view state items * * * * See SaveViewState() * */ public function GetViewStateList() { $result = new DUP_CTRL_Result($this); try { //CONTROLLER LOGIC $payload = DUP_UI_ViewState::getArray(); //RETURN RESULT $test = (is_array($payload) && count($payload)) ? DUP_CTRL_Status::SUCCESS : DUP_CTRL_Status::FAILED; return $result->process($payload, $test); } catch (Exception $exc) { $result->processError($exc); } } }