This repository was archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathclass-wp-customize-posts-panel.php
More file actions
119 lines (110 loc) · 3.33 KB
/
class-wp-customize-posts-panel.php
File metadata and controls
119 lines (110 loc) · 3.33 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
<?php
/**
* Customize Posts Panel
*
* @package WordPress
* @subpackage Customize
*/
/**
* Class WP_Customize_Posts_Panel
*/
class WP_Customize_Posts_Panel extends WP_Customize_Panel {
const TYPE = 'posts';
/**
* Type of control, used by JS.
*
* @access public
* @var string
*/
public $type = self::TYPE;
/**
* Post type.
*
* @access public
* @var string
*/
public $post_type;
/**
* Constructor.
*
* Any supplied $args override class property defaults.
*
* @throws Exception If there are bad arguments.
*
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
* @param string $id An specific ID for the panel.
* @param array $args Panel arguments.
*/
public function __construct( WP_Customize_Manager $manager, $id, array $args ) {
if ( empty( $args['post_type'] ) ) {
throw new Exception( 'Missing post_type' );
}
if ( sprintf( 'posts[%s]', $args['post_type'] ) !== $id ) {
throw new Exception( 'Bad ID.' );
}
if ( ! post_type_exists( $args['post_type'] ) ) {
throw new Exception( 'Unrecognized post_type' );
}
parent::__construct( $manager, $id, $args );
}
/**
* Render the panel's JS templates.
*
* This function is only run for panel types that have been registered with
* WP_Customize_Manager::register_panel_type().
*
* @see WP_Customize_Manager::register_panel_type()
*/
public function print_template() {
?>
<script type="text/html" id="tmpl-customize-posts-<?php echo esc_attr( $this->post_type ); ?>-panel-actions">
<li class="customize-posts-panel-actions">
<select class="post-selection-lookup"></select>
<# if ( data.can_create_posts ) { #>
<button class="button-secondary add-new-post-stub">
<span class="screen-reader-text">
{{ data.add_new_post_label }}
</span>
</button>
<# } #>
</li>
</script>
<script type="text/html" id="tmpl-customize-posts-<?php echo esc_attr( $this->post_type ); ?>-panel-select2-selection-item">
<# if ( ! data.id ) { // placeholder #>
{{ data.text }}
<# } else { #>
<em><?php esc_html_e( 'Loading “{{ data.text }}”…', 'customize-posts' ); ?></em>
<# } #>
</script>
<script type="text/html" id="tmpl-customize-posts-<?php echo esc_attr( $this->post_type ); ?>-panel-select2-result-item">
<# if ( data.featured_image && data.featured_image.sizes && data.featured_image.sizes.thumbnail && data.featured_image.sizes.thumbnail.url ) { #>
<img class="customize-posts-select2-thumbnail" src="{{ data.featured_image.sizes.thumbnail.url }}">
<# } #>
<# if ( data.status && 'trash' === data.status ) { #>
<em><?php esc_html_e( '[Trashed]', 'customize-posts' ); ?></em>
<span class="trashed-title">{{ data.title }}</span>
<# } else if ( data.text ) { #>
{{ data.text }}
<# } else { #>
<em><?php esc_html_e( '(No title)', 'customize-posts' ); ?></em>
<# } #>
</script>
<script id="tmpl-customize-panel-posts-<?php echo esc_attr( $this->post_type ); ?>-notice" type="text/html">
<div class="customize-posts-panel-notice">
<em>{{ data.message }}</em>
</div>
</script>
<?php
parent::print_template();
}
/**
* Export data to JS.
*
* @return array
*/
public function json() {
$data = parent::json();
$data['post_type'] = $this->post_type;
return $data;
}
}