Skip to content

Commit ff70a74

Browse files
committed
Add promotions
1 parent efd3df5 commit ff70a74

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-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: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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+
?>
32+
<div class="notice notice-info is-dismissibleX">
33+
<p>
34+
<strong><?php esc_html_e( '💡 Looking for a better way to manage custom code?', 'code-snippets' ); ?></strong>
35+
</p>
36+
<p>
37+
<?php
38+
printf(
39+
/* translators: %s: Code Snippets plugin name */
40+
esc_html__( '%s provides a powerful and user-friendly alternative to Elementor Custom Code, with cloud sync, advanced features, and an intuitive interface.', 'code-snippets' ),
41+
'<strong>Code Snippets Pro</strong>'
42+
);
43+
?>
44+
</p>
45+
<p>
46+
<a href="<?php echo esc_url( 'https://codesnippets.pro/pricing/?utm_source=elementor&utm_medium=banner&utm_campaign=custom-code' ); ?>" class="button button-primary" target="_blank">
47+
<?php esc_html_e( 'Learn More', 'code-snippets' ); ?>
48+
</a>
49+
<a href="<?php echo esc_url( admin_url( 'admin.php?page=snippets' ) ); ?>" class="button button-secondary">
50+
<?php esc_html_e( 'Try Code Snippets', 'code-snippets' ); ?>
51+
</a>
52+
</p>
53+
</div>
54+
<?php
55+
}
56+
57+
/**
58+
* Check if we're on the Custom Code admin screen.
59+
*
60+
* @return bool
61+
*/
62+
private function is_custom_code_screen(): bool {
63+
if ( ! is_admin() ) {
64+
return false;
65+
}
66+
67+
$current_screen = get_current_screen();
68+
69+
if ( ! $current_screen ) {
70+
return false;
71+
}
72+
73+
return in_array(
74+
$current_screen->id,
75+
[
76+
'edit-elementor_snippet',
77+
'elementor_snippet',
78+
],
79+
true
80+
);
81+
}
82+
83+
/**
84+
* Promotion on the Custom CSS section, inside the Elementor Editor.
85+
*
86+
* @return void
87+
*/
88+
public function promotion_in_custom_css_section() {
89+
add_action( 'elementor/element/common/section_custom_css/before_section_end', [ $this, 'add_promotion_to_custom_css_section' ], 10, 2 );
90+
}
91+
92+
/**
93+
* Register promotion section after the Custom CSS section.
94+
*
95+
* @param \Elementor\Widget_Base|\Elementor\Element_Base $element The Elementor element.
96+
*/
97+
public function add_promotion_to_custom_css_section( $element ) {
98+
99+
$element->add_control(
100+
'code_snippets_promotion_alert',
101+
[
102+
'type' => \Elementor\Controls_Manager::ALERT,
103+
'alert_type' => 'warning',
104+
'content' => esc_html__( 'Set locations and angle for each breakpoint to ensure the gradient adapts to different screen sizes.', 'code-snippets' ),
105+
'render_type' => 'ui',
106+
]
107+
);
108+
109+
$element->add_control(
110+
'code_snippets_promotion_notice',
111+
[
112+
'type' => \Elementor\Controls_Manager::NOTICE,
113+
'notice_type' => 'info',
114+
'dismissible' => true,
115+
'heading' => esc_html__( '💡 Looking for a better way to manage custom code?', 'code-snippets' ),
116+
'content' => sprintf(
117+
/* translators: %s: Code Snippets plugin name */
118+
esc_html__( '%s provides a powerful and user-friendly alternative to Elementor Custom Code, with cloud sync, advanced features, and an intuitive interface.', 'code-snippets' ),
119+
'<strong>Code Snippets Pro</strong>'
120+
),
121+
]
122+
);
123+
124+
$element->add_control(
125+
'code_snippets_promotion_raw_html',
126+
[
127+
'type' => \Elementor\Controls_Manager::RAW_HTML,
128+
'raw' => sprintf(
129+
'<div style="padding:12px;">
130+
<h3 style="margin-top:0; margin-bottom:8px; font-size:15px;">
131+
%s
132+
</h3>
133+
<p style="margin: 0 0 10px;">
134+
%s
135+
</p>
136+
<a href="%s" target="_blank" style="display:inline-block; padding:8px 14px; border-radius:4px; text-decoration:none; font-weight:500; border:1px solid #d33;">
137+
%s
138+
</a>
139+
</div>',
140+
esc_html__( '💡 Looking for a better way to manage custom code?', 'code-snippets' ),
141+
sprintf(
142+
/* translators: %s: Code Snippets plugin name */
143+
esc_html__( '%s provides a powerful and user-friendly alternative to Elementor Custom Code, with cloud sync, advanced features, and an intuitive interface.', 'code-snippets' ),
144+
'<strong>Code Snippets Pro</strong>'
145+
),
146+
esc_url( 'https://example.com/promo' ), // <-- Change to your promo URL.
147+
esc_html__( 'Learn More', 'code-snippets' )
148+
),
149+
'content_classes' => 'your-promo-class',
150+
]
151+
);
152+
}
153+
}

0 commit comments

Comments
 (0)