| 1 |
<?php |
| 2 |
|
| 3 |
namespace ULTP\Includes\Durbin; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
use ULTP\Includes\Durbin\Xpo; |
| 7 |
class OurPlugins { |
| 8 |
|
| 9 |
|
| 10 |
/** |
| 11 |
* Constructor. Hooks into various WordPress actions. |
| 12 |
*/ |
| 13 |
public function __construct() { |
| 14 |
// Our Plugin Activation Hooks. |
| 15 |
add_action( 'wp_ajax_ultp_install_plugin', array( $this, 'ultp_install_plugin_callback' ) ); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Handles plugin installation and activation via AJAX. |
| 20 |
* |
| 21 |
* @return void |
| 22 |
*/ |
| 23 |
public function ultp_install_plugin_callback() { |
| 24 |
|
| 25 |
$nonce = isset( $_POST['wpnonce'] ) ? sanitize_key( wp_unslash( $_POST['wpnonce'] ) ) : ''; |
| 26 |
$plugin = isset( $_POST['plugin'] ) ? $_POST['plugin'] : ''; |
| 27 |
|
| 28 |
if ( ! wp_verify_nonce( $nonce, 'ultp-nonce' ) || ! current_user_can( 'manage_options' ) ) { |
| 29 |
wp_send_json_error( array( 'message' => 'No plugin specified' ) ); |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
$res = array( 'message' => 'false' ); |
| 34 |
|
| 35 |
if ( $plugin ) { |
| 36 |
$res = Xpo::install_and_active_plugin( $plugin ); |
| 37 |
} |
| 38 |
|
| 39 |
wp_send_json_success( array( 'message' => $res ) ); |
| 40 |
|
| 41 |
die(); |
| 42 |
} |
| 43 |
} |
| 44 |
|