Addons.php
11 months ago
Admin.php
2 months ago
Ajax.php
9 months ago
Announcements.php
1 year ago
Assets.php
2 months ago
Backend_Page_Trait.php
1 year ago
BaseController.php
1 year ago
Config.php
11 months ago
Container.php
11 months ago
Course.php
2 months ago
Course_Embed.php
3 years ago
Course_Filter.php
1 year ago
Course_List.php
5 months ago
Course_Settings_Tabs.php
1 year ago
Course_Widget.php
1 year ago
Custom_Validation.php
3 years ago
Dashboard.php
1 year ago
Earnings.php
9 months ago
FormHandler.php
2 years ago
Frontend.php
1 year ago
Gutenberg.php
1 year ago
Icon.php
8 months ago
Input.php
1 year ago
Instructor.php
2 months ago
Instructors_List.php
2 months ago
Lesson.php
2 weeks ago
Options_V2.php
7 months ago
Permalink.php
2 years ago
Post_types.php
1 year ago
Private_Course_Access.php
1 year ago
Q_And_A.php
10 months ago
Question_Answers_List.php
11 months ago
Quiz.php
2 weeks ago
QuizBuilder.php
2 weeks ago
Quiz_Attempts_List.php
9 months ago
RestAPI.php
2 years ago
Reviews.php
9 months ago
Rewrite_Rules.php
2 years ago
Shortcode.php
9 months ago
Singleton.php
1 year ago
Student.php
2 months ago
Students_List.php
1 year ago
Taxonomies.php
1 year ago
Template.php
9 months ago
Theme_Compatibility.php
3 years ago
Tools.php
1 year ago
Tools_V2.php
3 weeks ago
Tutor.php
2 months ago
TutorEDD.php
1 year ago
Tutor_Base.php
2 years ago
Tutor_Setup.php
8 months ago
Upgrader.php
9 months ago
User.php
4 months ago
Utils.php
3 weeks ago
Video_Stream.php
3 years ago
WhatsNew.php
9 months ago
Withdraw.php
1 year ago
Withdraw_Requests_List.php
11 months ago
WooCommerce.php
7 months ago
Course_Embed.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Manage course embed |
| 4 | * |
| 5 | * @package Tutor |
| 6 | * @author Themeum <support@themeum.com> |
| 7 | * @link https://themeum.com |
| 8 | * @since 2.1.0 |
| 9 | */ |
| 10 | |
| 11 | namespace TUTOR; |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Course embed class |
| 19 | * |
| 20 | * @since 2.1.0 |
| 21 | */ |
| 22 | class Course_Embed { |
| 23 | |
| 24 | /** |
| 25 | * Register hooks |
| 26 | * |
| 27 | * @since 2.1.0 |
| 28 | * @return void |
| 29 | */ |
| 30 | public function __construct() { |
| 31 | add_filter( 'tutor_get_template_path', __CLASS__ . '::filter_template_path', 100, 2 ); |
| 32 | add_filter( 'embed_oembed_html', __CLASS__ . '::oembed_iframe_overrides', 10, 3 ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Filter oembed data |
| 37 | * |
| 38 | * @since 2.1.0 |
| 39 | * |
| 40 | * @param string $html html content to filter. |
| 41 | * @param string $url post embed url. |
| 42 | * @param array $attr attrs. |
| 43 | * |
| 44 | * @return string customized html content |
| 45 | */ |
| 46 | public static function oembed_iframe_overrides( $html, $url, $attr ) { |
| 47 | |
| 48 | $post_id = url_to_postid( $url ); |
| 49 | if ( ! $post_id || tutor()->course_post_type !== get_post_type( $post_id ) ) { |
| 50 | return $html; |
| 51 | } |
| 52 | |
| 53 | if ( strpos( $html, '<iframe' ) !== false ) { |
| 54 | $html = str_replace( |
| 55 | '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', |
| 56 | '<iframe class="wp-embedded-content" sandbox="allow-forms allow-popups allow-scripts allow-same-origin allow-top-navigation" security="restricted" ', |
| 57 | $html |
| 58 | ); |
| 59 | |
| 60 | $html = preg_replace( '/( height=".*")/i', ' height="620" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" ', $html ); |
| 61 | |
| 62 | $html = str_replace( |
| 63 | '<blockquote class="wp-embedded-content"', |
| 64 | '<blockquote class="wp-embedded-content" style="display:none" ', |
| 65 | $html |
| 66 | ); |
| 67 | return $html; |
| 68 | } else { |
| 69 | return $html; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Filter template |
| 75 | * |
| 76 | * @since 2.1.0 |
| 77 | * |
| 78 | * @param string $template_location default template location. |
| 79 | * @param string $template template name. |
| 80 | * |
| 81 | * @return string |
| 82 | */ |
| 83 | public static function filter_template_path( $template_location, $template ) { |
| 84 | $post_id = get_the_ID(); |
| 85 | if ( get_post_type( $post_id ) === tutor()->course_post_type && function_exists( 'is_embed' ) && is_embed() ) { |
| 86 | if ( 'single-course' === $template ) { |
| 87 | $template_location = tutor()->path . 'templates/course-embed.php'; |
| 88 | } |
| 89 | } |
| 90 | return $template_location; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Check if current course is embedded |
| 95 | * |
| 96 | * @since 2.1.0 |
| 97 | * @return boolean |
| 98 | */ |
| 99 | public static function is_embed_course() { |
| 100 | $post_id = get_the_ID(); |
| 101 | if ( get_post_type( $post_id ) === tutor()->course_post_type && function_exists( 'is_embed' ) && is_embed() ) { |
| 102 | return true; |
| 103 | } |
| 104 | return false; |
| 105 | } |
| 106 | } |
| 107 |