| 1 |
<?php |
| 2 |
namespace Easyel\EasyElements\Extensions\LiveCopy; |
| 3 |
use Easyel\EasyElements\Extensions\ExtensionHook\HookControl; |
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 |
class CopyPaste { |
| 6 |
|
| 7 |
/** |
| 8 |
* Singleton instance |
| 9 |
* @var CopyPaste|null |
| 10 |
*/ |
| 11 |
protected static $instance = null; |
| 12 |
|
| 13 |
/** |
| 14 |
* Constructor |
| 15 |
*/ |
| 16 |
private function __construct() { |
| 17 |
|
| 18 |
add_action( 'init', [ $this, 'easy_init' ] ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Get instance |
| 23 |
*/ |
| 24 |
public static function get_instance() { |
| 25 |
if ( null === self::$instance ) { |
| 26 |
self::$instance = new self(); |
| 27 |
} |
| 28 |
return self::$instance; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Initialize actions |
| 33 |
*/ |
| 34 |
public function easy_init() { |
| 35 |
|
| 36 |
add_action('elementor/element/common/_section_style/after_section_end', [ $this, 'easy_live_copy_register_section'] ); |
| 37 |
add_action('elementor/element/section/section_advanced/after_section_end', [ $this, 'easy_live_copy_register_section'] ); |
| 38 |
|
| 39 |
add_action('elementor/element/common/easy_live_copy_section/before_section_end', [ $this, 'easy_live_copy_register_controls'], 10, 2 ); |
| 40 |
add_action('elementor/element/section/easy_live_copy_section/before_section_end', [ $this, 'easy_live_copy_register_controls'], 10, 2 ); |
| 41 |
|
| 42 |
add_action('elementor/element/container/section_layout/after_section_end', [ $this, 'easy_live_copy_register_section'] ); |
| 43 |
|
| 44 |
add_action('elementor/element/container/easy_live_copy_section/before_section_end', [ $this, 'easy_live_copy_register_controls'], 10, 2 ); |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
public function easy_live_copy_register_section( $element ) { |
| 49 |
|
| 50 |
$enable_live_copy = get_option( 'easy_live_copy_btn_enable', true ); |
| 51 |
|
| 52 |
if( ( int ) $enable_live_copy !== 1 && class_exists( 'Easy_Elements_Pro' ) ) { |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
if ( function_exists( 'easy_element_is_enabled' ) && easy_element_is_enabled( 'enable_live_copy_paste' ) || ! class_exists( 'Easy_Elements_Pro' ) ) { |
| 57 |
|
| 58 |
$element->start_controls_section( |
| 59 |
'easy_live_copy_section', |
| 60 |
[ |
| 61 |
'label' => EASY_EXTENSION_BADGE . __( 'Live Copy Paste', 'easy-elements' ), |
| 62 |
'tab' => \Elementor\Controls_Manager::TAB_ADVANCED, |
| 63 |
] |
| 64 |
); |
| 65 |
|
| 66 |
$element->end_controls_section(); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Register visibility controls in Elementor panel |
| 72 |
*/ |
| 73 |
public function easy_live_copy_register_controls( $element, $args ) { |
| 74 |
if( ! class_exists( 'Easy_Elements_Pro' ) ) { |
| 75 |
|
| 76 |
HookControl::register_controls( $element, "live_copy_promo_key" ); |
| 77 |
} else { |
| 78 |
|
| 79 |
$pro_version = easyel_get_pro_clean_version(); |
| 80 |
|
| 81 |
if ( |
| 82 |
$pro_version && |
| 83 |
version_compare( $pro_version, '1.0.8', '>=' ) |
| 84 |
) { |
| 85 |
if ( did_action( 'plugins_loaded' ) && function_exists( 'easy_element_is_enabled' ) && easy_element_is_enabled( 'enable_live_copy_paste' ) && class_exists( '\EasyElements_Elementor\Pro\Extension\CopyPaste\LiveCopyPro' ) ) { |
| 86 |
$instance = \EasyElements_Elementor\Pro\Extension\CopyPaste\LiveCopyPro::get_instance(); |
| 87 |
$instance->easy_live_copy_register_controls_pro( $element, $args ); |
| 88 |
} |
| 89 |
} else { |
| 90 |
if ( did_action( 'plugins_loaded' ) && function_exists( 'easy_element_is_enabled' ) && easy_element_is_enabled( 'enable_live_copy_paste' ) && class_exists( 'Easy_Live_Copy_Paste_Pro' ) ) { |
| 91 |
\Easy_Live_Copy_Paste_Pro::easy_live_copy_register_controls_pro( $element, $args ); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
} |
| 96 |
} |
| 97 |
} |