su_shortcode_vimeo

The shortcodes-ultimate su shortcode vimeo function.

Published Date - February 15, 2021

Description

su_shortcode_vimeo( $atts, $content );

Parameters

  1. $atts

  2. $content


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_shortcode_vimeo' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/shortcodes/vimeo.php';
}

// The input(s). 
$atts = null;
$content = null;

// NOTICE! Understand what this does before running.
$result = su_shortcode_vimeo( $atts, $content );
            

Defined

The function is defined in the following location(s).

shortcodes-ultimate/includes/shortcodes/vimeo.php

function su_shortcode_vimeo( $atts = null, $content = null ) {

	$atts = shortcode_atts(
		array(
			'url'        => '',
			'width'      => 600,
			'height'     => 400,
			'autoplay'   => 'no',
			'dnt'        => 'no',
			'mute'       => 'no',
			'responsive' => 'yes',
			'title'      => '',
			'texttrack'  => '',
			'class'      => '',
		),
		$atts,
		'vimeo'
	);

	if ( ! $atts['url'] ) {
		return su_error_message( 'Vimeo', __( 'please specify correct url', 'shortcodes-ultimate' ) );
	}

	$atts['url'] = su_do_attribute( $atts['url'] );

	$video_id = preg_match( '~(?:<iframe [^>]*src=")?(?:https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/videos?)?\/([0-9]+)[^\s]*)"?(?:[^>]*></iframe>)?(?:<p>.*</p>)?~ix', $atts['url'], $match )
		? $match[1]
		: false;

	if ( ! $video_id ) {
		return su_error_message( 'Vimeo', __( 'please specify correct url', 'shortcodes-ultimate' ) );
	}

	$url_params = array(
		'title'     => 0,
		'byline'    => 0,
		'portrait'  => 0,
		'color'     => 'ffffff',
		'autoplay'  => 'yes' === $atts['autoplay'] ? 1 : 0,
		'dnt'       => 'yes' === $atts['dnt'] ? 1 : 0,
		'muted'     => 'yes' === $atts['mute'] ? 1 : 0,
		'texttrack' => $atts['texttrack'],
	);

	su_query_asset( 'css', 'su-shortcodes' );

	return '<div class="su-vimeo su-u-responsive-media-' . $atts['responsive'] . su_get_css_class( $atts ) . '"><iframe width="' . $atts['width'] . '" height="' . $atts['height'] . '" src="//player.vimeo.com/video/' . $video_id . '?' . esc_attr( http_build_query( $url_params ) ) . '" frameborder="0" allow="autoplay; fullscreen" allowfullscreen title="' . esc_attr( $atts['title'] ) . '"></iframe></div>';

}