/** * 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; $shortcode_handler = Jetpack_VideoPress_Shortcode::init(); 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'] = $shortcode_handler->shortcode_callback(array($item['vp_guid'], 'autoplay' => true, 'flashonly' => true, 'w' => 440)); $items[$key] = $item; } wp_send_json_success($items); }
// Enqueue VideoPress scripts $js_url = is_ssl() ? 'https://v0.wordpress.com/js/videopress.js' : 'http://s0.videopress.com/js/videopress.js'; wp_enqueue_script('videopress', $js_url, array('jquery', 'swfobject'), '1.09'); require_once dirname(__FILE__) . '/class.videopress-video.php'; require_once dirname(__FILE__) . '/class.videopress-player.php'; $player = new VideoPress_Player($guid, $attr['width'], $options); if (is_feed()) { return $player->asXML(); } else { return $player->asHTML(); } } /** * Validate user-supplied guid values against expected inputs * * @since 1.1 * @param string $guid video identifier * @return bool true if passes validation test */ public function is_valid_guid($guid) { if (!empty($guid) && strlen($guid) === 8 && ctype_alnum($guid)) { return true; } else { return false; } } } // Initialize the shortcode handler. Jetpack_VideoPress_Shortcode::init();