WP Subtitle - Version 2.2

Version Description

  • Moved subtitle field from meta box to below title field in WordPress 3.5+ (props Tor Morten)
  • Added 'wps_subtitle_use_meta_box' filter to allow the edit field to be displayed in a meta box (the old way).
Download this release

Release Info

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

Code changes from version 2.1 to 2.2

admin/admin.php CHANGED
@@ -5,15 +5,82 @@
5
  * @subpackage Admin
6
  */
7
 
8
- // Language
9
- load_plugin_textdomain( 'wp-subtitle', false, dirname( WPSUBTITLE_BASENAME ) . '/languages' );
10
-
11
- // Includes
12
- add_action( 'add_meta_boxes', array( 'WPSubtitle_Admin', '_add_meta_boxes' ) );
13
- add_action( 'save_post', array( 'WPSubtitle_Admin', '_save_post' ) );
14
 
15
  class WPSubtitle_Admin {
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  /**
18
  * Add Meta Boxes
19
  *
@@ -27,8 +94,7 @@ class WPSubtitle_Admin {
27
  static function _add_meta_boxes() {
28
  $post_types = WPSubtitle::get_supported_post_types();
29
  foreach ( $post_types as $post_type ) {
30
- $meta_box_title = apply_filters( 'wps_meta_box_title', __( 'Subtitle', 'wp-subtitle' ), $post_type );
31
- add_meta_box( 'wps_subtitle_panel', __( $meta_box_title ), array( 'WPSubtitle_Admin', '_add_subtitle_meta_box' ), $post_type, 'normal', 'high' );
32
  }
33
  }
34
 
@@ -48,6 +114,31 @@ class WPSubtitle_Admin {
48
  echo apply_filters( 'wps_subtitle_field_description', '', $post );
49
  }
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  /**
52
  * Save Subtitle
53
  *
@@ -129,4 +220,21 @@ class WPSubtitle_Admin {
129
  return false;
130
  }
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  }
5
  * @subpackage Admin
6
  */
7
 
8
+ add_action( 'plugins_loaded', array( 'WPSubtitle_Admin', '_setup' ) );
 
 
 
 
 
9
 
10
  class WPSubtitle_Admin {
11
 
12
+ /**
13
+ * Setup
14
+ *
15
+ * @since 2.2
16
+ * @internal
17
+ */
18
+ static function _setup() {
19
+
20
+ // Language
21
+ load_plugin_textdomain( 'wp-subtitle', false, dirname( WPSUBTITLE_BASENAME ) . '/languages' );
22
+
23
+ // Setup Field / Meta Box
24
+ $post_type = isset( $_GET['post'] ) ? get_post_type( $_GET['post'] ) : '';
25
+ if ( WPSubtitle_Admin::edit_form_after_title_supported( $post_type ) ) {
26
+ add_action( 'admin_head', array( 'WPSubtitle_Admin', '_add_admin_styles' ) );
27
+ add_action( 'edit_form_after_title', array( 'WPSubtitle_Admin', '_add_subtitle_field' ) );
28
+ } else {
29
+ add_action( 'add_meta_boxes', array( 'WPSubtitle_Admin', '_add_meta_boxes' ) );
30
+ }
31
+
32
+ add_action( 'save_post', array( 'WPSubtitle_Admin', '_save_post' ) );
33
+ }
34
+
35
+ /**
36
+ * Add Admin Styles
37
+ *
38
+ * @since 2.2
39
+ * @internal
40
+ */
41
+ static function _add_admin_styles() {
42
+ ?>
43
+ <style>
44
+ #subtitlediv.top {
45
+ margin-bottom: 15px;
46
+ position: relative;
47
+ }
48
+ #subtitlediv.top #subtitlewrap {
49
+ border: 0;
50
+ padding: 0;
51
+ }
52
+ #subtitlediv.top #wpsubtitle {
53
+ background-color: #fff;
54
+ font-size: 1.4em;
55
+ line-height: 1em;
56
+ margin: 0;
57
+ outline: 0;
58
+ padding: 3px 8px;
59
+ width: 100%;
60
+ height: 1.7em;
61
+ }
62
+ #subtitlediv.top #wpsubtitle::-webkit-input-placeholder { padding-top: 3px; }
63
+ #subtitlediv.top #wpsubtitle:-moz-placeholder { padding-top: 3px; }
64
+ #subtitlediv.top #wpsubtitle::-moz-placeholder { padding-top: 3px; }
65
+ #subtitlediv.top #wpsubtitle:-ms-input-placeholder { padding-top: 3px; }
66
+ #subtitlediv.top #subtitledescription {
67
+ margin: 5px 10px 0 10px;
68
+ }
69
+ </style>
70
+ <?php
71
+ }
72
+
73
+ /**
74
+ * Get Meta Box Title
75
+ *
76
+ * @since 2.2
77
+ *
78
+ * @uses apply_filters( 'wps_meta_box_title' )
79
+ */
80
+ static function get_meta_box_title( $post_type ) {
81
+ return apply_filters( 'wps_meta_box_title', __( 'Subtitle', 'wp-subtitle' ), $post_type );
82
+ }
83
+
84
  /**
85
  * Add Meta Boxes
86
  *
94
  static function _add_meta_boxes() {
95
  $post_types = WPSubtitle::get_supported_post_types();
96
  foreach ( $post_types as $post_type ) {
97
+ add_meta_box( 'wps_subtitle_panel', WPSubtitle_Admin::get_meta_box_title( $post_type ), array( 'WPSubtitle_Admin', '_add_subtitle_meta_box' ), $post_type, 'normal', 'high' );
 
98
  }
99
  }
100
 
114
  echo apply_filters( 'wps_subtitle_field_description', '', $post );
115
  }
116
 
117
+ /**
118
+ * Add Subtitle Field
119
+ *
120
+ * @since 2.2
121
+ * @internal
122
+ *
123
+ * @uses WPSubtitle::_get_post_meta()
124
+ * @uses apply_filters( 'wps_subtitle_field_description' )
125
+ */
126
+ static function _add_subtitle_field() {
127
+ global $post;
128
+ echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
129
+ echo '<div id="subtitlediv" class="top">';
130
+ echo '<div id="subtitlewrap">';
131
+ echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . WPSubtitle::_get_post_meta( $post->ID ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', 'wp-subtitle' ) ) ) . '" />';
132
+ echo '</div>';
133
+
134
+ // Description
135
+ $description = apply_filters( 'wps_subtitle_field_description', '', $post );
136
+ if ( ! empty( $description ) ) {
137
+ echo '<div id="subtitledescription">' . $description . '</div>';
138
+ }
139
+ echo '</div>';
140
+ }
141
+
142
  /**
143
  * Save Subtitle
144
  *
220
  return false;
221
  }
222
 
223
+ /**
224
+ * edit_form_after_title Supported
225
+ *
226
+ * @since 2.2
227
+ *
228
+ * @param string $post_type Post type.
229
+ * @return bool
230
+ */
231
+ static function edit_form_after_title_supported( $post_type = '' ) {
232
+ global $wp_version;
233
+
234
+ if ( version_compare( $wp_version, '3.5', '<' ) ) {
235
+ return false;
236
+ }
237
+ return ! apply_filters( 'wps_subtitle_use_meta_box', false, $post_type );
238
+ }
239
+
240
  }
