Skip to content

Commit

Permalink
Merge pull request #31 from smalltowndev/elementor-support
Browse files Browse the repository at this point in the history
Elementor support
  • Loading branch information
lushkant committed Feb 13, 2024
2 parents 4da8f16 + ec3eb3b commit 28ee2a1
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
83 changes: 83 additions & 0 deletions includes/Compatibility/Plugins/Elementor/class-compatibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Elementor's compatibility handler.
*
* @package RSFV
*/

namespace RSFV\Compatibility\Plugins\Elementor;

defined( 'ABSPATH' ) || exit;

use RSFV\Compatibility\Plugins\Base_Compatibility;
use RSFV\FrontEnd;

/**
* Class Compatibility
*
* @package RSFV
*/
class Compatibility extends Base_Compatibility {
/**
* Class instance.
*
* @var $instance
*/
protected static $instance;

/**
* Constructor.
*
* @param string $id Compat ID.
* @param string $title Compat title.
*/
public function __construct( $id, $title ) {
parent::__construct( $id, $title );

$this->setup();
}

/**
* Sets up hooks and filters.
*
* @return void
*/
public function setup() {
add_filter( 'elementor/image_size/get_attachment_image_html', array( $this, 'update_with_video_html' ), 10, 4 );
}

/**
* Override Elementor Pro's post widget featured image html.
*
* @since 0.8.6
*
* @param string $html ex html markup.
* @param array $settings Settings array of parent widget/element.
* @param string $image_size_key Image size key.
* @param string $image_key Image key.
*
* @return string
*/
public function update_with_video_html( $html, $settings, $image_size_key, $image_key ) {
// Exit early if Elementor Pro isn't active.
if ( ! class_exists( 'ElementorPro\Plugin' ) ) {
return $html;
}

// Check if the image markup is from somewhere else than post/archive widgets.
if ( $settings && ! isset( $settings['posts_post_type'] ) ) {
return $html;
}

global $post;

// Check if the $post object is not defined.
if ( 'object' !== gettype( $post ) ) {
return $html;
}

$post_id = $post->ID;

return FrontEnd::get_featured_video_markup( $post_id, $html );
}
}
6 changes: 6 additions & 0 deletions includes/Compatibility/class-plugin-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public function __construct() {
'class' => 'RSFV\Compatibility\Plugins\SalientCore\Compatibility',
'has_class_loaded' => 'Salient_Core',
),
'elementor' => array(
'title' => __( 'Elementor', 'rsfv' ),
'file_source' => RSFV_PLUGIN_DIR . 'includes/Compatibility/Plugins/Elementor/class-compatibility.php',
'class' => 'RSFV\Compatibility\Plugins\Elementor\Compatibility',
'has_class_loaded' => 'Elementor\Plugin',
),
)
);

Expand Down
21 changes: 21 additions & 0 deletions includes/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static function get_instance() {
*/
public function get_posts_hooks() {
add_filter( 'post_thumbnail_html', array( $this, 'get_post_video' ), 10, 5 );
add_filter( 'wp_kses_allowed_html', array( $this, 'update_wp_kses_allowed_html' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -344,4 +345,24 @@ public function generate_dynamic_css() {

return apply_filters( 'rsfv_generated_dynamic_css', $css );
}

/**
* Override wp_kses_post allowed html array to make way for videos.
*
* @param array $allowed_html List of html tags.
* @param string $context Key of current context.
*
* @return array
*/
public function update_wp_kses_allowed_html( $allowed_html, $context ) {

// Keep only for 'post' contenxt.
if ( 'post' === $context ) {
$additional_html = $this->get_allowed_html();

return array_merge( $allowed_html, $additional_html );
}

return $allowed_html;
}
}
2 changes: 1 addition & 1 deletion includes/class-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function get_video_markup( $post_id, $post_type ) {
$has_controls = $has_controls ? 'controls' : '';

if ( $video_url ) {
return '<video class="rsfv-video" id="rsfv-video-' . esc_attr( $post_id ) . '" src="' . esc_url( $video_url ) . '" style="max-width:100%;display:block;"' . esc_attr( $has_controls ) . ' ' . esc_attr( $is_autoplay ) . ' ' . esc_attr( $is_loop ) . ' ' . esc_attr( $is_muted ) . ' ' . esc_attr( $is_pip ) . '></video>';
return '<video class="rsfv-video" id="rsfv-video-' . esc_attr( $post_id ) . '" src="' . esc_url( $video_url ) . '" style="max-width:100%;display:block;" ' . esc_attr( $has_controls ) . ' ' . esc_attr( $is_autoplay ) . ' ' . esc_attr( $is_loop ) . ' ' . esc_attr( $is_muted ) . ' ' . esc_attr( $is_pip ) . '></video>';
}
}

Expand Down

0 comments on commit 28ee2a1

Please sign in to comment.