forked from gambitph/Titan-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-option-select-pages.php
59 lines (48 loc) · 1.48 KB
/
class-option-select-pages.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
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class TitanFrameworkOptionSelectPages extends TitanFrameworkOption {
public $defaultSecondarySettings = array(
'default' => '0', // show this when blank
);
private static $allPages;
/*
* Display for options and meta
*/
public function display() {
$this->echoOptionHeader();
// Remember the pages so as not to perform any more lookups
if ( ! isset( self::$allPages ) ) {
self::$allPages = get_pages();
}
echo "<select name='" . esc_attr( $this->getID() ) . "'>";
// The default value (nothing is selected)
printf( "<option value='%s' %s>%s</option>",
'0',
selected( $this->getValue(), '0', false ),
"— " . __( "Select", TF_I18NDOMAIN ) . " —"
);
// Print all the other pages
foreach ( self::$allPages as $page ) {
printf( "<option value='%s' %s>%s</option>",
esc_attr( $page->ID ),
selected( $this->getValue(), $page->ID, false ),
$page->post_title
);
}
echo "</select>";
$this->echoOptionFooter();
}
/*
* Display for theme customizer
*/
public function registerCustomizerControl( $wp_customize, $section, $priority = 1 ) {
$wp_customize->add_control( new TitanFrameworkCustomizeControl( $wp_customize, $this->getID(), array(
'label' => $this->settings['name'],
'section' => $section->settings['id'],
'settings' => $this->getID(),
'type' => 'dropdown-pages',
'description' => $this->settings['desc'],
'priority' => $priority,
) ) );
}
}