<?php
class UM_Online_API {
function __construct() {
$this->plugin_inactive = false;
add_action('init', array(&$this, 'plugin_check'), 1);
add_action('init', array(&$this, 'init'), 1);
add_action('init', array(&$this, 'log'), 1);
$this->users = get_option('um_online_users');
$this->schedule_update();
require_once um_online_path . 'core/um-online-widget.php';
add_action( 'widgets_init', array(&$this, 'widgets_init' ) );
}
/***
*** @Plugin check
***/
function plugin_check(){
if ( !class_exists('UM_API') ) {
$this->add_notice( sprintf(__('The <strong>%s</strong> extension requires the Ultimate Member plugin to be activated to work properly. You can download it <a href="https://wordpress.org/plugins/ultimate-member">here</a>','um-online'), um_online_extension) );
$this->plugin_inactive = true;
} else if ( !version_compare( ultimatemember_version, um_online_requires, '>=' ) ) {
$this->add_notice( sprintf(__('The <strong>%s</strong> extension requires a <a href="https://wordpress.org/plugins/ultimate-member">newer version</a> of Ultimate Member to work properly.','um-online'), um_online_extension) );
$this->plugin_inactive = true;
}
}
/***
*** @Plugin notice
***/
function add_notice( $msg ) {
if ( !is_admin() ) return;
echo '<div class="error"><p>' . $msg . '</p></div>';
}
/***
*** @Init
***/
function init() {
if ( $this->plugin_inactive ) return;
// Required classes
require_once um_online_path . 'core/um-online-shortcode.php';
require_once um_online_path . 'core/um-online-enqueue.php';
$this->shortcode = new UM_Online_Shortcode();
$this->enqueue = new UM_Online_Enqueue();
// Actions
require_once um_online_path . 'core/actions/um-online-profile.php';
require_once um_online_path . 'core/actions/um-online-account.php';
// Filters
require_once um_online_path . 'core/filters/um-online-fields.php';
}
/***
*** @Logs online user
***/
function log() {
// Guest or not on frontend
if ( is_admin() || !is_user_logged_in() )
return;
// User privacy do not allow that
$test = get_user_meta( get_current_user_id(), '_hide_online_status', true );
if ( $test == 1 ) {
return;
}
// We have a logged in user
// Store the user as online with a timestamp of last seen
$this->users[ get_current_user_id() ] = current_time('timestamp');
// Save the new online users
update_option('um_online_users', $this->users );
}
/***
*** @Gets users online
***/
function get_users() {
if ( isset( $this->users ) && is_array( $this->users ) && !empty( $this->users ) ) {
arsort( $this->users ); // this will get us the last active user first
return $this->users;
}
return false;
}
/***
*** @Checks if user is online
***/
function is_online( $user_id ) {
if ( isset( $this->users[ $user_id ] ) )
return true;
return false;
}
/***
*** @Update the online users
***/
private function schedule_update() {
$this->run_update();
}
/***
*** @Execute updating the list every x interval
***/
public function run_update() {
// Send a maximum of once per period
$last_send = $this->get_last_update();
if( $last_send && $last_send > strtotime( '-15 minutes' ) )
return;
// We have to check if each user was last seen in the previous x
if ( is_array( $this->users ) ) {
foreach( $this->users as $user_id => $last_seen ) {
if ( ( current_time('timestamp') - $last_seen ) > ( 60 * 15 ) ) {
// Time now is more than x since he was last seen
// Remove user from online list
unset( $this->users[$user_id] );
}
}
update_option('um_online_users', $this->users );
}
update_option( 'um_online_users_last_updated', time() );
}
private function get_last_update() {
return get_option( 'um_online_users_last_updated' );
}
function widgets_init() {
register_widget( 'um_online_users' );
}
}
$um_online = new UM_Online_API();
没有合适的资源?快使用搜索试试~ 我知道了~
WordPress插件UM用户中心在线显示
共16个文件
php:10个
po:2个
mo:2个
需积分: 10 7 下载量 5 浏览量
2018-01-28
11:45:02
上传
评论
收藏 14KB ZIP 举报
温馨提示
WordPress插件UM用户中心在线显示 适用于WordPressWordPress插件UM用户中心在线显示
资源推荐
资源详情
资源评论
收起资源包目录
um-online.zip (16个子文件)
um-online
languages
um-online-en_US.mo 582B
um-online-es_ES.mo 3KB
um-online-en_US.po 3KB
um-online-es_ES.po 4KB
um-online.php 1KB
core
um-online-shortcode.php 1KB
filters
um-online-fields.php 992B
um-online-init.php 4KB
um-online-enqueue.php 448B
actions
um-online-account.php 2KB
um-online-profile.php 416B
um-online-widget.php 3KB
assets
js
um-online.js 831B
css
um-online.css 1001B
templates
online.php 519B
nobody.php 84B
共 16 条
- 1
资源评论
qq_35279834
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功