Embedpress_Elementor_Integration.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Elementor; |
| 4 | |
| 5 | |
| 6 | (defined( 'ABSPATH' )) or die( "No direct script access allowed." ); |
| 7 | use EmbedPress\Compatibility; |
| 8 | class Embedpress_Elementor_Integration { |
| 9 | |
| 10 | /** |
| 11 | * @since 2.4.2 |
| 12 | */ |
| 13 | public function init() { |
| 14 | add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'embedpress_enqueue_style' ] ); |
| 15 | add_action( 'elementor/elements/categories_registered', array( $this, 'register_widget_categories' ) ); |
| 16 | add_action( 'elementor/widgets/widgets_registered', array( $this, 'register_widget' ) ); |
| 17 | add_filter( 'oembed_providers', [ $this, 'addOEmbedProviders' ] ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Add elementor category |
| 22 | * |
| 23 | * @since 2.4.3 |
| 24 | */ |
| 25 | public function register_widget_categories( $elements_manager ) { |
| 26 | $elements_manager->add_category( |
| 27 | 'embedpress', |
| 28 | [ |
| 29 | 'title' => __( 'EmbedPress', 'embedpress' ), |
| 30 | 'icon' => 'font', |
| 31 | ], 1 ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Load elementor widget |
| 36 | * |
| 37 | * @since 2.4.2 |
| 38 | */ |
| 39 | public function register_widget( $widgets_manager ) { |
| 40 | $widgets_manager->register_widget_type( new \EmbedPress\Elementor\Widgets\Embedpress_Elementor ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Enqueue elementor assets |
| 45 | * @since 2.4.3 |
| 46 | */ |
| 47 | public function embedpress_enqueue_style() { |
| 48 | wp_enqueue_style( |
| 49 | 'embedpress-elementor-css', |
| 50 | EMBEDPRESS_URL_ASSETS . 'css/embedpress-elementor.css', |
| 51 | false, |
| 52 | EMBEDPRESS_VERSION |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | public function addOEmbedProviders( $providers ) { |
| 57 | if (Compatibility::isWordPress5() && ! Compatibility::isClassicalEditorActive()) { |
| 58 | unset( $providers['#https?://(.+\.)?wistia\.com/medias/.+#i'], $providers['#https?://(.+\.)?fast\.wistia\.com/embed/medias/.+#i\.jsonp'] ); |
| 59 | } |
| 60 | |
| 61 | return $providers; |
| 62 | } |
| 63 | |
| 64 | } |
| 65 |