-
Notifications
You must be signed in to change notification settings - Fork 27
feat: can now embed youtube videos and shorts #1109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Plugin build for 6ea271a is ready 🛎️!
Note You can preview the changes in the Playground |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for embedding YouTube videos and shorts in RSS feed imports for free users. The implementation extracts YouTube video descriptions from RSS feeds and automatically embeds the videos using WordPress shortcodes.
- Adds a new method to handle YouTube-specific content processing
- Extracts video descriptions from YouTube RSS feeds using media RSS namespace
- Automatically appends embed shortcodes for YouTube URLs
// remove all dots in the hostname so that shortforms such as youtu.be can also be resolved. | ||
$host = str_replace( array( '.', 'www' ), '', $host ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string replacement logic is flawed. Removing 'www' as a substring will affect other parts of the hostname (e.g., 'wwwexample.com' becomes 'example.com'). Use a more precise approach like preg_replace('/^www\./', '', $host)
after removing dots.
// remove all dots in the hostname so that shortforms such as youtu.be can also be resolved. | |
$host = str_replace( array( '.', 'www' ), '', $host ); | |
// Remove the 'www.' prefix from the hostname if it exists. | |
$host = preg_replace( '/^www\./', '', $host ); | |
// Remove all dots in the hostname so that shortforms such as youtu.be can also be resolved. | |
$host = str_replace( '.', '', $host ); |
Copilot uses AI. Check for mistakes.
// remove all dots in the hostname so that shortforms such as youtu.be can also be resolved. | ||
$host = str_replace( array( '.', 'www' ), '', $host ); | ||
|
||
// youtube. | ||
if ( in_array( $host, array( 'youtubecom', 'youtube' ), true ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hostname check is incomplete. After removing dots, 'youtu.be' becomes 'youtube', but 'youtube.com' becomes 'youtubecom'. You should also include 'youtube' (for youtu.be) in the array or use a different approach to handle both domains properly.
// remove all dots in the hostname so that shortforms such as youtu.be can also be resolved. | |
$host = str_replace( array( '.', 'www' ), '', $host ); | |
// youtube. | |
if ( in_array( $host, array( 'youtubecom', 'youtube' ), true ) ) { | |
// Normalize the hostname by removing 'www.' if present. | |
$host = preg_replace( '/^www\./', '', $host ); | |
// Check if the hostname matches any valid YouTube domains. | |
if ( in_array( $host, array( 'youtube.com', 'youtu.be' ), true ) ) { |
Copilot uses AI. Check for mistakes.
$item_array['item_content'] = $desc; | ||
} | ||
if ( ( empty( $sc ) || 'yes' === $sc['summary'] ) && empty( $item_array['item_description'] ) ) { | ||
if ( is_numeric( $sc['summarylength'] ) && strlen( $desc ) > $sc['summarylength'] ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code assumes $sc['summarylength']
exists when $sc
is not empty, but there's no validation that this key exists in the array. This could cause a PHP notice or error if the key is missing.
if ( is_numeric( $sc['summarylength'] ) && strlen( $desc ) > $sc['summarylength'] ) { | |
if ( isset( $sc['summarylength'] ) && is_numeric( $sc['summarylength'] ) && strlen( $desc ) > $sc['summarylength'] ) { |
Copilot uses AI. Check for mistakes.
if ( str_contains( $item_array['item_content'], 'Post Content' ) ) { | ||
$item_array['item_content'] = '[embed]' . $url . '[/embed]' ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic string 'Post Content' appears to be a hardcoded check for some default content. This should be defined as a constant or documented to explain what this specific string represents and why it's being checked.
if ( str_contains( $item_array['item_content'], 'Post Content' ) ) { | |
$item_array['item_content'] = '[embed]' . $url . '[/embed]' ; | |
if ( str_contains( $item_array['item_content'], self::DEFAULT_ITEM_CONTENT ) ) { | |
$item_array['item_content'] = '[embed]' . $url . '[/embed]'; |
Copilot uses AI. Check for mistakes.
} | ||
} | ||
if ( str_contains( $item_array['item_content'], 'Post Content' ) ) { | ||
$item_array['item_content'] = '[embed]' . $url . '[/embed]' ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space before the semicolon. Should be [/embed]';
instead of [/embed]' ;
$item_array['item_content'] = '[embed]' . $url . '[/embed]' ; | |
$item_array['item_content'] = '[embed]' . $url . '[/embed]'; |
Copilot uses AI. Check for mistakes.
d6368b9
to
6ea271a
Compare
Summary
embed
instead ofvideo
shortcode sinceembed
has support for YouTube shorts.Will affect visual aspect of the product
YES
Screenshots
Test instructions
Check before Pull Request is ready:
Closes https://github.com/Codeinwp/feedzy-rss-feeds-pro/issues/841