| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) |
| 3 |
exit; |
| 4 |
|
| 5 |
|
| 6 |
add_action('wp_ajax_ihs_backlink', 'xyz_ihs_ajax_backlink'); |
| 7 |
function xyz_ihs_ajax_backlink() { |
| 8 |
check_ajax_referer('xyz-ihs-blink','security'); |
| 9 |
if(current_user_can('administrator')){ |
| 10 |
global $wpdb; |
| 11 |
if(isset($_POST)){ |
| 12 |
if(intval($_POST['enable'])==1){ |
| 13 |
update_option('xyz_credit_link','ihs'); |
| 14 |
echo 1; |
| 15 |
} |
| 16 |
if(intval($_POST['enable'])==-1){ |
| 17 |
update_option('xyz_ihs_credit_dismiss','dis'); |
| 18 |
echo -1; |
| 19 |
} |
| 20 |
} |
| 21 |
}die; |
| 22 |
} |
| 23 |
add_action('wp_ajax_xyz_ihs_sync_usage', function() { |
| 24 |
global $wpdb; |
| 25 |
|
| 26 |
$offset = isset($_POST['offset']) ? intval($_POST['offset']) : 0; |
| 27 |
$batch_size = 1; // adjust as needed |
| 28 |
$table_name = $wpdb->prefix . 'xyz_ihs_usage'; |
| 29 |
// Get posts starting from $offset |
| 30 |
$posts = $wpdb->get_results($wpdb->prepare( |
| 31 |
"SELECT ID, post_content, post_type FROM {$wpdb->posts} |
| 32 |
WHERE post_status = 'publish' |
| 33 |
ORDER BY ID ASC |
| 34 |
LIMIT %d, %d", |
| 35 |
$offset, $batch_size |
| 36 |
)); |
| 37 |
if (empty($posts)) { |
| 38 |
// Finished |
| 39 |
update_option('xyz_ihs_sync_needed', 0); // reset |
| 40 |
wp_send_json_success(['status' => 'complete']); |
| 41 |
} |
| 42 |
foreach ($posts as $post) { |
| 43 |
// Run your usage update logic |
| 44 |
xyz_ihs_update_usage_for_post($post->ID, $post->post_content, $post->post_type); |
| 45 |
} |
| 46 |
$new_offset = $offset + count($posts); |
| 47 |
// Store the new offset |
| 48 |
update_option('xyz_ihs_sync_needed', $new_offset); |
| 49 |
wp_send_json_success([ |
| 50 |
'status' => 'processing', |
| 51 |
'new_offset' => $new_offset |
| 52 |
]); |
| 53 |
}); |
| 54 |
?> |
| 55 |
|