Tutor.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PrestoPlayer\Integrations\Tutor; |
| 4 | |
| 5 | class Tutor { |
| 6 | |
| 7 | public function register() { |
| 8 | add_filter( 'tutor_course/single/video', array( $this, 'renderVideo' ) ); |
| 9 | add_filter( 'tutor_lesson/single/video', array( $this, 'renderVideo' ) ); |
| 10 | } |
| 11 | |
| 12 | public function renderVideo( $output ) { |
| 13 | if ( ! strpos( $output, '[presto_player' ) ) { |
| 14 | return $output; |
| 15 | } |
| 16 | |
| 17 | // read all image tags into an array |
| 18 | preg_match_all( '/<source[^>]+>/i', $output, $source ); |
| 19 | |
| 20 | if ( empty( $source[0] ) ) { |
| 21 | return $output; |
| 22 | } |
| 23 | |
| 24 | preg_match( '/src="([^"]+)/i', $source[0][0], $src ); |
| 25 | |
| 26 | if ( empty( $src[1] ) ) { |
| 27 | return $output; |
| 28 | } |
| 29 | |
| 30 | // remove accidental url encoding and protocol. |
| 31 | $source = str_replace( 'http://', '', $src[1] ); |
| 32 | $source = str_replace( 'https://', '', $source ); |
| 33 | $source = str_replace( '%20', ' ', $source ); |
| 34 | |
| 35 | return \do_shortcode( $source ); |
| 36 | } |
| 37 | } |
| 38 |