Skip to content

Commit 1d4d0bb

Browse files
authored
Merge pull request #307 from codesnippetspro/promotions
Add promotions
2 parents 883d44b + 75d9716 commit 1d4d0bb

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

src/php/class-plugin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ public function load_plugin() {
156156
$upgrade = new Upgrade( $this->version, $this->db );
157157
add_action( 'plugins_loaded', array( $upgrade, 'run' ), 0 );
158158
$this->licensing = new Licensing();
159+
160+
// Initialize promotions.
161+
new Promotions\Elementor_Pro();
159162
}
160163

161164
/**
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
namespace Code_Snippets\Promotions;
3+
4+
if ( ! defined( 'ABSPATH' ) ) {
5+
exit; // Exit if accessed directly.
6+
}
7+
8+
/**
9+
* Elementor Pro promotion class.
10+
*/
11+
class Elementor_Pro {
12+
13+
/**
14+
* Class constructor.
15+
*/
16+
public function __construct() {
17+
add_action( 'admin_notices', [ $this, 'promotion_in_custom_code_screen' ] );
18+
add_action( 'elementor/init', [ $this, 'promotion_in_custom_css_section' ] );
19+
}
20+
21+
/**
22+
* Promotion on the Custom Code post type screen in WordPress admin.
23+
*
24+
* @return void
25+
*/
26+
public function promotion_in_custom_code_screen() {
27+
if ( ! $this->is_custom_code_screen() ) {
28+
return;
29+
}
30+
?>
31+
<div class="notice notice-info is-dismissible">
32+
<p>
33+
<strong><?php esc_html_e( 'Looking for a better way to manage your custom code?', 'code-snippets' ); ?></strong>
34+
</p>
35+
<p>
36+
<?php esc_html_e( 'Code Snippets Pro provides a powerful and user-friendly alternative to Elementor Custom Code, with cloud sync, advanced features, and an intuitive interface.', 'code-snippets' ); ?>
37+
</p>
38+
<p>
39+
<a href="<?php echo esc_url( admin_url( 'admin.php?page=snippets' ) ); ?>" class="button button-primary">
40+
<?php esc_html_e( 'Manage your snippets', 'code-snippets' ); ?>
41+
</a>
42+
<a href="https://codesnippets.pro/pricing/?utm_source=elementor&utm_medium=banner&utm_campaign=custom-code" class="button button-secondary" target="_blank">
43+
<?php esc_html_e( 'Learn More', 'code-snippets' ); ?>
44+
</a>
45+
</p>
46+
</div>
47+
<?php
48+
}
49+
50+
/**
51+
* Check if we're on the Custom Code admin screen.
52+
*
53+
* @return bool
54+
*/
55+
private function is_custom_code_screen(): bool {
56+
if ( ! is_admin() ) {
57+
return false;
58+
}
59+
60+
$current_screen = get_current_screen();
61+
62+
if ( ! $current_screen ) {
63+
return false;
64+
}
65+
66+
return in_array(
67+
$current_screen->id,
68+
[
69+
'edit-elementor_snippet',
70+
'elementor_snippet',
71+
],
72+
true
73+
);
74+
}
75+
76+
/**
77+
* Promotion on the Custom CSS section, inside the Elementor Editor.
78+
*
79+
* @return void
80+
*/
81+
public function promotion_in_custom_css_section() {
82+
add_action( 'elementor/element/common/section_custom_css/before_section_end', [ $this, 'add_promotion_to_custom_css_section' ], 10, 2 );
83+
}
84+
85+
/**
86+
* Register promotion section after the Custom CSS section.
87+
*
88+
* @param \Elementor\Widget_Base|\Elementor\Element_Base $element The Elementor element.
89+
*/
90+
public function add_promotion_to_custom_css_section( $element ) {
91+
$element->add_control(
92+
'code_snippets_promotion_notice',
93+
[
94+
'type' => \Elementor\Controls_Manager::NOTICE,
95+
'notice_type' => 'info',
96+
'dismissible' => true,
97+
'heading' => esc_html__( 'Manage your custom styles', 'code-snippets' ),
98+
'content' => $this->get_promotion_content(),
99+
]
100+
);
101+
}
102+
103+
/**
104+
* Get the promotion content with appropriate link.
105+
*
106+
* @return string
107+
*/
108+
private function get_promotion_content(): string {
109+
$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' );
110+
111+
if ( $this->is_pro() ) {
112+
$link_text = esc_html__( 'Manage CSS snippets', 'code-snippets' );
113+
$url = admin_url( 'admin.php?page=snippets&type=css' );
114+
} else {
115+
$link_text = esc_html__( 'Learn More', 'code-snippets' );
116+
$url = 'https://codesnippets.pro/pricing/?utm_source=elementor&utm_medium=banner&utm_campaign=elementor-addon-custom-code';
117+
}
118+
119+
return sprintf( '%s <br><br><a href="%s" target="_blank" class="e-btn e-info" style="color:#fff;">%s</a>', $message, $url, $link_text );
120+
}
121+
122+
/**
123+
* Check if pro version is installed and active.
124+
*
125+
* @return bool
126+
*/
127+
private function is_pro(): bool {
128+
return defined( 'CODE_SNIPPETS_PRO' ) && CODE_SNIPPETS_PRO;
129+
}
130+
}

0 commit comments

Comments
 (0)