-
Notifications
You must be signed in to change notification settings - Fork 108
Add promotions #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add promotions #307
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| <?php | ||
| namespace Code_Snippets\Promotions; | ||
|
|
||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| exit; // Exit if accessed directly. | ||
| } | ||
|
|
||
| /** | ||
| * Elementor Pro promotion class. | ||
| */ | ||
| class Elementor_Pro { | ||
|
|
||
| /** | ||
| * Class constructor. | ||
| */ | ||
| public function __construct() { | ||
| add_action( 'admin_notices', [ $this, 'promotion_in_custom_code_screen' ] ); | ||
| add_action( 'elementor/init', [ $this, 'promotion_in_custom_css_section' ] ); | ||
| } | ||
|
|
||
| /** | ||
| * Promotion on the Custom Code post type screen in WordPress admin. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function promotion_in_custom_code_screen() { | ||
| if ( ! $this->is_custom_code_screen() ) { | ||
| return; | ||
| } | ||
| ?> | ||
| <div class="notice notice-info is-dismissible"> | ||
| <p> | ||
| <strong><?php esc_html_e( 'Looking for a better way to manage your custom code?', 'code-snippets' ); ?></strong> | ||
| </p> | ||
| <p> | ||
| <?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' ); ?> | ||
| </p> | ||
| <p> | ||
| <a href="<?php echo esc_url( admin_url( 'admin.php?page=snippets' ) ); ?>" class="button button-primary"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the proper API functions for generating plugin page URLs (e.g. |
||
| <?php esc_html_e( 'Manage your snippets', 'code-snippets' ); ?> | ||
| </a> | ||
| <a href="https://codesnippets.pro/pricing/?utm_source=elementor&utm_medium=banner&utm_campaign=custom-code" class="button button-secondary" target="_blank"> | ||
| <?php esc_html_e( 'Learn More', 'code-snippets' ); ?> | ||
| </a> | ||
| </p> | ||
| </div> | ||
| <?php | ||
| } | ||
|
|
||
| /** | ||
| * Check if we're on the Custom Code admin screen. | ||
| * | ||
| * @return bool | ||
| */ | ||
| private function is_custom_code_screen(): bool { | ||
| if ( ! is_admin() ) { | ||
| return false; | ||
| } | ||
|
|
||
| $current_screen = get_current_screen(); | ||
|
|
||
| if ( ! $current_screen ) { | ||
| return false; | ||
| } | ||
|
|
||
| return in_array( | ||
| $current_screen->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 <br><br><a href="%s" target="_blank" class="e-btn e-info" style="color:#fff;">%s</a>', $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; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure why this is its own class and sub-namespace. Shouldn't it be under
admin/? I also don't think it needs to be in the core plugin – it could be unique in Code Snippets Pro.