Skip to:
Content
Pages
Categories
Search
Top
Bottom

My findings concerning the warning raised with “bbPress Advanced Statistics”


  • Chuckie
    Participant

    @ajtruckle

    So the warning raised was:

    > Undefined index: latest-user

    The code flagged was:

    "%LATEST_USER%" => $this->stats["latest-user"]

    I did a bit more research and stumbled upon:

    `
    if( $this->parent->option[‘last_user’] === “on” ) {
    $HTMLOutput[“last_user”] = $this->section_latestuser();
    }
    `

    At first I thought that latest-user needed to be changed to last_user, or vice-versa. But I continued the research of the code and arrived here:

    `
    array(
    ‘id’ => ‘last_user’,
    ‘label’ => __( ‘Latest Registered user’, ‘bbpress-improved-statistics-users-online’ ),
    ‘description’ => __( ‘Display the latest user to register to the site?’, ‘bbpress-improved-statistics-users-online’ ),
    ‘type’ => ‘checkbox’,
    ‘default’ => $this->defaults[‘last_user’],
    ‘class’ => ”
    ),
    `

    I decided to have a look at my bbPress Advanced Statistics settings and this was actually unset. I have now switched it on:

    View post on imgur.com

    Now the warning does not display. Also, it then occured to me that the code has this line:

    $this->stats = $this->stats_extra( $activity );

    That function does this:

    `
    private function stats_extra( $activity ) {

    if( $this->parent->option[“bbpress_statistics”] == “on” ) {
    // Add the bbPress Statistics
    $activity[“bbpress”] = $this->get_formatted_statistics();
    }

    if( $this->parent->option[“last_user”] == “on” ) {
    // Get the HTML latest usser
    $activity[“latest-user”] = $this->get_latestuser( true );
    }

    if( $this->parent->option[“most_users_online”] == “on” ) {
    // Get/set the most users ever online, users the active online users
    $activity[“most-users”] = $this->get_mostusers( $activity[“count”][“active”] );
    }

    return $activity;
    }
    `

    Therein is the problem. This function is conditionally populating the stats array based on user options. Makes sense, but, this function, makes assumptions:

    `
    private function allowed_tags() {
    // Store all of the strings currently replace
    $this->_tags = array(
    “%MINS%” => $this->parent->option[‘user_inactivity_time’],
    “%COUNT_ACTIVE_USERS%” => $this->stats[“count”][“active”],
    “%HOURS%” => $this->parent->option[‘user_activity_time’],
    “%COUNT_ALL_USERS%” => $this->stats[“count”][“inactive”] – $this->stats[“count”][“guests”],
    “%COUNT_ALL_GUSERS%” => $this->stats[“count”][“guests”],
    “%COUNT_ACTIVE_GUSERS%” => $this->stats[“count”][“guestsa”],
    “%USER_USERS%” => _n(“user”, “users”, $this->stats[“count”][“active”], ‘bbpress-improved-statistics-users-online’),
    “%GUEST_GUESTS%” => _n(“guest”, “guests”, $this->stats[“count”][“guestsa”], ‘bbpress-improved-statistics-users-online’),
    “%ALL_USER_USERS%” => _n(“user”, “users”, $this->stats[“count”][“inactive”] – $this->stats[“count”][“guests”], ‘bbpress-improved-statistics-users-online’),
    “%ALL_GUEST_GUESTS%” => _n(“guest”, “guests”, $this->stats[“count”][“guests”], ‘bbpress-improved-statistics-users-online’),
    “%USER_RECORD%” => $this->most_users( “record” ),
    “%USER_RECORD_DATE%” => $this->most_users( “date” ),
    “%USER_RECORD_TIME%” => $this->most_users( “time” ),
    “%LATEST_USER%” => $this->stats[“latest-user”]
    );

    // Apply any filters that may have been applied to the list of existing tags
    if( has_filter(‘bbpas_replacement_tags’) ) {
    $this->_tags = apply_filters( ‘bbpas_replacement_tags’, $this->_tags );
    }
    }
    `

    I will be upfront here – I don’t know how to adjust the code so that it will not raise a warning when the Last Registered User setting it not checked. As a result I switched it on.

    I just thought i would throw my findings out here as someone might be able to provide the tweak to make it correct.

    have a good day!

  • You must be logged in to reply to this topic.
Skip to toolbar