author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
permissions | -rw-r--r-- |
5 | 1 |
<?php |
2 |
/** |
|
3 |
* Custom Widget for displaying specific post formats |
|
4 |
* |
|
5 |
* Displays posts from Aside, Quote, Video, Audio, Image, Gallery, and Link formats. |
|
6 |
* |
|
7 |
* @link https://codex.wordpress.org/Widgets_API#Developing_Widgets |
|
8 |
* |
|
9 |
* @package WordPress |
|
10 |
* @subpackage Twenty_Fourteen |
|
11 |
* @since Twenty Fourteen 1.0 |
|
12 |
*/ |
|
13 |
||
14 |
class Twenty_Fourteen_Ephemera_Widget extends WP_Widget { |
|
15 |
||
16 |
/** |
|
17 |
* The supported post formats. |
|
18 |
* |
|
19 |
* @since Twenty Fourteen 1.0 |
|
20 |
* |
|
21 |
* @var array |
|
22 |
*/ |
|
23 |
private $formats = array( 'aside', 'image', 'video', 'audio', 'quote', 'link', 'gallery' ); |
|
24 |
||
25 |
/** |
|
26 |
* Constructor. |
|
27 |
* |
|
28 |
* @since Twenty Fourteen 1.0 |
|
29 |
* |
|
30 |
* @return Twenty_Fourteen_Ephemera_Widget |
|
31 |
*/ |
|
32 |
public function __construct() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
parent::__construct( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
'widget_twentyfourteen_ephemera', __( 'Twenty Fourteen Ephemera', 'twentyfourteen' ), array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
'classname' => 'widget_twentyfourteen_ephemera', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
'description' => __( 'Use this widget to list your recent Aside, Quote, Video, Audio, Image, Gallery, and Link posts.', 'twentyfourteen' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
'customize_selective_refresh' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
* Enqueue scripts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
* @since Twenty Fourteen 1.7 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
public function enqueue_scripts() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
/** This filter is documented in wp-includes/media.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
$audio_library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
/** This filter is documented in wp-includes/media.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
$video_library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
if ( in_array( 'mediaelement', array( $video_library, $audio_library ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
wp_enqueue_style( 'wp-mediaelement' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
wp_enqueue_script( 'mediaelement-vimeo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
wp_enqueue_script( 'wp-mediaelement' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
} |
5 | 61 |
} |
62 |
||
63 |
/** |
|
64 |
* Output the HTML for this widget. |
|
65 |
* |
|
66 |
* @since Twenty Fourteen 1.0 |
|
67 |
* |
|
68 |
* @param array $args An array of standard parameters for widgets in this theme. |
|
69 |
* @param array $instance An array of settings for this widget instance. |
|
70 |
*/ |
|
71 |
public function widget( $args, $instance ) { |
|
72 |
$format = isset( $instance['format'] ) && in_array( $instance['format'], $this->formats ) ? $instance['format'] : 'aside'; |
|
73 |
||
74 |
switch ( $format ) { |
|
75 |
case 'image': |
|
76 |
$format_string = __( 'Images', 'twentyfourteen' ); |
|
77 |
$format_string_more = __( 'More images', 'twentyfourteen' ); |
|
78 |
break; |
|
79 |
case 'video': |
|
80 |
$format_string = __( 'Videos', 'twentyfourteen' ); |
|
81 |
$format_string_more = __( 'More videos', 'twentyfourteen' ); |
|
82 |
break; |
|
83 |
case 'audio': |
|
84 |
$format_string = __( 'Audio', 'twentyfourteen' ); |
|
85 |
$format_string_more = __( 'More audio', 'twentyfourteen' ); |
|
86 |
break; |
|
87 |
case 'quote': |
|
88 |
$format_string = __( 'Quotes', 'twentyfourteen' ); |
|
89 |
$format_string_more = __( 'More quotes', 'twentyfourteen' ); |
|
90 |
break; |
|
91 |
case 'link': |
|
92 |
$format_string = __( 'Links', 'twentyfourteen' ); |
|
93 |
$format_string_more = __( 'More links', 'twentyfourteen' ); |
|
94 |
break; |
|
95 |
case 'gallery': |
|
96 |
$format_string = __( 'Galleries', 'twentyfourteen' ); |
|
97 |
$format_string_more = __( 'More galleries', 'twentyfourteen' ); |
|
98 |
break; |
|
99 |
case 'aside': |
|
100 |
default: |
|
101 |
$format_string = __( 'Asides', 'twentyfourteen' ); |
|
102 |
$format_string_more = __( 'More asides', 'twentyfourteen' ); |
|
103 |
break; |
|
104 |
} |
|
105 |
||
106 |
$number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] ); |
|
107 |
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $format_string : $instance['title'], $instance, $this->id_base ); |
|
108 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
$ephemera = new WP_Query( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
'order' => 'DESC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
'posts_per_page' => $number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
'no_found_rows' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
'post_status' => 'publish', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
'post__not_in' => get_option( 'sticky_posts' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
'tax_query' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
'taxonomy' => 'post_format', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
'terms' => array( "post-format-$format" ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
'field' => 'slug', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
'operator' => 'IN', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
), |
5 | 123 |
), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
); |
5 | 126 |
|
127 |
if ( $ephemera->have_posts() ) : |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
$tmp_content_width = $GLOBALS['content_width']; |
5 | 129 |
$GLOBALS['content_width'] = 306; |
130 |
||
131 |
echo $args['before_widget']; |
|
132 |
?> |
|
133 |
<h1 class="widget-title <?php echo esc_attr( $format ); ?>"> |
|
134 |
<a class="entry-format" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>"><?php echo esc_html( $title ); ?></a> |
|
135 |
</h1> |
|
136 |
<ol> |
|
137 |
||
138 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
while ( $ephemera->have_posts() ) : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
$ephemera->the_post(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
$tmp_more = $GLOBALS['more']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
$GLOBALS['more'] = 0; |
5 | 143 |
?> |
144 |
<li> |
|
145 |
<article <?php post_class(); ?>> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
<div class="entry-content"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
if ( has_post_format( 'gallery' ) ) : |
5 | 149 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
if ( post_password_required() ) : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
else : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
$images = array(); |
5 | 154 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
$galleries = get_post_galleries( get_the_ID(), false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
if ( isset( $galleries[0]['ids'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
$images = explode( ',', $galleries[0]['ids'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
} |
5 | 159 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
if ( ! $images ) : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
$images = get_posts( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
'fields' => 'ids', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
'numberposts' => -1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
'order' => 'ASC', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
'orderby' => 'menu_order', |
5 | 167 |
'post_mime_type' => 'image', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
'post_parent' => get_the_ID(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
'post_type' => 'attachment', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
endif; |
5 | 173 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
$total_images = count( $images ); |
5 | 175 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
if ( has_post_thumbnail() ) : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
$post_thumbnail = get_the_post_thumbnail(); |
5 | 178 |
elseif ( $total_images > 0 ) : |
179 |
$image = reset( $images ); |
|
180 |
$post_thumbnail = wp_get_attachment_image( $image, 'post-thumbnail' ); |
|
181 |
endif; |
|
182 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
if ( ! empty( $post_thumbnail ) ) : |
5 | 184 |
?> |
185 |
<a href="<?php the_permalink(); ?>"><?php echo $post_thumbnail; ?></a> |
|
186 |
<?php endif; ?> |
|
187 |
<p class="wp-caption-text"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
printf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
_n( 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photo</a>.', 'This gallery contains <a href="%1$s" rel="bookmark">%2$s photos</a>.', $total_images, 'twentyfourteen' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
esc_url( get_permalink() ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
number_format_i18n( $total_images ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
?> |
5 | 195 |
</p> |
196 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
endif; |
5 | 198 |
|
199 |
else : |
|
200 |
the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyfourteen' ) ); |
|
201 |
endif; |
|
202 |
?> |
|
203 |
</div><!-- .entry-content --> |
|
204 |
||
205 |
<header class="entry-header"> |
|
206 |
<div class="entry-meta"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
if ( ! has_post_format( 'link' ) ) : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
endif; |
5 | 211 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
printf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
'<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
esc_url( get_permalink() ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
esc_attr( get_the_date( 'c' ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
esc_html( get_the_date() ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
get_the_author() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
); |
5 | 220 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : |
5 | 222 |
?> |
223 |
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyfourteen' ), __( '1 Comment', 'twentyfourteen' ), __( '% Comments', 'twentyfourteen' ) ); ?></span> |
|
224 |
<?php endif; ?> |
|
225 |
</div><!-- .entry-meta --> |
|
226 |
</header><!-- .entry-header --> |
|
227 |
</article><!-- #post-## --> |
|
228 |
</li> |
|
229 |
<?php endwhile; ?> |
|
230 |
||
231 |
</ol> |
|
232 |
<a class="post-format-archive-link" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>"> |
|
233 |
<?php |
|
234 |
/* translators: used with More archives link */ |
|
235 |
printf( __( '%s <span class="meta-nav">→</span>', 'twentyfourteen' ), $format_string_more ); |
|
236 |
?> |
|
237 |
</a> |
|
238 |
<?php |
|
239 |
||
240 |
echo $args['after_widget']; |
|
241 |
||
242 |
// Reset the post globals as this query will have stomped on it. |
|
243 |
wp_reset_postdata(); |
|
244 |
||
245 |
$GLOBALS['more'] = $tmp_more; |
|
246 |
$GLOBALS['content_width'] = $tmp_content_width; |
|
247 |
||
248 |
endif; // End check for ephemeral posts. |
|
249 |
} |
|
250 |
||
251 |
/** |
|
252 |
* Deal with the settings when they are saved by the admin. |
|
253 |
* |
|
254 |
* Here is where any validation should happen. |
|
255 |
* |
|
256 |
* @since Twenty Fourteen 1.0 |
|
257 |
* |
|
258 |
* @param array $new_instance New widget instance. |
|
259 |
* @param array $instance Original widget instance. |
|
260 |
* @return array Updated widget instance. |
|
261 |
*/ |
|
262 |
function update( $new_instance, $instance ) { |
|
263 |
$instance['title'] = strip_tags( $new_instance['title'] ); |
|
264 |
$instance['number'] = empty( $new_instance['number'] ) ? 2 : absint( $new_instance['number'] ); |
|
265 |
if ( in_array( $new_instance['format'], $this->formats ) ) { |
|
266 |
$instance['format'] = $new_instance['format']; |
|
267 |
} |
|
268 |
||
269 |
return $instance; |
|
270 |
} |
|
271 |
||
272 |
/** |
|
273 |
* Display the form for this widget on the Widgets page of the Admin area. |
|
274 |
* |
|
275 |
* @since Twenty Fourteen 1.0 |
|
276 |
* |
|
277 |
* @param array $instance |
|
278 |
*/ |
|
279 |
function form( $instance ) { |
|
280 |
$title = empty( $instance['title'] ) ? '' : esc_attr( $instance['title'] ); |
|
281 |
$number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] ); |
|
282 |
$format = isset( $instance['format'] ) && in_array( $instance['format'], $this->formats ) ? $instance['format'] : 'aside'; |
|
283 |
?> |
|
284 |
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'twentyfourteen' ); ?></label> |
|
285 |
<input id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>"></p> |
|
286 |
||
287 |
<p><label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( 'Number of posts to show:', 'twentyfourteen' ); ?></label> |
|
288 |
<input id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="text" value="<?php echo esc_attr( $number ); ?>" size="3"></p> |
|
289 |
||
290 |
<p><label for="<?php echo esc_attr( $this->get_field_id( 'format' ) ); ?>"><?php _e( 'Post format to show:', 'twentyfourteen' ); ?></label> |
|
291 |
<select id="<?php echo esc_attr( $this->get_field_id( 'format' ) ); ?>" class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'format' ) ); ?>"> |
|
292 |
<?php foreach ( $this->formats as $slug ) : ?> |
|
293 |
<option value="<?php echo esc_attr( $slug ); ?>"<?php selected( $format, $slug ); ?>><?php echo esc_html( get_post_format_string( $slug ) ); ?></option> |
|
294 |
<?php endforeach; ?> |
|
295 |
</select> |
|
296 |
<?php |
|
297 |
} |
|
298 |
} |