Flexible Posts Widget - Version 3.5.0

Version Description

Added multi-language support (WPML & PolyLang) and nested terms in the taxonomy & term select box. The plugin now updates widget settings in the background on update (if necessary).

=

Download this release

Release Info

Developer dpe415
Plugin Icon wp plugin Flexible Posts Widget
Version 3.5.0
Comparing to
See all releases

Code changes from version 3.4.1 to 3.5.0

css/admin.css CHANGED
@@ -1 +1,69 @@
1
- .dpe-fp-widget .cf{*zoom:1;}.dpe-fp-widget .cf:after{clear:both;}.dpe-fp-widget .cf:before,.dpe-fp-widget .cf:after{content:" ";display:table;}.dpe-fp-widget h4{margin-bottom:0.5em;}.dpe-fp-widget select{background-color:#fff;}.dpe-fp-widget .ui-tabs-active{background:#fff;border-color:#DFDFDF #DFDFDF #FFFFFF;}.dpe-fp-widget .ui-tabs-active a{color:#333333;}.dpe-fp-widget .warning{color:#d21703;}.dpe-fp-widget .section{margin-bottom:1.33em;border-bottom:1px solid #dfdfdf;}.dpe-fp-widget .section .getemby{padding-bottom:1.333em;}.dpe-fp-widget .tabs-panel.tt{padding:1.333em 1em;}.dpe-fp-widget .tabs-panel.id{padding:1.333em 1em 0;}.dpe-fp-widget .tabs-panel .terms{max-height:110px;overflow:auto;border:1px solid #DFDFDF;}.dpe-fp-widget .tabs-panel .terms ul{margin-left:1em;}.dpe-fp-widget .tabs-panel .terms p{margin:1em;}.dpe-fp-widget .display p{margin-bottom:0.5em;}.dpe-fp-widget .display p:last-child{margin-bottom:1em;}.dpe-fp-widget .display label{float:left;padding-top:0.4em;}.dpe-fp-widget .display input{float:right;width:60px;text-align:right;}.dpe-fp-widget .display select{float:right;width:120px;}.dpe-fp-widget .check input{float:none;width:auto;}.dpe-fp-widget .check label{float:none;padding-top:0.2em;}.dpe-fp-widget .description{display:inline-block;padding-top:5px;font-size:80%;}.dpe-fp-widget .templates p{margin:1.33em 0;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Flexible Posts Widget
3
+ * Admin Styles
4
+ * Author: dpe415
5
+ * URI: http://wordpress.org/extend/plugins/flexible-posts-widget/
6
+ */
7
+ .dpe-fp-widget .cf {
8
+ *zoom: 1; }
9
+ .dpe-fp-widget .cf:after {
10
+ clear: both; }
11
+ .dpe-fp-widget .cf:before, .dpe-fp-widget .cf:after {
12
+ content: " ";
13
+ display: table; }
14
+ .dpe-fp-widget h4 {
15
+ margin-bottom: 0.5em; }
16
+ .dpe-fp-widget select {
17
+ background-color: #fff; }
18
+ .dpe-fp-widget .ui-tabs-active {
19
+ background: #fff;
20
+ border-color: #DFDFDF #DFDFDF #FFFFFF; }
21
+ .dpe-fp-widget .ui-tabs-active a {
22
+ color: #333333; }
23
+ .dpe-fp-widget .warning {
24
+ color: #d21703; }
25
+ .dpe-fp-widget .section {
26
+ margin-bottom: 1.33em;
27
+ border-bottom: 1px solid #dfdfdf; }
28
+ .dpe-fp-widget .section .getemby {
29
+ padding-bottom: 1.333em; }
30
+ .dpe-fp-widget .tabs-panel.tt {
31
+ padding: 0 1em 1.333em 1em; }
32
+ .dpe-fp-widget .tabs-panel.id {
33
+ padding: 0 1em; }
34
+ .dpe-fp-widget .tabs-panel .terms {
35
+ max-height: 100px;
36
+ overflow: auto;
37
+ border: 1px solid #DFDFDF; }
38
+ .dpe-fp-widget .tabs-panel .terms > ul {
39
+ margin: 0.5em 1em; }
40
+ .dpe-fp-widget .tabs-panel .terms p {
41
+ margin: 1em; }
42
+ .dpe-fp-widget .display p {
43
+ margin-bottom: 0.5em; }
44
+ .dpe-fp-widget .display p:last-child {
45
+ margin-bottom: 1em; }
46
+ .dpe-fp-widget .display label {
47
+ float: left;
48
+ padding-top: 0.4em; }
49
+ .dpe-fp-widget .display input {
50
+ float: right;
51
+ width: 60px;
52
+ text-align: right; }
53
+ .dpe-fp-widget .display select {
54
+ float: right;
55
+ width: 120px; }
56
+ .dpe-fp-widget .check input {
57
+ float: none;
58
+ width: auto; }
59
+ .dpe-fp-widget .check label {
60
+ float: none;
61
+ padding-top: 0.2em; }
62
+ .dpe-fp-widget .description {
63
+ display: inline-block;
64
+ padding-top: 5px;
65
+ font-size: 80%; }
66
+ .dpe-fp-widget .templates p {
67
+ margin: 1.33em 0; }
68
+
69
+ /*# sourceMappingURL=admin.css.map */
css/admin.css.map ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ {
2
+ "version": 3,
3
+ "mappings": ";;;;;;AAUC,kBAAI;EACH,KAAK,EAAC,CAAC;EACP,wBAAQ;IAAC,KAAK,EAAC,IAAI;EACnB,mDAAkB;IAAC,OAAO,EAAC,GAAG;IAAE,OAAO,EAAC,KAAK;AAG9C,iBAAG;EAAC,aAAa,EAAC,KAAK;AACvB,qBAAO;EAAC,gBAAgB,EAAC,IAAI;AAE7B,8BAAgB;EACf,UAAU,EAAC,IAAI;EAAE,YAAY,EAAE,uBAAuB;EACtD,gCAAE;IAAC,KAAK,EAAC,OAAO;AAGjB,uBAAS;EAAC,KAAK,EAAC,OAAO;AAEvB,uBAAS;EACR,aAAa,EAAC,MAAM;EAAE,aAAa,EAAC,iBAAiB;EACrD,gCAAS;IAAC,cAAc,EAAC,OAAO;AAIhC,6BAAK;EACJ,OAAO,EAAC,iBAAiB;AAE1B,6BAAK;EAAC,OAAO,EAAC,KAAK;AACnB,iCAAO;EACN,UAAU,EAAC,KAAK;EAAE,QAAQ,EAAC,IAAI;EAAE,MAAM,EAAC,iBAAiB;EACzD,sCAAK;IAAC,MAAM,EAAC,SAAS;EACtB,mCAAG;IAAC,MAAM,EAAC,GAAG;AAKf,yBAAE;EACD,aAAa,EAAC,KAAK;EACnB,oCAAa;IAAC,aAAa,EAAC,GAAG;AAEhC,6BAAM;EAAC,KAAK,EAAC,IAAI;EAAE,WAAW,EAAC,KAAK;AACpC,6BAAM;EAAC,KAAK,EAAC,KAAK;EAAE,KAAK,EAAC,IAAI;EAAE,UAAU,EAAC,KAAK;AAChD,8BAAO;EAAC,KAAK,EAAC,KAAK;EAAE,KAAK,EAAC,KAAK;AAIhC,2BAAM;EAAC,KAAK,EAAC,IAAI;EAAE,KAAK,EAAC,IAAI;AAC7B,2BAAM;EAAC,KAAK,EAAC,IAAI;EAAE,WAAW,EAAC,KAAK;AAGrC,2BAAa;EAAC,OAAO,EAAC,YAAY;EAAE,WAAW,EAAC,GAAG;EAAE,SAAS,EAAC,GAAG;AAGjE,2BAAE;EAAC,MAAM,EAAC,QAAQ",
4
+ "sources": ["admin.scss"],
5
+ "names": [],
6
+ "file": "admin.css"
7
+ }
css/admin.min.css ADDED
@@ -0,0 +1 @@
 
1
+ .dpe-fp-widget .cf{*zoom:1}.dpe-fp-widget .cf:after{clear:both}.dpe-fp-widget .cf:before,.dpe-fp-widget .cf:after{content:" ";display:table}.dpe-fp-widget h4{margin-bottom:.5em}.dpe-fp-widget select{background-color:#fff}.dpe-fp-widget .ui-tabs-active{background:#fff;border-color:#dfdfdf #dfdfdf #fff}.dpe-fp-widget .ui-tabs-active a{color:#333}.dpe-fp-widget .warning{color:#d21703}.dpe-fp-widget .section{margin-bottom:1.33em;border-bottom:1px solid #dfdfdf}.dpe-fp-widget .section .getemby{padding-bottom:1.333em}.dpe-fp-widget .tabs-panel.tt{padding:0 1em 1.333em 1em}.dpe-fp-widget .tabs-panel.id{padding:0 1em}.dpe-fp-widget .tabs-panel .terms{max-height:100px;overflow:auto;border:1px solid #dfdfdf}.dpe-fp-widget .tabs-panel .terms>ul{margin:.5em 1em}.dpe-fp-widget .tabs-panel .terms p{margin:1em}.dpe-fp-widget .display p{margin-bottom:.5em}.dpe-fp-widget .display p:last-child{margin-bottom:1em}.dpe-fp-widget .display label{float:left;padding-top:.4em}.dpe-fp-widget .display input{float:right;width:60px;text-align:right}.dpe-fp-widget .display select{float:right;width:120px}.dpe-fp-widget .check input{float:none;width:auto}.dpe-fp-widget .check label{float:none;padding-top:.2em}.dpe-fp-widget .description{display:inline-block;padding-top:5px;font-size:80%}.dpe-fp-widget .templates p{margin:1.33em 0}
css/admin.scss CHANGED
@@ -7,7 +7,7 @@
7
 
8
 
9
  .dpe-fp-widget {
10
-
11
  .cf {
12
  *zoom:1;
13
  &:after {clear:both;}
@@ -30,12 +30,14 @@
30
  }
31
 
32
  .tabs-panel {
33
- &.tt {padding:1.333em 1em;}
34
- &.id {padding:1.333em 1em 0;}
 
 
35
  .terms {
36
- max-height:110px; overflow:auto; border:1px solid #DFDFDF;
37
- ul {margin-left:1em;}
38
- p {margin:1em;}
39
  }
40
  }
41
 
7
 
8
 
9
  .dpe-fp-widget {
10
+
11
  .cf {
12
  *zoom:1;
13
  &:after {clear:both;}
30
  }
31
 
32
  .tabs-panel {
33
+ &.tt {
34
+ padding:0 1em 1.333em 1em;
35
+ }
36
+ &.id {padding:0 1em;}
37
  .terms {
38
+ max-height:100px; overflow:auto; border:1px solid #DFDFDF;
39
+ > ul {margin:0.5em 1em;}
40
+ p {margin:1em;}
41
  }
42
  }
43
 
flexible-posts-widget.php CHANGED
@@ -2,30 +2,29 @@
2
  /**
3
  * Flexible Posts Widget
4
  *
5
- * Display posts as widget items.
6
  *
7
- * @package DPE_Flexible_Posts_Widget
8
- * @author David Paul Ellenwood <david@dpedesign.com>
9
- * @license GPL-2.0+
10
- * @link http://wordpress.org/extend/plugins/flexible-posts-widget
11
- * @copyright 2013 David Paul Ellenwood
12
  *
13
- * @flexible-posts-widget
14
  * Plugin Name: Flexible Posts Widget
15
- * Plugin URI: http://wordpress.org/extend/plugins/flexible-posts-widget
16
  * Description: An advanced posts display widget with many options: get posts by post type and taxonomy & term or by post ID; sorting & ordering; feature images; custom templates and more.
17
- * Version: 3.4.1
18
- * Author: dpe415
19
  * Author URI: http://dpedesign.com
20
- * Text Domain: flexible-posts-widget
21
  * License: GPL-2.0+
22
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 
23
  * Domain Path: /languages
24
- * GitHub Plugin URI: https://github.com/dpellenwood/flexible-posts-widget
25
  */
26
 
27
  /**
28
- * Copyright 2013 David Paul Ellenwood (email : david@dpedesign.com)
29
  *
30
  * This program is free software; you can redistribute it and/or modify
31
  * it under the terms of the GNU General Public License, version 2, as
@@ -41,596 +40,333 @@
41
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
42
  */
43
 
44
-
45
- // Block direct requests
46
  if ( ! defined( 'WPINC' ) ) {
47
  die;
48
  }
49
 
 
50
 
51
- /**
52
- * Flexible Posts Widget Class
53
- */
54
- class DPE_Flexible_Posts_Widget extends WP_Widget {
55
-
56
- /**
57
- * Plugin version number
58
- *
59
- * The variable name is used as a unique identifier for the widget
60
- *
61
- * @since 3.3.1
62
- *
63
- * @var string
64
- */
65
- protected $plugin_version = '3.4.1';
66
-
67
- /**
68
- * Unique identifier for your widget.
69
- *
70
- * The variable name is used as a unique identifier for the widget
71
- *
72
- * @since 1.0.0
73
- *
74
- * @var string
75
- */
76
- protected $widget_slug = 'dpe_fp_widget';
77
-
78
- /**
79
- * Unique identifier for your widget.
80
- *
81
- * The variable name is used as the text domain when internationalizing strings
82
- * of text. Its value should match the Text Domain file header in the main
83
- * widget file.
84
- *
85
- * @since 1.0.0
86
- *
87
- * @var string
88
- */
89
- protected $widget_text_domain = 'flexible-posts-widget';
90
-
91
- /**
92
- * Setup a number of variables to hold our default values
93
- *
94
- * @since 3.3.1
95
  */
96
- protected $posttypes = '';
97
- protected $pt_names = '';
98
- protected $taxonomies = '';
99
- protected $tax_names = '';
100
- protected $thumbsizes = '';
101
- protected $orderbys = '';
102
- protected $orders = '';
103
- protected $templates = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
 
 
 
 
 
 
105
 
106
- /*--------------------------------------------------*/
107
- /* Constructor
108
- /*--------------------------------------------------*/
109
 
110
- /**
111
- * Specifies the classname and description, instantiates the widget,
112
- * loads localization files, and includes necessary stylesheets and JavaScript.
113
- */
114
- public function __construct() {
115
-
116
- // load plugin text domain
117
- add_action( 'init', array( $this, 'widget_textdomain' ) );
118
-
119
- // The widget contrstructor
120
- parent::__construct(
121
- $this->get_widget_slug(),
122
- __( 'Flexible Posts Widget', $this->get_widget_text_domain() ),
123
- array(
124
- //'classname' => $this->get_widget_slug(),
125
- 'description' => __( 'Display posts as widget items.', $this->get_widget_text_domain() ),
126
- )
127
- );
128
-
129
- // Setup the default variables after wp is loaded
130
- add_action( 'wp_loaded', array( $this, 'setup_defaults' ) );
131
-
132
- // Register admin styles and scripts
133
- add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_styles' ) );
134
- add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) );
135
-
136
- // Setup our get terms/AJAX callback
137
- add_action( 'wp_ajax_dpe_fp_get_terms', array( &$this, 'terms_checklist' ) );
138
-
139
- }
140
-
141
- /**
142
- * Return the widget slug.
143
- *
144
- * @since 1.0.0
145
- *
146
- * @return Plugin slug variable.
147
- */
148
- public function get_widget_slug() {
149
- return $this->widget_slug;
150
- }
151
 
152
- /**
153
- * Return the widget text domain.
154
- *
155
- * @since 1.0.0
156
- *
157
- * @return Plugin text domain variable.
158
- */
159
- public function get_widget_text_domain() {
160
- return $this->widget_text_domain;
161
- }
162
-
163
- /**
164
- * Return the plugin version.
165
- *
166
- * @since 3.3.1
167
- *
168
- * @return Plugin version variable.
169
- */
170
- public function get_plugin_version() {
171
- return $this->plugin_version;
172
- }
173
 
 
 
 
 
 
 
174
 
175
- /*--------------------------------------------------*/
176
- /* Widget API Functions
177
- /*--------------------------------------------------*/
178
-
179
- /**
180
- * Outputs the content of the widget.
181
- *
182
- * @see WP_Widget::widget()
183
- *
184
- * @param array args The array of form elements
185
- * @param array instance The current instance of the widget
186
- */
187
- public function widget( $args, $instance ) {
188
-
189
- extract( $args );
190
- extract( $instance );
191
-
192
- $title = apply_filters( 'widget_title', empty( $title ) ? '' : $title );
193
-
194
- if ( empty( $template ) )
195
- $template = 'default.php';
196
-
197
- // Setup the query arguments array
198
- $args = array();
199
-
200
- // Get posts by post_ids specifically (ignore post type & tax/term values).
201
- if ( !empty( $pids ) ) {
202
-
203
- // Setup the query
204
- $args['post__in'] = $pids;
205
- $args['post_type'] = 'any';
206
-
207
- // Else get posts by post type and tax/term
208
- } else {
209
-
210
- // Setup the post types
211
- $args['post_type'] = $posttype;
212
-
213
- // Setup the tax & term query based on the user's selection
214
- if ( $taxonomy != 'none' && !empty( $term ) ) {
215
- $args['tax_query'] = array(
216
- array(
217
- 'taxonomy' => $taxonomy,
218
- 'field' => 'slug',
219
- 'terms' => $term,
220
- )
221
- );
222
- }
223
-
224
- }
225
-
226
- // Finish the query
227
- $args['post_status'] = array( 'publish', 'inherit' );
228
- $args['posts_per_page'] = $number;
229
- $args['offset'] = $offset;
230
- $args['orderby'] = $orderby;
231
- $args['order'] = $order;
232
- $args['ignore_sticky_posts'] = $sticky;
233
-
234
-
235
- // Allow filtering of the query arguments
236
- $args = apply_filters( 'dpe_fpw_args', $args );
237
-
238
- // Get the posts for this instance
239
- $flexible_posts = new WP_Query( $args );
240
-
241
- // Get and include the template we're going to use
242
- include( $this->get_template( $template ) );
243
-
244
- // Be sure to reset any post_data before proceeding
245
- wp_reset_postdata();
246
-
247
- }
248
-
249
- /**
250
- * Sanitize widget form values as they are saved.
251
- *
252
- * @see WP_Widget::update()
253
- *
254
- * @param array $new_instance Values just sent to be saved.
255
- * @param array $old_instance Previously saved values from database.
256
- *
257
- * @return array Updated safe values to be saved.
258
- */
259
- public function update( $new_instance, $old_instance ) {
260
-
261
- // Validate posttype submissions
262
- $posttypes = array();
263
- foreach( $new_instance['posttype'] as $pt ) {
264
- if( in_array( $pt, $this->pt_names ) )
265
- $posttypes[] = $pt;
266
- }
267
- if( empty( $posttypes ) )
268
- $posttypes[] = 'post';
269
-
270
- // Validate taxonomy & term submissions
271
- if( in_array( $new_instance['taxonomy'], $this->tax_names ) ) {
272
- $taxonomy = $new_instance['taxonomy'];
273
- $terms = array();
274
- if( 'none' != $taxonomy ) {
275
- $term_objects = get_terms( $taxonomy, array( 'hide_empty' => false ) );
276
- $term_names = array();
277
- foreach ( $term_objects as $object ) {
278
- $term_names[] = $object->slug;
279
- }
280
- foreach( $new_instance['term'] as $term ) {
281
- if( in_array( $term, $term_names ) )
282
- $terms[] = $term;
283
- }
284
- }
285
- } else {
286
- $taxonomy = 'none';
287
- $terms = array();
288
  }
289
-
290
- // Validate Post ID submissions
291
- $pids = array();
292
- if( !empty( $new_instance['pids'] ) ) {
293
- $pids_array = explode( ',', $new_instance['pids'] );
294
- foreach ( $pids_array as $id ) {
295
- $pids[] = absint( $id );
296
- }
297
- }
298
-
299
- $instance = $old_instance;
300
- $instance['title'] = strip_tags( $new_instance['title'] );
301
- $instance['posttype'] = $posttypes;
302
- $instance['taxonomy'] = $taxonomy;
303
- $instance['term'] = $terms;
304
- $instance['pids'] = $pids;
305
- $instance['number'] = (int) $new_instance['number'];
306
- $instance['offset'] = (int) $new_instance['offset'];
307
- $instance['orderby'] = ( array_key_exists( $new_instance['orderby'], $this->orderbys ) ? $new_instance['orderby'] : 'date' );
308
- $instance['order'] = ( array_key_exists( $new_instance['order'], $this->orders ) ? $new_instance['order'] : 'DESC' );
309
- $instance['sticky'] = ( isset( $new_instance['sticky'] ) ? (int) $new_instance['sticky'] : '0' );
310
- $instance['thumbnail'] = ( isset( $new_instance['thumbnail'] ) ? (int) $new_instance['thumbnail'] : '0' );
311
- $instance['thumbsize'] = ( in_array ( $new_instance['thumbsize'], $this->thumbsizes ) ? $new_instance['thumbsize'] : '' );
312
- $instance['template'] = ( array_key_exists( $new_instance['template'], $this->templates ) ? $new_instance['template'] : 'default.php' );
313
- $instance['cur_tab'] = (int) $new_instance['cur_tab'];
314
-
315
- return $instance;
316
-
317
- }
318
-
319
- /**
320
- * Back-end widget form.
321
- *
322
- * @see WP_Widget::form()
323
- *
324
- * @param array $instance Previously saved values from database.
325
- */
326
- public function form( $instance ) {
327
-
328
- $instance = wp_parse_args( (array) $instance, array(
329
- 'title' => '',
330
- 'posttype' => array( 'post' ),
331
- 'taxonomy' => 'none',
332
- 'term' => array(),
333
- 'pids' => '',
334
- 'number' => '3',
335
- 'offset' => '0',
336
- 'orderby' => 'date',
337
- 'order' => 'DESC',
338
- 'sticky' => '0',
339
- 'thumbnail' => '0',
340
- 'thumbsize' => '',
341
- 'template' => 'default.php',
342
- 'cur_tab' => '0',
343
- ) );
344
-
345
- extract( $instance );
346
-
347
- include( $this->get_template( 'admin' ) );
348
-
349
- }
350
 
351
- /**
352
- * Loads theme files in appropriate hierarchy:
353
- * 1. child theme 2. parent theme 3. plugin resources.
354
- * Will look in the flexible-posts-widget/ directory in a theme
355
- * and the views/ directory in the plugin
356
- *
357
- * Based on a function in the amazing image-widget
358
- * by Matt Wiebe at Modern Tribe, Inc.
359
- * http://wordpress.org/extend/plugins/image-widget/
360
- *
361
- * @param string $template template file to search for
362
- * @return template path
363
- **/
364
- public function get_template( $template ) {
365
-
366
- // whether or not .php was added
367
- $template_slug = preg_replace( '/.php$/', '', $template );
368
- $template = $template_slug . '.php';
369
-
370
- // Set to the default
371
- $file = 'views/' . $template;
372
-
373
- // Look for a custom version
374
- if ( $theme_file = locate_template( array( $this->get_widget_text_domain() . '/' . $template ) ) ) {
375
- $file = $theme_file;
376
  }
377
-
378
- return apply_filters( 'dpe_fpw_template_' . $template, $file );
379
-
380
- }
381
 
382
- /*--------------------------------------------------*/
383
- /* Public Functions
384
- /*--------------------------------------------------*/
 
 
 
385
 
386
- /**
387
- * Loads the Widget's text domain for localization and translation.
388
- */
389
- public function widget_textdomain() {
390
-
391
- load_plugin_textdomain( $this->get_widget_text_domain(), false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
392
-
393
- } // end widget_textdomain
394
 
395
- /**
396
- * Registers and enqueues admin-specific styles.
397
- */
398
- public function register_admin_styles() {
399
 
400
- wp_enqueue_style(
401
- $this->get_widget_slug() . '-admin',
402
- plugins_url( 'css/admin.css', __FILE__ ),
403
- array(),
404
- $this->get_plugin_version()
405
- );
406
 
407
- } // end register_admin_styles
408
 
409
- /**
410
- * Registers and enqueues admin-specific JavaScript.
411
- */
412
- public function register_admin_scripts() {
413
-
414
- $source = 'js/admin.min.js';
415
-
416
- if( SCRIPT_DEBUG ) {
417
- $source = 'js/admin.js';
418
  }
419
-
420
- wp_enqueue_script(
421
- $this->get_widget_slug() . '-admin',
422
- plugins_url( $source, __FILE__ ),
423
- array( 'jquery', 'jquery-ui-tabs' ),
424
- $this->get_plugin_version(),
425
- true
426
- );
427
-
428
- wp_localize_script( $this->get_widget_slug() . '-admin', 'fpwL10n', array(
429
- 'gettingTerms' => __( 'Getting terms...', $this->get_widget_text_domain() ),
430
- 'selectTerms' => __( 'Select terms:', $this->get_widget_text_domain() ),
431
- 'noTermsFound' => __( 'No terms found.', $this->get_widget_text_domain() ),
432
- ) );
433
-
434
- } // end register_admin_scripts
435
-
436
-
437
- /**
438
- * Return a list of terms for the chosen taxonomy used via AJAX
439
- */
440
- public function terms_checklist( $term ) {
441
 
442
- $taxonomy = esc_attr( $_POST['taxonomy'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
 
444
- if ( ! isset( $term ) )
445
- $term = esc_attr( $_POST['term'] );
446
-
447
- if ( empty( $taxonomy ) || 'none' == $taxonomy ) {
448
- echo false;
449
- die();
 
 
 
450
  }
451
-
452
- $args = array (
453
- 'hide_empty' => 0,
454
- );
455
-
456
- $terms = get_terms( $taxonomy, $args );
457
-
458
- if( empty($terms) ) {
459
- $output = '<p>' . __( 'No terms found.', $this->get_widget_text_domain() ) . '</p>';
460
- } else {
461
- $output = '<ul class="categorychecklist termschecklist form-no-clear">';
462
- foreach ( $terms as $option ) {
463
- $output .= "\n<li>" . '<label class="selectit"><input value="' . esc_attr( $option->slug ) . '" type="checkbox" name="' . $this->get_field_name('term') . '[]"' . checked( in_array( $option->slug, (array)$term ), true, false ) . ' /> ' . esc_html( $option->name ) . "</label></li>\n";
464
  }
465
- $output .= "</ul>\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
466
  }
467
-
468
- echo ( $output );
469
-
470
- die();
471
-
472
- }
473
-
474
- /**
475
- * Return a list of post types via AJAX
476
- */
477
- public function posttype_checklist( $posttype ) {
478
 
479
- $output = '<ul class="categorychecklist posttypechecklist form-no-clear">';
480
- foreach ( $this->posttypes as $type ) {
481
- $output .= "\n<li>" . '<label class="selectit"><input value="' . esc_attr( $type->name ) . '" type="checkbox" name="' . $this->get_field_name( 'posttype' ) . '[]"' . checked( in_array( $type->name, (array)$posttype ), true, false ) . ' /> ' . esc_html( $type->labels->name ) . "</label></li>\n";
 
 
 
 
 
482
  }
483
- $output .= "</ul>\n";
484
-
485
- echo ( $output );
486
-
487
- }
488
-
489
- /**
490
- * Setup a number of default variables used throughout the plugin
491
- *
492
- * Since 3.3.1
493
- *
494
- */
495
- public function setup_defaults() {
496
-
497
- // Get the registered post types
498
- $this->posttypes = get_post_types( array( 'public' => true ), 'objects' );
499
- $this->pt_names = get_post_types( array( 'public' => true ), 'names' );
500
-
501
- // Get the registered taxonomies
502
- $this->taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );
503
- $this->tax_names = get_taxonomies( array( 'public' => true ), 'names' );
504
- $this->tax_names[] = 'none';
505
-
506
- // Get the registered image sizes
507
- $this->thumbsizes = get_intermediate_image_sizes();
508
-
509
- // Set the options for orderby
510
- $this->orderbys = array(
511
- 'date' => __( 'Publish Date', $this->get_widget_text_domain() ),
512
- 'modified' => __( 'Modified Date', $this->get_widget_text_domain() ),
513
- 'title' => __( 'Title', $this->get_widget_text_domain() ),
514
- 'menu_order' => __( 'Menu Order', $this->get_widget_text_domain() ),
515
- 'ID' => __( 'Post ID', $this->get_widget_text_domain() ),
516
- 'author' => __( 'Author', $this->get_widget_text_domain() ),
517
- 'name' => __( 'Post Slug', $this->get_widget_text_domain() ),
518
- 'comment_count' => __( 'Comment Count', $this->get_widget_text_domain() ),
519
- 'rand' => __( 'Random', $this->get_widget_text_domain() ),
520
- 'post__in' => __( 'Post ID Order', $this->get_widget_text_domain() ),
521
- );
522
-
523
- // Set the options for order
524
- $this->orders = array(
525
- 'ASC' => __( 'Ascending', $this->get_widget_text_domain() ),
526
- 'DESC' => __( 'Descending', $this->get_widget_text_domain() ),
527
- );
528
-
529
- // Set the available templates
530
- $this->templates = wp_cache_get( 'templates', $this->widget_slug );
531
-
532
- if( false === $this->templates ) {
533
- $this->templates = (array) $this->get_files( 'php', 0, true );
534
- wp_cache_set( 'templates', $this->templates, $this->widget_slug );
535
  }
536
-
537
-
538
- }
539
 
540
- /**
541
- * Return template files from the current theme, parent theme and the plugin views directory.
542
- *
543
- * @since 3.3.1
544
- * @access public
545
- *
546
- * Based on the function of the same name in wp-includes/class-wp-theme.php
547
- *
548
- * @param mixed $type Optional. Array of extensions to return. Defaults to all files (null).
549
- * @param int $depth Optional. How deep to search for files. Defaults to a flat scan (0 depth). -1 depth is infinite.
550
- * @param bool $search_parent Optional. Whether to return parent files. Defaults to false.
551
- * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values
552
- * being absolute paths.
553
- */
554
- public function get_files( $type = null, $depth = 0, $search_parent = false ) {
555
-
556
- $files = array();
557
- $theme_dir = get_stylesheet_directory() . '/' . $this->get_widget_text_domain();
558
- $plugin_dir = dirname(__FILE__) . '/views';
559
-
560
- // Check the current theme
561
- if( is_dir( $theme_dir ) ) {
562
- $files += (array) self::scandir( $theme_dir, $type, $depth );
563
  }
564
 
565
- // Check the parent theme
566
- if ( $search_parent && is_child_theme() ) {
567
- $parent_theme_dir = get_template_directory() . '/' . $this->get_widget_text_domain();
568
- if( is_dir( $parent_theme_dir ) ) {
569
- $files += (array) self::scandir( $parent_theme_dir, $type, $depth );
570
- }
 
 
571
  }
572
-
573
- // Check the plugin views folder
574
- if( is_dir( $plugin_dir ) ) {
575
- $files += (array) self::scandir( $plugin_dir, $type, $depth );
576
- // Remove the admin view
577
- unset( $files['admin.php'] );
 
 
 
578
  }
579
-
580
- return $files;
581
- }
582
-
583
- /**
584
- * Scans a directory for files of a certain extension.
585
- *
586
- * @since 3.3.1
587
- * @access private
588
- *
589
- * Based on the function of the same name in wp-includes/class-wp-theme.php
590
- *
591
- * @param string $path Absolute path to search.
592
- * @param mixed Array of extensions to find, string of a single extension, or null for all extensions.
593
- * @param int $depth How deep to search for files. Optional, defaults to a flat scan (0 depth). -1 depth is infinite.
594
- * @param string $relative_path The basename of the absolute path. Used to control the returned path
595
- * for the found files, particularly when this function recurses to lower depths.
596
- */
597
- private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) {
598
- if ( ! is_dir( $path ) )
599
- return false;
600
 
601
- if ( $extensions ) {
602
- $extensions = (array) $extensions;
603
- $_extensions = implode( '|', $extensions );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
  }
605
 
606
- $relative_path = trailingslashit( $relative_path );
607
- if ( '/' == $relative_path )
608
- $relative_path = '';
609
-
610
- $results = scandir( $path );
611
- $files = array();
612
-
613
- foreach ( $results as $result ) {
614
- if ( '.' == $result[0] )
615
- continue;
616
- if ( is_dir( $path . '/' . $result ) ) {
617
- if ( ! $depth || 'CVS' == $result )
618
- continue;
619
- $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result );
620
- $files = array_merge_recursive( $files, $found );
621
- } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) {
622
- $files[ $relative_path . $result ] = $path . '/' . $result;
623
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
624
  }
625
 
626
- return $files;
627
- }
628
-
629
 
630
- } // class DPE_Flexible_Posts_Widget
631
 
 
632
 
633
  /**
634
- * Initialize the widget on widgets_init
 
 
635
  */
636
- add_action( 'widgets_init', create_function( '', 'register_widget("DPE_Flexible_Posts_Widget");' ) );
 
 
2
  /**
3
  * Flexible Posts Widget
4
  *
5
+ * A collection of widgets to display posts based on different criteria
6
  *
7
+ * @package DPE_Flexible_Posts_Widget
8
+ * @author DPE WS&D LLC <fpw@dpedesign.com>
9
+ * @license GPL-2.0+
10
+ * @link http://flexiblepostswidget.com
11
+ * @copyright 2013 DPE WS&D LLC
12
  *
13
+ * @wordpress-plugin
14
  * Plugin Name: Flexible Posts Widget
15
+ * Plugin URI: http://flexiblepostswidget.com
16
  * Description: An advanced posts display widget with many options: get posts by post type and taxonomy & term or by post ID; sorting & ordering; feature images; custom templates and more.
17
+ * Version: 3.5.0
18
+ * Author: DPE WS&D LLC
19
  * Author URI: http://dpedesign.com
 
20
  * License: GPL-2.0+
21
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
22
+ * Text Domain: flexible-posts-widget
23
  * Domain Path: /languages
 
24
  */
25
 
26
  /**
27
+ * Copyright 2013 DPE WS&D LLC
28
  *
29
  * This program is free software; you can redistribute it and/or modify
30
  * it under the terms of the GNU General Public License, version 2, as
40
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
41
  */
42
 
43
+ // If this file is called directly, abort.
 
44
  if ( ! defined( 'WPINC' ) ) {
45
  die;
46
  }
47
 
48
+ if ( ! class_exists( 'FPW_Plugin' ) ) {
49
 
50
+ /**
51
+ * Flexible Posts Widgets Plugin Class
52
+ *
53
+ * This is the bootstrapping class for the plugin.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  */
55
+ class FPW_Plugin {
56
+
57
+ /**
58
+ * The unique plugin id or slug.
59
+ *
60
+ * @since 3.5.0
61
+ * @access protected
62
+ * @var string $plugin_slug The slug used to uniquely identify the plugin.
63
+ */
64
+ protected $plugin_slug;
65
+
66
+ /**
67
+ * The current version of the plugin.
68
+ *
69
+ * @since 1.0.0
70
+ * @access protected
71
+ * @var string $version The current version of the plugin.
72
+ */
73
+ protected $version;
74
+
75
+ /**
76
+ * The current version of the plugin.
77
+ *
78
+ * @since 3.5.0
79
+ * @access protected
80
+ * @var int $db_version The current version of the plugin's database settings.
81
+ */
82
+ protected $db_version;
83
+
84
+ /**
85
+ * The unique identifier of this plugin.
86
+ *
87
+ * @since 1.0.0
88
+ * @access protected
89
+ * @var string $text_domain The string used for internationalization.
90
+ */
91
+ protected $text_domain;
92
+
93
+ /**
94
+ * The directory path for the plugin.
95
+ *
96
+ * @since 3.5.0
97
+ * @access protected
98
+ * @var string $plugin_dir The directory path to the plugin.
99
+ */
100
+ protected $plugin_dir;
101
+
102
+ /**
103
+ * Define the core functionality of the plugin.
104
+ *
105
+ * Set the plugin name and the plugin version that can be used throughout the plugin.
106
+ * Load the dependencies, define the locale, and set the hooks for the Dashboard and
107
+ * the public-facing side of the site.
108
+ *
109
+ * @since 3.5.0
110
+ */
111
+
112
+ public function __construct() {
113
+ $this->plugin_slug = 'dpe_fp_widget';
114
+ $this->version = '3.5.0';
115
+ $this->db_version = 2;
116
+ $this->text_domain = 'flexible-posts-widget';
117
+ $this->plugin_dir = plugin_dir_path( __FILE__ );
118
+ }
119
 
120
+ /**
121
+ * Setup the environment for the plugin.
122
+ * *
123
+ * @since 3.5.0
124
+ */
125
+ public function bootstrap() {
126
 
127
+ // Register activate/deactivate hooks
128
+ register_activation_hook( __FILE__, array( $this, 'activate' ) );
129
+ register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
130
 
131
+ // Check to see if we need to update the db
132
+ add_action( 'wp_loaded', array( $this, 'maybe_update' ), 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
+ // load plugin text domain
135
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
+ // Register admin styles and scripts
138
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
139
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
140
+
141
+ // Register our widget
142
+ add_action( 'widgets_init', array( $this, 'register_widgets' ) );
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
+ /**
147
+ * Do some stuff upon activation
148
+ *
149
+ * @since 3.5.0
150
+ */
151
+ public function activate() {
152
+
153
+ if ( ! current_user_can( 'activate_plugins' ) )
154
+ return;
155
+
156
+ /* This fails on bulk activate
157
+ $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
158
+ check_admin_referer( "activate-plugin_{$plugin}" );
159
+ */
160
+
161
+ $this->init_options();
162
+ $this->maybe_update();
163
+
 
 
 
 
 
 
 
164
  }
 
 
 
 
165
 
166
+ /**
167
+ * Do some stuff upon deactivation
168
+ *
169
+ * @since 3.5.0
170
+ */
171
+ public function deactivate() {
172
 
173
+ if ( ! current_user_can( 'activate_plugins' ) )
174
+ return;
 
 
 
 
 
 
175
 
 
 
 
 
176
 
177
+ /* This fails on bulk deactivate
178
+ $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
179
+ check_admin_referer( "deactivate-plugin_{$plugin}" );
180
+ */
 
 
181
 
182
+ // Do stuff here.
183
 
 
 
 
 
 
 
 
 
 
184
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
 
186
+ /**
187
+ * Do some stuff upon uninstall
188
+ *
189
+ * @since 3.5.0
190
+ */
191
+ public function uninstall() {
192
+
193
+ if ( ! current_user_can( 'activate_plugins' ) )
194
+ return;
195
+
196
+ check_admin_referer( 'bulk-plugins' );
197
+
198
+ // Important: Check if the file is the one
199
+ // that was registered during the uninstall hook.
200
+ if ( __FILE__ != WP_UNINSTALL_PLUGIN )
201
+ return;
202
 
203
+ // Do stuff here.
204
+
205
+ }
206
+
207
+ /**
208
+ * Initialize default option values
209
+ */
210
+ public function init_options() {
211
+ update_option( $this->plugin_slug . '_ver', $this->version );
212
  }
213
+
214
+ /**
215
+ * Check to see if we need to run an update routine
216
+ */
217
+ public function maybe_update() {
218
+
219
+ // Check the currently stored plugin version and update it if it doesn't match.
220
+ $current_ver = get_option( $this->plugin_slug . '_ver' );
221
+
222
+ if( $current_ver !== $this->version ) {
223
+ update_option( $this->plugin_slug . '_ver', $this->version );
 
 
224
  }
225
+
226
+ // this is the current database schema version number
227
+ $current_db_ver = (int)get_option( $this->plugin_slug . '_db_ver' );
228
+
229
+ // bail if this plugin data doesn't need updating
230
+ if ( $current_db_ver >= $this->db_version ) {
231
+ return;
232
+ }
233
+
234
+ // Otherwise, run the updater
235
+ require_once( $this->plugin_dir . 'includes/class-fpw-plugin-updater.php' );
236
+ $updater = new FPW_Plugin_Updater( $this->plugin_slug, $this->db_version );
237
+ $updater->update_plugin( $current_db_ver );
238
+
239
  }
 
 
 
 
 
 
 
 
 
 
 
240
 
241
+ /**
242
+ * Retrieve the unique id (slug) for the plugin
243
+ *
244
+ * @since 3.5.0
245
+ * @return string The plugin id/slug.
246
+ */
247
+ public function get_slug() {
248
+ return $this->plugin_slug;
249
  }
250
+
251
+ /**
252
+ * Retrieve the version number of the plugin.
253
+ *
254
+ * @since 3.5.0
255
+ * @return string The version number of the plugin.
256
+ */
257
+ public function get_version() {
258
+ return $this->version;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  }
 
 
 
260
 
261
+ /**
262
+ * Retrieve the database version number of the plugin.
263
+ *
264
+ * @since 3.5.0
265
+ * @return int The database version number of the plugin.
266
+ */
267
+ public function get_db_version() {
268
+ return $this->db_version;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  }
270
 
271
+ /**
272
+ * Retrieve the text domain of the plugin.
273
+ *
274
+ * @since 3.5.0
275
+ * @return string The text domain number of the plugin.
276
+ */
277
+ public function get_text_domain() {
278
+ return $this->text_domain;
279
  }
280
+
281
+ /**
282
+ * Retrieve the plugin directory path.
283
+ *
284
+ * @since 3.5.0
285
+ * @return string The directory path of the plugin.
286
+ */
287
+ public function get_plugin_dir() {
288
+ return $this->plugin_dir;
289
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
 
291
+ /**
292
+ * Loads the plugin's text domain for localization and translation.
293
+ *
294
+ * @since unknown
295
+ */
296
+ public function load_plugin_textdomain() {
297
+ load_plugin_textdomain( $this->text_domain, false, $this->plugin_dir . 'languages/' );
298
+ }
299
+
300
+ /**
301
+ * Registers and enqueues admin-specific styles.
302
+ *
303
+ * @since unknown
304
+ */
305
+ public function enqueue_admin_styles() {
306
+
307
+ // Set the source for our CSS file.
308
+ $source = 'css/admin.min.css';
309
+
310
+ // Use an uncompressed version for debugging.
311
+ if( SCRIPT_DEBUG ) {
312
+ $source = 'css/admin.css';
313
+ }
314
+
315
+ wp_enqueue_style( $this->plugin_slug . '-admin', plugins_url( $source, __FILE__ ), array(), $this->version );
316
+
317
  }
318
 
319
+ /**
320
+ * Registers and enqueues admin-specific JavaScript.
321
+ *
322
+ * @since unknown
323
+ */
324
+ public function enqueue_admin_scripts() {
325
+
326
+ // Set the source for our JS file.
327
+ $source = 'js/admin.min.js';
328
+
329
+ // Use an uncompressed version for debugging.
330
+ if( SCRIPT_DEBUG ) {
331
+ $source = 'js/admin.js';
 
 
 
 
332
  }
333
+
334
+ wp_enqueue_script(
335
+ $this->plugin_slug . '-admin',
336
+ plugins_url( $source, __FILE__ ) ,
337
+ array( 'jquery', 'jquery-ui-tabs' ),
338
+ $this->version,
339
+ true
340
+ );
341
+
342
+ wp_localize_script( $this->plugin_slug . '-admin', 'fpwL10n', array(
343
+ 'gettingTerms' => __( 'Getting terms...', $this->text_domain ),
344
+ 'selectTerms' => __( 'Select terms:', $this->text_domain ),
345
+ 'noTermsFound' => __( 'No terms found.', $this->text_domain ),
346
+ ) );
347
+
348
+ }
349
+
350
+ /**
351
+ * Register the main FPW Class for WordPress to use
352
+ *
353
+ * @since 3.5.0
354
+ */
355
+ public function register_widgets() {
356
+ require_once( $this->plugin_dir . 'includes/class-fpw-widget.php' );
357
+ register_widget( 'Flexible_Posts_Widget' );
358
  }
359
 
 
 
 
360
 
361
+ } // FPW_Plugin
362
 
363
+ }
364
 
365
  /**
366
+ * Begins execution of the plugin.
367
+ *
368
+ * @since 3.5.0
369
  */
370
+ global $dpe_fpw_plugin;
371
+ $dpe_fpw_plugin = new FPW_Plugin();
372
+ $dpe_fpw_plugin->bootstrap();
includes/class-fpw-plugin-updater.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * The plugin updater class.
4
+ *
5
+ * @link http://dpedesign.com
6
+ * @since 3.5.0
7
+ *
8
+ * @package Flexible_Posts_Widget
9
+ * @subpackage Flexible_Posts_Widget/includes
10
+ */
11
+
12
+ /**
13
+ * The plugin updater class.
14
+ *
15
+ * This class handles any database updates that may need to be performed.
16
+ * Updated are handled incrementally to make sure no changes are missed.
17
+ *
18
+ * @since 3.5.0
19
+ * @package Flexible_Posts_Widget
20
+ * @subpackage Flexible_Posts_Widget/includes
21
+ * @author DPE WS&D LLC <fpw@dpedesign.com>
22
+ */
23
+ class FPW_Plugin_Updater {
24
+
25
+ /**
26
+ * The unique plugin id or slug.
27
+ *
28
+ * @since 3.5.0
29
+ * @access private
30
+ * @var string $plugin_slug The slug used to uniquely identify the plugin.
31
+ */
32
+ private $plugin_slug;
33
+
34
+ /**
35
+ * The current version of the plugin.
36
+ *
37
+ * @since 3.5.0
38
+ * @access private
39
+ * @var int $db_version The current version of the plugin's database settings.
40
+ */
41
+ private $db_version;
42
+
43
+ /**
44
+ * Initialize the class and set it's properties.
45
+ *
46
+ * @since 3.5.0
47
+ */
48
+ public function __construct( $plugin_slug, $db_version ) {
49
+ $this->plugin_slug = $plugin_slug;
50
+ $this->db_version = $db_version;
51
+ }
52
+
53
+ /**
54
+ * The main updater method
55
+ *
56
+ * This method checks the database version saved in the site's options table
57
+ * against the version required by this version of the plugin.
58
+ * If the site's version is below the plugin's version, it runs an update
59
+ * function for each sequential version until the current version is attained.
60
+ *
61
+ * @since 3.5.0
62
+ */
63
+ public function update_plugin( $current_db_ver ) {
64
+
65
+ set_time_limit( 0 );
66
+
67
+ // this is the target version that we need to reach
68
+ $target_db_ver = $this->db_version;
69
+
70
+ // run update routines one by one until the current version number
71
+ // reaches the target version number
72
+ while ( $current_db_ver < $target_db_ver ) {
73
+
74
+ // increment the current db_ver by one
75
+ $current_db_ver ++;
76
+
77
+ // each db version will require a separate update function
78
+ // for example, for db_ver 3, the function name should be solis_update_routine_3
79
+ $function_name = $this->plugin_slug . '_update_routine_' . $current_db_ver;
80
+ if ( method_exists( $this, $function_name ) ) {
81
+ call_user_func( array( $this, $function_name ) );
82
+ }
83
+
84
+ // update the option in the database, so that this process can always
85
+ // pick up where it left off
86
+ update_option( $this->plugin_slug . '_db_ver', $current_db_ver );
87
+
88
+ }
89
+
90
+ }
91
+
92
+ /**
93
+ * The update routine for database version 2.
94
+ *
95
+ * This routine is used to update previous version's instance settings.
96
+ * Old versions of the plugin used term->slug to store the terms selected in each instance.
97
+ * Version 3.5.0 and above will store the term->ID instead of the slug, so we need to run through
98
+ * any existing widget instances and convert from term->slug to term->id for each selected term.
99
+ *
100
+ * @since 3.5.0
101
+ */
102
+ public function dpe_fp_widget_update_routine_2() {
103
+
104
+ // Boolean to check if we actually need to update the widget settings.
105
+ $needs_update = false;
106
+
107
+ // Go get the widget configuration data from the DB and save a backup copy.
108
+ $options = get_option( 'widget_' . $this->plugin_slug );
109
+ $options_bk = $options;
110
+
111
+ if( $options ) {
112
+
113
+ // Run through each instance's settings and check if we need to update...
114
+ foreach( $options as $key => $value ) {
115
+
116
+ // If the taxonomy key is set and not set to none...
117
+ if( isset( $value['taxonomy'] ) && ! empty( $value['taxonomy'] ) && 'none' != $value['taxonomy'] ) {
118
+
119
+ // If we've got terms to convert...
120
+ if( isset( $value['term'] ) && ! empty( $value['term'] ) ) {
121
+
122
+ /**
123
+ * Setup the conversion query...
124
+ * Get the term IDs for the array of term slugs we have saved in the taxonomy we have saved
125
+ */
126
+ $args = array(
127
+ 'fields' => 'ids',
128
+ 'slug' => $value['term'],
129
+ );
130
+ $term_ids = get_terms( $value['taxonomy'], $args );
131
+
132
+ if( ! is_wp_error( $term_ids ) && ! empty( $term_ids ) ) {
133
+ // As long as we have have a valid term response, set it to this instance's option value.
134
+ $options[$key]['term'] = $term_ids;
135
+ $needs_update = true;
136
+ }
137
+
138
+ }
139
+
140
+ }
141
+
142
+ }
143
+
144
+ // Finally, we create a backup of the existing settings and update the settings if the update is required.
145
+ if( $needs_update ) {
146
+ $prev_db_ver = $this->db_version - 1;
147
+ add_option( 'widget_' . $this->plugin_slug . '_backup_v' . $prev_db_ver, $options_bk, '', 'no' );
148
+ update_option( 'widget_' . $this->plugin_slug, $options );
149
+ }
150
+
151
+ }
152
+
153
+ }
154
+
155
+ }
includes/class-fpw-widget.php ADDED
@@ -0,0 +1,567 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Flexible Posts Widget
4
+ *
5
+ * @link http://dpedesign.com
6
+ * @since 1.0.0
7
+ *
8
+ * @package Flexible_Posts_Widget
9
+ * @subpackage Flexible_Posts_Widget/includes
10
+ */
11
+
12
+ /**
13
+ * Flexible Posts Widget.
14
+ *
15
+ * The primary widget that has existed since the beginning of FPW time.
16
+ *
17
+ * @since 1.0.0
18
+ * @package Flexible_Posts_Widget
19
+ * @subpackage Flexible_Posts_Widget/includes
20
+ * @author DPE WS&D LLC <fpw@dpedesign.com>
21
+ */
22
+
23
+ // If this file is called directly, abort.
24
+ if ( ! defined( 'WPINC' ) ) {
25
+ die;
26
+ }
27
+
28
+
29
+ /**
30
+ * Flexible Posts Widget Class
31
+ */
32
+ class Flexible_Posts_Widget extends WP_Widget {
33
+
34
+ /**
35
+ * Plugin version number
36
+ *
37
+ * The variable name is used as a unique identifier for the widget
38
+ *
39
+ * @since 3.3.1
40
+ * @access private
41
+ * @var string
42
+ */
43
+ private $version;
44
+
45
+ /**
46
+ * Unique identifier for your widget.
47
+ *
48
+ * The variable name is used as a unique identifier for the widget
49
+ *
50
+ * @since 1.0.0
51
+ * @access private
52
+ * @var string
53
+ */
54
+ private $widget_slug;
55
+
56
+ /**
57
+ * Unique identifier for your widget.
58
+ *
59
+ * The variable name is used as the text domain when internationalizing strings
60
+ * of text. Its value should match the Text Domain file header in the main
61
+ * widget file.
62
+ *
63
+ * @since 1.0.0
64
+ * @access private
65
+ * @var string
66
+ */
67
+ private $widget_text_domain;
68
+
69
+ /**
70
+ * The directory path for the plugin.
71
+ *
72
+ * @since 3.5.0
73
+ * @access private
74
+ * @var string $plugin_dir The directory path to the plugin.
75
+ */
76
+ private $plugin_dir;
77
+
78
+ /**
79
+ * Setup a number of variables to hold our default values
80
+ *
81
+ * @since 3.3.1
82
+ */
83
+ protected $posttypes = array();
84
+ protected $pt_names = array();
85
+ protected $taxonomies = array();
86
+ protected $tax_names = array();
87
+ protected $thumbsizes = array();
88
+ protected $orderbys = array();
89
+ protected $orders = array();
90
+ protected $templates = array();
91
+
92
+
93
+ /*--------------------------------------------------*/
94
+ /* Constructor
95
+ /*--------------------------------------------------*/
96
+
97
+ /**
98
+ * Specifies the classname and description, instantiates the widget,
99
+ * loads localization files, and includes necessary stylesheets and JavaScript.
100
+ */
101
+ public function __construct() {
102
+
103
+ global $dpe_fpw_plugin;
104
+
105
+ $this->version = $dpe_fpw_plugin->get_version();
106
+ $this->widget_slug = $dpe_fpw_plugin->get_slug();
107
+ $this->widget_text_domain = $dpe_fpw_plugin->get_text_domain();
108
+ $this->plugin_dir = $dpe_fpw_plugin->get_plugin_dir();
109
+
110
+ // Set the widget options
111
+ $widget_opts = array(
112
+ 'description' => __( 'Display posts as widget items.', $this->widget_text_domain ),
113
+ );
114
+
115
+ // The widget constructor
116
+ parent::__construct(
117
+ $this->widget_slug,
118
+ __( 'Flexible Posts Widget', $this->widget_text_domain ),
119
+ $widget_opts
120
+ );
121
+
122
+ // Setup the default variables after wp is loaded
123
+ add_action( 'wp_loaded', array( $this, 'setup_defaults' ) );
124
+
125
+ // Setup our get terms/AJAX callback
126
+ add_action( 'wp_ajax_dpe_fp_get_terms', array( &$this, 'terms_checklist' ) );
127
+
128
+ }
129
+
130
+
131
+ /*--------------------------------------------------*/
132
+ /* Widget API Functions
133
+ /*--------------------------------------------------*/
134
+
135
+ /**
136
+ * Outputs the content of the widget.
137
+ *
138
+ * @see WP_Widget::widget()
139
+ *
140
+ * @param array args The array of form elements
141
+ * @param array instance The current instance of the widget
142
+ */
143
+ public function widget( $args, $instance ) {
144
+
145
+ extract( $args );
146
+ extract( $instance );
147
+
148
+ $title = apply_filters( 'widget_title', empty( $title ) ? '' : $title );
149
+
150
+ if ( empty( $template ) )
151
+ $template = 'default.php';
152
+
153
+ // Setup the query arguments array
154
+ $query_args = array();
155
+
156
+ // Get posts by post_ids specifically (ignore post type & tax/term values).
157
+ if ( !empty( $pids ) ) {
158
+
159
+ // Setup the query
160
+ $query_args['post__in'] = $pids;
161
+ $query_args['post_type'] = 'any';
162
+
163
+ // Else get posts by post type and tax/term
164
+ } else {
165
+
166
+ // Setup the post types
167
+ $query_args['post_type'] = $posttype;
168
+
169
+ // Setup the tax & term query based on the user's selection
170
+ if ( $taxonomy != 'none' && !empty( $term ) ) {
171
+ $query_args['tax_query'] = array(
172
+ array(
173
+ 'taxonomy' => $taxonomy,
174
+ 'field' => 'id',
175
+ 'terms' => $term,
176
+ )
177
+ );
178
+ }
179
+
180
+ }
181
+
182
+ // Finish the query
183
+ $query_args['post_status'] = array( 'publish', 'inherit' );
184
+ $query_args['posts_per_page'] = $number;
185
+ $query_args['offset'] = $offset;
186
+ $query_args['orderby'] = $orderby;
187
+ $query_args['order'] = $order;
188
+ $query_args['ignore_sticky_posts'] = $sticky;
189
+
190
+ // Allow filtering of the query arguments
191
+ $query_args = apply_filters( 'dpe_fpw_args', $query_args );
192
+
193
+ // Get the posts for this instance
194
+ $flexible_posts = new WP_Query( $query_args );
195
+
196
+ // Get and include the template we're going to use
197
+ include( $this->get_template( $template ) );
198
+
199
+ // Be sure to reset any post_data before proceeding
200
+ wp_reset_postdata();
201
+
202
+ }
203
+
204
+ /**
205
+ * Sanitize widget form values as they are saved.
206
+ *
207
+ * @see WP_Widget::update()
208
+ *
209
+ * @param array $new_instance Values just sent to be saved.
210
+ * @param array $old_instance Previously saved values from database.
211
+ *
212
+ * @return array Updated safe values to be saved.
213
+ */
214
+ public function update( $new_instance, $old_instance ) {
215
+
216
+ $posttypes = array();
217
+ $terms = array();
218
+ $taxonomy = 'none';
219
+ $pids = array();
220
+
221
+ // Validate posttype
222
+ foreach ( $new_instance['posttype'] as $pt ) {
223
+ if ( in_array( $pt, $this->pt_names ) ) {
224
+ $posttypes[] = $pt;
225
+ }
226
+ }
227
+ if ( empty( $posttypes ) ) {
228
+ $posttypes[] = 'post';
229
+ }
230
+
231
+ // Validate taxonomy
232
+ if ( taxonomy_exists( $new_instance['taxonomy'] ) ) {
233
+ $taxonomy = $new_instance['taxonomy'];
234
+
235
+ /**
236
+ * Validate terms
237
+ * We have to work around the fact that the walker class for wp_terms_checklist()
238
+ * uses (DIFFERENT!!!) hard-coded HTML input names instead of allowing us to set
239
+ * a widget-instance-specific input name.
240
+ */
241
+ if ( isset( $_REQUEST['widget-id'] ) && $_REQUEST['widget-id'] == $this->id ) {
242
+
243
+ $posted_terms = array();
244
+
245
+ /**
246
+ * If the posted terms are from the built-in Post Category taxonomy
247
+ * We have to use one $_POST variable and a different, variable
248
+ * $_POST variable for every other taxonomy.
249
+ */
250
+ if( isset( $_POST['post_category'] ) ) {
251
+ $posted_terms = $_POST['post_category'];
252
+ } else {
253
+ if ( isset( $_POST['tax_input'][$taxonomy] ) ) {
254
+ $posted_terms = $_POST['tax_input'][$taxonomy];
255
+ }
256
+ }
257
+
258
+ // Once we actually have the $_POSTed terms, validate and and save them
259
+ foreach ( $posted_terms as $term ) {
260
+ if( term_exists( absint( $term ), $taxonomy ) ) {
261
+ $terms[] = absint( $term );
262
+ }
263
+ }
264
+
265
+ }
266
+
267
+ }
268
+
269
+ // Validate Post ID submissions
270
+ if ( !empty( $new_instance['pids'] ) ) {
271
+ $pids_array = explode( ',', $new_instance['pids'] );
272
+ foreach ( $pids_array as $id ) {
273
+ $pids[] = absint( $id );
274
+ }
275
+ }
276
+
277
+ $instance = $old_instance;
278
+ $instance['title'] = strip_tags( $new_instance['title'] );
279
+ $instance['posttype'] = $posttypes;
280
+ $instance['taxonomy'] = $taxonomy;
281
+ $instance['term'] = $terms;
282
+ $instance['pids'] = $pids;
283
+ $instance['number'] = (int) $new_instance['number'];
284
+ $instance['offset'] = (int) $new_instance['offset'];
285
+ $instance['orderby'] = ( array_key_exists( $new_instance['orderby'], $this->orderbys ) ? $new_instance['orderby'] : 'date' );
286
+ $instance['order'] = ( array_key_exists( $new_instance['order'], $this->orders ) ? $new_instance['order'] : 'DESC' );
287
+ $instance['sticky'] = ( isset( $new_instance['sticky'] ) ? (int) $new_instance['sticky'] : '0' );
288
+ $instance['thumbnail'] = ( isset( $new_instance['thumbnail'] ) ? (int) $new_instance['thumbnail'] : '0' );
289
+ $instance['thumbsize'] = ( in_array ( $new_instance['thumbsize'], $this->thumbsizes ) ? $new_instance['thumbsize'] : '' );
290
+ $instance['template'] = ( array_key_exists( $new_instance['template'], $this->templates ) ? $new_instance['template'] : 'default.php' );
291
+ $instance['cur_tab'] = (int) $new_instance['cur_tab'];
292
+
293
+ return $instance;
294
+
295
+ }
296
+
297
+ /**
298
+ * Back-end widget form.
299
+ *
300
+ * @see WP_Widget::form()
301
+ *
302
+ * @param array $instance Previously saved values from database.
303
+ */
304
+ public function form( $instance ) {
305
+
306
+ $instance = wp_parse_args( (array) $instance, array(
307
+ 'title' => '',
308
+ 'posttype' => array( 'post' ),
309
+ 'taxonomy' => 'none',
310
+ 'term' => array(),
311
+ 'pids' => '',
312
+ 'number' => '3',
313
+ 'offset' => '0',
314
+ 'orderby' => 'date',
315
+ 'order' => 'DESC',
316
+ 'sticky' => '0',
317
+ 'thumbnail' => '0',
318
+ 'thumbsize' => '',
319
+ 'template' => 'default.php',
320
+ 'cur_tab' => '0',
321
+ ) );
322
+
323
+ include( $this->get_template( 'admin' ) );
324
+
325
+ }
326
+
327
+ /**
328
+ * Loads theme files in appropriate hierarchy:
329
+ * 1. child theme 2. parent theme 3. plugin resources.
330
+ * Will look in the flexible-posts-widget/ directory in a theme
331
+ * and the views/ directory in the plugin
332
+ *
333
+ * Based on a function in the amazing image-widget
334
+ * by Matt Wiebe at Modern Tribe, Inc.
335
+ * http://wordpress.org/extend/plugins/image-widget/
336
+ *
337
+ * @param string $template template file to search for
338
+ * @return template path
339
+ **/
340
+ public function get_template( $template ) {
341
+
342
+ // whether or not .php was added
343
+ $template_slug = preg_replace( '/.php$/', '', $template );
344
+ $template = $template_slug . '.php';
345
+
346
+ // Set to the default
347
+ $file = $this->plugin_dir . 'views/' . $template;
348
+
349
+ // Look for a custom version
350
+ if ( $theme_file = locate_template( array( $this->widget_text_domain . '/' . $template ) ) ) {
351
+ $file = $theme_file;
352
+ }
353
+
354
+ return apply_filters( 'dpe_fpw_template_' . $template, $file );
355
+
356
+ }
357
+
358
+ /**
359
+ * Return a list of terms for the chosen taxonomy
360
+ */
361
+ public function terms_checklist( $taxonomy, $sel_terms = array() ) {
362
+
363
+ if ( empty( $taxonomy ) && isset( $_POST['taxonomy'] ) )
364
+ $taxonomy = esc_attr( $_POST['taxonomy'] );
365
+
366
+ if ( empty( $taxonomy ) || 'none' == $taxonomy ) {
367
+ echo false;
368
+ if( isset ( $_POST['action'] ) && 'dpe_fp_get_terms' === $_POST['action'] ) {
369
+ die();
370
+ }
371
+ }
372
+
373
+ if( isset ( $_POST['widget_id'] ) ) {
374
+ $widget_id = intval( $_POST['widget_id'] );
375
+ } else {
376
+ $widget_id = $this->number;
377
+ }
378
+
379
+ if( empty ( $sel_terms ) ) {
380
+ $settings = get_option( $this->option_name );
381
+ if( isset ( $settings[$widget_id]['taxonomy'] ) && $taxonomy == $settings[$widget_id]['taxonomy'] ) {
382
+ $sel_terms = $settings[$widget_id]['term'];
383
+ }
384
+ }
385
+
386
+ $args = array (
387
+ 'taxonomy' => $taxonomy,
388
+ 'selected_cats' => $sel_terms,
389
+ );
390
+
391
+ ob_start();
392
+ wp_terms_checklist( 0, $args );
393
+ $terms_html = ob_get_contents();
394
+ ob_end_clean();
395
+
396
+ if( ! empty( $terms_html ) ) {
397
+ $output = '<ul class="categorychecklist termschecklist form-no-clear">';
398
+ $output .= $terms_html;
399
+ $output .= "</ul>\n";
400
+ } else {
401
+ $output = '<p>' . __( 'No terms found.', $this->widget_text_domain ) . '</p>';
402
+ }
403
+
404
+ echo ( $output );
405
+
406
+ if( isset ( $_POST['action'] ) && 'dpe_fp_get_terms' === $_POST['action'] ) {
407
+ die();
408
+ }
409
+
410
+ }
411
+
412
+ /**
413
+ * Return a list of post types
414
+ */
415
+ public function posttype_checklist( $posttype ) {
416
+
417
+ $output = '<ul class="categorychecklist posttypechecklist form-no-clear">';
418
+ foreach ( $this->posttypes as $type ) {
419
+ $output .= "\n<li>" . '<label class="selectit"><input value="' . esc_attr( $type->name ) . '" type="checkbox" name="' . $this->get_field_name( 'posttype' ) . '[]"' . checked( in_array( $type->name, (array)$posttype ), true, false ) . ' /> ' . esc_html( $type->labels->name ) . "</label></li>\n";
420
+ }
421
+ $output .= "</ul>\n";
422
+
423
+ echo ( $output );
424
+
425
+ }
426
+
427
+ /**
428
+ * Setup a number of default variables used throughout the plugin
429
+ *
430
+ * Since 3.3.1
431
+ *
432
+ */
433
+ public function setup_defaults() {
434
+
435
+ // Get the registered post types
436
+ $this->posttypes = get_post_types( array( 'public' => true ), 'objects' );
437
+ $this->pt_names = get_post_types( array( 'public' => true ), 'names' );
438
+
439
+ // Get the registered taxonomies
440
+ $this->taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );
441
+ $this->tax_names = get_taxonomies( array( 'public' => true ), 'names' );
442
+ $this->tax_names[] = 'none';
443
+
444
+ // Get the registered image sizes
445
+ $this->thumbsizes = get_intermediate_image_sizes();
446
+
447
+ // Set the options for orderby
448
+ $this->orderbys = array(
449
+ 'date' => __( 'Publish Date', $this->widget_text_domain ),
450
+ 'modified' => __( 'Modified Date', $this->widget_text_domain ),
451
+ 'title' => __( 'Title', $this->widget_text_domain ),
452
+ 'menu_order' => __( 'Menu Order', $this->widget_text_domain ),
453
+ 'ID' => __( 'Post ID', $this->widget_text_domain ),
454
+ 'author' => __( 'Author', $this->widget_text_domain ),
455
+ 'name' => __( 'Post Slug', $this->widget_text_domain ),
456
+ 'comment_count' => __( 'Comment Count', $this->widget_text_domain ),
457
+ 'rand' => __( 'Random', $this->widget_text_domain ),
458
+ 'post__in' => __( 'Post ID Order', $this->widget_text_domain ),
459
+ );
460
+
461
+ // Set the options for order
462
+ $this->orders = array(
463
+ 'ASC' => __( 'Ascending', $this->widget_text_domain ),
464
+ 'DESC' => __( 'Descending', $this->widget_text_domain ),
465
+ );
466
+
467
+ // Set the available templates
468
+ $this->templates = wp_cache_get( 'templates', $this->widget_slug );
469
+
470
+ if( false === $this->templates ) {
471
+ $this->templates = (array) $this->get_files( 'php', 0, true );
472
+ wp_cache_set( 'templates', $this->templates, $this->widget_slug );
473
+ }
474
+
475
+
476
+ }
477
+
478
+ /**
479
+ * Return template files from the current theme, parent theme and the plugin views directory.
480
+ *
481
+ * @since 3.3.1
482
+ * @access public
483
+ *
484
+ * Based on the function of the same name in wp-includes/class-wp-theme.php
485
+ *
486
+ * @param mixed $type Optional. Array of extensions to return. Defaults to all files (null).
487
+ * @param int $depth Optional. How deep to search for files. Defaults to a flat scan (0 depth). -1 depth is infinite.
488
+ * @param bool $search_parent Optional. Whether to return parent files. Defaults to false.
489
+ * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values
490
+ * being absolute paths.
491
+ */
492
+ public function get_files( $type = null, $depth = 0, $search_parent = false ) {
493
+
494
+ $files = array();
495
+ $theme_dir = get_stylesheet_directory() . '/' . $this->widget_text_domain;
496
+ $plugin_dir = $this->plugin_dir . '/views';
497
+
498
+ // Check the current theme
499
+ if( is_dir( $theme_dir ) ) {
500
+ $files += (array) self::scandir( $theme_dir, $type, $depth );
501
+ }
502
+
503
+ // Check the parent theme
504
+ if ( $search_parent && is_child_theme() ) {
505
+ $parent_theme_dir = get_template_directory() . '/' . $this->widget_text_domain;
506
+ if( is_dir( $parent_theme_dir ) ) {
507
+ $files += (array) self::scandir( $parent_theme_dir, $type, $depth );
508
+ }
509
+ }
510
+
511
+ // Check the plugin views folder
512
+ if( is_dir( $plugin_dir ) ) {
513
+ $files += (array) self::scandir( $plugin_dir, $type, $depth );
514
+ // Remove the admin view
515
+ unset( $files['admin.php'] );
516
+ }
517
+
518
+ return $files;
519
+ }
520
+
521
+ /**
522
+ * Scans a directory for files of a certain extension.
523
+ *
524
+ * @since 3.3.1
525
+ * @access private
526
+ *
527
+ * Based on the function of the same name in wp-includes/class-wp-theme.php
528
+ *
529
+ * @param string $path Absolute path to search.
530
+ * @param mixed Array of extensions to find, string of a single extension, or null for all extensions.
531
+ * @param int $depth How deep to search for files. Optional, defaults to a flat scan (0 depth). -1 depth is infinite.
532
+ * @param string $relative_path The basename of the absolute path. Used to control the returned path
533
+ * for the found files, particularly when this function recurses to lower depths.
534
+ */
535
+ private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) {
536
+ if ( ! is_dir( $path ) )
537
+ return false;
538
+
539
+ if ( $extensions ) {
540
+ $extensions = (array) $extensions;
541
+ $_extensions = implode( '|', $extensions );
542
+ }
543
+
544
+ $relative_path = trailingslashit( $relative_path );
545
+ if ( '/' == $relative_path )
546
+ $relative_path = '';
547
+
548
+ $results = scandir( $path );
549
+ $files = array();
550
+
551
+ foreach ( $results as $result ) {
552
+ if ( '.' == $result[0] )
553
+ continue;
554
+ if ( is_dir( $path . '/' . $result ) ) {
555
+ if ( ! $depth || 'CVS' == $result )
556
+ continue;
557
+ $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result );
558
+ $files = array_merge_recursive( $files, $found );
559
+ } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) {
560
+ $files[ $relative_path . $result ] = $path . '/' . $result;
561
+ }
562
+ }
563
+
564
+ return $files;
565
+ }
566
+
567
+ } // class Flexible_Posts_Widget
index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
js/admin.js CHANGED
@@ -8,7 +8,7 @@
8
  /* global ajaxurl, fpwL10n */
9
 
10
  jQuery(function() {
11
-
12
  // Setup the show/hide thumbnails box
13
  jQuery('input.dpe-fp-thumbnail').each( function() {
14
  if( this.checked ) {
@@ -17,7 +17,7 @@ jQuery(function() {
17
  jQuery(this).parent().next().slideUp('fast');
18
  }
19
  });
20
-
21
  // Enable the Get Em By tabs
22
  jQuery('.dpe-fp-widget .getembytabs').tabs({
23
  // Set the active tab to a widget option
@@ -60,21 +60,18 @@ jQuery('#widgets-right').on('change', 'select.dpe-fp-taxonomy', function() {
60
 
61
  var terms_div = jQuery(this).parent().nextAll('div.terms'),
62
  terms_label = jQuery(this).parent().next('label'),
63
- selected_terms = [], data = {};
64
-
 
65
  // If we're not ignoring Taxonomy & Term...
66
  if( jQuery(this).val() !== 'none' ) {
67
 
68
  terms_label.html(fpwL10n.gettingTerms).show();
69
-
70
- terms_div.find('input:checked').each(function () {
71
- selected_terms.push( jQuery(this).val() );
72
- });
73
-
74
  data = {
75
- action: 'dpe_fp_get_terms',
76
- taxonomy: jQuery(this).val(),
77
- term: selected_terms
78
  };
79
 
80
  jQuery.post(ajaxurl, data, function(response) {
8
  /* global ajaxurl, fpwL10n */
9
 
10
  jQuery(function() {
11
+
12
  // Setup the show/hide thumbnails box
13
  jQuery('input.dpe-fp-thumbnail').each( function() {
14
  if( this.checked ) {
17
  jQuery(this).parent().next().slideUp('fast');
18
  }
19
  });
20
+
21
  // Enable the Get Em By tabs
22
  jQuery('.dpe-fp-widget .getembytabs').tabs({
23
  // Set the active tab to a widget option
60
 
61
  var terms_div = jQuery(this).parent().nextAll('div.terms'),
62
  terms_label = jQuery(this).parent().next('label'),
63
+ widget_id = jQuery(this).parents('form').find('input.widget_number'),
64
+ data = {};
65
+
66
  // If we're not ignoring Taxonomy & Term...
67
  if( jQuery(this).val() !== 'none' ) {
68
 
69
  terms_label.html(fpwL10n.gettingTerms).show();
70
+
 
 
 
 
71
  data = {
72
+ action: 'dpe_fp_get_terms',
73
+ widget_id: widget_id.val(),
74
+ taxonomy: jQuery(this).val()
75
  };
76
 
77
  jQuery.post(ajaxurl, data, function(response) {
js/admin.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(function(){jQuery("input.dpe-fp-thumbnail").each(function(){this.checked?jQuery(this).parent().next().slideDown("fast"):jQuery(this).parent().next().slideUp("fast")}),jQuery(".dpe-fp-widget .getembytabs").tabs({activate:function(){jQuery(this).find(".cur_tab").val(jQuery(this).tabs("option","active"))},create:function(){jQuery(this).tabs("option","active",jQuery(this).find(".cur_tab").val())}})}),jQuery(document).ajaxComplete(function(){jQuery(".dpe-fp-widget .getembytabs").tabs({activate:function(){jQuery(this).find(".cur_tab").val(jQuery(this).tabs("option","active"))},create:function(){jQuery(this).tabs("option","active",jQuery(this).find(".cur_tab").val())}})}),jQuery("#widgets-right").on("change","input.dpe-fp-thumbnail",function(){this.checked?jQuery(this).parent().next().slideDown("fast"):jQuery(this).parent().next().slideUp("fast")}),jQuery("#widgets-right").on("change","select.dpe-fp-taxonomy",function(){var terms_div=jQuery(this).parent().nextAll("div.terms"),terms_label=jQuery(this).parent().next("label"),selected_terms=[],data={};"none"!==jQuery(this).val()?(terms_label.html(fpwL10n.gettingTerms).show(),terms_div.find("input:checked").each(function(){selected_terms.push(jQuery(this).val())}),data={action:"dpe_fp_get_terms",taxonomy:jQuery(this).val(),term:selected_terms},jQuery.post(ajaxurl,data,function(response){terms_div.html(response),terms_label.html(fpwL10n.selectTerms).show(),terms_div.slideDown()}).error(function(){terms_label.html(fpwL10n.noTermsFound).show()})):(terms_div.slideUp().html(""),terms_label.hide())});
1
+ jQuery(function(){jQuery("input.dpe-fp-thumbnail").each(function(){if(this.checked){jQuery(this).parent().next().slideDown("fast")}else{jQuery(this).parent().next().slideUp("fast")}});jQuery(".dpe-fp-widget .getembytabs").tabs({activate:function(){jQuery(this).find(".cur_tab").val(jQuery(this).tabs("option","active"))},create:function(){jQuery(this).tabs("option","active",jQuery(this).find(".cur_tab").val())}})});jQuery(document).ajaxComplete(function(){jQuery(".dpe-fp-widget .getembytabs").tabs({activate:function(){jQuery(this).find(".cur_tab").val(jQuery(this).tabs("option","active"))},create:function(){jQuery(this).tabs("option","active",jQuery(this).find(".cur_tab").val())}})});jQuery("#widgets-right").on("change","input.dpe-fp-thumbnail",function(){if(this.checked){jQuery(this).parent().next().slideDown("fast")}else{jQuery(this).parent().next().slideUp("fast")}});jQuery("#widgets-right").on("change","select.dpe-fp-taxonomy",function(){var c=jQuery(this).parent().nextAll("div.terms"),a=jQuery(this).parent().next("label"),b=jQuery(this).parents("form").find("input.widget_number"),d={};if(jQuery(this).val()!=="none"){a.html(fpwL10n.gettingTerms).show();d={action:"dpe_fp_get_terms",widget_id:b.val(),taxonomy:jQuery(this).val()};jQuery.post(ajaxurl,d,function(e){c.html(e);a.html(fpwL10n.selectTerms).show();c.slideDown()}).error(function(){a.html(fpwL10n.noTermsFound).show()})}else{c.slideUp().html("");a.hide()}});
readme.html DELETED
@@ -1,292 +0,0 @@
1
- <h1>Flexible Posts Widget</h1>
2
-
3
- <p><strong>Contributors:</strong> dpe415<br/>
4
- <strong>Donate link:</strong> https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=DJKSKHJWYAWDU<br/>
5
- <strong>Tags:</strong> widget, widgets, posts, categories, tags, recent posts, thumbnails, custom post types, custom taxonomies, feature image<br/>
6
- <strong>Requires at least:</strong> 3.2<br/>
7
- <strong>Tested up to:</strong> 4.1<br/>
8
- <strong>Stable tag:</strong> 3.4.1
9
- <strong>License:</strong> GPL2 or later<br/>
10
- <strong>License URI:</strong> http://www.gnu.org/licenses/gpl-2.0.html</p>
11
-
12
- <p>An advanced posts display widget with many options. Display posts in your sidebars any way you&rsquo;d like!</p>
13
-
14
- <h2>Description</h2>
15
-
16
- <p>The default Recent Posts widget is exceptionally basic. I always find myself in need of a way to easily display a selection of posts from any combination post type or taxonomy. Hence, Flexible Post Widget.</p>
17
-
18
- <p>Flexible Posts Widget (FPW) is more than just a simple alternative to the default Recent Posts widget. With many per-instance options it is highly customizable and allows advanced users to display the resulting posts virtually any way imaginable.</p>
19
-
20
- <h3>Features &amp; options</h3>
21
-
22
- <ul>
23
- <li>Customizable widget title</li>
24
- <li>Get posts by post type(s) and/or taxonomy &amp; term(s) or directly by a list of post IDs.</li>
25
- <li>Control the number of posts displayed and the number of posts to offset.</li>
26
- <li>Option to display the post feature image.</li>
27
- <li>Select the post feature image size to display from existing image sizes: thumbnail, medium, large, post-thumbnail or any size defined by the current theme.</li>
28
- <li>Order posts by: date, modified date, ID, title, menu order, random, Post ID Order; and sort posts: ascending or descending.</li>
29
- <li>Each widget&rsquo;s output can be customized by user-defined templates added to the current theme folder.</li>
30
- </ul>
31
-
32
- <h3>Supported Languages</h3>
33
-
34
- <ul>
35
- <li>English</li>
36
- <li>Finnish</li>
37
- <li>Italian</li>
38
- <li>Polish</li>
39
- <li>Russian</li>
40
- <li>Spanish</li>
41
- </ul>
42
-
43
- <h2>Installation</h2>
44
-
45
- <ol>
46
- <li>Upload the <code>flexible-posts-widget</code> folder to the <code>/wp-content/plugins/</code> directory.</li>
47
- <li>Activate the plugin through the &lsquo;Plugins&rsquo; menu in WordPress.</li>
48
- <li>Go to &lsquo;Appearance&rsquo; > &lsquo;Widgets&rsquo; and place the widget into a sidebar to configure it.</li>
49
- </ol>
50
-
51
- <h2>To use a custom HTML output template</h2>
52
-
53
- <ol>
54
- <li>Create a folder called <code>flexible-posts-widget</code> in the root folder of the currently active theme.</li>
55
- <li>Copy <code>widget.php</code> from within the plugin&rsquo;s <code>views</code> folder into your theme&rsquo;s new <code>flexible-posts-widget</code> folder.</li>
56
- <li>Rename your theme&rsquo;s <code>widget.php</code> template file to a name of your choice. Example: <code>my-template.php</code>.</li>
57
- <li>Go to &lsquo;Appearance&rsquo; > &lsquo;Widgets&rsquo; in WordPress to configure an instance of the widget.</li>
58
- <li>In the &lsquo;Template Filename&rsquo; field choose the name of the template file you added to your theme. Example: <code>My Template</code></li>
59
- </ol>
60
-
61
- <h2>Frequently Asked Questions</h2>
62
-
63
- <h3>How does the &ldquo;Comma-separated list of post IDs&rdquo; work?</h3>
64
-
65
- <p>The third option (tab) available for getting posts is directly with a list of post IDs. If there is a value in this field, any settings in the &ldquo;Post Type&rdquo; or &ldquo;Taxonomy &amp; Term&rdquo; tabs will be ignored and all public post types will be queried for the specific post IDs provided. All the other widget options (Display, Thumbnails and Template settings) will still be applied.</p>
66
-
67
- <h3>How do I find a post&rsquo;s ID?</h3>
68
-
69
- <p>Per a <a href="http://wordpress.org/support/topic/where-can-find-the-post-id">WordPress support thread</a>:</p>
70
-
71
- <p>Go to Posts in your WordPress admin, and click the post you need the ID of. Then, if you look in the address bar of your browser, you&rsquo;ll see something like this:</p>
72
-
73
- <p><code>http://example.com/wp-admin/post.php?post=1280&amp;action=edit</code></p>
74
-
75
- <p>The number, in this case 1280, is the post ID.</p>
76
-
77
- <h3>How can I display custom fields (custom meta values) with FPW?</h3>
78
-
79
- <p>You&rsquo;ll want to create a custom HTML template by following <a href="http://wordpress.org/extend/plugins/flexible-posts-widget/installation/" title="View instructions for creating custom FPW templates">the instructions</a> and then you can use the standard WordPress <a href="http://codex.wordpress.org/Custom_Fields" title="View custom field functions on the WordPress Codex">Custom Field</a> functions the same way you would if you were editing your theme&rsquo;s other template files.</p>
80
-
81
- <p>A simple code example for a custom field named &ldquo;test_field&rdquo; <em>might</em> look like the following:
82
- <code>$test_field_value = get_post_meta( get_the_ID(), 'test_field', true );
83
- echo $test_field_value;</code></p>
84
-
85
- <h3>How can I style the images, titles or other widget output a certain way?</h3>
86
-
87
- <p>FPW intentionally does NOT add any styling of it&rsquo;s own. To adjust the font size, color, alignment, image size, etc. of any output from this widget, you&rsquo;ll need to edit your theme&rsquo;s styles.</p>
88
-
89
- <h3>Does this plugin/widget insert any styles or scripts into my site?</h3>
90
-
91
- <p>FPW does not add styles or scripts to your public theme. The plugin is intentionally designed to work within your existing theme. FPW does add one stylesheet and one JavaScript to the Widgets page in wp-admin to help with the administration of any FPWs in use.</p>
92
-
93
- <h3>Want to add support for another language?</h3>
94
-
95
- <p>I&rsquo;d love to support more languages. The plugin&rsquo;s POT file is available with the download. Feel free to post PO &amp; MO files for your language to a <a href="http://wordpress.org/tags/flexible-posts-widget/">new forum thread</a> and I&rsquo;ll get them added to the plugin.</p>
96
-
97
- <h3>Questions, Support &amp; Bug Reports</h3>
98
-
99
- <p>To get answers to your questions, request help or submit a bug report, please start a <a href="http://wordpress.org/tags/flexible-posts-widget/">new forum thread</a>.</p>
100
-
101
- <h2>Upgrade Notice</h2>
102
-
103
- <p>When upgrading from one major version to another (version 1.x to version 2.x to version 3.x, etc), please remember to verify your settings for any existing widgets. Not all settings combinations will be saved after a major release upgrade.</p>
104
-
105
- <h2>Other Notes</h2>
106
-
107
- <h3>Upgrading from one major version to another</h3>
108
-
109
- <p>When upgrading between major releases (version 1.x to version 2.x to version 3.x, etc), please remember to verify your settings for any existing widgets. Not all settings combinations will be saved after a major release upgrade.</p>
110
-
111
- <h3>Future updates &amp; feature requests list</h3>
112
-
113
- <ul>
114
- <li>Multilingual support (Polylang, WPML, etc.)</li>
115
- <li>Make Tax-Term drop-down hierarchical.</li>
116
- <li>Use search box instead of ID text field for post id&rsquo;s</li>
117
- <li>Shortcode functionality.</li>
118
- <li>Get posts by Author.</li>
119
- <li>Filter out the post currently being viewed.</li>
120
- <li>Get posts from the same archive (term/post type/etc).</li>
121
- <li>Limit results by a time period.</li>
122
- </ul>
123
-
124
- <h2>Changelog</h2>
125
-
126
- <h3>3.4.1</h3>
127
-
128
- <ul>
129
- <li>Version bump for WordPress 4.1 support.</li>
130
- </ul>
131
-
132
- <h3>3.4</h3>
133
-
134
- <ul>
135
- <li>Added Finnish language support. (Props: @eccola)</li>
136
- <li>Made the Template Filename field a select box based on the templates available in the current theme, the parent theme (if the current theme is a child theme) and the plugin&rsquo;s views folder. (Props @w3b-beweb)</li>
137
- <li>Added a new default template (<code>Default.php</code>) that works better in most sidebar situations. The current default template (<code>Widget.php</code>) will be used by any existing widgets unless manually changed.</li>
138
- <li>Added support to order posts by Modified Date.</li>
139
- <li>Migrated admin CSS to SASS.</li>
140
- <li>Much code clean up and refactoring.</li>
141
- <li>Fixed an issue with language files not loading properly (Props @sajtdavid).</li>
142
- </ul>
143
-
144
- <h3>3.3.1</h3>
145
-
146
- <ul>
147
- <li>Added plugin icon.</li>
148
- <li>Version bump for WordPress 4.0 support.</li>
149
- </ul>
150
-
151
- <h3>3.3</h3>
152
-
153
- <ul>
154
- <li>Refactored the PHP Class to encapsulate the plugin.</li>
155
- <li>Added the ability to sort posts by &ldquo;Post ID Order&rdquo;. Useful when getting posts using the ID tab (<code>post__in</code>). (Props: @cinus89)</li>
156
- <li>Added Russian translation. (Props: @mizhgun)</li>
157
- <li>Tested To bump for WordPress 3.9 support.</li>
158
- </ul>
159
-
160
-
161
- <h3>3.2.2</h3>
162
-
163
- <ul>
164
- <li>Version bump for WordPress 3.8 support</li>
165
- </ul>
166
-
167
-
168
- <h3>3.2.1</h3>
169
-
170
- <ul>
171
- <li>Added Italian language support. (Props: @adriano-esposito)</li>
172
- </ul>
173
-
174
-
175
- <h3>3.2</h3>
176
-
177
- <ul>
178
- <li>Added option to ignore sticky posts.</li>
179
- <li>Added support to get post by post ID directly.</li>
180
- <li>Added Polish language support. (Props: @Invens)</li>
181
- <li>Added a few filters: <code>dpe_fpw_args</code> to filter the query vars before submitting the query and <code>'dpe_fpw_template_' . [$template_name]</code> to filter the selected template.</li>
182
- </ul>
183
-
184
-
185
- <h3>3.1.2</h3>
186
-
187
- <ul>
188
- <li>Fixed several pesky PHP notices. (Props: @eeb1)</li>
189
- </ul>
190
-
191
-
192
- <h3>3.1.1</h3>
193
-
194
- <ul>
195
- <li>Fixed incorrect use of rtrim in getTemplateHierarchy when getting custom template files. (Props: @mortenf)</li>
196
- </ul>
197
-
198
-
199
- <h3>3.1</h3>
200
-
201
- <ul>
202
- <li>Internationalized and added Spanish language support. (Props: @elarequi)</li>
203
- <li>Added support for Media post types with &ldquo;image/&rdquo; mime types to be displayed directly in the default template.</li>
204
- </ul>
205
-
206
-
207
- <h3>3.0.2</h3>
208
-
209
- <ul>
210
- <li>Bug fix: Added a check to make sure both taxonomy &amp; term are set for tax queries.</li>
211
- </ul>
212
-
213
-
214
- <h3>3.0.1</h3>
215
-
216
- <ul>
217
- <li>Bug fix: Not able to get all registered post types &amp; taxonomies until after widget init. Had to reorder some code.</li>
218
- <li>Bug fix: when getting post types for display in widget admin. (Props: @angelfish276)</li>
219
- </ul>
220
-
221
-
222
- <h3>3.0</h3>
223
-
224
- <ul>
225
- <li>Allow widgets to query by post type and/or taxonomy &amp; term instead of just one or the other. (Props: @vernal)</li>
226
- <li>Allow widgets to query by multiple post types and multiple terms within the same taxonomy. (Props: @vernal)</li>
227
- <li>Changed the list of available post types and taxonomies from every possible option to just those that are public.</li>
228
- <li>General UI enhancements for the widget admin.</li>
229
- <li>Some minor code cleanup and security improvements.</li>
230
- </ul>
231
-
232
-
233
- <h3>2.1.1</h3>
234
-
235
- <ul>
236
- <li>Fixed a source order bug in the widget.php template file. (Props: @carstenbach).</li>
237
- </ul>
238
-
239
-
240
- <h3>2.1</h3>
241
-
242
- <ul>
243
- <li>Added offset parameter to display options.</li>
244
- </ul>
245
-
246
-
247
- <h3>2.0</h3>
248
-
249
- <ul>
250
- <li><em>Upgrade notice:</em> When upgrading from v1.x.x to v2.x, remember to double-check the settings for any existing widgets.</li>
251
- <li>Dynamically populate available terms based on selected taxonomy.</li>
252
- <li>Make the &ldquo;Get Posts By&rdquo; section selectable and only show the chosen method: Taxonomy &amp; Term or Post Type.</li>
253
- <li>Miscellaneous admin improvements.</li>
254
- </ul>
255
-
256
-
257
- <h3>1.0.5</h3>
258
-
259
- <ul>
260
- <li>Bug fix: Removed post_status &lsquo;private&rsquo; from wp_queries. We don&rsquo;t want to show private posts in our loops.</li>
261
- </ul>
262
-
263
-
264
- <h3>1.0.4</h3>
265
-
266
- <ul>
267
- <li>Fixed an issue where post thumbnails aren&rsquo;t displaying.</li>
268
- </ul>
269
-
270
-
271
- <h3>1.0.3</h3>
272
-
273
- <ul>
274
- <li>Fixed PHP notices that showed in the admin when WP_DEBUG is enabled</li>
275
- <li>Added some stub code for future admin JavaScripts (not active yet).</li>
276
- <li>Readme.txt updates</li>
277
- </ul>
278
-
279
-
280
- <h3>1.0.2</h3>
281
-
282
- <ul>
283
- <li>Readme.txt updates</li>
284
- </ul>
285
-
286
-
287
- <h3>1.0</h3>
288
-
289
- <ul>
290
- <li>First public release</li>
291
- </ul>
292
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.md CHANGED
@@ -1,184 +1,208 @@
1
- # Flexible Posts Widget #
2
- **Contributors:** dpe415
3
- **Donate link:** https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DJKSKHJWYAWDU
4
- **Tags:** widget, widgets, posts, categories, tags, recent posts, thumbnails, custom post types, custom taxonomies, feature image
5
- **Requires at least:** 3.2
6
- **Tested up to:** 4.1
7
- **Stable tag:** 3.4.1
8
- **License:** GPL2 or later
9
- **License URI:** http://www.gnu.org/licenses/gpl-2.0.html
10
-
11
- An advanced posts display widget with many options. Display posts in your sidebars any way you'd like!
12
-
13
- ## Description ##
14
- The default Recent Posts widget is exceptionally basic. I always find myself in need of a way to easily display a selection of posts from any combination post type or taxonomy. Hence, Flexible Post Widget.
15
-
16
- Flexible Posts Widget (FPW) is more than just a simple alternative to the default Recent Posts widget. With many per-instance options it is highly customizable and allows advanced users to display the resulting posts virtually any way imaginable.
17
-
18
- ### Features & options ###
19
- * Customizable widget title
20
- * Get posts by post type(s) and/or taxonomy & term(s) or directly by a list of post IDs.
21
- * Control the number of posts displayed and the number of posts to offset.
22
- * Option to display the post feature image.
23
- * Select the post feature image size to display from existing image sizes: thumbnail, medium, large, post-thumbnail or any size defined by the current theme.
24
- * Order posts by: date, modified date, ID, title, menu order, random, Post ID Order; and sort posts: ascending or descending.
25
- * Each widget's output can be customized by user-defined templates added to the current theme folder.
26
-
27
- ### Supported Languages ###
28
- * English
29
- * Finnish
30
- * Italian
31
- * Polish
32
- * Russian
33
- * Spanish
34
-
35
- ## Installation ##
36
- 1. Upload the `flexible-posts-widget` folder to the `/wp-content/plugins/` directory.
37
- 1. Activate the plugin through the 'Plugins' menu in WordPress.
38
- 1. Go to 'Appearance' > 'Widgets' and place the widget into a sidebar to configure it.
39
-
40
- ## To use a custom HTML output template ##
41
- 1. Create a folder called `flexible-posts-widget` in the root folder of the currently active theme.
42
- 1. Copy `widget.php` from within the plugin's `views` folder into your theme's new `flexible-posts-widget` folder.
43
- 1. Rename your theme's `widget.php` template file to a name of your choice. Example: `my-template.php`.
44
- 1. Go to 'Appearance' > 'Widgets' in WordPress to configure an instance of the widget.
45
- 1. In the 'Template Filename' field choose the name of the template file you added to your theme. Example: `My Template`
46
-
47
- ## Frequently Asked Questions ##
48
-
49
- ### How does the "Comma-separated list of post IDs" work? ###
50
- The third option (tab) available for getting posts is directly with a list of post IDs. If there is a value in this field, any settings in the "Post Type" or "Taxonomy & Term" tabs will be ignored and all public post types will be queried for the specific post IDs provided. All the other widget options (Display, Thumbnails and Template settings) will still be applied.
51
-
52
- ### How do I find a post's ID? ###
53
- Per a [WordPress support thread](http://wordpress.org/support/topic/where-can-find-the-post-id):
54
-
55
- Go to Posts in your WordPress admin, and click the post you need the ID of. Then, if you look in the address bar of your browser, you'll see something like this:
56
-
57
- `http://example.com/wp-admin/post.php?post=1280&action=edit`
58
-
59
- The number, in this case 1280, is the post ID.
60
-
61
- ### How can I display custom fields (custom meta values) with FPW? ###
62
- You'll want to create a custom HTML template by following [the instructions](http://wordpress.org/extend/plugins/flexible-posts-widget/installation/ "View instructions for creating custom FPW templates") and then you can use the standard WordPress [Custom Field](http://codex.wordpress.org/Custom_Fields "View custom field functions on the WordPress Codex") functions the same way you would if you were editing your theme's other template files.
63
-
64
- A simple code example for a custom field named "test_field" _might_ look like the following:
65
- `$test_field_value = get_post_meta( get_the_ID(), 'test_field', true );
66
- echo $test_field_value;`
67
-
68
- ### How can I style the images, titles or other widget output a certain way? ###
69
- FPW intentionally does NOT add any styling of it's own. To adjust the font size, color, alignment, image size, etc. of any output from this widget, you'll need to edit your theme's styles.
70
-
71
- ### Does this plugin/widget insert any styles or scripts into my site? ###
72
- FPW does not add styles or scripts to your public theme. The plugin is intentionally designed to work within your existing theme. FPW does add one stylesheet and one JavaScript to the Widgets page in wp-admin to help with the administration of any FPWs in use.
73
-
74
- ### Want to add support for another language? ###
75
- I'd love to support more languages. The plugin's POT file is available with the download. Feel free to post PO & MO files for your language to a [new forum thread](http://wordpress.org/tags/flexible-posts-widget/) and I'll get them added to the plugin.
76
-
77
- ### Questions, Support & Bug Reports ###
78
- To get answers to your questions, request help or submit a bug report, please start a [new forum thread](http://wordpress.org/tags/flexible-posts-widget/).
79
-
80
- ## Upgrade Notice ##
81
- When upgrading from one major version to another (version 1.x to version 2.x to version 3.x, etc), please remember to verify your settings for any existing widgets. Not all settings combinations will be saved after a major release upgrade.
82
-
83
- ## Other Notes ##
84
- ### Upgrading from one major version to another ###
85
- When upgrading between major releases (version 1.x to version 2.x to version 3.x, etc), please remember to verify your settings for any existing widgets. Not all settings combinations will be saved after a major release upgrade.
86
-
87
- ### Future updates & feature requests list ###
88
- * Multilingual support (Polylang, WPML, etc.)
89
- * Make Tax-Term drop-down hierarchical.
90
- * Use search box instead of ID text field for post id's
91
- * Shortcode functionality.
92
- * Get posts by Author.
93
- * Filter out the post currently being viewed.
94
- * Get posts from the same archive (term/post type/etc).
95
- * Limit results by a time period.
96
-
97
- ## Changelog ##
98
-
99
- ### 3.4.1 ###
100
- * Version bump for WordPress 4.1 support.
101
-
102
- ### 3.4 ###
103
- * Added Finnish language support. (Props: @eccola)
104
- * Made the Template Filename field a select box based on the templates available in the current theme, the parent theme (if the current theme is a child theme) and the plugin's views folder. (Props @w3b-beweb)
105
- * Added a new default template (`Default.php`) that works better in most sidebar situations. The current default template (`Widget.php`) will be used by any existing widgets unless manually changed.
106
- * Added support to order posts by Modified Date.
107
- * Migrated admin CSS to SASS.
108
- * Much code clean up and refactoring.
109
- * Fixed an issue with language files not loading properly (Props @sajtdavid).
110
-
111
- ### 3.3.1 ###
112
- * Added plugin icon.
113
- * Version bump for WordPress 4.0 support.
114
-
115
- ### 3.3 ###
116
- * Refactored the PHP Class to encapsulate the plugin.
117
- * Added the ability to sort posts by "Post ID Order". Useful when getting posts using the ID tab (`post__in`). (Props: @cinus89)
118
- * Added Russian translation. (Props: @mizhgun)
119
- * Tested To bump for WordPress 3.9 support.
120
-
121
- ### 3.2.2 ###
122
- * Version bump for WordPress 3.8 support
123
-
124
- ### 3.2.1 ###
125
- * Added Italian language support. (Props: @adriano-esposito)
126
-
127
- ### 3.2 ###
128
- * Added option to ignore sticky posts.
129
- * Added support to get post by post ID directly.
130
- * Added Polish language support. (Props: @Invens)
131
- * Added a few filters: `dpe_fpw_args` to filter the query vars before submitting the query and `'dpe_fpw_template_' . [$template_name]` to filter the selected template.
132
-
133
- ### 3.1.2 ###
134
- * Fixed several pesky PHP notices. (Props: @eeb1)
135
-
136
- ### 3.1.1 ###
137
- * Fixed incorrect use of rtrim in getTemplateHierarchy when getting custom template files. (Props: @mortenf)
138
-
139
- ### 3.1 ###
140
- * Internationalized and added Spanish language support. (Props: @elarequi)
141
- * Added support for Media post types with "image/" mime types to be displayed directly in the default template.
142
-
143
- ### 3.0.2 ###
144
- * Bug fix: Added a check to make sure both taxonomy & term are set for tax queries.
145
-
146
- ### 3.0.1 ###
147
- * Bug fix: Not able to get all registered post types & taxonomies until after widget init. Had to reorder some code.
148
- * Bug fix: when getting post types for display in widget admin. (Props: @angelfish276)
149
-
150
- ### 3.0 ###
151
- * Allow widgets to query by post type and/or taxonomy & term instead of just one or the other. (Props: @vernal)
152
- * Allow widgets to query by multiple post types and multiple terms within the same taxonomy. (Props: @vernal)
153
- * Changed the list of available post types and taxonomies from every possible option to just those that are public.
154
- * General UI enhancements for the widget admin.
155
- * Some minor code cleanup and security improvements.
156
-
157
- ### 2.1.1 ###
158
- * Fixed a source order bug in the widget.php template file. (Props: @carstenbach).
159
-
160
- ### 2.1 ###
161
- * Added offset parameter to display options.
162
-
163
- ### 2.0 ###
164
- * *Upgrade notice:* When upgrading from v1.x.x to v2.x, remember to double-check the settings for any existing widgets.
165
- * Dynamically populate available terms based on selected taxonomy.
166
- * Make the "Get Posts By" section selectable and only show the chosen method: Taxonomy & Term or Post Type.
167
- * Miscellaneous admin improvements.
168
-
169
- ### 1.0.5 ###
170
- * Bug fix: Removed post_status 'private' from wp_queries. We don't want to show private posts in our loops.
171
-
172
- ### 1.0.4 ###
173
- * Fixed an issue where post thumbnails aren't displaying.
174
-
175
- ### 1.0.3 ###
176
- * Fixed PHP notices that showed in the admin when WP_DEBUG is enabled
177
- * Added some stub code for future admin JavaScripts (not active yet).
178
- * Readme.txt updates
179
-
180
- ### 1.0.2 ###
181
- * Readme.txt updates
182
-
183
- ### 1.0 ###
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  * First public release
1
+ # Flexible Posts Widget #
2
+ **Contributors:** dpe415
3
+ **Donate link:** https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DJKSKHJWYAWDU
4
+ **Tags:** widget, widgets, posts, categories, tags, recent posts, thumbnails, custom post types, custom taxonomies, feature image
5
+ **Requires at least:** 3.2
6
+ **Tested up to:** 4.7
7
+ **Stable tag:** 3.5.0
8
+ **License:** GPL2 or later
9
+ **License URI:** http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ An advanced posts display widget with many options. Display posts in your sidebars any way you'd like!
12
+
13
+ ## Description ##
14
+ The default Recent Posts widget is exceptionally basic. I always find myself in need of a way to easily display a selection of posts from any combination post type or taxonomy. Hence, Flexible Posts Widget.
15
+
16
+ Flexible Posts Widget (FPW) is more than just a simple alternative to the default Recent Posts widget. With many per-instance options it is highly customizable and allows advanced users to display the resulting posts virtually any way imaginable.
17
+
18
+ ### Features & options ###
19
+ * Customizable widget title
20
+ * Get posts by post type(s) and/or taxonomy & term(s) or directly by a list of post IDs.
21
+ * Control the number of posts displayed and the number of posts to offset.
22
+ * Option to display the post feature image.
23
+ * Select the post feature image size to display from existing image sizes: thumbnail, medium, large, post-thumbnail or any size defined by the current theme.
24
+ * Order posts by: date, modified date, ID, title, menu order, random, Post ID Order; and sort posts: ascending or descending.
25
+ * Each widget's output can be customized by user-defined templates added to the current theme folder.
26
+ * Multi Language support. Compatible with [WPML](http://wpml.org/) and [PolyLang](https://wordpress.org/plugins/polylang/) for sure. Not tested with other multi-language plugins, but it should work.
27
+
28
+ ## Installation ##
29
+ 1. Upload the `flexible-posts-widget` folder to the `/wp-content/plugins/` directory.
30
+ 1. Activate the plugin through the 'Plugins' menu in WordPress.
31
+ 1. Go to 'Appearance' > 'Widgets' and place the widget into a sidebar to configure it.
32
+
33
+ ### To use a custom HTML output template ###
34
+ 1. Create a folder called `flexible-posts-widget` in the root folder of the currently active theme.
35
+ 1. Copy `widget.php` from within the plugin's `views` folder into your theme's new `flexible-posts-widget` folder.
36
+ 1. Rename your theme's `widget.php` template file to a name of your choice. Example: `my-template.php`.
37
+ 1. Go to 'Appearance' > 'Widgets' in WordPress to configure an instance of the widget.
38
+ 1. In the 'Template Filename' field choose the name of the template file you added to your theme. Example: `My Template`
39
+
40
+ ## Frequently Asked Questions ##
41
+
42
+ ### How does the "Comma-separated list of post IDs" work? ###
43
+ The third option (tab) available for getting posts is directly with a list of post IDs. If there is a value in this field, any settings in the "Post Type" or "Taxonomy & Term" tabs will be ignored and all public post types will be queried for the specific post IDs provided. All the other widget options (Display, Thumbnails and Template settings) will still be applied.
44
+
45
+ ### How do I find a post's ID? ###
46
+ Per a [WordPress support thread](http://wordpress.org/support/topic/where-can-find-the-post-id):
47
+
48
+ Go to Posts in your WordPress admin, and click the post you need the ID of. Then, if you look in the address bar of your browser, you'll see something like this:
49
+
50
+ `http://example.com/wp-admin/post.php?post=1280&action=edit`
51
+
52
+ The number, in this case 1280, is the post ID.
53
+
54
+ ### How can I display custom fields (custom meta values) with FPW? ###
55
+ You'll want to create a custom HTML template by following [the instructions](http://wordpress.org/extend/plugins/flexible-posts-widget/installation/ "View instructions for creating custom FPW templates") and then you can use the standard WordPress [Custom Field](http://codex.wordpress.org/Custom_Fields "View custom field functions on the WordPress Codex") functions the same way you would if you were editing your theme's other template files.
56
+
57
+ A simple code example for a custom field named "test_field" _might_ look like the following:
58
+
59
+ ` $test_field_value = get_post_meta( get_the_ID(), 'test_field', true );
60
+ echo $test_field_value; `
61
+
62
+ ### How can I style the images, titles or other widget output a certain way? ###
63
+ FPW intentionally does NOT add any styling of it's own. To adjust the font size, color, alignment, image size, etc. of any output from this widget, you'll need to edit your theme's styles.
64
+
65
+ ### Does this plugin/widget insert any styles or scripts into my site? ###
66
+ FPW does not add styles or scripts to your public theme. The plugin is intentionally designed to work within your existing theme. FPW does add one stylesheet and one JavaScript to the Widgets page in wp-admin to help with the administration of any FPWs in use.
67
+
68
+ ### Want to add support for another language? ###
69
+ I'd love to support more languages. The plugin's POT file is available with the download. Feel free to post PO & MO files for your language to a [new forum thread](http://wordpress.org/tags/flexible-posts-widget/) and I'll get them added to the plugin.
70
+
71
+ ### Questions, Support & Bug Reports ###
72
+ To get answers to your questions, request help or submit a bug report, please start a [new forum thread](http://wordpress.org/tags/flexible-posts-widget/).
73
+
74
+ ## Screenshots ##
75
+ ###1. Configuring a FPW in wp-admin with the Post Type tab displayed.###
76
+ ![Configuring a FPW in wp-admin with the Post Type tab displayed.](https://s.w.org/plugins/flexible-posts-widget/screenshot-1.png)
77
+
78
+ ###2. Configuring a FPW in wp-admin with the Taxonomy & Term tab displayed.###
79
+ ![Configuring a FPW in wp-admin with the Taxonomy & Term tab displayed.](https://s.w.org/plugins/flexible-posts-widget/screenshot-2.png)
80
+
81
+ ###3. Configuring a FPW in wp-admin with the ID tab displayed.###
82
+ ![Configuring a FPW in wp-admin with the ID tab displayed.](https://s.w.org/plugins/flexible-posts-widget/screenshot-3.png)
83
+
84
+ ###4. An example FPW displayed using WordPress's TwentyTwelve theme and the default Feature Image (post-thumbnail) size. This demonstrates how the plugin looks out-of-the-box with no user-customized styling or output in a default theme.###
85
+ ![An example FPW displayed using WordPress's TwentyTwelve theme and the default Feature Image (post-thumbnail) size. This demonstrates how the plugin looks out-of-the-box with no user-customized styling or output in a default theme.](https://s.w.org/plugins/flexible-posts-widget/screenshot-4.png)
86
+
87
+ ###5. In the Wild: FPW displaying a selection of featured beers (Post Type: Brew) over at http://canalparkbrewery.com. This example uses slightly customized output and some theme-specific styles. ###
88
+ ![In the Wild: FPW displaying a selection of featured beers (Post Type: Brew) over at http://canalparkbrewery.com. This example uses slightly customized output and some theme-specific styles. ](https://s.w.org/plugins/flexible-posts-widget/screenshot-5.png)
89
+
90
+ ###6. In the wild: FPW displaying a selection media attachments, with custom thumbnails. This example uses highly customized HTML output and very theme-specific styles.###
91
+ ![In the wild: FPW displaying a selection media attachments, with custom thumbnails. This example uses highly customized HTML output and very theme-specific styles.](https://s.w.org/plugins/flexible-posts-widget/screenshot-6.png)
92
+
93
+ ###7. In the wild: FPW displaying several posts over at http://chnl7700.mnsu.edu. Also highly customized output and theme styles.###
94
+ ![In the wild: FPW displaying several posts over at http://chnl7700.mnsu.edu. Also highly customized output and theme styles.](https://s.w.org/plugins/flexible-posts-widget/screenshot-7.png)
95
+
96
+
97
+ ## Other Notes ##
98
+ ### Plugin Hooks ###
99
+ Flexible posts widget currently has two public hooks:
100
+
101
+ * Filter: [`dpe_fpw_args`](https://plugins.trac.wordpress.org/browser/flexible-posts-widget/trunk/includes/class-fpw-widget.php#L191) allows filtering the query vars before submitting the widget posts query.
102
+ * Filter: [`dpe_fpw_template_{$template_name}`](https://plugins.trac.wordpress.org/browser/flexible-posts-widget/trunk/includes/class-fpw-widget.php#L354) filters the template file path used to display the widget output.
103
+
104
+ ### Future updates & feature requests list ###
105
+ * Use search box instead of ID text field for post id's
106
+ * Shortcode functionality.
107
+ * Get posts by Author.
108
+ * Filter out the post currently being viewed.
109
+ * Get posts from the same archive (term/post type/etc).
110
+ * Limit results by a time period.
111
+
112
+ ## Upgrade Notice ##
113
+ ### 3.5.0 ###
114
+ Added multi-language support (WPML & PolyLang) and nested terms in the taxonomy & term select box. The plugin now updates widget settings in the background on update (if necessary).
115
+
116
+ ## Changelog ##
117
+ ### 3.5.0 ###
118
+ * Major codebase rewrite to prepare for additional widgets, options.
119
+ * Automatically updates any widget settings when the plugin is updated to a new version
120
+ * Multi Language support (WPML & PolyLang)
121
+ * Term selection box now uses built-in WordPress function [`wp_terms_checklist()`](http://codex.wordpress.org/Function_Reference/wp_terms_checklist). This provides support for visually displaying nested terms and brings the plugin into compliance with WordPress code.
122
+
123
+ ### 3.4.1 ###
124
+ * Version bump for WordPress 4.1 support.
125
+
126
+ ### 3.4 ###
127
+ * Added Finnish language support. (Props: @eccola)
128
+ * Made the Template Filename field a select box based on the templates available in the current theme, the parent theme (if the current theme is a child theme) and the plugin's views folder. (Props @w3b-beweb)
129
+ * Added a new default template `Default.php` that works better in most sidebar situations. The current default template `Widget.php` will be used by any existing widgets unless manually changed.
130
+ * Added support to order posts by Modified Date.
131
+ * Migrated admin CSS to SASS.
132
+ * Much code clean up and refactoring.
133
+ * Fixed an issue with language files not loading properly (Props @sajtdavid).
134
+
135
+ ### 3.3.1 ###
136
+ * Added plugin icon.
137
+ * Version bump for WordPress 4.0 support.
138
+
139
+ ### 3.3 ###
140
+ * Refactored the PHP Class to encapsulate the plugin.
141
+ * Added the ability to sort posts by "Post ID Order". Useful when getting posts using the ID tab `post__in`. (Props: @cinus89)
142
+ * Added Russian translation. (Props: @mizhgun)
143
+ * Tested To bump for WordPress 3.9 support.
144
+
145
+ ### 3.2.2 ###
146
+ * Version bump for WordPress 3.8 support
147
+
148
+ ### 3.2.1 ###
149
+ * Added Italian language support. (Props: @adriano-esposito)
150
+
151
+ ### 3.2 ###
152
+ * Added option to ignore sticky posts.
153
+ * Added support to get post by post ID directly.
154
+ * Added Polish language support. (Props: @Invens)
155
+ * Added a few filters: `dpe_fpw_args` to filter the query vars before submitting the query and `dpe_fpw_template_{$template_name}` to filter the selected template.
156
+
157
+ ### 3.1.2 ###
158
+ * Fixed several pesky PHP notices. (Props: @eeb1)
159
+
160
+ ### 3.1.1 ###
161
+ * Fixed incorrect use of rtrim in getTemplateHierarchy when getting custom template files. (Props: @mortenf)
162
+
163
+ ### 3.1 ###
164
+ * Internationalized and added Spanish language support. (Props: @elarequi)
165
+ * Added support for Media post types with "image/" mime types to be displayed directly in the default template.
166
+
167
+ ### 3.0.2 ###
168
+ * Bug fix: Added a check to make sure both taxonomy & term are set for tax queries.
169
+
170
+ ### 3.0.1 ###
171
+ * Bug fix: Not able to get all registered post types & taxonomies until after widget init. Had to reorder some code.
172
+ * Bug fix: when getting post types for display in widget admin. (Props: @angelfish276)
173
+
174
+ ### 3.0 ###
175
+ * Allow widgets to query by post type and/or taxonomy & term instead of just one or the other. (Props: @vernal)
176
+ * Allow widgets to query by multiple post types and multiple terms within the same taxonomy. (Props: @vernal)
177
+ * Changed the list of available post types and taxonomies from every possible option to just those that are public.
178
+ * General UI enhancements for the widget admin.
179
+ * Some minor code cleanup and security improvements.
180
+
181
+ ### 2.1.1 ###
182
+ * Fixed a source order bug in the widget.php template file. (Props: @carstenbach).
183
+
184
+ ### 2.1 ###
185
+ * Added offset parameter to display options.
186
+
187
+ ### 2.0 ###
188
+ * *Upgrade notice:* When upgrading from v1.x.x to v2.x, remember to double-check the settings for any existing widgets.
189
+ * Dynamically populate available terms based on selected taxonomy.
190
+ * Make the "Get Posts By" section selectable and only show the chosen method: Taxonomy & Term or Post Type.
191
+ * Miscellaneous admin improvements.
192
+
193
+ ### 1.0.5 ###
194
+ * Bug fix: Removed post_status 'private' from wp_queries. We don't want to show private posts in our loops.
195
+
196
+ ### 1.0.4 ###
197
+ * Fixed an issue where post thumbnails aren't displaying.
198
+
199
+ ### 1.0.3 ###
200
+ * Fixed PHP notices that showed in the admin when WP_DEBUG is enabled
201
+ * Added some stub code for future admin JavaScripts (not active yet).
202
+ * Readme.txt updates
203
+
204
+ ### 1.0.2 ###
205
+ * Readme.txt updates
206
+
207
+ ### 1.0 ###
208
  * First public release
readme.txt CHANGED
@@ -3,15 +3,15 @@ Contributors: dpe415
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DJKSKHJWYAWDU
4
  Tags: widget, widgets, posts, categories, tags, recent posts, thumbnails, custom post types, custom taxonomies, feature image
5
  Requires at least: 3.2
6
- Tested up to: 4.1
7
- Stable tag: 3.4.1
8
  License: GPL2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  An advanced posts display widget with many options. Display posts in your sidebars any way you'd like!
12
 
13
  == Description ==
14
- The default Recent Posts widget is exceptionally basic. I always find myself in need of a way to easily display a selection of posts from any combination post type or taxonomy. Hence, Flexible Post Widget.
15
 
16
  Flexible Posts Widget (FPW) is more than just a simple alternative to the default Recent Posts widget. With many per-instance options it is highly customizable and allows advanced users to display the resulting posts virtually any way imaginable.
17
 
@@ -23,14 +23,7 @@ Flexible Posts Widget (FPW) is more than just a simple alternative to the defaul
23
  * Select the post feature image size to display from existing image sizes: thumbnail, medium, large, post-thumbnail or any size defined by the current theme.
24
  * Order posts by: date, modified date, ID, title, menu order, random, Post ID Order; and sort posts: ascending or descending.
25
  * Each widget's output can be customized by user-defined templates added to the current theme folder.
26
-
27
- = Supported Languages =
28
- * English
29
- * Finnish
30
- * Italian
31
- * Polish
32
- * Russian
33
- * Spanish
34
 
35
  == Installation ==
36
  1. Upload the `flexible-posts-widget` folder to the `/wp-content/plugins/` directory.
@@ -62,8 +55,9 @@ The number, in this case 1280, is the post ID.
62
  You'll want to create a custom HTML template by following [the instructions](http://wordpress.org/extend/plugins/flexible-posts-widget/installation/ "View instructions for creating custom FPW templates") and then you can use the standard WordPress [Custom Field](http://codex.wordpress.org/Custom_Fields "View custom field functions on the WordPress Codex") functions the same way you would if you were editing your theme's other template files.
63
 
64
  A simple code example for a custom field named "test_field" _might_ look like the following:
65
- `$test_field_value = get_post_meta( get_the_ID(), 'test_field', true );
66
- echo $test_field_value;`
 
67
 
68
  = How can I style the images, titles or other widget output a certain way? =
69
  FPW intentionally does NOT add any styling of it's own. To adjust the font size, color, alignment, image size, etc. of any output from this widget, you'll need to edit your theme's styles.
@@ -86,16 +80,14 @@ To get answers to your questions, request help or submit a bug report, please st
86
  1. In the wild: FPW displaying a selection media attachments, with custom thumbnails. This example uses highly customized HTML output and very theme-specific styles.
87
  1. In the wild: FPW displaying several posts over at http://chnl7700.mnsu.edu. Also highly customized output and theme styles.
88
 
89
- == Upgrade Notice ==
90
- When upgrading from one major version to another (version 1.x to version 2.x to version 3.x, etc), please remember to verify your settings for any existing widgets. Not all settings combinations will be saved after a major release upgrade.
91
-
92
  == Other Notes ==
93
- = Upgrading from one major version to another =
94
- When upgrading between major releases (version 1.x to version 2.x to version 3.x, etc), please remember to verify your settings for any existing widgets. Not all settings combinations will be saved after a major release upgrade.
 
 
 
95
 
96
  = Future updates & feature requests list =
97
- * Multilingual support (Polylang, WPML, etc.)
98
- * Make Tax-Term drop-down hierarchical.
99
  * Use search box instead of ID text field for post id's
100
  * Shortcode functionality.
101
  * Get posts by Author.
@@ -103,8 +95,16 @@ When upgrading between major releases (version 1.x to version 2.x to version 3.x
103
  * Get posts from the same archive (term/post type/etc).
104
  * Limit results by a time period.
105
 
 
 
 
106
 
107
  == Changelog ==
 
 
 
 
 
108
 
109
  = 3.4.1 =
110
  * Version bump for WordPress 4.1 support.
@@ -112,7 +112,7 @@ When upgrading between major releases (version 1.x to version 2.x to version 3.x
112
  = 3.4 =
113
  * Added Finnish language support. (Props: @eccola)
114
  * Made the Template Filename field a select box based on the templates available in the current theme, the parent theme (if the current theme is a child theme) and the plugin's views folder. (Props @w3b-beweb)
115
- * Added a new default template (`Default.php`) that works better in most sidebar situations. The current default template (`Widget.php`) will be used by any existing widgets unless manually changed.
116
  * Added support to order posts by Modified Date.
117
  * Migrated admin CSS to SASS.
118
  * Much code clean up and refactoring.
@@ -124,7 +124,7 @@ When upgrading between major releases (version 1.x to version 2.x to version 3.x
124
 
125
  = 3.3 =
126
  * Refactored the PHP Class to encapsulate the plugin.
127
- * Added the ability to sort posts by "Post ID Order". Useful when getting posts using the ID tab (`post__in`). (Props: @cinus89)
128
  * Added Russian translation. (Props: @mizhgun)
129
  * Tested To bump for WordPress 3.9 support.
130
 
@@ -138,7 +138,7 @@ When upgrading between major releases (version 1.x to version 2.x to version 3.x
138
  * Added option to ignore sticky posts.
139
  * Added support to get post by post ID directly.
140
  * Added Polish language support. (Props: @Invens)
141
- * Added a few filters: `dpe_fpw_args` to filter the query vars before submitting the query and `'dpe_fpw_template_' . [$template_name]` to filter the selected template.
142
 
143
  = 3.1.2 =
144
  * Fixed several pesky PHP notices. (Props: @eeb1)
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DJKSKHJWYAWDU
4
  Tags: widget, widgets, posts, categories, tags, recent posts, thumbnails, custom post types, custom taxonomies, feature image
5
  Requires at least: 3.2
6
+ Tested up to: 4.7
7
+ Stable tag: 3.5.0
8
  License: GPL2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  An advanced posts display widget with many options. Display posts in your sidebars any way you'd like!
12
 
13
  == Description ==
14
+ The default Recent Posts widget is exceptionally basic. I always find myself in need of a way to easily display a selection of posts from any combination post type or taxonomy. Hence, Flexible Posts Widget.
15
 
16
  Flexible Posts Widget (FPW) is more than just a simple alternative to the default Recent Posts widget. With many per-instance options it is highly customizable and allows advanced users to display the resulting posts virtually any way imaginable.
17
 
23
  * Select the post feature image size to display from existing image sizes: thumbnail, medium, large, post-thumbnail or any size defined by the current theme.
24
  * Order posts by: date, modified date, ID, title, menu order, random, Post ID Order; and sort posts: ascending or descending.
25
  * Each widget's output can be customized by user-defined templates added to the current theme folder.
26
+ * Multi Language support. Compatible with [WPML](http://wpml.org/) and [PolyLang](https://wordpress.org/plugins/polylang/) for sure. Not tested with other multi-language plugins, but it should work.
 
 
 
 
 
 
 
27
 
28
  == Installation ==
29
  1. Upload the `flexible-posts-widget` folder to the `/wp-content/plugins/` directory.
55
  You'll want to create a custom HTML template by following [the instructions](http://wordpress.org/extend/plugins/flexible-posts-widget/installation/ "View instructions for creating custom FPW templates") and then you can use the standard WordPress [Custom Field](http://codex.wordpress.org/Custom_Fields "View custom field functions on the WordPress Codex") functions the same way you would if you were editing your theme's other template files.
56
 
57
  A simple code example for a custom field named "test_field" _might_ look like the following:
58
+
59
+ ` $test_field_value = get_post_meta( get_the_ID(), 'test_field', true );
60
+ echo $test_field_value; `
61
 
62
  = How can I style the images, titles or other widget output a certain way? =
63
  FPW intentionally does NOT add any styling of it's own. To adjust the font size, color, alignment, image size, etc. of any output from this widget, you'll need to edit your theme's styles.
80
  1. In the wild: FPW displaying a selection media attachments, with custom thumbnails. This example uses highly customized HTML output and very theme-specific styles.
81
  1. In the wild: FPW displaying several posts over at http://chnl7700.mnsu.edu. Also highly customized output and theme styles.
82
 
 
 
 
83
  == Other Notes ==
84
+ = Plugin Hooks =
85
+ Flexible posts widget currently has two public hooks:
86
+
87
+ * Filter: [`dpe_fpw_args`](https://plugins.trac.wordpress.org/browser/flexible-posts-widget/trunk/includes/class-fpw-widget.php#L191) allows filtering the query vars before submitting the widget posts query.
88
+ * Filter: [`dpe_fpw_template_{$template_name}`](https://plugins.trac.wordpress.org/browser/flexible-posts-widget/trunk/includes/class-fpw-widget.php#L354) filters the template file path used to display the widget output.
89
 
90
  = Future updates & feature requests list =
 
 
91
  * Use search box instead of ID text field for post id's
92
  * Shortcode functionality.
93
  * Get posts by Author.
95
  * Get posts from the same archive (term/post type/etc).
96
  * Limit results by a time period.
97
 
98
+ == Upgrade Notice ==
99
+ = 3.5.0 =
100
+ Added multi-language support (WPML & PolyLang) and nested terms in the taxonomy & term select box. The plugin now updates widget settings in the background on update (if necessary).
101
 
102
  == Changelog ==
103
+ = 3.5.0 =
104
+ * Major codebase rewrite to prepare for additional widgets, options.
105
+ * Automatically updates any widget settings when the plugin is updated to a new version
106
+ * Multi Language support (WPML & PolyLang)
107
+ * Term selection box now uses built-in WordPress function [`wp_terms_checklist()`](http://codex.wordpress.org/Function_Reference/wp_terms_checklist). This provides support for visually displaying nested terms and brings the plugin into compliance with WordPress code.
108
 
109
  = 3.4.1 =
110
  * Version bump for WordPress 4.1 support.
112
  = 3.4 =
113
  * Added Finnish language support. (Props: @eccola)
114
  * Made the Template Filename field a select box based on the templates available in the current theme, the parent theme (if the current theme is a child theme) and the plugin's views folder. (Props @w3b-beweb)
115
+ * Added a new default template `Default.php` that works better in most sidebar situations. The current default template `Widget.php` will be used by any existing widgets unless manually changed.
116
  * Added support to order posts by Modified Date.
117
  * Migrated admin CSS to SASS.
118
  * Much code clean up and refactoring.
124
 
125
  = 3.3 =
126
  * Refactored the PHP Class to encapsulate the plugin.
127
+ * Added the ability to sort posts by "Post ID Order". Useful when getting posts using the ID tab `post__in`. (Props: @cinus89)
128
  * Added Russian translation. (Props: @mizhgun)
129
  * Tested To bump for WordPress 3.9 support.
130
 
138
  * Added option to ignore sticky posts.
139
  * Added support to get post by post ID directly.
140
  * Added Polish language support. (Props: @Invens)
141
+ * Added a few filters: `dpe_fpw_args` to filter the query vars before submitting the query and `dpe_fpw_template_{$template_name}` to filter the selected template.
142
 
143
  = 3.1.2 =
144
  * Fixed several pesky PHP notices. (Props: @eeb1)
views/admin.php CHANGED
@@ -12,63 +12,46 @@ if ( !defined( 'ABSPATH' ) )
12
 
13
  <div class="section title">
14
  <p>
15
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Widget title:', $this->get_widget_text_domain() ); ?></label>
16
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
17
  </p>
18
  </div>
19
 
20
  <div class="section getemby">
21
- <h4><?php _e( 'Get posts by', $this->get_widget_text_domain() ); ?></h4>
22
  <div class="inside">
23
 
24
  <div id="<?php echo $this->get_field_id( 'getemby' ); ?>" class="categorydiv getembytabs">
25
 
26
- <input id="<?php echo $this->get_field_id( 'cur_tab' ); ?>" class="cur_tab" name="<?php echo $this->get_field_name( 'cur_tab' ); ?>" type="hidden" value="<?php echo $cur_tab; ?>" />
27
 
28
  <ul id="<?php echo $this->get_field_id( 'getemby-tabs' ); ?>" class="category-tabs">
29
- <li><a title="<?php _e( 'Post Type', $this->get_widget_text_domain() ); ?>" href="#<?php echo $this->get_field_id( 'getemby-pt' ); ?>"><?php _e( 'Post Type', $this->get_widget_text_domain() ); ?></a></li>
30
- <li><a title="<?php _e( 'Taxonomy &amp; Term', $this->get_widget_text_domain() ); ?>" href="#<?php echo $this->get_field_id( 'getemby-tt' ); ?>"><?php _e( 'Taxonomy &amp; Term', $this->get_widget_text_domain() ); ?></a></li>
31
- <li><a title="<?php _e( 'Post ID', $this->get_widget_text_domain() ); ?>" href="#<?php echo $this->get_field_id( 'getemby-id' ); ?>"><?php _e( 'ID', $this->get_widget_text_domain() ); ?></a></li>
32
  </ul>
33
 
34
  <div id="<?php echo $this->get_field_id( 'getemby-pt' ); ?>" class="tabs-panel pt">
35
- <?php $this->posttype_checklist( $posttype ); ?>
36
  </div><!-- .pt.getemby -->
37
 
38
  <div id="<?php echo $this->get_field_id( 'getemby-tt' ); ?>" class="tabs-panel tt" style="display:none;">
39
  <p>
40
- <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e( 'Select a taxonomy:', $this->get_widget_text_domain() ); ?></label>
41
  <select class="widefat dpe-fp-taxonomy" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>">
42
- <option value="none" <?php echo 'none' == $taxonomy ? ' selected="selected"' : ''; ?>><?php _e( 'Ignore Taxonomy &amp; Term', $this->get_widget_text_domain() ); ?></option>
43
  <?php
44
  foreach ($this->taxonomies as $option) {
45
- echo '<option value="' . $option->name . '"', $taxonomy == $option->name ? ' selected="selected"' : '', '>', $option->label, '</option>';
46
  }
47
  ?>
48
  </select>
49
  </p>
50
- <label <?php echo 'none' == $taxonomy ? ' style="display:none;"' : ''; ?>><?php _e( 'Select terms:', $this->get_widget_text_domain() ); ?></label>
51
- <div class="terms" <?php echo 'none' == $taxonomy ? ' style="display:none;"' : ''; ?>>
52
  <?php
53
- if ( !empty( $taxonomy ) && 'none' != $taxonomy ) {
54
-
55
- $args = array (
56
- 'hide_empty' => 0,
57
- );
58
-
59
- $terms = get_terms( $taxonomy, $args );
60
-
61
- if( ! empty( $terms ) ) {
62
- $output = '<ul class="categorychecklist termschecklist form-no-clear">';
63
- foreach ( $terms as $option ) {
64
- $output .= "\n<li>" . '<label class="selectit"><input value="' . esc_attr( $option->slug ) . '" type="checkbox" name="' . $this->get_field_name( 'term' ) . '[]"' . checked( in_array( $option->slug, (array)$term ), true, false ) . ' /> ' . esc_html( $option->name ) . "</label></li>\n";
65
- }
66
- $output .= "</ul>\n";
67
- } else {
68
- $output = '<p>' . __( 'No terms found.', $this->get_widget_text_domain() ) . '</p>';
69
- }
70
-
71
- echo ( $output );
72
  }
73
  ?>
74
  </div>
@@ -76,9 +59,9 @@ if ( !defined( 'ABSPATH' ) )
76
 
77
  <div id="<?php echo $this->get_field_id( 'getemby-id' ); ?>" class="tabs-panel id" style="display:none;">
78
  <p>
79
- <label for="<?php echo $this->get_field_id( 'pids' ); ?>"><?php _e( 'Comma-separated list of post IDs:', $this->get_widget_text_domain() ); ?></label><br />
80
- <input id="<?php echo $this->get_field_id( 'pids' ); ?>" name="<?php echo $this->get_field_name( 'pids' ); ?>" class="widefat" type="text" value="<?php echo ( empty( $pids ) ? '' : implode( ',', $pids ) ); ?>" /><br />
81
- <span class="description"><?php _e( 'Will override settings on the Post Type and Taxonomy &amp; Term tabs.', $this->get_widget_text_domain() ); ?> <a target="_blank" href="http://wordpress.org/extend/plugins/flexible-posts-widget/faq/"><?php _e( 'See documentation.', $this->get_widget_text_domain() ); ?></a></span>
82
  </p>
83
  </div><!-- .id.getemby -->
84
 
@@ -89,35 +72,35 @@ if ( !defined( 'ABSPATH' ) )
89
  </div>
90
 
91
  <div class="section display">
92
- <h4><?php _e( 'Display options', $this->get_widget_text_domain() ); ?></h4>
93
  <p class="check cf">
94
- <input class="dpe-fp-sticky" id="<?php echo $this->get_field_id( 'sticky' ); ?>" name="<?php echo $this->get_field_name( 'sticky' ); ?>" type="checkbox" value="1" <?php checked( '1', $sticky ); ?>/>
95
- <label for="<?php echo $this->get_field_id( 'sticky' ); ?>"><?php _e( 'Ignore sticky posts?', $this->get_widget_text_domain() ); ?></label>
96
  </p>
97
  <p class="cf">
98
- <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:', $this->get_widget_text_domain() ); ?></label>
99
- <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" />
100
  </p>
101
  <p class="cf">
102
- <label for="<?php echo $this->get_field_id( 'offset' ); ?>"><?php _e( 'Number of posts to skip:', $this->get_widget_text_domain() ); ?></label>
103
- <input id="<?php echo $this->get_field_id( 'offset' ); ?>" name="<?php echo $this->get_field_name( 'offset' ); ?>" type="text" value="<?php echo $offset; ?>" />
104
  </p>
105
  <p class="cf">
106
- <label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Order posts by:', $this->get_widget_text_domain() ); ?></label>
107
  <select name="<?php echo $this->get_field_name( 'orderby' ); ?>" id="<?php echo $this->get_field_id( 'orderby' ); ?>">
108
  <?php
109
  foreach ( $this->orderbys as $key => $value ) {
110
- echo '<option value="' . $key . '" id="' . $this->get_field_id( $key ) . '"', $orderby == $key ? ' selected="selected"' : '', '>', $value, '</option>';
111
  }
112
  ?>
113
  </select>
114
  </p>
115
  <p class="cf">
116
- <label for="<?php echo $this->get_field_id( 'order' ); ?>"><?php _e( 'Order:', $this->get_widget_text_domain() ); ?></label>
117
  <select name="<?php echo $this->get_field_name( 'order' ); ?>" id="<?php echo $this->get_field_id( 'order' ); ?>">
118
  <?php
119
  foreach ( $this->orders as $key => $value ) {
120
- echo '<option value="' . $key . '" id="' . $this->get_field_id( $key ) . '"', $order == $key ? ' selected="selected"' : '', '>', $value, '</option>';
121
  }
122
  ?>
123
  </select>
@@ -126,15 +109,15 @@ if ( !defined( 'ABSPATH' ) )
126
 
127
  <div class="section thumbnails">
128
  <p class="check">
129
- <input class="dpe-fp-thumbnail" id="<?php echo $this->get_field_id( 'thumbnail' ); ?>" name="<?php echo $this->get_field_name( 'thumbnail' ); ?>" type="checkbox" value="1" <?php checked( '1', $thumbnail ); ?>/>
130
- <label style="font-weight:bold;" for="<?php echo $this->get_field_id( 'thumbnail' ); ?>"><?php _e( 'Display thumbnails?', $this->get_widget_text_domain() ); ?></label>
131
  </p>
132
- <p <?php echo $thumbnail ? '' : 'style="display:none;"'?> class="thumb-size">
133
- <label for="<?php echo $this->get_field_id( 'thumbsize' ); ?>"><?php _e( 'Select a thumbnail size to show:', $this->get_widget_text_domain() ); ?></label>
134
  <select class="widefat" name="<?php echo $this->get_field_name( 'thumbsize' ); ?>" id="<?php echo $this->get_field_id( 'thumbsize' ); ?>">
135
  <?php
136
  foreach ($this->thumbsizes as $option) {
137
- echo '<option value="' . $option . '" id="' . $this->get_field_id( $option ) . '"', $thumbsize == $option ? ' selected="selected"' : '', '>', $option, '</option>';
138
  }
139
  ?>
140
  </select>
@@ -143,13 +126,13 @@ if ( !defined( 'ABSPATH' ) )
143
 
144
  <div class="section templates">
145
  <p>
146
- <label for="<?php echo $this->get_field_id( 'template' ); ?>"><?php _e( 'Template filename:', $this->get_widget_text_domain() ); ?></label>
147
  <?php
148
  ?>
149
  <select class="widefat" name="<?php echo $this->get_field_name( 'template' ); ?>" id="<?php echo $this->get_field_id( 'template' ); ?>">
150
  <?php
151
  foreach ($this->templates as $key => $value ) {
152
- echo '<option value="' . $key . '" id="' . $this->get_field_id( $key ) . '"', $template == $key ? ' selected="selected"' : '', '>', ucwords( preg_replace( array( '/-/', '/_/' ), ' ', preg_replace( '/.php$/', '', $key ) ) ), '</option>';
153
  }
154
  ?>
155
  </select>
12
 
13
  <div class="section title">
14
  <p>
15
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Widget title:', $this->widget_text_domain ); ?></label>
16
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $instance['title']; ?>" />
17
  </p>
18
  </div>
19
 
20
  <div class="section getemby">
21
+ <h4><?php _e( 'Get posts by', $this->widget_text_domain ); ?></h4>
22
  <div class="inside">
23
 
24
  <div id="<?php echo $this->get_field_id( 'getemby' ); ?>" class="categorydiv getembytabs">
25
 
26
+ <input id="<?php echo $this->get_field_id( 'cur_tab' ); ?>" class="cur_tab" name="<?php echo $this->get_field_name( 'cur_tab' ); ?>" type="hidden" value="<?php echo $instance['cur_tab']; ?>" />
27
 
28
  <ul id="<?php echo $this->get_field_id( 'getemby-tabs' ); ?>" class="category-tabs">
29
+ <li><a title="<?php _e( 'Post Type', $this->widget_text_domain ); ?>" href="#<?php echo $this->get_field_id( 'getemby-pt' ); ?>"><?php _e( 'Post Type', $this->widget_text_domain ); ?></a></li>
30
+ <li><a title="<?php _e( 'Taxonomy &amp; Term', $this->widget_text_domain ); ?>" href="#<?php echo $this->get_field_id( 'getemby-tt' ); ?>"><?php _e( 'Taxonomy &amp; Term', $this->widget_text_domain ); ?></a></li>
31
+ <li><a title="<?php _e( 'Post ID', $this->widget_text_domain ); ?>" href="#<?php echo $this->get_field_id( 'getemby-id' ); ?>"><?php _e( 'ID', $this->widget_text_domain ); ?></a></li>
32
  </ul>
33
 
34
  <div id="<?php echo $this->get_field_id( 'getemby-pt' ); ?>" class="tabs-panel pt">
35
+ <?php $this->posttype_checklist( $instance['posttype'] ); ?>
36
  </div><!-- .pt.getemby -->
37
 
38
  <div id="<?php echo $this->get_field_id( 'getemby-tt' ); ?>" class="tabs-panel tt" style="display:none;">
39
  <p>
40
+ <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e( 'Select a taxonomy:', $this->widget_text_domain ); ?></label>
41
  <select class="widefat dpe-fp-taxonomy" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>">
42
+ <option value="none" <?php echo 'none' == $instance['taxonomy'] ? ' selected="selected"' : ''; ?>><?php _e( 'Ignore Taxonomy &amp; Term', $this->widget_text_domain ); ?></option>
43
  <?php
44
  foreach ($this->taxonomies as $option) {
45
+ echo '<option value="' . $option->name . '"', $instance['taxonomy'] == $option->name ? ' selected="selected"' : '', '>', $option->label, '</option>';
46
  }
47
  ?>
48
  </select>
49
  </p>
50
+ <label <?php echo 'none' == $instance['taxonomy'] ? ' style="display:none;"' : ''; ?>><?php _e( 'Select terms:', $this->widget_text_domain ); ?></label>
51
+ <div class="terms" <?php echo 'none' == $instance['taxonomy'] ? ' style="display:none;"' : ''; ?>>
52
  <?php
53
+ if( 'none' != $instance['taxonomy'] ) {
54
+ $this->terms_checklist( $instance['taxonomy'], $instance['term'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
  ?>
57
  </div>
59
 
60
  <div id="<?php echo $this->get_field_id( 'getemby-id' ); ?>" class="tabs-panel id" style="display:none;">
61
  <p>
62
+ <label for="<?php echo $this->get_field_id( 'pids' ); ?>"><?php _e( 'Comma-separated list of post IDs:', $this->widget_text_domain ); ?></label><br />
63
+ <input id="<?php echo $this->get_field_id( 'pids' ); ?>" name="<?php echo $this->get_field_name( 'pids' ); ?>" class="widefat" type="text" value="<?php echo ( empty( $instance['pids'] ) ? '' : implode( ',', $instance['pids'] ) ); ?>" /><br />
64
+ <span class="description"><?php _e( 'Will override settings on the Post Type and Taxonomy &amp; Term tabs.', $this->widget_text_domain ); ?> <a target="_blank" href="http://wordpress.org/extend/plugins/flexible-posts-widget/faq/"><?php _e( 'See documentation.', $this->widget_text_domain ); ?></a></span>
65
  </p>
66
  </div><!-- .id.getemby -->
67
 
72
  </div>
73
 
74
  <div class="section display">
75
+ <h4><?php _e( 'Display options', $this->widget_text_domain ); ?></h4>
76
  <p class="check cf">
77
+ <input class="dpe-fp-sticky" id="<?php echo $this->get_field_id( 'sticky' ); ?>" name="<?php echo $this->get_field_name( 'sticky' ); ?>" type="checkbox" value="1" <?php checked( '1', $instance['sticky'] ); ?>/>
78
+ <label for="<?php echo $this->get_field_id( 'sticky' ); ?>"><?php _e( 'Ignore sticky posts?', $this->widget_text_domain ); ?></label>
79
  </p>
80
  <p class="cf">
81
+ <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:', $this->widget_text_domain ); ?></label>
82
+ <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $instance['number']; ?>" />
83
  </p>
84
  <p class="cf">
85
+ <label for="<?php echo $this->get_field_id( 'offset' ); ?>"><?php _e( 'Number of posts to skip:', $this->widget_text_domain ); ?></label>
86
+ <input id="<?php echo $this->get_field_id( 'offset' ); ?>" name="<?php echo $this->get_field_name( 'offset' ); ?>" type="text" value="<?php echo $instance['offset']; ?>" />
87
  </p>
88
  <p class="cf">
89
+ <label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Order posts by:', $this->widget_text_domain ); ?></label>
90
  <select name="<?php echo $this->get_field_name( 'orderby' ); ?>" id="<?php echo $this->get_field_id( 'orderby' ); ?>">
91
  <?php
92
  foreach ( $this->orderbys as $key => $value ) {
93
+ echo '<option value="' . $key . '" id="' . $this->get_field_id( $key ) . '"', $instance['orderby'] == $key ? ' selected="selected"' : '', '>', $value, '</option>';
94
  }
95
  ?>
96
  </select>
97
  </p>
98
  <p class="cf">
99
+ <label for="<?php echo $this->get_field_id( 'order' ); ?>"><?php _e( 'Order:', $this->widget_text_domain ); ?></label>
100
  <select name="<?php echo $this->get_field_name( 'order' ); ?>" id="<?php echo $this->get_field_id( 'order' ); ?>">
101
  <?php
102
  foreach ( $this->orders as $key => $value ) {
103
+ echo '<option value="' . $key . '" id="' . $this->get_field_id( $key ) . '"', $instance['order'] == $key ? ' selected="selected"' : '', '>', $value, '</option>';
104
  }
105
  ?>
106
  </select>
109
 
110
  <div class="section thumbnails">
111
  <p class="check">
112
+ <input class="dpe-fp-thumbnail" id="<?php echo $this->get_field_id( 'thumbnail' ); ?>" name="<?php echo $this->get_field_name( 'thumbnail' ); ?>" type="checkbox" value="1" <?php checked( '1', $instance['thumbnail'] ); ?>/>
113
+ <label style="font-weight:bold;" for="<?php echo $this->get_field_id( 'thumbnail' ); ?>"><?php _e( 'Display thumbnails?', $this->widget_text_domain ); ?></label>
114
  </p>
115
+ <p <?php echo $instance['thumbnail'] ? '' : 'style="display:none;"'?> class="thumb-size">
116
+ <label for="<?php echo $this->get_field_id( 'thumbsize' ); ?>"><?php _e( 'Select a thumbnail size to show:', $this->widget_text_domain ); ?></label>
117
  <select class="widefat" name="<?php echo $this->get_field_name( 'thumbsize' ); ?>" id="<?php echo $this->get_field_id( 'thumbsize' ); ?>">
118
  <?php
119
  foreach ($this->thumbsizes as $option) {
120
+ echo '<option value="' . $option . '" id="' . $this->get_field_id( $option ) . '"', $instance['thumbsize'] == $option ? ' selected="selected"' : '', '>', $option, '</option>';
121
  }
122
  ?>
123
  </select>
126
 
127
  <div class="section templates">
128
  <p>
129
+ <label for="<?php echo $this->get_field_id( 'template' ); ?>"><?php _e( 'Template filename:', $this->widget_text_domain ); ?></label>
130
  <?php
131
  ?>
132
  <select class="widefat" name="<?php echo $this->get_field_name( 'template' ); ?>" id="<?php echo $this->get_field_id( 'template' ); ?>">
133
  <?php
134
  foreach ($this->templates as $key => $value ) {
135
+ echo '<option value="' . $key . '" id="' . $this->get_field_id( $key ) . '"', $instance['template'] == $key ? ' selected="selected"' : '', '>', ucwords( preg_replace( array( '/-/', '/_/' ), ' ', preg_replace( '/.php$/', '', $key ) ) ), '</option>';
136
  }
137
  ?>
138
  </select>
views/default.php CHANGED
@@ -14,22 +14,22 @@ if ( !defined('ABSPATH') )
14
 
15
  echo $before_widget;
16
 
17
- if ( !empty($title) )
18
  echo $before_title . $title . $after_title;
19
 
20
- if( $flexible_posts->have_posts() ):
21
  ?>
22
  <ul class="dpe-flexible-posts">
23
- <?php while( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>
24
  <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
25
  <a href="<?php echo the_permalink(); ?>">
26
  <?php
27
- if( $thumbnail == true ) {
28
  // If the post has a feature image, show it
29
- if( has_post_thumbnail() ) {
30
  the_post_thumbnail( $thumbsize );
31
  // Else if the post has a mime type that starts with "image/" then show the image directly.
32
- } elseif( 'image/' == substr( $post->post_mime_type, 0, 6 ) ) {
33
  echo wp_get_attachment_image( $post->ID, $thumbsize );
34
  }
35
  }
14
 
15
  echo $before_widget;
16
 
17
+ if ( ! empty( $title ) )
18
  echo $before_title . $title . $after_title;
19
 
20
+ if ( $flexible_posts->have_posts() ):
21
  ?>
22
  <ul class="dpe-flexible-posts">
23
+ <?php while ( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>
24
  <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
25
  <a href="<?php echo the_permalink(); ?>">
26
  <?php
27
+ if ( $thumbnail == true ) {
28
  // If the post has a feature image, show it
29
+ if ( has_post_thumbnail() ) {
30
  the_post_thumbnail( $thumbsize );
31
  // Else if the post has a mime type that starts with "image/" then show the image directly.
32
+ } elseif ( 'image/' == substr( $post->post_mime_type, 0, 6 ) ) {
33
  echo wp_get_attachment_image( $post->ID, $thumbsize );
34
  }
35
  }