diff --git a/CHANGELOG.md b/CHANGELOG.md index d7bfec4..f7a2732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/README.md b/README.md index b5b6933..052977e 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 -------------- +### 3.0 +Make `wps_subtitle` available via WordPress REST API. + ### 2.9.1 Fix preview not rendering correct template and other post meta. diff --git a/includes/rest.php b/includes/rest.php new file mode 100644 index 0000000..80ffaec --- /dev/null +++ b/includes/rest.php @@ -0,0 +1,68 @@ + 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(); + + } + +} diff --git a/readme.txt b/readme.txt index 92f7c23..e4c2858 100644 --- a/readme.txt +++ b/readme.txt @@ -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 @@ -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. @@ -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. diff --git a/wp-subtitle.php b/wp-subtitle.php index f1c9105..f2fa698 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.9.1 +Version: 3.0 Author: Ben Huson, Husani Oakley Author URI: https://github.com/benhuson/wp-subtitle License: GPLv2 @@ -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() ) { @@ -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 @@ -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 *