Changeset 3383806
- Timestamp:
- 10/24/2025 07:40:44 AM (5 months ago)
- File:
-
- 1 edited
-
quizell/trunk/plugin.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
quizell/trunk/plugin.php
r3383746 r3383806 16 16 session_start(); 17 17 } 18 const API_URL = 'https://api.quizell.com'; 19 const USER_DASHBOARD_APP = "https://app.quizell.com"; 20 // Create a tab in the admin dashboard 18 21 19 // Create a tab in the admin dashboard 22 20 add_action('admin_menu', 'quizell_admin_menu'); 23 //register_activation_hook(__FILE__, 'quizell_create_table'); 24 register_deactivation_hook(__FILE__, 'quizell_deactivate'); 21 25 22 26 23 function quizell_admin_menu() … … 41 38 } 42 39 43 function quizell_deactivate() 44 { 45 //logout user 46 quizell_destory_login_user(); 40 41 /** 42 * Load handler - simplified to always load Vue app without PHP redirects 43 */ 44 function quizell_handle_load() { 45 // Remove callback parameter from URL if present to clean it up 46 if (isset($_GET['callback'])) { 47 $clean_url = admin_url('admin.php?page=quizell'); 48 wp_safe_redirect($clean_url); 49 exit; 50 } 51 52 // Continue to page rendering - Vue app will handle routing 47 53 } 48 54 49 55 // include api and root page functions 50 require_once(dirname(__FILE__) . '/api-calls.php');51 require_once(dirname(__FILE__) . '/ajax-handlers.php');52 56 require_once(dirname(__FILE__) . '/includes/root-page.php'); 53 57 require_once(dirname(__FILE__) . '/includes/vue-root-page.php'); … … 141 145 } 142 146 }); 143 144 145 // AJAX actions for Resend OTP146 add_action('wp_ajax_quizell_resend_otp', 'quizell_resend_otp_callback');147 add_action('wp_ajax_nopriv_quizell_resend_otp', 'quizell_resend_otp_callback');148 149 function quizell_resend_otp_callback() {150 check_ajax_referer('quizell_resend_otp_nonce', 'nonce');151 152 $result = quizell_resend_otp(); // your existing function153 154 if ($result) {155 wp_send_json_success(['message' => 'OTP sent successfully']);156 } else {157 wp_send_json_error(['message' => 'Failed to send OTP']);158 }159 }160 161 162 function quizell_custom_scripts_enqueue() {163 wp_enqueue_script('custom-script', esc_url(plugins_url('../js/quizell-script.js', __FILE__)), array('jquery'), '1.0', true);164 }165 add_action('wp_enqueue_scripts', 'quizell_custom_scripts_enqueue');166 167 /**168 * Load handler - simplified to always load Vue app without PHP redirects169 */170 function quizell_handle_load() {171 // Remove callback parameter from URL if present to clean it up172 if (isset($_GET['callback'])) {173 $clean_url = admin_url('admin.php?page=quizell');174 wp_safe_redirect($clean_url);175 exit;176 }177 178 // Continue to page rendering - Vue app will handle routing179 }180 181 function quizell_admin_redirect(string $page_name)182 {183 $url = admin_url('admin.php?page=quizell&callback=' . urlencode($page_name));184 wp_safe_redirect($url);185 exit; // always stop execution after redirect186 }187 188 function quizell_admin_redirect_js(string $page_name)189 {190 $url = admin_url('admin.php?page=quizell&callback=' . urlencode($page_name));191 ?>192 <script>193 window.location.href = '<?php echo esc_url($url); ?>';194 </script>195 <?php196 exit;197 }198 199 function quizell_upate_login_record(string $email, string $password, string $access_token, bool $isVerified = false)200 {201 $_SESSION['quizell_is_verified'] = $isVerified;202 global $wpdb;203 $data = array(204 'email' => $email,205 'password' => $password,206 'access_token' => $access_token,207 'is_verified' => $isVerified,208 );209 //var_dump( wp_json_encode($data));210 if (update_option('quizell_login', wp_json_encode($data))) {211 return true;212 } else {213 //echo 'Error: ' . esc_js( $wpdb->last_error); // Echo the error214 return false;215 }216 }217 218 function quizell_delete_login_records(){219 220 delete_option('quizell_login');221 delete_option('quazilla_access_token');222 }223 224 function quizell_get_current_user(){225 $latest_record = json_decode(get_option('quizell_login'), true);226 $_SESSION['quizell_is_verified'] = $latest_record['is_user_verified'];227 return $latest_record;228 }229 230 function quizell_db_unverify_user(){231 $_SESSION['quizell_is_verified'] = false;232 $latest_record = json_decode(get_option('quizell_login'), true);233 if($latest_record['is_user_verified'] == 1){234 $data = array(235 'email' => $latest_record['email'] ,236 'password' => $latest_record['password'] ,237 'access_token' => $latest_record['access_token'] ,238 'is_verified' => 0,239 );240 }241 //var_dump( wp_json_encode($data));242 $test = update_option('quizell_login', wp_json_encode($data));243 }244 245 function quizell_db_verify_user(){246 $_SESSION['quizell_is_verified'] = true;247 $latest_record = json_decode(get_option('quizell_login'), true);248 249 //if($latest_record['is_user_verified'] == 0){250 $data = array(251 'email' => $latest_record['email'] ,252 'password' => $latest_record['password'] ,253 'access_token' => $latest_record['access_token'] ,254 'is_verified' => 1,255 );256 //}257 //var_dump( wp_json_encode($data));258 $test = update_option('quizell_login', wp_json_encode($data));259 }260 261 function quizell_is_current_user_verified(){262 $latest_record = json_decode(get_option('quizell_login'), true);263 if(isset($latest_record['is_verified']) && $latest_record['is_verified'] == 1){264 return true;265 }266 else{267 return false;268 }269 }270 271 272 function quizell_destory_login_user(){273 unset($_SESSION['quizell_access_token']);274 unset($_SESSION['quizell_is_verified']);275 quizell_delete_login_records();276 }277 278 279 function quizell_is_verified_route(){280 $verified_routes = [281 'dashboard',282 ];283 return in_array(quizell_get_route(), $verified_routes);284 }285 add_action('wp_ajax_update_sp_sl_woo_quizell_connect', 'sp_sl_quizell_update_coonect_woo_data');286 function sp_sl_quizell_update_coonect_woo_data(){287 $data_nonce = sanitize_text_field($_REQUEST['data_nonce']);288 if(wp_verify_nonce($data_nonce, 'submit_woo_quizell_connect')){289 $array = array(290 'saved' => 'no'291 );292 //$array['on'] = 'asdsad';293 $consumer_key = sanitize_text_field($_REQUEST['consumer_key']);294 $consumer_secret = sanitize_text_field($_REQUEST['consumer_secret']);295 $store_url = sanitize_url($_REQUEST['store_url']);296 if( $consumer_key == '' || $consumer_secret == '' || $store_url == ''){297 $array['error'] = 'All Fields are Mandatory';298 }299 else{300 $data = quizell_woo_zx_coonect_sp_sl_da($consumer_key, $consumer_secret, $store_url);301 $array['dumpdata'] = $data;302 if(isset($data['ok']) && $data['ok'] == true && isset($data['connection_id'])){303 update_option('quizell_woo_sp_sl_key', $consumer_key );304 update_option('quizell_woo_sp_sl_secret', $consumer_secret );305 update_option('quizell_woo_sp_sl_store_url', $store_url );306 update_option('quizell_woo_sp_sl_connection_id', sanitize_text_field($data['connection_id']) );307 $array['on'] = 'Connection Saved';308 $array['saved'] = 'Yes';309 }310 else{311 $array['on'] = $data;312 }313 314 }315 }316 wp_send_json( $array );317 wp_die();318 }
Note: See TracChangeset
for help on using the changeset viewer.