Пример #1
0
 /**
  * Hook building custom options in Permalink settings page.
  *
  * @uses register_setting()
  * @uses add_settings_field()
  *
  * @since 3.2.4
  */
 public function hookFieldsPermalink()
 {
     if (empty($this->posttypes)) {
         return false;
     }
     //Add section
     add_settings_section('tea-to-permalinks', TeaThemeOptions::__('Custom Permalinks'), array(&$this, 'hookPermalinkTitle'), 'permalink');
     //Flush all rewrite rules
     if (isset($_POST['tea-to-flushpermalink'])) {
         flush_rewrite_rules();
     }
     //Iterate on each cpt
     foreach ($this->posttypes as $pt) {
         //Special case: do not change post/page component
         if (in_array($pt['slug'], array('post', 'page'))) {
             continue;
         }
         //Option
         $opt = str_replace('%SLUG%', $pt['slug'], Engine::getPermalink());
         //Check POST
         if (isset($_POST[$opt])) {
             $value = $_POST[$opt];
             TeaThemeOptions::setOption($opt, $value);
         } else {
             $value = TeaThemeOptions::getOption($opt, '/%' . $pt['slug'] . '%-%post_id%');
         }
         //Define metabox title
         $title = $pt['labels']['name'] . ' <code>%' . $pt['slug'] . '%</code>';
         //Add fields
         add_settings_field($opt, $title, array(&$this, 'hookPermalinkSet'), 'permalink', 'tea-to-permalinks', array('name' => $opt, 'value' => $value));
     }
     return true;
 }
Пример #2
0
 /**
  * Register $_POST and $_FILES into transients.
  *
  * @uses wp_handle_upload()
  * @param array $request Contains all data in $_REQUEST
  * @param array $files Contains all data in $_FILES
  *
  * @since 3.3.0
  */
 protected function updateSettings($request, $files)
 {
     //Admin panel
     if (!TTO_IS_ADMIN) {
         return;
     }
     //Check request
     if (empty($request)) {
         return;
     }
     //Set all options
     foreach ($request as $k => $v) {
         //Don't register this default value
         if (in_array($k, array('do', 'from', 'updated', 'submit'))) {
             continue;
         }
         //Check the key for special "NONE" value
         $v = 'NONE' == $v || empty($v) ? '' : $v;
         //Check settings
         if (preg_match('/^tto-configs-/', $k)) {
             $k = str_replace('tto-configs-', '', $k);
             TeaThemeOptions::setConfigs($k, $v);
         } else {
             /**
              * Fires for each data saved in DB.
              *
              * @param string $k Option's name
              * @param string $v Option's value
              *
              * @since 3.3.0
              */
             do_action('tto_action_update_settings', $k, $v);
             //Register option
             TeaThemeOptions::setOption($k, $v);
         }
     }
     //Check if files are attempting to be uploaded
     if (!empty($files)) {
         //Get required files
         require_once ABSPATH . 'wp-admin/includes/image.php';
         require_once ABSPATH . 'wp-admin/includes/file.php';
         require_once ABSPATH . 'wp-admin/includes/media.php';
         //Set all URL in transient
         foreach ($files as $k => $v) {
             //Don't do nothing if no file is defined
             if (empty($v['tmp_name'])) {
                 continue;
             }
             //Do the magic
             $file = wp_handle_upload($v, array('test_form' => false));
             //Register option and transient
             TeaThemeOptions::setOption($k, $file['url']);
         }
     }
     //Notify
     TeaThemeOptions::notify('updated', TeaThemeOptions::__('The Tea Theme Options is updated.'));
 }