PluginProbe
Insert PHP Code Snippet / 1.4.7
Insert PHP Code Snippet v1.4.7
1.4.7 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 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
insert-php-code-snippet / ajax-handler.php

ajax-handler.php in Insert PHP Code Snippet 1.4.7, at ajax-handler.php

111 lines 3.1 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 add_action('wp_ajax_ips_backlink', 'xyz_ips_ajax_backlink');
6 add_action("wp_ajax_xyz_ips_execute_shortcode","xyz_ips_execute_shortcode");
7 function xyz_ips_execute_shortcode() {
8 global $wpdb;
9
10 $response = array(
11 'status' => 0,
12 'message' => 'Unexpected error',
13 'data' => array()
14 );
15
16
17 try {
18 if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'xyz_ips_execute_shortcode')) {
19 $response['status'] = 0;
20 $response['message'] = 'Invalid request. Please try again.';
21 } else {
22
23 $id =intval($_POST['id']);
24
25
26 $shortcodeDetails = $wpdb->get_results($wpdb->prepare( "SELECT * FROM {$wpdb->prefix}xyz_ips_short_code WHERE id = %d AND insertionMethod = %d",$id, 3 ));
27 if(!empty($shortcodeDetails))
28 {
29 $shortcode =$shortcodeDetails[0];
30 $response['status'] = 1;
31 $response['message'] = 'Success';
32 $content_to_eval =xyz_ips_prepare_content_to_eval($shortcode->content);
33 try {
34
35 eval($content_to_eval);
36 $response['message'] = 'You have successfully executed the code in background';
37 } catch (Throwable $e) {
38
39 $response['status'] = 0;
40 $response['message'] = 'Error: ' . $e->getMessage();
41 }
42
43
44
45
46 }
47 else{
48 $response['message'] ='Invalid snippet id';
49 }
50 }
51 } catch (Exception $e) {
52
53 $response['status'] = 0;
54 $response['message'] = 'Error: ' . $e->getMessage();
55 }
56
57
58
59
60 wp_send_json($response);
61 wp_die();
62 }
63 function xyz_ips_ajax_backlink() {
64
65 check_ajax_referer('xyz-ips-blink','security');
66 if(current_user_can('administrator')){
67 global $wpdb;
68 if(isset($_POST)){
69 if(intval($_POST['enable'])==1){
70 update_option('xyz_credit_link','ips');
71 echo 1;
72 }
73 if(intval($_POST['enable'])==-1){
74 update_option('xyz_ips_credit_dismiss','dis');
75 echo -1;
76 }
77 }
78 }die;
79 }
80
81 add_action('wp_ajax_xyz_ips_sync_usage', function() {
82 global $wpdb;
83 $offset = isset($_POST['offset']) ? intval($_POST['offset']) : 0;
84 $batch_size = 100; // adjust as needed
85 $table_name = $wpdb->prefix . 'xyz_ips_usage';
86 // Get posts starting from $offset
87 $posts = $wpdb->get_results($wpdb->prepare(
88 "SELECT ID, post_content, post_type FROM {$wpdb->posts}
89 WHERE post_status = 'publish'
90 ORDER BY ID ASC
91 LIMIT %d, %d",
92 $offset, $batch_size
93 ));
94 if (empty($posts)) {
95 // Finished
96 update_option('xyz_ips_sync_needed', 0); // reset
97 wp_send_json_success(['status' => 'complete']);
98 }
99 foreach ($posts as $post) {
100 // Run your usage update logic
101 xyz_ips_update_usage_for_post($post->ID, $post->post_content, $post->post_type);
102 }
103 $new_offset = $offset + count($posts);
104 // Store the new offset
105 update_option('xyz_ips_sync_needed', $new_offset);
106 wp_send_json_success([
107 'status' => 'processing',
108 'new_offset' => $new_offset
109 ]);
110 });
111 ?>