WP Subtitle - Version 3.3

Version Description

  • New API for displaying the subtitle using do_action( 'plugins/wp_subtitle/the_subtitle' ).
  • New API for getting the subtitle using apply_filters( 'plugins/wp_subtitle/get_subtitle', '' ).
  • Admin column title now matches the meta box title if altered using the wps_meta_box_title filter.
Download this release

Release Info

Developer husobj
Plugin Icon 128x128 WP Subtitle
Version 3.3
Comparing to
See all releases

Code changes from version 3.2 to 3.3

CHANGELOG.md CHANGED
@@ -2,7 +2,14 @@
2
  All notable changes to this project will be documented in this file.
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
 
5
- ## [Unreleased]
 
 
 
 
 
 
 
6
 
7
  ## [3.2] - 2018-12-10
8
 
@@ -156,7 +163,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
156
  ### Added
157
  - First version.
158
 
159
- [Unreleased]: https://github.com/benhuson/wp-subtitle/compare/3.2...HEAD
 
160
  [3.2]: https://github.com/benhuson/wp-subtitle/compare/3.1...3.2
161
  [3.1]: https://github.com/benhuson/wp-subtitle/compare/3.0...3.1
162
  [3.0]: https://github.com/benhuson/wp-subtitle/compare/2.9.2...3.0
2
  All notable changes to this project will be documented in this file.
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
 
5
+ ## [3.3] - 2019-09-04
6
+
7
+ ### Changed
8
+ - New API for displaying the subtitle using `do_action( 'plugins/wp_subtitle/the_subtitle' )`.
9
+ - New API for getting the subtitle using `apply_filters( 'plugins/wp_subtitle/get_subtitle', '' )`.
10
+
11
+ ### Fixed
12
+ - Admin column title now matches the meta box title if altered using the `wps_meta_box_title` filter.
13
 
14
  ## [3.2] - 2018-12-10
15
 
163
  ### Added
164
  - First version.
165
 
166
+ [Unreleased]: https://github.com/benhuson/wp-subtitle/compare/3.3...HEAD
167
+ [3.3]: https://github.com/benhuson/wp-subtitle/compare/3.2...3.3
168
  [3.2]: https://github.com/benhuson/wp-subtitle/compare/3.1...3.2
169
  [3.1]: https://github.com/benhuson/wp-subtitle/compare/3.0...3.1
170
  [3.0]: https://github.com/benhuson/wp-subtitle/compare/2.9.2...3.0
README.md CHANGED
@@ -5,54 +5,102 @@ Add subtitles (subheadings) to your pages, posts or custom post types.
5
 
6
  The WP Subtitle plugin allows your pages and posts to contain a subtitle. Also called a sub-heading, this this short line of text is meant to appear beneath a post's (or page's) title, but can be inserted in your template wherever you choose.
7
 
8
- `<?php the_subtitle(); ?>` is used for inside The Loop. If you wish to get a page/post's subtitle outside The Loop, use `<?php get_the_subtitle( $post ); ?>`, where $post is a post object or ID ($post->ID).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  ### Parameters
11
 
12
- Just like WP's built-in `<?php the_title(); ?>` method, `<?php the_subtitle(); ?>` tag accepts three parameters:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- **$before**
15
- *(string)* Text to place before the subtitle. Defaults to "".
16
 
17
- **$after**
18
- *(string)* Text to place after the subtitle. Defaults to "".
19
 
20
- **$echo**
21
- *(boolean)* If true, display the subtitle in HTML. If false, return the subtitle for use in PHP. Defaults to true.
22
 
23
- Things are slightly different in `<?php get_the_subtitle(); ?>`:
24
 
25
- **$post**
26
- *(int|object)* Post, page or custom post type object or ID.
 
27
 
28
- **$before**
29
- *(string)* Text to place before the subtitle. Defaults to "".
30
 
31
- **$after**
32
- *(string)* Text to place after the subtitle. Defaults to "".
33
 
34
- **$echo**
35
- *(boolean)* If true, display the subtitle in HTML. If false, return the subtitle for use in PHP. Defaults to true.
36
 
