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 #223 #342

Closed
wants to merge 19 commits into from
Closed
Changes from all 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: 15 additions & 5 deletions liveblog.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ final class WPCOM_Liveblog {
public static $is_rest_api_call = false;
public static $auto_archive_days = null;
public static $auto_archive_expiry_key = 'liveblog_autoarchive_expiry_date';

public static $supported_post_types = array();
Copy link
Member

Choose a reason for hiding this comment

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

Why is a static variable better here than a regular class variable?

Copy link
Author

@shantanu2704 shantanu2704 Jan 21, 2018

Choose a reason for hiding this comment

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

The init method is static. As far as I know PHP doesn't allow non-static members to be accessed in a static method.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, you're right - the is_liveblog_post() method is static too and it's going to rely on this.



/** Load Methods **********************************************************/
Expand Down Expand Up @@ -236,11 +238,19 @@ private static function register_embed_handlers() {
*/
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 liveblog support to the 'post' and 'page' post type.
*/
$post_types = array( 'post', 'page' );
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, this will also add support for pages out of the box? I'd rather we just stick to posts, and allowing pages to be added using the filter.


/**
* This allows the users to filter their supported post types.
*/
add_post_type_support( 'post', self::key );
self::$supported_post_types = apply_filters( 'liveblog_modify_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.
* NULL is classed as disabled.
Expand Down Expand Up @@ -451,14 +461,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