Example #1
0
 public function initializeFields()
 {
     # the createFieldGroup method will automatically create the appropriate
     # post_meta entries for the post type with the names in the "fields" parameter.
     # the labels need to be in the same order
     $this->createFieldGroup(array("name" => "Details", "fields" => array("title", "artist", "album", 'review', 'color', 'textColor', 'releaseDate', 'itunesTrackId', 'itunesCollectionId'), "labels" => array("Title", "Artist", 'Album', "Review", 'Color', 'Text Color', "Release Date", 'itunesTrackId', 'itunesCollectionId'), "position" => "normal", "priority" => "core", "render" => function ($name, $fieldList) {
         # create an array to hold the HTML
         $html = array();
         # this is just standard markup to emulate the base wordpress styles
         $html[] = "<div class='inner-group-content'>";
         # loop over the fieldList (if they have data already, it will have been pulled)
         # fieldList is in the following format, referencing the above, where "exampleLink" has data:
         /*
             [
                 0 => [
                         "fieldName" => "exampleLink",
                         "label" => "Example Link",
                         "data" => "https://google.com"
                     ],
                 1 => [
                         "fieldName" => "author",
                         "label" => "Author",
                         "data" => false
                     ],
                 2 ...
             ]
         */
         # You can pass the $field in this loop directly to the Form::methods()
         # as it expects the above data-structure. Below is an example of how you can
         # handle multiple data types and use the form class to automatically pull data
         foreach ($fieldList as $field) {
             $html[] = "<div>";
             $html[] = "<label class='custom-field-label'>";
             $html[] = "<span class='label-wrapper'>{$field['label']}</span>";
             switch ($field['fieldName']) {
                 case "songReviewField":
                     $html[] = Form::wysiwyg($field);
                     break;
                 default:
                     $html[] = Form::input($field, 'text');
                     break;
             }
             $html[] = "</label>";
             $html[] = "</div>";
         }
         $html[] = "</div>";
         # finally, echo out our completed HTML
         echo implode('', $html);
     }));
     return $this;
 }