Exemple #1
0
 /**
  * Initialize options of this plugin with default value.
  *
  * @param $forceDefault
  *
  * @return $this;
  */
 public function initialize($forceDefault = false)
 {
     //Set default value in options bag
     foreach ($this->settings as $id => &$params) {
         if (true === $forceDefault && isset($params['std'])) {
             //by pass fields without default value
             $this->options[$id] = $params['std'];
         } elseif (isset($params['originalKey'])) {
             //Option defined in old format, convert it to new format
             $originalKey = $params['originalKey'];
             if (!isset($this->options[$id]) && isset($this->options[$originalKey])) {
                 $this->options[$id] = $this->options[$originalKey];
                 unset($this->options[$originalKey]);
             }
         }
     }
     //Save option bag in wordpress
     $this->options->save();
     return $this;
 }
Exemple #2
0
 /**
  * Method to generate HTML form'elements to manage setting in the configuratio panel
  * of this plugin.
  *
  * @param array $setting
  */
 public function displaySettings($setting = array())
 {
     if (\is_admin()) {
         $id = null;
         if (isset($setting['id'])) {
             $id = $setting['id'];
         }
         $class = null;
         if (isset($setting['class'])) {
             $class = ' ' . $setting['class'];
         }
         $type = null;
         if (isset($setting['type'])) {
             $type = $setting['type'];
         }
         $std = null;
         if (isset($setting['std'])) {
             $std = $setting['std'];
         }
         $desc = null;
         if (isset($setting['desc'])) {
             $desc = $setting['desc'];
         }
         $choices = array();
         if (isset($setting['choices'])) {
             $choices = $setting['choices'];
         }
         $options = $this->options->toArray();
         if (!isset($options[$id]) && 'checkbox' != $type) {
             $options[$id] = $std;
         } elseif (!isset($options[$id])) {
             $options[$id] = 0;
         }
         if (is_readable(SELLSY_WP_PATH_INC . '/admin-setting.php')) {
             include SELLSY_WP_PATH_INC . '/admin-setting.php';
         }
     }
 }