-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerm_UI.php
More file actions
128 lines (110 loc) · 2.48 KB
/
Copy pathTerm_UI.php
File metadata and controls
128 lines (110 loc) · 2.48 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* Term_UI class.
*
* @package Schedule_Terms
*/
namespace Torounit\WP\Schedule_Terms;
use Torounit\WP\Schedule_Terms\Term\UI;
/**
* Term meta UI controller.
*/
class Term_UI extends UI {
/**
* Plugin version.
*
* @var string
*/
public $version = '2.0.0';
/**
* Database version.
*
* @var string
*/
public $db_version = 202204190000;
/**
* Metadata key.
*
* @var string
*/
public $meta_key = '';
/**
* Constrouctor.
*
* @param string $file Plugin file.
* @param string $meta_key Metadata key.
*/
public function __construct( $file, string $meta_key ) {
$this->meta_key = $meta_key;
$this->labels = array(
'singular' => esc_html__( 'Enable scheduling', 'schedule-posts' ),
);
parent::__construct( $file );
}
/**
* Enqueue scripts.
*/
public function enqueue_scripts() {
$asset_file = include plugin_dir_path( __DIR__ ) . 'build/admin.asset.php';
foreach ( $asset_file['dependencies'] as $style ) {
wp_enqueue_style( $style );
}
wp_enqueue_script(
'schedule-terms-admin',
plugins_url( 'build/admin.js', __DIR__ ),
$asset_file['dependencies'],
$asset_file['version'],
true
);
wp_set_script_translations( 'schedule-terms-admin', 'schedule-terms' );
}
/**
* Output.
*
* @param mixed $meta term meta.
*/
protected function format_output( $meta ): string {
ob_start();
if ( $meta ) {
?>
<span data-schedule-terms-active><?php esc_html_e( 'Scheduling', 'schedule-posts' ); ?></span>
<?php
}
$contents = ob_get_contents();
ob_end_clean();
if ( ! $contents ) {
return '';
}
return $contents;
}
/**
* Output the form field
*
* @param \WP_Term|null $term term meta.
*/
protected function form_field( $term = null ) {
$value = isset( $term->term_id )
? $this->get_meta( $term->term_id )
: '';
?>
<label for="term-<?php echo esc_attr( $this->meta_key ); ?>">
<input
type="checkbox"
name="term-<?php echo esc_attr( $this->meta_key ); ?>"
id="term-<?php echo esc_attr( $this->meta_key ); ?>"
<?php checked( (bool) $value, true, true ); ?>
/>
<?php esc_html_e( 'Automatically attach or detach this term on schedule.', 'schedule-posts' ); ?>
</label>
<?php
}
/**
* Output the form field
*/
protected function quick_edit_form_field() {
?>
<input type="checkbox" name="term-<?php echo esc_attr( $this->meta_key ); ?>">
<?php esc_html_e( 'Automatically attach or detach this term on schedule.', 'schedule-posts' ); ?>
<?php
}
}