Skip to:
Content

bbPress.org

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#3428 closed defect (bug) (fixed)

Statistics widget throws Undefined index if no replies or topics tags

Reported by: robin-w's profile Robin W Owned by: johnjamesjacoby's profile johnjamesjacoby
Milestone: 2.6.10 Priority: low
Severity: minor Version:
Component: General - Administration Keywords: has-patch
Cc:

Description

If you create a new install with just one forum and one topic and no replies and add the statistics widget to the widget area then in the front of the website you get these notifications.

Notice: Undefined index: reply_count in /var/docs/server.tst/public/wp-content/plugins/bbpress/templates/default/bbpress/content-statistics.php on line 37

Notice: Undefined index: topic_tag_count in /var/docs/server.tst/public/wp-content/plugins/bbpress/templates/default/bbpress/content-statistics.php on line <i>42

Attachments (4)

issue on frontend.png (406.9 KB) - added by hasanuzzamanshamim 3 years ago.
Issue screenshot
3428.diff (1.2 KB) - added by hasanuzzamanshamim 3 years ago.
Patch created for validation
3428.02.patch (1.3 KB) - added by johnjamesjacoby 3 years ago.
3428.03.patch (16.3 KB) - added by johnjamesjacoby 3 years ago.

Download all attachments as: .zip

Change History (11)

#1 @createquest
3 years ago

I fixed this by wrapping the topic count like so.

<?php if(isset($stats['topic_tag_count'])) : ?>
    <dt><?php esc_html_e( 'Topic Tags', 'createquest' ); ?></dt>
      <dd>
	<strong>
	<?php echo esc_html( $stats['topic_tag_count'] ); ?>
	</strong>
     </dd>
<?php endif; ?>

The same is repeated throughout the same file by using empty() instead of isset().

#2 @johnjamesjacoby
3 years ago

  • Component changed from General to General - Administration
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 2.6.10
  • Owner set to johnjamesjacoby
  • Status changed from new to assigned

@hasanuzzamanshamim
3 years ago

Issue screenshot

@hasanuzzamanshamim
3 years ago

Patch created for validation

#3 @hasanuzzamanshamim
3 years ago

  • Keywords has-patch added; needs-patch removed

#4 @hasanuzzamanshamim
3 years ago

  • Summary changed from Statistics widget throws Undefined index if no relies or topics tags to Statistics widget throws Undefined index if no replies or topics tags

#5 @johnjamesjacoby
3 years ago

3428.02.patch takes a slightly different approach:

  • Remove the array_filter() call on the return value of bbp_get_statistics() to ensure most keys are always set
  • Relatedly, adds a class to the statistics dl element to make it easier/possible to style
Version 0, edited 3 years ago by johnjamesjacoby (next)

#6 @johnjamesjacoby
3 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 7236:

Statistics: numerous code improvements:

  • Prevent PHP warnings/notices when passing specific arguments and when viewed as a user with specific capabilities
  • Rename "trashed" & "spammed" keys to "trash" & "spam" respectively, to better match their status IDs
  • Refactor bbp_get_statistics() to be simpler internally – includes fully updated docs
  • Add unofficial support for "hidden" topic & reply statuses in statistics
  • Add bbp-stats class to default template part to make it easier to target with custom styling

These changes together vastly improve the experience of using the bbp-stats shortcode.

Props createquest, hasanuzzamanshamim, robin-w.

In trunk for 2.7.0. Fixes #3428.

#7 @johnjamesjacoby
3 years ago

In 7237:

Statistics: numerous code improvements:

  • Prevent PHP warnings/notices when passing specific arguments and when viewed as a user with specific capabilities
  • Rename "trashed" & "spammed" keys to "trash" & "spam" respectively, to better match their status IDs
  • Refactor bbp_get_statistics() to be simpler internally – includes fully updated docs
  • Add unofficial support for "hidden" topic & reply statuses in statistics
  • Add bbp-stats class to default template part to make it easier to target with custom styling

These changes together vastly improve the experience of using the bbp-stats shortcode.

Props createquest, hasanuzzamanshamim, robin-w.

In branches/2.6 for 2.6.10. Fixes #3428.

Note: See TracTickets for help on using tickets.