WP Subtitle - Version 2.8

Version Description

  • Allow subtitle to contain HTML (same as main post title ).
  • Add wps_default_subtitle filter.
  • Use WP_Subtitle class to validate saving of subtitle in the admin.
Download this release

Release Info

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

Code changes from version 2.7.1 to 2.8

Files changed (6) hide show
  1. CHANGELOG.md +11 -1
  2. README.md +3 -0
  3. admin/admin.php +44 -27
  4. includes/subtitle.php +58 -1
  5. readme.txt +9 -1
  6. wp-subtitle.php +1 -1
CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
 
5
  ## [Unreleased]
6
 
 
 
 
 
 
 
 
 
 
7
  ## [2.7.1] - 2016-08-05
8
 
9
  ### Fixed
@@ -110,7 +119,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
110
  ### Added
111
  - First version.
112
 
113
- [Unreleased]: https://github.com/benhuson/wp-subtitle/compare/2.7.1...HEAD
 
114
  [2.7.1]: https://github.com/benhuson/wp-subtitle/compare/2.7...2.7.1
115
  [2.7]: https://github.com/benhuson/wp-subtitle/compare/2.6...2.7
116
  [2.6]: https://github.com/benhuson/wp-subtitle/compare/2.5...2.6
4
 
5
  ## [Unreleased]
6
 
7
+ ## [2.8] - 2016-09-07
8
+
9
+ ### Added
10
+ - Add `wps_default_subtitle` filter.
11
+
12
+ ### Changed
13
+ - Allow subtitle to contain HTML (same as main post title ).
14
+ - Use WP_Subtitle class to validate saving of subtitle in the admin.
15
+
16
  ## [2.7.1] - 2016-08-05
17
 
18
  ### Fixed
119
  ### Added
120
  - First version.
121
 
122
+ [Unreleased]: https://github.com/benhuson/wp-subtitle/compare/2.8...HEAD
123
+ [2.8]: https://github.com/benhuson/wp-subtitle/compare/2.7.1...2.8
124
  [2.7.1]: https://github.com/benhuson/wp-subtitle/compare/2.7...2.7.1
125
  [2.7]: https://github.com/benhuson/wp-subtitle/compare/2.6...2.7
126
  [2.6]: https://github.com/benhuson/wp-subtitle/compare/2.5...2.6
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.7.1
92
  Fix incorrect post ID reference preventing subtitle from saving.
93
 
88
  Upgrade Notice
89
  --------------
90
 
91
+ ### 2.8
92
+ Allow subtitle to contain HTML (same as main post title ) and add `wps_default_subtitle` filter.
93
+
94
  ### 2.7.1
95
  Fix incorrect post ID reference preventing subtitle from saving.
96
 
