settings = $settings ?: [ 'feed_title' => 'BdThemes News & Updates', 'transient_key' => 'bdthemes_product_feeds', 'feed_link' => 'https://bdthemes.com/feed', 'text_domain' => 'ultimate-store-kit', 'footer_links' => [ [ 'url' => 'https://bdthemes.com/blog/', 'title' => 'Blog', ], [ 'url' => 'https://bdthemes.com/knowledge-base/', 'title' => 'Docs', ], [ 'url' => 'https://store.bdthemes.com/', 'title' => 'Get Pro', ], [ 'url' => 'https://feedback.elementpack.pro/announcements/', 'title' => 'Changelog', ], ], ]; add_action('wp_dashboard_setup', [$this, 'register_rss_feeds']); } /** * Register RSS Feeds for Element Pack */ public function register_rss_feeds() { if (self::$feed_displayed) { /** * If the feed has already been displayed, do not add it again */ return; } wp_add_dashboard_widget( 'bdt-dashboard-overview', esc_html($this->settings['feed_title']), [$this, 'display_rss_feeds_content'], null, null, 'column4', 'core' ); /** * Mark the feed as displayed */ self::$feed_displayed = true; } /** * Display RSS Feeds Content */ public function display_rss_feeds_content() { echo wp_kses_post($this->get_rss_posts_data()); } /** * Get RSS Posts Data * * @return string */ private function get_rss_posts_data() { // Written out in full rather than concatenated so the prefix is visible to // static analysis. The resolved key is byte-identical to the previous // $this->settings['transient_key'] . '_rss', so no cached data is orphaned. $transient_key = 'bdthemes_product_feeds_rss'; $transient_failed_key = 'bdthemes_product_feeds_rss_failed'; $cached_data = get_transient($transient_key); if (! empty($cached_data)) { /** * Decode as associative array */ $rss_items = json_decode($cached_data, true); if (! is_array($rss_items)) { $rss_items = []; } } elseif (get_transient($transient_failed_key)) { /** * A recent fetch failed, so skip the blocking request entirely. */ $rss_items = []; } else { include_once ABSPATH . WPINC . '/feed.php'; add_action('wp_feed_options', [$this, 'set_feed_timeout']); $rss = fetch_feed($this->settings['feed_link']); remove_action('wp_feed_options', [$this, 'set_feed_timeout']); if (is_wp_error($rss)) { set_transient($transient_failed_key, 1, self::FAILURE_BACKOFF); return '
  • ' . esc_html__('Items Not Found', 'ultimate-store-kit') . '.
  • '; } $maxitems = $rss->get_item_quantity(5); $rss_items = $rss->get_items(0, $maxitems); /** * Convert RSS items to a simpler array to avoid serialization issues */ $simplified_rss_items = array_map(function ($item) { return [ 'title' => $item->get_title(), 'link' => $item->get_permalink(), 'date' => $item->get_date('U'), 'content' => $item->get_content(), ]; }, $rss_items); set_transient($transient_key, json_encode($simplified_rss_items), 6 * HOUR_IN_SECONDS); $rss_items = $simplified_rss_items; } ob_start(); ?>
    set_timeout(self::REQUEST_TIMEOUT); } /** * Check if a feed item is "new" (published within the last 7 days). * * @param int|string $date Unix timestamp. * @return bool */ private function is_feed_item_new($date) { $timestamp = is_numeric($date) ? (int) $date : strtotime($date); if (! $timestamp) { return false; } $cutoff = time() - (7 * DAY_IN_SECONDS); return $timestamp >= $cutoff; } }