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