目前正在查看论坛的用户数量

时间:2017-09-12 15:21:48

标签: wordpress plugins forum bbpress

我正在尝试输入vBulletin在我的论坛上使用BBpress的功能。它显示当前正在查看特定论坛或主题的用户数量。我正在尝试编辑CBX用户在线插件,因为它具有显示当前正在查看当前页面的用户数量的功能,因此我试图找出如何为每个单独的论坛而不是当前页面编辑它。

这是在当前页面上记录用户访问的功能:

public function log_visit($page_url = '', $page_title = '') {
    global $wpdb;

    if (empty($page_url))
        $page_url = sanitize_text_field($_SERVER['REQUEST_URI']);
        //$page_url = bbp_forum_permalink($forum_id);
    if (empty($page_title))
        $page_title = self::get_title();



    $referral = CBXUseronlineHelper::get_referral();

    $user_ip = CBXUseronlineHelper::get_ipaddress();


    $user_agent   = CBXUseronlineHelper::get_useragent();
    $current_user = wp_get_current_user();
    $bots         = CBXUseronlineHelper::get_bots();


    $bot_found = false;
    $user_id = '';

    foreach ($bots as $name => $lookfor)
    {
        if (stristr($user_agent, $lookfor) !== false)
        {

            $user_id   = $_COOKIE[CBX_USERONLINE_COOKIE_NAME];
            $user_name = $name;
            $username  = $lookfor;
            $user_type = 'bot';
            $bot_found = true;

            break;
        }
    }



    // If No Bot Is Found, Then We Check Members And Guests
    if (!$bot_found)
    {
        if ($current_user->ID)
        {
            // Check For Member
            $user_id   = $current_user->ID;
            $user_name = $current_user->display_name;
            $user_type = 'user';
            $where     = $wpdb->prepare("WHERE user_id = %d", $user_id);
        }
        elseif (isset($_COOKIE[CBX_USERONLINE_COOKIE_NAME])){
            $user_id   = $_COOKIE[CBX_USERONLINE_COOKIE_NAME];

            $user_name = (!empty($_COOKIE['comment_author_' . COOKIEHASH])) ? trim(strip_tags($_COOKIE['comment_author_' . COOKIEHASH])): __('Guest', 'cbxuseronline');
            $user_type = 'guest';
        }
    }
    else{
        return;
    }

    $mobile = (CBXUseronlineHelper::is_mobile())? 1: 0;


    // Current GMT Timestamp
    $timestamp = current_time('mysql');

    $cbxuseronline_tablename = CBXUseronlineHelper::get_tablename();

    $userid  = $user_id;

    $cbxuseronline_basics = get_option('cbxuseronline_basics');
    $refresh_time =  isset($cbxuseronline_basics['refreshtime'])? intval($cbxuseronline_basics['refreshtime']): 3600;


    // Purge table
    $real_purge = $wpdb->query( $wpdb->prepare( "DELETE FROM $cbxuseronline_tablename WHERE userid = %s OR timestamp < DATE_SUB(%s, INTERVAL %d SECOND)", $userid, $timestamp, $refresh_time ) );
    if($real_purge !== false){
        do_action('cbxuseronline_record');
    }



    // Insert Users
    $data = compact( 'timestamp', 'user_type', 'userid', 'user_name', 'user_ip', 'user_agent', 'page_title', 'page_url', 'referral', 'mobile' );
    $data = stripslashes_deep( $data );



    $wpdb->replace( $cbxuseronline_tablename, $data );

    // Count Users Online
    $cbxuseronline_mostonline_now = intval( $wpdb->get_var( "SELECT COUNT( * ) FROM $cbxuseronline_tablename" ) );

    $cbxuseronline_mostonline_old = get_option('cbxuseronline_mostonline');
    if($cbxuseronline_mostonline_old ===  FALSE || ($cbxuseronline_mostonline_now > intval($cbxuseronline_mostonline_old['count'])) ){

        update_option('cbxuseronline_mostonline', array(
            'count' => $cbxuseronline_mostonline_now,
            'date' => current_time( 'timestamp' )
        ));
    }
}

我很确定这是负责在当前页面上记录用户访问的代码段:

$page_url = sanitize_text_field($_SERVER['REQUEST_URI']);

但我尝试将其编辑为类似的内容:

$page_url = bbp_forum_permalink($forum_id);

但不幸的是,这不起作用。

有人知道我做错了吗?

提前感谢您提供的任何信息/建议。

enter image description here

0 个答案:

没有答案
相关问题