public function ajax_plugins()
{
if (!check_ajax_referer('envato_setup_nonce', 'wpnonce') || empty($_POST['slug'])) {
wp_send_json_error(array('error' => 1, 'message' => esc_html__('No Slug Found')));
}
$json = array();
// send back some json we use to hit up TGM
$plugins = $this->_get_plugins();
// what are we doing with this plugin?
foreach ($plugins['activate'] as $slug => $plugin) {
if ($_POST['slug'] == $slug) {
$json = array('url' => admin_url($this->tgmpa_url), 'plugin' => array($slug), 'tgmpa-page' => $this->tgmpa_menu_slug, 'plugin_status' => 'all', '_wpnonce' => wp_create_nonce('bulk-plugins'), 'action' => 'tgmpa-bulk-activate', 'action2' => -1, 'message' => esc_html__('Activating Plugin'));
break;
}
}
foreach ($plugins['update'] as $slug => $plugin) {
if ($_POST['slug'] == $slug) {
$json = array('url' => admin_url($this->tgmpa_url), 'plugin' => array($slug), 'tgmpa-page' => $this->tgmpa_menu_slug, 'plugin_status' => 'all', '_wpnonce' => wp_create_nonce('bulk-plugins'), 'action' => 'tgmpa-bulk-update', 'action2' => -1, 'message' => esc_html__('Updating Plugin'));
break;
}
}
foreach ($plugins['install'] as $slug => $plugin) {
if ($_POST['slug'] == $slug) {
$json = array('url' => admin_url($this->tgmpa_url), 'plugin' => array($slug), 'tgmpa-page' => $this->tgmpa_menu_slug, 'plugin_status' => 'all', '_wpnonce' => wp_create_nonce('bulk-plugins'), 'action' => 'tgmpa-bulk-install', 'action2' => -1, 'message' => esc_html__('Installing Plugin'));
break;
}
}
if ($json) {
$json['hash'] = md5(serialize($json));
// used for checking if duplicates happen, move to next plugin
wp_send_json($json);
} else {
wp_send_json(array('done' => 1, 'message' => esc_html__('Success')));
}
exit;
}