Esempio n. 1
0
function x_init_custom_fields()
{
    // check that the metadata manager plugin is active by checking if the two functions we need exist
    if (function_exists('x_add_metadata_group') && function_exists('x_add_metadata_field')) {
        // adds a new group to the test post type
        x_add_metadata_group('x_metaBox1', 'strain', array('label' => 'Lab Results'));
        // adds a text field to the first group
        x_add_metadata_field('x_fieldName1', 'strain', array('group' => 'x_metaBox1', 'label' => 'THC %', 'display_column' => true));
        // adds a text field to the 2nd group
        x_add_metadata_field('x_fieldName2', 'strain', array('group' => 'x_metaBox1', 'label' => 'CBD %', 'display_column' => true));
        // adds a cloneable textarea field to the 1st group
        x_add_metadata_field('x_fieldTextarea1', 'strain', array('group' => 'x_metaBox1', 'label' => 'CBN %'));
    }
}
function x_init_custom_fields()
{
    // check that the metadata manager plugin is active by checking if the two functions we need exist
    if (function_exists('x_add_metadata_group') && function_exists('x_add_metadata_field')) {
        // adds a new group to the test post type
        x_add_metadata_group('x_metaBox1', 'x_test', array('label' => 'Group with Multiple Fields'));
        // adds another group to the test post type + posts + users
        x_add_metadata_group('x_metaBox2', array('x_test', 'post', 'user'), array('label' => 'Group for Post and User'));
        // adds a text field to the first group
        x_add_metadata_field('x_fieldName1', 'x_test', array('group' => 'x_metaBox1', 'description' => 'This is field #1. It\'s a simple text field.', 'label' => 'Text Field', 'display_column' => true));
        // adds a text field to the 2nd group
        x_add_metadata_field('x_fieldName2', 'x_test', array('group' => 'x_metaBox1', 'display_column' => 'My Column (with Custom Callback)', 'display_column_callback' => 'fieldName2_columnCallback', 'label' => 'Text with Custom Callback'));
        // adds a cloneable textarea field to the 1st group
        x_add_metadata_field('x_fieldTextarea1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'textarea', 'multiple' => true, 'label' => 'Repeatable Text Area'));
        // adds a readonly textarea field to the 1st group
        x_add_metadata_field('x_fieldTextareaReadOnly1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'textarea', 'readonly' => true, 'label' => 'Read Only Text Area'));
        // adds a readonly text field to the 1st group
        x_add_metadata_field('x_fieldTextReadOnly1', 'x_test', array('group' => 'x_metaBox1', 'readonly' => true, 'label' => 'Read Only Text Area'));
        // adds a wysiwyg (full editor) field to the 2nd group
        x_add_metadata_field('x_fieldWysiwyg1', array('x_test', 'user'), array('group' => 'x_metaBox2', 'field_type' => 'wysiwyg', 'label' => 'TinyMCE / Wysiwyg field'));
        // adds a datepicker field to the 1st group
        x_add_metadata_field('x_fieldDatepicker1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'datepicker', 'label' => 'Datepicker field'));
        // adds an upload field to the 1st group
        x_add_metadata_field('x_fieldUpload1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'upload', 'label' => 'Upload field'));
        // adds a checkbox field to the first group
        x_add_metadata_field('x_fieldCheckbox1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'checkbox', 'label' => 'Checkbox field'));
        // adds a radio button field to the first group
        x_add_metadata_field('x_fieldRadio1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'radio', 'values' => array('option1' => 'Option #1', 'option2' => 'Option #2'), 'label' => 'Radio field'));
        // adds a select box in the first group
        x_add_metadata_field('x_fieldSelect1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'select', 'values' => array('option1' => 'Option #1', 'option2' => 'Option #2'), 'label' => 'Select field'));
        // adds a field to posts and users
        x_add_metadata_field('x_fieldName2', array('post', 'user'), array('group' => 'x_metaBox2', 'label' => 'Text field'));
        // adds a field with a custom display callback (see below)
        x_add_metadata_field('x_fieldCustomHidden1', 'x_test', array('group' => 'x_metaBox1', 'display_callback' => 'fieldCustomHidden1_display', 'label' => 'Hidden field'));
        // field with capabilities limited
        x_add_metadata_field('x_cap-limited-field', 'x_test', array('label' => 'Cap Limited Field (edit_posts)', 'required_cap' => 'edit_posts'));
        // field with role limited
        x_add_metadata_field('x_author-cap-limited-field', 'user', array('label' => 'Cap Limited Field (author)', 'required_cap' => 'author'));
        // comment field
        x_add_metadata_field('x_commentField1', 'comment', array('label' => 'Field for Comment', 'display_column' => true));
        // field that exludes posts
        x_add_metadata_field('x_fieldNameExcluded1', 'post', array('description' => 'This field is excluded from Post ID#2476', 'label' => 'Excluded Field', 'exclude' => 2476));
        // field that includes certain posts only
        x_add_metadata_field('x_fieldNameIncluded1', 'post', array('description' => 'This field is only included on Post ID#2476', 'label' => 'Included Field', 'include' => 2476));
    }
}
 public function print_form()
 {
     if (!empty($this->form)) {
         foreach ($this->form as $f) {
             switch ($f['item_type']) {
                 case 'metabox':
                     echo x_add_metadata_group($f['name'], $f['post_type'], $f['fields']);
                     break;
                 case 'field':
                     echo x_add_metadata_field($f['name'], $f['post_type'], $f['fields']);
                     break;
                 case 'multifield':
                     echo x_add_metadata_multifield($f['name'], $f['post_type'], $f['fields']);
                     break;
             }
         }
     }
 }
Esempio n. 4
0
/**
 * Add metadata information for Candela.
 */
function add_meta_boxes()
{
    x_add_metadata_group('candela-book-information', 'metadata', array('label' => __('Candela Book Information', 'pressbooks'), 'priority' => 'high'));
    $fields = array('candela-course-id' => array('label' => __('Course Id')), 'candela-faculty-first-name' => array('label' => __('Faculty First Name')), 'candela-faculty-last-name' => array('label' => __('Faculty Last Name')), 'candela-year' => array('label' => __('Year')), 'candela-semsester' => array('label' => __('Semester'), 'description' => __('')), 'candela-previous-textbook-cost' => array('label' => __('Previous Textbook Cost'), 'description' => __('Previous textbook cost rounded down to the nearest dollar.')));
    foreach ($fields as $key => $info) {
        $info['group'] = 'candela-book-information';
        x_add_metadata_field($key, 'metadata', $info);
    }
    add_meta_box('nav-links', 'Edit Navigation Links', __NAMESPACE__ . '\\nav_links', 'chapter', 'side', 'low');
}
function x_init_custom_fields()
{
    // adds a new group to the test post type
    x_add_metadata_group('x_metaBox1', 'x_test', array('label' => 'Group with Multiple Fields'));
    // adds another group to the test post type + posts + users
    x_add_metadata_group('x_metaBox2', array('x_test', 'post', 'user'), array('label' => 'Group for Post and User', 'description' => "Here's a group with a description!"));
    // adds a text field to the first group
    x_add_metadata_field('x_fieldName1', 'x_test', array('group' => 'x_metaBox1', 'description' => 'This is field #1. It\'s a simple text field.', 'label' => 'Text Field', 'display_column' => true));
    // adds a text field to the 2nd group
    x_add_metadata_field('x_fieldName2', 'x_test', array('group' => 'x_metaBox1', 'display_column' => 'My Column (with Custom Callback)', 'display_column_callback' => 'x_field_name2_callback', 'label' => 'Text with Custom Callback'));
    // adds a cloneable textarea field to the 1st group
    x_add_metadata_field('x_fieldTextarea1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'textarea', 'multiple' => true, 'label' => 'Repeatable Text Area'));
    // adds a readonly textarea field to the 1st group
    x_add_metadata_field('x_fieldTextareaReadOnly1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'textarea', 'readonly' => true, 'label' => 'Read Only Text Area'));
    // adds a readonly text field to the 1st group
    x_add_metadata_field('x_fieldTextReadOnly1', 'x_test', array('group' => 'x_metaBox1', 'readonly' => true, 'label' => 'Read Only Text Area'));
    // adds a wysiwyg (full editor) field to the 2nd group
    x_add_metadata_field('x_fieldWysiwyg1', array('x_test', 'user'), array('group' => 'x_metaBox2', 'field_type' => 'wysiwyg', 'label' => 'TinyMCE / Wysiwyg field'));
    // adds a datepicker field to the 1st group
    x_add_metadata_field('x_fieldDatepicker1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'datepicker', 'label' => 'Datepicker field'));
    // adds a datetimepicker field to the 1st group
    x_add_metadata_field('x_fieldDatetimepicker1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'datetimepicker', 'label' => 'Datetimepicker field'));
    // adds a timepicker field to the 1st group
    x_add_metadata_field('x_fieldTimepicker1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'timepicker', 'label' => 'Timepicker field'));
    // adds an upload field to the 1st group
    x_add_metadata_field('x_fieldUpload1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'upload', 'readonly' => true, 'label' => 'Upload field'));
    // adds a checkbox field to the first group
    x_add_metadata_field('x_fieldCheckbox1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'checkbox', 'label' => 'Checkbox field'));
    // adds a radio button field to the first group
    x_add_metadata_field('x_fieldRadio1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'radio', 'values' => array('option1' => 'Option #1', 'option2' => 'Option #2'), 'label' => 'Radio field'));
    // adds a select box in the first group
    x_add_metadata_field('x_fieldSelect1', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'select', 'values' => array('option1' => 'Option #1', 'option2' => 'Option #2'), 'label' => 'Select field'));
    // adds a multi-select field in the first group
    x_add_metadata_field('x_field_multi_select', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'multi_select', 'values' => array('option1' => 'Option #1', 'option2' => 'Option #2', 'option3' => 'Option #3', 'option4' => 'Option #4'), 'label' => 'Multi Select field'));
    // adds a multi-select field with chosen in the first group
    // note: `select2` and `chosen` args do the exact same (add select2)
    // but for the purposes of testing, we're using chosen here
    x_add_metadata_field('x_field_multi_select_chosen', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'multi_select', 'values' => array('option1' => 'Option #1', 'option2' => 'Option #2', 'option3' => 'Option #3', 'option4' => 'Option #4'), 'label' => 'Multi Select field (with chosen)', 'chosen' => true));
    // adds a select field with select2 in the first group
    x_add_metadata_field('x_field_select_select2', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'select', 'values' => array('option1' => 'Option #1', 'option2' => 'Option #2', 'option3' => 'Option #3', 'option4' => 'Option #4'), 'label' => 'Select field (with select2)', 'select2' => true));
    // adds a taxonomy checkbox field in the first group
    x_add_metadata_field('x_field_taxonomy_checkbox', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'taxonomy_checkbox', 'taxonomy' => 'category', 'label' => 'Category checkbox field'));
    // adds a taxonomy select field in the first group
    x_add_metadata_field('x_field_taxonomy_select', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'taxonomy_select', 'taxonomy' => 'category', 'label' => 'Category select field'));
    // adds a taxonomy multiselect field in the first group
    x_add_metadata_field('x_field_taxonomy_multi_select', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'taxonomy_multi_select', 'taxonomy' => 'category', 'label' => 'Category multiselect field'));
    // adds a taxonomy multiselect w/ select2 field in the first group
    x_add_metadata_field('x_field_taxonomy_multi_select2', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'taxonomy_multi_select', 'taxonomy' => 'category', 'label' => 'Category multiselect w/ select2 field', 'select2' => true));
    // adds a number field in the first group (with no min/max)
    x_add_metadata_field('x_field_number', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'number', 'label' => 'Number field'));
    // adds a number field in the first group (with min/max)
    x_add_metadata_field('x_field_number_with_min_max', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'number', 'min' => '-3', 'max' => '25', 'multiple' => true, 'label' => 'Number field (with min/max + cloneable)'));
    // adds an email field in the first group
    x_add_metadata_field('x_field_email', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'email', 'label' => 'Email field'));
    // adds a link field in the first group
    x_add_metadata_field('x_field_link', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'link', 'label' => 'Link field'));
    // adds a telephone field in the first group (with default value)
    x_add_metadata_field('x_field_telephone', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'tel', 'label' => 'Telephone field', 'default_value' => '123-4567'));
    // adds a text field with a default value
    x_add_metadata_field('x_field_text_default', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'text', 'label' => 'Text field with default value', 'default_value' => 'lorem ipsum'));
    // adds a text field with placeholder
    x_add_metadata_field('x_field_textarea_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'textarea', 'label' => 'Textarea field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds a password field with placeholder
    x_add_metadata_field('x_field_password_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'password', 'label' => 'Password field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds a number field with placeholder
    x_add_metadata_field('x_field_number_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'number', 'label' => 'Number field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds an email field with placeholder
    x_add_metadata_field('x_field_email_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'email', 'label' => 'Email field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds a link field with placeholder
    x_add_metadata_field('x_field_link_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'link', 'label' => 'Link field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds an telephone field with placeholder
    x_add_metadata_field('x_field_telephone_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'tel', 'label' => 'Telephone field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds an upload field with placeholder
    x_add_metadata_field('x_field_upload_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'upload', 'label' => 'Upload field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds an datepicker field with placeholder
    x_add_metadata_field('x_field_datepicker_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'datepicker', 'label' => 'Datepicker field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds a datetimepicker field with placeholder
    x_add_metadata_field('x_field_datetimepicker_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'datetimepicker', 'label' => 'Datetimepicker field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds a timepicker field with placeholder
    x_add_metadata_field('x_field_timepicker_placeholder', 'x_test', array('group' => 'x_metaBox1', 'field_type' => 'timepicker', 'label' => 'Timepicker field with placeholder', 'placeholder' => 'some placeholder text'));
    // adds a mulitifield
    x_add_metadata_multifield('x_test_multifield', 'x_test', array('group' => 'x_metabox1', 'label' => 'Multifield test', 'description' => 'This is a great multifield'));
    // adds a text field to the multifield
    x_add_metadata_field('multifield_field_1', 'x_test', array('group' => 'x_metabox1', 'multifield' => 'x_test_multifield', 'description' => 'This is field #1 of the multifield.', 'label' => 'Text Field', 'field_type' => 'text'));
    // adds an upload text field to the multifield
    x_add_metadata_field('multifield_field_2', 'x_test', array('group' => 'x_metabox1', 'multifield' => 'x_test_multifield', 'description' => 'This is field #2 of the multifield.', 'label' => 'Upload Field', 'field_type' => 'upload'));
    // adds an upload text field to the multifield
    x_add_metadata_field('multifield_field_3', 'x_test', array('group' => 'x_metabox1', 'multifield' => 'x_test_multifield', 'description' => 'This is field #4 of the multifield.', 'label' => 'Telephone Field', 'field_type' => 'tel'));
    // adds a text field to the multifield
    x_add_metadata_field('multifield_field_4', 'x_test', array('group' => 'x_metabox1', 'multifield' => 'x_test_multifield', 'description' => 'This is field #4 of the multifield.', 'label' => 'Password Field', 'field_type' => 'password'));
    // adds a field to posts and users
    x_add_metadata_field('x_fieldName2', array('post', 'user'), array('group' => 'x_metaBox2', 'label' => 'Text field'));
    // adds a field with a custom display callback (see below)
    x_add_metadata_field('x_fieldCustomHidden1', 'x_test', array('group' => 'x_metaBox1', 'display_callback' => 'x_field_customhidden1_callback', 'label' => 'Hidden field'));
    // field with capabilities limited
    x_add_metadata_field('x_cap-limited-field', 'x_test', array('label' => 'Cap Limited Field (edit_posts)', 'required_cap' => 'edit_posts'));
    // field with role limited
    x_add_metadata_field('x_author-cap-limited-field', 'user', array('label' => 'Cap Limited Field (author)', 'required_cap' => 'author'));
    // comment field
    x_add_metadata_field('x_commentField1', 'comment', array('label' => 'Field for Comment', 'display_column' => true));
    // field that exludes posts
    x_add_metadata_field('x_fieldNameExcluded1', 'post', array('description' => 'This field is excluded from Post ID#2476', 'label' => 'Excluded Field', 'exclude' => 2476));
    // field that includes certain posts only
    x_add_metadata_field('x_fieldNameIncluded1', 'post', array('description' => 'This field is only included on Post ID#2476', 'label' => 'Included Field', 'include' => 2476));
    x_add_metadata_field('x_fieldExcludeCallback', 'post', array('description' => 'This field is excluded using a custom callback; will be excluded from posts in the "aside" category', 'label' => 'Excluded Field (with callback)', 'exclude' => 'x_custom_exclude_callback'));
    /**
     *
     *
     * @param unknown $thing_slug  string Slug of the field or group
     * @param unknown $thing       object Field or Group args set up when registering
     * @param unknown $object_type string What type of object (post, comment, user)
     * @param unknown $object_id   int|string ID of the object
     * @param unknown $object_slug string
     */
    function x_custom_exclude_callback($thing_slug, $thing, $object_type, $object_id, $object_slug)
    {
        // exclude from all posts that are in the aside category
        return in_category('aside', $object_id);
    }
    x_add_metadata_field('x_fieldIncludedCallback', 'post', array('description' => 'This field is included using a custom callback; will only be included for posts that are not published', 'label' => 'Included Field (with callback)', 'include' => 'x_custom_include_callback'));
    function x_custom_include_callback($thing_slug, $thing, $object_type, $object_id, $object_slug)
    {
        $post = get_post($object_id);
        return 'publish' != $post->post_status;
    }
}
Esempio n. 6
0
/**
 * Adds some custom fields to user profiles
 */
function add_user_meta()
{
    x_add_metadata_group('profile-information', 'user', array('label' => __('Extra Profile Information', 'pressbooks')));
    x_add_metadata_field('user_interface_lang', 'user', array('group' => 'profile-information', 'field_type' => 'select', 'values' => \PressBooks\L10n\get_dashboard_languages(), 'label' => __('Language', 'pressbooks')));
}
/**
 * Defines Cover Image Attribution metabox
 */
function cover_image_attribution_meta_box()
{
    x_add_metadata_group($group = 'cover-image-attributions', 'metadata', array('label' => __('Cover Image Attributions'), 'priority' => 'low'));
    $fields = array('attribution-type' => array('label' => __('Type'), 'field_type' => 'select', 'values' => array('' => 'Choose citation type', 'original' => 'CC licensed content, Original', 'cc' => 'CC licensed content, Shared previously', 'cc-attribution' => 'CC licensed content, Specific attribution', 'copyrighted_video' => 'All rights reserved content', 'pd' => 'Public domain content', 'lumen' => 'Lumen Learning authored content')), 'attribution-description' => array('label' => __('Description')), 'attribution-author' => array('label' => __('Author')), 'attribution-organization' => array('label' => __('Organization')), 'attribution-url' => array('label' => __('URL')), 'attribution-project' => array('label' => __('Project')), 'attribution-licensing' => array('label' => __('Licensing'), 'field_type' => 'select', 'values' => array('' => 'Choose licensing', 'pd' => 'Public Domain: No Known Copyright', 'cc0' => 'CC0: No Rights Reserved', 'cc-by' => 'CC BY: Attribution', 'cc-by-sa' => 'CC BY-SA: Attribution-ShareAlike', 'cc-by-nd' => 'CC BY-ND: Attribution-NoDerivatives', 'cc-by-nc' => 'CC BY-NC: Attribution-NonCommercial', 'cc-by-nc-sa' => 'CC BY-NC-SA: Attribution-NonCommercial-ShareAlike', 'cc-by-nc-nd' => 'CC BY-NC-ND: Attribution-NonCommercial-NoDerivatives')), 'attribution-license-terms' => array('label' => __('License Terms')));
    render_meta_box_fields($group, $fields);
}
/**
 * Adds some custom fields to user profiles
 */
function add_user_meta()
{
    x_add_metadata_group('profile-information', 'user', array('label' => __('Extra Profile Information', 'pressbooks')));
    x_add_metadata_field('user_interface_lang', 'user', array('group' => 'profile-information', 'field_type' => 'select', 'values' => array('en_US' => __('English', 'pressbooks'), 'zh_TW' => __('Chinese, Traditional', 'pressbooks'), 'et' => __('Estonian', 'pressbooks'), 'fr_FR' => __('French', 'pressbooks'), 'de_DE' => __('German', 'pressbooks'), 'it_IT' => __('Italian', 'pressbooks'), 'ja' => __('Japanese', 'pressbooks'), 'pt_BR' => __('Portuguese, Brazil', 'pressbooks'), 'es_ES' => __('Spanish', 'pressbooks'), 'sv_SE' => __('Swedish', 'pressbooks')), 'label' => __('Language', 'pressbooks')));
}
Esempio n. 9
0
/**
 * Adds some custom fields to user profiles
 */
function add_user_meta()
{
    x_add_metadata_group('profile-information', 'user', array('label' => __('Extra Profile Information', 'pressbooks')));
    x_add_metadata_field('user_interface_lang', 'user', array('group' => 'profile-information', 'field_type' => 'select', 'values' => \Pressbooks\L10n\get_dashboard_languages(), 'label' => __('Language', 'pressbooks'), 'description' => sprintf('<a href="https://www.transifex.com/pressbooks/pressbooks/">%s</a>', __('Help translate Pressbooks into your language!', 'pressbooks'))));
}