From d91ab1e249618f4d31fbdda0bcee034660e48015 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Thu, 23 Jun 2016 21:16:45 +0100 Subject: [PATCH 01/14] Add WP_Subtitle->current_user_can_edit() method. --- includes/subtitle.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/includes/subtitle.php b/includes/subtitle.php index fa8b36f..0b2c730 100644 --- a/includes/subtitle.php +++ b/includes/subtitle.php @@ -146,4 +146,44 @@ private function get_supported_post_types() { } + /** + * Current User Can Edit + * + * @return boolean + */ + private function current_user_can_edit() { + + // Check supported post type + if ( $this->is_supported_post_type() ) { + + $post_type = get_post_type( $this->post_id ); + + // Current user can... + switch ( $post_type ) { + + // ... edit page + case 'page': + return current_user_can( 'edit_page', $this->post_id ); + + // ... edit post + case 'post': + return current_user_can( 'edit_post', $this->post_id ); + + // ... edit other post type + default: + + $post_types = (array) get_post_types( array( + '_builtin' => false + ), 'objects' ); + + return current_user_can( $post_types[ $post_type ]->cap->edit_post, $this->post_id ); + + } + + } + + return false; + + } + } From 6f08a8dfbc6aa5c434077143f3431aaad34d5fd6 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Thu, 23 Jun 2016 21:17:10 +0100 Subject: [PATCH 02/14] Use WP_Subtitle->current_user_can_edit(). --- admin/admin.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/admin/admin.php b/admin/admin.php index a8ce907..9e96765 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -293,18 +293,17 @@ public static function _save_post( $post_id ) { return; } - // Check edit capability - if ( ! self::_verify_post_edit_capability( $post_id ) ) { - return; - } - - // Save data + // Check data and save if ( isset( $_POST['wps_subtitle'] ) ) { - $subtitle = new WP_Subtitle( $post ); - $subtitle->update_subtitle( $_POST['wps_subtitle'] ); + $subtitle = new WP_Subtitle( $post_id ); + + if ( $subtitle->current_user_can_edit() ) { + $subtitle->update_subtitle( $_POST['wps_subtitle'] ); + } } + } /** From 75fec3e7a159c9b39aad0a729698b9f9f924e84a Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Thu, 23 Jun 2016 21:17:33 +0100 Subject: [PATCH 03/14] Deprecate WPSubtitle_Admin::_verify_post_edit_capability(). --- admin/admin.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/admin/admin.php b/admin/admin.php index 9e96765..fbb25cf 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -309,7 +309,8 @@ public static function _save_post( $post_id ) { /** * Verify Post Edit Capability * - * @since 2.0.1 + * @since 2.0.1 + * @deprecated 2.7 Use WP_Subtitle->current_user_can_edit() instead. * @internal * * @param int $post_id Post ID. @@ -317,22 +318,12 @@ public static function _save_post( $post_id ) { */ private static function _verify_post_edit_capability( $post_id ) { - $post_types_obj = (array) get_post_types( array( - '_builtin' => false - ), 'objects' ); - - // Check supported post type - if ( isset( $_POST['post_type'] ) && WPSubtitle::is_supported_post_type( $_POST['post_type'] ) ) { - if ( 'page' == $_POST['post_type'] && current_user_can( 'edit_page', $post_id ) ) { - return true; - } elseif ( 'post' == $_POST['post_type'] && current_user_can( 'edit_post', $post_id ) ) { - return true; - } elseif ( current_user_can( $post_types_obj[ $_POST['post_type'] ]->cap->edit_post, $post_id ) ) { - return true; - } - } + _deprecated_function( '_verify_post_edit_capability()', '2.7', 'WP_Subtitle->current_user_can_edit()' ); + + $subtitle = new WP_Subtitle( $post_id ); + + return $subtitle->current_user_can_edit(); - return false; } /** From 09e010b2c12c9836f0a1a0fce50ed27c547ff757 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Thu, 23 Jun 2016 21:19:38 +0100 Subject: [PATCH 04/14] WP_Subtitle->current_user_can_edit() should be public. --- includes/subtitle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/subtitle.php b/includes/subtitle.php index 0b2c730..f1b95c3 100644 --- a/includes/subtitle.php +++ b/includes/subtitle.php @@ -151,7 +151,7 @@ private function get_supported_post_types() { * * @return boolean */ - private function current_user_can_edit() { + public function current_user_can_edit() { // Check supported post type if ( $this->is_supported_post_type() ) { From 3ecf7f08adfa11a5e128b3f35fbcc12cd1d82626 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Mon, 5 Sep 2016 16:42:56 +0100 Subject: [PATCH 05/14] Allow subtitle to contain HTML - same as main post title. --- admin/admin.php | 2 +- includes/subtitle.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/admin.php b/admin/admin.php index 2ad9cca..67a1b7e 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -259,7 +259,7 @@ public static function _add_subtitle_field() { echo ''; echo '
'; echo '
'; - echo ''; + echo ''; echo '
'; // Description diff --git a/includes/subtitle.php b/includes/subtitle.php index fa8b36f..852deec 100644 --- a/includes/subtitle.php +++ b/includes/subtitle.php @@ -91,7 +91,7 @@ public function get_raw_subtitle() { */ public function update_subtitle( $subtitle ) { - return update_post_meta( $this->post_id, $this->get_post_meta_key(), wp_kses_post( $subtitle ) ); + return update_post_meta( $this->post_id, $this->get_post_meta_key(), $subtitle ); } From 85431b3617f2ea54faf0ebfce96ab76ecf902b77 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Mon, 5 Sep 2016 18:05:53 +0100 Subject: [PATCH 06/14] Add `default_subtitle` filter like the WordPress `default_title` filter. --- admin/admin.php | 12 +++++++++++- includes/subtitle.php | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/admin/admin.php b/admin/admin.php index b56f004..b2fd6c5 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -256,10 +256,20 @@ public static function _add_subtitle_field() { $subtitle = new WP_Subtitle( $post ); + $value = $subtitle->get_raw_subtitle(); + + // Default subtitle + if ( function_exists( 'get_current_screen' ) && empty( $value ) ) { + $screen = get_current_screen(); + if ( isset( $screen->action ) && 'add' == $screen->action ) { + $value = $subtitle->get_default_subtitle( $post ); + } + } + echo ''; echo '
'; echo '
'; - echo ''; + echo ''; echo '
'; // Description diff --git a/includes/subtitle.php b/includes/subtitle.php index 9769ae2..d7eda05 100644 --- a/includes/subtitle.php +++ b/includes/subtitle.php @@ -83,6 +83,17 @@ public function get_raw_subtitle() { } + /** + * Get Default Subtitle + * + * @return string Default title. + */ + public function get_default_subtitle() { + + return apply_filters( 'default_subtitle', '', $this->post_id ); + + } + /** * Update Subtitle * From 3b361a1250ac05c37ec088aed1546d45bea7d06e Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Wed, 7 Sep 2016 10:44:17 +0100 Subject: [PATCH 07/14] Allow subtitle to contain HTML in old meta box. --- admin/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/admin.php b/admin/admin.php index 67a1b7e..836066d 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -237,7 +237,7 @@ public static function _add_subtitle_meta_box() { $subtitle = new WP_Subtitle( $post ); echo ''; - echo ''; + echo ''; echo apply_filters( 'wps_subtitle_field_description', '', $post ); } From c9e72de9264508dbb9222b8f4f35880db4ced124 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Wed, 7 Sep 2016 10:47:52 +0100 Subject: [PATCH 08/14] Enable default subtitle on old subtitle meta box. --- admin/admin.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/admin/admin.php b/admin/admin.php index e4c0d56..1f60da0 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -236,8 +236,18 @@ public static function _add_subtitle_meta_box() { $subtitle = new WP_Subtitle( $post ); + $value = $subtitle->get_raw_subtitle(); + + // Default subtitle + if ( function_exists( 'get_current_screen' ) && empty( $value ) ) { + $screen = get_current_screen(); + if ( isset( $screen->action ) && 'add' == $screen->action ) { + $value = $subtitle->get_default_subtitle( $post ); + } + } + echo ''; - echo ''; + echo ''; echo apply_filters( 'wps_subtitle_field_description', '', $post ); } From 1956d1691e150694fe708a277671963350053dd2 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Wed, 7 Sep 2016 11:05:38 +0100 Subject: [PATCH 09/14] Add private WPSubtitle_Admin::get_admin_subtitle_value() method. --- admin/admin.php | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/admin/admin.php b/admin/admin.php index 1f60da0..72ff4b5 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -234,17 +234,7 @@ public static function _add_subtitle_meta_box() { global $post; - $subtitle = new WP_Subtitle( $post ); - - $value = $subtitle->get_raw_subtitle(); - - // Default subtitle - if ( function_exists( 'get_current_screen' ) && empty( $value ) ) { - $screen = get_current_screen(); - if ( isset( $screen->action ) && 'add' == $screen->action ) { - $value = $subtitle->get_default_subtitle( $post ); - } - } + $value = self::get_admin_subtitle_value( $post ); echo ''; echo ''; @@ -264,17 +254,7 @@ public static function _add_subtitle_field() { global $post; - $subtitle = new WP_Subtitle( $post ); - - $value = $subtitle->get_raw_subtitle(); - - // Default subtitle - if ( function_exists( 'get_current_screen' ) && empty( $value ) ) { - $screen = get_current_screen(); - if ( isset( $screen->action ) && 'add' == $screen->action ) { - $value = $subtitle->get_default_subtitle( $post ); - } - } + $value = self::get_admin_subtitle_value( $post ); echo ''; echo '
'; @@ -290,6 +270,30 @@ public static function _add_subtitle_field() { echo '
'; } + /** + * Get Admin Subtitle Value + * + * @param WP_Post $post Post object. + * @return string Subtitle value. + */ + private function get_admin_subtitle_value( $post ) { + + $subtitle = new WP_Subtitle( $post ); + + $value = $subtitle->get_raw_subtitle(); + + // Default subtitle if adding new post + if ( function_exists( 'get_current_screen' ) && empty( $value ) ) { + $screen = get_current_screen(); + if ( isset( $screen->action ) && 'add' == $screen->action ) { + $value = $subtitle->get_default_subtitle( $post ); + } + } + + return $value; + + } + /** * Save Subtitle * From c5e780d9bfed4c42bb740fa1a976ee6a8fd8daca Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Wed, 7 Sep 2016 11:08:52 +0100 Subject: [PATCH 10/14] Add field placeholder to old admin meta box. --- admin/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/admin.php b/admin/admin.php index 72ff4b5..4acbb73 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -237,7 +237,7 @@ public static function _add_subtitle_meta_box() { $value = self::get_admin_subtitle_value( $post ); echo ''; - echo ''; + echo ''; echo apply_filters( 'wps_subtitle_field_description', '', $post ); } From fb368fbfbf1572291fe3b42607053b529dbb1261 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Wed, 7 Sep 2016 11:38:08 +0100 Subject: [PATCH 11/14] Add @since docblocks. --- admin/admin.php | 3 +++ includes/subtitle.php | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/admin/admin.php b/admin/admin.php index 4acbb73..13bfeaf 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -273,6 +273,9 @@ public static function _add_subtitle_field() { /** * Get Admin Subtitle Value * + * @since 2.8 + * @internal + * * @param WP_Post $post Post object. * @return string Subtitle value. */ diff --git a/includes/subtitle.php b/includes/subtitle.php index d7eda05..87aa0c3 100644 --- a/includes/subtitle.php +++ b/includes/subtitle.php @@ -86,6 +86,8 @@ public function get_raw_subtitle() { /** * Get Default Subtitle * + * @since 2.8 + * * @return string Default title. */ public function get_default_subtitle() { @@ -135,6 +137,8 @@ private function is_supported_post_type() { /** * Get Supported Post Types * + * @since 2.7 + * * @return array Array of supported post types. */ private function get_supported_post_types() { @@ -160,6 +164,8 @@ private function get_supported_post_types() { /** * Current User Can Edit * + * @since 2.8 + * * @return boolean */ public function current_user_can_edit() { From 67f38ca0b583d64dea15f855b40eba6de1177649 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Wed, 7 Sep 2016 11:41:38 +0100 Subject: [PATCH 12/14] Use plugin prefix for default subtitle filter `wps_default_subtitle`. --- includes/subtitle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/subtitle.php b/includes/subtitle.php index d7eda05..19b7105 100644 --- a/includes/subtitle.php +++ b/includes/subtitle.php @@ -90,7 +90,7 @@ public function get_raw_subtitle() { */ public function get_default_subtitle() { - return apply_filters( 'default_subtitle', '', $this->post_id ); + return apply_filters( 'wps_default_subtitle', '', $this->post_id ); } From 3a3cd4b8a21591a3e4fea6676cb6f0eab6246578 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Wed, 7 Sep 2016 11:49:14 +0100 Subject: [PATCH 13/14] Update changelog and readme. --- CHANGELOG.md | 12 +++++++++++- README.md | 3 +++ readme.txt | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 931cb34..52298d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [2.8] - 2016-09-07 + +### Added +- Add `wps_default_subtitle` filter. + +### Changed +- Allow subtitle to contain HTML (same as main post title ). +- Use WP_Subtitle class to validate saving of subtitle in the admin. + ## [2.7.1] - 2016-08-05 ### Fixed @@ -110,7 +119,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - First version. -[Unreleased]: https://github.com/benhuson/wp-subtitle/compare/2.7.1...HEAD +[Unreleased]: https://github.com/benhuson/wp-subtitle/compare/2.8...HEAD +[2.8]: https://github.com/benhuson/wp-subtitle/compare/2.7.1...2.8 [2.7.1]: https://github.com/benhuson/wp-subtitle/compare/2.7...2.7.1 [2.7]: https://github.com/benhuson/wp-subtitle/compare/2.6...2.7 [2.6]: https://github.com/benhuson/wp-subtitle/compare/2.5...2.6 diff --git a/README.md b/README.md index ba08b6f..d2cda37 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu Upgrade Notice -------------- +### 2.8 +Allow subtitle to contain HTML (same as main post title ) and add `wps_default_subtitle` filter. + ### 2.7.1 Fix incorrect post ID reference preventing subtitle from saving. diff --git a/readme.txt b/readme.txt index ebb2b96..1d2ce94 100644 --- a/readme.txt +++ b/readme.txt @@ -100,6 +100,11 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu == Changelog == += 2.8 = +* 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. + = 2.7.1 = * Fix incorrect post ID reference preventing subtitle from saving. @@ -162,6 +167,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu == Upgrade Notice == += 2.8 = +Allow subtitle to contain HTML (same as main post title ) and add `wps_default_subtitle` filter. + = 2.7.1 = Fix incorrect post ID reference preventing subtitle from saving. From f9034d5124085c7902822528cdc52457afd905ab Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Wed, 7 Sep 2016 11:49:42 +0100 Subject: [PATCH 14/14] Version 2.8 --- readme.txt | 2 +- wp-subtitle.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index 1d2ce94..5d822d4 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i Tags: subtitle, content, title, subheading, subhead, alternate title Requires at least: 3.7 Tested up to: 4.6 -Stable tag: 2.7.1 +Stable tag: 2.8 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.txt diff --git a/wp-subtitle.php b/wp-subtitle.php index b346e1c..d481b60 100644 --- a/wp-subtitle.php +++ b/wp-subtitle.php @@ -4,7 +4,7 @@ Plugin Name: WP Subtitle Plugin URI: http://wordpress.org/plugins/wp-subtitle/ Description: Adds a subtitle field to pages and posts. Possible to add support for custom post types. -Version: 2.7.1 +Version: 2.8 Author: Ben Huson, Husani Oakley Author URI: https://github.com/benhuson/wp-subtitle License: GPLv2