Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpc_video_field( $form_fields, $post ) {
- $form_fields['wpc-video-url'] = array(
- 'label' => 'Video URL',
- 'input' => 'text',
- 'value' => get_post_meta( $post->ID, 'wpc_video_url', true ),
- 'helps' => 'If provided, video will be loaded',
- );
- return $form_fields;
- }
- add_filter( 'attachment_fields_to_edit', 'wpc_video_field', 10, 2 );
- /**
- * Save values of Photographer Name and URL in media uploader
- *
- * @param $post array, the post data for database
- * @param $attachment array, attachment fields from $_POST form
- * @return $post array, modified post data
- */
- function wpc_video_field_save( $post, $attachment ) {
- if( isset( $attachment['wpc-video-url'] ) )
- update_post_meta( $post['ID'], 'wpc_video_url', $attachment['wpc-video-url'] );
- return $post;
- }
- add_filter( 'attachment_fields_to_save', 'wpc_video_field_save', 10, 2 );
- function getVimeoVideoIdFromUrl($url = '') {
- $regs = array();
- $id = '';
- if (preg_match('%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$%im', $url, $regs)) {
- $id = $regs[3];
- }
- return $id;
- }
- function getYoutubeVideoIdFromUrl($url = '') {
- $match = array();
- $id = '';
- if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
- $id = $match[1];
- }
- return $id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement