Skip to content

Commit

Permalink
Add happy addons banner
Browse files Browse the repository at this point in the history
  • Loading branch information
hasinur1997 committed Aug 5, 2019
1 parent 8d2d09f commit 9a16825
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 0 deletions.
53 changes: 53 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,56 @@ PLEASE DO NOT MODIFY*/
visibility: visible;
opacity: 1;
}
.wcct-notice-wrap {
overflow: hidden;
padding: 22px 15px;
}
.wcct-message-icon {
width: 10%;
float: left;
}
.wcct-message-icon img {
height: 50px;
}
.wcct-message-content {
width: 70%;
float: left;
margin-top: 20px;
}
.wcct-message-content p {
font-size: 16px;
padding: 0;
margin: 0;
}
.wcct-message-action {
width: 16.5%;
float: right;
text-align: center;
margin-right: 1.2%;
}
#wcct_remote_notice {
display: none;
}
#wcct-install-happ-addons {
background: #5c41d2 !important;
border-color: #5c41d2 !important;
box-shadow: 0 1px 0 #5c41d2;
color: #fff;
text-decoration: none;
text-shadow: 0 -1px 1px #5c41d2, 1px 0 1px #5c41d2, 0 1px 1px #5c41d2, -1px 0 1px #5c41d2;
height: inherit;
padding: 4px 20px;
display: flex;
align-items: center;
}
#wcct-install-happ-addons i {
margin-right: 7px;
}
#wcct-install-happ-addons:hover {
background: #150654 !important;
border-color: #150654 !important;
box-shadow: 0 1px 0 #150654;
color: #fff;
text-decoration: none;
text-shadow: 0 -1px 1px #150654, 1px 0 1px #150654, 0 1px 1px #150654, -1px 0 1px #150654;
}
Binary file added assets/images/happy-addons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,27 @@
$( tooltipText ).text( newText );
} );

// Install and activate happy addons
$( '#wcct-install-happ-addons' ).on( 'click', function( e ) {
e.preventDefault();
var loader = $( '#wcct-preloader' );
$('.wcct-update-icon').remove();
$(this).text('Installing...');
$(this).addClass( 'updating-message' );
loader.show();
var remote_message = $( '#wcct_remote_notice' );
wp.ajax.send( 'activate_happy_addons', {
success: function( response ) {
$('.wcct-notice-wrap').hide();
loader.hide();
remote_message.show();
remote_message.html('<p><strong>' + response.message + 'Happy Addons !</strong></p>');
},
error: function( error ) {
loader.hide();
remote_message.html('<p><strong>' + response.message + '</strong></p>');
}
} );
} );

})( jQuery );
35 changes: 35 additions & 0 deletions conversion-tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function init_hooks() {
add_action( 'init', array( $this, 'init_tracker' ) );
add_action( 'admin_notices', array( $this, 'check_woocommerce_exist' ) );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
add_action( 'admin_notices', array( $this, 'happy_addons_ads_banner' ) );
}

/**
Expand Down Expand Up @@ -286,6 +287,40 @@ public function check_woocommerce_exist() {
<?php
}
}

/**
* Add happy addons ads banner
*
* @return void
*/
public function happy_addons_ads_banner() {
if ( ! class_exists( '\Elementor\Plugin' ) ) {
return;
}

if ( class_exists( '\Happy_Addons\Elementor\Base' ) ) {
return;
}

?>
<div id="wcct_remote_notice" class="notice notice-success">
</div>
<div class="notice wcct-notice-wrap">
<div class="wcct-message-icon">
<img src="<?php echo WCCT_ASSETS . '/images/happy-addons.png'?>" alt="">
</div>
<div class="wcct-message-content">
<p><?php _e( 'Reach beyond your imagination in creating web pages. <strong> Try Happy Addons for Elementor to shape your dream.</strong> 😊') ?></p>
</div>
<div class="wcct-message-action">
<a href="" id="wcct-install-happ-addons" class="button button-primary"> <i class="dashicons dashicons-update wcct-update-icon"></i> Install Now For FREE</a>
<p></strong><a target="_blank" href="https://wordpress.org/plugins/happy-elementor-addons/">Read more details ➔</a>
</p>
</div>
</div>

<?php
}
}

function wcct_init() {
Expand Down
47 changes: 47 additions & 0 deletions includes/class-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class WCCT_Ajax {
*/
public function __construct() {
add_action( 'wp_ajax_wcct_save_settings', array( $this, 'wcct_save_settings' ) );
add_action( 'wp_ajax_activate_happy_addons', array( $this, 'wcct_install_happy_addons' ) );
}

/**
Expand Down Expand Up @@ -42,4 +43,50 @@ public function wcct_save_settings() {
) );

}
/**
* Install the Happy addons via ajax
*
* @return json
*/
public function wcct_install_happy_addons() {

include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

$upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );

$plugin = 'happy-elementor-addons';
$api = plugins_api( 'plugin_information', array( 'slug' => $plugin, 'fields' => array( 'sections' => false ) ) );


if (is_wp_error($api)) {
die(sprintf(__('ERROR: Error fetching plugin information: %s', 'woocommerce-conversion-tracking'), $api->get_error_message()));
}

add_filter( 'upgrader_package_options', function ( $options ) {
$options['clear_destination'] = true;
$options['hook_extra'] = [
'type' => 'plugin',
'action' => 'install',
'plugin' => 'happy-elementor-addons/plugin.php',
];
return $options;
});

$result = $upgrader->install( $api->download_link );

if ( is_wp_error( $result ) ) {
wp_send_json_error( $result );
}

$result = activate_plugin( 'happy-elementor-addons/plugin.php' );

if ( is_wp_error( $result ) ) {
wp_send_json_error( $result );
}
wp_send_json_success([
'message' => __( 'Successfully installed and activate,', 'woocommerce-conversion-tracking' )
]);
}

}

0 comments on commit 9a16825

Please sign in to comment.