php - How to enable the user to add value through the admin panel? (wordpress) -


please me! have custom posts type 'gallery'. in custom post type have custom fields. added them through file functions.php. how enable user add value through admin panel field 'цвет'(colors)(http://prntscr.com/7svcck), without going functions.php allow users add color , see in drop-down list of colors(see screen).

my code in functions.php

if ( ! function_exists( 'bazar_tax' ) ) {      function bazar_tax() {          $labels = array(             'name'                       => _x( 'Категории базарчика', 'taxonomy general name', 'bazar' ),             'singular_name'              => _x( 'Категория базарчик', 'taxonomy singular name', 'bazar' ),             'menu_name'                  => __( 'Категории', 'bazar' ),             'all_items'                  => __( 'Категории', 'bazar' ),             'parent_item'                => __( 'Родительская категория Базарчик', 'bazar' ),             'parent_item_colon'          => __( 'Родительская категория Базарчик:', 'bazar' ),             'new_item_name'              => __( 'Новая категория', 'bazar' ),             'add_new_item'               => __( 'Добавить новую категорию', 'bazar' ),             'edit_item'                  => __( 'Редактировать категорию', 'bazar' ),             'update_item'                => __( 'Обновить категорию', 'bazar' ),             'search_items'               => __( 'Найти', 'bazar' ),             'add_or_remove_items'        => __( 'Добавить или удалить категорию', 'bazar' ),             'choose_from_most_used'      => __( 'Поиск среди популярных', 'bazar' ),             'not_found'                  => __( 'Не найдено', 'bazar' ),         );         $args = array(             'labels'                     => $labels,             'hierarchical'               => true,             'public'                     => true,         );         register_taxonomy( 'bazar_tax', array( 'bazar' ), $args );      }      add_action( 'init', 'bazar_tax', 0 );   }   function my_meta_box() {       add_meta_box(           'my_meta_box',          'Дополнительная информация',          'show_my_metabox',          'bazar',         'normal',         'high'); }   add_action('add_meta_boxes', 'my_meta_box');  $meta_fields1 = array(       array(           'label' => 'Размер',           'desc'  => 'Пример: 25х25',           'id'    => 'razmer', // даем идентификатор.         'type'  => 'text'  // Указываем тип поля.     ),       array(           'label' => 'Номер партии',           'desc'  => '',           'id'    => 'nomer',  // даем идентификатор.         'type'  => 'text'  // Указываем тип поля.     ),       array(           'label' => 'Город продавца',           'desc'  => '',           'id'    => 'gorod',  // даем идентификатор.         'type'  => 'text'  // Указываем тип поля.     ),     array(           'label' => 'Имя продавца',           'desc'  => '',           'id'    => 'name',  // даем идентификатор.         'type'  => 'text'  // Указываем тип поля.     ),     array(           'label' => 'Телефон продавца',           'desc'  => '',           'id'    => 'telephone',  // даем идентификатор.         'type'  => 'text'  // Указываем тип поля.     ),         array(           'label' => 'Цвет',           'desc'  => 'Цвет',           'id'    => 'cvet',           'type'  => 'select',           'options' => array (  // Параметры, всплывающие данные             'one' => array (                   'label' => 'aspen brown ab632',  // Название поля                 'value' => 'aspen brown ab632'  // Значение             ),               'two' => array (                   'label' => 'aspen fiesta af611',  // Название поля                 'value' => 'aspen fiesta af611'  // Значение             ),               'three' => array (                   'label' => 'aspen glacier ag612',  // Название поля                 'value' => 'aspen glacier ag612'  // Значение             ),             'four' => array (                   'label' => 'aspen lava al650',  // Название поля                 'value' => 'aspen lava al650'  // Значение             ),             'five' => array (                   'label' => 'aspen mine am633',  // Название поля                 'value' => 'aspen mine am633'  // Значение             ),             'six' => array (                   'label' => 'aspen pepper ap640',  // Название поля                 'value' => 'aspen pepper ap640'  // Значение             ),             'seven' => array (                   'label' => 'aspen seashell as642',  // Название поля                 'value' => 'aspen seashell as642'  // Значение             ),             'eight' => array (                   'label' => 'aspen sky as670',  // Название поля                 'value' => 'aspen sky as670'  // Значение             ),             'ten' => array (                   'label' => 'aspen snow as610',  // Название поля                 'value' => 'aspen snow as610'  // Значение             ),             'eleven' => array (                   'label' => 'metallic beach eb545',  // Название поля                 'value' => 'metallic beach eb545'  // Значение             ),             'twelve' => array (                   'label' => 'metallic cosmos ec 596',  // Название поля                 'value' => 'metallic cosmos ec 596'  // Значение             ),             'thirteen' => array (                   'label' => 'metallic galaxy eg595',  // Название поля                 'value' => 'metallic galaxy eg595'  // Значение             ),             'fourteen' => array (                   'label' => 'metallic sunray es557',  // Название поля                 'value' => 'metallic sunray es557'  // Значение             ),             'fifteen' => array (                   'label' => 'metallic  satingold es558',  // Название поля                 'value' => 'metallic  satingold es558'  // Значение             ),             'sixteen' => array (                   'label' => 'metallic sleeksilver es581',  // Название поля                 'value' => 'metallic sleeksilver es581'  // Значение             ),             'seventeen' => array (                   'label' => 'metallic yukon ey510',  // Название поля                 'value' => 'metallic yukon ey510'  // Значение             ),             'eighteen' => array (                   'label' => 'mosaic dalmatin qd212',  // Название поля                 'value' => 'mosaic dalmatin qd212'  // Значение             ),             'nineteen' => array (                   'label' => 'mosaic nimbus qn287',  // Название поля                 'value' => 'mosaic nimbus qn287'  // Значение             ),             'twenty' => array (                   'label' => 'mosaic black bean qb299',  // Название поля                 'value' => 'mosaic black bean qb299'  // Значение             ),             'twenty-one' => array (                   'label' => 'pebble aqua pa860',  // Название поля                 'value' => 'pebble aqua pa860'  // Значение             ),             'twenty-two' => array (                   'label' => 'pebble blue pb870',  // Название поля                 'value' => 'pebble blue pb870'  // Значение             ),             'twenty-three' => array (                   'label' => 'pebble cliffside pc 895',  // Название поля                 'value' => 'pebble cliffside pc 895'  // Значение             ),             'twenty-four' => array (                   'label' => 'pebble confetti pc880',  // Название поля                 'value' => 'pebble confetti pc880'  // Значение             ),             'twenty-five' => array (                   'label' => 'pebble copper pc851',  // Название поля                 'value' => 'pebble copper pc851'  // Значение             ),             'twenty-six' => array (                   'label' => 'pebble ebony pe814',  // Название поля                 'value' => 'pebble ebony pe814'  // Значение             ),             'twenty-seven' => array (                   'label' => 'pebble frost pf812',  // Название поля                 'value' => 'pebble frost pf812'  // Значение             ),             'twenty-eight' => array (                   'label' => 'pebble gold pg840',  // Название поля                 'value' => 'pebble gold pg840'  // Значение             ),             'twenty-nine' => array (                   'label' => 'pebble grey pg810',  // Название поля                 'value' => 'pebble grey pg810'  // Значение             ),             'thirty' => array (                   'label' => 'pebble ice pi 811',  // Название поля                 'value' => 'pebble ice pi 811'  // Значение             ),             'thirty-one' => array (                   'label' => 'pebble kernel pk843',  // Название поля                 'value' => 'pebble kernel pk843'  // Значение             ),             'thirty-two' => array (                   'label' => 'pebble limestone pl848',  // Название поля                 'value' => 'pebble limestone pl848'  // Значение             ),             'thirty-three' => array (                   'label' => 'pebble ponderosa pp868',  // Название поля                 'value' => 'pebble ponderosa pp868'  // Значение             ),             'thirty-four' => array (                   'label' => 'pebble rose pr850',  // Название поля                 'value' => 'pebble rose pr850'  // Значение             ),             'thirty-five' => array (                   'label' => 'pebble saratoga ps820',  // Название поля                 'value' => 'pebble saratoga ps820'  // Значение             ),             'thirty-six' => array (                   'label' => 'pebble swan ps813',  // Название поля                 'value' => 'pebble swan ps813'  // Значение             ),             'thirty-seven' => array (                   'label' => 'pebble terrain pt857',  // Название поля                 'value' => 'pebble terrain pt857'  // Значение             ),             'thirty-eight' => array (                   'label' => 'quarry mesa qm242',  // Название поля                 'value' => 'quarry mesa qm242'  // Значение             ),             'thirty-nine' => array (                   'label' => 'quarry esker qe240',  // Название поля                 'value' => 'quarry esker qe240'  // Значение             ),             'forty' => array (                   'label' => 'quarry oyster to310',  // Название поля                 'value' => 'quarry oyster to310'  // Значение             ),             'forty-one' => array (                   'label' => 'sanded blush sb452',  // Название поля                 'value' => 'sanded blush sb452'  // Значение             ),             'forty-two' => array (                   'label' => 'sanded birch sb412',  // Название поля                 'value' => 'sanded birch sb412'  // Значение             ),             'forty-three' => array (                   'label' => 'sanded cornmeal sc433',  // Название поля                 'value' => 'sanded cornmeal sc433'  // Значение             ),             'forty-four' => array (                   'label' => 'sanded chesnut sc457',  // Название поля                 'value' => 'sanded chesnut sc457'  // Значение             ),             'forty-five' => array (                   'label' => 'sanded cream sm421',  // Название поля                 'value' => 'sanded cream sm421'  // Значение             ),             'forty-six' => array (                   'label' => 'sanded dark nebula dn421',  // Название поля                 'value' => 'sanded dark nebula dn421'  // Значение             ),             'forty-seven' => array (                   'label' => 'sanded gold dust sg441',  // Название поля                 'value' => 'sanded gold dust sg441'  // Значение             ),             'forty-eight' => array (                   'label' => 'sanded grey sg420',  // Название поля                 'value' => 'sanded grey sg420'  // Значение             ),             'forty-nine' => array (                   'label' => 'sanded icicle si414',  // Название поля                 'value' => 'sanded icicle si414'  // Значение             ),             'fifty' => array (                   'label' => 'sanded kiwi sk432',  // Название поля                 'value' => 'sanded kiwi sk432'  // Значение             ),             'fifty-one' => array (                   'label' => 'sanded mocha sm453',  // Название поля                 'value' => 'sanded mocha sm453'  // Значение             ),             'fifty-two' => array (                   'label' => 'sanded oatmeal so446',  // Название поля                 'value' => 'sanded oatmeal so446'  // Значение             ),             'fifty-three' => array (                   'label' => 'sanded onyx so423',  // Название поля                 'value' => 'sanded onyx so423'  // Значение             ),             'fifty-four' => array (                   'label' => 'sanded pine sp462',  // Название поля                 'value' => 'sanded pine sp462'  // Значение             ),             'fifty-five' => array (                   'label' => 'sanded sahara ss440',  // Название поля                 'value' => 'sanded sahara ss440'  // Значение             ),             'fifty-six' => array (                   'label' => 'sanded seafoam ss471',  // Название поля                 'value' => 'sanded seafoam ss471'  // Значение             ),             'fifty-seven' => array (                   'label' => 'sanded sunset ss451',  // Название поля                 'value' => 'sanded sunset ss451'  // Значение             ),             'fifty-eight' => array (                   'label' => 'sanded stratus ss418',  // Название поля                 'value' => 'sanded stratus ss418'  // Значение             ),             'sixty' => array (                   'label' => 'sanded vermillion sv430',  // Название поля                 'value' => 'sanded vermillion sv430'  // Значение             ),             'sixty-one' => array (                   'label' => 'sanded white pepper wp410',  // Название поля                 'value' => 'sanded white pepper wp410'  // Значение             ),             'sixty-two' => array (                   'label' => 'solid  steel st023',  // Название поля                 'value' => 'solid  steel st023'  // Значение             ),             'sixty-three' => array (                   'label' => 'solid blonde sb043',  // Название поля                 'value' => 'solid blonde sb043'  // Значение             ),             'sixty-four' => array (                   'label' => 'solid bright white bw010',  // Название поля                 'value' => 'solid bright white bw010'  // Значение             ),             'sixty-five' => array (                   'label' => 'solid quasar white sq019',  // Название поля                 'value' => 'solid quasar white sq019'  // Значение             ),             'sixty-six' => array (                   'label' => 'solid californiya poppy sc052',  // Название поля                 'value' => 'solid californiya poppy sc052'  // Значение             ),             'sixty-seven' => array (                   'label' => 'solid dazzling white sd001',  // Название поля                 'value' => 'solid dazzling white sd001'  // Значение             ),             'sixty-eight' => array (                   'label' => 'solid fog sf020',  // Название поля                 'value' => 'solid fog sf020'  // Значение             ),             'sixty-nine' => array (                   'label' => 'solid iris si056',  // Название поля                 'value' => 'solid iris si056'  // Значение             ),             'seventy' => array (                   'label' => 'solid ivory si040',  // Название поля                 'value' => 'solid ivory si040'  // Значение             ),             'seventy-one' => array (                   'label' => 'solid natural sv041',  // Название поля                 'value' => 'solid natural sv041'  // Значение             ),             'seventy-two' => array (                   'label' => 'solid onyx on095',  // Название поля                 'value' => 'solid onyx on095'  // Значение             ),             'seventy-three' => array (                   'label' => 'solid pearl sp011',  // Название поля                 'value' => 'solid pearl sp011'  // Значение             ),             'seventy-four' => array (                   'label' => 'solid pure white sp016',  // Название поля                 'value' => 'solid pure white sp016'  // Значение             ),             'seventy-five' => array (                   'label' => 'solid sunflower ss042',  // Название поля                 'value' => 'solid sunflower ss042'  // Значение             ),             'seventy-six' => array (                   'label' => 'solid univers su053',  // Название поля                 'value' => 'solid univers su053'  // Значение             ),             'seventy-seven' => array (                   'label' => 'talus luna tl385',  // Название поля                 'value' => 'talus luna tl385'  // Значение             ),             'seventy-eight' => array (                   'label' => 'tempest adamantine fa159',  // Название поля                 'value' => 'tempest adamantine fa159'  // Значение             ),             'seventy-nine' => array (                   'label' => 'tempest blaze fb147',  // Название поля                 'value' => 'tempest blaze fb147'  // Значение             ),             'eighty-one' => array (                   'label' => 'tempest cinnamon fc153',  // Название поля                 'value' => 'tempest cinnamon fc153'  // Значение             ),             'eighty-two' => array (                   'label' => 'tempest coffee bean fc158',  // Название поля                 'value' => 'tempest coffee bean fc158'  // Значение             ),             'eighty-three' => array (                   'label' => 'tempest confection fc116',  // Название поля                 'value' => 'tempest confection fc116'  // Значение             ),             'eighty-four' => array (                   'label' => 'tempest constellation fc197',  // Название поля                 'value' => 'tempest constellation fc197'  // Значение             ),             'eighty-five' => array (                   'label' => 'tempest genesis fg174',  // Название поля                 'value' => 'tempest genesis fg174'  // Значение             ),             'eighty-six' => array (                   'label' => 'tempest gleam fg146',  // Название поля                 'value' => 'tempest gleam fg146'  // Значение             ),             'eighty-seven' => array (                   'label' => 'tempest glimmer fg144',  // Название поля                 'value' => 'tempest glimmer fg144'  // Значение             ),             'eighty-eight' => array (                   'label' => 'tempest gold leaf fg196',  // Название поля                 'value' => 'tempest gold leaf fg196'  // Значение             ),             'ninety' => array (                   'label' => 'tempest horizon fh114',  // Название поля                 'value' => 'tempest horizon fh114'  // Значение             ),             'ninety-one' => array (                   'label' => 'tempest igneous fi187',  // Название поля                 'value' => 'tempest igneous fi187'  // Значение             ),             'ninety-two' => array (                   'label' => 'tempest meteor fm111',  // Название поля                 'value' => 'tempest meteor fm111'  // Значение             ),             'ninety-three' => array (                   'label' => 'tempest moonlight fm122',  // Название поля                 'value' => 'tempest moonlight fm122'  // Значение             ),             'ninety-four' => array (                   'label' => 'tempest paprika fp136',  // Название поля                 'value' => 'tempest paprika fp136'  // Значение             ),             'ninety-five' => array (                   'label' => 'tempest peak fp100',  // Название поля                 'value' => 'tempest peak fp100'  // Значение             ),             'ninety-six' => array (                   'label' => 'tempest pinnacle fp112',  // Название поля                 'value' => 'tempest pinnacle fp112'  // Значение             ),             'ninety-seven' => array (                   'label' => 'tempest praire fp142',  // Название поля                 'value' => 'tempest praire fp142'  // Значение             ),             'ninety-eight' => array (                   'label' => 'tempest rattan fr124',  // Название поля                 'value' => 'tempest rattan fr124'  // Значение             ),             'ninety-nine' => array (                   'label' => 'tempest rime fr118',  // Название поля                 'value' => 'tempest rime fr118'  // Значение             ),             'one-hundred' => array (                   'label' => 'tempest shallot fs157',  // Название поля                 'value' => 'tempest shallot fs157'  // Значение             ),             'one-hundred-and-one' => array (                   'label' => 'tempest shell fs115',  // Название поля                 'value' => 'tempest shell fs115'  // Значение             ),              'one-hundred-and-two' => array (                   'label' => 'tempest shimmer(radiance) fr148',  // Название поля                 'value' => 'tempest shimmer(radiance) fr148'  // Значение             ),             'one-hundred-and-three' => array (                   'label' => 'tempest spearmint fs164',  // Название поля                 'value' => 'tempest spearmint fs164'  // Значение             ),              'one-hundred-and-four' => array (                   'label' => 'tempest spice fs137',  // Название поля                 'value' => 'tempest spice fs137'  // Значение             ),              'one-hundred-and-five' => array (                   'label' => 'tempest starfire fs198',  // Название поля                 'value' => 'tempest starfire fs198'  // Значение             ),             'one-hundred-and-six' => array (                   'label' => 'tempest tektite ft188',  // Название поля                 'value' => 'tempest tektite ft188'  // Значение             ),             'one-hundred-and-seven' => array (                   'label' => 'tempest twilight ft113',  // Название поля                 'value' => 'tempest twilight ft113'  // Значение             ),              'one-hundred-and-eight' => array (                   'label' => 'tempest whippoorwill fw145',  // Название поля                 'value' => 'tempest whippoorwill fw145'  // Значение             ),             'one-hundred-and-nine' => array (                   'label' => 'tempest zenith fz184',  // Название поля                 'value' => 'tempest zenith fz184'  // Значение             ),                                                                          )       )   );  function show_my_metabox() {   global $meta_fields1; global $post;   echo '<input type="hidden" name="custom_meta_box_nonce" value="'.wp_create_nonce(basename(__file__)).'" />';         echo '<table class="form-table">';       foreach ($meta_fields1 $field) {            $meta = get_post_meta($post->id, $field['id'], true);            echo '<tr>                  <th><label for="'.$field['id'].'">'.$field['label'].'</label></th>                  <td>';                   switch($field['type']) {                       case 'text':       echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />         <br /><span class="description">'.$field['desc'].'</span>';   break; case 'textarea':       echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>          <br /><span class="description">'.$field['desc'].'</span>';   break; case 'checkbox':       echo '<input type="checkbox" name="'.$field['id'].'" id="'.$field['id'].'" ',$meta ? ' checked="checked"' : '','/>         <label for="'.$field['id'].'">'.$field['desc'].'</label>';   break;  case 'select':       echo '<select name="'.$field['id'].'" id="'.$field['id'].'">';       foreach ($field['options'] $option) {           echo '<option', $meta == $option['value'] ? ' selected="selected"' : '', ' value="'.$option['value'].'">'.$option['label'].'</option>';       }       echo '</select><br /><span class="description">'.$field['desc'].'</span>';   break;                 }         echo '</td></tr>';       }       echo '</table>';  }   function save_my_meta_fields($post_id) {       global $meta_fields1;         if (!wp_verify_nonce($_post['custom_meta_box_nonce'], basename(__file__)))            return $post_id;       // Проверяем авто-сохранение      if (defined('doing_autosave') && doing_autosave)           return $post_id;       // Проверяем права доступа       if ('page' == $_post['post_type']) {           if (!current_user_can('edit_page', $post_id))               return $post_id;           } elseif (!current_user_can('edit_post', $post_id)) {               return $post_id;       }        foreach ($meta_fields1 $field) {           $old = get_post_meta($post_id, $field['id'], true);          $new = $_post[$field['id']];           if ($new && $new != $old) {  // Если данные новые             update_post_meta($post_id, $field['id'], $new);          } elseif ('' == $new && $old) {               delete_post_meta($post_id, $field['id'], $old);         }       } // end foreach   }   add_action('save_post', 'save_my_meta_fields');  

don't use select meta field if users need change options every time. think, simple solution adding 'color' taxonomy 'gallery' post type in functions.php:

add_action( 'init', 'create_color_tax' );  function create_color_tax() {     register_taxonomy(         'color',         'gallery',         array(             'label' => __( 'color' ),             'rewrite' => array( 'slug' => 'color' ),             'hierarchical' => true,         )     ); } 

users able add , remove colors every time without modifying functions.php.


Comments