Example #1
0
 function cpotheme_meta_fields($post, $cpo_metadata = null)
 {
     if ($cpo_metadata == null || sizeof($cpo_metadata) == 0) {
         return;
     }
     $output = '';
     wp_enqueue_style('cpotheme_admin');
     wp_nonce_field('cpotheme_savemeta', 'cpotheme_nonce');
     foreach ($cpo_metadata as $current_meta) {
         $field_name = $current_meta["name"];
         $field_title = $current_meta['label'];
         $field_desc = $current_meta['desc'];
         $field_type = $current_meta['type'];
         $field_value = '';
         $field_value = get_post_meta($post->ID, $field_name, true);
         //Additional CSS classes depending on field type
         $field_classes = '';
         if ($field_type == 'collection') {
             $field_classes = ' cpometabox-wide';
         }
         $output .= '<div class="cpometabox ' . $field_classes . '"><div class="name">' . $field_title . '</div>';
         $output .= '<div class="field">';
         // Print metaboxes here. Develop different cases for each type of field.
         if ($field_type == 'readonly') {
             $output .= cpotheme_form_readonly($field_name, $field_value);
         } elseif ($field_type == 'text') {
             $output .= cpotheme_form_text($field_name, $field_value, $current_meta);
         } elseif ($field_type == 'textarea') {
             $output .= cpotheme_form_textarea($field_name, $field_value, $current_meta);
         } elseif ($field_type == 'select') {
             $output .= cpotheme_form_select($field_name, $field_value, $current_meta['option'], $current_meta);
         } elseif ($field_type == 'collection') {
             $output .= cpotheme_form_collection($field_name, $field_value, $current_meta['option'], $current_meta);
         } elseif ($field_type == 'checkbox') {
             $output .= cpotheme_form_checkbox($field_name, $field_value, $current_meta['option'], $current_meta);
         } elseif ($field_type == 'yesno') {
             $output .= cpotheme_form_yesno($field_name, $field_value, $current_meta);
         } elseif ($field_type == 'color') {
             $output .= cpotheme_form_color($field_name, $field_value);
         } elseif ($field_type == 'imagelist') {
             $output .= cpotheme_form_imagelist($field_name, $field_value, $current_meta['option'], $current_meta);
         } elseif ($field_type == 'iconlist') {
             $output .= cpotheme_form_iconlist($field_name, $field_value, $current_meta);
         } elseif ($field_type == 'upload') {
             $output .= cpotheme_form_upload($field_name, $field_value, null, $post);
         } elseif ($field_type == 'date') {
             $output .= cpotheme_form_date($field_name, $field_value, null);
         }
         $output .= '</div>';
         $output .= '<div class="desc">' . $field_desc . '</div></div>';
     }
     echo $output;
 }
Example #2
0
 function cpotheme_taxonomy_meta_fields($title, $post, $cpo_metadata)
 {
     if ($cpo_metadata == null || sizeof($cpo_metadata) == 0) {
         return;
     }
     $post_id = isset($_GET['tag_ID']) ? $_GET['tag_ID'] : false;
     $output = '';
     $field_prefix = 'cpotheme_taxonomy_meta_';
     $output .= '<h3>' . $title . '</h3>';
     $output .= '<table class="form-table">';
     $output .= '<tbody>';
     //Loop through all the data taxonomies and create the field associated to them.
     foreach ($cpo_metadata as $current_meta) {
         $field_name = $current_meta["name"];
         $field_title = $current_meta['label'];
         $field_desc = $current_meta['desc'];
         $field_type = $current_meta['type'];
         $field_value = cpotheme_tax_meta($post_id, $field_name);
         $output .= '<tr>';
         $output .= '<th scope="row"><label for="' . $field_name . '" class="field_title">' . $field_title . '</label></th>';
         $output .= '<td>';
         // Print metaboxes here. Develop different cases for each type of field.
         if ($field_type == 'text') {
             $output .= cpotheme_form_text($field_name, $field_value, $current_meta);
         } elseif ($field_type == 'textarea') {
             $output .= cpotheme_form_textarea($field_name, $field_value, $current_meta);
         } elseif ($field_type == 'select') {
             $output .= cpotheme_form_select($field_name, $field_value, $current_meta['option'], $current_meta);
         } elseif ($field_type == 'checkbox') {
             $output .= cpotheme_form_checkbox($field_name, $field_value, $current_meta);
         } elseif ($field_type == 'yesno') {
             $output .= cpotheme_form_yesno($field_name, $field_value, $current_meta);
         } elseif ($field_type == 'color') {
             $output .= cpotheme_form_color($field_name, $field_value);
         } elseif ($field_type == 'imagelist') {
             $output .= cpotheme_form_imagelist($field_name, $field_value, $current_meta['option'], $current_meta);
         } elseif ($field_type == 'upload') {
             $output .= cpotheme_form_upload($field_name, $field_value, null, $post);
         } elseif ($field_type == 'date') {
             $output .= cpotheme_form_date($field_name, $field_value, null);
         }
         //Separators
         if ($field_type != 'separator' && $field_type != 'divider') {
             $output .= '<br><span class="description">' . $field_desc . '</span>';
             $output .= '</td>';
             $output .= '</tr>';
         }
     }
     $output .= '</tbody>';
     $output .= '</table>';
     return $output;
 }