'; protected $table_name; public $limit = AIAUTOTOOL_FREE; private $plan_limit_aiautotool; public $name_plan; public $config = array(); public $notice; public function __construct() { global $wpdb; $this->table_name = $wpdb->prefix . 'aiautotool_keywords'; $this->name_plan = esc_html__('Autopost from Keyword', 'ai-auto-tool'); $this->plan_limit_aiautotool = 'plan_limit_aiautotool_' . $this->active_option_name; $this->notice = new aiautotool_Warning_Notice(); $this->active = get_option($this->active_option_name, true); if ($this->active == 'true') { $this->init(); } add_action('wp_ajax_update_active_option_canonical_' . $this->active_option_name, array($this, 'update_active_option_callback')); add_action('wp_ajax_nopriv_update_active_option_canonical_' . $this->active_option_name, array($this, 'update_active_option_callback')); add_action('wp_ajax_get_keyword_queue', array($this, 'get_keyword_queue_callback')); add_action('wp_ajax_run_keyword_cron_now', array($this, 'run_keyword_cron_now_callback')); add_action('wp_ajax_get_cron_status', array($this, 'get_cron_status_callback')); add_action('wp_ajax_bulk_delete_keywords', array($this, 'bulk_delete_keywords_callback')); add_action('wp_ajax_bulk_process_keywords', array($this, 'bulk_process_keywords_callback')); } public function create_keywords_table() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE IF NOT EXISTS {$this->table_name} ( id mediumint(9) NOT NULL AUTO_INCREMENT, keyword varchar(255) NOT NULL, category_id int(11) DEFAULT 0, tags text, language varchar(10) DEFAULT 'vi', status varchar(20) DEFAULT 'pending', priority int(11) DEFAULT 0, created_at datetime DEFAULT CURRENT_TIMESTAMP, processed_at datetime NULL, post_id int(11) DEFAULT 0, error_message text, PRIMARY KEY (id), KEY status (status), KEY priority (priority) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } public function init() { $this->create_keywords_table(); $configs = get_option($this->plan_limit_aiautotool, array()); if (!$this->aiautotool_has_plugin_data()) { $this->aiautotool_initialize_plugin_data(); $configs = (array) $this->aiautotool_has_plugin_data(); } if (!isset($configs['expiration'])) { $current_date = date('Y-m-d'); $expiration = strtotime('+1 month', strtotime($current_date)); $configs['expiration'] = date('Y-m-d', $expiration); } $this->config = array( 'number_post' => $this->limit, 'usage' => get_option($this->usage_option_name, 0, 'no'), 'time_exprice' => $configs['expiration'] ); if ($this->is_premium()->get_plan_name() == 'aiautotoolpro' || $this->is_premium()->get_plan_name() == 'premium') { $this->config = array( 'number_post' => -1, 'usage' => get_option($this->usage_option_name, 0, 'no'), 'time_exprice' => $this->is_premium()->_get_license()->expiration ); } add_action('admin_menu', array($this, 'add_menu')); add_action('admin_init', array($this, 'aiautotool_check_post_limit')); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); if ($this->aiautotool_checklimit($this->config)) { add_filter('cron_schedules', array($this, 'keyword_autopost_schedule_cron_intervals')); if (!wp_next_scheduled('keyword_autopost_cron_event')) { wp_schedule_event(time(), 'keyword_autopost_schedule_cron_intervals', 'keyword_autopost_cron_event'); } add_action('keyword_autopost_cron_event', array($this, 'process_keyword_autopost')); } else { $this->notice->add_notice( AIAUTOTOOL_TITLE_UPGRADE, 'notice-error', null, true, 'aiautotool' ); } add_action('wp_ajax_add_keywords', array($this, 'add_keywords_callback')); add_action('wp_ajax_nopriv_add_keywords', array($this, 'add_keywords_callback')); add_action('wp_ajax_delete_keyword', array($this, 'delete_keyword_callback')); add_action('wp_ajax_clear_keywords_log', array($this, 'clear_keywords_log_callback')); } public function keyword_autopost_schedule_cron_intervals($schedules) { $current_interval = get_option('keyword_autopost_time', 5); $schedules['keyword_autopost_schedule_cron_intervals'] = array( 'interval' => intval($current_interval) * 60, 'display' => __('Keyword autopost interval', 'ai-auto-tool') ); return $schedules; } public function process_keyword_autopost() { global $wpdb; $log = new AIautoTool_log(); $cron_widget = AIAutoTool_Cron_Status_Widget::get_instance(); // Update last run time update_option('keyword_autopost_last_run', current_time('Y-m-d H:i:s')); // Update cron status - starting $cron_widget->update_cron_status(array( 'is_running' => true, 'current_task' => __('Searching for pending keywords...', 'aiautotool-cron-widget'), 'current_post_title' => '', 'progress' => 10, 'cron_type' => __('Keyword Autopost', 'aiautotool-cron-widget') )); // Get pending keywords $pending_keywords = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE status = 'pending' ORDER BY priority DESC, created_at ASC LIMIT 1" ) ); if (empty($pending_keywords)) { $cron_widget->update_cron_status(array( 'is_running' => false, 'current_task' => __('No pending keywords found', 'aiautotool-cron-widget'), 'current_post_title' => '', 'progress' => 100, 'cron_type' => __('Keyword Autopost', 'aiautotool-cron-widget') )); return; } $keyword_data = $pending_keywords[0]; // Update status - found keyword $cron_widget->update_cron_status(array( 'is_running' => true, 'current_task' => __('Processing keyword...', 'aiautotool-cron-widget'), 'current_post_title' => $keyword_data->keyword, 'progress' => 20, 'cron_type' => __('Keyword Autopost', 'aiautotool-cron-widget') )); try { // Mark as processing $wpdb->update( $this->table_name, array('status' => 'processing'), array('id' => $keyword_data->id) ); if ($this->aiautotool_checklimit($this->config)) { $log->set_log('keyword_autopost', array( 'keyword_id' => $keyword_data->id, 'keyword' => $keyword_data->keyword, 'msg' => 'Starting keyword processing' )); // Generate title from keyword $cron_widget->update_cron_status(array( 'is_running' => true, 'current_task' => __('Generating title from keyword...', 'aiautotool-cron-widget'), 'current_post_title' => $keyword_data->keyword, 'progress' => 30, 'cron_type' => __('Keyword Autopost', 'aiautotool-cron-widget') )); $title = $this->generate_title_from_keyword($keyword_data->keyword, $keyword_data->language); if (!$title) { throw new Exception('Failed to generate title from keyword'); } // Generate content $cron_widget->update_cron_status(array( 'is_running' => true, 'current_task' => __('Generating content...', 'aiautotool-cron-widget'), 'current_post_title' => $title, 'progress' => 50, 'cron_type' => __('Keyword Autopost', 'aiautotool-cron-widget') )); $content = $this->generate_content_from_keyword($keyword_data->keyword, $keyword_data->language); if (!$content) { throw new Exception('Failed to generate content from keyword'); } // Process images $cron_widget->update_cron_status(array( 'is_running' => true, 'current_task' => __('Processing images...', 'aiautotool-cron-widget'), 'current_post_title' => $title, 'progress' => 70, 'cron_type' => __('Keyword Autopost', 'aiautotool-cron-widget') )); $content = $this->process_images_for_content($content, $title); // Validate and fix content before publishing (only if validation is enabled) if (get_option('keyword_autopost_content_validation', 1)) { $content = $this->validate_and_fix_content($content); } // Create and publish post $cron_widget->update_cron_status(array( 'is_running' => true, 'current_task' => __('Creating and publishing post...', 'aiautotool-cron-widget'), 'current_post_title' => $title, 'progress' => 90, 'cron_type' => __('Keyword Autopost', 'aiautotool-cron-widget') )); $post_id = $this->create_and_publish_post($title, $content, $keyword_data); if ($post_id) { // Update keyword status $wpdb->update( $this->table_name, array( 'status' => 'completed', 'processed_at' => current_time('mysql'), 'post_id' => $post_id ), array('id' => $keyword_data->id) ); $this->aiautotool_update_usage(); $log->set_log('keyword_autopost', array( 'keyword_id' => $keyword_data->id, 'keyword' => $keyword_data->keyword, 'post_id' => $post_id, 'msg' => 'Successfully created and published post' )); $cron_widget->update_cron_status(array( 'is_running' => false, 'current_task' => __('Post published successfully', 'aiautotool-cron-widget'), 'current_post_title' => $title, 'progress' => 100, 'cron_type' => __('Keyword Autopost', 'aiautotool-cron-widget') )); } else { throw new Exception('Failed to create and publish post'); } } else { throw new Exception('Usage limit exceeded'); } } catch (Exception $e) { // Update keyword status to error $wpdb->update( $this->table_name, array( 'status' => 'error', 'error_message' => $e->getMessage(), 'processed_at' => current_time('mysql') ), array('id' => $keyword_data->id) ); $log->set_log('keyword_autopost', array( 'keyword_id' => $keyword_data->id, 'keyword' => $keyword_data->keyword, 'msg' => 'Error: ' . $e->getMessage() )); $cron_widget->update_cron_status(array( 'is_running' => false, 'current_task' => __('Error: ' . $e->getMessage(), 'aiautotool-cron-widget'), 'current_post_title' => $keyword_data->keyword, 'progress' => 100, 'cron_type' => __('Keyword Autopost', 'aiautotool-cron-widget') )); } } private function generate_title_from_keyword($keyword, $language) { $bardGenContent = new BardGenContent(); $prompt = "Generate a compelling, SEO-friendly title for the keyword: '{$keyword}'. The title should be engaging and include the keyword naturally. Write in {$language}."; return $bardGenContent->gentitle($prompt, $language); } private function generate_content_from_keyword($keyword, $language) { $bardGenContent = new BardGenContent(); // Enhanced prompt to avoid markdown issues $prompt = "Write a comprehensive, informative article about '{$keyword}'. Requirements: - Write in {$language} - Minimum 1000 words - Use proper HTML formatting (h2, h3, p, ul, li, strong, em) - Do NOT use markdown code blocks or ``` symbols - Do NOT use
tags
- Do NOT include DOCTYPE, HTML, HEAD, BODY tags
- Do NOT return a complete HTML document
- Use proper paragraph breaks with tags
- Include relevant headings with
and tags
- Use bullet points with and - tags when appropriate
- Make it SEO-friendly with natural keyword usage
- Include practical information and examples
- Write in a conversational, engaging tone
Structure the article with:
1. Introduction paragraph
2. Main content with 3-4 sections
3. Conclusion paragraph
Return ONLY the article content with HTML formatting, NOT a complete HTML document.";
$content = $bardGenContent->bardcontentfull($prompt, $language);
// Post-process the content to fix any remaining issues (only if validation is enabled)
if (get_option('keyword_autopost_content_validation', 1)) {
$content = $this->clean_and_format_content($content);
}
return $content;
}
private function clean_and_format_content($content) {
// Remove DOCTYPE, HTML, HEAD, BODY tags and other unwanted elements
$content = preg_replace('/]*>/i', '', $content);
$content = preg_replace('/]*>/i', '', $content);
$content = preg_replace('/<\/html>/i', '', $content);
$content = preg_replace('/]*>.*?<\/head>/is', '', $content);
$content = preg_replace('/]*>/i', '', $content);
$content = preg_replace('/<\/body>/i', '', $content);
$content = preg_replace('/
]*>.*?<\/title>/is', '', $content);
$content = preg_replace('/]*>/i', '', $content);
$content = preg_replace('/]*>/i', '', $content);
$content = preg_replace('/
roles;
if (!in_array('administrator', $user_roles) && !is_super_admin()) {
return;
}
wp_localize_script('jquery', 'aiautotool_js_setting', array(
'ajax_url' => admin_url('admin-ajax.php'),
'security' => wp_create_nonce('aiautotool_nonce'),
'is_admin' => true
));
}
// Inherit methods from parent class
private function aiautotool_has_plugin_data() {
return get_option($this->plan_limit_aiautotool) !== false;
}
private function aiautotool_initialize_plugin_data() {
$current_date = date('Y-m-d');
$expiration = strtotime('+1 month', strtotime($current_date));
$expiration = date('Y-m-d', $expiration);
update_option($this->plan_limit_aiautotool, array('start_date' => $current_date, 'expiration' => $expiration));
}
public function aiautotool_check_post_limit() {
$stored_data = get_option($this->plan_limit_aiautotool, array());
$current_date = date('Y-m-d');
if ($this->is_new_month($current_date, $stored_data['start_date'])) {
$expiration = strtotime('+1 month', strtotime($current_date));
$expiration = date('Y-m-d', $expiration);
update_option($this->plan_limit_aiautotool, array('start_date' => $current_date, 'expiration' => $expiration));
update_option($this->usage_option_name, 0, null, 'no');
}
}
private function is_new_month($current_date, $start_date) {
$current_month = date('m', strtotime($current_date));
$start_month = date('m', strtotime($start_date));
return ($current_month != $start_month);
}
public function aiautotool_checklimit($config) {
return self::check_quota();
}
public function aiautotool_update_usage() {
$this->aiautotool_check_post_limit();
$current_value = get_option($this->usage_option_name, 0);
$new_value = $current_value + 1;
if ($this->config['number_post'] != -1) {
if ($this->config['number_post'] > $new_value) {
update_option($this->usage_option_name, $new_value, 'no');
}
} else {
update_option($this->usage_option_name, $new_value, 'no');
}
return $new_value;
}
public function render_plan() {
if ($this->active == 'true') {
$quota = $this->config['number_post'] == -1 ? 'Unlimited' : esc_html($this->config['number_post']);
echo wp_kses(
'' . $this->icon . ' ' . esc_html($this->name_plan) .
': Usage: ' . esc_html($this->config['usage']) . '
',
[
'p' => [],
'i' => ['class' => []],
'strong' => [],
]
);
}
}
public function update_active_option_callback() {
check_ajax_referer('aiautotool_nonce', 'security');
if (isset($_POST['active'])) {
$active = sanitize_text_field($_POST['active']);
update_option($this->active_option_name, $active, null, 'no');
print_r($active);
}
wp_die();
}
public function bulk_delete_keywords_callback() {
check_ajax_referer('aiautotool_nonce', 'security');
if (!current_user_can('manage_options')) {
wp_send_json_error('Insufficient permissions');
}
$keyword_ids = isset($_POST['keyword_ids']) ? array_map('intval', $_POST['keyword_ids']) : array();
if (empty($keyword_ids)) {
wp_send_json_error('No keywords selected');
}
global $wpdb;
$deleted_count = 0;
foreach ($keyword_ids as $keyword_id) {
$deleted = $wpdb->delete(
$this->table_name,
array('id' => $keyword_id),
array('%d')
);
if ($deleted) {
$deleted_count++;
}
}
wp_send_json_success(array(
'message' => sprintf(__('%d keywords deleted successfully', 'ai-auto-tool'), $deleted_count),
'deleted_count' => $deleted_count
));
}
public function bulk_process_keywords_callback() {
check_ajax_referer('aiautotool_nonce', 'security');
if (!current_user_can('manage_options')) {
wp_send_json_error('Insufficient permissions');
}
$keyword_ids = isset($_POST['keyword_ids']) ? array_map('intval', $_POST['keyword_ids']) : array();
if (empty($keyword_ids)) {
wp_send_json_error('No keywords selected');
}
global $wpdb;
$updated_count = 0;
foreach ($keyword_ids as $keyword_id) {
$updated = $wpdb->update(
$this->table_name,
array('status' => 'pending'),
array('id' => $keyword_id, 'status' => 'error'),
array('%s'),
array('%d', '%s')
);
if ($updated) {
$updated_count++;
}
}
wp_send_json_success(array(
'message' => sprintf(__('%d keywords queued for processing', 'ai-auto-tool'), $updated_count),
'updated_count' => $updated_count
));
}
public function render_keyword_queue_table($page = 1, $per_page = 20, $filter = 'all', $search = '', $sort_order = 'recent-completed') {
global $wpdb;
$offset = ($page - 1) * $per_page;
$where_conditions = array();
$where_values = array();
// Apply status filter
if ($filter !== 'all') {
$where_conditions[] = 'status = %s';
$where_values[] = $filter;
}
// Apply search filter
if (!empty($search)) {
$where_conditions[] = 'keyword LIKE %s';
$where_values[] = '%' . $wpdb->esc_like($search) . '%';
}
$where_clause = '';
if (!empty($where_conditions)) {
$where_clause = 'WHERE ' . implode(' AND ', $where_conditions);
}
// Get total count for pagination
$count_query = "SELECT COUNT(*) FROM {$this->table_name} {$where_clause}";
if (!empty($where_values)) {
$total_keywords = $wpdb->get_var($wpdb->prepare($count_query, $where_values));
} else {
$total_keywords = $wpdb->get_var($count_query);
}
// Build ORDER BY clause based on sort order
$order_by = $this->build_order_by_clause($sort_order);
// Get keywords for current page
$keywords_query = "SELECT * FROM {$this->table_name}
{$where_clause}
{$order_by}
LIMIT %d OFFSET %d";
$query_values = array_merge($where_values, array($per_page, $offset));
$keywords = $wpdb->get_results($wpdb->prepare($keywords_query, $query_values));
$total_pages = ceil($total_keywords / $per_page);
$html = '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
$html .= '';
// Pagination
if ($total_pages > 1) {
$html .= $this->render_pagination($page, $total_pages, $filter, $search);
}
return $html;
}
private function render_pagination($current_page, $total_pages, $filter, $search) {
$html = '';
$html .= '';
$html .= '' . sprintf(esc_html__('Page %d of %d', 'ai-auto-tool'), $current_page, $total_pages) . '';
$html .= '';
$html .= '';
// Previous button
if ($current_page > 1) {
$html .= '';
}
// Page numbers
$start_page = max(1, $current_page - 2);
$end_page = min($total_pages, $current_page + 2);
for ($i = $start_page; $i <= $end_page; $i++) {
$active_class = ($i == $current_page) ? 'active' : '';
$html .= '';
}
// Next button
if ($current_page < $total_pages) {
$html .= '';
}
$html .= '';
$html .= '';
return $html;
}
private function validate_and_fix_content($content) {
// Final validation and cleanup
$issues_found = array();
// Check for common markdown issues
if (strpos($content, '```') !== false) {
$issues_found[] = 'Found markdown code blocks';
$content = preg_replace('/```[a-zA-Z]*\n(.*?)\n```/s', '$1
', $content);
}
if (strpos($content, ']*>/', '', $content);
$content = preg_replace('/<\/code><\/pre>/', '
', $content);
$content = preg_replace('//', '', $content);
$content = preg_replace('/<\/code><\/pre>/', '
', $content);
}
if (strpos($content, 'language-') !== false) {
$issues_found[] = 'Found language attributes';
$content = preg_replace('/class="[^"]*language-[^"]*"/', '', $content);
}
// Check for DOCTYPE and HTML document tags
if (strpos($content, ']*>/i', '', $content);
}
if (strpos($content, ']*>/i', '', $content);
$content = preg_replace('/<\/html>/i', '', $content);
}
if (strpos($content, ']*>.*?<\/head>/is', '', $content);
}
if (strpos($content, ']*>/i', '', $content);
$content = preg_replace('/<\/body>/i', '', $content);
}
// Check for malformed paragraph tags
if (strpos($content, '') !== false) {
$issues_found[] = 'Found malformed paragraph tags';
$content = preg_replace('/
/', '
', $content);
$content = preg_replace('/<\/p><\/p>/', '
', $content);
}
// Check for unclosed tags
$open_tags = array();
preg_match_all('/<(\/?)([a-zA-Z0-9]+)/', $content, $matches);
foreach ($matches[2] as $index => $tag) {
if ($matches[1][$index] === '/') {
// Closing tag
if (end($open_tags) === $tag) {
array_pop($open_tags);
}
} else {
// Opening tag (skip self-closing tags)
if (!in_array($tag, array('img', 'br', 'hr', 'input', 'meta', 'link'))) {
$open_tags[] = $tag;
}
}
}
if (!empty($open_tags)) {
$issues_found[] = 'Found unclosed tags: ' . implode(', ', $open_tags);
// Close any remaining open tags
foreach (array_reverse($open_tags) as $tag) {
$content .= "{$tag}>";
}
}
// Ensure minimum content length
$text_content = strip_tags($content);
if (strlen($text_content) < 500) {
$issues_found[] = 'Content too short';
}
// Log any issues found
if (!empty($issues_found)) {
error_log('Keyword Autopost Content Issues: ' . implode(', ', $issues_found));
}
// Final cleanup
$content = $this->final_content_cleanup($content);
return $content;
}
private function final_content_cleanup($content) {
// Remove any remaining DOCTYPE and HTML document elements
$content = preg_replace('/]*>/i', '', $content);
$content = preg_replace('/]*>/i', '', $content);
$content = preg_replace('/<\/html>/i', '', $content);
$content = preg_replace('/]*>.*?<\/head>/is', '', $content);
$content = preg_replace('/]*>/i', '', $content);
$content = preg_replace('/<\/body>/i', '', $content);
// Remove any remaining markdown artifacts
$content = str_replace(['```', '`'], '', $content);
// Fix any double spaces
$content = preg_replace('/\s{2,}/', ' ', $content);
// Fix any double line breaks
$content = preg_replace('/\n\s*\n/', "\n", $content);
// Ensure proper spacing around HTML tags
$content = preg_replace('/>\s+', '><', $content);
// Remove any empty paragraphs
$content = preg_replace('/\s*<\/p>/', '', $content);
// Remove any malformed paragraph tags
$content = preg_replace('/
/', '
', $content);
$content = preg_replace('/<\/p><\/p>/', '
', $content);
// Ensure content starts and ends properly
$content = trim($content);
// Add a final paragraph wrapper if content doesn't start with a tag
if (!preg_match('/^', $content)) {
$content = '' . $content . '
';
}
return $content;
}
private function build_order_by_clause($sort_order) {
switch ($sort_order) {
case 'recent-completed':
return "ORDER BY
CASE
WHEN status = 'completed' THEN 1
WHEN status = 'processing' THEN 2
WHEN status = 'pending' THEN 3
WHEN status = 'error' THEN 4
END,
CASE
WHEN status = 'completed' THEN processed_at
ELSE created_at
END DESC";
case 'oldest-first':
return "ORDER BY created_at ASC";
case 'newest-first':
return "ORDER BY created_at DESC";
case 'priority':
return "ORDER BY priority DESC, created_at ASC";
default:
return "ORDER BY
CASE
WHEN status = 'completed' THEN 1
WHEN status = 'processing' THEN 2
WHEN status = 'pending' THEN 3
WHEN status = 'error' THEN 4
END,
CASE
WHEN status = 'completed' THEN processed_at
ELSE created_at
END DESC";
}
}
private function generate_tags_from_content($content, $keyword, $language) {
$bardGenContent = new BardGenContent();
// Extract text content for analysis
$text_content = strip_tags($content);
// Limit content length for API call
$text_content = substr($text_content, 0, 2000);
$prompt = "Analyze this article content and generate 5-8 relevant tags for SEO and content organization.
Article keyword: '{$keyword}'
Language: {$language}
Content preview: " . substr($text_content, 0, 500) . "...
Requirements:
- Generate 5-8 relevant tags
- Tags should be related to the main keyword and content topics
- Use single words or short phrases (2-3 words max)
- Separate tags with commas
- Write in {$language}
- Focus on SEO-friendly terms
- Include the main keyword and related terms
- Avoid generic terms like 'article', 'content', 'information'
Return only the tags separated by commas, no additional text.";
$tags_response = $bardGenContent->bardcontentfull($prompt, $language);
if (!$tags_response) {
// Fallback: return keyword-based tags
return $keyword;
}
// Clean up the response
$tags = trim($tags_response);
// Remove any HTML tags that might be returned
$tags = strip_tags($tags);
// Remove quotes, extra punctuation
$tags = str_replace(['"', "'", ';', '.'], '', $tags);
// Split by commas and clean each tag
$tag_array = array_map('trim', explode(',', $tags));
// Filter out empty tags and limit to 8 tags
$tag_array = array_filter($tag_array, function($tag) {
return !empty($tag) && strlen($tag) > 1;
});
// Limit to 8 tags maximum
$tag_array = array_slice($tag_array, 0, 8);
// If no tags generated, use the keyword
if (empty($tag_array)) {
return $keyword;
}
return implode(',', $tag_array);
}
private function format_tags_display($tags) {
if (empty($tags)) {
return '';
}
$tag_array = array_map('trim', explode(',', $tags));
$tag_array = array_filter($tag_array, function($tag) {
return !empty($tag) && strlen($tag) > 1;
});
if (empty($tag_array)) {
return '';
}
$formatted_tags = array();
foreach ($tag_array as $tag) {
$formatted_tags[] = '' . esc_html($tag) . '';
}
return implode(' ', $formatted_tags);
}
}