PluginProbe
Insert Html Snippet / trunk
Insert Html Snippet vtrunk
1.4.6 trunk 1.0 1.0.1 1.1 1.1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 All 27 releases
insert-html-snippet / ajax-handler.php

ajax-handler.php in Insert Html Snippet trunk, at ajax-handler.php

55 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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