Skip to:
Content

bbPress.org

Opened 3 years ago

Closed 2 years ago

Last modified 2 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 2 years ago.
Issue screenshot
3428.diff (1.2 KB) - added by hasanuzzamanshamim 2 years ago.
Patch created for validation
3428.02.patch (1.3 KB) - added by johnjamesjacoby 2 years ago.
3428.03.patch (16.3 KB) - added by johnjamesjacoby 2 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
2 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
2 years ago

Issue screenshot

@hasanuzzamanshamim
2 years ago

Patch created for validation

#3 @hasanuzzamanshamim
2 years ago

  • Keywords has-patch added; needs-patch removed

#4 @hasanuzzamanshamim
2 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
2 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
  • Use bbp_number_not_negative() to explicitly prevent invalid numbers
  • Relatedly, adds a class to the statistics dl element to make it easier/possible to style
Last edited 2 years ago by johnjamesjacoby (previous) (diff)

#6 @johnjamesjacoby
2 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
2 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.