/** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance * Values just sent to be saved. * @param array $old_instance * Previously saved values from database. * @return array Updated safe values to be saved. * @since 1.0.0 * @author Panagiotis Vagenas <*****@*****.**> */ public function update($new_instance, $old_instance) { /* #? Verify nonce */ if (!isset($_POST['erpPRO_meta_box_nonce']) || !wp_verify_nonce($_POST['erpPRO_meta_box_nonce'], 'erpPRO_meta_box_nonce')) { return; } erpPROPaths::requireOnce(erpPROPaths::$erpPROWidOpts); // get an instance to validate options $widOpts = new erpPROWidOpts($old_instance); // validate wid options $widOptsValidated = $widOpts->saveOptions($new_instance, $old_instance); // validate template options if (isset($new_instance['dsplLayout'])) { erpPROPaths::requireOnce(erpPROPaths::$VPluginThemeFactory); VPluginThemeFactory::registerThemeInPathRecursive(erpPROPaths::getAbsPath(erpPROPaths::$widgetThemesFolder), $new_instance['dsplLayout']); $theme = VPluginThemeFactory::getThemeByName($new_instance['dsplLayout']); if ($theme) { $themeValidated = $theme->saveSettings($new_instance); foreach ($theme->getDefOptions() as $key => $value) { unset($new_instance[$key]); } } else { // TODO Set notices class // $message = new WP_Error_Notice('Theme ' . $new_instance ['dsplLayout'] . ' not found. Theme options discarded'); // WP_Admin_Notices::getInstance()->addNotice($message); } } // save updated options return $widOptsValidated + $themeValidated; }
private static function delWidOptions() { erpPROPaths::requireOnce(erpPROPaths::$erpPROWidOpts); $wOpts = new erpPROWidOpts(); delete_option($wOpts->getOptionsArrayName()); }