Advertisement
maximus87

Untitled

Jun 3rd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. function wpc_video_field( $form_fields, $post ) {
  2.     $form_fields['wpc-video-url'] = array(
  3.         'label' => 'Video URL',
  4.         'input' => 'text',
  5.         'value' => get_post_meta( $post->ID, 'wpc_video_url', true ),
  6.         'helps' => 'If provided, video will be loaded',
  7.     );
  8.  
  9.     return $form_fields;
  10. }
  11.  
  12. add_filter( 'attachment_fields_to_edit', 'wpc_video_field', 10, 2 );
  13.  
  14. /**
  15.  * Save values of Photographer Name and URL in media uploader
  16.  *
  17.  * @param $post array, the post data for database
  18.  * @param $attachment array, attachment fields from $_POST form
  19.  * @return $post array, modified post data
  20.  */
  21.  
  22. function wpc_video_field_save( $post, $attachment ) {
  23.     if( isset( $attachment['wpc-video-url'] ) )
  24.         update_post_meta( $post['ID'], 'wpc_video_url', $attachment['wpc-video-url'] );
  25.  
  26.     return $post;
  27. }
  28.  
  29. add_filter( 'attachment_fields_to_save', 'wpc_video_field_save', 10, 2 );
  30.  
  31. function getVimeoVideoIdFromUrl($url = '') {
  32.    
  33.         $regs = array();
  34.    
  35.         $id = '';
  36.    
  37.         if (preg_match('%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$%im', $url, $regs)) {
  38.             $id = $regs[3];
  39.         }
  40.    
  41.         return $id;
  42.    
  43.     }
  44.  
  45. function getYoutubeVideoIdFromUrl($url = '') {
  46.    
  47.         $match = array();
  48.    
  49.         $id = '';
  50.    
  51.         if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
  52.             $id = $match[1];
  53.         }
  54.    
  55.         return $id;
  56.    
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement