private function handle_form_submission($post, $action = '') { if ($action == 'save_menu') { //Save the admin menu configuration. if (isset($post['data'])) { check_admin_referer('menu-editor-form'); //Try to decode a menu tree encoded as JSON $url = remove_query_arg(array('noheader')); try { $menu = ameMenu::load_json($post['data'], true); } catch (InvalidMenuException $ex) { $debugData = ''; $debugData .= "Exception:\n" . $ex->getMessage() . "\n\n"; $debugData .= "Used POST data:\n" . print_r($this->post, true) . "\n\n"; $debugData .= "Original POST:\n" . print_r($this->originalPost, true) . "\n\n"; $debugData .= "\$_POST global:\n" . print_r($_POST, true); $debugData = sprintf("<textarea rows=\"30\" cols=\"100\">%s</textarea>", htmlentities($debugData)); wp_die("Error: Failed to decode menu data!<br><br>\n" . "Please send this debugging information to the developer: <br>" . $debugData); return; } //Sanitize menu item properties. $menu['tree'] = ameMenu::sanitize($menu['tree']); //Save the custom menu $this->set_custom_menu($menu); //Redirect back to the editor and display the success message. //Also, automatically select the last selected actor (convenience feature). $query = array('message' => 1); if (isset($post['selected_actor']) && !empty($post['selected_actor'])) { $query['selected_actor'] = rawurlencode(strval($post['selected_actor'])); } wp_redirect(add_query_arg($query, $url)); die; } else { $message = "Failed to save the menu. "; if (isset($this->post['data_length']) && is_numeric($this->post['data_length'])) { $message .= sprintf('Expected to receive %d bytes of menu data in $_POST[\'data\'], but got nothing.', intval($this->post['data_length'])); } wp_die($message); } } else { if ($action == 'save_settings') { //Save overall plugin configuration (permissions, etc). check_admin_referer('save_settings'); //Plugin access setting. $valid_access_settings = array('super_admin', 'manage_options'); //On Multisite only Super Admins can choose the "Only the current user" option. if (!is_multisite() || is_super_admin()) { $valid_access_settings[] = 'specific_user'; } if (isset($this->post['plugin_access']) && in_array($this->post['plugin_access'], $valid_access_settings)) { $this->options['plugin_access'] = $this->post['plugin_access']; if ($this->options['plugin_access'] === 'specific_user') { $this->options['allowed_user_id'] = get_current_user_id(); } else { $this->options['allowed_user_id'] = null; } } //Whether to hide the plugin on the "Plugins" admin page. if (!is_multisite() || is_super_admin()) { if (!empty($this->post['hide_plugin_from_others'])) { $this->options['plugins_page_allowed_user_id'] = get_current_user_id(); } else { $this->options['plugins_page_allowed_user_id'] = null; } } //Configuration scope. The Super Admin is the only one who can change it since it affects all sites. if (is_multisite() && is_super_admin()) { $valid_scopes = array('global', 'site'); if (isset($this->post['menu_config_scope']) && in_array($this->post['menu_config_scope'], $valid_scopes)) { $this->options['menu_config_scope'] = $this->post['menu_config_scope']; } } //Security logging. $this->options['security_logging_enabled'] = !empty($this->post['security_logging_enabled']); //Hide some menu options by default. $this->options['hide_advanced_settings'] = !empty($this->post['hide_advanced_settings']); //Enable the now-obsolete "Hide" button. if ($this->is_pro_version()) { $this->options['show_deprecated_hide_button'] = !empty($this->post['show_deprecated_hide_button']); } //Menu editor colour scheme. if (!empty($this->post['ui_colour_scheme'])) { $valid_colour_schemes = array('classic', 'wp-grey'); $scheme = strval($this->post['ui_colour_scheme']); if (in_array($scheme, $valid_colour_schemes)) { $this->options['ui_colour_scheme'] = $scheme; } } //Enable submenu icons. if (!empty($this->post['submenu_icons_enabled'])) { $submenu_icons_enabled = strval($this->post['submenu_icons_enabled']); $valid_icon_settings = array('never', 'if_custom', 'always'); if (in_array($submenu_icons_enabled, $valid_icon_settings, true)) { $this->options['submenu_icons_enabled'] = $submenu_icons_enabled; } } $this->save_options(); wp_redirect(add_query_arg('updated', 1, $this->get_settings_page_url())); } } }