-
Notifications
You must be signed in to change notification settings - Fork 0
/
metaboxes.php
executable file
·73 lines (64 loc) · 2.11 KB
/
metaboxes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Include and setup custom metaboxes and fields. (make sure you copy this file to outside the CMB directory)
*
* @category YourThemeOrPlugin
* @package Metaboxes
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* @link https://github.com/webdevstudios/Custom-Metaboxes-and-Fields-for-WordPress
*/
/**
* Get the bootstrap! If using the plugin from wordpress.org, REMOVE THIS!
*/
if ( file_exists( __DIR__ . '/cmb2/init.php' ) ) {
require_once __DIR__ . '/cmb2/init.php';
} elseif ( file_exists( __DIR__ . '/CMB2/init.php' ) ) {
require_once __DIR__ . '/CMB2/init.php';
}
/**
* Conditionally displays a field when used as a callback in the 'show_on_cb' field parameter
*
* @param CMB2_Field object $field Field object
*
* @return bool True if metabox should show
*/
function cmb2_hide_if_no_cats( $field ) {
// Don't show this field if not in the cats category
if ( ! has_tag( 'cats', $field->object_id ) ) {
return false;
}
return true;
}
add_filter( 'cmb2_meta_boxes', 'cmb2_sample_metaboxes' );
/**
* Define the metabox and field configurations.
*
* @param array $meta_boxes
* @return array
*/
function cmb2_sample_metaboxes( array $meta_boxes ) {
// Start with an underscore to hide fields from custom fields list
$prefix = '_cmb2_';
/**
* Metabox to be displayed on a single page ID
*/
$meta_boxes['home_page_metabox'] = array(
'id' => 'about_page_metabox',
'title' => __( 'About Page Metabox', 'cmb2' ),
'object_types' => array( 'page', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'show_on' => array( 'id' => array( 2, ) ), // Specific post IDs to display this metabox
'fields' => array(
array(
'name' => __( 'Test Text', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => $prefix . '_about_test_text',
'type' => 'text',
),
)
);
// Add other metaboxes as needed
return $meta_boxes;
}