Skip to content

Commit

Permalink
Merge branch 'release/3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
benhuson committed Feb 8, 2020
2 parents c8aec83 + 263de36 commit 211fb64
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 30 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.4] - 2020-01-31
- Added support for the SEOPress plugin. Props @chriselkins.
- You can now update the subtitle via the REST API. Props @chriselkins.

## [3.3.1] - 2020-01-29

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

[Unreleased]: https://github.com/benhuson/wp-subtitle/compare/3.3.1...HEAD
[Unreleased]: https://github.com/benhuson/wp-subtitle/compare/3.4...HEAD
[3.3.1]: https://github.com/benhuson/wp-subtitle/compare/3.3.1...3.4
[3.3.1]: https://github.com/benhuson/wp-subtitle/compare/3.3...3.3.1
[3.3]: https://github.com/benhuson/wp-subtitle/compare/3.2...3.3
[3.2]: https://github.com/benhuson/wp-subtitle/compare/3.1...3.2
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ Subtitles can automatically be added to your WooCommerce products without needin
- Display the subtitle on single product pages
- Display the subtitle on product archives (category pages)

### Yoast SEO Plugin Support
### Yoast SEO and SEOPress Plugin Support

The plugin allows you to include the subtitle in your Yoast SEO meta titles and descriptions.
The plugin allows you to include the subtitle in your meta titles and descriptions via the [Yoast SEO](https://wordpress.org/plugins/wordpress-seo/) and [SEOPress](https://wordpress.org/plugins/wp-seopress/) plugins.

Similar to the Yoast `%%title%%` placeholder which inserts the post title, you can use `%%wps_subtitle%%`.

There are also addition placeholders and filters to allow to to customize seperators for the subtitle.

For more information, [view the Yoast SEO documentation here](https://github.com/benhuson/wp-subtitle/wiki/Yoast-SEO-Plugin-Support).
For more information, [view the SEO support documentation here](https://github.com/benhuson/wp-subtitle/wiki/Yoast-SEO-Plugin-Support).

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

### 3.4
Added support for the SEOPress plugin and updating the subtitle via the REST API.

### 3.3.1
Fixed broken closing H2 tag for WooCommerce subtitle.

Expand Down
2 changes: 1 addition & 1 deletion plugin/admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public static function _save_post( $post_id ) {
// Check data and save
if ( isset( $_POST['wps_subtitle'] ) ) {

$new_value = $_POST['wps_subtitle'];
$new_value = wp_kses_post( $_POST['wps_subtitle'] );

$subtitle = new WP_Subtitle( $post_id );

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

/**
* @package WP Subtitle
* @subpackage SEOPress
*
* @since 3.4
*
* Compatibility for the SEOPress plugin:
* https://wordpress.org/plugins/wp-seopress/
*
* Adds support for a `%%wps_subtitle%%` placeholder to include
* the subtitle in browser titles and meta descriptions.
*
* Also adds `%%wps_subtitle_before_sep%%` and `%%wps_subtitle_after_sep%%`.
* These can be used to add seperators before/after the subtitle. If there
* is no subtitle set these placeholders will not be output.
*
* The seperator placeholders can be customized using the `wps_subtitle_seo_before_sep`
* and `wps_subtitle_seo_after_sep` filters.
*
* The seperator placeholders include a 'space' either side by default. This means that
* you should create your title template with no whitespace around the seperator placeholders.
* It allows you to customize the seperators to include commas and butt the seperator up to
* the preceding/following text.
*
* e.g. If '%%wps_subtitle_before_sep%%' is set to ', ':
* `%%title%%%%wps_subtitle_before_sep%%%%wps_subtitle%% %%sep%% %%sitename%%`
* "Title, Subtitle - Sitename"
*/

class WPSubtitle_SEOPress {

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

add_filter( 'seopress_titles_template_variables_array', array( $this, 'add_seopress_replacements' ) );
add_filter( 'seopress_titles_template_replace_array', array( $this, 'replace_seopress_replacements' ) );

}

/**
* Add SEOPress Replacements Variables
*
* @since 3.4
*
* @param array $replacements SEO replacements variables.
* @return array Filtered replacements variables.
*
* @internal Called via the `seopress_titles_template_variables_array` filter.
*/
public function add_seopress_replacements( $replacements ) {

$replacements[] = '%%wps_subtitle%%';
$replacements[] = '%%wps_subtitle_before_sep%%';
$replacements[] = '%%wps_subtitle_after_sep%%';

return $replacements;

}

/**
* Replace SEOPress Replacements Values
*
* @since 3.4
*
* @param array $replacements SEO replacements values.
* @return array Filtered replacements values.
*
* @internal Called via the `seopress_titles_template_replace_array` filter.
*/
public function replace_seopress_replacements( $replacements ) {

global $post;

$wp_subtitle = new WP_Subtitle( $post );
$subtitle = $wp_subtitle->get_subtitle();

$replacements[] = $subtitle;

$sep = ' ' . $replacements[0] . ' ';

$before_sep = '';
$after_sep = '';

if ( ! empty( $subtitle ) ) {

$before_sep = apply_filters( 'wps_subtitle_seo_before_sep', $sep );
$after_sep = apply_filters( 'wps_subtitle_seo_after_sep', $sep );

}

$replacements[] = $before_sep;
$replacements[] = $after_sep;

return $replacements;

}

}
18 changes: 17 additions & 1 deletion plugin/includes/rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function register_rest_field() {

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

Expand Down Expand Up @@ -65,4 +65,20 @@ public function get_rest_field( $object, $field_name, $request ) {

}

/**
* Update REST Field
*
* @since 3.4
*
* @internal Called via register_rest_field() callback.
*
* @param string $value New value for the field.
* @param array $object Current post details.
*/
public function update_rest_field( $value, $object ) {

update_post_meta( $object->ID, 'wps_subtitle', wp_kses_post( $value ) );

}

}
Binary file modified plugin/languages/wp-subtitle-de_DE.mo
Binary file not shown.
43 changes: 36 additions & 7 deletions plugin/languages/wp-subtitle-de_DE.po
Original file line number Diff line number Diff line change
@@ -1,34 +1,63 @@
msgid ""
msgstr ""
"Project-Id-Version: WP Subtitle\n"
"POT-Creation-Date: 2015-07-02 06:57-0000\n"
"POT-Creation-Date: 2020-01-31 09:28+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: me <me@fake.it>\n"
"Language-Team: \n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.7.3\n"
"X-Generator: Poedit 2.2.4\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;_x;_ex\n"
"X-Poedit-Basepath: .\n"
"Language: de_DE\n"
"X-Poedit-SearchPath-0: ..\n"

#: ../admin/admin.php:79 ../admin/admin.php:150
#: plugin/admin/admin.php:109 plugin/admin/admin.php:203
#: plugin/admin/admin.php:274
msgid "Subtitle"
msgstr "Untertitel"

#: ../admin/admin.php:200
#: plugin/admin/admin.php:317 plugin/admin/admin.php:344
msgid "Enter subtitle here"
msgstr "Untertitel hier eingeben"

#: ../admin/pointers.php:146
#: plugin/admin/pointers.php:149
#, php-format
msgid "%s Field"
msgstr "%sfeld"

#: ../admin/pointers.php:147
#: plugin/admin/pointers.php:150
msgid "This field has moved from a meta box to below the post title."
msgstr "Dieses Feld wurde aus einer Metabox unter den Beitragstitel verschoben."

#: plugin/includes/compat/woocommerce.php:102
#, fuzzy
#| msgid "Subtitle"
msgid "WP Subtitle"
msgstr "Untertitel"

#: plugin/includes/compat/woocommerce.php:109
msgid "Enable Product Subtitles"
msgstr ""

#: plugin/includes/compat/woocommerce.php:110
msgid "Add subtitle field to product edit screen"
msgstr ""

#: plugin/includes/compat/woocommerce.php:117
#, fuzzy
#| msgid "Subtitle"
msgid "Subtitle Display"
msgstr "Untertitel"

#: plugin/includes/compat/woocommerce.php:118
msgid "Show on single product pages"
msgstr ""

#: plugin/includes/compat/woocommerce.php:126
msgid "Show on product archives"
msgstr ""
23 changes: 11 additions & 12 deletions plugin/languages/wp-subtitle.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
msgid ""
msgstr ""
"Project-Id-Version: WP Subtitle\n"
"POT-Creation-Date: 2018-12-19 23:04+0000\n"
"POT-Creation-Date: 2020-01-31 09:28+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: Ben Huson <ben@thewhiteroom.net>\n"
"Language-Team: \n"
Expand All @@ -11,19 +11,18 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.2\n"
"X-Generator: Poedit 2.2.4\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c\n"
"X-Poedit-Basepath: ../..\n"
"X-Poedit-SearchPath-0: .\n"

#: plugin/admin/admin.php:99 plugin/admin/admin.php:130
#: plugin/admin/admin.php:138 plugin/admin/admin.php:191
#: plugin/admin/admin.php:262
#: plugin/admin/admin.php:109 plugin/admin/admin.php:203
#: plugin/admin/admin.php:274
msgid "Subtitle"
msgstr ""

#: plugin/admin/admin.php:305 plugin/admin/admin.php:332
#: plugin/admin/admin.php:317 plugin/admin/admin.php:344
msgid "Enter subtitle here"
msgstr ""

Expand All @@ -36,26 +35,26 @@ msgstr ""
msgid "This field has moved from a meta box to below the post title."
msgstr ""

#: plugin/includes/compat/woocommerce.php:96
#: plugin/includes/compat/woocommerce.php:102
msgid "WP Subtitle"
msgstr ""

#: plugin/includes/compat/woocommerce.php:103
#: plugin/includes/compat/woocommerce.php:109
msgid "Enable Product Subtitles"
msgstr ""

#: plugin/includes/compat/woocommerce.php:104
#: plugin/includes/compat/woocommerce.php:110
msgid "Add subtitle field to product edit screen"
msgstr ""

#: plugin/includes/compat/woocommerce.php:111
#: plugin/includes/compat/woocommerce.php:117
msgid "Subtitle Display"
msgstr ""

#: plugin/includes/compat/woocommerce.php:112
#: plugin/includes/compat/woocommerce.php:118
msgid "Show on single product pages"
msgstr ""

#: plugin/includes/compat/woocommerce.php:120
#: plugin/includes/compat/woocommerce.php:126
msgid "Show on product archives"
msgstr ""
11 changes: 11 additions & 0 deletions plugin/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
include_once( WPSUBTITLE_DIR . 'includes/shortcode.php' );
include_once( WPSUBTITLE_DIR . 'includes/rest.php' );
include_once( WPSUBTITLE_DIR . 'includes/compat/wordpress-seo.php' );
include_once( WPSUBTITLE_DIR . 'includes/compat/seopress.php' );
include_once( WPSUBTITLE_DIR . 'includes/compat/woocommerce.php' );

// Include admin-only functionality
Expand Down Expand Up @@ -64,6 +65,15 @@ class WPSubtitle {
*/
private static $wpseo = null;

/**
* SEOPress (plugin compatibility)
*
* @since 3.4
*
* @var WPSubtitle_SEOPress|null
*/
private static $seopress = null;

/**
* WooCommerce
*
Expand All @@ -83,6 +93,7 @@ public static function load() {
self::$api = new WP_Subtitle_API();
self::$rest = new WPSubtitle_REST();
self::$wpseo = new WPSubtitle_WPSEO();
self::$seopress = new WPSubtitle_SEOPress();
self::$woocommerce = new WPSubtitle_WooCommerce();

self::$api->setup_hooks();
Expand Down
Loading

0 comments on commit 211fb64

Please sign in to comment.