forked from gambitph/Titan-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-option-select-post-types.php
62 lines (49 loc) · 1.44 KB
/
class-option-select-post-types.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
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly
}
class TitanFrameworkOptionSelectPostTypes extends TitanFrameworkOptionSelect {
public $defaultSecondarySettings = array(
'default' => '0', // show this when blank
'public' => true,
'value' => 'all',
'slug' => true,
);
/**
* Creates the options for the select input. Puts the options in $this->settings['options']
*
* @since 1.11
*
* @return void
*/
public function create_select_options() {
// Fetch post types.
$post_types = tf_get_post_types( $this->settings['public'], $this->settings['value'] );
$this->settings['options'] = array(
'' => '— ' . __( 'Select', TF_I18NDOMAIN ) . ' —'
);
// Print all the other pages
foreach ( $post_types as $post_type ) {
if ( ! empty( $post_type->labels->singular_name ) ) {
$slugname = true == $this->settings['slug'] ? ' (' . $post_type->name . ')' : '';
$name = $post_type->labels->singular_name . $slugname;
} else {
$name = $post_type->name;
}
$this->settings['options'][ $post_type->name ] = $name;
}
}
/*
* Display for options and meta
*/
public function display() {
$this->create_select_options();
parent::display();
}
/*
* Display for theme customizer
*/
public function registerCustomizerControl( $wp_customize, $section, $priority = 1 ) {
$this->create_select_options();
parent::registerCustomizerControl( $wp_customize, $section, $priority );
}
}