diff --git a/admin/class-bread-admin.php b/admin/class-bread-admin.php
index a0bb4c7..908f80d 100644
--- a/admin/class-bread-admin.php
+++ b/admin/class-bread-admin.php
@@ -335,8 +335,8 @@ function pwsix_process_settings_import()
$settings['authors'] = array(wp_get_current_user()->ID);
$this->bread->setOptions($settings);
update_option($this->bread->getOptionsName(), $this->bread->getOptions());
- setcookie('pwsix_action', "import_settings", time() + 10);
setcookie('current-meeting-list', $this->bread->getRequestedSetting(), time() + 10);
+ setcookie('bread_import_file', $import_file, time() + 10);
wp_safe_redirect(admin_url('?page=class-bread-admin.php'));
}
function my_theme_add_editor_styles()
@@ -442,6 +442,9 @@ function admin_options_page()
break;
}
}
+ if (empty($this->bread->getOptions())) {
+ $this->bread->getConfigurationForSettingId($this->bread->getRequestedSetting());
+ }
include_once plugin_dir_path(__FILE__) . 'partials/bread-admin-display.php';
(new Bread_AdminDisplay($this))->admin_options_page();
}
@@ -460,7 +463,8 @@ function pwsix_process_wizard()
}
$settings = json_decode($encode_options, true);
$ncols = substr_count($settings['meeting_template_content'], '
bread->getInitialSetting() ? 1 : ((is_numeric($_POST['wizard_setting_id'])) ? intval($_POST['wizard_setting_id']) : $this->bread->getMaxSetting() + 1);
+ $id = $this->bread->loadAllSettings([]);
+ $id = $this->bread->isInitialSetting() ? 1 : ((is_numeric($_POST['wizard_setting_id'])) ? intval($_POST['wizard_setting_id']) : $this->bread->getMaxSetting() + 1);
$optionsName = $this->bread->generateOptionName($id);
$settings['page_size'] = $layoutInfos[1];
$settings['authors'] = array();
@@ -504,7 +508,6 @@ function pwsix_process_wizard()
$setting_name = $setting_name == '' ? 'Setting ' . $id : $setting_name;
$this->bread->setAndSaveSetting($id, $setting_name);
$this->bread->getConfigurationForSettingId($id);
- $this->bread->setRequestedSetting($id);
ignore_user_abort(true);
ob_clean();
header('Content-Type: application/json; charset=utf-8');
@@ -529,7 +532,6 @@ function pwsix_process_settings_admin()
}
$this->bread->deleteSetting($this->bread->getRequestedSetting());
$this->bread->getConfigurationForSettingId(1);
- $this->bread->setRequestedSetting(1);
} elseif (isset($_POST['duplicate'])) {
if (!$this->current_user_can_create()) {
return;
@@ -544,17 +546,14 @@ function pwsix_process_settings_admin()
}
function process_customize_form()
{
- $this->bread->getConfigurationForSettingId($this->bread->getRequestedSetting());
- if (!isset($_POST['bmltmeetinglistsave'])) {
- $_POST['bmltmeetinglistsave'] = false;
- }
- if (!isset($_POST['bmltmeetinglistpreview'])) {
- $_POST['bmltmeetinglistpreview'] = false;
- }
+ $_POST['bmltmeetinglistsave'] = isset($_POST['bmltmeetinglistsave']);
+ $_POST['bmltmeetinglistpreview'] = isset($_POST['bmltmeetinglistpreview']);
+
if ($_POST['bmltmeetinglistsave'] || $_POST['bmltmeetinglistpreview']) {
if (!wp_verify_nonce($_POST['_wpnonce'], 'bmltmeetinglistupdate-options')) {
die('Whoops! There was a problem with the data you posted. Please go back and try again.');
}
+ $this->bread->getConfigurationForSettingId($this->bread->getRequestedSetting());
$this->bread->setOption('bread_version', sanitize_text_field($_POST['bread_version']));
$this->bread->setOption('front_page_content', wp_kses_post($_POST['front_page_content']));
$this->bread->setOption('front_page_line_height', $_POST['front_page_line_height']);
@@ -691,12 +690,6 @@ function process_customize_form()
wp_redirect(home_url() . "?preview-meeting-list=1");
exit();
}
- } elseif (isset($_REQUEST['pwsix_action']) && $_REQUEST['pwsix_action'] == "import_settings") {
- echo 'Your file was successfully imported! ';
- $num = delete_transient($this->bread->get_TransientKey($this->bread->getRequestedSetting()));
- } elseif (isset($_REQUEST['pwsix_action']) && $_REQUEST['pwsix_action'] == "default_settings_success") {
- echo 'Your default settings were successfully updated! ';
- $num = delete_transient($this->bread->get_TransientKey($this->bread->getRequestedSetting()));
}
}
}
diff --git a/admin/partials/bread-admin-display.php b/admin/partials/bread-admin-display.php
index 0dffe70..39fcb93 100644
--- a/admin/partials/bread-admin-display.php
+++ b/admin/partials/bread-admin-display.php
@@ -90,6 +90,9 @@ function admin_options_page()
set_transient('admin_notice', 'Please put down your weapon. You have 20 seconds to comply.');
if (!$this->admin->current_user_can_modify()) {
echo 'You do not have permission to save this configuation! ';
+ } elseif (isset($_COOKIE['bread_import_file'])) {
+ echo ' File loaded. ';
+ delete_transient($this->bread->get_TransientKey($this->bread->getRequestedSetting()));
} else {
$this->admin->save_admin_options();
echo ' Your changes were successfully saved! ';
@@ -99,7 +102,7 @@ function admin_options_page()
}
}
echo ' ';
-
+
$this->bread->fillUnsetOptions();
?>
diff --git a/includes/class-bread.php b/includes/class-bread.php
index 0f7874c..2031018 100644
--- a/includes/class-bread.php
+++ b/includes/class-bread.php
@@ -59,7 +59,7 @@ class Bread
*
* @var integer
*/
- private int $requested_setting = 1;
+ private int $requested_setting = 0;
private $protocol;
private string $tmp_dir;
/**
@@ -74,7 +74,6 @@ class Bread
* @var array
*/
private array $translate = array();
- private bool $generating_meeting_list = false;
private bool $exporting_meeting_list = false;
/**
* The wizard wants to know if we are generating the first meeting list for this site.
@@ -176,7 +175,7 @@ private static function rrmdir($dir)
@rmdir($dir);
}
}
- private function loadAllSettings($holder): int
+ public function loadAllSettings($holder): int
{
if (isset($holder['bread_preview_settings'])) {
$this->allSettings = array();
@@ -188,6 +187,7 @@ private function loadAllSettings($holder): int
$this->allSettings = array();
$this->allSettings[1] = "Default Setting";
$this->maxSetting = 1;
+ $this->initial_setting = true;
} else {
foreach ($this->allSettings as $key => $value) {
if ($key > $this->maxSetting) {
@@ -241,29 +241,26 @@ private function getCurrentMeetingListHolder(): array
$ret['current-meeting-list'] = $_REQUEST['current-meeting-list'];
} elseif (isset($_REQUEST['export-meeting-list'])) {
$ret['current-meeting-list'] = $_REQUEST['export-meeting-list'];
- $this->exporting_meeting_list = true;
} elseif (isset($_COOKIE['current-meeting-list'])) {
$ret['current-meeting-list'] = $_COOKIE['current-meeting-list'];
}
- $this->generating_meeting_list = !empty($ret) && !is_admin() && !$this->exporting_meeting_list;
return $ret;
}
- /**
- * Undocumented function
- *
- * @return void
- */
public function generatingMeetingList(): bool
{
- return $this->generating_meeting_list;
+ return (isset($_REQUEST['current-meeting-list']) || isset($_REQUEST['preview-meeting-list'])) && !is_admin();
}
public function exportingMeetingList(): bool
{
- return $this->exporting_meeting_list;
+ return isset($_REQUEST['export-meeting-list']) && !is_admin();
}
public function generateOptionName($current_setting)
{
- return Bread::OPTIONS_NAME . '_' . $current_setting;
+ if ($current_setting != 1) {
+ return Bread::OPTIONS_NAME . '_' . $current_setting;
+ } else {
+ return Bread::OPTIONS_NAME;
+ }
}
/**
* Retrieves the plugin options from the database.
@@ -278,11 +275,7 @@ public function &getConfigurationForSettingId($current_setting)
if (is_array($this->allSettings[$current_setting])) {
$this->options = $this->allSettings[$current_setting];
} else {
- if ($current_setting != 1) {
- $this->optionsName = $this->generateOptionName($current_setting);
- } else {
- $this->optionsName = Bread::OPTIONS_NAME;
- }
+ $this->optionsName = $this->generateOptionName($current_setting);
//Don't forget to set up the default options
if (!$theOptions = get_option($this->optionsName)) {
if ($current_setting != 1) {
@@ -290,7 +283,6 @@ public function &getConfigurationForSettingId($current_setting)
update_option(Bread::SETTINGS, $this->allSettings);
die('Undefined setting: ' . $current_setting);
}
- $this->initial_setting = true;
$import_file = plugin_dir_path(__FILE__) . "../admin/templates/30/trifold-landscape-largefont.json";
$encode_options = file_get_contents($import_file);
$theOptions = json_decode($encode_options, true);
@@ -322,12 +314,12 @@ public function setOptionsName($name)
}
public function getRequestedSetting()
{
+ if ($this->requested_setting == 0) {
+ $holder = $this->getCurrentMeetingListHolder();
+ $this->requested_setting = $this->loadAllSettings($holder);
+ }
return $this->requested_setting;
}
- public function setRequestedSetting($id)
- {
- $this->requested_setting = $id;
- }
/**
* Define the core functionality of the plugin.
*
@@ -347,9 +339,6 @@ public function __construct()
$this->plugin_name = 'bread';
$this->tmp_dir = $this->setup_temp_dir();
$this->protocol = (strpos(strtolower(home_url()), "https") !== false ? "https" : "http") . "://";
-
- $holder = $this->getCurrentMeetingListHolder();
- $this->requested_setting = $this->loadAllSettings($holder);
$this->bread_bmlt = new Bread_Bmlt($this);
$this->load_dependencies();
@@ -383,7 +372,7 @@ public function getProtocol()
*
* @return bool true when no setting existed previously, ie, if we should create setting 1.
*/
- public function getInitialSetting()
+ public function isInitialSetting()
{
return $this->initial_setting;
}
@@ -775,7 +764,7 @@ private function renamed_option(string $old, string $new)
*/
public function updateOptions()
{
- update_option(Bread::getOptionsName(), $this->options);
+ update_option($this->getOptionsName(), $this->options);
}
public static function get_TransientKey($setting): string
{
|