| Server IP : 158.247.231.215 / Your IP : 216.73.216.10 Web Server : Apache/2.4.41 (Ubuntu) System : Linux CTMS 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /mnt/blockstorage/ctms/api/custom-api/ |
Upload File : |
<?php
/**
* Update User Social Profiles API
* POST /api/custom-api/user-social-profiles-update.php
* Requires: Authorization header with Bearer token
* Body: {facebook, twitter, linkedin, website, github}
*/
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Authorization");
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}
// Load WordPress
require_once('/mnt/blockstorage/ctms/wp-load.php');
require_once('auth-helper.php');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
send_error_response('Only POST requests are allowed', 405);
}
// Verify JWT token
$user_id = verify_jwt_token();
if (!$user_id) {
send_error_response('User not authenticated', 401);
}
// Get POST data
$input = file_get_contents('php://input');
$data = json_decode($input, true);
if (!$data) {
$data = $_POST;
}
$facebook = isset($data['facebook']) ? sanitize_text_field($data['facebook']) : null;
$twitter = isset($data['twitter']) ? sanitize_text_field($data['twitter']) : null;
$linkedin = isset($data['linkedin']) ? sanitize_text_field($data['linkedin']) : null;
$website = isset($data['website']) ? esc_url_raw($data['website']) : null;
$github = isset($data['github']) ? sanitize_text_field($data['github']) : null;
// Update meta data
if ($facebook !== null) {
update_user_meta($user_id, '_tutor_profile_facebook', $facebook);
}
if ($twitter !== null) {
update_user_meta($user_id, '_tutor_profile_twitter', $twitter);
}
if ($linkedin !== null) {
update_user_meta($user_id, '_tutor_profile_linkedin', $linkedin);
}
if ($website !== null) {
update_user_meta($user_id, '_tutor_profile_website', $website);
}
if ($github !== null) {
update_user_meta($user_id, '_tutor_profile_github', $github);
}
send_json_response(array(
'success' => true,
'message' => 'Social profiles updated successfully',
'social_profiles' => array(
'facebook' => get_user_meta($user_id, '_tutor_profile_facebook', true) ?: '',
'twitter' => get_user_meta($user_id, '_tutor_profile_twitter', true) ?: '',
'linkedin' => get_user_meta($user_id, '_tutor_profile_linkedin', true) ?: '',
'website' => get_user_meta($user_id, '_tutor_profile_website', true) ?: '',
'github' => get_user_meta($user_id, '_tutor_profile_github', true) ?: '',
),
), 200);
?>