diff --git a/README.md b/README.md index 70ff3f11c..6a2029df6 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,12 @@ https://www.youtube.com/watch?v=dJrykKQGDcs ## Changelog ## +### 4.7.1 + +* FIXED + * Fixed a critical error related to inline annotations on certain themes. + * Resolved shimmering issue for newly uploaded media on the BuddyPress Groups page when GoDAM is active. + ### 4.7.0 * ENHANCEMENTS diff --git a/app/assets/js/godam-integration.js b/app/assets/js/godam-integration.js index f30b940d6..cb5299c4f 100644 --- a/app/assets/js/godam-integration.js +++ b/app/assets/js/godam-integration.js @@ -62,7 +62,8 @@ document.addEventListener('DOMContentLoaded', () => { initializePopupVideos(); } - if (node.classList?.contains('activity')) { + // Check for either 'activity' or 'groups' class. + if (node.classList?.contains('activity') || node.classList?.contains('groups')) { setTimeout(() => safeGODAMPlayer(node), 100); } } diff --git a/app/assets/js/godam-integration.min.js b/app/assets/js/godam-integration.min.js index 6d059872d..5a0727ecf 100644 --- a/app/assets/js/godam-integration.min.js +++ b/app/assets/js/godam-integration.min.js @@ -1 +1 @@ -const safeGODAMPlayer=(e=null)=>{try{return e&&1===e.nodeType&&e.isConnected?GODAMPlayer(e):GODAMPlayer(),!0}catch(e){return!1}};safeGODAMPlayer();let popupInitTimeout=null;const initializePopupVideos=()=>{clearTimeout(popupInitTimeout),popupInitTimeout=setTimeout((()=>{const e=document.querySelector(".mfp-content");if(e){e.querySelectorAll("video").length>0&&(safeGODAMPlayer(e)||safeGODAMPlayer())}}),200)};document.addEventListener("DOMContentLoaded",(()=>{safeGODAMPlayer();new MutationObserver((e=>{for(const t of e)for(const e of t.addedNodes)if(1===e.nodeType){const t=e.classList?.contains("mfp-content")||e.querySelector?.(".mfp-content"),o="VIDEO"===e.tagName||e.querySelector?.("video");(t||o&&e.closest(".mfp-content"))&&initializePopupVideos(),e.classList?.contains("activity")&&setTimeout((()=>safeGODAMPlayer(e)),100)}})).observe(document.body,{childList:!0,subtree:!0}),"undefined"!=typeof $&&$.magnificPopup&&($(document).on("mfpOpen mfpChange",(()=>{initializePopupVideos()})),$(document).on("mfpOpen",(()=>{setTimeout(initializePopupVideos,500)})))})); \ No newline at end of file +const safeGODAMPlayer=(e=null)=>{try{return e&&1===e.nodeType&&e.isConnected?GODAMPlayer(e):GODAMPlayer(),!0}catch(e){return!1}};safeGODAMPlayer();let popupInitTimeout=null;const initializePopupVideos=()=>{clearTimeout(popupInitTimeout),popupInitTimeout=setTimeout((()=>{const e=document.querySelector(".mfp-content");if(e){e.querySelectorAll("video").length>0&&(safeGODAMPlayer(e)||safeGODAMPlayer())}}),200)};document.addEventListener("DOMContentLoaded",(()=>{safeGODAMPlayer();new MutationObserver((e=>{for(const t of e)for(const e of t.addedNodes)if(1===e.nodeType){const t=e.classList?.contains("mfp-content")||e.querySelector?.(".mfp-content"),o="VIDEO"===e.tagName||e.querySelector?.("video");(t||o&&e.closest(".mfp-content"))&&initializePopupVideos(),(e.classList?.contains("activity")||e.classList?.contains("groups"))&&setTimeout((()=>safeGODAMPlayer(e)),100)}})).observe(document.body,{childList:!0,subtree:!0}),"undefined"!=typeof $&&$.magnificPopup&&($(document).on("mfpOpen mfpChange",(()=>{initializePopupVideos()})),$(document).on("mfpOpen",(()=>{setTimeout(initializePopupVideos,500)})))})); \ No newline at end of file diff --git a/app/main/RTMedia.php b/app/main/RTMedia.php index 2efc61ff6..f5018232c 100755 --- a/app/main/RTMedia.php +++ b/app/main/RTMedia.php @@ -1267,7 +1267,7 @@ public function enqueue_scripts_styles() { 'rtmedia-emoji-picker', ), RTMEDIA_VERSION, - args: true + true ); } else { wp_enqueue_script( diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php index a2c53b6b7..f919646c9 100644 --- a/app/main/controllers/template/rtmedia-functions.php +++ b/app/main/controllers/template/rtmedia-functions.php @@ -593,23 +593,20 @@ function rtmedia_media( $size_flag = true, $echo = true, $media_size = 'rt_media // Check if Godam plugin is active. if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) { $html .= do_shortcode( '[godam_video id="' . esc_attr( $rtmedia_media->media_id ) . '"]' ); + } elseif ( empty( $youtube_url ) ) { + $html .= sprintf( + '', + esc_url( ! empty( $rtmedia_media->cover_art ) ? $rtmedia_media->cover_art : '' ), + esc_url( wp_get_attachment_url( $rtmedia_media->media_id ) ), + $size_attr, + esc_attr( $rtmedia_media->id ) + ); } else { - // Fallback to native or YouTube player. - if ( empty( $youtube_url ) ) { - $html .= sprintf( - '', - esc_url( $rtmedia_media->cover_art ?: '' ), - esc_url( wp_get_attachment_url( $rtmedia_media->media_id ) ), - $size_attr, - esc_attr( $rtmedia_media->id ) - ); - } else { - $html .= sprintf( - '', - esc_attr( $rtmedia_media->id ), - esc_url( $youtube_url ) - ); - } + $html .= sprintf( + '', + esc_attr( $rtmedia_media->id ), + esc_url( $youtube_url ) + ); } $html .= ''; @@ -997,7 +994,7 @@ function rtmedia_delete_allowed() { global $rtmedia_media; $flag = false; - if ( $rtmedia_media !== null && isset( $rtmedia_media->media_author ) ) { + if ( null !== $rtmedia_media && isset( $rtmedia_media->media_author ) ) { $flag = intval( $rtmedia_media->media_author ) === get_current_user_id(); } if ( ! $flag && isset( $rtmedia_media->context ) && 'group' === $rtmedia_media->context && function_exists( 'bp_group_is_admin' ) ) { @@ -1025,7 +1022,7 @@ function rtmedia_edit_allowed() { global $rtmedia_media; $flag = false; - if ( $rtmedia_media !== null && isset( $rtmedia_media->media_author ) ) { + if ( null !== $rtmedia_media && isset( $rtmedia_media->media_author ) ) { $flag = intval( $rtmedia_media->media_author ) === get_current_user_id(); } if ( ! $flag ) { @@ -1482,13 +1479,13 @@ function rmedia_single_comment( $comment, $count = false, $i = false ) { if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) { global $wpdb; - // Replace all tags with ID pattern rt_media_video_{id} + // Replace all tags with ID pattern rt_media_video_{id}. $html = preg_replace_callback( '#]*id="rt_media_video_(\d+)"[^>]*>.*?#is', - function( $matches ) use ( $wpdb ) { - $extracted_id = intval( $matches[1] ); // Extract numeric ID from video tag + function ( $matches ) use ( $wpdb ) { + $extracted_id = intval( $matches[1] ); // Extract numeric ID from video tag. - // Fetch media_id from rt_rtm_media table using the extracted ID + // Fetch media_id from rt_rtm_media table using the extracted ID. $media_id = $wpdb->get_var( $wpdb->prepare( "SELECT media_id FROM {$wpdb->prefix}rt_rtm_media WHERE id = %d", @@ -1496,7 +1493,7 @@ function( $matches ) use ( $wpdb ) { ) ); - // If media_id exists, return Godam video shortcode + // If media_id exists, return Godam video shortcode. if ( ! empty( $media_id ) ) { return '' . '' @@ -1504,7 +1501,7 @@ function( $matches ) use ( $wpdb ) { . ''; } - // If no media_id found, return original video HTML + // If no media_id found, return original video HTML. return $matches[0]; }, $html @@ -5233,6 +5230,14 @@ function rtmedia_like_eraser( $email_address, $page = 1 ) { */ add_action( 'wp_enqueue_scripts', 'enqueue_scripts_globally', 20 ); + /** + * Enqueues all necessary frontend scripts and styles globally for the Godam player. + * + * This includes the player script, analytics script, and both frontend and core styles. + * Intended to be called on every page load where the player may be used. + * + * @return void + */ function enqueue_scripts_globally() { wp_enqueue_script( 'godam-player-frontend-script' ); wp_enqueue_script( 'godam-player-analytics-script' ); @@ -5243,130 +5248,141 @@ function enqueue_scripts_globally() { /** * Enqueue frontend scripts for Godam integration and AJAX refresh. */ - add_action( 'wp_enqueue_scripts', function() { - - // Enqueue integration script for rtMedia and Godam. - wp_enqueue_script( - 'godam-rtmedia-integration', - RTMEDIA_URL . 'app/assets/js/godam-integration.min.js', - [ 'godam-player-frontend-script' ], - null, - true - ); + add_action( + 'wp_enqueue_scripts', + function () { + + // Enqueue integration script for rtMedia and Godam. + wp_enqueue_script( + 'godam-rtmedia-integration', + RTMEDIA_URL . 'app/assets/js/godam-integration.min.js', + array( 'godam-player-frontend-script' ), + null, + true + ); - // Enqueue the script responsible for AJAX-based comment refresh. - wp_enqueue_script( - 'godam-ajax-refresh', - RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.min.js', - [], - null, - true - ); + // Enqueue the script responsible for AJAX-based comment refresh. + wp_enqueue_script( + 'godam-ajax-refresh', + RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.min.js', + array(), + null, + true + ); - // Pass AJAX URL and nonce to the script. - wp_localize_script( 'godam-ajax-refresh', 'GodamAjax', [ - 'ajax_url' => admin_url( 'admin-ajax.php' ), - 'nonce' => wp_create_nonce( 'godam-ajax-nonce' ), - ]); - } ); + // Pass AJAX URL and nonce to the script. + wp_localize_script( + 'godam-ajax-refresh', + 'GodamAjax', + array( + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'nonce' => wp_create_nonce( 'godam-ajax-nonce' ), + ) + ); + } + ); /** * Filter BuddyPress activity content to replace rtMedia video list * with Godam player shortcodes. */ - add_filter( 'bp_get_activity_content_body', function( $content ) { - global $activities_template; - - // Bail early if activity object is not available - if ( empty( $activities_template->activity ) || ! is_object( $activities_template->activity ) ) { - return $content; - } - - $activity = $activities_template->activity; - - // Allow only certain activity types - $valid_types = [ 'rtmedia_update', 'activity_update', 'activity_comment' ]; - if ( ! isset( $activity->type ) || ! in_array( $activity->type, $valid_types, true ) ) { - return $content; - } - - // Ensure RTMediaModel class exists - if ( ! class_exists( 'RTMediaModel' ) ) { - return $content; - } - - $model = new RTMediaModel(); - $media_items = $model->get( [ 'activity_id' => $activity->id ] ); + add_filter( + 'bp_get_activity_content_body', + function ( $content ) { + global $activities_template; + + // Bail early if activity object is not available. + if ( empty( $activities_template->activity ) || ! is_object( $activities_template->activity ) ) { + return $content; + } - if ( empty( $media_items ) || ! is_array( $media_items ) ) { - return $content; - } + $activity = $activities_template->activity; - // Remove rtMedia default video - $clean_content = preg_replace( - '#]*class="[^"]*rtmedia-list[^"]*rtm-activity-media-list[^"]*rtmedia-activity-media-length-[0-9]+[^"]*rtm-activity-video-list[^"]*"[^>]*>.*?#si', - '', - $activity->content - ); + // Allow only certain activity types. + $valid_types = array( 'rtmedia_update', 'activity_update', 'activity_comment' ); + if ( ! isset( $activity->type ) || ! in_array( $activity->type, $valid_types, true ) ) { + return $content; + } - // Group media by type - $grouped_media = []; - foreach ( $media_items as $media ) { - $grouped_media[ $media->media_type ][] = $media; - } + // Ensure RTMediaModel class exists. + if ( ! class_exists( 'RTMediaModel' ) ) { + return $content; + } - $godam_videos = ''; + $model = new RTMediaModel(); + $media_items = $model->get( array( 'activity_id' => $activity->id ) ); - // Build Godam player shortcodes for videos - if ( ! empty( $grouped_media['video'] ) ) { - foreach ( $grouped_media['video'] as $index => $video ) { - $player_id = 'godam-activity-' . esc_attr( $activity->id ) . '-' . $index; - $godam_videos .= do_shortcode( - '[godam_video id="' . esc_attr( $video->media_id ) . - '" context="buddypress" player_id="' . esc_attr( $player_id ) . '"]' - ); + if ( empty( $media_items ) || ! is_array( $media_items ) ) { + return $content; } - } - // Process video media in activity comments - if ( ! empty( $activity->children ) && is_array( $activity->children ) ) { - foreach ( $activity->children as $child ) { - $child_media = $model->get( [ 'activity_id' => $child->id ] ); + // Remove rtMedia default video . + $clean_content = preg_replace( + '#]*class="[^"]*rtmedia-list[^"]*rtm-activity-media-list[^"]*rtmedia-activity-media-length-[0-9]+[^"]*rtm-activity-video-list[^"]*"[^>]*>.*?#si', + '', + $activity->content + ); - if ( empty( $child_media ) ) { - continue; - } + // Group media by type. + $grouped_media = array(); + foreach ( $media_items as $media ) { + $grouped_media[ $media->media_type ][] = $media; + } - $child_videos = ''; + $godam_videos = ''; - foreach ( $child_media as $index => $video ) { - $player_id = 'godam-comment-' . esc_attr( $child->id ) . '-' . $index; - $child_videos .= do_shortcode( - '[godam_video id="' . esc_attr( $video->media_id ) . '"]' + // Build Godam player shortcodes for videos. + if ( ! empty( $grouped_media['video'] ) ) { + foreach ( $grouped_media['video'] as $index => $video ) { + $player_id = 'godam-activity-' . esc_attr( $activity->id ) . '-' . $index; + $godam_videos .= do_shortcode( + '[godam_video id="' . esc_attr( $video->media_id ) . + '" context="buddypress" player_id="' . esc_attr( $player_id ) . '"]' ); } + } - if ( $child_videos ) { - // Remove rtMedia from comment - $child->content = preg_replace( - '#]*class="[^"]*rtmedia-list[^"]*rtm-activity-media-list[^"]*rtmedia-activity-media-length-[0-9]+[^"]*rtm-activity-video-list[^"]*"[^>]*>.*?#si', - '', - $child->content - ); - - // Append Godam video players - $child->content .= '' . $child_videos . ''; + // Process video media in activity comments. + if ( ! empty( $activity->children ) && is_array( $activity->children ) ) { + foreach ( $activity->children as $child ) { + $child_media = $model->get( array( 'activity_id' => $child->id ) ); + + if ( empty( $child_media ) ) { + continue; + } + + $child_videos = ''; + + foreach ( $child_media as $index => $video ) { + $player_id = 'godam-comment-' . esc_attr( $child->id ) . '-' . $index; + $child_videos .= do_shortcode( + '[godam_video id="' . esc_attr( $video->media_id ) . '"]' + ); + } + + if ( $child_videos ) { + // Remove rtMedia from comment. + $child->content = preg_replace( + '#]*class="[^"]*rtmedia-list[^"]*rtm-activity-media-list[^"]*rtmedia-activity-media-length-[0-9]+[^"]*rtm-activity-video-list[^"]*"[^>]*>.*?#si', + '', + $child->content + ); + + // Append Godam video players. + $child->content .= '' . $child_videos . ''; + } } } - } - // Final video output appended to cleaned content - if ( $godam_videos ) { - $godam_videos = '' . $godam_videos . ''; - } + // Final video output appended to cleaned content. + if ( $godam_videos ) { + $godam_videos = '' . $godam_videos . ''; + } - return wp_kses_post( $clean_content ) . $godam_videos; - }, 10 ); + return wp_kses_post( $clean_content ) . $godam_videos; + }, + 10 + ); /** * Handle AJAX request for loading a single activity comment's HTML. @@ -5374,6 +5390,14 @@ function enqueue_scripts_globally() { add_action( 'wp_ajax_get_single_activity_comment_html', 'handle_get_single_activity_comment_html' ); add_action( 'wp_ajax_nopriv_get_single_activity_comment_html', 'handle_get_single_activity_comment_html' ); + /** + * AJAX handler to fetch and return the HTML for a single activity comment. + * + * Validates the request, loads the activity comment by ID, + * renders its HTML using the BuddyPress template, and returns it in a JSON response. + * + * @return void Outputs JSON response with rendered HTML or error message. + */ function handle_get_single_activity_comment_html() { check_ajax_referer( 'godam-ajax-nonce', 'nonce' ); @@ -5390,10 +5414,10 @@ function handle_get_single_activity_comment_html() { global $activities_template; - // Backup original activity + // Backup original activity. $original_activity = $activities_template->activity ?? null; - // Replace global for template rendering + // Replace global for template rendering. $activities_template = new stdClass(); $activities_template->activity = $activity; @@ -5401,12 +5425,12 @@ function handle_get_single_activity_comment_html() { bp_get_template_part( 'activity/entry' ); $html = ob_get_clean(); - // Restore original + // Restore original. if ( $original_activity ) { $activities_template->activity = $original_activity; } - wp_send_json_success( [ 'html' => $html ] ); + wp_send_json_success( array( 'html' => $html ) ); } } @@ -5435,21 +5459,21 @@ function enqueue_rtmedia_magnific_popup_script() { $version = RTMEDIA_VERSION; $in_footer = true; - // Deregister the script if already registered or enqueued to prevent conflicts - if (wp_script_is($handle, 'registered') || wp_script_is($handle, 'enqueued')) { - wp_deregister_script($handle); + // Deregister the script if already registered or enqueued to prevent conflicts. + if ( wp_script_is( $handle, 'registered' ) || wp_script_is( $handle, 'enqueued' ) ) { + wp_deregister_script( $handle ); } - // Determine dependencies based on whether Godam integration is active - $dependencies = []; + // Determine dependencies based on whether Godam integration is active. + $dependencies = array(); - // If Godam plugin is NOT active, add dependencies for jQuery and mediaelement - if (!defined('RTMEDIA_GODAM_ACTIVE') || !RTMEDIA_GODAM_ACTIVE) { - $dependencies = ['jquery', 'rt-mediaelement-wp']; + // If Godam plugin is NOT active, add dependencies for jQuery and mediaelement. + if ( ! defined( 'RTMEDIA_GODAM_ACTIVE' ) || ! RTMEDIA_GODAM_ACTIVE ) { + $dependencies = array( 'jquery', 'rt-mediaelement-wp' ); } - // Enqueue the Magnific Popup script with the appropriate dependencies - wp_enqueue_script($handle, $script_src, $dependencies, $version, $in_footer); + // Enqueue the Magnific Popup script with the appropriate dependencies. + wp_enqueue_script( $handle, $script_src, $dependencies, $version, $in_footer ); } -add_action('wp_enqueue_scripts', 'enqueue_rtmedia_magnific_popup_script'); +add_action( 'wp_enqueue_scripts', 'enqueue_rtmedia_magnific_popup_script' ); diff --git a/index.php b/index.php index 558567272..6ebc7b7f3 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: rtMedia for WordPress, BuddyPress and bbPress * Plugin URI: https://rtmedia.io/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media * Description: This plugin adds missing media rich features like photos, videos and audio uploading to BuddyPress which are essential if you are building social network, seriously! - * Version: 4.7.0 + * Version: 4.7.1 * Author: rtCamp * Text Domain: buddypress-media * Author URI: http://rtcamp.com/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media @@ -19,7 +19,7 @@ /** * The version of the plugin */ - define( 'RTMEDIA_VERSION', '4.7.0' ); + define( 'RTMEDIA_VERSION', '4.7.1' ); } if ( ! defined( 'RTMEDIA_PATH' ) ) { diff --git a/readme.txt b/readme.txt index b4ea9aeb8..59d9a9eb0 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Requires at least: WordPress 4.1 Tested up to: 6.8.1 -Stable tag: 4.7.0 +Stable tag: 4.7.1 Add albums, photo, audio/video upload, privacy, sharing, front-end uploads & more. All this works on mobile/tablets devices. @@ -133,6 +133,12 @@ http://www.youtube.com/watch?v=dJrykKQGDcs == Changelog == += 4.7.1 [June 6, 2025] = + +* FIXED + * Fixed a critical error related to inline annotations on certain themes. + * Resolved shimmering issue for newly uploaded media on the BuddyPress Groups page when GoDAM is active. + = 4.7.0 [June 2, 2025] = * ENHANCEMENTS @@ -1934,6 +1940,9 @@ http://www.youtube.com/watch?v=dJrykKQGDcs == Upgrade Notice == += 4.7.1 = +Improved integration with GoDAM services and resolved a critical inline annotation error on certain themes. + = 4.7.0 = This update introduces comprehensive support for the GoDAM video player across rtMedia galleries and all BuddyPress components, including activity streams, groups, and forums.