Skip to content

Commit

Permalink
Merge branch 'release/2.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
benhuson committed Sep 7, 2016
2 parents 61db1bc + f9034d5 commit 3301559
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 31 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
71 changes: 44 additions & 27 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ public static function _add_subtitle_meta_box() {

global $post;

$subtitle = new WP_Subtitle( $post );
$value = self::get_admin_subtitle_value( $post );

echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( $subtitle->get_raw_subtitle() ) . '" style="width:99%;" />';
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%;" />';
echo apply_filters( 'wps_subtitle_field_description', '', $post );
}

Expand All @@ -254,12 +254,12 @@ public static function _add_subtitle_field() {

global $post;

$subtitle = new WP_Subtitle( $post );
$value = self::get_admin_subtitle_value( $post );

echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
echo '<div id="subtitlediv" class="top">';
echo '<div id="subtitlewrap">';
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' ) ) ) . '" />';
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' ) ) ) . '" />';
echo '</div>';

// Description
Expand All @@ -270,6 +270,33 @@ public static function _add_subtitle_field() {
echo '</div>';
}

/**
* Get Admin Subtitle Value
*
* @since 2.8
* @internal
*
* @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
*
Expand All @@ -293,47 +320,37 @@ 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_id );
$subtitle->update_subtitle( $_POST['wps_subtitle'] );

if ( $subtitle->current_user_can_edit() ) {
$subtitle->update_subtitle( $_POST['wps_subtitle'] );
}

}

}

/**
* 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.
* @return bool
*/
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;
}

/**
Expand Down
59 changes: 58 additions & 1 deletion includes/subtitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ public function get_raw_subtitle() {

}

/**
* Get Default Subtitle
*
* @since 2.8
*
* @return string Default title.
*/
public function get_default_subtitle() {

return apply_filters( 'wps_default_subtitle', '', $this->post_id );

}

/**
* Update Subtitle
*
Expand All @@ -91,7 +104,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 );

}

Expand Down Expand Up @@ -124,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() {
Expand All @@ -146,4 +161,46 @@ private function get_supported_post_types() {

}

/**
* Current User Can Edit
*
* @since 2.8
*
* @return boolean
*/
public 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;

}

}
10 changes: 9 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion wp-subtitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3301559

Please sign in to comment.