| @@ -1,9 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 2 | +/** | |
| 3 | + * Check and load integrations for plugins like BuddyPress or BuddyBoss. | |
| 4 | + * | |
| 5 | + * This function checks if the BuddyPress or BuddyBoss plugin is active | |
| 6 | + * and, if so, includes the necessary integration file for compatibility. | |
| 7 | + * | |
| 8 | + * @return void | |
| 9 | + */ | |
| 3 | 10 | function wpstream_check_integrations() { |
| 11 | + // Check if the BuddyPress or BuddyBoss class exists, indicating the plugin is active. | |
| 4 | 12 | if (class_exists('BuddyPress')) { |
| 5 | - require plugin_dir_path( __FILE__ ) . 'buddyboss/buddyboss.php'; | |
| 13 | + // Include the integration file for BuddyBoss compatibility. | |
| 14 | + require plugin_dir_path( __FILE__ ) . 'buddyboss/buddyboss.php'; | |
| 6 | 15 | } |
| 7 | 16 | } |
| 8 | 17 | |
| 9 | 18 | |
| @@ -8,26 +17,52 @@ | ||
| 8 | 17 | |
| 9 | 18 | |
| 10 | 19 | |
| 11 | 20 | |
| 12 | -/* | |
| 13 | -* | |
| 14 | -* Get live events for logged in user | |
| 15 | -* | |
| 16 | -*/ | |
| 21 | +/** | |
| 22 | + * Get live events for the logged-in user. | |
| 23 | + * | |
| 24 | + * This function retrieves the live event associated with the current logged-in user. | |
| 25 | + * It first checks if the event data is cached in a transient to avoid redundant processing. | |
| 26 | + * If no cached data is found, it retrieves the live event data using the wpstream plugin | |
| 27 | + * and stores it in a transient for 10 minutes. Optionally, it can exit after fetching the data. | |
| 28 | + * | |
| 29 | + * @param string $with_exit Optional. Whether to exit after retrieving live events. Defaults to 'yes'. | |
| 30 | + * @return mixed The live event data for the logged-in user. | |
| 31 | + */ | |
| 32 | +function wpestream_integrations_get_current_user_live_events($with_exit = 'yes') { | |
| 33 | + // Check if the live event data is cached in a transient. | |
| 34 | + $live_event_for_user = get_transient('wpstream_bb_get_live_event_for_user'); | |
| 35 | + global $wpstream_plugin; | |
| 17 | 36 | |
| 18 | -function wpestream_integrations_get_current_user_live_events(){ | |
| 19 | - $live_event_for_user = get_transient('wpstream_bb_get_live_event_for_user'); | |
| 37 | + // If no cached data is found, fetch the live event data. | |
| 38 | + if ($live_event_for_user === false) { | |
| 39 | + $live_event_for_user = $wpstream_plugin->main->wpstream_live_connection->wpstream_get_live_event_for_user($with_exit); | |
| 20 | 40 | |
| 21 | - if($live_event_for_user===false){ | |
| 22 | - $live_event_for_user = $wpstream_plugin->main->wpstream_live_connection->wpstream_get_live_event_for_user(); | |
| 23 | - set_transient('wpstream_bb_get_live_event_for_user',$live_event_for_user,600); | |
| 41 | + // Cache the live event data in a transient for 10 minutes. | |
| 42 | + set_transient('wpstream_bb_get_live_event_for_user', $live_event_for_user, 600); | |
| 24 | 43 | } |
| 25 | 44 | |
| 45 | + // Return the live event data for the logged-in user. | |
| 26 | 46 | return $live_event_for_user; |
| 27 | - | |
| 28 | 47 | } |
| 29 | 48 | |
| 30 | - | |
| 31 | - | |
| 49 | +if ( ! function_exists('wpstream_get_live_tag_html' ) ) { | |
| 50 | + /** | |
| 51 | + * Check if a product is live and return the live tag HTML if applicable. | |
| 52 | + * | |
| 53 | + * @param int $post_id The ID of the post. | |
| 54 | + * @return string The HTML for the live tag or an empty string. | |
| 55 | + */ | |
| 56 | + function wpstream_get_live_tag_html($post_id) | |
| 57 | + { | |
| 58 | + if ((get_post_type($post_id) === 'product' && has_term('live_stream', 'product_type', $post_id)) || get_post_type($post_id) === 'wpstream_product') { | |
| 59 | + $live_events = wpestream_integrations_get_current_user_live_events('no'); | |
| 60 | + if (is_array($live_events) && array_key_exists($post_id, $live_events)) { | |
| 61 | + return '<div class="wpstream_featured_image_live_tag">' . esc_html_x('LIVE', 'Card tag', 'hello-wpstream') . '</div>'; | |
| 62 | + } | |
| 63 | + } | |
| 64 | + return ''; | |
| 65 | + } | |
| 66 | +} | |
| 32 | 67 | |
| 33 | 68 | ?> |