add_action('admin_init', 'calicanna_safe_batch_url_fix');
function calicanna_safe_batch_url_fix() {
// Sirf tab chalega jab aap admin dashboard par honge
if (!is_admin() || !current_user_can('manage_options')) {
return;
}
$search  = 'http://calicanna.cc';
$replace = 'https://calicanna.cc';
// Ek baar mein sirf 50 posts process karein (taaki server crash na ho)
$batch_size = 50; 
// Un posts ko nikalein jinki body mein http://calicanna.cc maujood hai
$posts = get_posts(array(
'post_type'   => array('post', 'page', 'product'), // Agar e-commerce hai toh product bhi handle hoga
'post_status' => 'any',
'numberposts' => $batch_size,
's'           => $search, // Sirf wahi posts uthayega jismein yeh link ho
));
if (empty($posts)) {
// Agar saare posts khatam ho chuke hain toh console mein success dikhaye
echo "<script>console.log('CaliCanna Fixer: All target posts have been successfully updated to HTTPS!');</script>";
return;
}
$updated_count = 0;
foreach ($posts as $post) {
$content = $post->post_content;
if (strpos($content, $search) !== false) {
$content = str_replace($search, $replace, $content);
wp_update_post(array(
'ID'           => $post->ID,
'post_content' => $content,
));
$updated_count++;
}
}
// Har baar jab aap page update ya refresh karenge, yeh console mein count batayega
echo "<script>
console.group('--- CaliCanna Batch Progress ---');
console.log('Status: Processing...');
console.log('This batch updated: " . $updated_count . " posts.');
console.log('Action: Keep refreshing the page until this group stops appearing.');
console.groupEnd();
</script>";
}
@media only screen and (max-width: 48em) { }