Opened 6 years ago
Last modified 6 years ago
#45377 new defect (bug)
Video Shortcode Ajax Issue
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | minor | Version: | 5.0 |
Component: | Shortcodes | Keywords: | |
Focuses: | Cc: |
Description
Hi guys,
I have the problem with wp_video_shortcode element settings on ajax trigger, where defaults_atts variable override settings I forward to shortcode. Because is_admin() conditional inside shortcode function return true on ajax calling.
Example code
<div class="video-player-element"> <?php // Get video meta src $video_meta = get_post_meta( get_the_ID(), 'video_player_src', true ); // Video player settings $settings = apply_filters( 'video_player_settings', array( 'width' => 1300, // Aspect ration is 16:9 'height' => 731, 'loop' => true ) ); // Init video player echo wp_video_shortcode( array_merge( array( 'src' => esc_url( $video_meta ) ), $settings ) ); ?> </div>
When I call ajax to load the new content on frontend, video player element is loaded with my settings but on rendering video, wp_video_shortcode function override my settings with default because function enters inside this conditional
if ( is_admin() ) { // shrink the video so it isn't huge in the admin if ( $atts['width'] > $defaults_atts['width'] ) { $atts['height'] = round( ( $atts['height'] * $defaults_atts['width'] ) / $atts['width'] ); $atts['width'] = $defaults_atts['width']; } }
Is there any solutions to skip this check, or if you add some filter around defaults_atts so I can be able to change that values? Thanks for your solutions
Best regards,
Nenad
Change History (5)
#2
@
6 years ago
Hi swissspidly,
Thanks for your response. This might be one solution, but if anyone what to use admin-ajax instead of Rest API then problem will still exist.
Is it possible to add some hook around defaults_atts and we can fix this problem with simple hook when we use ajax-admin, example code
/** * Filters the default video shortcode attributes. * * @see wp_video_shortcode() * * @param array $defaults_atts Default attributes of the shortcode. @see wp_video_shortcode() */ $defaults_atts = apply_filters( 'wp_video_shortcode_defaults_atts', $defaults_atts );
Best regards,
Nenad
#3
@
6 years ago
Hi swissspidly,
Because if I understand the purpose of this conditional, that you set this case in order to set smaller video player inside TinyMCE editor and not for the frontend area
Best regards,
Nenad
As the name implies,
admin-ajax.php
runs in admin context. I'd recommend looking into using the superior REST API instead. For example, WordPress 5.0 has aWP_REST_Block_Renderer_Controller
class that you could use as inspiration for a shortcode renderer controller.