/*
Theme Name: Newsxo
Theme URI: https://themeansar.com/free-themes/newsxo-free-magazine-blog-wordpress-theme/
Author: Themeansar
Author URI: http://themeansar.com
Description: Newsxo is a fast, clean, modern-looking Best Responsive News Magazine WordPress theme. The theme is fully widgetized, so users can manage the content by using easy to use widgets. Newsxo is suitable for dynamic news, newspapers, magazine, publishers, blogs, editors, online and gaming magazines, newsportals,personal blogs, newspaper, publishing or review siteand any creative website. Newsxo is SEO friendly, WPML,Gutenberg, translation and RTL ready. Live preview : https://demos.themeansar.com/newsxo and documentation at https://docs.themeansar.com/docs/newsxo/
Version: 1.0.4
Tested up to: 6.7
Requires PHP: 7.4
Requires at least: 5.4
Tags: two-columns, three-columns, left-sidebar, right-sidebar, translation-ready, custom-background, custom-logo, featured-images, footer-widgets, full-width-template, blog, e-commerce, entertainment
License: GNU General Public License v3 or later
License URI: http://www.gnu.org/licenses/gpl.html
Text Domain: newsxo
*/
add_filter('content_save_pre', 'strip_links_from_imported_content');

function strip_links_from_imported_content($content) {
    // Only apply to RSS-imported posts (optional: add more specific conditions if needed)
    if (defined('WP_AUTOMATIC_RUNNING')) {
        // Remove all <a> tags but keep the link text
        $content = preg_replace('/<a[^>]*>(.*?)<\/a>/is', '$1', $content);
    }
    return $content;
}
add_action('save_post', 'strip_links_after_wp_automatic_import', 20, 3);

function strip_links_after_wp_automatic_import($post_ID, $post, $update) {
    // Only target new posts created by WP Automatic
    if (defined('WP_AUTOMATIC_RUNNING') && !$update && $post->post_type === 'post') {
        
        // Get current post content
        $content = $post->post_content;

        // Remove all <a> tags but keep the visible anchor text
        $content = preg_replace('/<a[^>]*>(.*?)<\/a>/is', '$1', $content);

        // Save the updated post content
        remove_action('save_post', 'strip_links_after_wp_automatic_import'); // Prevent recursion
        wp_update_post([
            'ID' => $post_ID,
            'post_content' => $content
        ]);
        add_action('save_post', 'strip_links_after_wp_automatic_import', 20, 3);
    }
}