Advertisement
phpface

Block embedding from other websites

Aug 17th, 2022 (edited)
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. function is_allowed_referer() {
  2.  
  3.     $self = parse_url( home_url('/') );
  4.  
  5.     $search_engine_terms = [ 'google', 'bing', 'yahoo', 'ask', 'duckduckgo', 'ecosia', $self['host'] ];
  6.  
  7.     $referer_url    = $_SERVER['HTTP_REFERER'];
  8.     $referer_host   = parse_url( $referer_url, PHP_URL_HOST );
  9.  
  10.     foreach ( $search_engine_terms as $term ) {
  11.         if( strpos( $term , $referer_host ) !== false ){
  12.             return true;
  13.         }
  14.     }
  15.  
  16.     return false;
  17. }
  18.  
  19. /**
  20.  *
  21.  * Block embedding from other websites
  22.  *
  23.  */
  24. add_filter( 'streamtube/player/file/output', function( $player, $setup, $source ){
  25.     if( is_embed() ){
  26.  
  27.         if( ! is_allowed_referer() ){
  28.             $player = '';
  29.         }
  30.     }
  31.  
  32.     return $player;
  33. }, 999, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement