Skip to content

Commit

Permalink
Merge branch 'release/3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
benhuson committed Sep 6, 2017
2 parents a7320c5 + 9930ec1 commit 473dfce
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 4 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [3.0] - 2017-09-05

### Added
- Make `wps_subtitle` available via WordPress REST API.

## [2.9.1] - 2017-06-01

### Fixed
Expand Down Expand Up @@ -137,7 +142,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- First version.

[Unreleased]: https://github.com/benhuson/wp-subtitle/compare/2.9.1...HEAD
[Unreleased]: https://github.com/benhuson/wp-subtitle/compare/3.0...HEAD
[3.0]: https://github.com/benhuson/wp-subtitle/compare/2.9.2...3.0
[2.9.1]: https://github.com/benhuson/wp-subtitle/compare/2.9...2.9.1
[2.9]: https://github.com/benhuson/wp-subtitle/compare/2.8.1...2.9
[2.8.1]: https://github.com/benhuson/wp-subtitle/compare/2.8...2.8.1
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
--------------

### 3.0
Make `wps_subtitle` available via WordPress REST API.

### 2.9.1
Fix preview not rendering correct template and other post meta.

Expand Down
68 changes: 68 additions & 0 deletions includes/rest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* @package WP Subtitle
* @subpackage REST API
*
* @since 3.0
*/

class WPSubtitle_REST {

/**
* Constructor
*
* @since 3.0
*
* @internal Do not create multiple instances.
*/
public function __construct() {

add_action( 'rest_api_init', array( $this, 'register_rest_field' ) );

}

/**
* Register REST Field
*
* @since 3.0
*
* @internal Called via the `rest_api_init` action.
*/
public function register_rest_field() {

$post_types = WPSubtitle::get_supported_post_types();

foreach ( $post_types as $post_type ) {

register_rest_field( $post_types, 'wps_subtitle', array(
'get_callback' => array( $this, 'get_rest_field' ),
'update_callback' => null,
'schema' => null
) );

}

}

/**
* Get REST Field
*
* @since 3.0
*
* @internal Called via register_rest_field() callback.
*
* @param array $object Current post details.
* @param string $field_name Name of field.
* @param WP_REST_Request $request Current request.
* @return string Subtitle
*/
public function get_rest_field( $object, $field_name, $request ) {

$subtitle = new WP_Subtitle( $object['id'] );

return $subtitle->get_raw_subtitle();

}

}
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: husobj, husani
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SLZUF4XJTS4E6
Tags: subtitle, content, title, subheading, subhead, alternate title
Requires at least: 3.7
Tested up to: 4.7.5
Stable tag: 2.9.1
Tested up to: 4.8.1
Stable tag: 3.0
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.txt

Expand Down Expand Up @@ -102,6 +102,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu

= Unreleased =

= 3.0 =
* Make `wps_subtitle` available via WordPress REST API.

= 2.9.1 =
* Fix preview not rendering correct template and other post meta.

Expand Down Expand Up @@ -179,6 +182,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu

== Upgrade Notice ==

= 3.0 =
* Make `wps_subtitle` available via WordPress REST API.

= 2.9.1 =
Fix preview not rendering correct template and other post meta.

Expand Down
24 changes: 23 additions & 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.9.1
Version: 3.0
Author: Ben Huson, Husani Oakley
Author URI: https://github.com/benhuson/wp-subtitle
License: GPLv2
Expand Down Expand Up @@ -41,6 +41,7 @@
include_once( WPSUBTITLE_DIR . 'includes/subtitle.php' );
include_once( WPSUBTITLE_DIR . 'includes/deprecated.php' );
include_once( WPSUBTITLE_DIR . 'includes/shortcode.php' );
include_once( WPSUBTITLE_DIR . 'includes/rest.php' );

// Include admin-only functionality
if ( is_admin() ) {
Expand All @@ -52,6 +53,7 @@
}
}

add_action( 'plugins_loaded', array( 'WPSubtitle', 'load' ) );
add_action( 'init', array( 'WPSubtitle', '_add_default_post_type_support' ), 5 );

// Default subtitle filters
Expand All @@ -60,6 +62,26 @@

class WPSubtitle {

/**
* REST API
*
* @since 3.0
*
* @var WPSubtitle_REST|null
*/
private static $rest = null;

/**
* Load
*
* @since 3.0
*/
public static function load() {

self::$rest = new WPSubtitle_REST();

}

/**
* Add Default Post Type Support
*
Expand Down

0 comments on commit 473dfce

Please sign in to comment.