WP Subtitle - Version 2.4

Version Description

  • Add subtitle admin column.
Download this release

Release Info

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

Code changes from version 2.3.2 to 2.4

Files changed (4) hide show
  1. admin/admin.php +46 -3
  2. admin/pointers.php +62 -22
  3. readme.txt +8 -2
  4. wp-subtitle.php +3 -1
admin/admin.php CHANGED
@@ -41,7 +41,7 @@ class WPSubtitle_Admin {
41
  $post_type = $_GET['post_type'];
42
  } elseif ( isset( $_GET['post'] ) ) {
43
  $post_type = get_post_type( $_GET['post'] );
44
- } elseif ( $pagenow == 'post-new.php' ) {
45
  $post_type = 'post';
46
  }
47
 
@@ -53,6 +53,49 @@ class WPSubtitle_Admin {
53
  } else {
54
  add_action( 'add_meta_boxes', array( 'WPSubtitle_Admin', '_add_meta_boxes' ) );
55
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
57
 
58
  }
@@ -103,7 +146,7 @@ class WPSubtitle_Admin {
103
  * @uses apply_filters( 'wps_meta_box_title' )
104
  */
105
  static function get_meta_box_title( $post_type ) {
106
- return apply_filters( 'wps_meta_box_title', __( 'Subtitle', 'wp-subtitle' ), $post_type );
107
  }
108
 
109
  /**
@@ -153,7 +196,7 @@ class WPSubtitle_Admin {
153
  echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
154
  echo '<div id="subtitlediv" class="top">';
155
  echo '<div id="subtitlewrap">';
156
- echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( WPSubtitle::_get_post_meta( $post->ID ) ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', 'wp-subtitle' ) ) ) . '" />';
157
  echo '</div>';
158
 
159
  // Description
41
  $post_type = $_GET['post_type'];
42
  } elseif ( isset( $_GET['post'] ) ) {
43
  $post_type = get_post_type( $_GET['post'] );
44
+ } elseif ( in_array( $pagenow, array( 'post-new.php', 'edit.php' ) ) ) {
45
  $post_type = 'post';
46
  }
47
 
53
  } else {
54
  add_action( 'add_meta_boxes', array( 'WPSubtitle_Admin', '_add_meta_boxes' ) );
55
  }
56
+
57
+ add_filter( 'manage_edit-' . $post_type . '_columns', array( 'WPSubtitle_Admin', 'manage_subtitle_columns' ) );
58
+ add_action( 'manage_' . $post_type . '_posts_custom_column', array( 'WPSubtitle_Admin', 'manage_subtitle_columns_content' ), 10, 2 );
59
+
60
+ }
61
+
62
+ }
63
+
64
+ /**
65
+ * Add subtitle admin column.
66
+ *
67
+ * @since 2.4
68
+ *
69
+ * @param array $columns A columns
70
+ * @return array Updated columns.
71
+ */
72
+ public static function manage_subtitle_columns( $columns ) {
73
+
74
+ $new_columns = array();
75
+
76
+ foreach ( $columns as $column => $value ) {
77
+ $new_columns[ $column ] = $value;
78
+ if ( 'title' == $column ) {
79
+ $new_columns['wps_subtitle'] = __( 'Subtitle', WPSubtitle::TEXTDOMAIN );
80
+ }
81
+ }
82
+
83
+ return $new_columns;
84
+
85
+ }
86
+
87
+ /**
88
+ * Display subtitle column.
89
+ *
90
+ * @since 2.4
91
+ *
92
+ * @param string $column_name Column name.
93
+ * @param int $post_id Post ID
94
+ */
95
+ public static function manage_subtitle_columns_content( $column_name, $post_id ) {
96
+
97
+ if ( $column_name == 'wps_subtitle' ) {
98
+ echo get_the_subtitle( $post_id, '', '', false );
99
  }
100
 
101
  }
146
  * @uses apply_filters( 'wps_meta_box_title' )
147
  */
148
  static function get_meta_box_title( $post_type ) {
149
+ return apply_filters( 'wps_meta_box_title', __( 'Subtitle', WPSubtitle::TEXTDOMAIN ), $post_type );
150
  }
151
 
152
  /**
196
  echo '<input type="hidden" name="wps_noncename" id="wps_noncename" value="' . wp_create_nonce( 'wp-subtitle' ) . '" />';
197
  echo '<div id="subtitlediv" class="top">';
198
  echo '<div id="subtitlewrap">';
199
+ echo '<input type="text" id="wpsubtitle" name="wps_subtitle" value="' . esc_attr( WPSubtitle::_get_post_meta( $post->ID ) ) . '" autocomplete="off" placeholder="' . esc_attr( apply_filters( 'wps_subtitle_field_placeholder', __( 'Enter subtitle here', WPSubtitle::TEXTDOMAIN ) ) ) . '" />';
200
  echo '</div>';
201
 
202
  // Description
admin/pointers.php CHANGED
@@ -40,20 +40,59 @@ class WPSubtitle_Pointers {
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.
@@ -70,19 +109,20 @@ class WPSubtitle_Pointers {
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
 
@@ -103,8 +143,8 @@ class WPSubtitle_Pointers {
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',
40
  return;
41
  }
42
 
43
+ // Get pointers for this screen, or return.
44
+ $pointers = self::get_current_pointers();
45
+ if ( empty( $pointers ) ) {
46
+ return;
47
+ }
 
48
 
49
+ // Get dismissed pointers, or return.
50
+ $valid_pointers = self::remove_dismissed_pointers( $pointers );
51
+ if ( empty( $valid_pointers ) ) {
52
  return;
53
  }
54
 
55
+ // Enqueue pointer scripts and styles.
56
+ wp_enqueue_style( 'wp-pointer' );
57
+ wp_enqueue_script( 'wps-subtitle-pointer', plugins_url( 'js/pointers.js', __FILE__ ), array( 'wp-pointer' ) );
58
+ wp_localize_script( 'wps-subtitle-pointer', 'wpsSubtitlePointer', $valid_pointers );
59
+
60
+ }
61
+
62
+ /**
63
+ * Get Current Pointers
64
+ *
65
+ * Get pointers for the current aadmin screen.
66
+ *
67
+ * @since 2.4
68
+ *
69
+ * @return array Current screen pointers.
70
+ */
71
+ public static function get_current_pointers() {
72
+
73
+ $screen = get_current_screen();
74
+ $pointers = apply_filters( 'wps_subtitle_admin_pointers-' . $screen->id, array() );
75
+
76
+ // Only return valid array of pointers.
77
+ if ( is_array( $pointers ) ) {
78
+ return $pointers;
79
+ }
80
+
81
+ return array();
82
+
83
+ }
84
+
85
+ /**
86
+ * Remove Dismissed Pointers
87
+ *
88
+ * @since 2.4
89
+ *
90
+ * @param array $pointers Pointers.
91
+ * @return array Active pointers.
92
+ */
93
+ public static function remove_dismissed_pointers( $pointers ) {
94
+
95
+ $dismissed = self::get_dismissed_pointers();
96
  $valid_pointers = array();
97
 
98
  // Check pointers and remove dismissed ones.
109
  $valid_pointers['pointers'][] = $pointer;
110
  }
111
 
112
+ return $valid_pointers;
 
 
 
113
 
114
+ }
 
