PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / trunk
WPSSO Core – Complete Schema Markup and Meta Tags vtrunk
22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
wpsso / lib / std / media / youtube.php

youtube.php in WPSSO Core – Complete Schema Markup and Meta Tags trunk, at lib/std/media/youtube.php

96 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * License: GPLv3
4 * License URI: https://www.gnu.org/licenses/gpl.txt
5 * Copyright 2012-2026 Jean-Sebastien Morisset (https://wpsso.com/)
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9
10 die( 'These aren\'t the droids you\'re looking for.' );
11 }
12
13 if ( ! class_exists( 'WpssoStdMediaYoutube' ) ) {
14
15 class WpssoStdMediaYoutube {
16
17 private $p; // Wpsso class object.
18
19 public function __construct( &$plugin ) {
20
21 $this->p =& $plugin;
22
23 if ( $this->p->debug->enabled ) {
24
25 $this->p->debug->mark();
26 }
27
28 /*
29 * Filter priorities:
30 *
31 * 10 = Youtube Videos.
32 * 20 = Vimeo Videos.
33 * 30 = Wistia Videos.
34 * 40 = Slideshare Presentations.
35 * 60 = Facebook Videos.
36 * 80 = Soundcloud Tracks.
37 * 100 = WP Media Library Video Blocks.
38 * 110 = WP Media Library Video Shortcodes.
39 * 1000 = Gravatar Images.
40 */
41 $this->p->util->add_plugin_filters( $this, array(
42 'video_details' => 3,
43 ), $prio = 10 );
44 }
45
46 public function filter_video_details( $mt_single_video, $args, $mod ) {
47
48 if ( $this->p->debug->enabled ) {
49
50 $this->p->debug->mark();
51 }
52
53 if ( ! empty( $args[ 'attach_id' ] ) ) {
54
55 if ( $this->p->debug->enabled ) {
56
57 $this->p->debug->log( 'exiting early: have attachment ID' );
58 }
59
60 return array();
61
62 } elseif ( false === strpos( $args[ 'url' ], 'youtu' ) ) { // Optimize before preg_match().
63
64 if ( $this->p->debug->enabled ) {
65
66 $this->p->debug->log( 'exiting early: "youtu" string not found in video URL' );
67 }
68
69 return array();
70
71 } elseif ( ! preg_match( '/^.*(youtube\.com|youtube-nocookie\.com|youtu\.be)\/(watch\/?\?v=)?([^\?\&\#<>]+)' .
72 '(\?(list)=([^\?\&\#<>]+)|.*)$/', $args[ 'url' ], $match ) ) {
73
74 if ( $this->p->debug->enabled ) {
75
76 $this->p->debug->log( 'exiting early: youtube video URL pattern not found' );
77 }
78
79 return array();
80 }
81
82 if ( $this->p->debug->enabled ) {
83
84 $this->p->debug->log( 'YouTube video URL found but no video API modules' );
85 }
86
87 if ( $this->p->notice->is_admin_pre_notices() ) {
88
89 $this->p->msgs->pro_feature_video_found_notice( _x( 'YouTube', 'video service name', 'wpsso' ), $mod );
90 }
91
92 return array();
93 }
94 }
95 }
96