diff --git a/src/php/class-plugin.php b/src/php/class-plugin.php index c05613e2..4e83f674 100644 --- a/src/php/class-plugin.php +++ b/src/php/class-plugin.php @@ -156,6 +156,9 @@ public function load_plugin() { $upgrade = new Upgrade( $this->version, $this->db ); add_action( 'plugins_loaded', array( $upgrade, 'run' ), 0 ); $this->licensing = new Licensing(); + + // Initialize promotions. + new Promotions\Elementor_Pro(); } /** diff --git a/src/php/promotions/elementor-pro.php b/src/php/promotions/elementor-pro.php new file mode 100644 index 00000000..8a01396b --- /dev/null +++ b/src/php/promotions/elementor-pro.php @@ -0,0 +1,130 @@ +is_custom_code_screen() ) { + return; + } + ?> +
+

+ +

+

+ +

+

+ + + + + + +

+
+ id, + [ + 'edit-elementor_snippet', + 'elementor_snippet', + ], + true + ); + } + + /** + * Promotion on the Custom CSS section, inside the Elementor Editor. + * + * @return void + */ + public function promotion_in_custom_css_section() { + add_action( 'elementor/element/common/section_custom_css/before_section_end', [ $this, 'add_promotion_to_custom_css_section' ], 10, 2 ); + } + + /** + * Register promotion section after the Custom CSS section. + * + * @param \Elementor\Widget_Base|\Elementor\Element_Base $element The Elementor element. + */ + public function add_promotion_to_custom_css_section( $element ) { + $element->add_control( + 'code_snippets_promotion_notice', + [ + 'type' => \Elementor\Controls_Manager::NOTICE, + 'notice_type' => 'info', + 'dismissible' => true, + 'heading' => esc_html__( 'Manage your custom styles', 'code-snippets' ), + 'content' => $this->get_promotion_content(), + ] + ); + } + + /** + * Get the promotion content with appropriate link. + * + * @return string + */ + private function get_promotion_content(): string { + $message = esc_html__( 'Code Snippets Pro provides a powerful and user-friendly alternative to Elementor Custom Code, with cloud sync, conditional logic, and advanced features.', 'code-snippets' ); + + if ( $this->is_pro() ) { + $link_text = esc_html__( 'Manage CSS snippets', 'code-snippets' ); + $url = admin_url( 'admin.php?page=snippets&type=css' ); + } else { + $link_text = esc_html__( 'Learn More', 'code-snippets' ); + $url = 'https://codesnippets.pro/pricing/?utm_source=elementor&utm_medium=banner&utm_campaign=elementor-addon-custom-code'; + } + + return sprintf( '%s

%s', $message, $url, $link_text ); + } + + /** + * Check if pro version is installed and active. + * + * @return bool + */ + private function is_pro(): bool { + return defined( 'CODE_SNIPPETS_PRO' ) && CODE_SNIPPETS_PRO; + } +}