forked from Automattic/babble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-meta.php
99 lines (77 loc) · 2.1 KB
/
class-meta.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* Class for handling post meta translations.
*
* @package Babble
* @since 1.5
*/
abstract class Babble_Meta_Field {
public function __construct( WP_Post $post, $meta_key, $meta_title, array $args = array() ) {
$this->post = $post;
$this->meta_key = $meta_key;
$this->meta_title = $meta_title;
$this->meta_value = get_post_meta( $this->post->ID, $this->meta_key, true );
$this->args = $args;
}
abstract public function get_input( $name, $value );
public function get_output() {
return esc_html( $this->get_value() );
}
public function get_title() {
return $this->meta_title;
}
public function get_value() {
return $this->meta_value;
}
public function get_key() {
return $this->meta_key;
}
public function update( $value, WP_Post $job ) {
return $value;
}
}
class Babble_Meta_Field_Text extends Babble_Meta_Field {
public function get_input( $name, $value ) {
return sprintf( '<input type="text" name="%s" value="%s">',
esc_attr( $name ),
esc_attr( $value )
);
}
}
class Babble_Meta_Field_Textarea extends Babble_Meta_Field {
public function get_input( $name, $value ) {
return sprintf( '<textarea name="%s" rows="10">%s</textarea>',
esc_attr( $name ),
esc_textarea( $value )
);
}
public function get_output() {
return nl2br( esc_html( $this->get_value() ) );
}
}
class Babble_Meta_Field_Editor extends Babble_Meta_Field {
public function get_input( $name, $value ) {
$args = array(
'textarea_name' => $name,
);
# see _WP_Editors()::parse_settings() for available editor settings
if ( !empty( $this->args['editor_settings'] ) ) {
$args = array_merge( $args, $this->args['editor_settings'] );
}
ob_start();
wp_editor( $value, sprintf( 'meta-input-%s', $this->get_key() ), $args );
return ob_get_clean();
}
public function get_output() {
$args = array(
'textarea_name' => 'doesnotmatter',
'media_buttons' => false,
'tinymce' => array(
'readonly' => 1,
),
);
ob_start();
wp_editor( $this->get_value(), sprintf( 'meta-output-%s', $this->get_key() ), $args );
return ob_get_clean();
}
}