admin/js/pointers.js ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ /**
3
+ * @package WP Subtitle
4
+ * @subpackage JavaScript > Pointers
5
+ */
6
+
7
+ jQuery( document ).ready( function( $ ) {
8
+
9
+ function wps_subtitle_open_pointer( i ) {
10
+ pointer = wpsSubtitlePointer.pointers[ i ];
11
+ options = $.extend( pointer.options, {
12
+ close : function() {
13
+ $.post( ajaxurl, {
14
+ pointer : pointer.pointer_id,
15
+ action : 'dismiss-wp-pointer'
16
+ } );
17
+ }
18
+ });
19
+
20
+ $( pointer.target ).pointer( options ).pointer( 'open' );
21
+ }
22
+
23
+ wps_subtitle_open_pointer( 0 );
24
+
25
+ } );
admin/pointers.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @package WP Subtitle
5
+ * @subpackage Pointers
6
+ */
7
+
8
+ add_action( 'admin_init', array( 'WPSubtitle_Pointers', '_setup' ) );
9
+
10
+ class WPSubtitle_Pointers {
11
+
12
+ /**
13
+ * Setup
14
+ *
15
+ * @since 2.2
16
+ * @internal
17
+ */
18
+ static function _setup() {
19
+ add_action( 'admin_enqueue_scripts', array( 'WPSubtitle_Pointers', '_pointer_load' ) );
20
+
21
+ // Post Pointers
22
+ $post_types = WPSubtitle::get_supported_post_types();
23
+ foreach ( $post_types as $post_type ) {
24
+ add_filter( 'wps_subtitle_admin_pointers-' . $post_type, array( 'WPSubtitle_Pointers', '_post_type_pointers' ) );
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Load Pointers
30
+ *
31
+ * @since 2.2
32
+ * @internal
33
+ *
34
+ * @param string $hook_suffix Page hook.
35
+ */
36
+ static function _pointer_load( $hook_suffix ) {
37
+
38
+ // Don't run on WP < 3.3
39
+ if ( get_bloginfo( 'version' ) < '3.3' ) {
40
+ return;
41
+ }
42
+
43
+ // Get the screen ID
44
+ $screen = get_current_screen();
45
+ $screen_id = $screen->id;
46
+
47
+ // Get pointers for this screen
48
+ $pointers = apply_filters( 'wps_subtitle_admin_pointers-' . $screen_id, array() );
49
+
50
+ // No pointers? Then we stop.
51
+ if ( ! $pointers || ! is_array( $pointers ) ) {
52
+ return;
53
+ }
54
+
55
+ // Get dismissed pointers
56
+ $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
57
+ $valid_pointers = array();
58
+
59
+ // Check pointers and remove dismissed ones.
60
+ foreach ( $pointers as $pointer_id => $pointer ) {
61
+
62
+ // Sanity check
63
+ if ( in_array( $pointer_id, $dismissed ) || empty( $pointer ) || empty( $pointer_id ) || empty( $pointer['target'] ) || empty( $pointer['options'] ) ) {
64
+ continue;
65
+ }
66
+
67
+ $pointer['pointer_id'] = $pointer_id;
68
+
69
+ // Add the pointer to $valid_pointers array
70
+ $valid_pointers['pointers'][] = $pointer;
71
+ }
72
+
73
+ // No valid pointers? Stop here.
74
+ if ( empty( $valid_pointers ) ) {
75
+ return;
76
+ }
77
+
78
+ // Enqueue pointers.
79
+ wp_enqueue_style( 'wp-pointer' );
80
+
81
+ // Enqueue our pointers script.
82
+ wp_enqueue_script( 'wps-subtitle-pointer', plugins_url( 'js/pointers.js', __FILE__ ), array( 'wp-pointer' ) );
83
+
84
+ // Add pointer options.
85
+ wp_localize_script( 'wps-subtitle-pointer', 'wpsSubtitlePointer', $valid_pointers );
86
+
87
+ }
88
+
89
+ /**
90
+ * Post Type Pointers.
91
+ * The add pointers for multiple post types.
92
+ *
93
+ * @since 2.2
94
+ * @internal
95
+ *
96
+ * @param array $pointers Pointers.
97
+ * @return array Pointers.
98
+ */
99
+ static function _post_type_pointers( $pointers ) {
100
+
101
+ // Subtitle field moved to below the post title (v.2.2)
102
+ $pointers['wps_subtitle_field_to_top'] = array(
103
+ 'target' => '#subtitlewrap',
104
+ 'options' => array(
105
+ 'content' => sprintf( '<h3>%s</h3><p>%s</p>',
106
+ sprintf( __( '%s Field', 'wp-subtitle' ), WPSubtitle_Admin::get_meta_box_title( get_post_type( get_queried_object_id() ) ) ),
107
+ __( 'This field has moved from a meta box to below the post title.', 'wp-subtitle' )
108
+ ),
109
+ 'position' => array(
110
+ 'edge' => 'top',
111
+ 'align' => 'middle'
112
+ )
113
+ )
114
+ );
115
+
116
+ return $pointers;
117
+ }
118
+
119
+ }
languages/wp-subtitle.pot CHANGED
@@ -1,7 +1,7 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: WP Subtitle\n"
4
- "POT-Creation-Date: 2014-03-12 07:07-0000\n"
5
  "PO-Revision-Date: \n"
6
  "Last-Translator: Ben Huson <ben@thewhiteroom.net>\n"
7
  "Language-Team: \n"
@@ -16,6 +16,19 @@ msgstr ""
16
  "X-Poedit-Basepath: .\n"
17
  "X-Poedit-SearchPath-0: ..\n"
18
 
19
- #: ../admin/admin.php:30
20
  msgid "Subtitle"
21
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: WP Subtitle\n"
4
+ "POT-Creation-Date: 2014-07-02 21:25-0000\n"
5
  "PO-Revision-Date: \n"
6
  "Last-Translator: Ben Huson <ben@thewhiteroom.net>\n"
7
  "Language-Team: \n"
16
  "X-Poedit-Basepath: .\n"
17
  "X-Poedit-SearchPath-0: ..\n"
18
 
19
+ #: ../admin/admin.php:81
20
  msgid "Subtitle"
21
  msgstr ""
22
+
23
+ #: ../admin/admin.php:131
24
+ msgid "Enter subtitle here"
25
+ msgstr ""
26
+
27
+ #: ../admin/pointers.php:106
28
+ #, php-format
29
+ msgid "%s Field"
30
+ msgstr ""
31
+
32
+ #: ../admin/pointers.php:107
33
+ msgid "This field has moved from a meta box to below the post title."
34
+ msgstr ""
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: husani, husobj
3
  Tags: subtitle, content, title, subheading, subhead, alternate title
4
  Requires at least: 3.0
5
- Tested up to: 3.8.1
6
- Stable tag: 2.1
7
  License: GPL2
8
 
9
  Add subtitles (subheadings) to your pages, posts or custom post types.
@@ -79,11 +79,16 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
79
 
80
  == Screenshots ==
81
 
82
- 1. Edit post screen
 
83
  2. A single page showing a subtitle
84
 
85
  == Changelog ==
86
 
 
 
 
 
87
  = 2.1 =
88
  * Ready for translation - .pot file added.
89
  * Only include admin functionality when needed.
@@ -106,11 +111,14 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
106
 
107
  == Upgrade Notice ==
108
 
 
 
 
109
  = 2.1 =
110
- * Fixed static method warnings and only load admin functionality when needed.
111
 
112
  = 2.0 =
113
- * Added custom post type support and support for more recent versions of WordPress.
114
 
115
  = 1.0 =
116
- * Initial release.
2
  Contributors: husani, husobj
3
  Tags: subtitle, content, title, subheading, subhead, alternate title
4
  Requires at least: 3.0
5
+ Tested up to: 3.9.1
6
+ Stable tag: 2.2
7
  License: GPL2
8
 
9
  Add subtitles (subheadings) to your pages, posts or custom post types.
79
 
80
  == Screenshots ==
81
 
82
+ 1. Edit post screen (WordPress 3.5+ and WP Title 2.2+)
83
+ 1. Edit post screen (for earlier versions of WordPress or using the 'wps_subtitle_use_meta_box' filter)
84
  2. A single page showing a subtitle
85
 
86
  == Changelog ==
87
 
88
+ = 2.2 =
89
+ * Moved subtitle field from meta box to below title field in WordPress 3.5+ (props Tor Morten)
90
+ * Added 'wps_subtitle_use_meta_box' filter to allow the edit field to be displayed in a meta box (the old way).
91
+
92
  = 2.1 =
93
  * Ready for translation - .pot file added.
94
  * Only include admin functionality when needed.
111
 
112
  == Upgrade Notice ==
113
 
114
+ = 2.2 =
115
+ Subtitle field moved to below title field (only in WordPress 3.5+)
116
+
117
  = 2.1 =
118
+ Fixed static method warnings and only load admin functionality when needed.
119
 
120
  = 2.0 =
121
+ Added custom post type support and support for more recent versions of WordPress.
122
 
123
  = 1.0 =
124
+ Initial release.
wp-subtitle.php CHANGED
@@ -6,7 +6,7 @@ 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
  Author: Husani Oakley, Ben Huson
8
  Author URI: https://github.com/benhuson/wp-subtitle
9
- Version: 2.1
10
  License: GPLv2
11
  */
12
 
@@ -43,6 +43,7 @@ if ( is_admin() ) {
43
  // Load AJAX functions here if required...
44
  } else {
45
  require_once( WPSUBTITLE_DIR . 'admin/admin.php' );
 
46
  }
47
  }
48
 
6
  Description: Adds a subtitle field to pages and posts. Possible to add support for custom post types.
7
  Author: Husani Oakley, Ben Huson
8
  Author URI: https://github.com/benhuson/wp-subtitle
9
+ Version: 2.2
10
  License: GPLv2
11
  */
12
 
43
  // Load AJAX functions here if required...
44
  } else {
45
  require_once( WPSUBTITLE_DIR . 'admin/admin.php' );
46
+ require_once( WPSUBTITLE_DIR . 'admin/pointers.php' );
47
  }
48
  }
49