PluginProbe
Code Snippets / 4.0.0-beta.3
Code Snippets v4.0.0-beta.3
4.0.0-beta.3 4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 All 66 releases
code-snippets / php / Integration / Promotions / Other / Elementor_Editor.php

Elementor_Editor.php in Code Snippets 4.0.0-beta.3, at php/Integration/Promotions/Other/Elementor_Editor.php

106 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 if ( ! $this->supports_notice_control() ) {
27 return;
28 }
29
30 // Elementor Core.
31 add_action(
32 'elementor/element/common/section_custom_css/after_section_start',
33 function ( $element ) {
34 $this->add_promotion_control( $element, 'core' );
35 }
36 );
37
38 // Elementor Pro.
39 add_action(
40 'elementor/element/common/section_custom_css_pro/after_section_start',
41 function ( $element ) {
42 $this->add_promotion_control( $element, 'pro' );
43 }
44 );
45 }
46
47 /**
48 * Check whether this version of Elementor offers the notice control type.
49 *
50 * The type arrived in Elementor 3.19. On anything older the constant does
51 * not exist, and reading it while the editor builds its controls raises an
52 * Error that leaves the editor unusable, so the promotion is skipped
53 * rather than degraded.
54 *
55 * @return bool
56 */
57 protected function supports_notice_control(): bool {
58 return defined( Controls_Manager::class . '::NOTICE' );
59 }
60
61 /**
62 * Register promotion section in the Custom CSS section.
63 *
64 * @param Widget_Base|Element_Base $element The Elementor element.
65 * @param string $suffix Identifier to append.
66 */
67 public function add_promotion_control( $element, string $suffix ) {
68 $element->add_control(
69 "code_snippets_promotion_notice_elementor_$suffix",
70 [
71 'type' => Controls_Manager::NOTICE,
72 'notice_type' => 'info',
73 'dismissible' => true,
74 'heading' => esc_html__( 'Manage your custom styles', 'code-snippets' ),
75 'content' => $this->get_promotion_content(),
76 ]
77 );
78 }
79
80 /**
81 * Get the promotion content with appropriate link.
82 *
83 * @return string
84 */
85 private function get_promotion_content(): string {
86 // translators: %s: plugin name.
87 $message = __( 'Code Snippets provides a powerful and user-friendly alternative to "%s", with cloud sync, advanced features, and an intuitive interface.', 'code-snippets' );
88 $message = sprintf( $message, __( 'Elementor Custom Code', 'code-snippets' ) );
89
90 if ( code_snippets()->licensing->is_licensed() ) {
91 $link_text = __( 'Manage CSS snippets', 'code-snippets' );
92 $link_url = add_query_arg( 'type', 'css', code_snippets()->get_menu_url() );
93 } else {
94 $link_text = __( 'Learn more', 'code-snippets' );
95 $link_url = 'https://codesnippets.pro/pricing/?utm_source=elementor&utm_medium=banner&utm_campaign=elementor-addon-custom-code';
96 }
97
98 return sprintf(
99 '%s <br><br><a href="%s" target="_blank" rel="noopener noreferrer" class="e-btn e-info" style="color: #fff;">%s</a>',
100 esc_html( $message ),
101 esc_url( $link_url ),
102 esc_html( $link_text )
103 );
104 }
105 }
106