PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / trunk
WpStream – Live Streaming, Video on Demand, Pay Per View vtrunk
4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 4.5.12 All 180 releases
wpstream / integrations / integrations.php

integrations.php in WpStream – Live Streaming, Video on Demand, Pay Per View trunk, at integrations/integrations.php

90 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Third-party plugin integration bootstrap and shared helpers.
4 *
5 * This file is the entry point for WpStream's compatibility layer with other
6 * plugins. It detects whether BuddyPress/BuddyBoss is active and conditionally
7 * loads the matching integration file, and it exposes small helper functions
8 * (live-event lookup with transient caching, and a "LIVE" card badge) that the
9 * integrations and theme templates reuse.
10 *
11 * @package Wpstream
12 * @subpackage Wpstream/integrations
13 */
14
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * Check and load integrations for plugins like BuddyPress or BuddyBoss.
23 *
24 * This function checks if the BuddyPress or BuddyBoss plugin is active
25 * and, if so, includes the necessary integration file for compatibility.
26 *
27 * @return void
28 */
29 function wpstream_check_integrations() {
30 // Check if the BuddyPress or BuddyBoss class exists, indicating the plugin is active.
31 if (class_exists('BuddyPress')) {
32 // Include the integration file for BuddyBoss compatibility.
33 require plugin_dir_path( __FILE__ ) . 'buddyboss/buddyboss.php';
34 }
35 }
36
37
38
39
40 /**
41 * Get live events for the logged-in user.
42 *
43 * This function retrieves the live event associated with the current logged-in user.
44 * It first checks if the event data is cached in a transient to avoid redundant processing.
45 * If no cached data is found, it retrieves the live event data using the wpstream plugin
46 * and stores it in a transient for 10 minutes.
47 *
48 * @return mixed The live event data for the logged-in user.
49 */
50 function wpestream_integrations_get_current_user_live_events() {
51 // Check if the live event data is cached in a transient.
52 $live_event_for_user = get_transient('wpstream_bb_get_live_event_for_user');
53 global $wpstream_plugin;
54
55 // If no cached data is found, fetch the live event data.
56 if ($live_event_for_user === false) {
57 $live_event_for_user = $wpstream_plugin->main->wpstream_live_connection->wpstream_get_live_event_for_user();
58
59 // Cache the live event data in a transient for 10 minutes.
60 set_transient('wpstream_bb_get_live_event_for_user', $live_event_for_user, 600);
61 }
62
63 // Return the live event data for the logged-in user.
64 return $live_event_for_user;
65 }
66
67 if ( ! function_exists('wpstream_get_live_tag_html' ) ) {
68 /**
69 * Check if a product is live and return the live tag HTML if applicable.
70 *
71 * @param int $post_id The ID of the post.
72 * @return string The HTML for the live tag or an empty string.
73 */
74 function wpstream_get_live_tag_html($post_id)
75 {
76 // Only WooCommerce live-stream products or native wpstream_product posts can be "live".
77 if ((get_post_type($post_id) === 'product' && has_term('live_stream', 'product_type', $post_id)) || get_post_type($post_id) === 'wpstream_product') {
78 // Pull the current user's live events so we can test membership.
79 $live_events = wpestream_integrations_get_current_user_live_events();
80 // If this post is among the live events, emit the "LIVE" badge markup.
81 if (is_array($live_events) && array_key_exists($post_id, $live_events)) {
82 return '<div class="wpstream_featured_image_live_tag">' . esc_html_x('LIVE', 'Card tag', 'wpstream') . '</div>';
83 }
84 }
85 // Not a live post (or no live event matched): render nothing.
86 return '';
87 }
88 }
89
90 ?>