37
- For full details on the template tags and their arguments, [view the documentation here](https://github.com/benhuson/wp-subtitle/wiki).
38
 
39
- By default, subtitle are supported by both posts and pages. To add support for custom post types use add_post_type_support( 'my_post_type', 'wps_subtitle' ).
40
 
41
  Installation
42
  ------------
43
 
44
  1. Upload the WP Subtitle plugin to your WordPress site in the `/wp-content/plugins` folder or install via the WordPress admin.
45
  1. Activate it from the Wordpress plugin admin screen.
46
- 1. Edit your page and/or post template and use the `<?php the_subtitle(); ?>` template tag where you'd like the subtitle to appear.
47
 
48
- For full details on the template tags and their arguments, [view the documentation here](https://github.com/benhuson/wp-subtitle/wiki).
49
 
50
  Frequently Asked Questions
51
  --------------------------
52
 
53
  __What does WP Subtitle do?__
54
 
55
- The plugin adds a Subtitle field when editing posts or pages. The subtitle is stores as a custom field (post meta data) and can be output using template tags.
56
 
57
  __Where does WP Subtitle store the subtitles?__
58
 
@@ -60,7 +108,7 @@ All subtitles are stored as post meta data. Deactivating this plugin will not re
60
 
61
  __Compatibility with WordPress 5.0+__
62
 
63
- In the new editor in WordPress 5.0 the subtitle is editable via ap panel in the sidebar (like excerpts).
64
 
65
  __How do I add the subtitle to my pages?__
66
 
@@ -68,14 +116,14 @@ Refer to [the documentation](https://github.com/benhuson/wp-subtitle/wiki).
68
 
69
  __How do I add support for custom post types?__
70
 
71
- To add support for custom post types use add_post_type_support( 'my_post_type', 'wps_subtitle' ):
72
 
73
- `
74
  function my_wp_subtitle_page_part_support() {
75
  add_post_type_support( 'my_post_type', 'wps_subtitle' );
76
  }
77
  add_action( 'init', 'my_wp_subtitle_page_part_support' );
78
- `
79
 
80
  __Where can I get help?__
81
 
@@ -92,7 +140,8 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
92
  Upgrade Notice
93
  --------------
94
 
95
- ### Unreleased
 
96
 
97
  ### 3.2
98
  Fix WordPress 5.0 compatibility.
5
 
6
  The WP Subtitle plugin allows your pages and posts to contain a subtitle. Also called a sub-heading, this this short line of text is meant to appear beneath a post's (or page's) title, but can be inserted in your template wherever you choose.
7
 
8
+ The subtitle can be inserted into your theme template files (or plugin) using the following API:
9
+
10
+ ### Display The Subtitle
11
+
12
+ All parameters are optional. If 'post_id' is omitted then the current post ID in the loop is used.
13
+
14
+ PHP Code:
15
+
16
+ ```
17
+ do_action( 'plugins/wp_subtitle/the_subtitle', array(
18
+ 'before' => '<p class="subtitle">',
19
+ 'after' => '</p>',
20
+ 'post_id' => get_the_ID(),
21
+ 'default_value' => ''
22
+ ) );
23
+ ```
24
+
25
+ Output:
26
+
27
+ `<p class="subtitle">My Post Subtitle</p>`
28
+
29
+ ### Get The Subtitle
30
+
31
+ All parameters are optional. If 'post_id' is omitted then the current post ID in the loop is used.
32
+
33
+ A default value can be supplied as the second parameter for `apply_filters`. This will be used if the post does not have a subtitle. Leave as an empty string to return an empty string if the post does not have a subtitle.
34
+
35
+ PHP Code:
36
+
37
+ ```
38
+ $subtitle = apply_filters( 'plugins/wp_subtitle/get_subtitle', '', array(
39
+ 'before' => '<p class="subtitle">',
40
+ 'after' => '</p>',
41
+ 'post_id' => get_the_ID()
42
+ ) );
43
+ ```
44
+
45
+ Result:
46
+
47
+ `$subtitle = '<p class="subtitle">My Post Subtitle</p>'`
48
 
49
  ### Parameters
50
 
51
+ The array of arguments accepted for the `plugins/wp_subtitle/the_subtitle` action and `plugins/wp_subtitle/get_subtitle` filter are:
52
+
53
+ **before**
54
+ *(string)* Text to place before the subtitle if one exists. Defaults to an empty string.
55
+
56
+ **after**
57
+ *(string)* Text to place after the subtitle if one exists. Defaults to to an empty string.
58
+
59
+ **post_id**
60
+ *(integer)* Post, page or custom post type ID.
61
+
62
+ **default_value**
63
+ *(string)* Only used by the `plugins/wp_subtitle/the_subtitle` action, allows you to specify a default subtitle to display if the post does not have one. For the `plugins/wp_subtitle/get_subtitle` filter the second parameter of `apply_filters` should be used instead. Defaults to to an empty string.
64
+
65
+ ### Post Type Support
66
 
67
+ By default, subtitle are supported by both posts and pages. To add support for custom post types add teh following to your theme functions file or plugin:
 
68
 
69
+ `add_post_type_support( 'my_post_type', 'wps_subtitle' )`
 
70
 
71
+ ### WooCommerce Plugin Support
 
72
 
73
+ Subtitles can automatically be added to your WooCommerce products without needing to make template changes. In the admin go to WooCommerce > Settings > Products where you can choose to:
74
 
75
+ - Enable Product Subtitles
76
+ - Display the subtitle on single product pages
77
+ - Display the subtitle on product archives (category pages)
78
 
79
+ ### Yoast SEO Plugin Support
 
80
 
81
+ The plugin allows you to include the subtitle in your Yoast SEO meta titles and descriptions.
 
82
 
83
+ Similar to the Yoast `%%title%%` placeholder which inserts the post title, you can use `%%wps_subtitle%%`.
 
84
 
85
+ There are also addition placeholders and filters to allow to to customize seperators for the subtitle.
86
 
87
+ For more information, [view the Yoast SEO documentation here](https://github.com/benhuson/wp-subtitle/wiki/Yoast-SEO-Plugin-Support).
88
 
89
  Installation
90
  ------------
91
 
92
  1. Upload the WP Subtitle plugin to your WordPress site in the `/wp-content/plugins` folder or install via the WordPress admin.
93
  1. Activate it from the Wordpress plugin admin screen.
94
+ 1. Use the API to display the subtitle in your theme.
95
 
96
+ For full details on the API and how to display the subtitle, [view the documentation here](https://github.com/benhuson/wp-subtitle/wiki).
97
 
98
  Frequently Asked Questions
99
  --------------------------
100
 
101
  __What does WP Subtitle do?__
102
 
103
+ The plugin adds a Subtitle field when editing posts, pages or custom post types. The subtitle is stored as a custom field (post meta data) and can be output using API actions and filters.
104
 
105
  __Where does WP Subtitle store the subtitles?__
106
 
108
 
109
  __Compatibility with WordPress 5.0+__
110
 
111
+ In the new editor in WordPress 5.0 the subtitle is editable via a panel in the sidebar (like excerpts).
112
 
113
  __How do I add the subtitle to my pages?__
114
 
116
 
117
  __How do I add support for custom post types?__
118
 
119
+ To add support for custom post types add the following to your theme functions file or plugin:
120
 
121
+ ```
122
  function my_wp_subtitle_page_part_support() {
123
  add_post_type_support( 'my_post_type', 'wps_subtitle' );
124
  }
125
  add_action( 'init', 'my_wp_subtitle_page_part_support' );
126
+ ```
127
 
128
  __Where can I get help?__
129
 
140
  Upgrade Notice
141
  --------------
142
 
143
+ ### 3.3
144
+ New API for getting and displaying the subtitle using `do_action( 'plugins/wp_subtitle/the_subtitle' )` and `apply_filters( 'plugins/wp_subtitle/get_subtitle', '' )`. Please see the documentation.
145
 
146
  ### 3.2
147
  Fix WordPress 5.0 compatibility.
includes/deprecated.php DELETED
@@ -1,72 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * @package WP Subtitle
5
- * @subpackage Deprecated Functions
6
- */
7
-
8
- /**
9
- * Query DB and echo page/post subtitle, if any
10
- *
11
- * @uses WPSubtitle::_get_post_meta()
12
- *
13
- * @since 1.0
14
- * @deprecated 2.0 Use get_the_subtitle() instead.
15
- */
16
- function wps_get_the_subtitle() {
17
- _deprecated_function( 'wps_get_the_subtitle()', '2.0', 'the_subtitle()' );
18
-
19
- $subtitle = new WP_Subtitle( get_the_ID() );
20
- $subtitle->the_subtitle();
21
-
22
- }
23
-
24
- /**
25
- * Display XHTML for subtitle panel
26
- *
27
- * @since 1.0
28
- * @deprecated 2.0 Legacy function.
29
- */
30
- function wps_addPanelXHTML() {
31
- _deprecated_function( 'wps_addPanelXHTML()', '2.0' );
32
- }
33
-
34
- /**
35
- * Include CSS for subtitle panel
36
- *
37
- * @since 1.0
38
- * @deprecated 2.0 Legacy function.
39
- */
40
- function wps_addPanelCSS() {
41
- _deprecated_function( 'wps_addPanelCSS()', '2.0' );
42
- }
43
-
44
- /**
45
- * Include XHTML for form inside panel
46
- *
47
- * @since 1.0
48
- * @deprecated 2.0 Legacy function.
49
- */
50
- function wps_showSubtitlePanel() {
51
- _deprecated_function( 'wps_addPanelCSS()', '2.0' );
52
- }
53
-
54
- /**
55
- * For pre-2.5, include shell for panel
56
- *
57
- * @since 1.0
58
- * @deprecated 2.0 Legacy function.
59
- */
60
- function wps_showSubtitlePanelOld() {
61
- _deprecated_function( 'wps_showSubtitlePanelOld()', '2.0' );
62
- }
63
-
64
- /**
65
- * Store subtitle content in db as custom field
66
- *
67
- * @since 1.0
68
- * @deprecated 2.0 Legacy function.
69
- */
70
- function wps_saveSubtitle( $post_id ) {
71
- _deprecated_function( 'wps_saveSubtitle()', '2.0' );
72
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
{admin → plugin/admin}/admin.php RENAMED
@@ -38,18 +38,7 @@ class WPSubtitle_Admin {
38
  */
39
  public static function _admin_init() {
40
 
41
- global $pagenow;
42
-
43
- // Get post type
44
- $post_type = '';
45
-
46
- if ( isset( $_REQUEST['post_type'] ) ) {
47
- $post_type = sanitize_text_field( $_REQUEST['post_type'] );
48
- } elseif ( isset( $_GET['post'] ) ) {
49
- $post_type = get_post_type( absint( $_GET['post'] ) );
50
- } elseif ( in_array( $pagenow, array( 'post-new.php', 'edit.php' ) ) ) {
51
- $post_type = 'post';
52
- }
53
 
54
  // Setup Field / Meta Box
55
  if ( WPSubtitle::is_supported_post_type( $post_type ) ) {
@@ -74,6 +63,27 @@ class WPSubtitle_Admin {
74
 
75
  }
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  /**
78
  * Add subtitle input to quick edit.
79
  *
@@ -125,9 +135,11 @@ class WPSubtitle_Admin {
125
  $after_column = 'name';
126
  }
127
 
 
 
128
  // Add column
129
  if ( empty( $after_column ) ) {
130
- $columns['wps_subtitle'] = __( 'Subtitle', 'wp-subtitle' );
131
  return $columns;
132
  }
133
 
@@ -135,7 +147,7 @@ class WPSubtitle_Admin {
135
  foreach ( $columns as $column => $value ) {
136
  $new_columns[ $column ] = $value;
137
  if ( $after_column == $column ) {
138
- $new_columns['wps_subtitle'] = __( 'Subtitle', 'wp-subtitle' );
139
  }
140
  }
141
 
38
  */
39
  public static function _admin_init() {
40
 
41
+ $post_type = self::get_admin_page_post_type();
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  // Setup Field / Meta Box
44
  if ( WPSubtitle::is_supported_post_type( $post_type ) ) {
63
 
64
  }
65
 
66
+ /**
67
+ * Get Admin Page Post Type
68
+ *
69
+ * @return string
70
+ */
71
+ protected static function get_admin_page_post_type() {
72
+
73
+ global $pagenow;
74
+
75
+ if ( isset( $_REQUEST['post_type'] ) ) {
76
+ return sanitize_text_field( $_REQUEST['post_type'] );
77
+ } elseif ( isset( $_GET['post'] ) ) {
78
+ return get_post_type( absint( $_GET['post'] ) );
79
+ } elseif ( in_array( $pagenow, array( 'post-new.php', 'edit.php' ) ) ) {
80
+ return 'post';
81
+ }
82
+
83
+ return '';
84
+
85
+ }
86
+
87
  /**
88
  * Add subtitle input to quick edit.
89
  *
135
  $after_column = 'name';
136
  }
137
 
138
+ $column_name = self::get_meta_box_title( self::get_admin_page_post_type() );
139
+
140
  // Add column
141
  if ( empty( $after_column ) ) {
142
+ $columns['wps_subtitle'] = $column_name;
143
  return $columns;
144
  }
145
 
147
  foreach ( $columns as $column => $value ) {
148
  $new_columns[ $column ] = $value;
149
  if ( $after_column == $column ) {
150
+ $new_columns['wps_subtitle'] = $column_name;
151
  }
152
  }
153
 
{admin → plugin/admin}/js/admin-edit.js RENAMED
File without changes
{admin → plugin/admin}/js/pointers.js RENAMED
File without changes
{admin → plugin/admin}/pointers.php RENAMED
File without changes
plugin/includes/class-api.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package WP Subtitle
5
+ * @subpackage API Class
6
+ *
7
+ * Usage examples below. All parameters are optional.
8
+ *
9
+ * // Example: Display subtitle
10
+ * do_action( 'plugins/wp_subtitle/the_subtitle', array(
11
+ * 'before' => '<p class="subtitle">', // Before subtitle HTML output (default empty string)
12
+ * 'after' => '</p>', // After subtitle HTML output (default empty string)
13
+ * 'post_id' => get_the_ID(), // Post ID (default current post ID)
14
+ * 'default_value' => '' // Default output (if no subtitle)
15
+ * ) );
16
+ *
17
+ * // Example: Get subtitle display
18
+ * $subtitle = apply_filters( 'plugins/wp_subtitle/get_subtitle', '', array(
19
+ * 'before' => '<p class="subtitle">', // Before subtitle HTML output (default empty string)
20
+ * 'after' => '</p>', // After subtitle HTML output (default empty string)
21
+ * 'post_id' => get_the_ID() // Post ID (default current post ID)
22
+ * ) );
23
+ */
24
+
25
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
26
+
27
+ class WP_Subtitle_API {
28
+
29
+ /**
30
+ * Setup Hooks
31
+ */
32
+ public function setup_hooks() {
33
+
34
+ add_action( 'plugins/wp_subtitle/the_subtitle', array( $this, 'the_subtitle' ) );
35
+ add_filter( 'plugins/wp_subtitle/get_subtitle', array( $this, 'get_subtitle' ), 10, 2 );
36
+
37
+ }
38
+
39
+ /**
40
+ * The Subtitle
41
+ *
42
+ * @param array $args Display args.
43
+ *
44
+ * @internal Private. Called via the `the_subtitle` action.
45
+ */
46
+ public function the_subtitle( $args = '' ) {
47
+
48
+ $default_value = isset( $args['default_value'] ) ? $args['default_value'] : '';
49
+
50
+ echo $this->get_subtitle( $default_value, $args );
51
+
52
+ }
53
+
54
+ /**
55
+ * Get Subtitle
56
+ *
57
+ * @param string $default_subtitle Default/fallback subtitle.
58
+ * @param array $args Display args.
59
+ * @return string The subtitle.
60
+ *
61
+ * @internal Private. Called via the `get_subtitle` action.
62
+ */
63
+ public function get_subtitle( $default_subtitle, $args = '' ) {
64
+
65
+ $args = wp_parse_args( $args, array(
66
+ 'post_id' => get_the_ID(), // Post ID
67
+ 'before' => '', // Before subtitle HTML output
68
+ 'after' => '' // After subtitle HTML output
69
+ ) );
70
+
71
+ $subtitle_obj = new WP_Subtitle( $args['post_id'] );
72
+ $subtitle = $subtitle_obj->get_subtitle( $args );
73
+
74
+ if ( ! empty( $subtitle ) ) {
75
+ return $subtitle;
76
+ }
77
+
78
+ return $default_subtitle;
79
+
80
+ }
81
+
82
+ }
{includes → plugin/includes}/compat/woocommerce.php RENAMED
@@ -61,7 +61,10 @@ class WPSubtitle_WooCommerce {
61
  */
62
  public function single_product_summary() {
63
 
64
- the_subtitle( '<h2 class="product_subtitle entry-subtitle wp-subtitle">', '</h2>' );
 
 
 
65
 
66
  }
67
 
@@ -74,7 +77,10 @@ class WPSubtitle_WooCommerce {
74
  */
75
  public function shop_loop_item_title() {
76
 
77
- the_subtitle( '<p class="woocommerce-loop-product__subtitle wp-subtitle">', '</p>' );
 
 
 
78
 
79
  }
80
 
61
  */
62
  public function single_product_summary() {
63
 
64
+ do_action( 'plugins/wp_subtitle/the_subtitle', array(
65
+ 'before' => '<h2 class="product_subtitle entry-subtitle wp-subtitle">',
66
+ 'after' => '</p>'
67
+ ) );
68
 
69
  }
70
 
77
  */
78
  public function shop_loop_item_title() {
79
 
80
+ do_action( 'plugins/wp_subtitle/the_subtitle', array(
81
+ 'before' => '<p class="woocommerce-loop-product__subtitle wp-subtitle">',
82
+ 'after' => '</p>'
83
+ ) );
84
 
85
  }
86
 
{includes → plugin/includes}/compat/wordpress-seo.php RENAMED
File without changes
plugin/includes/deprecated.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package WP Subtitle
5
+ * @subpackage Deprecated Functions
6
+ */
7
+
8
+ /**
9
+ * The Subtitle
10
+ *
11
+ * @since 1.0
12
+ * @deprecated 3.3 Use do_action( 'plugins/wp_subtitle/the_subtitle' ) instead.
13
+ *
14
+ * @uses WP_Subtitle::get_subtitle()
15
+ *
16
+ * @param string $before Before the subtitle.
17
+ * @param string $after After the subtitle.
18
+ * @param bool $echo Output if true, return if false.
19
+ * @return string The subtitle string.
20
+ */
21
+ function the_subtitle( $before = '', $after = '', $echo = true ) {
22
+
23
+ if ( ! $echo ) {
24
+
25
+ return apply_filters( 'plugins/wp_subtitle/get_subtitle', '', array(
26
+ 'before' => $before,
27
+ 'after' => $after
28
+ ) );
29
+
30
+ }
31
+
32
+ do_action( 'plugins/wp_subtitle/the_subtitle', array(
33
+ 'before' => $before,
34
+ 'after' => $after
35
+ ) );
36
+
37
+ }
38
+
39
+ /**
40
+ * Get the Subtitle
41
+ *
42
+ * @since 1.0
43
+ * @deprecated 3.3 Use apply_filters( 'plugins/wp_subtitle/get_subtitle' ) instead.
44
+ *
45
+ * @uses WP_Subtitle::get_subtitle()
46
+ *
47
+ * @param int|object $post Post ID or object.
48
+ * @param string $before Before the subtitle.
49
+ * @param string $after After the subtitle.
50
+ * @param bool $echo Output if true, return if false.
51
+ * @return string The subtitle string.
52
+ */
53
+ function get_the_subtitle( $post = 0, $before = '', $after = '', $echo = true ) {
54
+
55
+ $output = apply_filters( 'plugins/wp_subtitle/get_subtitle', '', array(
56
+ 'post_id' => is_a( $post, 'WP_Post' ) ? $post->ID : $post,
57
+ 'before' => $before,
58
+ 'after' => $after
59
+ ) );
60
+
61
+ if ( ! $echo ) {
62
+ return $output;
63
+ }
64
+
65
+ echo $output;
66
+
67
+ }
68
+
69
+ /**
70
+ * Query DB and echo page/post subtitle, if any
71
+ *
72
+ * @uses WPSubtitle::_get_post_meta()
73
+ *
74
+ * @since 1.0
75
+ * @deprecated 2.0 Use get_the_subtitle() instead.
76
+ */
77
+ function wps_get_the_subtitle() {
78
+ _deprecated_function( 'wps_get_the_subtitle()', '2.0', "do_action( 'plugins/wp_subtitle/the_subtitle' )" );
79
+
80
+ $subtitle = new WP_Subtitle( get_the_ID() );
81
+ $subtitle->the_subtitle();
82
+
83
+ }
84
+
85
+ /**
86
+ * Display XHTML for subtitle panel
87
+ *
88
+ * @since 1.0
89
+ * @deprecated 2.0 Legacy function.
90
+ */
91
+ function wps_addPanelXHTML() {
92
+ _deprecated_function( 'wps_addPanelXHTML()', '2.0' );
93
+ }
94
+
95
+ /**
96
+ * Include CSS for subtitle panel
97
+ *
98
+ * @since 1.0
99
+ * @deprecated 2.0 Legacy function.
100
+ */
101
+ function wps_addPanelCSS() {
102
+ _deprecated_function( 'wps_addPanelCSS()', '2.0' );
103
+ }
104
+
105
+ /**
106
+ * Include XHTML for form inside panel
107
+ *
108
+ * @since 1.0
109
+ * @deprecated 2.0 Legacy function.
110
+ */
111
+ function wps_showSubtitlePanel() {
112
+ _deprecated_function( 'wps_addPanelCSS()', '2.0' );
113
+ }
114
+
115
+ /**
116
+ * For pre-2.5, include shell for panel
117
+ *
118
+ * @since 1.0
119
+ * @deprecated 2.0 Legacy function.
120
+ */
121
+ function wps_showSubtitlePanelOld() {
122
+ _deprecated_function( 'wps_showSubtitlePanelOld()', '2.0' );
123
+ }
124
+
125
+ /**
126
+ * Store subtitle content in db as custom field
127
+ *
128
+ * @since 1.0
129
+ * @deprecated 2.0 Legacy function.
130
+ */
131
+ function wps_saveSubtitle( $post_id ) {
132
+ _deprecated_function( 'wps_saveSubtitle()', '2.0' );
133
+ }
{includes → plugin/includes}/rest.php RENAMED
File without changes
{includes → plugin/includes}/shortcode.php RENAMED
File without changes
{includes → plugin/includes}/subtitle.php RENAMED
File without changes
{languages → plugin/languages}/wp-subtitle-de_DE.mo RENAMED
File without changes
{languages → plugin/languages}/wp-subtitle-de_DE.po RENAMED
File without changes
{languages → plugin/languages}/wp-subtitle.pot RENAMED
@@ -2,7 +2,7 @@
2
  msgid ""
3
  msgstr ""
4
  "Project-Id-Version: WP Subtitle\n"
5
- "POT-Creation-Date: 2017-12-14 08:21+0000\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Ben Huson <ben@thewhiteroom.net>\n"
8
  "Language-Team: \n"
@@ -11,50 +11,51 @@ msgstr ""
11
  "Content-Type: text/plain; charset=UTF-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
13
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
14
- "X-Generator: Poedit 2.0.2\n"
15
  "X-Poedit-SourceCharset: UTF-8\n"
16
- "X-Poedit-KeywordsList: __;_e;_x;_ex\n"
17
- "X-Poedit-Basepath: .\n"
18
- "X-Poedit-SearchPath-0: ..\n"
19
 
20
- #: ../admin/admin.php:130 ../admin/admin.php:138 ../admin/admin.php:191
21
- #: ../admin/admin.php:262
 
22
  msgid "Subtitle"
23
  msgstr ""
24
 
25
- #: ../admin/admin.php:301 ../admin/admin.php:328
26
  msgid "Enter subtitle here"
27
  msgstr ""
28
 
29
- #: ../admin/pointers.php:149
30
  #, php-format
31
  msgid "%s Field"
32
  msgstr ""
33
 
34
- #: ../admin/pointers.php:150
35
  msgid "This field has moved from a meta box to below the post title."
36
  msgstr ""
37
 
38
- #: ../includes/compat/woocommerce.php:96
39
  msgid "WP Subtitle"
40
  msgstr ""
41
 
42
- #: ../includes/compat/woocommerce.php:103
43
  msgid "Enable Product Subtitles"
44
  msgstr ""
45
 
46
- #: ../includes/compat/woocommerce.php:104
47
  msgid "Add subtitle field to product edit screen"
48
  msgstr ""
49
 
50
- #: ../includes/compat/woocommerce.php:111
51
  msgid "Subtitle Display"
52
  msgstr ""
53
 
54
- #: ../includes/compat/woocommerce.php:112
55
  msgid "Show on single product pages"
56
  msgstr ""
57
 
58
- #: ../includes/compat/woocommerce.php:120
59
  msgid "Show on product archives"
60
  msgstr ""
2
  msgid ""
3
  msgstr ""
4
  "Project-Id-Version: WP Subtitle\n"
5
+ "POT-Creation-Date: 2018-12-19 23:04+0000\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Ben Huson <ben@thewhiteroom.net>\n"
8
  "Language-Team: \n"
11
  "Content-Type: text/plain; charset=UTF-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
13
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
14
+ "X-Generator: Poedit 2.2\n"
15
  "X-Poedit-SourceCharset: UTF-8\n"
16
+ "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"
17
+ "X-Poedit-Basepath: ../..\n"
18
+ "X-Poedit-SearchPath-0: .\n"
19
 
20
+ #: plugin/admin/admin.php:99 plugin/admin/admin.php:130
21
+ #: plugin/admin/admin.php:138 plugin/admin/admin.php:191
22
+ #: plugin/admin/admin.php:262
23
  msgid "Subtitle"
24
  msgstr ""
25
 
26
+ #: plugin/admin/admin.php:305 plugin/admin/admin.php:332
27
  msgid "Enter subtitle here"
28
  msgstr ""
29
 
30
+ #: plugin/admin/pointers.php:149
31
  #, php-format
32
  msgid "%s Field"
33
  msgstr ""
34
 
35
+ #: plugin/admin/pointers.php:150
36
  msgid "This field has moved from a meta box to below the post title."
37
  msgstr ""
38
 
39
+ #: plugin/includes/compat/woocommerce.php:96
40
  msgid "WP Subtitle"
41
  msgstr ""
42
 
43
+ #: plugin/includes/compat/woocommerce.php:103
44
  msgid "Enable Product Subtitles"
45
  msgstr ""
46
 
47
+ #: plugin/includes/compat/woocommerce.php:104
48
  msgid "Add subtitle field to product edit screen"
49
  msgstr ""
50
 
51
+ #: plugin/includes/compat/woocommerce.php:111
52
  msgid "Subtitle Display"
53
  msgstr ""
54
 
55
+ #: plugin/includes/compat/woocommerce.php:112
56
  msgid "Show on single product pages"
57
  msgstr ""
58
 
59
+ #: plugin/includes/compat/woocommerce.php:120
60
  msgid "Show on product archives"
61
  msgstr ""
plugin/plugin.php ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package WP Subtitle
5
+ * @subpackage Plugin
6
+ */
7
+
8
+ // Plugin directory and url paths.
9
+ define( 'WPSUBTITLE_BASENAME', plugin_basename( __FILE__ ) );
10
+ define( 'WPSUBTITLE_SUBDIR', '/' . str_replace( basename( __FILE__ ), '', WPSUBTITLE_BASENAME ) );
11
+ define( 'WPSUBTITLE_URL', plugins_url( WPSUBTITLE_SUBDIR ) );
12
+ define( 'WPSUBTITLE_DIR', plugin_dir_path( __FILE__ ) );
13
+
14
+ // Includes
15
+ include_once( WPSUBTITLE_DIR . 'includes/class-api.php' );
16
+ include_once( WPSUBTITLE_DIR . 'includes/subtitle.php' );
17
+ include_once( WPSUBTITLE_DIR . 'includes/deprecated.php' );
18
+ include_once( WPSUBTITLE_DIR . 'includes/shortcode.php' );
19
+ include_once( WPSUBTITLE_DIR . 'includes/rest.php' );
20
+ include_once( WPSUBTITLE_DIR . 'includes/compat/wordpress-seo.php' );
21
+ include_once( WPSUBTITLE_DIR . 'includes/compat/woocommerce.php' );
22
+
23
+ // Include admin-only functionality
24
+ if ( is_admin() ) {
25
+ require_once( WPSUBTITLE_DIR . 'admin/admin.php' );
26
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
27
+ // Load AJAX functions here if required...
28
+ } else {
29
+ require_once( WPSUBTITLE_DIR . 'admin/pointers.php' );
30
+ }
31
+ }
32
+
33
+ add_action( 'plugins_loaded', array( 'WPSubtitle', 'load' ) );
34
+ add_action( 'init', array( 'WPSubtitle', '_add_default_post_type_support' ), 5 );
35
+
36
+ // Default subtitle filters
37
+ add_filter( 'wps_subtitle', 'wptexturize' );
38
+ add_filter( 'wps_subtitle', 'trim' );
39
+
40
+ class WPSubtitle {
41
+
42
+ /**
43
+ * API
44
+ *
45
+ * @var WP_Subtitle_API|null
46
+ */
47
+ private static $api = null;
48
+
49
+ /**
50
+ * REST API
51
+ *
52
+ * @since 3.1
53
+ *
54
+ * @var WPSubtitle_REST|null
55
+ */
56
+ private static $rest = null;
57
+
58
+ /**
59
+ * WP SEO (plugin compatibility)
60
+ *
61
+ * @since 3.1
62
+ *
63
+ * @var WPSubtitle_WPSEO|null
64
+ */
65
+ private static $wpseo = null;
66
+
67
+ /**
68
+ * WooCommerce
69
+ *
70
+ * @since 3.1
71
+ *
72
+ * @var WPSubtitle_WooCommerce|null
73
+ */
74
+ private static $woocommerce = null;
75
+
76
+ /**
77
+ * Load
78
+ *
79
+ * @since 3.1
80
+ */
81
+ public static function load() {
82
+
83
+ self::$api = new WP_Subtitle_API();
84
+ self::$rest = new WPSubtitle_REST();
85
+ self::$wpseo = new WPSubtitle_WPSEO();
86
+ self::$woocommerce = new WPSubtitle_WooCommerce();
87
+
88
+ self::$api->setup_hooks();
89
+
90
+ }
91
+
92
+ /**
93
+ * Add Default Post Type Support
94
+ *
95
+ * @since 2.0
96
+ * @internal
97
+ */
98
+ public static function _add_default_post_type_support() {
99
+
100
+ add_post_type_support( 'page', 'wps_subtitle' );
101
+ add_post_type_support( 'post', 'wps_subtitle' );
102
+ add_post_type_support( 'revision', 'wps_subtitle' );
103
+
104
+ }
105
+
106
+ /**
107
+ * Get Supported Post Types
108
+ *
109
+ * @since 2.0
110
+ *
111
+ * @return array Array of supported post types.
112
+ */
113
+ public static function get_supported_post_types() {
114
+ $post_types = (array) get_post_types( array(
115
+ '_builtin' => false
116
+ ) );
117
+ $post_types = array_merge( $post_types, array( 'post', 'page', 'revision' ) );
118
+ $supported = array();
119
+ foreach ( $post_types as $post_type ) {
120
+ if ( post_type_supports( $post_type, 'wps_subtitle' ) ) {
121
+ $supported[] = $post_type;
122
+ }
123
+ }
124
+ return $supported;
125
+ }
126
+
127
+ /**
128
+ * Is Supported Post Type
129
+ *
130
+ * @since 2.3
131
+ *
132
+ * @param string $post_type Post Type.
133
+ * @return boolean
134
+ */
135
+ public static function is_supported_post_type( $post_type ) {
136
+ $post_types = self::get_supported_post_types();
137
+ if ( in_array( $post_type, $post_types ) ) {
138
+ return true;
139
+ }
140
+ return false;
141
+ }
142
+
143
+ /**
144
+ * Get the Subtitle
145
+ *
146
+ * @since 2.0
147
+ *
148
+ * @uses WP_Subtitle::get_subtitle()
149
+ *
150
+ * @param int|object $post Post ID or object.
151
+ * @return string The filtered subtitle meta value.
152
+ */
153
+ public static function get_the_subtitle( $post = 0 ) {
154
+
155
+ $subtitle = new WP_Subtitle( $post );
156
+
157
+ return $subtitle->get_subtitle();
158
+
159
+ }
160
+
161
+ /**
162
+ * Get Post Meta
163
+ *
164
+ * @since 2.0
165
+ * @internal
166
+ *
167
+ * @uses WP_Subtitle::get_raw_subtitle()
168
+ *
169
+ * @param int|object $post Post ID or object.
170
+ * @return string The subtitle meta value.
171
+ */
172
+ public static function _get_post_meta( $post = 0 ) {
173
+
174
+ $subtitle = new WP_Subtitle( $post );
175
+
176
+ return $subtitle->get_raw_subtitle();
177
+
178
+ }
179
+
180
+ /**
181
+ * Get Post Meta Key
182
+ *
183
+ * @since 2.5.x
184
+ * @internal
185
+ *
186
+ * @param int $post Post ID.
187
+ * @return string The subtitle meta key.
188
+ */
189
+ public static function _get_post_meta_key( $post_id = 0 ) {
190
+
191
+ return apply_filters( 'wps_subtitle_key', 'wps_subtitle', $post_id );
192
+
193
+ }
194
+
195
+ }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: husobj, husani
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SLZUF4XJTS4E6
4
  Tags: subtitle, content, title, subheading, subhead, alternate title
5
  Requires at least: 3.7
6
- Tested up to: 5.0
7
- Stable tag: 3.2
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
 
@@ -14,52 +14,100 @@ Add subtitles (subheadings) to your pages, posts or custom post types.
14
 
15
  The WP Subtitle plugin allows your pages and posts to contain a subtitle. Also called a sub-heading, this this short line of text is meant to appear beneath a post's (or page's) title, but can be inserted in your template wherever you choose.
16
 
17
- `<?php the_subtitle(); ?>` is used for inside The Loop. If you wish to get a page/post's subtitle outside The Loop, use `<?php get_the_subtitle( $post ); ?>`, where $post is a post object or ID ($post->ID).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  = Parameters =
20
 
21
- Just like WP's built-in `<?php the_title(); ?>` method, `<?php the_subtitle(); ?>` tag accepts three parameters:
 
 
 
22
 
23
- **$before**
24
- *(string)* Text to place before the subtitle. Defaults to "".
25
 
26
- **$after**
27
- *(string)* Text to place after the subtitle. Defaults to "".
28
 
29
- **$echo**
30
- *(boolean)* If true, display the subtitle in HTML. If false, return the subtitle for use in PHP. Defaults to true.
31
 
32
- Things are slightly different in `<?php get_the_subtitle(); ?>`:
33
 
34
- **$post**
35
- *(int|object)* Post, page or custom post type object or ID.
36
 
37
- **$before**
38
- *(string)* Text to place before the subtitle. Defaults to "".
39
 
40
- **$after**
41
- *(string)* Text to place after the subtitle. Defaults to "".
42
 
43
- **$echo**
44
- *(boolean)* If true, display the subtitle in HTML. If false, return the subtitle for use in PHP. Defaults to true.
45
 
46
- For full details on the template tags and their arguments, [view the documentation here](https://github.com/benhuson/wp-subtitle/wiki).
 
 
47
 
48
- By default, subtitle are supported by both posts and pages. To add support for custom post types use add_post_type_support( 'my_post_type', 'wps_subtitle' ).
 
 
 
 
 
 
 
 
49
 
50
  == Installation ==
51
 
52
  1. Upload the WP Subtitle plugin to your WordPress site in the `/wp-content/plugins` folder or install via the WordPress admin.
53
  2. Activate it from the Wordpress plugin admin screen.
54
- 3. Edit your page and/or post template and use the `<?php the_subtitle(); ?>` template tag where you'd like the subtitle to appear.
55
 
56
- For full details on the template tags and their arguments, [view the documentation here](https://github.com/benhuson/wp-subtitle/wiki).
57
 
58
  == Frequently Asked Questions ==
59
 
60
  = What does WP Subtitle do? =
61
 
62
- The plugin adds a Subtitle field when editing posts or pages. The subtitle is stores as a custom field (post meta data) and can be output using template tags.
63
 
64
  = Where does WP Subtitle store the subtitles? =
65
 
@@ -75,7 +123,7 @@ Refer to [the documentation](https://github.com/benhuson/wp-subtitle/wiki).
75
 
76
  = How do I add support for custom post types? =
77
 
78
- To add support for custom post types use add_post_type_support( 'my_post_type', 'wps_subtitle' ):
79
 
80
  `
81
  function my_wp_subtitle_page_part_support() {
@@ -98,13 +146,17 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
98
 
99
  == Screenshots ==
100
 
101
- 1. Edit post screen (WordPress 3.5+ and WP Title 2.2+)
102
- 1. Edit post screen (for earlier versions of WordPress or using the 'wps_subtitle_use_meta_box' filter)
103
- 2. A single page showing a subtitle
 
104
 
105
  == Changelog ==
106
 
107
- = Unreleased =
 
 
 
108
 
109
  = 3.2 =
110
  * Fix WordPress 5.0 compatibility - check `use_block_editor_for_post_type`.
@@ -195,6 +247,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
195
 
196
  == Upgrade Notice ==
197
 
 
 
 
198
  = 3.2 =
199
  Fix WordPress 5.0 compatibility.
200
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SLZUF4XJTS4E6
4
  Tags: subtitle, content, title, subheading, subhead, alternate title
5
  Requires at least: 3.7
6
+ Tested up to: 5.2
7
+ Stable tag: 3.3
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
 
14
 
15
  The WP Subtitle plugin allows your pages and posts to contain a subtitle. Also called a sub-heading, this this short line of text is meant to appear beneath a post's (or page's) title, but can be inserted in your template wherever you choose.
16
 
17
+ The subtitle can be inserted into your theme template files (or plugin) using the following API:
18
+
19
+ = Display The Subtitle =
20
+
21
+ All parameters are optional. If 'post_id' is omitted then the current post ID in the loop is used.
22
+
23
+ PHP Code:
24
+
25
+ `
26
+ do_action( 'plugins/wp_subtitle/the_subtitle', array(
27
+ 'before' => '<p class="subtitle">',
28
+ 'after' => '</p>',
29
+ 'post_id' => get_the_ID(),
30
+ 'default_value' => ''
31
+ ) );
32
+ `
33
+
34
+ Output:
35
+
36
+ `<p class="subtitle">My Post Subtitle</p>`
37
+
38
+ = Get The Subtitle =
39
+
40
+ All parameters are optional. If 'post_id' is omitted then the current post ID in the loop is used.
41
+
42
+ A default value can be supplied as the second parameter for `apply_filters`. This will be used if the post does not have a subtitle. Leave as an empty string to return an empty string if the post does not have a subtitle.
43
+
44
+ PHP Code:
45
+
46
+ `
47
+ $subtitle = apply_filters( 'plugins/wp_subtitle/get_subtitle', '', array(
48
+ 'before' => '<p class="subtitle">',
49
+ 'after' => '</p>',
50
+ 'post_id' => get_the_ID()
51
+ ) );
52
+ `
53
+
54
+ Result:
55
+
56
+ `$subtitle = '<p class="subtitle">My Post Subtitle</p>'`
57
 
58
  = Parameters =
59
 
60
+ The array of arguments accepted for the `plugins/wp_subtitle/the_subtitle` action and `plugins/wp_subtitle/get_subtitle` filter are:
61
+
62
+ **before**
63
+ *(string)* Text to place before the subtitle if one exists. Defaults to an empty string.
64
 
65
+ **after**
66
+ *(string)* Text to place after the subtitle if one exists. Defaults to to an empty string.
67
 
68
+ **post_id**
69
+ *(integer)* Post, page or custom post type ID.
70
 
71
+ **default_value**
72
+ *(string)* Only used by the `plugins/wp_subtitle/the_subtitle` action, allows you to specify a default subtitle to display if the post does not have one. For the `plugins/wp_subtitle/get_subtitle` filter the second parameter of `apply_filters` should be used instead. Defaults to to an empty string.
73
 
74
+ = Post Type Support =
75
 
76
+ By default, subtitle are supported by both posts and pages. To add support for custom post types add teh following to your theme functions file or plugin:
 
77
 
78
+ `add_post_type_support( 'my_post_type', 'wps_subtitle' )`
 
79
 
80
+ = WooCommerce Plugin Support =
 
81
 
82
+ Subtitles can automatically be added to your WooCommerce products without needing to make template changes. In the admin go to WooCommerce > Settings > Products where you can choose to:
 
83
 
84
+ - Enable Product Subtitles
85
+ - Display the subtitle on single product pages
86
+ - Display the subtitle on product archives (category pages)
87
 
88
+ = Yoast SEO Plugin Support =
89
+
90
+ The plugin allows you to include the subtitle in your Yoast SEO meta titles and descriptions.
91
+
92
+ Similar to the Yoast `%%title%%` placeholder which inserts the post title, you can use `%%wps_subtitle%%`.
93
+
94
+ There are also addition placeholders and filters to allow to to customize seperators for the subtitle.
95
+
96
+ For more information, [view the Yoast SEO documentation here](https://github.com/benhuson/wp-subtitle/wiki/Yoast-SEO-Plugin-Support).
97
 
98
  == Installation ==
99
 
100
  1. Upload the WP Subtitle plugin to your WordPress site in the `/wp-content/plugins` folder or install via the WordPress admin.
101
  2. Activate it from the Wordpress plugin admin screen.
102
+ 3. Use the API to display the subtitle in your theme.
103
 
104
+ For full details on the API and how to display the subtitle, [view the documentation here](https://github.com/benhuson/wp-subtitle/wiki).
105
 
106
  == Frequently Asked Questions ==
107
 
108
  = What does WP Subtitle do? =
109
 
110
+ The plugin adds a Subtitle field when editing posts, pages or custom post types. The subtitle is stored as a custom field (post meta data) and can be output using API actions and filters.
111
 
112
  = Where does WP Subtitle store the subtitles? =
113
 
123
 
124
  = How do I add support for custom post types? =
125
 
126
+ To add support for custom post types add the following to your theme functions file or plugin:
127
 
128
  `
129
  function my_wp_subtitle_page_part_support() {
146
 
147
  == Screenshots ==
148
 
149
+ 1. Edit post screen (WordPress 5.0+ and WP Title 3.1+)
150
+ 2. Edit post screen (WordPress 3.5+ and WP Title 2.2+)
151
+ 3. Edit post screen (for earlier versions of WordPress or using the 'wps_subtitle_use_meta_box' filter)
152
+ 4. A single page showing a subtitle
153
 
154
  == Changelog ==
155
 
156
+ = 3.3 =
157
+ * New API for displaying the subtitle using `do_action( 'plugins/wp_subtitle/the_subtitle' )`.
158
+ * New API for getting the subtitle using `apply_filters( 'plugins/wp_subtitle/get_subtitle', '' )`.
159
+ * Admin column title now matches the meta box title if altered using the `wps_meta_box_title` filter.
160
 
161
  = 3.2 =
162
  * Fix WordPress 5.0 compatibility - check `use_block_editor_for_post_type`.
247
 
248
  == Upgrade Notice ==
249
 
250
+ = 3.3 =
251
+ New API for getting and displaying the subtitle using `do_action( 'plugins/wp_subtitle/the_subtitle' )` and `apply_filters( 'plugins/wp_subtitle/get_subtitle', '' )`. Please see the documentation.
252
+
253
  = 3.2 =
254
  Fix WordPress 5.0 compatibility.
255
 
wp-subtitle.php CHANGED
@@ -4,13 +4,13 @@
4
  Plugin Name: WP Subtitle
5
  Plugin URI: http://wordpress.org/plugins/wp-subtitle/
6
  Description: Adds a subtitle field to pages and posts. Possible to add support for custom post types.
7
- Version: 3.2
8
  Author: Ben Huson, Husani Oakley
9
  Author URI: https://github.com/benhuson/wp-subtitle
10
  License: GPLv2
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
  Text Domain: wp-subtitle
13
- Domain Path: /languages
14
  */
15
 
16
  /*
@@ -31,239 +31,4 @@ along with this program; if not, write to the Free Software
31
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32
  */
33
 
34
- // Plugin directory and url paths.
35
- define( 'WPSUBTITLE_BASENAME', plugin_basename( __FILE__ ) );
36
- define( 'WPSUBTITLE_SUBDIR', '/' . str_replace( basename( __FILE__ ), '', WPSUBTITLE_BASENAME ) );
37
- define( 'WPSUBTITLE_URL', plugins_url( WPSUBTITLE_SUBDIR ) );
38
- define( 'WPSUBTITLE_DIR', plugin_dir_path( __FILE__ ) );
39
-
40
- // Includes
41
- include_once( WPSUBTITLE_DIR . 'includes/subtitle.php' );
42
- include_once( WPSUBTITLE_DIR . 'includes/deprecated.php' );
43
- include_once( WPSUBTITLE_DIR . 'includes/shortcode.php' );
44
- include_once( WPSUBTITLE_DIR . 'includes/rest.php' );
45
- include_once( WPSUBTITLE_DIR . 'includes/compat/wordpress-seo.php' );
46
- include_once( WPSUBTITLE_DIR . 'includes/compat/woocommerce.php' );
47
-
48
- // Include admin-only functionality
49
- if ( is_admin() ) {
50
- require_once( WPSUBTITLE_DIR . 'admin/admin.php' );
51
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
52
- // Load AJAX functions here if required...
53
- } else {
54
- require_once( WPSUBTITLE_DIR . 'admin/pointers.php' );
55
- }
56
- }
57
-
58
- add_action( 'plugins_loaded', array( 'WPSubtitle', 'load' ) );
59
- add_action( 'init', array( 'WPSubtitle', '_add_default_post_type_support' ), 5 );
60
-
61
- // Default subtitle filters
62
- add_filter( 'wps_subtitle', 'wptexturize' );
63
- add_filter( 'wps_subtitle', 'trim' );
64
-
65
- class WPSubtitle {
66
-
67
- /**
68
- * REST API
69
- *
70
- * @since 3.1
71
- *
72
- * @var WPSubtitle_REST|null
73
- */
74
- private static $rest = null;
75
-
76
- /**
77
- * WP SEO (plugin compatibility)
78
- *
79
- * @since 3.1
80
- *
81
- * @var WPSubtitle_WPSEO|null
82
- */
83
- private static $wpseo = null;
84
-
85
- /**
86
- * WooCommerce
87
- *
88
- * @since 3.1
89
- *
90
- * @var WPSubtitle_WooCommerce|null
91
- */
92
- private static $woocommerce = null;
93
-
94
- /**
95
- * Load
96
- *
97
- * @since 3.1
98
- */
99
- public static function load() {
100
-
101
- self::$rest = new WPSubtitle_REST();
102
- self::$wpseo = new WPSubtitle_WPSEO();
103
- self::$woocommerce = new WPSubtitle_WooCommerce();
104
-
105
- }
106
-
107
- /**
108
- * Add Default Post Type Support
109
- *
110
- * @since 2.0
111
- * @internal
112
- */
113
- public static function _add_default_post_type_support() {
114
-
115
- add_post_type_support( 'page', 'wps_subtitle' );
116
- add_post_type_support( 'post', 'wps_subtitle' );
117
- add_post_type_support( 'revision', 'wps_subtitle' );
118
-
119
- }
120
-
121
- /**
122
- * Get Supported Post Types
123
- *
124
- * @since 2.0
125
- *
126
- * @return array Array of supported post types.
127
- */
128
- public static function get_supported_post_types() {
129
- $post_types = (array) get_post_types( array(
130
- '_builtin' => false
131
- ) );
132
- $post_types = array_merge( $post_types, array( 'post', 'page', 'revision' ) );
133
- $supported = array();
134
- foreach ( $post_types as $post_type ) {
135
- if ( post_type_supports( $post_type, 'wps_subtitle' ) ) {
136
- $supported[] = $post_type;
137
- }
138
- }
139
- return $supported;
140
- }
141
-
142
- /**
143
- * Is Supported Post Type
144
- *
145
- * @since 2.3
146
- *
147
- * @param string $post_type Post Type.
148
- * @return boolean
149
- */
150
- public static function is_supported_post_type( $post_type ) {
151
- $post_types = self::get_supported_post_types();
152
- if ( in_array( $post_type, $post_types ) ) {
153
- return true;
154
- }
155
- return false;
156
- }
157
-
158
- /**
159
- * Get the Subtitle
160
- *
161
- * @since 2.0
162
- *
163
- * @uses WP_Subtitle::get_subtitle()
164
- *
165
- * @param int|object $post Post ID or object.
166
- * @return string The filtered subtitle meta value.
167
- */
168
- public static function get_the_subtitle( $post = 0 ) {
169
-
170
- $subtitle = new WP_Subtitle( $post );
171
-
172
- return $subtitle->get_subtitle();
173
-
174
- }
175
-
176
- /**
177
- * Get Post Meta
178
- *
179
- * @since 2.0
180
- * @internal
181
- *
182
- * @uses WP_Subtitle::get_raw_subtitle()
183
- *
184
- * @param int|object $post Post ID or object.
185
- * @return string The subtitle meta value.
186
- */
187
- public static function _get_post_meta( $post = 0 ) {
188
-
189
- $subtitle = new WP_Subtitle( $post );
190
-
191
- return $subtitle->get_raw_subtitle();
192
-
193
- }
194
-
195
- /**
196
- * Get Post Meta Key
197
- *
198
- * @since 2.5.x
199
- * @internal
200
- *
201
- * @param int $post Post ID.
202
- * @return string The subtitle meta key.
203
- */
204
- public static function _get_post_meta_key( $post_id = 0 ) {
205
-
206
- return apply_filters( 'wps_subtitle_key', 'wps_subtitle', $post_id );
207
-
208
- }
209
-
210
- }
211
-
212
- /**
213
- * The Subtitle
214
- *
215
- * @since 1.0
216
- *
217
- * @uses WP_Subtitle::get_subtitle()
218
- *
219
- * @param string $before Before the subtitle.
220
- * @param string $after After the subtitle.
221
- * @param bool $echo Output if true, return if false.
222
- * @return string The subtitle string.
223
- */
224
- function the_subtitle( $before = '', $after = '', $echo = true ) {
225
-
226
- $subtitle = new WP_Subtitle( get_the_ID() );
227
-
228
- $output = $subtitle->get_subtitle( array(
229
- 'before' => $before,
230
- 'after' => $after
231
- ) );
232
-
233
- if ( ! $echo ) {
234
- return $output;
235
- }
236
-
237
- echo $output;
238
-
239
- }
240
-
241
- /**
242
- * Get the Subtitle
243
- *
244
- * @since 1.0
245
- *
246
- * @uses WP_Subtitle::get_subtitle()
247
- *
248
- * @param int|object $post Post ID or object.
249
- * @param string $before Before the subtitle.
250
- * @param string $after After the subtitle.
251
- * @param bool $echo Output if true, return if false.
252
- * @return string The subtitle string.
253
- */
254
- function get_the_subtitle( $post = 0, $before = '', $after = '', $echo = true ) {
255
-
256
- $subtitle = new WP_Subtitle( $post );
257
-
258
- $output = $subtitle->get_subtitle( array(
259
- 'before' => $before,
260
- 'after' => $after
261
- ) );
262
-
263
- if ( ! $echo ) {
264
- return $output;
265
- }
266
-
267
- echo $output;
268
-
269
- }
4
  Plugin Name: WP Subtitle
5
  Plugin URI: http://wordpress.org/plugins/wp-subtitle/
6
  Description: Adds a subtitle field to pages and posts. Possible to add support for custom post types.
7
+ Version: 3.3
8
  Author: Ben Huson, Husani Oakley
9
  Author URI: https://github.com/benhuson/wp-subtitle
10
  License: GPLv2
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
  Text Domain: wp-subtitle
13
+ Domain Path: /plugin/languages
14
  */
15
 
16
  /*
31
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32
  */
33
 
34
+ require_once( plugin_dir_path( __FILE__ ) . 'plugin/plugin.php' );