Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #3
0
 function cpotheme_form_collection($name, $value, $list, $args = null)
 {
     $field_class = isset($args['class']) ? $args['class'] : '';
     $output = '<div class="cpometabox-field-collection ' . $field_class . '">';
     //Check that given value is an array. If empty, add a single row
     if (empty($value) || $value == '') {
         $value = array('');
     }
     $output .= '<table>';
     //Table header
     $output .= '<thead>';
     foreach ($list as $list_key => $list_value) {
         $field_title = isset($list_value['label']) ? $list_value['label'] : $list_value;
         $output .= '<th>' . $field_title . '</th>';
     }
     $output .= '</thead>';
     //Table contents
     $counter = -1;
     foreach ($value as $current_key => $current_value) {
         $counter++;
         $output .= '<tr class="collection-row" data-index="' . $current_key . '">';
         foreach ($list as $list_key => $list_value) {
             $output .= '<td>';
             //Save field data-- collections can be of any field type
             $field_name = $name . '[' . $current_key . '][' . $list_key . ']';
             $field_type = isset($list_value['type']) ? $list_value['type'] : 'text';
             $field_args = isset($list_value['args']) ? $list_value['args'] : null;
             $field_options = isset($list_value['option']) ? $list_value['option'] : null;
             $field_value = isset($current_value[$list_key]) ? $current_value[$list_key] : '';
             //Display corresponding type of field
             if ($field_type == 'readonly') {
                 $output .= cpotheme_form_readonly($field_name, $field_value, $field_args);
             } elseif ($field_type == 'text') {
                 $output .= cpotheme_form_text($field_name, $field_value, $field_args);
             } elseif ($field_type == 'textarea') {
                 $output .= cpotheme_form_textarea($field_name, $field_value, $field_args);
             } elseif ($field_type == 'select') {
                 $output .= cpotheme_form_select($field_name, $field_value, $field_options, $field_args);
             } elseif ($field_type == 'checkbox') {
                 $output .= cpotheme_form_checkbox($field_name, $field_value, $field_args);
             } elseif ($field_type == 'yesno') {
                 $output .= cpotheme_form_yesno($field_name, $field_value, $field_args);
             } elseif ($field_type == 'color') {
                 $output .= cpotheme_form_color($field_name, $field_value);
             } 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 .= '</td>';
         }
         $output .= '<td>';
         $output .= '<a href="#" tabindex="-1" class="collection-remove-row">' . __('Remove', 'cpocore') . '</a>';
         $output .= '</td>';
         $output .= '</tr>';
     }
     $output .= '<tr>';
     $output .= '<td>';
     $output .= '<a href="#" class="button collection-add-row">' . __('Add Row', 'cpocore') . '</a>';
     $output .= '</td>';
     $output .= '</tr>';
     $output .= '</table>';
     $output .= '</div>';
     return $output;
 }