Skip to:
Content
Pages
Categories
Search
Top
Bottom

Warning PHP statistics forums


  • itsmifred
    Participant

    @itsmifred

    Hi,
    I need to keep at least one forum with visibility “Public” otherwise, if all forums are “Private” I got a PHP warning instead of forums number :
    Warning: Undefined array key “forum_count” in /home/clients/3db470ac3c186374a924a94534df90ab/sites/test.com/wp-content/plugins/youzify/includes/public/templates/bbpress/content-statistics.php on line 33
    Forums

    Even when Yousify is not activate.

    And also, warning doesn’t appears when at least one forum is “Public” but, I need to use extra snippet to get the real numbers of forums otherwise statistics say 1 when there is more…

Viewing 23 replies - 1 through 23 (of 23 total)

  • Robin W
    Moderator

    @robin-w

    that error is for the youzify plugin, so can only appear if that plugin is active, or if you have not cleared cache.


    itsmifred
    Participant

    @itsmifred

    Hi Robin,

    I’m sorry, but I can only contradict you: Yousify deactivated and cache cleared the warning still appears.

    Warning don’t appear only if at least one forum is “Public” visibility.
    All forums “Private” and none “Public” make the warning appears.


    Robin W
    Moderator

    @robin-w

    the warning is

    Warning: Undefined array key “forum_count” in /home/clients/3db470ac3c186374a924a94534df90ab/sites/test.com/wp-content/plugins/youzify

    which says the undefined array key is in the plugin youzify

    sorry I cannot help further


    itsmifred
    Participant

    @itsmifred

    Ok

    Best regards


    Robin W
    Moderator

    @robin-w

    basically you need to raise this with youzify


    itsmifred
    Participant

    @itsmifred

    Support Yousify told me the warning appears even when Yousify is deactivated and this is right. I checked it myself (cleared cache)…
    Anyway I am going to keep trying to find…


    Robin W
    Moderator

    @robin-w

    Unless you are using the plugin or bespoke code to load that template, I fail to see how that can be, the error quotes a file within Youzify

    plugins/youzify/includes/public/templates/bbpress/content-statistics.php on line 33

    but quite happy for you to pursue as you feel fit


    itsmifred
    Participant

    @itsmifred

    HI Robin,
    in fact, sorry I didn’t pay enough attention, but when Yousify is not activated the warning is else :

    Forums

    Warning: Undefined array key “forum_count” in /home/clients/3db470ac3c186374a924a94534df90ab/sites/testXXXX.com/wp-content/plugins/bbpress/templates/default/bbpress/content-statistics.php on line 27


    Robin W
    Moderator

    @robin-w

    ok, so with no ‘public’ forums, what do you want the template to display against forums – presume 0 ?


    itsmifred
    Participant

    @itsmifred

    well no, I’d like the template to display the exact number of forums, whether public or private, the total number.
    Isn’t that what it’s supposed to do?
    By the way, that’s what I’m getting at the moment, but for that we need at least one forum with “Public” visibility. Otherwise there is a warning. Of course I could also disable warnings…

    (you seem tireless Robin, is the W for Wood 😉


    Robin W
    Moderator

    @robin-w

    Isn’t that what it’s supposed to do?

    Honestly not a bit of code I’ve looked at in 10 years. I am presuming this is the [bbp-stats] shortcode that is doing this? and if so do you want to show this to all users, or just logged in ?


    itsmifred
    Participant

    @itsmifred

    yes it is, the [bbp-stats] shortcode…

    My idea is just to communicate URL of this page to moderators whose role is more to facilitate trade than to control it (2/3 members in the private of a fellow workers’ group).
    That way they could easily,simply and clearly get an overview of the forums…

    in that way, I would say it is more appropriate just logged in…


    Robin W
    Moderator

    @robin-w

    can you try

    add_filter ('bbp_get_statistics', 'rew_count_forums' , 10 , 3) ;
    
    function rew_count_forums ($statistics, $r, $args ) {
    	//fix counts for forums to show private forums if user can read them and not error if site is only private forums
    	// forums
    	if ( ! empty( $r['count_forums'] ) ) {
    		$private = bbp_get_private_status_id();
    		$all_forums  = wp_count_posts( bbp_get_forum_post_type() );
    
    		// Published (publish)
    		$forums['publish'] = $all_forums->publish ;
    		$forums['private'] = 0 ;
    		if ( current_user_can( 'read_private_forums' ) ) {
    
    			// Private
    			$forums['private'] = $all_forums->{$private} ;
    			
    		}
    		//now add the two 
    		$statistics['forum_count'] = $forums['publish'] + $forums['private'] ;
    		}
    // Filter & return
    return (array) apply_filters( 'rew_count_forums', $statistics, $r, $args );
    
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets


    Robin W
    Moderator

    @robin-w

    I’ve also added this as a bug fix to my style pack plugin -m see bug fixes tab


    itsmifred
    Participant

    @itsmifred

    Hi Robin,

    thank you so much for your work, here is where I am :

    . no more warning Forums
    . but count was double ; Tell 20 when there is 10 forums…

    I checked and it was because I had a previous snippet ; when I disable that one, your code seems to be well working. Here is the previous one (made because without it only public forums were counted). Can you confirm please I can delete it and keep only yours ?

    `function bbpress_include_private_posts_count($statistics, $r, $args){
    if( isset($statistics[‘forum_count’]) ){
    $private = wp_count_posts(“forum”)->private;
    if( !empty($private) ){
    $statistics[‘forum_count’] = $private + $statistics[‘forum_count’];
    }
    }
    return $statistics;
    }
    add_filter(‘bbp_get_statistics’, ‘bbpress_include_private_posts_count’, 999, 3);


    Robin W
    Moderator

    @robin-w

    yes you can delete that


    itsmifred
    Participant

    @itsmifred

    Hi again,

    oops ! not yet… there is a new warning in admin Dashboard > At a Glance :

    Warning: Undefined array key “forum_count_int” in /home/clients/3db470ac3c186374a924a94534df90ab/sites/testXXXX.com/wp-content/plugins/bbpress/includes/admin/metaboxes.php on line 52


    Robin W
    Moderator

    @robin-w

    add_filter ('bbp_get_statistics', 'rew_count_forums' , 10 , 3) ;
    function bsp_count_forums ($statistics, $r, $args ) {
    	//fix counts for forums to show private forums if user can read them and not error if site is only private forums
    	// forums
    	if ( ! empty( $r['count_forums'] ) ) {
    		$private = bbp_get_private_status_id();
    		$all_forums  = wp_count_posts( bbp_get_forum_post_type() );
    
    		// Published (publish)
    		$forums['publish'] = $all_forums->publish ;
    		$forums['private'] = 0 ;
    		if ( current_user_can( 'read_private_forums' ) ) {
    
    			// Private
    			$forums['private'] = $all_forums->{$private} ;
    			
    		}
    		//now add the two 
    		$statistics['forum_count'] = $forums['publish'] + $forums['private'] ;
    		$statistics['forum_count_int'] = $statistics['forum_count'] ;
    		}
    // Filter & return
    return (array) apply_filters( 'bsp_count_forums', $statistics, $r, $args );
    
    }

    itsmifred
    Participant

    @itsmifred

    Snippet automatically deactivated due to an error on line 3:
    Cannot redeclare function bsp_count_forums.


    Robin W
    Moderator

    @robin-w

    can you confirm that you are using style pack, in which case I’ll just issue a newer version and you can forget the snippet


    itsmifred
    Participant

    @itsmifred

    Hi Robin,

    yes I confirm (Version 5.8.9) and you’re right, if I activate the fix in Style Pack, warning don’t appears. Well done, I think it’s ok…

    thx


    Robin W
    Moderator

    @robin-w

    great, I’ve just released 5.9.0 as well which has a further line to make sure it works (I hope!)


    itsmifred
    Participant

    @itsmifred

    5.9.O is working too, I can see that on production site… I don’t know why but automatic update keep me 5.8.9 on my test site…

    thanks again dear…

Viewing 23 replies - 1 through 23 (of 23 total)
  • You must be logged in to reply to this topic.
Skip to toolbar