Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for other post types #539

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions liveblog.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ final class WPCOM_Liveblog {
public static $auto_archive_days = null;
public static $auto_archive_expiry_key = 'liveblog_autoarchive_expiry_date';
public static $latest_timestamp = false;
public static $supported_post_types = array();


/** Load Methods **********************************************************/
Expand Down Expand Up @@ -250,7 +251,20 @@ public static function init() {
* Add liveblog support to the 'post' post type. This is done here so
* we can possibly introduce this to other post types later.
*/
add_post_type_support( 'post', self::KEY );
$post_types = array( 'post' );

/**
* Filters post types supported by liveblog.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a plan to possibly change the name of the plugin, so maybe change liveblog here to be this plugin?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we changing the name in this release?
If not, I think this should stay as liveblog as it'll be easier to change the prefix with a search-replace when the name is finalised.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefix on the filter is unlikely to change, unless it was aiming to break BC.

In this case, it was just the name in the filter description (line 257), that I was referring to.

Not a biggie - there are likely other instances of "liveblog" in other DocBlocks as well that would need changing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, got it! thanks!

*
* @since 2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to 2.0.0. Versions should use the 3-digit style.

*
* @param array An array of supported post types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is already specified as an array, so the description can just be Supported post types.

*/
self::$supported_post_types = apply_filters( 'liveblog_supported_post_types', $post_types );

foreach ( self::$supported_post_types as $post_type ) {
add_post_type_support( $post_type, self::KEY );
}

/**
* Apply a Filter to Setup our Auto Archive Days.
Expand Down Expand Up @@ -493,14 +507,14 @@ public static function is_liveblog_post( $post_id = null ) {
* @return bool
*/
public static function is_viewing_liveblog_post() {
return (bool) ( is_single() && self::is_liveblog_post() );
return (bool) ( is_singular( self::$supported_post_types ) && self::is_liveblog_post() );
}

/**
* One of: 'enable', 'archive', false.
*/
public static function get_liveblog_state( $post_id = null ) {
if ( ! is_single() && ! is_admin() && ! self::$is_rest_api_call ) {
if ( ! is_singular( self::$supported_post_types ) && ! is_admin() && ! self::$is_rest_api_call ) {
return false;
}
if ( empty( $post_id ) ) {
Expand Down