-
Notifications
You must be signed in to change notification settings - Fork 123
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
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cd814f1
Add nbproject to git ignore
shantanu2704 43dd4de
Add post type support for page, attachment and revision in init() of …
shantanu2704 b7a457e
Add checks for page and attachment when checking for liveblog post
shantanu2704 a8876f0
Use is_singular instead of multiple is_* checks
shantanu2704 6e8d31c
Update get_liveblog_state
shantanu2704 094727a
Remove support for revision type
shantanu2704 6cfe394
Remove support for attachment type
shantanu2704 6ea2457
Add a new filter to allow the user to filter the supported post types
shantanu2704 b08da6c
Fix declarations
shantanu2704 6675564
Add ruleset
shantanu2704 b69ec27
Try adding a conditional to the url endpoint
shantanu2704 0c42d8c
Revert last commit
shantanu2704 69bafc4
Remove /nbproject from gitignore
shantanu2704 3773a49
Add a 'liveblog' prefix to the filter name
shantanu2704 becefb7
Remove phpcs.xml.dist which was added by mistake
shantanu2704 7bc535f
Refine the is_singular() conditional
shantanu2704 7ee23c4
Fix formatting
shantanu2704 7bb33b3
Merge branch 'master' of github.com:Automattic/liveblog
shantanu2704 9f6e3a1
Merge branch 'master' of github.com:automattic/liveblog
shantanu2704 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
||
|
||
/** Load Methods **********************************************************/ | ||
|
@@ -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' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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 ) ) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.