Skip to content

Commit

Permalink
Register Elementor and Elementor Pro compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
lushkant committed Feb 13, 2024
1 parent 97939a1 commit ec3eb3b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
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

0 comments on commit ec3eb3b

Please sign in to comment.