[wp-trac] [WordPress Trac] #42034: PHP 7.1 PHP Warning: A non-numeric value encountered wp-includes/formatting.php on line 3362

WordPress Trac noreply at wordpress.org
Fri Sep 29 16:43:09 UTC 2017


#42034: PHP 7.1 PHP Warning:  A non-numeric value encountered wp-
includes/formatting.php on line 3362
-------------------------------+------------------------------
 Reporter:  laserjobs          |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Formatting         |     Version:  4.8.2
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------

Comment (by laserjobs):

 I know you have probably heard this before but it is a live site I really
 can't test with. Is there another way to check without having to change
 themes out or disable plugins? Can I search files for "wp_trim_words()"
 because I found that the wp-content/themes/smart-mag/lib/posts.php file is
 common to all those warning and is the only reference I found to that
 function in themes and plugins?

 {{{#!php
 <?php
         /**
          * Custom excerpt function - utilize existing wordpress functions
 to add real support for <!--more-->
          * to excerpts which is missing in the_excerpt().
          *
          * Maintain plugin functionality by utilizing wordpress core
 functions and filters.
          *
          * @param  string|null  $text
          * @param  integer  $length
          * @param  array   $options   add_more: add more if needed,
 more_text = more link anchor, force_more: always add more link
          * @return string
          */
         public function excerpt($text = null, $length = 55, $options =
 array())
         {
                 global $more;

                 // add defaults
                 $options = array_merge(array('add_more' => null,
 'force_more' => null), $options);

                 // add support for <!--more--> cut-off on custom home-
 pages and the like
                 $old_more = $more;
                 $more = false;

                 // override options
                 $more_text = $this->more_text;
                 extract($options);

                 // set global more_text - used by excerpt_read_more()
                 $this->more_text = $more_text;

                 if (!$text) {

                         // have a manual excerpt?
                         if (has_excerpt()) {
                                 return apply_filters('the_excerpt',
 get_the_excerpt()) . ($force_more ? $this->excerpt_read_more() : '');
                         }

                         // don't add "more" link
                         $text = get_the_content('');
                 }

                 $text =
 strip_shortcodes(apply_filters('bunyad_excerpt_pre_strip_shortcodes',
 $text));
                 $text = str_replace(']]>', ']]>', $text);

                 // get plaintext excerpt trimmed to right length
                 $excerpt = wp_trim_words($text, $length,
 apply_filters('bunyad_excerpt_hellip', '…') . ($add_more !== false
 ? $this->excerpt_read_more() : ''));


                 /*
                  * Force "More" link?
                  *
                  * wp_trim_words() will only add the read more link if
 it's needed - if the length actually EXCEEDS. In some cases,
                  * for styling, read more has to be always present.
                  *
                  */
                 if ($force_more) {

                         $read_more = $this->excerpt_read_more();

                         if (substr($excerpt, -strlen($read_more)) !==
 $read_more) {
                                 $excerpt .= $this->excerpt_read_more();
                         }
                 }

                 // fix extra spaces
                 $excerpt = trim(str_replace(' ', ' ', $excerpt));

                 // apply filters after to prevent added html functionality
 from being stripped
                 // REMOVED: the_content filters often clutter the HTML -
 use the_excerpt filter instead
                 // $excerpt = apply_filters('the_content', $excerpt);

                 $excerpt = apply_filters('the_excerpt',
 apply_filters('get_the_excerpt', $excerpt));

                 // revert
                 $more = $old_more;

                 return $excerpt;
         }
 }}}

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


More information about the wp-trac mailing list