Skip to content

Commit

Permalink
Merge pull request #186 from rupok/pdev
Browse files Browse the repository at this point in the history
 Core Installer ( Possible issue, fix )
  • Loading branch information
rupok authored Feb 19, 2019
2 parents b040a64 + 4292164 commit 71b7c29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 11 additions & 9 deletions includes/class-wpdev-core-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
* WPDeveloper Core Install
*/
class WPDeveloper_Core_Installer {
/**
* Plugin Base Name
*
* @var string
*/
private $plugin_basename;
/**
* Instantiate the class
*
* @param string $affiliate
*/
function __construct() {
function __construct( $plugin_basename = '' ) {
$this->plugin_basename = $plugin_basename;
add_action( 'init', array( $this, 'init_hooks' ) );
}
/**
Expand All @@ -21,7 +28,7 @@ public function init_hooks() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
add_action( 'wp_ajax_wpdeveloper_upsale_core_install', array( $this, 'core_install' ) );
add_action( 'wp_ajax_wpdeveloper_upsale_core_install_' . $this->plugin_basename, array( $this, 'core_install' ) );
}
/**
* Fail if plugin installtion/activation fails
Expand All @@ -42,7 +49,7 @@ public function fail_on_error( $thing ) {
* @return void
*/
public function core_install() {
check_ajax_referer( 'wpdeveloper_upsale_core_install' );
check_ajax_referer( 'wpdeveloper_upsale_core_install_' . $this->plugin_basename );

if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'You don\'t have permission to install the plugins' ) );
Expand Down Expand Up @@ -92,9 +99,4 @@ public function install_plugin( $slug, $file ) {
return activate_plugin( $plugin_basename );
}
}
/**
* Initiate The Core Installer
*/
new WPDeveloper_Core_Installer();
endif;

endif;
10 changes: 6 additions & 4 deletions includes/class-wpdev-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public function __construct( $plugin_file = '', $version = '' ) {

if( ! class_exists( 'WPDeveloper_Core_Installer' ) ) {
require_once dirname( __FILE__ ) . '/class-wpdev-core-install.php';

new WPDeveloper_Core_Installer( $this->plugin_name );
}
}
/**
Expand Down Expand Up @@ -363,7 +365,7 @@ private function upsale_button(){
if( empty( $plugin_slug ) ) {
return;
}
echo '<button data-slug="'. $plugin_slug .'" id="plugin-install-core" class="button button-primary">'. __( 'Install Now!', $this->text_domain ) .'</button>';
echo '<button data-slug="'. $plugin_slug .'" id="plugin-install-core-'. $this->plugin_name .'" class="button button-primary">'. __( 'Install Now!', $this->text_domain ) .'</button>';
}
/**
* This methods is responsible for get notice image.
Expand Down Expand Up @@ -723,7 +725,7 @@ public function upsale_button_script(){
<script type="text/javascript">
jQuery(document).ready( function($) {
<?php if( ! empty( $plugin_slug ) && ! empty( $plugin_file ) ) : ?>
$('#plugin-install-core').on('click', function (e) {
$('#plugin-install-core-<?php echo $this->plugin_name; ?>').on('click', function (e) {
var self = $(this);
e.preventDefault();
self.addClass('install-now updating-message');
Expand All @@ -733,8 +735,8 @@ public function upsale_button_script(){
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
type: 'POST',
data: {
action: 'wpdeveloper_upsale_core_install',
_wpnonce: '<?php echo wp_create_nonce('wpdeveloper_upsale_core_install'); ?>',
action: 'wpdeveloper_upsale_core_install_<?php echo $this->plugin_name; ?>',
_wpnonce: '<?php echo wp_create_nonce('wpdeveloper_upsale_core_install_' . $this->plugin_name); ?>',
slug : '<?php echo $plugin_slug; ?>',
file : '<?php echo $plugin_file; ?>'
},
Expand Down

0 comments on commit 71b7c29

Please sign in to comment.