115
 
116
+ /**
117
+ * Get Dismissed Pointers
118
+ *
119
+ * @since 2.4
120
+ *
121
+ * @return array Dismissed pointers.
122
+ */
123
+ public static function get_dismissed_pointers() {
124
 
125
+ return explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
 
126
 
127
  }
128
 
143
  'target' => '#subtitlewrap',
144
  'options' => array(
145
  'content' => sprintf( '<h3>%s</h3><p>%s</p>',
146
+ sprintf( __( '%s Field', WPSubtitle::TEXTDOMAIN ), WPSubtitle_Admin::get_meta_box_title( get_post_type( get_queried_object_id() ) ) ),
147
+ __( 'This field has moved from a meta box to below the post title.', WPSubtitle::TEXTDOMAIN )
148
  ),
149
  'position' => array(
150
  'edge' => 'top',
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: husobj, husani
3
  Tags: subtitle, content, title, subheading, subhead, alternate title
4
  Requires at least: 3.7
5
- Tested up to: 4.1
6
- Stable tag: 2.3.2
7
  License: GPL2
8
 
9
  Add subtitles (subheadings) to your pages, posts or custom post types.
@@ -98,6 +98,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
98
 
99
  == Changelog ==
100
 
 
 
 
101
  = 2.3.2 =
102
  * Show subtitle admin field when adding new post. Props Gabriel Doty.
103
 
@@ -134,6 +137,9 @@ The plugin is [hosted on GitHub](https://github.com/benhuson/wp-subtitle) and pu
134
 
135
  == Upgrade Notice ==
136
 
 
 
 
137
  = 2.3.1 =
138
  Security Update: Ensure subtitles are sanitized when saving.
139
 
2
  Contributors: husobj, husani
3
  Tags: subtitle, content, title, subheading, subhead, alternate title
4
  Requires at least: 3.7
5
+ Tested up to: 4.2
6
+ Stable tag: 2.4
7
  License: GPL2
8
 
9
  Add subtitles (subheadings) to your pages, posts or custom post types.
98
 
99
  == Changelog ==
100
 
101
+ = 2.4 =
102
+ * Add subtitle admin column.
103
+
104
  = 2.3.2 =
105
  * Show subtitle admin field when adding new post. Props Gabriel Doty.
106
 
137
 
138
  == Upgrade Notice ==
139
 
140
+ = 2.4 =
141
+ Add subtitle admin column.
142
+
143
  = 2.3.1 =
144
  Security Update: Ensure subtitles are sanitized when saving.
145
 
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.3.2
10
  License: GPLv2
11
  */
12
 
@@ -51,6 +51,8 @@ add_action( 'init', array( 'WPSubtitle', '_add_default_post_type_support' ), 5 )
51
 
52
  class WPSubtitle {
53
 
 
 
54
  /**
55
  * Add Default Post Type Support
56
  *
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.4
10
  License: GPLv2
11
  */
12
 
51
 
52
  class WPSubtitle {
53
 
54
+ const TEXTDOMAIN = 'wps_subtitle';
55
+
56
  /**
57
  * Add Default Post Type Support
58
  *