Version Description
- Add support for post revisions. Props Fabian Marz.
- As of WordPress 4.3 no need to esc_attr() AND htmlentities() - can mess up special characters.
Download this release
Release Info
Developer | husobj |
Plugin | WP Subtitle |
Version | 2.9 |
Comparing to | |
See all releases |
Code changes from version 2.8.1 to 2.9
- CHANGELOG.md +10 -1
- README.md +3 -0
- admin/admin.php +57 -5
- includes/subtitle.php +40 -2
- readme.txt +11 -2
- wp-subtitle.php +29 -2
CHANGELOG.md
CHANGED
@@ -4,6 +4,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4 |
|
5 |
## [Unreleased]
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
## [2.8.1] - 2016-09-14
|
8 |
|
9 |
### Fixed
|
@@ -124,7 +132,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
124 |
### Added
|
125 |
- First version.
|
126 |
|
127 |
-
[Unreleased]: https://github.com/benhuson/wp-subtitle/compare/2.
|
|
|
128 |
[2.8.1]: https://github.com/benhuson/wp-subtitle/compare/2.8...2.8.1
|
129 |
[2.8]: https://github.com/benhuson/wp-subtitle/compare/2.7.1...2.8
|
130 |
[2.7.1]: https://github.com/benhuson/wp-subtitle/compare/2.7...2.7.1
|
4 |
|
5 |
## [Unreleased]
|
6 |
|
7 |
+
## [2.9] - 2017-05-03
|
8 |
+
|
9 |
+
### Added
|
10 |
+
- Add support for post revisions. Props [Fabian Marz](https://github.com/fabianmarz).
|
11 |
+
|
12 |
+
### Fixed
|
13 |
+
- As of WordPress 4.3 no need to esc_attr() AND htmlentities() - can mess up special characters.
|
14 |
+
|
15 |
## [2.8.1] - 2016-09-14
|
16 |
|
17 |
### Fixed
|
132 |
### Added
|
133 |
- First version.
|
134 |
|
135 |
+
[Unreleased]: https://github.com/benhuson/wp-subtitle/compare/2.9...HEAD
|
136 |
+
[2.9]: https://github.com/benhuson/wp-subtitle/compare/2.8.1...2.9
|
137 |
[2.8.1]: https://github.com/benhuson/wp-subtitle/compare/2.8...2.8.1
|
138 |
[2.8]: https://github.com/benhuson/wp-subtitle/compare/2.7.1...2.8
|
139 |
[2.7.1]: https://github.com/benhuson/wp-subtitle/compare/2.7...2.7.1
|
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.8.1
|
92 |
Fix PHP warning - `get_admin_subtitle_value()` should be declared static.
|
93 |
|
88 |
Upgrade Notice
|
89 |
--------------
|
90 |
|
91 |
+
### 2.9
|
92 |
+
Add support for revisions and fix special character encoding.
|
93 |
+
|
94 |
### 2.8.1
|
95 |
Fix PHP warning - `get_admin_subtitle_value()` should be declared static.
|
96 |
|
admin/admin.php
CHANGED
@@ -21,8 +21,13 @@ class WPSubtitle_Admin {
|
|
21 |
load_plugin_textdomain( 'wp-subtitle', false, dirname( WPSUBTITLE_BASENAME ) . '/languages' );
|
22 |
|
23 |
add_action( 'admin_init', array( 'WPSubtitle_Admin', '_admin_init' ) );
|
|
|
24 |
add_action( 'save_post', array( 'WPSubtitle_Admin', '_save_post' ) );
|
25 |
add_action( 'admin_enqueue_scripts', array( 'WPSubtitle_Admin', '_add_admin_scripts' ) );
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
|
28 |
/**
|
@@ -151,6 +156,37 @@ class WPSubtitle_Admin {
|
|
151 |
|
152 |
}
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
/**
|
155 |
* Add Admin Styles
|
156 |
*
|
@@ -237,8 +273,13 @@ class WPSubtitle_Admin {
|
|
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 |
-
|
|
|
|
|
|
|
|
|
241 |
echo apply_filters( 'wps_subtitle_field_description', '', $post );
|
|
|
242 |
}
|
243 |
|
244 |
/**
|
@@ -258,9 +299,13 @@ class WPSubtitle_Admin {
|
|
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 |
-
|
262 |
-
|
263 |
-
|
|
|
|
|
|
|
|
|
264 |
|
265 |
// Description
|
266 |
$description = apply_filters( 'wps_subtitle_field_description', '', $post );
|
@@ -323,10 +368,17 @@ class WPSubtitle_Admin {
|
|
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( $
|
330 |
}
|
331 |
|
332 |
}
|
21 |
load_plugin_textdomain( 'wp-subtitle', false, dirname( WPSUBTITLE_BASENAME ) . '/languages' );
|
22 |
|
23 |
add_action( 'admin_init', array( 'WPSubtitle_Admin', '_admin_init' ) );
|
24 |
+
add_action( 'post_updated', array( 'WPSubtitle_Admin', '_save_post' ), 9 );
|
25 |
add_action( 'save_post', array( 'WPSubtitle_Admin', '_save_post' ) );
|
26 |
add_action( 'admin_enqueue_scripts', array( 'WPSubtitle_Admin', '_add_admin_scripts' ) );
|
27 |
+
|
28 |
+
add_filter( '_wp_post_revision_fields', array( 'WPSubtitle_Admin', '_wp_post_revision_fields' ), 9 );
|
29 |
+
add_action( 'wp_restore_post_revision', array( 'WPSubtitle_Admin', 'wp_restore_post_revision' ), 10, 2 );
|
30 |
+
|
31 |
}
|
32 |
|
33 |
/**
|
156 |
|
157 |
}
|
158 |
|
159 |
+
/**
|
160 |
+
* Add `wps_subtitle` to post revision fields.
|
161 |
+
*
|
162 |
+
* @since 2.9
|
163 |
+
* @internal
|
164 |
+
*
|
165 |
+
* @param array $fields Revision fields.
|
166 |
+
*/
|
167 |
+
public static function _wp_post_revision_fields( $fields ) {
|
168 |
+
|
169 |
+
$fields['wps_subtitle'] = __( 'Subtitle', 'wp-subtitle' );
|
170 |
+
|
171 |
+
return $fields;
|
172 |
+
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Restore revisioned `wps_subtitle` value to post.
|
177 |
+
*
|
178 |
+
* @since 2.9
|
179 |
+
*
|
180 |
+
* @param int $post_id Post ID.
|
181 |
+
* @param int $revision_id Revision ID.
|
182 |
+
*/
|
183 |
+
public static function wp_restore_post_revision( $post_id, $revision_id ) {
|
184 |
+
|
185 |
+
$subtitle = new WP_Subtitle( $post_id );
|
186 |
+
$subtitle->restore_post_revision( $revision_id );
|
187 |
+
|
188 |
+
}
|
189 |
+
|
190 |
/**
|
191 |
* Add Admin Styles
|
192 |
*
|
273 |
$value = self::get_admin_subtitle_value( $post );
|
274 |
|
275 |
echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
|
276 |
+
|
277 |
+
// As of WordPress 4.3 no need to esc_attr() AND htmlentities().
|
278 |
+
// @see https://core.trac.wordpress.org/changeset/33271
|
279 |
+
echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( $value ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', 'wp-subtitle' ) ) ) . '" style="width:99%;" />';
|
280 |
+
|
281 |
echo apply_filters( 'wps_subtitle_field_description', '', $post );
|
282 |
+
|
283 |
}
|
284 |
|
285 |
/**
|
299 |
|
300 |
echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
|
301 |
echo '<div id="subtitlediv" class="top">';
|
302 |
+
echo '<div id="subtitlewrap">';
|
303 |
+
|
304 |
+
// As of WordPress 4.3 no need to esc_attr() AND htmlentities().
|
305 |
+
// @see https://core.trac.wordpress.org/changeset/33271
|
306 |
+
echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( $value ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', 'wp-subtitle' ) ) ) . '" />';
|
307 |
+
|
308 |
+
echo '</div>';
|
309 |
|
310 |
// Description
|
311 |
$description = apply_filters( 'wps_subtitle_field_description', '', $post );
|
368 |
// Check data and save
|
369 |
if ( isset( $_POST['wps_subtitle'] ) ) {
|
370 |
|
371 |
+
$new_value = $_POST['wps_subtitle'];
|
372 |
+
|
373 |
$subtitle = new WP_Subtitle( $post_id );
|
374 |
|
375 |
+
// Don't save if value not changed
|
376 |
+
if ( $subtitle->is_current_subtitle( $new_value ) ) {
|
377 |
+
return;
|
378 |
+
}
|
379 |
+
|
380 |
if ( $subtitle->current_user_can_edit() ) {
|
381 |
+
$subtitle->update_subtitle( $new_value );
|
382 |
}
|
383 |
|
384 |
}
|
includes/subtitle.php
CHANGED
@@ -104,7 +104,22 @@ class WP_Subtitle {
|
|
104 |
*/
|
105 |
public function update_subtitle( $subtitle ) {
|
106 |
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
}
|
110 |
|
@@ -121,6 +136,25 @@ class WP_Subtitle {
|
|
121 |
|
122 |
}
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
/**
|
125 |
* Is Supported Post Type?
|
126 |
*
|
@@ -147,7 +181,7 @@ class WP_Subtitle {
|
|
147 |
'_builtin' => false
|
148 |
) );
|
149 |
|
150 |
-
$post_types = array_merge( $post_types, array( 'post', 'page' ) );
|
151 |
|
152 |
$supported = array();
|
153 |
|
@@ -175,6 +209,10 @@ class WP_Subtitle {
|
|
175 |
|
176 |
$post_type = get_post_type( $this->post_id );
|
177 |
|
|
|
|
|
|
|
|
|
178 |
// Current user can...
|
179 |
switch ( $post_type ) {
|
180 |
|
104 |
*/
|
105 |
public function update_subtitle( $subtitle ) {
|
106 |
|
107 |
+
// Uses `update_metadata` as `update_post_meta` doesn't work with revisions.
|
108 |
+
return update_metadata( 'post', $this->post_id, $this->get_post_meta_key(), $subtitle );
|
109 |
+
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Is Current Subtitle?
|
114 |
+
*
|
115 |
+
* @since 2.9
|
116 |
+
*
|
117 |
+
* @param string $subtitle Subtitle value.
|
118 |
+
* @return boolean
|
119 |
+
*/
|
120 |
+
public function is_current_subtitle( $subtitle ) {
|
121 |
+
|
122 |
+
return $subtitle === get_metadata( 'post', $this->post_id, 'wps_subtitle', true );
|
123 |
|
124 |
}
|
125 |
|
136 |
|
137 |
}
|
138 |
|
139 |
+
/**
|
140 |
+
* Restore revision.
|
141 |
+
*
|
142 |
+
* @since 2.9
|
143 |
+
*
|
144 |
+
* @param int $revision_id Revision ID.
|
145 |
+
*/
|
146 |
+
public function restore_post_revision( $revision_id ) {
|
147 |
+
|
148 |
+
$meta_value = get_metadata( 'post', $revision_id, $this->get_post_meta_key(), true );
|
149 |
+
|
150 |
+
if ( $meta_value ) {
|
151 |
+
$this->update_subtitle( $meta_value );
|
152 |
+
} else {
|
153 |
+
delete_post_meta( $this->post_id, $this->get_post_meta_key() );
|
154 |
+
}
|
155 |
+
|
156 |
+
}
|
157 |
+
|
158 |
/**
|
159 |
* Is Supported Post Type?
|
160 |
*
|
181 |
'_builtin' => false
|
182 |
) );
|
183 |
|
184 |
+
$post_types = array_merge( $post_types, array( 'post', 'page', 'revision' ) );
|
185 |
|
186 |
$supported = array();
|
187 |
|
209 |
|
210 |
$post_type = get_post_type( $this->post_id );
|
211 |
|
212 |
+
if ( $revision = wp_is_post_revision( $this->post_id ) ) {
|
213 |
+
$post_type = get_post_type( $revision );
|
214 |
+
}
|
215 |
+
|
216 |
// Current user can...
|
217 |
switch ( $post_type ) {
|
218 |
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: husobj, husani
|
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SLZUF4XJTS4E6
|
4 |
Tags: subtitle, content, title, subheading, subhead, alternate title
|
5 |
Requires at least: 3.7
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
10 |
|
@@ -100,6 +100,12 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
|
|
100 |
|
101 |
== Changelog ==
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
= 2.8.1 =
|
104 |
* Fix PHP warning - `get_admin_subtitle_value()` should be declared static.
|
105 |
|
@@ -170,6 +176,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
|
|
170 |
|
171 |
== Upgrade Notice ==
|
172 |
|
|
|
|
|
|
|
173 |
= 2.8.1 =
|
174 |
Fix PHP warning - `get_admin_subtitle_value()` should be declared static.
|
175 |
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SLZUF4XJTS4E6
|
4 |
Tags: subtitle, content, title, subheading, subhead, alternate title
|
5 |
Requires at least: 3.7
|
6 |
+
Tested up to: 4.7.4
|
7 |
+
Stable tag: 2.9
|
8 |
License: GPLv2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
10 |
|
100 |
|
101 |
== Changelog ==
|
102 |
|
103 |
+
= Unreleased =
|
104 |
+
|
105 |
+
= 2.9 =
|
106 |
+
* Add support for post revisions. Props [Fabian Marz](https://github.com/fabianmarz).
|
107 |
+
* As of WordPress 4.3 no need to esc_attr() AND htmlentities() - can mess up special characters.
|
108 |
+
|
109 |
= 2.8.1 =
|
110 |
* Fix PHP warning - `get_admin_subtitle_value()` should be declared static.
|
111 |
|
176 |
|
177 |
== Upgrade Notice ==
|
178 |
|
179 |
+
= 2.9 =
|
180 |
+
Add support for revisions and fix special character encoding.
|
181 |
+
|
182 |
= 2.8.1 =
|
183 |
Fix PHP warning - `get_admin_subtitle_value()` should be declared static.
|
184 |
|
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.
|
8 |
Author: Ben Huson, Husani Oakley
|
9 |
Author URI: https://github.com/benhuson/wp-subtitle
|
10 |
License: GPLv2
|
@@ -69,6 +69,33 @@ class WPSubtitle {
|
|
69 |
public static function _add_default_post_type_support() {
|
70 |
add_post_type_support( 'page', 'wps_subtitle' );
|
71 |
add_post_type_support( 'post', 'wps_subtitle' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
|
74 |
/**
|
@@ -82,7 +109,7 @@ class WPSubtitle {
|
|
82 |
$post_types = (array) get_post_types( array(
|
83 |
'_builtin' => false
|
84 |
) );
|
85 |
-
$post_types = array_merge( $post_types, array( 'post', 'page' ) );
|
86 |
$supported = array();
|
87 |
foreach ( $post_types as $post_type ) {
|
88 |
if ( post_type_supports( $post_type, 'wps_subtitle' ) ) {
|
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.9
|
8 |
Author: Ben Huson, Husani Oakley
|
9 |
Author URI: https://github.com/benhuson/wp-subtitle
|
10 |
License: GPLv2
|
69 |
public static function _add_default_post_type_support() {
|
70 |
add_post_type_support( 'page', 'wps_subtitle' );
|
71 |
add_post_type_support( 'post', 'wps_subtitle' );
|
72 |
+
add_post_type_support( 'revision', 'wps_subtitle' );
|
73 |
+
|
74 |
+
add_filter( 'the_preview', array( 'WPSubtitle', 'the_preview' ), 10, 2 );
|
75 |
+
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Returns the autosaved data to make changes visible in preview mode.
|
80 |
+
*
|
81 |
+
* @since 2.9
|
82 |
+
*
|
83 |
+
* @param object $post Post object.
|
84 |
+
* @param object $query Query object.
|
85 |
+
* @return WP_Post|false The autosaved data or false on failure or when no autosave exists.
|
86 |
+
*/
|
87 |
+
public static function the_preview( $post, $query ) {
|
88 |
+
|
89 |
+
if ( isset( $_GET['preview_id'] ) ) {
|
90 |
+
return wp_get_post_autosave( $post->ID );
|
91 |
+
}
|
92 |
+
|
93 |
+
if ( $revisions = wp_get_post_revisions( $post->ID ) ) {
|
94 |
+
return array_shift( $revisions );
|
95 |
+
}
|
96 |
+
|
97 |
+
return $post;
|
98 |
+
|
99 |
}
|
100 |
|
101 |
/**
|
109 |
$post_types = (array) get_post_types( array(
|
110 |
'_builtin' => false
|
111 |
) );
|
112 |
+
$post_types = array_merge( $post_types, array( 'post', 'page', 'revision' ) );
|
113 |
$supported = array();
|
114 |
foreach ( $post_types as $post_type ) {
|
115 |
if ( post_type_supports( $post_type, 'wps_subtitle' ) ) {
|