Make WordPress Core

Ticket #43441: 43441.diff

File 43441.diff, 5.6 KB (added by iandunn, 5 years ago)

WIP attempting comment:3 - not elegant

  • Gruntfile.js

    diff --git Gruntfile.js Gruntfile.js
    index 7d820e1075..0188625447 100644
    module.exports = function(grunt) { 
    11271127                                files: [
    11281128                                        SOURCE_DIR + '**',
    11291129                                        '!' + SOURCE_DIR + 'js/**/*.js',
     1130                                        '!' + SOURCE_DIR + 'wp-content/**',
    11301131                                        // Ignore version control directories.
    11311132                                        '!' + SOURCE_DIR + '**/.{svn,git}/**'
    11321133                                ],
  • src/wp-admin/includes/dashboard.php

    diff --git src/wp-admin/includes/dashboard.php src/wp-admin/includes/dashboard.php
    index edc30cda2c..17c75bf950 100644
    function wp_dashboard_rss_output( $widget_id ) { 
    10941094 * @return bool True on success, false on failure.
    10951095 */
    10961096function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) {
     1097        /*
     1098        always show the latest new item
     1099        if the 2nd was published less than 7-10 days ago, show it too
     1100        */
     1101
    10971102        $loading    = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&hellip;' ) . '</p><div class="hide-if-js notice notice-error inline"><p>' . __( 'This widget requires JavaScript.' ) . '</p></div>';
    10981103        $doing_ajax = wp_doing_ajax();
    10991104
    function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = ar 
    11081113
    11091114        $locale    = get_user_locale();
    11101115        $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
     1116
    11111117        $output    = get_transient( $cache_key );
    11121118        if ( false !== $output ) {
    11131119                echo $output;
    function wp_print_community_events_templates() { 
    14191425 *
    14201426 * @since 2.7.0
    14211427 * @since 4.8.0 Removed popular plugins feed.
     1428 * @since todo 2nd news item conditionally displayed, if so then planet item removed
    14221429 */
    14231430function wp_dashboard_primary() {
    14241431        $feeds = array(
    function wp_dashboard_primary() { 
    14411448                         * @param string $url The widget's primary feed URL.
    14421449                         */
    14431450                        'url'          => apply_filters( 'dashboard_primary_feed', __( 'https://wordpress.org/news/feed/' ) ),
     1451                                // save to constant to make DRY?
    14441452
    14451453                        /**
    14461454                         * Filters the primary link title for the 'WordPress Events and News' dashboard widget.
    function wp_dashboard_primary() { 
    14501458                         * @param string $title Title attribute for the widget's primary link.
    14511459                         */
    14521460                        'title'        => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
    1453                         'items'        => 1,
     1461'items'        => 1, // leave at one to test condition
     1462//                      'items'        => 2,
    14541463                        'show_summary' => 0,
    14551464                        'show_author'  => 0,
    14561465                        'show_date'    => 0,
    function wp_dashboard_primary() { 
    15111520 * @param array  $feeds     Array of RSS feeds.
    15121521 */
    15131522function wp_dashboard_primary_output( $widget_id, $feeds ) {
     1523        add_action( 'wp_feed_post_init', '_wp_dashboard_add_extra_news_item', 10, 2 );
     1524                // needs to be all time because of ajax? doesn't need to run when cached, just when savings
     1525
    15141526        foreach ( $feeds as $type => $args ) {
    15151527                $args['type'] = $type;
    15161528                echo '<div class="rss-widget">';
     1529                        // or maybe don't call this function, and instead call fetch_feed() yourself?
    15171530                        wp_widget_rss_output( $args['url'], $args );
    15181531                echo '</div>';
    15191532        }
     1533
     1534        remove_action( 'wp_feed_post_init', '_wp_dashboard_add_extra_news_item', 10 );
     1535}
     1536
     1537
     1538function _wp_dashboard_add_extra_news_item( $feed, $url ) {
     1539        // if wrong url, return
     1540        if ( __( 'https://wordpress.org/news/feed/' ) !== $url ) {
     1541                return;
     1542        }
     1543
     1544        var_dump($feed);wp_die();
     1545        // just modify public data or raw_data?
     1546        // or use accessor functions?
     1547
     1548        // make sure passing by reference
     1549
     1550
     1551        // if 2nd item has been displayed for 7+ days already, then remove it
     1552
     1553        // but also need to need to edit the planet feed to make remove one of theirs, so would need some kind of global variable to track that
     1554        // this architecture is so not straightforward, maybe refactor it instead
     1555        // top level function should call model to get array of items, then modify it, then pass it to function to render it
    15201556}
    15211557
    15221558/**
  • src/wp-admin/includes/upgrade.php

    diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php
    index e0170f2705..5a74d7b894 100644
    function upgrade_550() { 
    22022202        }
    22032203}
    22042204
     2205// need to flush cache during upgrade, otherwise will get errors b/c code expects 2 but there's only 1?
     2206        // prob. just delete the transient
     2207$cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
     2208// need to do for all locales. so sql query to delete where LIKE ?
     2209// but object cache
     2210// maybe simpler to just have code check if there's a 2nd
     2211// or do all transients get cleared during upgrade anyway?
     2212
    22052213/**
    22062214 * Executes network-level upgrade routines.
    22072215 *
  • src/wp-includes/feed.php

    diff --git src/wp-includes/feed.php src/wp-includes/feed.php
    index 0b84cc10a5..646fa4cf28 100644
    function fetch_feed( $url ) { 
    821821        $feed->init();
    822822        $feed->set_output_encoding( get_option( 'blog_charset' ) );
    823823
     824        // add action here, so can modify the results?
     825
     826        do_action_ref_array( 'wp_feed_post_init', array( &$feed, $url ) );
     827
    824828        if ( $feed->error() ) {
    825829                return new WP_Error( 'simplepie-error', $feed->error() );
    826830        }
  • src/wp-includes/widgets.php

    diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php
    index 0d176687fb..5d3069080f 100644
    function wp_widget_rss_output( $rss, $args = array() ) { 
    15281528                return;
    15291529        }
    15301530
     1531        // could maybe assign get_items() to a var, and filter that. that might be cleanest.
     1532        // although, if gonna add a filter, might as well do it higher up so it's useful to more people
     1533
    15311534        echo '<ul>';
    15321535        foreach ( $rss->get_items( 0, $items ) as $item ) {
    15331536                $link = $item->get_link();