diff --git a/includes/Settings.php b/includes/Settings.php index 484a52e5..2ab72008 100644 --- a/includes/Settings.php +++ b/includes/Settings.php @@ -13,6 +13,11 @@ class Settings protected $settings; public function __construct() + { + add_action('rrze_wp_settings_after_update_option', [$this, 'flushRewriteRules']); + } + + public function loaded() { $this->settings = new OptionsSettings(__('Calendar Settings', 'rrze-calendar'), 'rrze-calendar'); @@ -59,12 +64,19 @@ public function __construct() $this->settings->build(); } + public function flushRewriteRules($optionName) + { + if ($optionName === self::OPTION_NAME) { + flush_rewrite_rules(false); + } + } + public function validateEndpointSlug($value) { - if ($validation = strlen(sanitize_title($value)) > 4) { - flush_rewrite_rules(); + if (mb_strlen(sanitize_title($value)) < 4) { + return false; } - return $validation; + return true; } public function getOption($option)