Example #1
0
/**
 * An intermediary shortcode parser for the Core `[video]` shortcode.
 *
 * This lets us convert legacy video embeds over to VideoPress embeds,
 * if the video files have been uploaded and transcoded.
 *
 * @param $attr
 *
 * @return string|void
 */
function videopress_shortcode_override_for_core_shortcode($raw_attr, $contents, $tag)
{
    $attr = $raw_attr;
    $videopress_guid = null;
    if (isset($attr['videopress_guid'])) {
        $videopress_guid = $attr['videopress_guid'];
    } elseif (isset($attr['mp4'])) {
        $url = $attr['mp4'];
        if (preg_match('@videos.videopress.com/([a-z0-9]{8})/@', $url, $matches)) {
            $videopress_guid = $matches[1];
        }
    }
    if ($videopress_guid) {
        $videopress_attr = array($videopress_guid);
        if ($attr['width']) {
            $videopress_attr['w'] = (int) $attr['width'];
        }
        if ($attr['autoplay']) {
            $videopress_attr['autoplay'] = $attr['autoplay'];
        }
        if ($attr['loop']) {
            $videopress_attr['loop'] = $attr['loop'];
        }
        // Then display the VideoPress version of the stored GUID!
        return videopress_shortcode_callback($videopress_attr);
    }
    // Nothing else caught, so fall back to the core shortcode.
    return call_user_func($GLOBALS['vp_original_video_shortcode_callback'], $raw_attr, $contents, $tag);
}
Example #2
0
 /**
  * Our custom AJAX callback for the query-attachments action
  * used in the media modal. By-passed if not for VideoPress.
  */
 function wp_ajax_query_attachments()
 {
     // Watch for VideoPress calls
     if (!isset($_POST['query']['videopress'])) {
         return;
     }
     if (!$this->can('read_videos')) {
         return wp_send_json_error('permission denied');
     }
     // Get and sanitize query arguments.
     $query_args = $this->sanitize_wp_query_args($_POST['query']);
     // Fire a remote WP_Query
     $result = $this->query('jetpack.vpQuery', $query_args);
     if (is_wp_error($result)) {
         return wp_send_json_error('xml rpc request error');
     }
     $items = $result;
     foreach ($items as $key => $item) {
         // Check local permissions
         if (!$this->can('edit_videos')) {
             unset($item['vp_nonces']['update']);
         }
         if (!$this->can('delete_videos')) {
             unset($item['vp_nonces']['delete']);
         }
         // Add a second pair of nonces for the .org blog.
         $item['nonces'] = array();
         if (!empty($item['vp_nonces']['update'])) {
             $item['nonces']['update'] = wp_create_nonce('update-videopress-post_' . $item['id']);
         }
         if (!empty($item['vp_nonces']['delete'])) {
             $item['nonces']['delete'] = wp_create_nonce('delete-videopress-post_' . $item['id']);
         }
         $item['vp_embed'] = videopress_shortcode_callback(array($item['vp_guid'], 'autoplay' => true, 'flashonly' => true, 'w' => 440));
         $items[$key] = $item;
     }
     wp_send_json_success($items);
 }