Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Last active December 30, 2015 04:19
Show Gist options
  • Save mikeschinkel/7775461 to your computer and use it in GitHub Desktop.
Save mikeschinkel/7775461 to your computer and use it in GitHub Desktop.
Example of defining form and fields for a "Person" post type for Sunrise (v1): https://bitbucket.org/newclarity/sunrise-1
<?php
/**
* DEFINING FIELDS
*/
sr_register_fields( 'person', array(
'object_type' => 'post',
'fields' => array(
// Basic info
'post_title' => array(
'type' => 'hidden',
'storage' => 'core',
'default' => 'To be replaced',
'get_value' => array( __CLASS__, 'get_post_title' ),
'get_default' => array( __CLASS__, 'default_post_title' ),
),
'first_name' => array(
'type' => 'text',
'label' => 'First Name',
'required' => true,
'size' => 50,
),
'middle_initial' => array(
'type' => 'text',
'label' => 'Middle Initial',
'size' => 10,
),
'last_name' => array(
'type' => 'text',
'label' => 'Last Name',
'required' => true,
'size' => 50,
),
'suffix' => array(
'label' => 'Suffix',
'size' => 10,
),
'email' => array(
'type' => 'text',
'label' => 'Email',
'required' => true,
'placeholder' => 'youremail@yourfirm.com',
'size' => 50,
),
'phone' => array(
'type' => 'text',
'label' => 'Phone',
'required' => true,
'placeholder' => '999-999-9999',
'pattern' => '^[0-9]{3}-[0-9]{3}-[0-9]{4}$',
'size' => 50,
),
'alternate_phone_1' => array(
'label' => 'Alternate Phone 1',
'placeholder' => '999-999-9999',
'size' => 50,
),
'alternate_phone_2' => array(
'label' => 'Alternate Phone 2',
'placeholder' => '999-999-9999',
'size' => 50,
),
'photo' => array(
'type' => 'image',
'label' => 'Photo: Main',
'image_type' => 'headshot',
'infobox' => 'Crop to 238 x 288 pixels.',
'view_size' => 'small',
'force_delete' => false,
),
'headshot_photo' => array(
'type' => 'image',
'label' => 'Photo: Closeup',
'image_type' => 'headshot_closeup',
'infobox' => 'To bypass the cropping tool, click the cancel button.',
'view_size' => 'teaser',
'force_delete' => false,
),
'resume' => array(
'type' => 'file',
'label' => 'Resume (PDF)',
'extensions' => 'pdf',
'force_delete' => false,
),
'linkedin_url' => array(
'type' => 'text',
'label' => 'LinkedIn Profile URL',
'placeholder' => 'http://www.linkedin.com/in/your-profile-name',
'size' => 60,
),
'twitter_url' => array(
'type' => 'text',
'label' => 'Twitter Profile URL',
'placeholder' => 'http://twitter.com/your-screen-name',
'help' => 'URL must begin with http://',
'size' => 60,
),
'position' => array(
'type' => 'taxonomy_term',
'label' => 'Position',
'taxonomy' => 'people-position',
'default' => 'Select a Position',
'exclude' => 'attorney',
),
'alternate_title' => array(
'type' => 'text',
'label' => 'Alternate Title',
'infobox' => "<p>This allows you to add a secondary title, which appears underneath a person’s<br />
name on their microsite header. For staff/administrative, this becomes their only<br />
title because staff/administrative is not displayed as a title.</p>"
),
'office_location' => array(
'type' => 'related_posts',
'relationship_name' => 'person_to_office',
'label' => 'Office Location',
'default_option' => false,
'multi_select' => true,
),
'large_heading' => array(
'type' => 'text',
'label' => 'Large Heading',
),
'text_content' => array(
'type' => 'redactor',
'label' => 'Text Content',
),
'more_link' => array(
'type' => 'text',
'label' => '"More" Link',
'placeholder' => 'http://www.website.com',
'size' => 60,
),
'highlight_photo' => array(
'type' => 'image',
'label' => 'Photo',
'force_delete' => false,
'image_type' => 'microsite_person_sidebar',
'infobox' => 'Images uploaded into this field will be cropped to 171 x 129 pixels.',
),
'pullquote' => array(
'type' => 'redactor',
'label' => 'Callout / Pullquote (20-30 words max)',
),
'multi_photos' => array(
'type' => 'repeating',
'label' => false,
'indentable' => false,
'no_colon' => true,
'controls' => array( 'add_field', 'delete_field' ),
'field_args' => array(
'type' => 'fieldset',
'fields' => array(
'multi_highlight_photo' => array(
'type' => 'image',
'label' => 'Photo',
'force_delete' => false,
'image_type' => 'microsite_person_sidebar',
'infobox' => 'Images uploaded into this field will be cropped to 171 x 129 pixels.',
),
'caption' => array(
'type' => 'redactor',
'label' => 'Caption',
'rows' => '5',
'cols' => '50',
),
),
),
),
'sidebar_dropdown' => array(
'type' => 'form_select',
'label' => 'Sidebar',
'help_text' => 'Select an option from the dropdown to enable a sidebar on the page.',
'form_type' => 'admin_post_form',
'image_dropdown' => true,
'post_type' => 'person',
'forms' => array(
'no_sidebar' => array(
'title' => 'No Sidebar',
'fields' => array(),
),
'photo_highlight_box' => array(
'title' => 'Highlight Box (with Photo)',
'fields' => array(
'highlight_photo',
'large_heading',
'text_content',
'more_link',
),
),
'text_highlight_box' => array(
'title' => 'Highlight Box (Text Only)',
'fields' => array(
'large_heading',
'text_content',
'more_link',
),
),
'pullquote_box' => array(
'title' => 'Pullquote Box',
'fields' => array(
'highlight_photo',
'pullquote',
),
),
'multiple_photos' => array(
'title' => 'Multiple Photos',
'fields' => array( 'multi_photos', ),
),
),
),
'full_content' => array(
'type' => 'redactor',
'label' => 'Biography Narrative',
'label_position' => 'above',
'rows' => 20,
'cols' => 60,
),
'education' => array(
'type' => 'indentable_repeating',
'label' => 'Education',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'bar_memberships' => array(
'type' => 'indentable_repeating',
'label' => 'Bar Memberships',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'work_experience' => array(
'type' => 'indentable_repeating',
'label' => 'Work Experience',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'professional_affiliations' => array(
'type' => 'indentable_repeating',
'label' => 'Professional Affiliations',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'special_honors' => array(
'type' => 'indentable_repeating',
'label' => 'Special Honors',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'reported_cases' => array(
'type' => 'indentable_repeating',
'label' => 'Reported Cases',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'charitable_civic_involvement' => array(
'type' => 'indentable_repeating',
'label' => 'Charitable & Civic Involvement',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'languages' => array(
'type' => 'indentable_repeating',
'label' => 'Languages',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'category_name_1' => array(
'type' => 'text',
'size' => 50,
'label' => 'Category Name',
'label_position' => 'above',
),
'list_1' => array(
'type' => 'indentable_repeating',
'label' => 'List Items',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'text_content_1' => array(
'type' => 'redactor',
'label' => 'Description',
'label_position' => 'above',
'cols' => 50,
),
'custom_category_1' => array(
'type' => 'form_select',
'label' => 'Custom Category 1',
'label_position' => 'above',
'form_type' => 'admin_post_form',
'post_type' => 'person',
'forms' => array(
'none_1' => array(
'title' => 'None',
'fields' => array(),
),
'indented_1' => array(
'title' => 'Indented List',
'fields' => array(
'category_name_1',
'list_1',
),
),
'freeform_1' => array(
'title' => 'Freeform',
'fields' => array(
'category_name_1',
'text_content_1',
),
),
),
),
'category_name_2' => array(
'type' => 'text',
'size' => 50,
'label' => 'Category Name',
'label_position' => 'above',
),
'list_2' => array(
'type' => 'indentable_repeating',
'label' => 'List Items',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'text_content_2' => array(
'type' => 'redactor',
'label' => 'Description',
'label_position' => 'above',
'cols' => 50,
),
'custom_category_2' => array(
'type' => 'form_select',
'label' => 'Custom Category 2',
'label_position' => 'above',
'form_type' => 'admin_post_form',
'post_type' => 'person',
'forms' => array(
'none_2' => array(
'title' => 'None',
'fields' => array(),
),
'indented_2' => array(
'title' => 'Indented List',
'fields' => array(
'category_name_2',
'list_2',
),
),
'freeform_2' => array(
'title' => 'Freeform',
'fields' => array(
'category_name_2',
'text_content_2',
),
),
),
),
'category_name_3' => array(
'type' => 'text',
'size' => 50,
'label' => 'Category Name',
'label_position' => 'above',
),
'list_3' => array(
'type' => 'indentable_repeating',
'label' => 'List Items',
'label_position' => 'above',
'indentable' => true,
'field_args' => array(
'type' => 'text',
'size' => '50',
),
),
'text_content_3' => array(
'type' => 'redactor',
'label' => 'Description',
'label_position' => 'above',
'cols' => 50,
),
'custom_category_3' => array(
'type' => 'form_select',
'label' => 'Custom Category 3',
'label_position' => 'above',
'form_type' => 'admin_post_form',
'post_type' => 'person',
'forms' => array(
'none_3' => array(
'title' => 'None',
'fields' => array(),
),
'indented_3' => array(
'title' => 'Indented List',
'fields' => array(
'category_name_3',
'list_3',
),
),
'freeform_3' => array(
'title' => 'Freeform',
'fields' => array(
'category_name_3',
'text_content_3',
),
),
),
),
)
)
);
<?php
/**
* DEFINING FORMS
*/
sr_register_form( 'basic_info', array(
'form_type' => 'admin_post_form',
'post_type' => 'person',
'title' => 'Basic Information',
'priority' => 'default',
'fields' => array(
'post_title',
'first_name',
'middle_initial',
'last_name',
'suffix',
'email',
'phone',
'alternate_phone_1',
'alternate_phone_2',
'photo',
'headshot_photo',
'resume',
'linkedin_url',
'twitter_url',
'position',
'alternate_title',
'office_location',
),
));
sr_register_form( 'curriculum_vitae', array(
'form_type' => 'admin_post_form',
'post_type' => 'person',
'title' => 'Biography',
'priority' => 'default',
'fields' => array(
'full_content',
'education',
'bar_memberships',
'work_experience',
'professional_affiliations',
'special_honors',
'reported_cases',
'charitable_civic_involvement',
'languages',
'custom_category_1',
'custom_category_2',
'custom_category_3',
),
));
sr_register_form( 'sidebar', array(
'form_type' => 'admin_post_form',
'post_type' => 'person',
'title' => 'Sidebar',
'priority' => 'low',
'view_state' => 'always_open',
'fields' => array( 'sidebar_dropdown', ),
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment