| 1516 | |
| 1517 | /** |
| 1518 | * 'WordPress.tv' dashboard widget. |
| 1519 | * |
| 1520 | * @since 5.4.2 |
| 1521 | */ |
| 1522 | function wp_dashboard_wp_tv() { |
| 1523 | ?> |
| 1524 | <div class="wordpress-tv hide-if-no-js"> |
| 1525 | <?php echo wp_dashboard_wp_tv_render(); ?> |
| 1526 | </div> |
| 1527 | <?php |
| 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * Render 'WordPress.tv' dashboard widget |
| 1532 | * |
| 1533 | * @since 5.4.2 |
| 1534 | * |
| 1535 | * @return string |
| 1536 | */ |
| 1537 | function wp_dashboard_wp_tv_render() { |
| 1538 | $feeds = array( |
| 1539 | 'news' => array( |
| 1540 | 'link' => apply_filters( 'wp_tv_dashboard_primary_link', __( 'https://wordpress.tv/feed' ) ), |
| 1541 | 'url' => apply_filters( 'wp_tv_dashboard_secondary_feed', __( 'https://wordpress.tv/feed' ) ), |
| 1542 | 'title' => apply_filters( 'wp_tv_dashboard_primary_title', __( 'WordPress.tv' ) ), |
| 1543 | 'items' => 8, |
| 1544 | 'show_summary' => 0, |
| 1545 | 'show_author' => 0, |
| 1546 | 'show_date' => 0, |
| 1547 | ), |
| 1548 | ); |
| 1549 | |
| 1550 | return wp_dashboard_wp_tv_output( 'dashboard_wp_tv', $feeds ); |
| 1551 | } |
| 1552 | |
| 1553 | /** |
| 1554 | * Generate the dashboard widget content |
| 1555 | * |
| 1556 | * @since 5.4.2 |
| 1557 | * |
| 1558 | * @param $widget_id |
| 1559 | * @param $feeds |
| 1560 | * |
| 1561 | * @return string the RSS feed output |
| 1562 | */ |
| 1563 | function wp_dashboard_wp_tv_output( $widget_id, $feeds ) { |
| 1564 | /** |
| 1565 | * Check if there is a cached version of the RSS Feed and output it |
| 1566 | */ |
| 1567 | $locale = get_user_locale(); |
| 1568 | $cache_key = 'wp_tv_dash_' . md5( $widget_id . '_' . $locale ); |
| 1569 | $rss_output = get_transient( $cache_key ); |
| 1570 | if ( false !== $rss_output ) { |
| 1571 | return $rss_output; |
| 1572 | } |
| 1573 | /** |
| 1574 | * Get the RSS Feed contents |
| 1575 | */ |
| 1576 | ob_start(); |
| 1577 | foreach ( $feeds as $type => $args ) { |
| 1578 | $args['type'] = $type; |
| 1579 | echo '<div class="rss-widget">'; |
| 1580 | wp_widget_rss_output( $args['url'], $args ); |
| 1581 | echo '</div>'; |
| 1582 | } |
| 1583 | $rss_output = ob_get_clean(); |
| 1584 | /** |
| 1585 | * Set up the cached version to expire in 12 hours and output the content |
| 1586 | */ |
| 1587 | set_transient( $cache_key, $rss_output, 12 * HOUR_IN_SECONDS ); |
| 1588 | return $rss_output; |
| 1589 | } |
| 1590 | |