PluginProbe
Gallery Box / trunk
Gallery Box vtrunk
trunk 1.3.1 1.3.3 1.4.0 1.4.1 1.4.2 1.5.1 1.7.35
gallery-box / admin / src / cmb2-tabs / example-functions.php

example-functions.php in Gallery Box trunk, at admin/src/cmb2-tabs/example-functions.php

149 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Include and setup custom metaboxes and fields. (make sure you copy this file to outside the CMB2 directory)
4 *
5 * Be sure to replace all instances of 'cmb2_tabs_' with your project's prefix.
6 *
7 * @category WordPress_Plugin
8 * @package Demo_CMB2_Tabs
9 * @license http://www.opensource.org/licenses/gpl-license.php GPL v3.0 (or later)
10 * @link https://github.com/stackadroit/cmb2-extensions
11 */
12
13 /**
14 * Get the bootstrap! If using the plugin from wordpress.org, REMOVE THIS!
15 */
16
17
18 /**
19 * Conditionally displays a metabox when used as a callback in the 'show_on_cb' cmb2_box parameter
20 *
21 * @param CMB2 object $cmb CMB2 object.
22 *
23 * @return bool True if metabox should show
24 */
25 function cmb2_tabs_show_if_front_page($cmb) {
26 // Don't show this metabox if it's not the front page template.
27 if (get_option('page_on_front') !== $cmb->object_id) {
28 return false;
29 }
30 return true;
31 }
32
33
34 add_action('cmb2_admin_init', 'cmb2_tabs_register_demo_metabox');
35
36 /**
37 * Hook in and add a demo metabox. Can only happen on the 'cmb2_admin_init' or 'cmb2_init' hook.
38 */
39 function cmb2_tabs_register_demo_metabox() {
40 $prefix = 'cmb2_tabs_';
41
42 /**
43 * Sample metabox to demonstrate each field type included
44 */
45 $cmb_tabs_demo = new_cmb2_box(array(
46 'id' => $prefix.'metabox',
47 'title' => esc_html__('Test Metabox', 'cmb2_tabs'),
48 'object_types' => array('page'), // Post type
49 'tabs' => array(
50 'contact' => array(
51 'label' => __('Contact', 'cmb2_tabs'),
52 'show_on_cb' => 'cmb2_tabs_show_if_front_page',
53 ),
54 'social' => array(
55 'label' => __('Social Media', 'cmb2_tabs'),
56 'icon' => 'dashicons-share', // Dashicon
57 ),
58 'note' => array(
59 'label' => __('Note', 'cmb2_tabs'),
60 'icon' => 'dashicons-sos', // Custom icon, using image
61 ),
62 ),
63 // 'show_on_cb' => 'cmb2_tabs_show_if_front_page', // function should return a bool value
64 // 'context' => 'normal',
65 // 'priority' => 'high',
66 // 'show_names' => true, // Show field names on the left
67 // 'cmb_styles' => false, // false to disable the CMB stylesheet
68 // 'closed' => true, // true to keep the metabox closed by default
69 // 'classes' => 'extra-class', // Extra cmb2-wrap classes
70 ));
71
72
73
74 /*******************GROUPS**************************/
75 $group_field_id = $cmb_tabs_demo->add_field( array(
76 'id' => 'wiki_test_repeat_group',
77 'type' => 'group',
78 'description' => __( 'Generates reusable form entries', 'cmb2_tabs' ),
79 'tab' => 'note',
80 'render_row_cb' => array('CMB2_Tabs', 'tabs_render_group_row_cb'),
81 // 'repeatable' => false, // use false if you want non-repeatable group
82 'options' => array(
83 'group_title' => __( 'Entry {#}', 'cmb2_tabs' ), // since version 1.1.4, {#} gets replaced by row number
84 'add_button' => __( 'Add Another Entry', 'cmb2_tabs' ),
85 'remove_button' => __( 'Remove Entry', 'cmb2_tabs' ),
86 'sortable' => true, // beta
87 // 'closed' => true, // true to have the groups closed by default
88 ),
89 ) );
90
91 // Id's for group's fields only need to be unique for the group. Prefix is not needed.
92 $cmb_tabs_demo->add_group_field( $group_field_id, array(
93 'name' => __( 'Entry Title', 'cmb2_tabs' ),
94 'id' => 'title',
95 'type' => 'text',
96 // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
97 ) );
98
99 /*******************GROUPS**************************/
100 $group_field_id = $cmb_tabs_demo->add_field( array(
101 'id' => 'wiki_test_repeat_group',
102 'type' => 'group',
103 'description' => __( 'Generates reusable form entries', 'cmb2_tabs' ),
104 'tab' => 'note',
105 'render_row_cb' => array('CMB2_Tabs', 'tabs_render_group_row_cb'),
106 // 'repeatable' => false, // use false if you want non-repeatable group
107 'options' => array(
108 'group_title' => __( 'Entry {#}', 'cmb2_tabs' ), // since version 1.1.4, {#} gets replaced by row number
109 'add_button' => __( 'Add Another Entry', 'cmb2_tabs' ),
110 'remove_button' => __( 'Remove Entry', 'cmb2_tabs' ),
111 'sortable' => true, // beta
112 // 'closed' => true, // true to have the groups closed by default
113 ),
114 ) );
115
116 // Id's for group's fields only need to be unique for the group. Prefix is not needed.
117 $cmb_tabs_demo->add_group_field( $group_field_id, array(
118 'name' => __( 'Entry Title', 'cmb2_tabs' ),
119 'id' => 'title',
120 'type' => 'text',
121 // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
122 ) ); /*******************GROUPS**************************/
123 $group_field_id2 = $cmb_tabs_demo->add_field( array(
124 'id' => 'wiki_test_repeat_group1',
125 'type' => 'group',
126 'description' => __( 'Generates reusable form entries', 'cmb2_tabs' ),
127 'tab' => 'note',
128 'render_row_cb' => array('CMB2_Tabs', 'tabs_render_group_row_cb'),
129 // 'repeatable' => false, // use false if you want non-repeatable group
130 'options' => array(
131 'group_title' => __( 'Entry {#}', 'cmb2_tabs' ), // since version 1.1.4, {#} gets replaced by row number
132 'add_button' => __( 'Add Another Entry', 'cmb2_tabs' ),
133 'remove_button' => __( 'Remove Entry', 'cmb2_tabs' ),
134 'sortable' => true, // beta
135 // 'closed' => true, // true to have the groups closed by default
136 ),
137 ) );
138
139 // Id's for group's fields only need to be unique for the group. Prefix is not needed.
140 $cmb_tabs_demo->add_group_field( $group_field_id2, array(
141 'name' => __( 'Entry Title', 'cmb2_tabs' ),
142 'id' => 'title',
143 'type' => 'text',
144 // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
145 ) );
146
147 }
148
149