function justmedia_vip_video_shortcode($atts) {
$atts = shortcode_atts( array(
‘video_url’ => ”,
‘cover’ => ”,
), $atts );
// 1. 获取当前用户(JustMedia实际逻辑)
$current_user = wp_get_current_user();
$is_member = false;
$vip_expire = 0;
// 2. 调试输出(显示实际判断过程)
echo ‘
echo ‘JustMedia实际会员逻辑调试:
‘;
// 3. 实际会员判断(完全复用付费下载逻辑)
if ($current_user->ID) { // 仅登录用户
// ① 获取JustMedia存储的会员过期时间(元数据`vip`,实际核心字段)
$vip_meta = get_user_meta($current_user->ID, ‘vip’, true);
echo ‘用户ID ‘ . $current_user->ID . ‘ 的vip元数据值:’ . var_export($vip_meta, true) . ‘
‘;
// ② 实际判断规则(与付费下载模块完全一致):
// – 必须是数字(时间戳)
// – 必须大于当前时间(未过期)
if (is_numeric($vip_meta)) {
$vip_expire = intval($vip_meta);
$now = time();
echo ‘会员过期时间:’ . date(‘Y-m-d H:i:s’, $vip_expire) . ‘
‘;
echo ‘当前时间:’ . date(‘Y-m-d H:i:s’, $now) . ‘
‘;
if ($vip_expire > $now) {
$is_member = true;
echo ‘会员状态:有效(未过期)
‘;
} else {
echo ‘会员状态:无效(已过期)
‘;
}
} else {
echo ‘会员状态:无效(非时间戳格式)
‘;
}
} else {
echo ‘用户状态:未登录 → 非会员
‘;
}
// 最终判定结果
echo ‘最终结果:‘ . ($is_member ? ‘会员可观看‘ : ‘非会员‘);
echo ‘
‘;
// 4. 内容展示(基于实际判断结果)
if ($is_member && !empty($atts[‘video_url’])) {
return ‘
‘;
} else {
$cover_url = !empty($atts[‘cover’]) ? esc_url($atts[‘cover’]) : ‘https://picsum.photos/1200/675?grayscale’;
return ‘
‘;
}
}
add_shortcode(‘justmedia_vip_video’, ‘justmedia_vip_video_shortcode’);