From 5952c06c59efa92cac0f2d4a8d2962235fb7b5c2 Mon Sep 17 00:00:00 2001 From: yuriinalivaiko Date: Sun, 19 Jan 2025 14:58:59 +0200 Subject: [PATCH] Task CU-86cxq9tuk - changed Open Graph image size. --- includes/core/um-actions-profile.php | 62 ++++++++++++++++------------ 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index dfd07abf..4735798e 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -672,24 +672,6 @@ function um_profile_dynamic_meta_desc() { $description = um_convert_tags( UM()->options()->get( 'profile_desc' ) ); $url = um_user_profile_url( $user_id ); - /** - * Filters the profile SEO image size. Default 190. Available 'original'. - * - * @param {string} $image_size Image size. - * @param {int} $user_id User ID. - * - * @return {array} Changed image type - * - * @since 2.5.5 - * @hook um_profile_dynamic_meta_image_size - * - * @example Change meta image to cover photo `cover_photo`. - * function my_um_profile_dynamic_meta_image_size( $image_size, $user_id ) { - * return 'original'; - * } - * add_filter( 'um_profile_dynamic_meta_image_size', 'my_um_profile_dynamic_meta_image_size', 10, 2 ); - */ - $image_size = apply_filters( 'um_profile_dynamic_meta_image_size', 190, $user_id ); /** * Filters the profile SEO image type. Default 'profile_photo'. Available 'cover_photo', 'profile_photo'. * @@ -709,6 +691,29 @@ function um_profile_dynamic_meta_desc() { */ $image_type = apply_filters( 'um_profile_dynamic_meta_image_type', 'profile_photo', $user_id ); + // The minimum size is 200 x 200 px, however, we recommend keeping it to 600 x 315 px. + // If your image is smaller than 600 x 315 pixels, it will appear as a small image in the link preview. + $image_size_def = 'cover_photo' === $image_type ? 600 : 200; + + /** + * Filters the profile SEO image size. Default 190. Available 'original'. + * + * @param {string} $image_size Image size. + * @param {int} $user_id User ID. + * + * @return {array} Changed image type + * + * @since 2.5.5 + * @hook um_profile_dynamic_meta_image_size + * + * @example Change meta image to cover photo `cover_photo`. + * function my_um_profile_dynamic_meta_image_size( $image_size, $user_id ) { + * return 'original'; + * } + * add_filter( 'um_profile_dynamic_meta_image_size', 'my_um_profile_dynamic_meta_image_size', 10, 2 ); + */ + $image_size = apply_filters( 'um_profile_dynamic_meta_image_size', $image_size_def, $user_id ); + if ( 'cover_photo' === $image_type ) { if ( is_numeric( $image_size ) ) { $sizes = UM()->options()->get( 'cover_thumb_sizes' ); @@ -730,10 +735,17 @@ function um_profile_dynamic_meta_desc() { } $image = current( explode( '?', $image ) ); // strip $_GET attributes from photo URL. - $image_url = wp_parse_url( $image ); - $image_name = explode( '/', $image_url['path'] ); - $image_name = end( $image_name ); - $image_info = wp_check_filetype( $image_name ); + $image_path = wp_normalize_path( ABSPATH . wp_parse_url( $image, PHP_URL_PATH ) ); + $image_info = wp_check_filetype( $image_path ); + + $imagesizes = getimagesize( $image_path ); + if ( is_array( $imagesizes ) ) { + $image_width = $imagesizes[0]; + $image_height = $imagesizes[1]; + } else { + $image_width = $image_size; + $image_height = $image_size; + } $person = array( '@context' => 'https://schema.org', @@ -796,10 +808,8 @@ function um_profile_dynamic_meta_desc() { - - - - + +