'. esc_html__('Auto term settings not found', 'simple-tags') .'
';
wp_send_json($response);
}
if (empty($autoterm_data['post_types'])) {
$response['message'] = '
'. esc_html__('The selected Auto Term setting is not enabled for any post type. Please select at least one post type in the Auto Term settings.', 'simple-tags') .'
';
wp_send_json($response);
}
if (empty($autoterm_data['autoterm_for_existing_content'])) {
$response['message'] = '
'. esc_html__('The selected Auto Term is not enabled for existing content. Please enable it in Auto Term settings.', 'simple-tags') .'
';
wp_send_json($response);
}
$limit = (isset($autoterm_data['existing_terms_batches']) && (int)$autoterm_data['existing_terms_batches'] > 0) ? (int)$autoterm_data['existing_terms_batches'] : 2;
$sleep = (isset($autoterm_data['existing_terms_sleep']) && (int)$autoterm_data['existing_terms_sleep'] > 0) ? (int)$autoterm_data['existing_terms_sleep'] : 0;
if ($sleep > 0 && $start_from > 0) {
sleep($sleep);
}
$limit_days = (int) $autoterm_data['limit_days'];
$limit_days_sql = '';
if ($limit_days > 0) {
$limit_days_sql = 'AND post_date > "' . date('Y-m-d H:i:s', time() - $limit_days * 86400) . '"';
}
$post_types = $autoterm_data['post_types'];
$post_status = isset($autoterm_data['post_status']) && is_array($autoterm_data['post_status']) ? $autoterm_data['post_status'] : ['publish'];
$total = isset($_POST['total']) ? (int)$_POST['total'] : 0;
$post_types = array_map('sanitize_key', (array) $post_types);
$post_status = array_map('sanitize_key', (array) $post_status);
$post_types_placeholders = implode(',', array_fill(0, count($post_types), '%s'));
$post_status_placeholders = implode(',', array_fill(0, count($post_status), '%s'));
if ($autoterm_existing_content_exclude > 0) {
$sql = "SELECT ID, post_title, post_content FROM {$wpdb->posts}
LEFT JOIN {$wpdb->postmeta} ON ( ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_taxopress_autotermed' )
WHERE post_type IN ({$post_types_placeholders})
AND {$wpdb->postmeta}.post_id IS NULL
AND post_status IN ({$post_status_placeholders})
{$limit_days_sql}
ORDER BY ID DESC
LIMIT %d OFFSET %d";
$prepare_args = array_merge($post_types, $post_status, [$limit, $offset_start_from]);
$objects = (array) $wpdb->get_results($wpdb->prepare($sql, $prepare_args));
} else {
$sql = "SELECT ID, post_title, post_content FROM {$wpdb->posts}
WHERE post_type IN ({$post_types_placeholders})
AND post_status IN ({$post_status_placeholders})
{$limit_days_sql}
ORDER BY ID DESC
LIMIT %d OFFSET %d";
$prepare_args = array_merge($post_types, $post_status, [$limit, $offset_start_from]);
$objects = (array) $wpdb->get_results($wpdb->prepare($sql, $prepare_args));
}
$response_content = '';
if (!empty($objects)) {
foreach ($objects as $object) {
update_post_meta($object->ID, '_taxopress_autotermed', 1);
$post_object = get_post($object->ID);
SimpleTags_Client_Autoterms::auto_terms_post($post_object, $autoterm_data['taxonomy'], $autoterm_data, true, 'existing_content', 'st_autoterms');
$log_messages = !empty($empty_term_messages[$object->ID]['message']) ? $empty_term_messages[$object->ID]['message'] : [];
$log_message_html = '';
if (!empty($log_messages)) {
$log_message_html .= '
'. sprintf(esc_html__('Please leave this screen running to continue the scan. To stop the scan, close this screen or click here: %1sStop%2s | %3sPause%4s', 'simple-tags'), '', '', '', '') .'