| 1 |
<?php |
| 2 |
|
| 3 |
namespace HydraBooking\Admin; |
| 4 |
|
| 5 |
use HydraBooking\Admin\Controller\AdminMenu; |
| 6 |
use HydraBooking\Admin\Controller\Notification; |
| 7 |
use HydraBooking\Admin\Controller\UpdateController; |
| 8 |
use HydraBooking\Services\Integrations\Zoom\ZoomServices; |
| 9 |
use HydraBooking\Hooks\Mailer; |
| 10 |
use HydraBooking\Migration\Migration; |
| 11 |
use HydraBooking\Admin\Controller\NoticeController; |
| 12 |
use HydraBooking\Admin\Controller\licenseController; |
| 13 |
use HydraBooking\License\HydraBooking; |
| 14 |
// Load Migrator |
| 15 |
use HydraBooking\DB\Migrator; |
| 16 |
|
| 17 |
// exit |
| 18 |
if (! defined('ABSPATH')) { |
| 19 |
exit; |
| 20 |
} |
| 21 |
|
| 22 |
class Admin |
| 23 |
{ |
| 24 |
|
| 25 |
// constaract |
| 26 |
public function __construct() |
| 27 |
{ |
| 28 |
// run migrator |
| 29 |
new Migrator(); |
| 30 |
|
| 31 |
|
| 32 |
// admin menu |
| 33 |
new AdminMenu(); |
| 34 |
|
| 35 |
|
| 36 |
// update controller |
| 37 |
new UpdateController(); |
| 38 |
|
| 39 |
// notice controller |
| 40 |
new NoticeController(); |
| 41 |
|
| 42 |
// Notification controller |
| 43 |
// new Notification(); |
| 44 |
|
| 45 |
// activation hooks |
| 46 |
register_activation_hook(TFHB_URL, array($this, 'activate')); |
| 47 |
|
| 48 |
Migration::instance(); |
| 49 |
|
| 50 |
// license controller |
| 51 |
new HydraBooking(); |
| 52 |
new licenseController(); |
| 53 |
|
| 54 |
|
| 55 |
add_action('admin_init', array($this, 'tfhb_hydra_activation_redirect')); |
| 56 |
|
| 57 |
// Update Existing User Role |
| 58 |
add_action('admin_init', array($this, 'plugins_update_v_1_0_10')); |
| 59 |
|
| 60 |
// |
| 61 |
// add dome in admin footer based one page template |
| 62 |
add_action('admin_footer', array($this, 'add_admin_footer_content')); |
| 63 |
|
| 64 |
|
| 65 |
add_action('wp_ajax_tfhb_hydra_manage_plugin', array($this, 'tfhb_hydra_manage_plugin')); |
| 66 |
|
| 67 |
// send demo mail |
| 68 |
// add_action('admin_init', array( $this, 'tfhb_send_demo_mail' ) ); |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
public function tfhb_send_demo_mail() |
| 73 |
{ |
| 74 |
|
| 75 |
$to = get_option('admin_email'); |
| 76 |
$subject = 'Hydra Booking - Test Email'; |
| 77 |
$body = Mailer::mail_body_template([ |
| 78 |
'recipient_name' => 'Dear Admin', |
| 79 |
'title' => esc_html__('Your account has been activated', 'hydra-booking'), |
| 80 |
'subtitle' => esc_html__('Your account has been successfully activated.', 'hydra-booking'), |
| 81 |
'brand_name' => get_bloginfo('name'), |
| 82 |
/* translators: %s: Site name */ |
| 83 |
'footer_text' => sprintf(esc_html__('This is an automated email from %s, please do not reply.', 'hydra-booking'), get_bloginfo('name')), |
| 84 |
]); |
| 85 |
$headers = array('Content-Type: text/html; charset=UTF-8'); |
| 86 |
|
| 87 |
Mailer::send($to, $subject, $body, $headers); |
| 88 |
} |
| 89 |
|
| 90 |
public function add_admin_footer_content() |
| 91 |
{ |
| 92 |
if (! function_exists('get_current_screen')) { |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
$screen = get_current_screen(); |
| 97 |
|
| 98 |
if (empty($screen) || 'toplevel_page_hydra-booking' !== $screen->id) { |
| 99 |
return; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
public function tfhb_hydra_manage_plugin() |
| 105 |
{ |
| 106 |
check_ajax_referer('wp_rest', 'security'); |
| 107 |
|
| 108 |
if (!current_user_can('install_plugins')) { |
| 109 |
wp_send_json_error(__('You do not have permission to perform this action.', 'hydra-booking')); |
| 110 |
} |
| 111 |
|
| 112 |
$plugin_slug = isset($_POST['plugin_slug']) ? sanitize_text_field(wp_unslash($_POST['plugin_slug'])) : ''; |
| 113 |
$plugin_filename = isset($_POST['plugin_filename']) ? sanitize_text_field(wp_unslash($_POST['plugin_filename'])) : ''; |
| 114 |
$plugin_action = isset($_POST['plugin_action']) ? sanitize_text_field(wp_unslash($_POST['plugin_action'])) : ''; |
| 115 |
|
| 116 |
if (!$plugin_slug || !$plugin_action) { |
| 117 |
wp_send_json_error(__('Invalid request.', 'hydra-booking')); |
| 118 |
} |
| 119 |
|
| 120 |
include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 121 |
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 122 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 123 |
|
| 124 |
if ($plugin_action === 'install') { |
| 125 |
$api = plugins_api('plugin_information', ['slug' => $plugin_slug]); |
| 126 |
|
| 127 |
if (is_wp_error($api)) { |
| 128 |
wp_send_json_error($api->get_error_message()); |
| 129 |
} |
| 130 |
|
| 131 |
$upgrader = new \Plugin_Upgrader(new \WP_Ajax_Upgrader_Skin()); |
| 132 |
$install_result = $upgrader->install($api->download_link); |
| 133 |
|
| 134 |
if (is_wp_error($install_result)) { |
| 135 |
wp_send_json_error($install_result->get_error_message()); |
| 136 |
} |
| 137 |
|
| 138 |
wp_send_json_success(['message' => __('Installed successfully.', 'hydra-booking')]); |
| 139 |
} |
| 140 |
|
| 141 |
if ($plugin_action === 'activate') { |
| 142 |
$plugin_path = WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_filename . '.php'; |
| 143 |
|
| 144 |
if (!file_exists($plugin_path)) { |
| 145 |
wp_send_json_error(__('Plugin file not found.', 'hydra-booking')); |
| 146 |
} |
| 147 |
|
| 148 |
$activate_result = activate_plugin($plugin_path); |
| 149 |
|
| 150 |
if (is_wp_error($activate_result)) { |
| 151 |
wp_send_json_error($activate_result->get_error_message()); |
| 152 |
} |
| 153 |
|
| 154 |
wp_send_json_success(['message' => __('Activated successfully.', 'hydra-booking')]); |
| 155 |
} |
| 156 |
|
| 157 |
wp_send_json_error(__('Invalid action.', 'hydra-booking')); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
public function activate() |
| 162 |
{ |
| 163 |
// $Migrator = new Migrator(); |
| 164 |
new Migrator(); |
| 165 |
} |
| 166 |
|
| 167 |
public function tfhb_hydra_activation_redirect() |
| 168 |
{ |
| 169 |
if (wp_doing_ajax()) { |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
if (! get_option('tfhb_hydra_quick_setup')) { |
| 174 |
|
| 175 |
update_option('tfhb_hydra_quick_setup', 1); |
| 176 |
wp_safe_redirect(admin_url('admin.php?page=hydra-booking#/setup-wizard')); |
| 177 |
exit; |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
public function plugins_update_v_1_0_10() |
| 182 |
{ |
| 183 |
|
| 184 |
|
| 185 |
if (TFHB_VERSION == '1.0.10' && get_option('tfhb_update_status') != '1.0.10') { |
| 186 |
$role = get_role('tfhb_host'); |
| 187 |
// remove capabilities |
| 188 |
$role->remove_cap('edit_posts'); |
| 189 |
$role->remove_cap('edit_pages'); |
| 190 |
$role->remove_cap('edit_others_posts'); |
| 191 |
$role->remove_cap('create_posts'); |
| 192 |
$role->remove_cap('manage_categories'); |
| 193 |
$role->remove_cap('publish_posts'); |
| 194 |
$role->remove_cap('edit_themes'); |
| 195 |
$role->remove_cap('install_plugins'); |
| 196 |
$role->remove_cap('update_plugin'); |
| 197 |
$role->remove_cap('update_core'); |
| 198 |
$role->remove_cap('manage_options'); |
| 199 |
|
| 200 |
// Tfhb Update Status |
| 201 |
update_option('tfhb_update_status', '1.0.10'); |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
|