showWidget() ) { wp_add_dashboard_widget( 'aioseo-rss-feed', esc_html__( 'SEO News', 'all-in-one-seo-pack' ), [ $this, 'displayRssDashboardWidget', ] ); } } /** * Whether or not to show the widget. * * @since 4.0.0 * * @return boolean True if yes, false otherwise. */ protected function showWidget() { // API filter hook to disable showing SEO News dashboard widget. if ( false === apply_filters( 'aioseo_show_seo_news', true ) ) { return false; } return true; } /** * Display RSS Dashboard Widget * * @since 4.0.0 */ public function displayRssDashboardWidget() { // check if the user has chosen not to display this widget through screen options. $currentScreen = get_current_screen(); $hiddenWidgets = get_user_meta( get_current_user_id(), 'metaboxhidden_' . $currentScreen->id ); if ( $hiddenWidgets && count( $hiddenWidgets ) > 0 && is_array( $hiddenWidgets[0] ) && in_array( 'aioseo-rss-feed', $hiddenWidgets[0], true ) ) { return; } include_once( ABSPATH . WPINC . '/feed.php' ); $rssItems = aioseo()->cache->get( 'rss_feed' ); if ( null === $rssItems ) { $rss = fetch_feed( 'https://aioseo.com/feed/' ); if ( is_wp_error( $rss ) ) { esc_html_e( 'Temporarily unable to load feed.', 'all-in-one-seo-pack' ); return; } $rssItems = $rss->get_items( 0, 4 ); // Show four items. $cached = []; foreach ( $rssItems as $item ) { $cached[] = [ 'url' => $item->get_permalink(), 'title' => $item->get_title(), 'date' => $item->get_date( 'M jS Y' ), 'content' => substr( wp_strip_all_tags( $item->get_content() ), 0, 128 ) . '...', ]; } $rssItems = $cached; aioseo()->cache->update( 'rss_feed', $cached, 12 * HOUR_IN_SECONDS ); } ?>