Last active
February 23, 2018 21:07
-
-
Save hellofromtonya/40896d067218a28cca7cae3e79e22ab1 to your computer and use it in GitHub Desktop.
Testing Beans Fields API for post meta.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'admin_init', 'beans_child_test_fields' ); | |
/** | |
* Test the Fields API for post meta. | |
* | |
* @since 1.5.0 | |
* | |
* @return void | |
*/ | |
function beans_child_test_fields() { | |
$beans_uri = get_template_directory_uri(); | |
// Christoph, you'll need to add a featured image to the Hello World! post. | |
$image_id = (int) get_post_thumbnail_id( 1, 'thumbnail' ); | |
$fields = array( | |
array( | |
'id' => 'beans_test_slider', | |
'label' => 'Test Slider', | |
'description' => 'Testing the slider', | |
'type' => 'slider', | |
'default' => 40, | |
'min' => 0, | |
'max' => 100, | |
'interval' => 1, | |
'unit' => 'Percentage complete', // Adds this text after the current value. | |
), | |
array( | |
'id' => 'beans_test_radio_with_images', | |
'label' => 'Layout', | |
'description' => 'The layout to select', | |
'type' => 'radio', | |
'default' => 'default_fallback', | |
'options' => array( | |
'default_fallback' => 'Use Default Layout', | |
'c' => array( | |
'src' => $beans_uri . '/lib/admin/assets/images/layouts/c.png', | |
'alt' => 'Full width content layout', | |
'screen_reader_text' => 'Select the full width content layout', | |
), | |
'c_sp' => array( | |
'src' => $beans_uri . '/lib/admin/assets/images/layouts/cs.png', | |
'alt' => 'Content + Sidebar Primary Layout', | |
'screen_reader_text' => 'Select the content and sidebar primary layout', | |
), | |
'sp_c' => array( | |
'src' => $beans_uri . '/lib/admin/assets/images/layouts/sc.png', | |
'alt' => 'Sidebar Primary + Content Layout', | |
'screen_reader_text' => 'Select the sidebar primary and content layout', | |
), | |
), | |
), | |
array( | |
'id' => 'beans_text_test', | |
'type' => 'text', | |
'label' => 'Testing the text field.', | |
'default' => '', | |
), | |
array( | |
'id' => 'beans_textarea_test', | |
'type' => 'textarea', | |
'label' => 'Testing the textarea field.', | |
'default' => '', | |
), | |
array( | |
'id' => 'beans_radio_test', | |
'label' => 'Radio buttons', | |
'description' => 'Radio buttons', | |
'type' => 'radio', | |
'default' => 'no', | |
'options' => array( | |
'no' => 'No', | |
'yes' => 'Yes', | |
), | |
), | |
array( | |
'id' => 'beans_image_test', | |
'type' => 'image', | |
'label' => 'Image Test', | |
'default' => $image_id, | |
), | |
); | |
beans_register_post_meta( $fields, array( 'post' ), 'beans_single_test', array( 'title' => 'Testing Single Fields' ) ); | |
$fields = array( | |
array( | |
'id' => 'beans_group_test', | |
'label' => 'Group of fields', | |
'description' => 'This is a group of fields.', | |
'type' => 'group', | |
'fields' => array( | |
array( | |
'id' => 'beans_group_activation_test', | |
'label' => 'Activate', | |
'type' => 'activation', | |
'default' => false, | |
), | |
array( | |
'id' => 'beans_group_select_test', | |
'label' => 'Select', | |
'type' => 'select', | |
'default' => 'aggressive', | |
'attributes' => array( 'style' => 'margin: -3px 0 0 -8px;' ), | |
'options' => array( | |
'aggressive' => 'Aggressive', | |
'standard' => 'Standard', | |
), | |
), | |
array( | |
'id' => 'beans_group_checkbox_test', | |
'label' => false, | |
'checkbox_label' => 'Enable the checkbox test', | |
'type' => 'checkbox', | |
'default' => false, | |
), | |
), | |
), | |
); | |
beans_register_post_meta( $fields, array( 'post' ), 'beans_group_test', array( 'title' => 'Testing a Group of Fields' ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment