[wp-trac] [WordPress Trac] #42814: PHP 7.2 Warning: ...wp-includes/post-template.php on line 284

WordPress Trac noreply at wordpress.org
Thu Jan 11 00:24:20 UTC 2018


#42814: PHP 7.2 Warning: ...wp-includes/post-template.php on line 284
--------------------------+------------------------------
 Reporter:  internetwerk  |       Owner:
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  4.9.1
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+------------------------------
Changes (by dd32):

 * keywords:  needs-testing reporter-feedback => needs-patch


Comment:

 Duplicated it against an attachment when Jetpack is in use (and out of
 development mode)

 Here's a backtrace:
 {{{
 ( ! ) Warning: count(): Parameter must be an array or an object that
 implements Countable in ../wp-includes/post-template.php on line 292
 Call Stack
 #       Time    Memory  Function        Location
 1       0.0002  394584          {main}( )       .../index.php:0
 2       0.0004  396520          require( '.../wp-blog-header.php' )
 .../index.php:17
 3       0.8743  35298240        require_once( '.../wp-includes/template-
 loader.php' )   .../wp-blog-header.php:19
 4       0.8863  35641272        include( '.../wp-
 content/themes/twentyseventeen/single.php' )   .../template-loader.php:77
 5       0.8863  35641272        get_header( )   .../single.php:13
 6       0.8863  35641648        locate_template( )      .../general-
 template.php:41
 7       0.8864  35641744        load_template( )
 .../template.php:653
 8       0.8865  35648296        require_once( '.../wp-
 content/themes/twentyseventeen/header.php' )      .../template.php:695
 9       0.8873  35656288        wp_head( )      .../header.php:22
 10      0.8873  35656288        do_action( )    .../general-
 template.php:2661
 11      0.8873  35656664        WP_Hook->do_action( )   .../plugin.php:465
 12      0.8873  35656664        WP_Hook->apply_filters( )       .../class-
 wp-hook.php:310
 13      0.9288  35757880        jetpack_og_tags( )      .../class-wp-
 hook.php:286
 14      0.9308  35762904        apply_filters( )
 .../functions.opengraph.php:216
 15      0.9308  35763304        WP_Hook->apply_filters( )
 .../plugin.php:208
 16      0.9853  35835632        Jetpack_Twitter_Cards::twitter_cards_tags(
 )    .../class-wp-hook.php:288
 17      0.9918  35822616        Jetpack_Media_Summary::get( )   .../class
 .jetpack-twitter-cards.php:80
 18      0.9920  35823920        Jetpack_Media_Summary::get_excerpt( )
 .../class.media-summary.php:57
 19      0.9920  35823920        apply_filters( )        .../class.media-
 summary.php:314
 20      0.9920  35824320        WP_Hook->apply_filters( )
 .../plugin.php:208
 21      0.9920  35825072        wp_trim_excerpt( )      .../class-wp-
 hook.php:286
 22      0.9920  35825072        get_the_content( )
 .../formatting.php:3568
 }}}

 The reason this is being run into, is because Jetpacks
 `Jetpack_Media_Summary::get_excerpt` calls `apply_filters(
 'get_the_excerpt', $post_excerpt );` where `$post_excerpt` is empty, and
 before `WP_Query::setup_postdata()`/`the_post()` is called.
 `get_the_content()` currently expects that it'll be used within an actual
 post content loop (which is a fairly sane assumption to make, except
 plugins do weird things)
 Jetpack is doing it wrong here, but in a subtle way that would be expected
 to work by many.

 Now, we can paper over this by checking if it's an array, but that's not
 the actual problem at play here.
 The issue is that `get_the_content()` relies upon
 `WP_Query::setup_postdata()` having being run in order to actually return
 the correct data, and in this case, it can't as the source variables for
 the content are not yet setup.
 The more correct fix would be to ensure that `get_the_content()` can split
 content into pages for correct return values even when it's not within the
 loop.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42814#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list