/**
  * Returns an instance of this class.
  *
  * @since 1.0.0
  * @return WP_Admin_Notices
  */
 public static function getInstance()
 {
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 /**
  * Saves admin options.
  * This is called through a hook
  *
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 2.0.0
  */
 public function saveOptions()
 {
     if (!current_user_can('manage_options')) {
         wp_die('Not allowed');
     }
     erpPaths::requireOnce(erpPaths::$erpMainOpts);
     // Save template options
     if (isset($_POST['dsplLayout'])) {
         erpPaths::requireOnce(erpPaths::$VPluginThemeFactory);
         VPluginThemeFactory::registerThemeInPathRecursive(erpPaths::getAbsPath(erpPaths::$mainThemesFolder), $_POST['dsplLayout']);
         $theme = VPluginThemeFactory::getThemeByName($_POST['dsplLayout']);
         if ($theme) {
             $theme->saveSettings($_POST);
             foreach ($theme->getDefOptions() as $key => $value) {
                 unset($_POST[$key]);
             }
         } else {
             $message = new WP_Error_Notice('Theme ' . $_POST['dsplLayout'] . ' not found. Theme options discarded', 1, array('settings_page_erp_settings'));
             WP_Admin_Notices::getInstance()->addNotice($message);
         }
     }
     // Save the rest of the options
     $mainOptionsObj = new erpMainOpts();
     $mainOptionsObj->saveOptions($_POST);
     $message = new WP_Updated_Notice('Options saved', 1, array('settings_page_erp_settings'));
     WP_Admin_Notices::getInstance()->addNotice($message);
     wp_redirect(add_query_arg(array('page' => $this->plugin_slug . '_settings', 'tab-spec' => wp_strip_all_tags($_POST['tab-spec'])), admin_url('options-general.php')));
     exit;
 }
Example #3
0
<?php

/**
 * Project: wp-admin-notices
 * File: init.php
 * User: Panagiotis Vagenas <*****@*****.**>
 * Date: 1/11/2015
 * Time: 9:07 μμ
 * Since: 2.0.0
 * Copyright: 2015 Panagiotis Vagenas
 */
namespace Pan\Notices;

if (defined('WPINC')) {
    $displayNtcCallback = array(WP_Admin_Notices::getInstance(), 'displayNotices');
    if (!has_action('admin_notices', $displayNtcCallback)) {
        add_action('admin_notices', $displayNtcCallback);
    }
    $dismissNtcCallback = array(WP_Admin_Notices::getInstance(), 'ajaxDismissNotice');
    if (!has_action('admin_notices', $dismissNtcCallback)) {
        add_action('wp_ajax_' . WP_Admin_Notices::KILL_STICKY_NTC_AJAX_ACTION, $dismissNtcCallback);
    }
}
 /**
  * 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 2.0.0
  * @author Panagiotis Vagenas <*****@*****.**>
  */
 public function update($new_instance, $old_instance)
 {
     /* #? Verify nonce */
     if (!isset($_POST['erp_meta_box_nonce']) || !wp_verify_nonce($_POST['erp_meta_box_nonce'], 'erp_meta_box_nonce')) {
         return;
     }
     erpPaths::requireOnce(erpPaths::$erpWidOpts);
     // get an instance to validate options
     $widOpts = new erpWidOpts($old_instance);
     // validate wid options
     $widOptsValidated = $widOpts->saveOptions($new_instance, $old_instance);
     // validate template options
     if (isset($new_instance['dsplLayout'])) {
         erpPaths::requireOnce(erpPaths::$VPluginThemeFactory);
         VPluginThemeFactory::registerThemeInPathRecursive(erpPaths::getAbsPath(erpPaths::$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 {
             $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;
 }
 /**
  * Fired for each blog when the plugin is activated.
  *
  * @since 2.0.0
  */
 private static function single_activate()
 {
     erpPaths::requireOnce(erpPaths::$erpActivator);
     $compareVersions = erpDefaults::compareVersion(get_option(erpDefaults::versionNumOptName));
     if ($compareVersions < 0) {
         // New install
         /**
          * If an old version is present translate options
          */
         if (get_option('erpVersion')) {
             $mainOpts = self::migrateMainOptions();
             $notice = new WP_Updated_Notice('<strong>Easy Related Posts updated from V1 to V2.</strong>' . 'You should review the main plugin and widget settings.<br>' . 'There are some major changes in this version and this affects options as well. ' . 'We are  sorry for the inconvenience but this was necessary to move this plugin forward');
             WP_Admin_Notices::getInstance()->addNotice($notice);
             // Delete old options
             delete_option('erpVersion');
             delete_option('erpSubVersion');
             delete_option('erpOpts');
         } else {
             $mainOpts = erpDefaults::$comOpts + erpDefaults::$mainOpts;
         }
         erpActivator::addNonExistingMainOptions($mainOpts, EPR_MAIN_OPTIONS_ARRAY_NAME);
         erpActivator::addNonExistingWidgetOptions(erpDefaults::$comOpts + erpDefaults::$mainOpts, 'widget_' . erpDefaults::erpWidgetOptionsArrayName);
         erpDefaults::updateVersionNumbers();
     } elseif ($compareVersions === 0) {
         // Major update
         erpDefaults::updateVersionNumbers();
     } elseif ($compareVersions === 1) {
         // Release update
         erpDefaults::updateVersionNumbers();
     } elseif ($compareVersions === 2) {
         // Minor update
         erpDefaults::updateVersionNumbers();
     }
 }