forked from cloudwebteam/WP-Misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-features.php
48 lines (45 loc) · 1.33 KB
/
page-features.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
$features = array(
'feature_slug' => array(
// field spec
),
'feature2_slug' => array(
// field spec
)
);
$features_field = array(
'title' => 'Page Features',
'type' => 'checkbox',
'options' => array_fill_keys( array_keys( $features ), '' )
);
/* ==== PAGE ============================================= */
$Forms->add_metabox( array( 'post_type' => 'page' ), 'page-info', array(
'fields' => array(
// other fields can go here.
'---enabled_features' => 'Enabled Features',
'features' => $features_field
)
));
/* ==== ENABLED FEATURES ============================================= */
$features_to_add = false;
if ( is_admin() && $Forms->wp_context_matches( array( 'post_type' => 'page' )) && !empty( $_GET['post'] )) {
if( $enabled_features = get_metabox_options( $_GET['post'], "page-info", "features" ) ){
$features_to_add = array_intersect_key( $features, $enabled_features );
}
} else {
$features_to_add = $features;
}
if ( $features_to_add ){
foreach( $features_to_add as $slug => $feature_to_add ){
$features_to_add[$slug]['description'] = '['.$slug.'] <-- to insert on page';
}
$Forms->add_metabox( array( 'post_type' => 'page'), 'page_features', array(
'defaults' => array(
'field' => array(
'layout' => array(
'title', 'description', 'input', 'error'
)
)
),
'fields' => $features_to_add
));
}