function enqueue_short_news_assets() {
wp_enqueue_style('your-existing-css-handle');
wp_enqueue_script('your-existing-js-handle', plugin_dir_url(__FILE__) . 'your-existing-js-file.js', ['jquery'], '1.0', true);
wp_localize_script('your-existing-js-handle', 'shortNewsSettings', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('short_news_nonce')
]);
}
add_action('wp_enqueue_scripts', 'enqueue_short_news_assets');
add_action('wp_ajax_load_more_news', 'load_more_news_handler');
add_action('wp_ajax_nopriv_load_more_news', 'load_more_news_handler');
function load_more_news_handler() {
check_ajax_referer('short_news_nonce', 'nonce');
$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
$limit = isset($_GET['limit']) ? intval($_GET['limit']) : 5;
$query = new WP_Query([
'post_type' => 'post',
'posts_per_page' => $limit,
'offset' => $offset,
'post_status' => 'publish',
]);
$posts = [];
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$posts[] = [
'id' => get_the_ID(),
'title' => get_the_title(),
'excerpt' => wp_trim_words(get_the_excerpt(), 20, '...'),
'link' => get_permalink(),
'featured_image_url' => get_the_post_thumbnail_url(get_the_ID(), 'medium') ?: '',
];
}
wp_reset_postdata();
}
wp_send_json($posts);
}
add_action('wp_ajax_toggle_bookmark', 'toggle_bookmark_handler');
function toggle_bookmark_handler() {
check_ajax_referer('short_news_nonce', 'nonce');
$post_id = intval($_POST['post_id']);
$user_id = get_current_user_id();
if (!$user_id || !$post_id) {
wp_send_json_error('Invalid user or post ID');
}
$bookmarks = get_user_meta($user_id, 'short_news_bookmarks', true);
if (!is_array($bookmarks)) {
$bookmarks = [];
}
if (in_array($post_id, $bookmarks)) {
$bookmarks = array_diff($bookmarks, [$post_id]);
update_user_meta($user_id, 'short_news_bookmarks', $bookmarks);
wp_send_json(['bookmarked' => false]);
} else {
$bookmarks[] = $post_id;
update_user_meta($user_id, 'short_news_bookmarks', $bookmarks);
wp_send_json(['bookmarked' => true]);
}
}
Warning: Cannot modify header information - headers already sent by (output started at /home2/indiarw9/tweelabs.com/wp-content/plugins/short-news/short-news.php:337) in /home2/indiarw9/tweelabs.com/wp-includes/pluggable.php on line 1450
Warning: Cannot modify header information - headers already sent by (output started at /home2/indiarw9/tweelabs.com/wp-content/plugins/short-news/short-news.php:337) in /home2/indiarw9/tweelabs.com/wp-includes/pluggable.php on line 1453