PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.4.5
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.4.5
3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 All 177 releases
simple-tags / inc / ajax-request.php

ajax-request.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.4.5, at inc/ajax-request.php

73 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 //Taxopress auto terms => Auto terms all content ajax callback
3 add_action('wp_ajax_taxopress_autoterms_content_by_ajax', 'taxopress_autoterms_content_by_ajax');
4 function taxopress_autoterms_content_by_ajax()
5 {
6 global $wpdb;
7
8 // run a quick security check
9 check_ajax_referer('st-admin-js', 'security');
10
11 //instantiate response default value
12 $response['status'] = 'error';
13 $response['message'] = '';
14 $response['content'] = '';
15 $response['total'] = 0;
16 $response['next_start'] = 0;
17 $response['percentage'] = '';
18
19 $autoterms = taxopress_get_autoterm_data();
20 $auto_term_id = isset($_POST['auto_term_id']) ? (int)$_POST['auto_term_id'] : 0;
21 $start_from = isset($_POST['start_from']) ? (int)$_POST['start_from'] : 0;
22
23
24 if(!current_user_can('simple_tags')){
25 $response['message'] = esc_html__('Permission denied.', 'simple-tags');
26 wp_send_json($response);
27 }
28
29 if($auto_term_id === 0 ){
30 $response['message'] = esc_html__('Kindly save your auto terms settings before running this function', 'simple-tags');
31 wp_send_json($response);
32 }
33
34 if ($auto_term_id && array_key_exists($auto_term_id, $autoterms)) {
35 $autoterm_data = $autoterms[$auto_term_id];
36 }else{
37 $response['message'] = esc_html__('Auto term settings not found', 'simple-tags');
38 wp_send_json($response);
39 }
40
41 $post_types = $autoterm_data['post_types'];
42 $post_status = isset($autoterm_data['post_status']) && is_array($autoterm_data['post_status']) ? $autoterm_data['post_status'] : ['publish'];
43
44 $total = isset($_POST['total']) ? (int)$_POST['total'] : $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('%s') AND post_status IN ('%s')", implode( "', '", $post_types ), implode( "', '", $post_status ) ));
45 $response['total'] = $total;
46 $objects = (array) $wpdb->get_results($wpdb->prepare("SELECT ID, post_title, post_content FROM {$wpdb->posts} WHERE post_type IN ('%s') AND post_status IN ('%s') ORDER BY ID DESC LIMIT %d, 20", implode( "', '", $post_types ), implode( "', '", $post_status), $start_from ));
47
48 $response_content = '';
49 if (!empty($objects)) {
50 foreach ($objects as $object) {
51 SimpleTags_Client_Autoterms::auto_terms_post( $object, $autoterm_data['taxonomy'], $autoterm_data, true );
52 $response_content .= '<li>#' . $object->ID . ' ' . $object->post_title . '</li>';
53 unset($object);
54 }
55 $response['status'] = 'progress';
56 $response['content'] = $response_content;
57 $response['done'] = ($start_from + count($objects));
58 $percentage = round((($start_from + count($objects))/$total)*100);
59
60 } else {
61
62 $counter = (int)get_option('tmp_auto_terms_st');
63 delete_option('tmp_auto_terms_st');
64 $response['status'] = 'sucess';
65 $response['done'] = $total;
66 $response['message'] = sprintf(esc_html__('All done! %s terms added.', 'simple-tags'), $counter);
67 $percentage = 100;
68 }
69 $response['percentage'] = '<div class="taxopress-loader-border"><div class="taxopress-loader-green" style="width:'.$percentage.'%;">'.$percentage.'%</div></div>';
70
71 wp_send_json($response);
72
73 }