Redirect Snippet

add_action(‘rest_api_init’, function() {
register_rest_route(‘zeevou/v1’, ‘/create-redirect’, [
‘methods’ => ‘POST’,
‘callback’ => function($request) {
if ($request[‘secret’] !== ‘zeevou-redirect-2026’) {
return new WP_Error(‘unauthorized’, ‘Invalid secret’, [‘status’ => 401]);
}

$source = $request[‘source’];
$target = $request[‘target’];
$code = $request[‘code’] ?? 301;

// Method 1: Try using Redirection plugin if installed
if (class_exists(‘Red_Item’)) {
$redirect = Red_Item::create([
‘url’ => $source,
‘action_data’ => [‘url’ => $target],
‘action_type’ => ‘url’,
‘match_type’ => ‘url’,
‘action_code’ => $code,
‘group_id’ => 1
]);

if ($redirect) {
return [
‘success’ => true,
‘method’ => ‘redirection_plugin’,
‘source’ => $source,
‘target’ => $target,
‘code’ => $code
];
}
}

// Method 2: Store in options table for manual .htaccess generation
$redirects = get_option(‘zeevou_manual_redirects’, []);
$redirects[] = [
‘source’ => $source,
‘target’ => $target,
‘code’ => $code,
‘created’ => current_time(‘mysql’)
];
update_option(‘zeevou_manual_redirects’, $redirects);

return [
‘success’ => true,
‘method’ => ‘options_table’,
‘source’ => $source,
‘target’ => $target,
‘code’ => $code,
‘note’ => ‘Redirect stored in options table. Add to .htaccess manually.’
];
},
‘permission_callback’ => ‘__return_true’
]);
});

Scroll to Top
Solution lamp for mobile header

Custom Solutions with Zeevou

Discover tailored solutions perfectly suited to your role, business size, and specific use cases.