forked from gambitph/Titan-Framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-option-text.php
55 lines (48 loc) · 1.53 KB
/
class-option-text.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
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class TitanFrameworkOptionText extends TitanFrameworkOption {
public $defaultSecondarySettings = array(
'placeholder' => '', // show this when blank
'is_password' => false,
'sanitize_callbacks' => array(),
'maxlength' => '',
'unit' => ''
);
/*
* Display for options and meta
*/
public function display() {
$this->echoOptionHeader();
printf("<input class=\"regular-text\" name=\"%s\" placeholder=\"%s\" maxlength=\"%s\" id=\"%s\" type=\"%s\" value=\"%s\"\> %s",
$this->getID(),
$this->settings['placeholder'],
$this->settings['maxlength'],
$this->getID(),
$this->settings['is_password'] ? 'password' : 'text',
esc_attr( $this->getValue() ),
$this->settings['unit']
);
$this->echoOptionFooter();
}
public function cleanValueForSaving( $value ){
$value = sanitize_text_field( $value );
if( !empty( $this->settings['sanitize_callbacks'] ) ){
foreach( $this->settings['sanitize_callbacks'] as $callback ){
$value = call_user_func_array( $callback, array( $value, $this ) );
}
}
return $value;
}
/*
* 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(),
'description' => $this->settings['desc'],
'priority' => $priority,
) ) );
}
}