WP Subtitle - Version 2.7

Version Description

  • Trim subtitle by default.
  • Apply wptexturize() on subtitle.
  • Use WP_Subtitle class to manage post subtitle.
Download this release

Release Info

Developer husobj
Plugin Icon 128x128 WP Subtitle
Version 2.7
Comparing to
See all releases

Code changes from version 2.6 to 2.7

CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
 
5
  ## [Unreleased]
6
 
 
 
 
 
 
 
 
7
  ## [2.6] - 2015-12-08
8
 
9
  ### Security
4
 
5
  ## [Unreleased]
6
 
7
+ ## [2.7] - 2016-08-04
8
+
9
+ ### Changed
10
+ - Trim subtitle by default.
11
+ - Apply wptexturize() on subtitle.
12
+ - Use WP_Subtitle class to manage post subtitle.
13
+
14
  ## [2.6] - 2015-12-08
15
 
16
  ### Security
README.md CHANGED
@@ -88,6 +88,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
88
  Upgrade Notice
89
  --------------
90
 
 
 
 
91
  ### 2.6
92
  Added quick edit support for subtitle. Security Update: Sanitize `$_REQUEST` and `$_GET` when establishing post type in the admin.
93
 
88
  Upgrade Notice
89
  --------------
90
 
91
+ ### 2.7
92
+ Trim subtitle and wptexturize() by default.
93
+
94
  ### 2.6
95
  Added quick edit support for subtitle. Security Update: Sanitize `$_REQUEST` and `$_GET` when establishing post type in the admin.
96
 
admin/admin.php CHANGED
@@ -127,8 +127,10 @@ class WPSubtitle_Admin {
127
  public static function manage_subtitle_columns_content( $column_name, $post_id ) {
128
 
129
  if ( $column_name == 'wps_subtitle' ) {
130
- $subtitle = get_the_subtitle( $post_id, '', '', false );
131
- echo '<span data-wps_subtitle="' . esc_attr( $subtitle ) . '">' . esc_html( $subtitle ) . '</span>';
 
 
132
  }
133
 
134
  }
@@ -229,9 +231,13 @@ class WPSubtitle_Admin {
229
  * @uses apply_filters( 'wps_subtitle_field_description' )
230
  */
231
  public static function _add_subtitle_meta_box() {
 
232
  global $post;
 
 
 
233
  echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
234
- echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( WPSubtitle::_get_post_meta( $post->ID ) ) . '" style="width:99%;" />';
235
  echo apply_filters( 'wps_subtitle_field_description', '', $post );
236
  }
237
 
@@ -245,11 +251,15 @@ class WPSubtitle_Admin {
245
  * @uses apply_filters( 'wps_subtitle_field_description' )
246
  */
247
  public static function _add_subtitle_field() {
 
248
  global $post;
 
 
 
249
  echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
250
  echo '<div id="subtitlediv" class="top">';
251
  echo '<div id="subtitlewrap">';
252
- echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( WPSubtitle::_get_post_meta( $post->ID ) ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', 'wp-subtitle' ) ) ) . '" />';
253
  echo '</div>';
254
 
255
  // Description
@@ -290,7 +300,10 @@ class WPSubtitle_Admin {
290
 
291
  // Save data
292
  if ( isset( $_POST['wps_subtitle'] ) ) {
293
- update_post_meta( $post_id, WPSubtitle::_get_post_meta_key( $post_id ), wp_kses_post( $_POST['wps_subtitle'] ) );
 
 
 
294
  }
295
  }
296
 
127
  public static function manage_subtitle_columns_content( $column_name, $post_id ) {
128
 
129
  if ( $column_name == 'wps_subtitle' ) {
130
+
131
+ $subtitle = new WP_Subtitle( $post_id );
132
+ echo '<span data-wps_subtitle="' . esc_attr( $subtitle->get_subtitle() ) . '">' . esc_html( $subtitle->get_subtitle() ) . '</span>';
133
+
134
  }
135
 
136
  }
231
  * @uses apply_filters( 'wps_subtitle_field_description' )
232
  */
233
  public static function _add_subtitle_meta_box() {
234
+
235
  global $post;
236
+
237
+ $subtitle = new WP_Subtitle( $post );
238
+
239
  echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
240
+ echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( $subtitle->get_raw_subtitle() ) . '" style="width:99%;" />';
241
  echo apply_filters( 'wps_subtitle_field_description', '', $post );
242
  }
243
 
251
  * @uses apply_filters( 'wps_subtitle_field_description' )
252
  */
253
  public static function _add_subtitle_field() {
254
+
255
  global $post;
256
+
257
+ $subtitle = new WP_Subtitle( $post );
258
+
259
  echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
260
  echo '<div id="subtitlediv" class="top">';
261
  echo '<div id="subtitlewrap">';
262
+ echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( $subtitle->get_raw_subtitle() ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', 'wp-subtitle' ) ) ) . '" />';
263
  echo '</div>';
264
 
265
  // Description
300
 
301
  // Save data
302
  if ( isset( $_POST['wps_subtitle'] ) ) {
303
+
304
+ $subtitle = new WP_Subtitle( $post );
305
+ $subtitle->update_subtitle( $_POST['wps_subtitle'] );
306
+
307
  }
308
  }
309
 
includes/deprecated.php CHANGED
@@ -15,7 +15,10 @@
15
  */
16
  function wps_get_the_subtitle() {
17
  _deprecated_function( 'wps_get_the_subtitle()', '2.0', 'the_subtitle()' );
18
- the_subtitle();
 
 
 
19
  }
20
 
21
  /**
15
  */
16
  function wps_get_the_subtitle() {
17
  _deprecated_function( 'wps_get_the_subtitle()', '2.0', 'the_subtitle()' );
18
+
19
+ $subtitle = new WP_Subtitle( get_the_ID() );
20
+ $subtitle->the_subtitle();
21
+
22
  }
23
 
24
  /**
includes/shortcode.php CHANGED
@@ -43,7 +43,12 @@ class WPSubtitle_Shortcode {
43
  $before .= self::format_subtitle_content( $atts['before'], 'before' );
44
  $after = self::format_subtitle_content( $atts['after'], 'after' ) . $after;
45
 
46
- return get_the_subtitle( $post->ID, $before, $after, false );
 
 
 
 
 
47
 
48
  }
49
 
43
  $before .= self::format_subtitle_content( $atts['before'], 'before' );
44
  $after = self::format_subtitle_content( $atts['after'], 'after' ) . $after;
45
 
46
+ $subtitle = new WP_Subtitle( $post );
47
+
48
+ return $subtitle->get_subtitle( array(
49
+ 'before' => $before,
50
+ 'after' => $after
51
+ ) );
52
 
53
  }
54
 
includes/subtitle.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package WP Subtitle
5
+ * @subpackage Subtitle Class
6
+ */
7
+
8
+ class WP_Subtitle {
9
+
10
+ /**
11
+ * Post ID
12
+ *
13
+ * @var int
14
+ */
15
+ private $post_id = 0;
16
+
17
+ /**
18
+ * Constructor
19
+ *
20
+ * @param int|WP_Post $post Post object or ID.
21
+ */
22
+ public function __construct( $post ) {
23
+
24
+ // Post ID
25
+ if ( is_a( $post, 'WP_Post' ) ) {
26
+ $this->post_id = absint( $post->ID );
27
+ } else {
28
+ $this->post_id = absint( $post );
29
+ }
30
+
31
+ }
32
+
33
+ /**
34
+ * The Subtitle
35
+ *
36
+ * @param array $args Display parameters.
37
+ */
38
+ public function the_subtitle( $args = '' ) {
39
+
40
+ echo $this->get_subtitle( $args );
41
+
42
+ }
43
+
44
+ /**
45
+ * Get the Subtitle
46
+ *
47
+ * @uses apply_filters( 'wps_subtitle' )
48
+ *
49
+ * @param array $args Display parameters.
50
+ * @return string The filtered subtitle meta value.
51
+ */
52
+ public function get_subtitle( $args = '' ) {
53
+
54
+ if ( $this->post_id && $this->is_supported_post_type() ) {
55
+
56
+ $args = wp_parse_args( $args, array(
57
+ 'before' => '',
58
+ 'after' => ''
59
+ ) );
60
+
61
+ $subtitle = apply_filters( 'wps_subtitle', $this->get_raw_subtitle(), get_post( $this->post_id ) );
62
+
63
+ if ( ! empty( $subtitle ) ) {
64
+ $subtitle = $args['before'] . $subtitle . $args['after'];
65
+ }
66
+
67
+ return $subtitle;
68
+
69
+ }
70
+
71
+ return '';
72
+
73
+ }
74
+
75
+ /**
76
+ * Get Raw Subtitle
77
+ *
78
+ * @return string The subtitle meta value.
79
+ */
80
+ public function get_raw_subtitle() {
81
+
82
+ return get_post_meta( $this->post_id, $this->get_post_meta_key(), true );
83
+
84
+ }
85
+
86
+ /**
87
+ * Update Subtitle
88
+ *
89
+ * @param string $subtitle Subtitle.
90
+ * @return int|bool Meta ID if new entry. True if updated, false if not updated or the same as current value.
91
+ */
92
+ public function update_subtitle( $subtitle ) {
93
+
94
+ return update_post_meta( $this->post_id, $this->get_post_meta_key(), wp_kses_post( $subtitle ) );
95
+
96
+ }
97
+
98
+ /**
99
+ * Get Post Meta Key
100
+ *
101
+ * @uses apply_filters( 'wps_subtitle_key' )
102
+ *
103
+ * @return string The subtitle meta key.
104
+ */
105
+ private function get_post_meta_key() {
106
+
107
+ return apply_filters( 'wps_subtitle_key', 'wps_subtitle', $this->post_id );
108
+
109
+ }
110
+
111
+ /**
112
+ * Is Supported Post Type?
113
+ *
114
+ * @return boolean
115
+ */
116
+ private function is_supported_post_type() {
117
+
118
+ $post_types = $this->get_supported_post_types();
119
+
120
+ return in_array( get_post_type( $this->post_id ), $post_types );
121
+
122
+ }
123
+
124
+ /**
125
+ * Get Supported Post Types
126
+ *
127
+ * @return array Array of supported post types.
128
+ */
129
+ private function get_supported_post_types() {
130
+
131
+ $post_types = (array) get_post_types( array(
132
+ '_builtin' => false
133
+ ) );
134
+
135
+ $post_types = array_merge( $post_types, array( 'post', 'page' ) );
136
+
137
+ $supported = array();
138
+
139
+ foreach ( $post_types as $post_type ) {
140
+ if ( post_type_supports( $post_type, 'wps_subtitle' ) ) {
141
+ $supported[] = $post_type;
142
+ }
143
+ }
144
+
145
+ return $supported;
146
+
147
+ }
148
+
149
+ }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: husobj, husani
3
  Tags: subtitle, content, title, subheading, subhead, alternate title
4
  Requires at least: 3.7
5
- Tested up to: 4.4
6
- Stable tag: 2.6
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.txt
9
 
@@ -99,6 +99,11 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
99
 
100
  == Changelog ==
101
 
 
 
 
 
 
102
  = 2.6 =
103
  * Security Update: Sanitize `$_REQUEST` and `$_GET` when establishing post type in the admin.
104
  * Added quick edit support for subtitle. Props [Fabian Marz](https://github.com/fabianmarz) and [sun](https://github.com/sun).
@@ -153,6 +158,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
153
 
154
  == Upgrade Notice ==
155
 
 
 
 
156
  = 2.6 =
157
  Added quick edit support for subtitle. Security Update: Sanitize `$_REQUEST` and `$_GET` when establishing post type in the admin.
158
 
2
  Contributors: husobj, husani
3
  Tags: subtitle, content, title, subheading, subhead, alternate title
4
  Requires at least: 3.7
5
+ Tested up to: 4.6
6
+ Stable tag: 2.7
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.txt
9
 
99
 
100
  == Changelog ==
101
 
102
+ = 2.7 =
103
+ * Trim subtitle by default.
104
+ * Apply wptexturize() on subtitle.
105
+ * Use WP_Subtitle class to manage post subtitle.
106
+
107
  = 2.6 =
108
  * Security Update: Sanitize `$_REQUEST` and `$_GET` when establishing post type in the admin.
109
  * Added quick edit support for subtitle. Props [Fabian Marz](https://github.com/fabianmarz) and [sun](https://github.com/sun).
158
 
159
  == Upgrade Notice ==
160
 
161
+ = 2.7 =
162
+ Trim subtitle and wptexturize() by default.
163
+
164
  = 2.6 =
165
  Added quick edit support for subtitle. Security Update: Sanitize `$_REQUEST` and `$_GET` when establishing post type in the admin.
166
 
wp-subtitle.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: WP Subtitle
5
  Plugin URI: http://wordpress.org/plugins/wp-subtitle/
6
  Description: Adds a subtitle field to pages and posts. Possible to add support for custom post types.
7
- Version: 2.6
8
  Author: Ben Huson, Husani Oakley
9
  Author URI: https://github.com/benhuson/wp-subtitle
10
  License: GPLv2
@@ -38,6 +38,7 @@ define( 'WPSUBTITLE_URL', plugins_url( WPSUBTITLE_SUBDIR ) );
38
  define( 'WPSUBTITLE_DIR', plugin_dir_path( __FILE__ ) );
39
 
40
  // Includes
 
41
  include_once( WPSUBTITLE_DIR . 'includes/deprecated.php' );
42
  include_once( WPSUBTITLE_DIR . 'includes/shortcode.php' );
43
 
@@ -53,6 +54,10 @@ if ( is_admin() ) {
53
 
54
  add_action( 'init', array( 'WPSubtitle', '_add_default_post_type_support' ), 5 );
55
 
 
 
 
 
56
  class WPSubtitle {
57
 
58
  /**
@@ -108,19 +113,17 @@ class WPSubtitle {
108
  *
109
  * @since 2.0
110
  *
111
- * @uses WPSubtitle::_get_post_meta()
112
- * @uses apply_filters( 'wps_subtitle' )
113
  *
114
  * @param int|object $post Post ID or object.
115
  * @return string The filtered subtitle meta value.
116
  */
117
  public static function get_the_subtitle( $post = 0 ) {
118
- $post = get_post( $post );
119
- if ( $post && self::is_supported_post_type( $post->post_type ) ) {
120
- $subtitle = self::_get_post_meta( $post );
121
- return apply_filters( 'wps_subtitle', $subtitle, $post );
122
- }
123
- return '';
124
  }
125
 
126
  /**
@@ -129,12 +132,17 @@ class WPSubtitle {
129
  * @since 2.0
130
  * @internal
131
  *
 
 
132
  * @param int|object $post Post ID or object.
133
  * @return string The subtitle meta value.
134
  */
135
- public static function _get_post_meta( $id = 0 ) {
136
- $post = get_post( $id );
137
- return get_post_meta( $post->ID, self::_get_post_meta_key( $post->ID ), true );
 
 
 
138
  }
139
 
140
  /**
@@ -159,7 +167,7 @@ class WPSubtitle {
159
  *
160
  * @since 1.0
161
  *
162
- * @uses get_the_subtitle()
163
  *
164
  * @param string $before Before the subtitle.
165
  * @param string $after After the subtitle.
@@ -167,7 +175,20 @@ class WPSubtitle {
167
  * @return string The subtitle string.
168
  */
169
  function the_subtitle( $before = '', $after = '', $echo = true ) {
170
- return get_the_subtitle( 0, $before, $after, $echo );
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  }
172
 
173
  /**
@@ -175,7 +196,7 @@ function the_subtitle( $before = '', $after = '', $echo = true ) {
175
  *
176
  * @since 1.0
177
  *
178
- * @uses WPSubtitle::get_the_subtitle()
179
  *
180
  * @param int|object $post Post ID or object.
181
  * @param string $before Before the subtitle.
@@ -184,14 +205,18 @@ function the_subtitle( $before = '', $after = '', $echo = true ) {
184
  * @return string The subtitle string.
185
  */
186
  function get_the_subtitle( $post = 0, $before = '', $after = '', $echo = true ) {
187
- $subtitle = WPSubtitle::get_the_subtitle( $post );
188
 
189
- if ( ! empty( $subtitle ) ) {
190
- $subtitle = $before . $subtitle . $after;
191
- }
 
 
 
192
 
193
  if ( ! $echo ) {
194
- return $subtitle;
195
  }
196
- echo $subtitle;
 
 
197
  }
4
  Plugin Name: WP Subtitle
5
  Plugin URI: http://wordpress.org/plugins/wp-subtitle/
6
  Description: Adds a subtitle field to pages and posts. Possible to add support for custom post types.
7
+ Version: 2.7
8
  Author: Ben Huson, Husani Oakley
9
  Author URI: https://github.com/benhuson/wp-subtitle
10
  License: GPLv2
38
  define( 'WPSUBTITLE_DIR', plugin_dir_path( __FILE__ ) );
39
 
40
  // Includes
41
+ include_once( WPSUBTITLE_DIR . 'includes/subtitle.php' );
42
  include_once( WPSUBTITLE_DIR . 'includes/deprecated.php' );
43
  include_once( WPSUBTITLE_DIR . 'includes/shortcode.php' );
44
 
54
 
55
  add_action( 'init', array( 'WPSubtitle', '_add_default_post_type_support' ), 5 );
56
 
57
+ // Default subtitle filters
58
+ add_filter( 'wps_subtitle', 'wptexturize' );
59
+ add_filter( 'wps_subtitle', 'trim' );
60
+
61
  class WPSubtitle {
62
 
63
  /**
113
  *
114
  * @since 2.0
115
  *
116
+ * @uses WP_Subtitle::get_subtitle()
 
117
  *
118
  * @param int|object $post Post ID or object.
119
  * @return string The filtered subtitle meta value.
120
  */
121
  public static function get_the_subtitle( $post = 0 ) {
122
+
123
+ $subtitle = new WP_Subtitle( $post );
124
+
125
+ return $subtitle->get_subtitle();
126
+
 
127
  }
128
 
129
  /**
132
  * @since 2.0
133
  * @internal
134
  *
135
+ * @uses WP_Subtitle::get_raw_subtitle()
136
+ *
137
  * @param int|object $post Post ID or object.
138
  * @return string The subtitle meta value.
139
  */
140
+ public static function _get_post_meta( $post = 0 ) {
141
+
142
+ $subtitle = new WP_Subtitle( $post );
143
+
144
+ return $subtitle->get_raw_subtitle();
145
+
146
  }
147
 
148
  /**
167
  *
168
  * @since 1.0
169
  *
170
+ * @uses WP_Subtitle::get_subtitle()
171
  *
172
  * @param string $before Before the subtitle.
173
  * @param string $after After the subtitle.
175
  * @return string The subtitle string.
176
  */
177
  function the_subtitle( $before = '', $after = '', $echo = true ) {
178
+
179
+ $subtitle = new WP_Subtitle( get_the_ID() );
180
+
181
+ $output = $subtitle->get_subtitle( array(
182
+ 'before' => $before,
183
+ 'after' => $after
184
+ ) );
185
+
186
+ if ( ! $echo ) {
187
+ return $output;
188
+ }
189
+
190
+ echo $output;
191
+
192
  }
193
 
194
  /**
196
  *
197
  * @since 1.0
198
  *
199
+ * @uses WP_Subtitle::get_subtitle()
200
  *
201
  * @param int|object $post Post ID or object.
202
  * @param string $before Before the subtitle.
205
  * @return string The subtitle string.
206
  */
207
  function get_the_subtitle( $post = 0, $before = '', $after = '', $echo = true ) {
 
208
 
209
+ $subtitle = new WP_Subtitle( $post );
210
+
211
+ $output = $subtitle->get_subtitle( array(
212
+ 'before' => $before,
213
+ 'after' => $after
214
+ ) );
215
 
216
  if ( ! $echo ) {
217
+ return $output;
218
  }
219
+
220
+ echo $output;
221
+
222
  }