Ejemplo n.º 1
0
/**
 * View function.
 * 
 * @global type $wp_embed
 * @global object $wpdb
 *
 * @param type $field
 * @return string
 */
function wpcf_fields_video_view($params)
{
    if (is_string($params['field_value'])) {
        $params['field_value'] = stripslashes($params['field_value']);
    }
    $value = $params['field_value'];
    if (empty($value)) {
        return '__wpcf_skip_empty';
    }
    list($default_width, $default_height) = wpcf_media_size();
    $url = trim(strval($value));
    $width = !empty($params['width']) ? intval($params['width']) : $default_width;
    $height = !empty($params['height']) ? intval($params['height']) : $default_height;
    $add = '';
    if (!empty($params['poster'])) {
        $add .= " poster=\"{$params['poster']}\"";
    }
    if (!empty($params['loop'])) {
        $add .= " loop=\"{$params['loop']}\"";
    }
    if (!empty($params['autoplay'])) {
        $add .= " autoplay=\"{$params['autoplay']}\"";
    }
    if (!empty($params['preload'])) {
        $add .= " preload=\"{$params['preload']}\"";
    }
    $shortcode = "[video width=\"{$width}\" height=\"{$height}\" src=\"{$url}\"{$add}]";
    $output = do_shortcode($shortcode);
    if (empty($output)) {
        return '__wpcf_skip_empty';
    }
    return $output;
}
Ejemplo n.º 2
0
/**
 * View function.
 * 
 * @global type $wp_embed
 * @param type $field
 * @return string
 */
function wpcf_fields_embed_view($params)
{
    global $wp_embed;
    $value = $params['field_value'];
    if (empty($value)) {
        return '__wpcf_skip_empty';
    }
    list($default_width, $default_height) = wpcf_media_size();
    $url = trim(strval($value));
    if (!types_validate('url', $url)) {
        return '__wpcf_skip_empty';
    }
    $width = !empty($params['width']) ? intval($params['width']) : $default_width;
    $height = !empty($params['height']) ? intval($params['height']) : $default_height;
    $shortcode = '[embed width="' . $width . '" height="' . $height . '"]' . $url . '[/embed]';
    $output = $wp_embed->run_shortcode($shortcode);
    if (empty($output)) {
        return '__wpcf_skip_empty';
    }
    return $output;
}