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

Add support for other post types #223 #342

wants to merge 19 commits into from

Conversation

shantanu2704
Copy link

  1. Added a static variable for supported post types that can be filtered with the 'modify_supported_post_types' filter in the init() method.

  2. Added support for 'pages' in the init() method.

Copy link
Member

@pyronaur pyronaur left a comment

Choose a reason for hiding this comment

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

Thank you for the pull request! I noted some things that I think need some more thought.

.gitignore Outdated
@@ -7,6 +7,7 @@ yarn-error.log
.svn
composer.lock
vendor/
/nbproject
Copy link
Member

Choose a reason for hiding this comment

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

I recommend that you add the /nbrpoject to your global gitignore, that way you won't have to add it to the project. Or you can move it to where the .idea folder is ignored

liveblog.php Outdated
*/
add_post_type_support( 'post', self::key );
self::$supported_post_types = apply_filters( 'modify_supported_post_types', $post_types );
Copy link
Member

Choose a reason for hiding this comment

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

Filters have to be prefixed. Some useful info here.

liveblog.php Outdated
@@ -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::is_liveblog_post() );
Copy link
Member

Choose a reason for hiding this comment

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

This will return true for all post types, including unsupported post types. This needs more precision. Also, possibly a filter - not sure.

Copy link
Author

Choose a reason for hiding this comment

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

is_singular will return true for all default single post types.
Correct me if I am wrong, but for it to return true on a custom post type, the name of the custom post type needs to be sent as a parameter.

Also, how do you think this conditional should be handled?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

is_singular by default will check if any post type is singular, not just post or pages. So you have to check the is_signular() against all of the post types that support LIveblog.

liveblog.php Outdated
}

/**
* 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() && ! is_admin() && ! self::$is_rest_api_call) {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above - needs more precision.

Copy link
Author

Choose a reason for hiding this comment

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

I think we could use get_post_type() here.
https://developer.wordpress.org/reference/functions/get_post_type/

Something like:
...
if ( !is_singular( get_post_type( $post_id ) ) ... )

Copy link
Member

Choose a reason for hiding this comment

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

is_singular will accept post types as the parameter. You can pass the static $supported_post_types variable to the function instead.

@@ -57,6 +57,8 @@
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.

liveblog.php Outdated
@@ -245,7 +245,7 @@ public static function init() {
/**
* This allows the users to filter their supported post types.
*/
self::$supported_post_types = apply_filters( 'modify_supported_post_types', $post_types );
self::$supported_post_types = apply_filters( 'liveblog_modify_supported_post_types', $post_types );
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the modify from the filter? I think that would be better because it would almost look like the variable name we're already using: liveblog_supported_post_types

@pyronaur
Copy link
Member

Changes looking good! I think we need just a few more tweaks and we're good to go.

@shantanu2704
Copy link
Author

Hey @justnorris, I was wondering if you had a chance to look at the tests that are failing. I could use a little help there

@pyronaur
Copy link
Member

Have a look at the test logs - could it be that your tests issue is related to #344 ?

@shantanu2704
Copy link
Author

It could be.
The two tests that are failing, expect the HTTP error code 403 but are getting the HTTP error code 401.

@pyronaur
Copy link
Member

In that case, I think we can wait until the tests are pulled in the master branch - then you can update your pull request to make sure the tests pass.

@shantanu2704
Copy link
Author

That sounds good. Thanks, Norris!

@shantanu2704
Copy link
Author

Hey @justnorris!
#344 has been merged. Is there a way to check if the tests that were previously failing are still failing or do they pass?

@pyronaur
Copy link
Member

You can pull the master branch in your pull request branch - that should update everything and make the tests run again.

@pyronaur
Copy link
Member

pyronaur commented Feb 2, 2018

I think this looks good! /cc @philipjohn

@GaryJones
Copy link
Contributor

This PR has a merge conflict.

Copy link
Contributor

@philipjohn philipjohn left a comment

Choose a reason for hiding this comment

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

Thanks for this @shantanu2704! Could you take a look at my one inline comment and the merge conflict please? Then I think we can include this in v2.0 :)

* 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.

@shantanu2704
Copy link
Author

Hey @philipjohn! Thanks for the feedback!
Sadly, the changes made for this PR are long gone.
So I have submitted a new PR - #539 - which, along with the changes from this PR, incorporates your feedback, re the post type page.

Closing out this PR in favour of #539 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants