Last active
January 24, 2025 07:18
-
-
Save wpmudev-sls/688888dd84d21c164a6feb470088ec46 to your computer and use it in GitHub Desktop.
[Smartcrawl Pro] - Fix missing og image on groups page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Smartcrawl Pro] Fix missing og images on groups | |
* Description: Fix missing og images on groups. | |
* Author: Prashant @ WPMUDEV | |
* Task: SMA-67 | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
/** | |
* Fixes missing og images on groups pages. | |
* | |
* @param array $filtered_value Opengraph images. | |
*/ | |
function wpmudev_fix_group_cover_image_og( $filtered_value ) { | |
if ( ! empty( $filtered_value ) ) { | |
return $filtered_value; | |
} | |
if ( ! function_exists( 'bp_is_groups_component' ) ) { | |
return $filtered_value; | |
} | |
if ( bp_is_groups_component() ) { | |
$group_id = bp_get_current_group_id(); | |
if ( ! empty( $group_id ) ) { | |
$cover_image = bp_attachments_get_attachment( | |
'url', | |
array( | |
'object_dir' => 'groups', | |
'item_id' => $group_id, | |
) | |
); | |
if ( ! empty( $cover_image ) ) { | |
$filtered_value[] = array( $cover_image ); | |
} | |
} | |
} | |
return $filtered_value; | |
} | |
add_filter( 'smartcrawl_get_opengraph_images', 'wpmudev_fix_group_cover_image_og' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment