-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21962 from Yoast/show-alert-when-avif-file-is-use…
…d-in-social-preview Show alert when avif file is used in social preview
- Loading branch information
Showing
7 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useEffect, useState } from "@wordpress/element"; | ||
import { __, sprintf } from "@wordpress/i18n"; | ||
|
||
/** | ||
* Checks if the fallback image is in AVIF format and sets a warning message. | ||
* | ||
* @param {string} imageFallbackUrl The fallback image URL. | ||
* @param {string} imageUrl The image URL. | ||
* @param {array} imageWarnings The image warnings. | ||
* | ||
* @returns {string[]} An array of warnings. | ||
*/ | ||
export const useFallbackWarning = ( imageFallbackUrl, imageUrl, imageWarnings ) => { | ||
const [ hasFallbackWarning, setHasFallbackWarning ] = useState( false ); | ||
const warningMessage = sprintf( | ||
/* Translators: %s expands to the jpg format, %s expands to the png format, %s expands to the webp format, %s expands to the gif format. */ | ||
__( | ||
"No image was found that we can automatically set as your social image. Please use %s, %s, %s or %s formats to ensure it displays correctly on social media.", | ||
"wordpress-seo" | ||
), | ||
"JPG", "PNG", "WEBP", "GIF" | ||
); | ||
useEffect( () => { | ||
setHasFallbackWarning( imageUrl === "" ? imageFallbackUrl.toLowerCase().endsWith( ".avif" ) : false ); | ||
}, [ imageFallbackUrl, imageUrl ] ); | ||
return hasFallbackWarning ? [ warningMessage ] : imageWarnings; | ||
}; |
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
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