Skip to content
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

[rt_media attachment_id=XX] short does not work #139

Open
kjnanda opened this issue Mar 26, 2020 · 2 comments
Open

[rt_media attachment_id=XX] short does not work #139

kjnanda opened this issue Mar 26, 2020 · 2 comments
Assignees
Labels
Milestone

Comments

@kjnanda
Copy link

kjnanda commented Mar 26, 2020

Using this shortcode does not show anything and throws PHP Notice for Undefined variable: media_url

Please check this screenshot.

rtTranscoder_Shortcode_–_krupa-transcoder_dev2_rt_gw

@Pathan-Amaankhan
Copy link
Member

Pathan-Amaankhan commented Jan 31, 2023

I tried replicating this issue but was unable to replicate it for audio & video attachments but was able to replicate this error for image type attachments.

After further investigation found that the rt_media shortcode does not support image type attachments as there is no generation of output if we pass the id of the image type attachment as attachment_id.

function rt_media_shortcode( $attrs, $content = '' ) {
if ( empty( $attrs['attachment_id'] ) ) {
return false;
}
$attachment_id = $attrs['attachment_id'];
$type = get_post_mime_type( $attachment_id );
if ( empty( $type ) ) {
return false;
}
$mime_type = explode( '/', $type );
if ( 'video' === $mime_type[0] ) {
$video_shortcode_attributes = '';
$media_url = rtt_get_media_url( $attachment_id );
$poster = rt_media_get_video_thumbnail( $attachment_id );
$attrs['src'] = $media_url;
$attrs['poster'] = $poster;
foreach ( $attrs as $key => $value ) {
$video_shortcode_attributes .= ' ' . $key . '="' . $value . '"';
}
$content = do_shortcode( "[video {$video_shortcode_attributes}]" );
} elseif ( 'audio' === $mime_type[0] ) {
$media_url = rtt_get_media_url( $attachment_id, 'mp3' );
$audio_shortcode_attributes = 'src="' . $media_url . '"';
foreach ( $attrs as $key => $value ) {
$audio_shortcode_attributes .= ' ' . $key . '="' . $value . '"';
}
$content = do_shortcode( "[audio {$audio_shortcode_attributes}]" );
}
if ( is_file_being_transcoded( $attachment_id ) ) {
$content .= '<p class="transcoding-in-progress"> ' . esc_html__( 'This file is being transcoded. Please wait.', 'transcoder' ) . '</p>';
}
/**
* Allow user to filter [rt_media] short code content.
*
* @since 1.0.0
*
* @param string $content Activity content.
* @param int $attachment_id ID of attachment.
* @param string $media_url URL of the media.
* @param string $media_type Mime type of the media.
*/
return apply_filters( 'rt_media_shortcode', $content, $attachment_id, $media_url, $mime_type[0] );
}
add_shortcode( 'rt_media', 'rt_media_shortcode' );

@gagan0123 please let me know if this functionality is working as it should and if are we going to extend the functionality for image-type attachments also.

cc: @aviral-mittal

@gagan0123
Copy link
Member

@Pathan-Amaankhan

Image type attachments are not supposed to be handled as of now, but still lets display a translatable message saying "Image attachments are not handled by Transcoder plugin."

Apart from that, handle the "Undefined variable: media_url" notice as well, by passing the correct media URL, as any third party plugin that want to handle image attachments as well can still make use of the filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants