Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
Add subtitles into post, page, and custom post type columns in the Da…
Browse files Browse the repository at this point in the history
…shboard.
  • Loading branch information
Philip Arthur Moore committed Jul 19, 2015
1 parent df32042 commit 9fa9ec1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions admin/subtitles-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ protected function __construct() {
* @since 1.0.0
*/
add_action( 'admin_enqueue_scripts', array( &$this, 'subtitle_admin_scripts' ) );

/**
* Add subtitles into post, page, and custom post type columns in the Dashboard.
*
* @since 2.1.0
*/
add_action( 'manage_posts_columns', array( &$this, 'build_subtitles_column_head' ), 10, 2 );
add_action( 'manage_posts_custom_column', array( &$this, 'build_subtitles_column_content' ), 10, 2 );
add_action( 'manage_pages_columns', array( &$this, 'build_subtitles_column_head' ) );
add_action( 'manage_pages_custom_column', array( &$this, 'build_subtitles_column_content' ), 10, 2 );
} // end method __construct()

/**
Expand Down Expand Up @@ -347,5 +357,47 @@ public function subtitle_admin_scripts( $hook ) {
*/
wp_enqueue_script( self::PLUGIN_SLUG . '-admin-scripts', plugins_url( 'assets/js/subtitles.js' , __FILE__ ), array( 'jquery' ), self::VERSION, true );
} // end subtitle_admin_scripts()

/**
* Build Subtitle column headers for post, pages, and custom post types.
*
* @see function esc_html__
* @see function is_admin
* @see function post_type_supports
* @since 2.1.0
* @access public
*/
public function build_subtitles_column_head( $posts_columns, $post_type = 'page' ) {
if ( ! is_admin() ) {
return;
}

$post_type_support = post_type_supports( $post_type, self::SUBTITLE_FEATURE_SUPPORT );
if ( $post_type_support ) {
$posts_columns['subtitle'] = esc_html__( 'Subtitle', 'subtitles' );
}

return $posts_columns;
} // end function build_subtitles_column_head

/**
* Build Subtitle column content for post, pages, and custom post types.
*
* @see function is_admin
* @see function get_the_subtitle
* @since 2.1.0
* @access public
*/
public function build_subtitles_column_content( $column_name, $post_id ) {
if ( ! is_admin() || 'subtitle' !== $column_name ) {
return;
}

$subtitle = get_the_subtitle( $post_id );

if ( ! empty( $subtitle ) ) {
echo $subtitle; // WPCS: XSS OK
}
} // end function build_subtitles_column_content
} // end class Subtitles_Admin
} // end class Subtitles_Admin check
2 changes: 1 addition & 1 deletion public/class-subtitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ public static function get_the_subtitle( $post = 0 ) {
$post_id = ( isset( $post ) ) ? $post->ID : 0; // post ID should always be a non-negative integer
$subtitle = (string) html_entity_decode( wp_unslash( esc_html( get_post_meta( $post_id, self::SUBTITLE_META_KEY, true ) ) ), ENT_QUOTES );

if ( '' == $subtitle ) {
if ( '' === $subtitle ) {
return $subtitle;
}

Expand Down

0 comments on commit 9fa9ec1

Please sign in to comment.