| 1 |
<?php |
| 2 |
|
| 3 |
namespace Code_Snippets\Integration\Promotions\Other; |
| 4 |
|
| 5 |
use Elementor\Controls_Manager; |
| 6 |
use Elementor\Element_Base; |
| 7 |
use Elementor\Widget_Base; |
| 8 |
use function Code_Snippets\code_snippets; |
| 9 |
|
| 10 |
/** |
| 11 |
* Handle adding promotions to the Elementor editor. |
| 12 |
*/ |
| 13 |
class Elementor_Editor { |
| 14 |
|
| 15 |
/** |
| 16 |
* Class constructor. |
| 17 |
*/ |
| 18 |
public function __construct() { |
| 19 |
add_action( 'elementor/init', [ $this, 'promotion_in_custom_css_section' ] ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Promotion on the Custom CSS section, inside the Elementor Editor. |
| 24 |
*/ |
| 25 |
public function promotion_in_custom_css_section() { |
| 26 |
// Elementor Core. |
| 27 |
add_action( |
| 28 |
'elementor/element/common/section_custom_css/after_section_start', |
| 29 |
function ( $element ) { |
| 30 |
$this->add_promotion_control( $element, 'core' ); |
| 31 |
} |
| 32 |
); |
| 33 |
|
| 34 |
// Elementor Pro. |
| 35 |
add_action( |
| 36 |
'elementor/element/common/section_custom_css_pro/after_section_start', |
| 37 |
function ( $element ) { |
| 38 |
$this->add_promotion_control( $element, 'pro' ); |
| 39 |
} |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Register promotion section in the Custom CSS section. |
| 45 |
* |
| 46 |
* @param Widget_Base|Element_Base $element The Elementor element. |
| 47 |
* @param string $suffix Identifier to append. |
| 48 |
*/ |
| 49 |
public function add_promotion_control( $element, string $suffix ) { |
| 50 |
$element->add_control( |
| 51 |
"code_snippets_promotion_notice_elementor_$suffix", |
| 52 |
[ |
| 53 |
'type' => Controls_Manager::NOTICE, |
| 54 |
'notice_type' => 'info', |
| 55 |
'dismissible' => true, |
| 56 |
'heading' => esc_html__( 'Manage your custom styles', 'code-snippets' ), |
| 57 |
'content' => $this->get_promotion_content(), |
| 58 |
] |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Get the promotion content with appropriate link. |
| 64 |
* |
| 65 |
* @return string |
| 66 |
*/ |
| 67 |
private function get_promotion_content(): string { |
| 68 |
// translators: %s: plugin name. |
| 69 |
$message = __( 'Code Snippets provides a powerful and user-friendly alternative to "%s", with cloud sync, advanced features, and an intuitive interface.', 'code-snippets' ); |
| 70 |
$message = sprintf( $message, __( 'Elementor Custom Code', 'code-snippets' ) ); |
| 71 |
|
| 72 |
if ( code_snippets()->licensing->is_licensed() ) { |
| 73 |
$link_text = __( 'Manage CSS snippets', 'code-snippets' ); |
| 74 |
$link_url = add_query_arg( 'type', 'css', code_snippets()->get_menu_url() ); |
| 75 |
} else { |
| 76 |
$link_text = __( 'Learn more', 'code-snippets' ); |
| 77 |
$link_url = 'https://codesnippets.pro/pricing/?utm_source=elementor&utm_medium=banner&utm_campaign=elementor-addon-custom-code'; |
| 78 |
} |
| 79 |
|
| 80 |
return sprintf( |
| 81 |
'%s <br><br><a href="%s" target="_blank" rel="noopener noreferrer" class="e-btn e-info" style="color: #fff;">%s</a>', |
| 82 |
esc_html( $message ), |
| 83 |
esc_url( $link_url ), |
| 84 |
esc_html( $link_text ) |
| 85 |
); |
| 86 |
} |
| 87 |
} |
| 88 |
|