-
Notifications
You must be signed in to change notification settings - Fork 167
Fix PHP Warning: Parameter must be an array or an object that implements Countable #661
Fix PHP Warning: Parameter must be an array or an object that implements Countable #661
Conversation
header.php
Outdated
@@ -34,7 +34,7 @@ | |||
<?php twentynineteen_post_thumbnail(); ?> | |||
<?php the_post(); ?> | |||
<?php $discussion = ! is_page() && twentynineteen_can_show_post_thumbnail() ? twentynineteen_get_discussion_data() : null; ?> | |||
<div class="<?php echo ( ! empty( $discussion ) && count( $discussion->responses ) > 0 ) ? 'entry-header has-discussion' : 'entry-header'; ?>"> | |||
<div class="<?php echo ( ! empty( $discussion ) && count( $discussion->authors ) > 0 ) ? 'entry-header has-discussion' : 'entry-header'; ?>"> |
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.
If the intention is to count the number of responses, why change it to counting the number of authors instead? Just dumping count()
did the trick for me locally. Since $discussion->responses
returns a string value (which probably should be reviewed), wrapping it in absint()
ensures we get an integer:
<div class="<?php echo ( ! empty( $discussion ) && absint( $discussion->responses ) > 0 ) ? 'entry-header has-discussion' : 'entry-header'; ?>">
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.
I made your suggested change. Since you asked, the author count seemed more reliable at the time because $discussion->responses
is derived from get_comment_count()
and its return value can be filtered.
What can happen is another plugin, like muut, will filter the count to be zero (or even a placeholder to be filled later with JS). So there's a chance a post with comments will have a filtered value be zero, but that's probably an edge case. Worse case scenario is the CSS class won't be added there.
This commit brings over several changes that occurred upstream in the theme’s GitHub repository into core. - Fixes some minor code quality issues. WordPress/twentynineteen#237 - Fix PHP Warning: Parameter must be an array or an object that implements Countable. WordPress/twentynineteen#661 - Add missing text domain and escaping to comment author text. WordPress/twentynineteen#274 - Remove hyphens rule for cover image text. WordPress/twentynineteen#691 Props khleomix, grapplerulrich, iCaleb, kjellr, allancole. See #45424. git-svn-id: https://develop.svn.wordpress.org/branches/5.0@44199 602fd350-edb4-49c9-b593-d223f7449a82
This commit brings over several changes that occurred upstream in the theme’s GitHub repository into core. - Fixes some minor code quality issues. WordPress/twentynineteen#237 - Fix PHP Warning: Parameter must be an array or an object that implements Countable. WordPress/twentynineteen#661 - Add missing text domain and escaping to comment author text. WordPress/twentynineteen#274 - Remove hyphens rule for cover image text. WordPress/twentynineteen#691 Props khleomix, grapplerulrich, iCaleb, kjellr, allancole. See #45424. Built from https://develop.svn.wordpress.org/branches/5.0@44199 git-svn-id: http://core.svn.wordpress.org/branches/5.0@44029 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit brings over several changes that occurred upstream in the theme’s GitHub repository into core. - Fixes some minor code quality issues. WordPress/twentynineteen#237 - Fix PHP Warning: Parameter must be an array or an object that implements Countable. WordPress/twentynineteen#661 - Add missing text domain and escaping to comment author text. WordPress/twentynineteen#274 - Remove hyphens rule for cover image text. WordPress/twentynineteen#691 Props khleomix, grapplerulrich, iCaleb, kjellr, allancole. See #45424. Built from https://develop.svn.wordpress.org/branches/5.0@44199 git-svn-id: https://core.svn.wordpress.org/branches/5.0@44029 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit brings over several changes that occurred upstream in the theme’s GitHub repository into core. - Fix the gallery caption link color. WordPress/twentynineteen#687 - Remove left padding from pullquote blocks. WordPress/twentynineteen#690 - Print `skip-link-focus-fix` inline instead of enqueueing as blocking script. https://github .com/WordPress/twentynineteen/pull/47 - Fix and improve some strings with placeholders. WordPress/twentynineteen#217 - Fixes some minor code quality issues. WordPress/twentynineteen#237 - Fix PHP Warning: Parameter must be an array or an object that implements Countable. https://github .com/WordPress/twentynineteen/pull/661 - Add missing text domain and escaping to comment author text. WordPress/twentynineteen#274 - Remove hyphens rule for cover image text. WordPress/twentynineteen#691 - Fix left/right-aligned pullquote spacing. WordPress/twentynineteen#695 - Improve `readme.txt` to follow the correct standards for themes. WordPress/twentynineteen#689 Props kjellr, allancole, dimadin, westonruter, khleomix, grapplerulrich, iCaleb, desrosj. Merges [44196], [44199], and [44201-44202] into trunk. Fixes #45424. git-svn-id: https://develop.svn.wordpress.org/trunk@44305 602fd350-edb4-49c9-b593-d223f7449a82
This commit brings over several changes that occurred upstream in the theme’s GitHub repository into core. - Fix the gallery caption link color. WordPress/twentynineteen#687 - Remove left padding from pullquote blocks. WordPress/twentynineteen#690 - Print `skip-link-focus-fix` inline instead of enqueueing as blocking script. https://github .com/WordPress/twentynineteen/pull/47 - Fix and improve some strings with placeholders. WordPress/twentynineteen#217 - Fixes some minor code quality issues. WordPress/twentynineteen#237 - Fix PHP Warning: Parameter must be an array or an object that implements Countable. https://github .com/WordPress/twentynineteen/pull/661 - Add missing text domain and escaping to comment author text. WordPress/twentynineteen#274 - Remove hyphens rule for cover image text. WordPress/twentynineteen#691 - Fix left/right-aligned pullquote spacing. WordPress/twentynineteen#695 - Improve `readme.txt` to follow the correct standards for themes. WordPress/twentynineteen#689 Props kjellr, allancole, dimadin, westonruter, khleomix, grapplerulrich, iCaleb, desrosj. Merges [44196], [44199], and [44201-44202] into trunk. Fixes #45424. git-svn-id: https://develop.svn.wordpress.org/trunk@44305 602fd350-edb4-49c9-b593-d223f7449a82
This commit brings over several changes that occurred upstream in the theme’s GitHub repository into core. - Fix the gallery caption link color. WordPress/twentynineteen#687 - Remove left padding from pullquote blocks. WordPress/twentynineteen#690 - Print `skip-link-focus-fix` inline instead of enqueueing as blocking script. https://github .com/WordPress/twentynineteen/pull/47 - Fix and improve some strings with placeholders. WordPress/twentynineteen#217 - Fixes some minor code quality issues. WordPress/twentynineteen#237 - Fix PHP Warning: Parameter must be an array or an object that implements Countable. https://github .com/WordPress/twentynineteen/pull/661 - Add missing text domain and escaping to comment author text. WordPress/twentynineteen#274 - Remove hyphens rule for cover image text. WordPress/twentynineteen#691 - Fix left/right-aligned pullquote spacing. WordPress/twentynineteen#695 - Improve `readme.txt` to follow the correct standards for themes. WordPress/twentynineteen#689 Props kjellr, allancole, dimadin, westonruter, khleomix, grapplerulrich, iCaleb, desrosj. Merges [44196], [44199], and [44201-44202] into trunk. Fixes #45424. Built from https://develop.svn.wordpress.org/trunk@44305 git-svn-id: http://core.svn.wordpress.org/trunk@44135 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit brings over several changes that occurred upstream in the theme’s GitHub repository into core. - Fix the gallery caption link color. WordPress/twentynineteen#687 - Remove left padding from pullquote blocks. WordPress/twentynineteen#690 - Print `skip-link-focus-fix` inline instead of enqueueing as blocking script. https://github .com/WordPress/twentynineteen/pull/47 - Fix and improve some strings with placeholders. WordPress/twentynineteen#217 - Fixes some minor code quality issues. WordPress/twentynineteen#237 - Fix PHP Warning: Parameter must be an array or an object that implements Countable. https://github .com/WordPress/twentynineteen/pull/661 - Add missing text domain and escaping to comment author text. WordPress/twentynineteen#274 - Remove hyphens rule for cover image text. WordPress/twentynineteen#691 - Fix left/right-aligned pullquote spacing. WordPress/twentynineteen#695 - Improve `readme.txt` to follow the correct standards for themes. WordPress/twentynineteen#689 Props kjellr, allancole, dimadin, westonruter, khleomix, grapplerulrich, iCaleb, desrosj. Merges [44196], [44199], and [44201-44202] into trunk. Fixes #45424. Built from https://develop.svn.wordpress.org/trunk@44305 git-svn-id: https://core.svn.wordpress.org/trunk@44135 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit brings over several changes that occurred upstream in the theme’s GitHub repository into core. - Fix the gallery caption link color. WordPress/twentynineteen#687 - Remove left padding from pullquote blocks. WordPress/twentynineteen#690 - Print `skip-link-focus-fix` inline instead of enqueueing as blocking script. https://github .com/WordPress/twentynineteen/pull/47 - Fix and improve some strings with placeholders. WordPress/twentynineteen#217 - Fixes some minor code quality issues. WordPress/twentynineteen#237 - Fix PHP Warning: Parameter must be an array or an object that implements Countable. https://github .com/WordPress/twentynineteen/pull/661 - Add missing text domain and escaping to comment author text. WordPress/twentynineteen#274 - Remove hyphens rule for cover image text. WordPress/twentynineteen#691 - Fix left/right-aligned pullquote spacing. WordPress/twentynineteen#695 - Improve `readme.txt` to follow the correct standards for themes. WordPress/twentynineteen#689 Props kjellr, allancole, dimadin, westonruter, khleomix, grapplerulrich, iCaleb, desrosj. Merges [44196], [44199], and [44201-44202] into trunk. Fixes #45424. Built from https://develop.svn.wordpress.org/trunk@44305 git-svn-id: http://core.svn.wordpress.org/trunk@44135 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Fixes #659. This branch was tested on a server with PHP 7.2. View a single post with a featured image, with WP_DEBUG set to true.