admin/admin.php CHANGED
@@ -234,10 +234,10 @@ class WPSubtitle_Admin {
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
 
@@ -254,12 +254,12 @@ class WPSubtitle_Admin {
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
@@ -270,6 +270,33 @@ class WPSubtitle_Admin {
270
  echo '</div>';
271
  }
272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  /**
274
  * Save Subtitle
275
  *
@@ -293,24 +320,24 @@ class WPSubtitle_Admin {
293
  return;
294
  }
295
 
296
- // Check edit capability
297
- if ( ! self::_verify_post_edit_capability( $post_id ) ) {
298
- return;
299
- }
300
-
301
- // Save data
302
  if ( isset( $_POST['wps_subtitle'] ) ) {
303
 
304
  $subtitle = new WP_Subtitle( $post_id );
305
- $subtitle->update_subtitle( $_POST['wps_subtitle'] );
 
 
 
306
 
307
  }
 
308
  }
309
 
310
  /**
311
  * Verify Post Edit Capability
312
  *
313
- * @since 2.0.1
 
314
  * @internal
315
  *
316
  * @param int $post_id Post ID.
@@ -318,22 +345,12 @@ class WPSubtitle_Admin {
318
  */
319
  private static function _verify_post_edit_capability( $post_id ) {
320
 
321
- $post_types_obj = (array) get_post_types( array(
322
- '_builtin' => false
323
- ), 'objects' );
324
-
325
- // Check supported post type
326
- if ( isset( $_POST['post_type'] ) && WPSubtitle::is_supported_post_type( $_POST['post_type'] ) ) {
327
- if ( 'page' == $_POST['post_type'] && current_user_can( 'edit_page', $post_id ) ) {
328
- return true;
329
- } elseif ( 'post' == $_POST['post_type'] && current_user_can( 'edit_post', $post_id ) ) {
330
- return true;
331
- } elseif ( current_user_can( $post_types_obj[ $_POST['post_type'] ]->cap->edit_post, $post_id ) ) {
332
- return true;
333
- }
334
- }
335
 
336
- return false;
337
  }
338
 
339
  /**
234
 
235
  global $post;
236
 
237
+ $value = self::get_admin_subtitle_value( $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( htmlentities( $value ) ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', 'wp-subtitle' ) ) ) . '" style="width:99%;" />';
241
  echo apply_filters( 'wps_subtitle_field_description', '', $post );
242
  }
243
 
254
 
255
  global $post;
256
 
257
+ $value = self::get_admin_subtitle_value( $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( htmlentities( $value ) ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', 'wp-subtitle' ) ) ) . '" />';
263
  echo '</div>';
264
 
265
  // Description
270
  echo '</div>';
271
  }
272
 
273
+ /**
274
+ * Get Admin Subtitle Value
275
+ *
276
+ * @since 2.8
277
+ * @internal
278
+ *
279
+ * @param WP_Post $post Post object.
280
+ * @return string Subtitle value.
281
+ */
282
+ private function get_admin_subtitle_value( $post ) {
283
+
284
+ $subtitle = new WP_Subtitle( $post );
285
+
286
+ $value = $subtitle->get_raw_subtitle();
287
+
288
+ // Default subtitle if adding new post
289
+ if ( function_exists( 'get_current_screen' ) && empty( $value ) ) {
290
+ $screen = get_current_screen();
291
+ if ( isset( $screen->action ) && 'add' == $screen->action ) {
292
+ $value = $subtitle->get_default_subtitle( $post );
293
+ }
294
+ }
295
+
296
+ return $value;
297
+
298
+ }
299
+
300
  /**
301
  * Save Subtitle
302
  *
320
  return;
321
  }
322
 
323
+ // Check data and save
 
 
 
 
 
324
  if ( isset( $_POST['wps_subtitle'] ) ) {
325
 
326
  $subtitle = new WP_Subtitle( $post_id );
327
+
328
+ if ( $subtitle->current_user_can_edit() ) {
329
+ $subtitle->update_subtitle( $_POST['wps_subtitle'] );
330
+ }
331
 
332
  }
333
+
334
  }
335
 
336
  /**
337
  * Verify Post Edit Capability
338
  *
339
+ * @since 2.0.1
340
+ * @deprecated 2.7 Use WP_Subtitle->current_user_can_edit() instead.
341
  * @internal
342
  *
343
  * @param int $post_id Post ID.
345
  */
346
  private static function _verify_post_edit_capability( $post_id ) {
347
 
348
+ _deprecated_function( '_verify_post_edit_capability()', '2.7', 'WP_Subtitle->current_user_can_edit()' );
349
+
350
+ $subtitle = new WP_Subtitle( $post_id );
351
+
352
+ return $subtitle->current_user_can_edit();
 
 
 
 
 
 
 
 
 
353
 
 
354
  }
355
 
356
  /**
includes/subtitle.php CHANGED
@@ -83,6 +83,19 @@ class WP_Subtitle {
83
 
84
  }
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  /**
87
  * Update Subtitle
88
  *
@@ -91,7 +104,7 @@ class WP_Subtitle {
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
 
@@ -124,6 +137,8 @@ class WP_Subtitle {
124
  /**
125
  * Get Supported Post Types
126
  *
 
 
127
  * @return array Array of supported post types.
128
  */
129
  private function get_supported_post_types() {
@@ -146,4 +161,46 @@ class WP_Subtitle {
146
 
147
  }
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  }
83
 
84
  }
85
 
86
+ /**
87
+ * Get Default Subtitle
88
+ *
89
+ * @since 2.8
90
+ *
91
+ * @return string Default title.
92
+ */
93
+ public function get_default_subtitle() {
94
+
95
+ return apply_filters( 'wps_default_subtitle', '', $this->post_id );
96
+
97
+ }
98
+
99
  /**
100
  * Update Subtitle
101
  *
104
  */
105
  public function update_subtitle( $subtitle ) {
106
 
107
+ return update_post_meta( $this->post_id, $this->get_post_meta_key(), $subtitle );
108
 
109
  }
110
 
137
  /**
138
  * Get Supported Post Types
139
  *
140
+ * @since 2.7
141
+ *
142
  * @return array Array of supported post types.
143
  */
144
  private function get_supported_post_types() {
161
 
162
  }
163
 
164
+ /**
165
+ * Current User Can Edit
166
+ *
167
+ * @since 2.8
168
+ *
169
+ * @return boolean
170
+ */
171
+ public function current_user_can_edit() {
172
+
173
+ // Check supported post type
174
+ if ( $this->is_supported_post_type() ) {
175
+
176
+ $post_type = get_post_type( $this->post_id );
177
+
178
+ // Current user can...
179
+ switch ( $post_type ) {
180
+
181
+ // ... edit page
182
+ case 'page':
183
+ return current_user_can( 'edit_page', $this->post_id );
184
+
185
+ // ... edit post
186
+ case 'post':
187
+ return current_user_can( 'edit_post', $this->post_id );
188
+
189
+ // ... edit other post type
190
+ default:
191
+
192
+ $post_types = (array) get_post_types( array(
193
+ '_builtin' => false
194
+ ), 'objects' );
195
+
196
+ return current_user_can( $post_types[ $post_type ]->cap->edit_post, $this->post_id );
197
+
198
+ }
199
+
200
+ }
201
+
202
+ return false;
203
+
204
+ }
205
+
206
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: subtitle, content, title, subheading, subhead, alternate title
5
  Requires at least: 3.7
6
  Tested up to: 4.6
7
- Stable tag: 2.7.1
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
 
@@ -100,6 +100,11 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
100
 
101
  == Changelog ==
102
 
 
 
 
 
 
103
  = 2.7.1 =
104
  * Fix incorrect post ID reference preventing subtitle from saving.
105
 
@@ -162,6 +167,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
162
 
163
  == Upgrade Notice ==
164
 
 
 
 
165
  = 2.7.1 =
166
  Fix incorrect post ID reference preventing subtitle from saving.
167
 
4
  Tags: subtitle, content, title, subheading, subhead, alternate title
5
  Requires at least: 3.7
6
  Tested up to: 4.6
7
+ Stable tag: 2.8
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
 
100
 
101
  == Changelog ==
102
 
103
+ = 2.8 =
104
+ * Allow subtitle to contain HTML (same as main post title ).
105
+ * Add `wps_default_subtitle` filter.
106
+ * Use WP_Subtitle class to validate saving of subtitle in the admin.
107
+
108
  = 2.7.1 =
109
  * Fix incorrect post ID reference preventing subtitle from saving.
110
 
167
 
168
  == Upgrade Notice ==
169
 
170
+ = 2.8 =
171
+ Allow subtitle to contain HTML (same as main post title ) and add `wps_default_subtitle` filter.
172
+
173
  = 2.7.1 =
174
  Fix incorrect post ID reference preventing subtitle from saving.
175
 
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.7.1
8
  Author: Ben Huson, Husani Oakley
9
  Author URI: https://github.com/benhuson/wp-subtitle
10
  License: GPLv2
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.8
8
  Author: Ben Huson, Husani Oakley
9
  Author URI: https://github.com/benhuson/wp-subtitle
10
  License: GPLv2