WordPress.org

Make WordPress Core

Ticket #11891: 11891.diff

File 11891.diff, 3.2 KB (added by nacin, 8 years ago)

Adds configuration option

  • wp-admin/includes/dashboard.php

     
    2828        wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' );
    2929
    3030        // Recent Comments Widget
     31        if ( !isset( $widget_options['dashboard_recent_comments'] ) || !isset( $widget_options['dashboard_recent_comments']['items'] ) ) {
     32                $update = true;
     33                $widget_options['dashboard_recent_comments'] = array(
     34                        'items' => 5,
     35                );
     36        }
    3137        $recent_comments_title = __( 'Recent Comments' );
    32         wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments' );
     38        wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments', 'wp_dashboard_recent_comments_control' );
    3339
    3440        // Incoming Links Widget
    3541        if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) {
     
    481487        $comments = array();
    482488        $start = 0;
    483489
     490        $widgets = get_option( 'dashboard_widget_options' );
     491        if ( isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] ) )
     492                $total_items = (int) $widgets['dashboard_recent_comments']['items'];
     493        else
     494                $total_items = 5;
     495
    484496        while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) {
    485497
    486498                foreach ( $possible as $comment ) {
    487                         if ( count( $comments ) >= 5 )
     499                        if ( count( $comments ) >= $total_items )
    488500                                break;
    489501                        if ( in_array( $comment->comment_approved, $allowed_states ) )
    490502                                $comments[] = $comment;
     
    611623<?php
    612624}
    613625
     626/**
     627 * The recent comments dashboard widget control.
     628 *
     629 * @since 3.0.0
     630 */
     631function wp_dashboard_recent_comments_control() {
     632        if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
     633                $widget_options = array();
     634
     635        if ( !isset($widget_options['dashboard_recent_comments']) )
     636                $widget_options['dashboard_recent_comments'] = array();
     637
     638        if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-recent-comments']) ) {
     639                $number = (int) stripslashes($_POST['widget-recent-comments']['items']);
     640                if ( $number < 1 || $number > 10 )
     641                        $number = 5;
     642                $widget_options['dashboard_recent_comments']['items'] = $number;
     643                update_option( 'dashboard_widget_options', $widget_options );
     644        }
     645
     646        $number = isset( $widget_options['dashboard_recent_comments']['items'] ) ? (int) $widget_options['dashboard_recent_comments']['items'] : '';
     647
     648        echo '<p><label for="comments-number">' . __('Number of comments to show:') . '</label>';
     649        echo '<input id="comments-number" name="widget-recent-comments[items]" type="text" value="' . $number . '" size="3" /> <small>(up to 10)</p>';
     650
     651}
     652
    614653function wp_dashboard_incoming_links() {
    615654        echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
    616655}