Skip to content

Commit 4bb4420

Browse files
committed
Security improvements
- security improvements & refinements - Readme update - further polishing
1 parent e72f31f commit 4bb4420

File tree

3 files changed

+71
-25
lines changed

3 files changed

+71
-25
lines changed

CHANGES.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#### Version 2016-08-19
2+
3+
* Updated Readme file
4+
* Updated .pot file plus German translations
5+
* Improved security and polishing of plugin
6+
7+
18
#### Version 2016-08-12
29

310
* Added Shortcut for German date format to get output `d.m.Y` like `12.08.2016` (Usage: `date_format="de"`)
@@ -23,4 +30,4 @@
2330

2431
#### Version 2015-05-25
2532

26-
* Initial release on GitHub
33+
* Initial release on GitHub

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
* Contributors: [David Decker](https://github.com/deckerweb), [contributors](https://github.com/deckerweb/shortcode-item-updated/graphs/contributors)
44
* Tags: shortcode, updated, last updated, date, time, item, post type, custom post types, post, element
5-
* Requires at least: 3.6
5+
* Requires at least: 3.6.0
66
* Tested up to: 4.6.x
77
* Stable tag: master
8-
* Donate link: http://ddwb.me/9s
8+
* Donate link: [http://ddwb.me/9s](http://ddwb.me/9s)
99
* License: GPL-2.0+
10-
* License URI: http://www.opensource.org/licenses/gpl-license.php
10+
* License URI: [http://www.opensource.org/licenses/gpl-license.php](http://www.opensource.org/licenses/gpl-license.php)
1111

12-
Shortcode for showing the last updated date (and/or time) of an item of a post type.
12+
Flexible Shortcode for showing the last updated date (and/or time) of an item of a post type.
1313

1414

1515
## Description:
@@ -19,6 +19,16 @@ Very useful to output the updated date of a custom post type item on a regular p
1919
*Backstory:* I needed something like that for a client project to display the last updated date/time of a download post type on a regular content page. Since I knew, I would need the same functionality for an other existing site and maybe in future too, I just build it into a "general plugin" rather than a simple code snippet...! There were no existing plugins/solutions out there (at least I didn't found them yet...) that fitted my needs so I had to build it myself...
2020

2121

22+
## Features:
23+
24+
* Can be used in post/ page content (also post types), text widgets and also for page builder plugins etc.
25+
* Supports date/ time format from WordPress settings by default
26+
* Genesis Framework: easily use this in various footer/ simple edit plugins (don't forget post ID) or with the awesome Blox free/pro plugin and similar - it's that easy!
27+
* Developer friendly: customize or extend via filters, styles and styling-friendly CSS classes
28+
* Fully internationalized and translateable! -- German translations already packaged!
29+
* Developed with security in mind: proper WordPress coding standards and security functions - escape all the things! :)
30+
31+
2232
## Plugin Installation:
2333

2434
**Manual Upload**
@@ -37,6 +47,7 @@ Very useful to output the updated date of a custom post type item on a regular p
3747
**Updates**
3848
* Are done via the plugin "GitHub Updater" (see above) - leveraging the default WordPress update system!
3949
* Setting your GitHub API Token is recommended! :)
50+
* It's so easy and seamless you won't find any better solution for this ;-)
4051

4152

4253
## Usage - Examples:
@@ -117,7 +128,6 @@ Will show only date (as set in WordPress Settings > General) for the item of a p
117128
* Used textdomain: `shortcode-item-updated`
118129
* Default `.pot` file included
119130
* German translations included (`de_DE`)
120-
* Currently translateable are the plugin title, plugin description, label before string and the separator string
121131
* Plugin's own path for translations: `wp-content/plugins/shortcode-item-updated/languages/shortcode-item-updated-de_DE.mo`
122132
* *Recommended:* Global WordPress lang dir path for translations: `wp-content/languages/plugins/shortcode-item-updated-de_DE.mo` ---> *NOTE: if this file/path exists it will be loaded at higher priority than the plugin path! This is the recommended path & way to store your translations as it is update-safe and allows for custom translations!*
123133
* Recommended translation tools: *Poedit Pro v1.8+* or *WordPress Plugin "Loco Translate"* or *your IDE/ Code Editor* or *old WordPress "Codestyling Localization"* (for the brave who know what they are doing :) )
@@ -127,4 +137,4 @@ Will show only date (as set in WordPress Settings > General) for the item of a p
127137

128138
See plugin file [CHANGES.md here](https://github.com/deckerweb/shortcode-item-updated/blob/master/CHANGES.md)
129139

130-
Copyright (c) 2015-2016 David Decker - DECKERWEB.de
140+
Copyright (c) 2015-2016 David Decker - DECKERWEB.de

shortcode-item-updated.php

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Plugin Name: Shortcode Item Updated
1212
* Plugin URI: https://github.com/deckerweb/shortcode-item-updated
1313
* Description: Shortcode for showing the last updated date (and/or time) of an item of a post type.
14-
* Version: 2016.08.12
14+
* Version: 2016.08.19
1515
* Author: David Decker - DECKERWEB
1616
* Author URI: http://deckerweb.de/
1717
* License: GPL-2.0+
@@ -24,7 +24,7 @@
2424
* Copyright (c) 2015-2016 David Decker - DECKERWEB
2525
*/
2626

27-
/*
27+
/**
2828
* Exit if called directly.
2929
*/
3030
if ( ! defined( 'WPINC' ) ) {
@@ -35,7 +35,7 @@
3535
add_action( 'init', 'ddw_siu_load_translations', 1 );
3636
/**
3737
* Load the text domain for translation of the plugin.
38-
*
38+
*
3939
* @since 2015.05.26
4040
*
4141
* @uses load_textdomain() To load translations first from WP_LANG_DIR sub folder.
@@ -71,6 +71,32 @@ function ddw_siu_load_translations() {
7171
} // end function
7272

7373

74+
/**
75+
* Data validation function to only allow values "yes" and "no".
76+
*
77+
* @since 2016.08.16
78+
*
79+
* @param string $param
80+
*
81+
* @return string Validated and escaped string.
82+
*/
83+
function ddw_siu_yes_no( $param = '' ) {
84+
85+
$param = strtolower( esc_attr( $param ) );
86+
87+
if ( 'yes' === $param ) {
88+
89+
return $param;
90+
91+
} else {
92+
93+
return 'no';
94+
95+
} // end if
96+
97+
} // end function
98+
99+
74100
add_shortcode( 'siu-item-updated', 'ddw_siu_item_updated' );
75101
/**
76102
* Shortcode for showing the last updated date (and/or time) of an item of a post type.
@@ -79,6 +105,7 @@ function ddw_siu_load_translations() {
79105
* @since 2015.05.25
80106
*
81107
* @uses shortcode_atts()
108+
* @uses ddw_siu_yes_no()
82109
*
83110
* @param array $atts
84111
*
@@ -138,18 +165,18 @@ function ddw_siu_item_updated( $atts ) {
138165
/** Prepare time display */
139166
$time_display = sprintf(
140167
'%1$s%2$s%3$s',
141-
( 'yes' == esc_attr( $atts[ 'show_sep' ] ) ) ? esc_attr( $atts[ 'sep' ] ) : '',
142-
( 'yes' == esc_attr( $atts[ 'show_time' ] ) ) ? ' ' . $time_updated : '',
168+
( 'yes' === ddw_siu_yes_no( $atts[ 'show_sep' ] ) ) ? esc_attr( $atts[ 'sep' ] ) : '',
169+
( 'yes' === ddw_siu_yes_no( $atts[ 'show_time' ] ) ) ? ' ' . $time_updated : '',
143170
! empty( $atts[ 'label_after' ] ) ? ' ' . esc_html__( $atts[ 'label_after' ] ) : ''
144171
);
145172

146173
/** Prepare output */
147174
$output = sprintf(
148175
'<%1$s class="item-last-updated%2$s">%3$s%4$s%5$s</%1$s>',
149-
esc_attr( $atts[ 'wrapper' ] ),
150-
! empty( $atts[ 'class' ] ) ? ' ' . esc_attr( $atts[ 'class' ] ) : '',
151-
( 'yes' == esc_attr( $atts[ 'show_label' ] ) ) ? esc_html__( $atts[ 'label_before' ] ) . ' ' : '',
152-
( 'yes' == esc_attr( $atts[ 'show_date' ] ) ) ? $date_updated : '',
176+
strtolower( sanitize_html_class( $atts[ 'wrapper' ] ) ),
177+
! empty( $atts[ 'class' ] ) ? ' ' . sanitize_html_class( $atts[ 'class' ] ) : '',
178+
( 'yes' === ddw_siu_yes_no( $atts[ 'show_label' ] ) ) ? esc_html__( $atts[ 'label_before' ] ) . ' ' : '',
179+
( 'yes' === ddw_siu_yes_no( $atts[ 'show_date' ] ) ) ? $date_updated : '',
153180
$time_display
154181
);
155182

@@ -189,6 +216,7 @@ function ddw_siu_prepare_shortcode_ui() {
189216

190217
/**
191218
* Shortcode UI setup for Shortcake plugin (Shortcode UI).
219+
* @link https://wordpress.org/plugins/shortcode-ui/
192220
*
193221
* @since 2016.08.12
194222
*
@@ -228,17 +256,17 @@ function ddw_siu_register_shortcode_for_ui() {
228256
'attr' => 'show_date',
229257
'type' => 'select',
230258
'options' => array(
231-
'yes' => esc_html__( 'Yes', 'shortcode-item-updated' ),
232-
'no' => esc_html__( 'No', 'shortcode-item-updated' ),
259+
'yes' => esc_html__( 'Yes', 'shortcode-item-updated' ),
260+
'no' => esc_html__( 'No', 'shortcode-item-updated' ),
233261
),
234262
),
235263
array(
236264
'label' => esc_html__( 'Show time?', 'shortcode-item-updated' ),
237265
'attr' => 'show_time',
238266
'type' => 'select',
239267
'options' => array(
240-
'no' => esc_html__( 'No', 'shortcode-item-updated' ),
241-
'yes' => esc_html__( 'Yes', 'shortcode-item-updated' ),
268+
'no' => esc_html__( 'No', 'shortcode-item-updated' ),
269+
'yes' => esc_html__( 'Yes', 'shortcode-item-updated' ),
242270
),
243271
'description' => esc_html__( 'Optional time of last update', 'shortcode-item-updated' ),
244272
),
@@ -247,8 +275,8 @@ function ddw_siu_register_shortcode_for_ui() {
247275
'attr' => 'show_sep',
248276
'type' => 'select',
249277
'options' => array(
250-
'no' => esc_html__( 'No', 'shortcode-item-updated' ),
251-
'yes' => esc_html__( 'Yes', 'shortcode-item-updated' ),
278+
'no' => esc_html__( 'No', 'shortcode-item-updated' ),
279+
'yes' => esc_html__( 'Yes', 'shortcode-item-updated' ),
252280
),
253281
'description' => esc_html__( 'Whether to show some string between date and time values', 'shortcode-item-updated' ),
254282
),
@@ -269,8 +297,8 @@ function ddw_siu_register_shortcode_for_ui() {
269297
'attr' => 'show_label',
270298
'type' => 'select',
271299
'options' => array(
272-
'no' => esc_html__( 'No', 'shortcode-item-updated' ),
273-
'yes' => esc_html__( 'Yes', 'shortcode-item-updated' ),
300+
'no' => esc_html__( 'No', 'shortcode-item-updated' ),
301+
'yes' => esc_html__( 'Yes', 'shortcode-item-updated' ),
274302
),
275303
'description' => esc_html__( 'Whether to show label before date', 'shortcode-item-updated' ),
276304
),
@@ -314,9 +342,10 @@ function ddw_siu_register_shortcode_for_ui() {
314342
),
315343
); // end array
316344

345+
/** Pass our Shortcode and UI args to Shortcake plugin - filterable */
317346
shortcode_ui_register_for_shortcode(
318347
'siu-item-updated',
319348
apply_filters( 'siu_filter_shortcode_ui_args', $shortcode_ui_args )
320349
);
321350

322-
} // end function
351+
} // end function

0 commit comments

Comments
 (0)