/**
 * Delete old feed items from the database to avoid bloat.
 * As of 3.8, it uses the new feed age system.
 *
 * @since 3.8
 */
function wprss_truncate_posts()
{
    // Get general settings
    $general_settings = get_option('wprss_settings_general');
    // Get all feed sources
    $feed_sources = wprss_get_all_feed_sources();
    // Check if there are feed sources
    if ($feed_sources->have_posts()) {
        // FOR EACH FEED SOURCE
        while ($feed_sources->have_posts()) {
            $feed_sources->the_post();
            // Get the max age setting for this feed source
            $max_age = wprss_get_max_age_for_feed_source(get_the_ID());
            // If the data is empty, do not delete
            if ($max_age === FALSE) {
                continue;
            }
            // Get all feed items for this source
            $feed_items = wprss_get_feed_items_for_source(get_the_ID());
            // If there are feed items
            if ($feed_items->have_posts()) {
                // Extend the timeout time limit for the deletion of the feed items
                $time_limit = wprss_get_item_import_time_limit();
                wprss_log("Extended execution time limit by {$time_limit}s for imported items truncation.", null, WPRSS_LOG_LEVEL_INFO);
                set_time_limit($time_limit);
                // For each feed item
                while ($feed_items->have_posts()) {
                    $feed_items->the_post();
                    // If the post is older than the maximum age
                    if (wprss_is_feed_item_older_than(get_the_ID(), $max_age) === TRUE) {
                        // Delete the post
                        wp_delete_post(get_the_ID(), true);
                    }
                }
                // Reset feed items query data
                wp_reset_postdata();
            }
        }
        // Reset feed sources query data
        wp_reset_postdata();
    }
    // If the filter to use the fixed limit is enabled, call the old truncation function
    if (apply_filters('wprss_use_fixed_feed_limit', FALSE) === TRUE && isset($general_settings['limit_feed_items_db'])) {
        wprss_old_truncate_posts();
    }
}
Esempio n. 2
0
/**
 * Delete old feed items from the database to avoid bloat.
 * As of 3.8, it uses the new feed age system.
 *
 * @since 3.8
 */
function wprss_truncate_posts()
{
    $general_settings = get_option('wprss_settings_general');
    // Get all feed sources
    $feed_sources = wprss_get_all_feed_sources();
    if ($feed_sources->have_posts()) {
        // FOR EACH FEED SOURCE
        while ($feed_sources->have_posts()) {
            $feed_sources->the_post();
            // Get the max age setting for this feed source
            $max_age = wprss_get_max_age_for_feed_source(get_the_ID());
            // If the data is empty, do not delete
            if ($max_age !== FALSE) {
                // Get all feed items for this source
                $feed_items = wprss_get_feed_items_for_source(get_the_ID());
                // FOR EACH FEED ITEM
                if ($feed_items->have_posts()) {
                    while ($feed_items->have_posts()) {
                        $feed_items->the_post();
                        // If the post is older than the maximum age
                        if (wprss_is_feed_item_older_than(get_the_ID(), $max_age) === TRUE) {
                            // Delete the post
                            wp_delete_post(get_the_ID(), true);
                        }
                    }
                    // Reset feed items query data
                    wp_reset_postdata();
                }
            }
        }
        // Reset feed sources query data
        wp_reset_postdata();
    }
    // If the filter to use the fixed limit is enabled, call the old truncation function
    if (apply_filters('wprss_use_fixed_feed_limit', FALSE) === TRUE && isset($general_settings['limit_feed_items_db'])) {
        wprss_old_truncate_posts();
    }
}