Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Fix PHP Warning: Parameter must be an array or an object that implements Countable #661

Merged
merged 4 commits into from
Nov 29, 2018
Merged

Fix PHP Warning: Parameter must be an array or an object that implements Countable #661

merged 4 commits into from
Nov 29, 2018

Conversation

joshfeck
Copy link
Contributor

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.

@allancole allancole added this to the 5.0 milestone Nov 24, 2018
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'; ?>">

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'; ?>">

Copy link
Contributor Author

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.

@allancole allancole added the bug Something isn't working label Nov 26, 2018
@allancole allancole merged commit 7e5b086 into WordPress:master Nov 29, 2018
@joshfeck joshfeck deleted the fix/countable-warning-comments branch November 29, 2018 22:24
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Dec 14, 2018
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
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Dec 15, 2018
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
gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this pull request Dec 15, 2018
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
nylen pushed a commit to nylen/wordpress-develop-svn that referenced this pull request Dec 18, 2018
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
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Dec 18, 2018
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
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Dec 19, 2018
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
gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this pull request Dec 19, 2018
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
svn2github pushed a commit to svn2github/wp-svn-2-git that referenced this pull request Dec 21, 2018
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants