diff --git a/src/php/class-plugin.php b/src/php/class-plugin.php index faa3ddc3..688a10c2 100644 --- a/src/php/class-plugin.php +++ b/src/php/class-plugin.php @@ -160,9 +160,9 @@ public function load_plugin() { // Importers. new Plugins_Import_Manager(); new Files_Import_Manager(); - - // Initialize promotions. - new Promotions\Elementor_Pro(); + + // Promotions. + new Promotion_Manager(); } /** diff --git a/src/php/promotions/admin-notices/elementor.php b/src/php/promotions/admin-notices/elementor.php new file mode 100644 index 00000000..69187743 --- /dev/null +++ b/src/php/promotions/admin-notices/elementor.php @@ -0,0 +1,55 @@ +get_plugin_name() + ); + } + + public function get_promotion_buttons(): array { + return [ + [ + 'url' => code_snippets()->get_menu_url(), + 'text' => esc_html__( 'Manage your snippets', 'code-snippets' ), + 'class' => 'button button-primary', + ], + [ + 'url' => 'https://codesnippets.pro/pricing/?utm_source=' . $this->get_plugin_slug() . '&utm_medium=promotion&utm_campaign=custom-code', + 'text' => esc_html__( 'Learn More', 'code-snippets' ), + 'class' => 'button button-secondary', + 'target' => '_blank', + ], + ]; + } +} diff --git a/src/php/promotions/admin-notices/head-footer-code.php b/src/php/promotions/admin-notices/head-footer-code.php new file mode 100644 index 00000000..0d383500 --- /dev/null +++ b/src/php/promotions/admin-notices/head-footer-code.php @@ -0,0 +1,48 @@ +get_plugin_name() + ); + } + + public function get_promotion_buttons(): array { + return [ + [ + 'url' => code_snippets()->get_menu_url(), + 'text' => esc_html__( 'Manage your snippets', 'code-snippets' ), + 'class' => 'button button-primary', + ], + [ + 'url' => 'https://codesnippets.pro/pricing/?utm_source=' . $this->get_plugin_slug() . '&utm_medium=promotion&utm_campaign=custom-code', + 'text' => esc_html__( 'Learn More', 'code-snippets' ), + 'class' => 'button button-secondary', + 'target' => '_blank', + ], + ]; + } +} diff --git a/src/php/promotions/admin-notices/header-footer-code-manager.php b/src/php/promotions/admin-notices/header-footer-code-manager.php new file mode 100644 index 00000000..691e212c --- /dev/null +++ b/src/php/promotions/admin-notices/header-footer-code-manager.php @@ -0,0 +1,69 @@ +get_plugin_name() + ); + } + + public function get_promotion_buttons(): array { + $buttons = []; + + if ( $this->has_snippets() ) { + $buttons[] = [ + 'url' => add_query_arg( 'tab', 'plugins', code_snippets()->get_menu_url( 'import' ) ), + 'text' => esc_html__( 'Migrate to Code Snippets', 'code-snippets' ), + 'class' => 'button button-primary', + ]; + } else { + $buttons[] = [ + 'url' => code_snippets()->get_menu_url(), + 'text' => esc_html__( 'Manage your snippets', 'code-snippets' ), + 'class' => 'button button-primary', + ]; + } + + $buttons[] = [ + 'url' => 'https://codesnippets.pro/pricing/?utm_source=' . $this->get_plugin_slug() . '&utm_medium=promotion&utm_campaign=custom-code', + 'text' => esc_html__( 'Learn More', 'code-snippets' ), + 'class' => 'button button-secondary', + 'target' => '_blank', + ]; + + return $buttons; + } + + protected function has_snippets(): bool { + $importer = new Header_Footer_Code_Manager_Importer(); + $data = $importer->get_data(); + return ! empty( $data ); + } +} diff --git a/src/php/promotions/admin-notices/insert-html-snippet.php b/src/php/promotions/admin-notices/insert-html-snippet.php new file mode 100644 index 00000000..3a02bf92 --- /dev/null +++ b/src/php/promotions/admin-notices/insert-html-snippet.php @@ -0,0 +1,51 @@ +get_plugin_name() + ); + } + + public function get_promotion_buttons(): array { + return [ + [ + 'url' => code_snippets()->get_menu_url(), + 'text' => esc_html__( 'Manage your snippets', 'code-snippets' ), + 'class' => 'button button-primary', + ], + [ + 'url' => 'https://codesnippets.pro/pricing/?utm_source=' . $this->get_plugin_slug() . '&utm_medium=promotion&utm_campaign=custom-code', + 'text' => esc_html__( 'Learn More', 'code-snippets' ), + 'class' => 'button button-secondary', + 'target' => '_blank', + ], + ]; + } +} diff --git a/src/php/promotions/admin-notices/insert-php-code-snippet.php b/src/php/promotions/admin-notices/insert-php-code-snippet.php new file mode 100644 index 00000000..f07056a3 --- /dev/null +++ b/src/php/promotions/admin-notices/insert-php-code-snippet.php @@ -0,0 +1,69 @@ +get_plugin_name() + ); + } + + public function get_promotion_buttons(): array { + $buttons = []; + + if ( $this->has_snippets() ) { + $buttons[] = [ + 'url' => add_query_arg( 'tab', 'plugins', code_snippets()->get_menu_url( 'import' ) ), + 'text' => esc_html__( 'Migrate to Code Snippets', 'code-snippets' ), + 'class' => 'button button-primary', + ]; + } else { + $buttons[] = [ + 'url' => code_snippets()->get_menu_url(), + 'text' => esc_html__( 'Manage your snippets', 'code-snippets' ), + 'class' => 'button button-primary', + ]; + } + + $buttons[] = [ + 'url' => 'https://codesnippets.pro/pricing/?utm_source=' . $this->get_plugin_slug() . '&utm_medium=promotion&utm_campaign=custom-code', + 'text' => esc_html__( 'Learn More', 'code-snippets' ), + 'class' => 'button button-secondary', + 'target' => '_blank', + ]; + + return $buttons; + } + + protected function has_snippets(): bool { + $importer = new Insert_PHP_Code_Snippet_Importer(); + $data = $importer->get_data(); + return ! empty( $data ); + } +} diff --git a/src/php/promotions/admin-notices/insert-php.php b/src/php/promotions/admin-notices/insert-php.php new file mode 100644 index 00000000..555065b2 --- /dev/null +++ b/src/php/promotions/admin-notices/insert-php.php @@ -0,0 +1,54 @@ +get_plugin_name() + ); + } + + public function get_promotion_buttons(): array { + return [ + [ + 'url' => code_snippets()->get_menu_url(), + 'text' => esc_html__( 'Manage your snippets', 'code-snippets' ), + 'class' => 'button button-primary', + ], + [ + 'url' => 'https://codesnippets.pro/pricing/?utm_source=' . $this->get_plugin_slug() . '&utm_medium=promotion&utm_campaign=custom-code', + 'text' => esc_html__( 'Learn More', 'code-snippets' ), + 'class' => 'button button-secondary', + 'target' => '_blank', + ], + ]; + } +} diff --git a/src/php/promotions/admin-notices/wp-headers-and-footers.php b/src/php/promotions/admin-notices/wp-headers-and-footers.php new file mode 100644 index 00000000..9b526d56 --- /dev/null +++ b/src/php/promotions/admin-notices/wp-headers-and-footers.php @@ -0,0 +1,48 @@ +get_plugin_name() + ); + } + + public function get_promotion_buttons(): array { + return [ + [ + 'url' => code_snippets()->get_menu_url(), + 'text' => esc_html__( 'Manage your snippets', 'code-snippets' ), + 'class' => 'button button-primary', + ], + [ + 'url' => 'https://codesnippets.pro/pricing/?utm_source=' . $this->get_plugin_slug() . '&utm_medium=promotion&utm_campaign=custom-code', + 'text' => esc_html__( 'Learn More', 'code-snippets' ), + 'class' => 'button button-secondary', + 'target' => '_blank', + ], + ]; + } +} diff --git a/src/php/promotions/elementor-pro.php b/src/php/promotions/elementor-pro.php deleted file mode 100644 index 8a01396b..00000000 --- a/src/php/promotions/elementor-pro.php +++ /dev/null @@ -1,130 +0,0 @@ -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+ get_promotion_heading(); ?> +
++ get_promotion_message(); ?> +
++ get_promotion_buttons(); + + foreach ( $buttons as $button ) { + $url = isset( $button['url'] ) ? esc_url( $button['url'] ) : ''; + $text = isset( $button['text'] ) ? $button['text'] : ''; + $class = isset( $button['class'] ) ? esc_attr( $button['class'] ) : 'button'; + $target = isset( $button['target'] ) ? esc_attr( $button['target'] ) : ''; + + printf( + '%s ', + $url, + $class, + $target ? ' target="' . $target . '"' : '', + $text + ); + } + ?> +
+