コード例 #1
0
 public function save($post_id)
 {
     if (!SB_Core::verify_nonce('sb_meta_box', 'sb_meta_box_nonce') || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || !current_user_can('edit_post', $post_id)) {
         return $post_id;
     }
     foreach ($this->fields as $field) {
         $type = isset($field['type']) ? $field['type'] : '';
         $name = isset($field['name']) ? $field['name'] : '';
         if (empty($name)) {
             continue;
         }
         if ('checkbox' == $type) {
             $value = isset($_POST[$name]) ? 1 : 0;
         } elseif ('datetime' == $type) {
             $value = isset($_POST[$name]) ? SB_PHP::string_to_datetime($_POST[$name], 'Y-m-d') : '';
             if (!empty($value)) {
                 $value = strtotime($value);
             }
         } else {
             $value = isset($_POST[$name]) ? $_POST[$name] : '';
         }
         $meta_value = SB_Core::sanitize($value, $type);
         SB_Post::update_meta($post_id, $name, $meta_value);
     }
     return $post_id;
 }
コード例 #2
0
 public function save($term_id)
 {
     if (!SB_Core::verify_nonce('sb_term_meta', 'sb_term_meta_nonce')) {
         return $term_id;
     }
     $taxonomy = isset($_POST['taxonomy']) ? $_POST['taxonomy'] : '';
     $sb_term_metas = SB_Option::get_term_metas();
     foreach ($this->fields as $field) {
         $name = isset($field['name']) ? $field['name'] : '';
         $value = isset($_POST[$name]) ? $_POST[$name] : '';
         $sb_term_metas[$term_id][$name] = $value;
         $sb_term_metas[$term_id]['taxonomy'] = $taxonomy;
     }
     SB_Option::update_term_metas($sb_term_metas);
     return $term_id;
 }