WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (3 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/dashboard.php

    r42228 r42343  
    2121    global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
    2222    $wp_dashboard_control_callbacks = array();
    23     $screen = get_current_screen();
     23    $screen                         = get_current_screen();
    2424
    2525    /* Register Widgets and Controls */
     
    2929    if ( $response && $response['upgrade'] ) {
    3030        add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
    31         if ( $response['insecure'] )
     31        if ( $response['insecure'] ) {
    3232            wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
    33         else
     33        } else {
    3434            wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' );
     35        }
    3536    }
    3637
    3738    // Right Now
    38     if ( is_blog_admin() && current_user_can('edit_posts') )
     39    if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
    3940        wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
    40 
    41     if ( is_network_admin() )
     41    }
     42
     43    if ( is_network_admin() ) {
    4244        wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
     45    }
    4346
    4447    // Activity Widget
     
    110113
    111114    foreach ( $dashboard_widgets as $widget_id ) {
    112         $name = empty( $wp_registered_widgets[$widget_id]['all_link'] ) ? $wp_registered_widgets[$widget_id]['name'] : $wp_registered_widgets[$widget_id]['name'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __('View all') . '</a>';
    113         wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
    114     }
    115 
    116     if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
     115        $name = empty( $wp_registered_widgets[ $widget_id ]['all_link'] ) ? $wp_registered_widgets[ $widget_id ]['name'] : $wp_registered_widgets[ $widget_id ]['name'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __( 'View all' ) . '</a>';
     116        wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[ $widget_id ]['callback'], $wp_registered_widget_controls[ $widget_id ]['callback'] );
     117    }
     118
     119    if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget_id'] ) ) {
    117120        check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
    118121        ob_start(); // hack - but the same hack wp-admin/widgets.php uses
     
    153156    if ( is_null( $callback_args ) ) {
    154157        $callback_args = $private_callback_args;
    155     } else if ( is_array( $callback_args ) ) {
     158    } elseif ( is_array( $callback_args ) ) {
    156159        $callback_args = array_merge( $callback_args, $private_callback_args );
    157160    }
    158161
    159162    if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
    160         $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
     163        $wp_dashboard_control_callbacks[ $widget_id ] = $control_callback;
    161164        if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
    162             list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
     165            list($url)    = explode( '#', add_query_arg( 'edit', false ), 2 );
    163166            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
    164             $callback = '_wp_dashboard_control_callback';
     167            $callback     = '_wp_dashboard_control_callback';
    165168        } else {
    166             list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
     169            list($url)    = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
    167170            $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
    168171        }
     
    172175
    173176    $location = 'normal';
    174     if ( in_array($widget_id, $side_widgets) )
     177    if ( in_array( $widget_id, $side_widgets ) ) {
    175178        $location = 'side';
     179    }
    176180
    177181    $priority = 'core';
    178     if ( 'dashboard_browser_nag' === $widget_id )
     182    if ( 'dashboard_browser_nag' === $widget_id ) {
    179183        $priority = 'high';
     184    }
    180185
    181186    add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
     
    195200    wp_dashboard_trigger_widget_control( $meta_box['id'] );
    196201    wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
    197     echo '<input type="hidden" name="widget_id" value="' . esc_attr($meta_box['id']) . '" />';
    198     submit_button( __('Submit') );
     202    echo '<input type="hidden" name="widget_id" value="' . esc_attr( $meta_box['id'] ) . '" />';
     203    submit_button( __( 'Submit' ) );
    199204    echo '</form>';
    200205}
     
    206211 */
    207212function wp_dashboard() {
    208     $screen = get_current_screen();
    209     $columns = absint( $screen->get_columns() );
     213    $screen      = get_current_screen();
     214    $columns     = absint( $screen->get_columns() );
    210215    $columns_css = '';
    211216    if ( $columns ) {
     
    260265                $text = _n( '%s Page', '%s Pages', $num_posts->publish );
    261266            }
    262             $text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
     267            $text             = sprintf( $text, number_format_i18n( $num_posts->publish ) );
    263268            $post_type_object = get_post_type_object( $post_type );
    264269            if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
     
    267272                printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
    268273            }
    269 
    270274        }
    271275    }
     
    283287        $aria_label = sprintf( _nx( '%s comment in moderation', '%s comments in moderation', $num_comm->moderated, 'comments' ), $moderated_comments_count_i18n );
    284288        ?>
    285         <li class="comment-mod-count<?php
    286             if ( ! $num_comm->moderated ) {
    287                 echo ' hidden';
    288             }
    289         ?>"><a href="edit-comments.php?comment_status=moderated" aria-label="<?php esc_attr_e( $aria_label ); ?>"><?php echo $text; ?></a></li>
     289        <li class="comment-mod-count
     290        <?php
     291        if ( ! $num_comm->moderated ) {
     292            echo ' hidden';
     293        }
     294        ?>
     295        "><a href="edit-comments.php?comment_status=moderated" aria-label="<?php esc_attr_e( $aria_label ); ?>"><?php echo $text; ?></a></li>
    290296        <?php
    291297    }
     
    339345         * @param string $content Default text.
    340346         */
    341         $content = apply_filters( 'privacy_on_link_text' , __( 'Search Engines Discouraged' ) );
     347        $content    = apply_filters( 'privacy_on_link_text', __( 'Search Engines Discouraged' ) );
    342348        $title_attr = '' === $title ? '' : " title='$title'";
    343349
     
    373379    $actions = ob_get_clean();
    374380
    375     if ( !empty( $actions ) ) : ?>
     381    if ( ! empty( $actions ) ) :
     382    ?>
    376383    <div class="sub">
    377384        <?php echo $actions; ?>
    378385    </div>
    379     <?php endif;
     386    <?php
     387    endif;
    380388}
    381389
     
    385393function wp_network_dashboard_right_now() {
    386394    $actions = array();
    387     if ( current_user_can('create_sites') )
    388         $actions['create-site'] = '<a href="' . network_admin_url('site-new.php') . '">' . __( 'Create a New Site' ) . '</a>';
    389     if ( current_user_can('create_users') )
    390         $actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>';
     395    if ( current_user_can( 'create_sites' ) ) {
     396        $actions['create-site'] = '<a href="' . network_admin_url( 'site-new.php' ) . '">' . __( 'Create a New Site' ) . '</a>';
     397    }
     398    if ( current_user_can( 'create_users' ) ) {
     399        $actions['create-user'] = '<a href="' . network_admin_url( 'user-new.php' ) . '">' . __( 'Create a New User' ) . '</a>';
     400    }
    391401
    392402    $c_users = get_user_count();
     
    427437    ?>
    428438
    429     <form action="<?php echo network_admin_url('users.php'); ?>" method="get">
     439    <form action="<?php echo network_admin_url( 'users.php' ); ?>" method="get">
    430440        <p>
    431441            <label class="screen-reader-text" for="search-users"><?php _e( 'Search Users' ); ?></label>
     
    435445    </form>
    436446
    437     <form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
     447    <form action="<?php echo network_admin_url( 'sites.php' ); ?>" method="get">
    438448        <p>
    439449            <label class="screen-reader-text" for="search-sites"><?php _e( 'Search Sites' ); ?></label>
     
    485495        }
    486496    } else {
    487         $post = get_default_post_to_edit( 'post' , true);
     497        $post    = get_default_post_to_edit( 'post', true );
    488498        $user_id = get_current_user_id();
    489499        // Don't create an option if this is a super admin who does not belong to this site.
    490         if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) )
     500        if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) {
    491501            update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
     502        }
    492503    }
    493504
     
    546557            'posts_per_page' => 4,
    547558            'orderby'        => 'modified',
    548             'order'          => 'DESC'
     559            'order'          => 'DESC',
    549560        );
    550561
     
    561572        if ( ! $drafts ) {
    562573            return;
    563         }
    564     }
     574        }
     575    }
    565576
    566577    echo '<div class="drafts">';
    567578    if ( count( $drafts ) > 3 ) {
    568579        echo '<p class="view-all"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '">' . __( 'View all drafts' ) . "</a></p>\n";
    569     }
     580    }
    570581    echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>";
    571582
    572583    $drafts = array_slice( $drafts, 0, 3 );
    573584    foreach ( $drafts as $draft ) {
    574         $url = get_edit_post_link( $draft->ID );
     585        $url   = get_edit_post_link( $draft->ID );
    575586        $title = _draft_or_post_title( $draft->ID );
    576587        echo "<li>\n";
     
    580591        if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) {
    581592            echo '<p>' . $the_content . '</p>';
    582         }
     593        }
    583594        echo "</li>\n";
    584     }
     595    }
    585596    echo "</ul>\n</div>";
    586597}
     
    603614
    604615        $comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
    605         $comment_post_url = get_the_permalink( $comment->comment_post_ID );
    606         $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
     616        $comment_post_url   = get_the_permalink( $comment->comment_post_ID );
     617        $comment_post_link  = "<a href='$comment_post_url'>$comment_post_title</a>";
    607618    } else {
    608619        $comment_post_link = '';
     
    613624        // Pre-order it: Approve | Reply | Edit | Spam | Trash.
    614625        $actions = array(
    615             'approve' => '', 'unapprove' => '',
    616             'reply' => '',
    617             'edit' => '',
    618             'spam' => '',
    619             'trash' => '', 'delete' => '',
    620             'view' => '',
     626            'approve'   => '',
     627            'unapprove' => '',
     628            'reply'     => '',
     629            'edit'      => '',
     630            'spam'      => '',
     631            'trash'     => '',
     632            'delete'    => '',
     633            'view'      => '',
    621634        );
    622635
    623         $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
     636        $del_nonce     = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
    624637        $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
    625638
    626         $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
     639        $approve_url   = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
    627640        $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
    628         $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
    629         $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
    630         $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
    631 
    632         $actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
     641        $spam_url      = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
     642        $trash_url     = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
     643        $delete_url    = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
     644
     645        $actions['approve']   = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
    633646        $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
    634         $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>". __( 'Edit' ) . '</a>';
    635         $actions['reply'] = '<a onclick="window.commentReply && commentReply.open(\'' . $comment->comment_ID . '\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" aria-label="' . esc_attr__( 'Reply to this comment' ) . '" href="#">' . __( 'Reply' ) . '</a>';
    636         $actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' aria-label='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
     647        $actions['edit']      = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>" . __( 'Edit' ) . '</a>';
     648        $actions['reply']     = '<a onclick="window.commentReply && commentReply.open(\'' . $comment->comment_ID . '\',\'' . $comment->comment_post_ID . '\');return false;" class="vim-r hide-if-no-js" aria-label="' . esc_attr__( 'Reply to this comment' ) . '" href="#">' . __( 'Reply' ) . '</a>';
     649        $actions['spam']      = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' aria-label='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
    637650
    638651        if ( ! EMPTY_TRASH_DAYS ) {
     
    655668         * @param WP_Comment $comment The comment object.
    656669         */
    657         $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
     670        $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
    658671
    659672        $i = 0;
    660673        foreach ( $actions as $action => $link ) {
    661674            ++$i;
    662             ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
     675            ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
    663676
    664677            // Reply and quickedit need a hide-if-no-js span
     
    679692            <?php echo get_avatar( $comment, 50, 'mystery' ); ?>
    680693
    681             <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
     694            <?php if ( ! $comment->comment_type || 'comment' == $comment->comment_type ) : ?>
    682695
    683696            <div class="dashboard-comment-wrap has-row-actions">
     
    685698            <?php
    686699                // Comments might not have a post they relate to, e.g. programmatically created ones.
    687                 if ( $comment_post_link ) {
    688                     printf(
    689                         /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */
    690                         __( 'From %1$s on %2$s %3$s' ),
    691                         '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
    692                         $comment_post_link,
    693                         '<span class="approve">' . __( '[Pending]' ) . '</span>'
    694                     );
    695                 } else {
    696                     printf(
    697                         /* translators: 1: comment author, 2: notification if the comment is pending */
    698                         __( 'From %1$s %2$s' ),
    699                         '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
    700                         '<span class="approve">' . __( '[Pending]' ) . '</span>'
    701                     );
    702                 }
     700            if ( $comment_post_link ) {
     701                printf(
     702                    /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */
     703                    __( 'From %1$s on %2$s %3$s' ),
     704                    '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
     705                    $comment_post_link,
     706                    '<span class="approve">' . __( '[Pending]' ) . '</span>'
     707                );
     708            } else {
     709                printf(
     710                    /* translators: 1: comment author, 2: notification if the comment is pending */
     711                    __( 'From %1$s %2$s' ),
     712                    '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
     713                    '<span class="approve">' . __( '[Pending]' ) . '</span>'
     714                );
     715            }
    703716            ?>
    704717            </p>
     
    707720            else :
    708721                switch ( $comment->comment_type ) {
    709                     case 'pingback' :
     722                    case 'pingback':
    710723                        $type = __( 'Pingback' );
    711724                        break;
    712                     case 'trackback' :
     725                    case 'trackback':
    713726                        $type = __( 'Trackback' );
    714727                        break;
    715                     default :
     728                    default:
    716729                        $type = ucwords( $comment->comment_type );
    717730                }
     
    722735            <?php
    723736                // Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones.
    724                 if ( $comment_post_link ) {
    725                     printf(
    726                         /* translators: 1: type of comment, 2: post link, 3: notification if the comment is pending */
    727                         _x( '%1$s on %2$s %3$s', 'dashboard' ),
    728                         "<strong>$type</strong>",
    729                         $comment_post_link,
    730                         '<span class="approve">' . __( '[Pending]' ) . '</span>'
    731                     );
    732                 } else {
    733                     printf(
    734                         /* translators: 1: type of comment, 2: notification if the comment is pending */
    735                         _x( '%1$s %2$s', 'dashboard' ),
    736                         "<strong>$type</strong>",
    737                         '<span class="approve">' . __( '[Pending]' ) . '</span>'
    738                     );
    739                 }
     737            if ( $comment_post_link ) {
     738                printf(
     739                    /* translators: 1: type of comment, 2: post link, 3: notification if the comment is pending */
     740                    _x( '%1$s on %2$s %3$s', 'dashboard' ),
     741                    "<strong>$type</strong>",
     742                    $comment_post_link,
     743                    '<span class="approve">' . __( '[Pending]' ) . '</span>'
     744                );
     745            } else {
     746                printf(
     747                    /* translators: 1: type of comment, 2: notification if the comment is pending */
     748                    _x( '%1$s %2$s', 'dashboard' ),
     749                    "<strong>$type</strong>",
     750                    '<span class="approve">' . __( '[Pending]' ) . '</span>'
     751                );
     752            }
    740753            ?>
    741754            </p>
     
    762775    echo '<div id="activity-widget">';
    763776
    764     $future_posts = wp_dashboard_recent_posts( array(
    765         'max'     => 5,
    766         'status'  => 'future',
    767         'order'   => 'ASC',
    768         'title'   => __( 'Publishing Soon' ),
    769         'id'      => 'future-posts',
    770     ) );
    771     $recent_posts = wp_dashboard_recent_posts( array(
    772         'max'     => 5,
    773         'status'  => 'publish',
    774         'order'   => 'DESC',
    775         'title'   => __( 'Recently Published' ),
    776         'id'      => 'published-posts',
    777     ) );
     777    $future_posts = wp_dashboard_recent_posts(
     778        array(
     779            'max'    => 5,
     780            'status' => 'future',
     781            'order'  => 'ASC',
     782            'title'  => __( 'Publishing Soon' ),
     783            'id'     => 'future-posts',
     784        )
     785    );
     786    $recent_posts = wp_dashboard_recent_posts(
     787        array(
     788            'max'    => 5,
     789            'status' => 'publish',
     790            'order'  => 'DESC',
     791            'title'  => __( 'Recently Published' ),
     792            'id'     => 'published-posts',
     793        )
     794    );
    778795
    779796    $recent_comments = wp_dashboard_recent_comments();
    780797
    781     if ( !$future_posts && !$recent_posts && !$recent_comments ) {
     798    if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) {
    782799        echo '<div class="no-activity">';
    783800        echo '<p class="smiley" aria-hidden="true"></p>';
     
    825842     */
    826843    $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args );
    827     $posts = new WP_Query( $query_args );
     844    $posts      = new WP_Query( $query_args );
    828845
    829846    if ( $posts->have_posts() ) {
     
    895912    $comments_query = array(
    896913        'number' => $total_items * 5,
    897         'offset' => 0
     914        'offset' => 0,
    898915    );
    899     if ( ! current_user_can( 'edit_posts' ) )
     916    if ( ! current_user_can( 'edit_posts' ) ) {
    900917        $comments_query['status'] = 'approve';
     918    }
    901919
    902920    while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
     
    905923        }
    906924        foreach ( $possible as $comment ) {
    907             if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
     925            if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) {
    908926                continue;
     927            }
    909928            $comments[] = $comment;
    910             if ( count( $comments ) == $total_items )
     929            if ( count( $comments ) == $total_items ) {
    911930                break 2;
     931            }
    912932        }
    913933        $comments_query['offset'] += $comments_query['number'];
    914         $comments_query['number'] = $total_items * 10;
     934        $comments_query['number']  = $total_items * 10;
    915935    }
    916936
     
    920940
    921941        echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
    922         foreach ( $comments as $comment )
     942        foreach ( $comments as $comment ) {
    923943            _wp_dashboard_recent_comments_row( $comment );
     944        }
    924945        echo '</ul>';
    925946
     
    950971    echo '<div class="rss-widget">';
    951972    wp_widget_rss_output( $widgets[ $widget_id ] );
    952     echo "</div>";
     973    echo '</div>';
    953974}
    954975
     
    969990 */
    970991function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
    971     $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><div class="hide-if-js notice notice-error inline"><p>' . __( 'This widget requires JavaScript.' ) . '</p></div>';
     992    $loading    = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><div class="hide-if-js notice notice-error inline"><p>' . __( 'This widget requires JavaScript.' ) . '</p></div>';
    972993    $doing_ajax = wp_doing_ajax();
    973994
    974     if ( empty($check_urls) ) {
     995    if ( empty( $check_urls ) ) {
    975996        $widgets = get_option( 'dashboard_widget_options' );
    976         if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
     997        if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) {
    977998            echo $loading;
    978999            return false;
    9791000        }
    980         $check_urls = array( $widgets[$widget_id]['url'] );
    981     }
    982 
    983     $locale = get_user_locale();
     1001        $check_urls = array( $widgets[ $widget_id ]['url'] );
     1002    }
     1003
     1004    $locale    = get_user_locale();
    9841005    $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
    9851006    if ( false !== ( $output = get_transient( $cache_key ) ) ) {
     
    10201041    global $wp_dashboard_control_callbacks;
    10211042
    1022     if ( is_scalar($widget_control_id) && $widget_control_id && isset($wp_dashboard_control_callbacks[$widget_control_id]) && is_callable($wp_dashboard_control_callbacks[$widget_control_id]) ) {
    1023         call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
     1043    if ( is_scalar( $widget_control_id ) && $widget_control_id && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] ) && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] ) ) {
     1044        call_user_func(
     1045            $wp_dashboard_control_callbacks[ $widget_control_id ], '', array(
     1046                'id'       => $widget_control_id,
     1047                'callback' => $wp_dashboard_control_callbacks[ $widget_control_id ],
     1048            )
     1049        );
    10241050    }
    10251051}
     
    10371063 */
    10381064function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
    1039     if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
     1065    if ( ! $widget_options = get_option( 'dashboard_widget_options' ) ) {
    10401066        $widget_options = array();
    1041 
    1042     if ( !isset($widget_options[$widget_id]) )
    1043         $widget_options[$widget_id] = array();
    1044 
    1045     $number = 1; // Hack to use wp_widget_rss_form()
    1046     $widget_options[$widget_id]['number'] = $number;
    1047 
    1048     if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
    1049         $_POST['widget-rss'][$number] = wp_unslash( $_POST['widget-rss'][$number] );
    1050         $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
    1051         $widget_options[$widget_id]['number'] = $number;
     1067    }
     1068
     1069    if ( ! isset( $widget_options[ $widget_id ] ) ) {
     1070        $widget_options[ $widget_id ] = array();
     1071    }
     1072
     1073    $number                                 = 1; // Hack to use wp_widget_rss_form()
     1074    $widget_options[ $widget_id ]['number'] = $number;
     1075
     1076    if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
     1077        $_POST['widget-rss'][ $number ]         = wp_unslash( $_POST['widget-rss'][ $number ] );
     1078        $widget_options[ $widget_id ]           = wp_widget_rss_process( $_POST['widget-rss'][ $number ] );
     1079        $widget_options[ $widget_id ]['number'] = $number;
    10521080
    10531081        // Title is optional. If black, fill it if possible.
    1054         if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
    1055             $rss = fetch_feed($widget_options[$widget_id]['url']);
    1056             if ( is_wp_error($rss) ) {
    1057                 $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
     1082        if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) {
     1083            $rss = fetch_feed( $widget_options[ $widget_id ]['url'] );
     1084            if ( is_wp_error( $rss ) ) {
     1085                $widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) );
    10581086            } else {
    1059                 $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
     1087                $widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) );
    10601088                $rss->__destruct();
    1061                 unset($rss);
     1089                unset( $rss );
    10621090            }
    10631091        }
    10641092        update_option( 'dashboard_widget_options', $widget_options );
    1065         $locale = get_user_locale();
     1093        $locale    = get_user_locale();
    10661094        $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
    10671095        delete_transient( $cache_key );
    10681096    }
    10691097
    1070     wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
     1098    wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs );
    10711099}
    10721100
     
    12071235
    12081236    <script id="tmpl-community-events-attend-event-near" type="text/template">
    1209         <?php printf(
     1237        <?php
     1238        printf(
    12101239            /* translators: %s: the name of a city */
    12111240            __( 'Attend an upcoming event near %s.' ),
    12121241            '<strong>{{ data.location.description }}</strong>'
    1213         ); ?>
     1242        );
     1243        ?>
    12141244    </script>
    12151245
    12161246    <script id="tmpl-community-events-could-not-locate" type="text/template">
    1217         <?php printf(
     1247        <?php
     1248        printf(
    12181249            /* translators: %s is the name of the city we couldn't locate.
    12191250             * Replace the examples with cities in your locale, but test
     
    12231254            __( 'We couldn&#8217;t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
    12241255            '<em>{{data.unknownCity}}</em>'
    1225         ); ?>
     1256        );
     1257        ?>
    12261258    </script>
    12271259
     
    12501282        <li class="event-none">
    12511283            <# if ( data.location.description ) { #>
    1252                 <?php printf(
     1284                <?php
     1285                printf(
    12531286                    /* translators: 1: the city the user searched for, 2: meetup organization documentation URL */
    12541287                    __( 'There aren&#8217;t any events scheduled near %1$s at the moment. Would you like to <a href="%2$s">organize one</a>?' ),
    12551288                    '{{ data.location.description }}',
    12561289                    __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
    1257                 ); ?>
     1290                );
     1291                ?>
    12581292
    12591293            <# } else { #>
    1260                 <?php printf(
     1294                <?php
     1295                printf(
    12611296                    /* translators: %s: meetup organization documentation URL */
    12621297                    __( 'There aren&#8217;t any events scheduled near you at the moment. Would you like to <a href="%s">organize one</a>?' ),
    12631298                    __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
    1264                 ); ?>
     1299                );
     1300                ?>
    12651301            <# } #>
    12661302        </li>
     
    12771313function wp_dashboard_primary() {
    12781314    $feeds = array(
    1279         'news' => array(
     1315        'news'   => array(
    12801316
    12811317            /**
     
    12861322             * @param string $link The widget's primary link URL.
    12871323             */
    1288             'link' => apply_filters( 'dashboard_primary_link', __( 'https://wordpress.org/news/' ) ),
     1324            'link'         => apply_filters( 'dashboard_primary_link', __( 'https://wordpress.org/news/' ) ),
    12891325
    12901326            /**
     
    12951331             * @param string $url The widget's primary feed URL.
    12961332             */
    1297             'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
     1333            'url'          => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
    12981334
    12991335            /**
     
    13191355             * @param string $link The widget's secondary link URL.
    13201356             */
    1321             'link' => apply_filters( 'dashboard_secondary_link', __( 'https://planet.wordpress.org/' ) ),
     1357            'link'         => apply_filters( 'dashboard_secondary_link', __( 'https://planet.wordpress.org/' ) ),
    13221358
    13231359            /**
     
    13281364             * @param string $url The widget's secondary feed URL.
    13291365             */
    1330             'url' => apply_filters( 'dashboard_secondary_feed', __( 'https://planet.wordpress.org/feed/' ) ),
     1366            'url'          => apply_filters( 'dashboard_secondary_feed', __( 'https://planet.wordpress.org/feed/' ) ),
    13311367
    13321368            /**
     
    13501386            'show_author'  => 0,
    13511387            'show_date'    => 0,
    1352         )
     1388        ),
    13531389    );
    13541390
     
    13701406        echo '<div class="rss-widget">';
    13711407            wp_widget_rss_output( $args['url'], $args );
    1372         echo "</div>";
     1408        echo '</div>';
    13731409    }
    13741410}
     
    13841420 */
    13851421function wp_dashboard_quota() {
    1386     if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) )
     1422    if ( ! is_multisite() || ! current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) ) {
    13871423        return true;
     1424    }
    13881425
    13891426    $quota = get_space_allowed();
    1390     $used = get_space_used();
    1391 
    1392     if ( $used > $quota )
     1427    $used  = get_space_used();
     1428
     1429    if ( $used > $quota ) {
    13931430        $percentused = '100';
    1394     else
     1431    } else {
    13951432        $percentused = ( $used / $quota ) * 100;
    1396     $used_class = ( $percentused >= 70 ) ? ' warning' : '';
    1397     $used = round( $used, 2 );
     1433    }
     1434    $used_class  = ( $percentused >= 70 ) ? ' warning' : '';
     1435    $used        = round( $used, 2 );
    13981436    $percentused = number_format( $percentused );
    13991437
     
    14031441    <ul>
    14041442        <li class="storage-count">
    1405             <?php $text = sprintf(
     1443            <?php
     1444            $text = sprintf(
    14061445                /* translators: %s: number of megabytes */
    14071446                __( '%s MB Space Allowed' ),
     
    14131452                $text,
    14141453                __( 'Manage Uploads' )
    1415             ); ?>
     1454            );
     1455            ?>
    14161456        </li><li class="storage-count <?php echo $used_class; ?>">
    1417             <?php $text = sprintf(
     1457            <?php
     1458            $text = sprintf(
    14181459                /* translators: 1: number of megabytes, 2: percentage */
    14191460                __( '%1$s MB (%2$s%%) Space Used' ),
     
    14261467                $text,
    14271468                __( 'Manage Uploads' )
    1428             ); ?>
     1469            );
     1470            ?>
    14291471        </li>
    14301472    </ul>
     
    14351477// Display Browser Nag Meta Box
    14361478function wp_dashboard_browser_nag() {
    1437     $notice = '';
     1479    $notice   = '';
    14381480    $response = wp_check_browser_version();
    14391481
     
    14411483        if ( $response['insecure'] ) {
    14421484            /* translators: %s: browser name and link */
    1443             $msg = sprintf( __( "It looks like you're using an insecure version of %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ),
     1485            $msg = sprintf(
     1486                __( "It looks like you're using an insecure version of %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ),
    14441487                sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
    14451488            );
    14461489        } else {
    14471490            /* translators: %s: browser name and link */
    1448             $msg = sprintf( __( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ),
     1491            $msg = sprintf(
     1492                __( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ),
    14491493                sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
    14501494            );
     
    14521496
    14531497        $browser_nag_class = '';
    1454         if ( !empty( $response['img_src'] ) ) {
    1455             $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
    1456 
    1457             $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
     1498        if ( ! empty( $response['img_src'] ) ) {
     1499            $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) ) ? $response['img_src_ssl'] : $response['img_src'];
     1500
     1501            $notice           .= '<div class="alignright browser-icon"><a href="' . esc_attr( $response['update_url'] ) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
    14581502            $browser_nag_class = ' has-browser-icon';
    14591503        }
     
    14611505
    14621506        $browsehappy = 'https://browsehappy.com/';
    1463         $locale = get_user_locale();
    1464         if ( 'en_US' !== $locale )
     1507        $locale      = get_user_locale();
     1508        if ( 'en_US' !== $locale ) {
    14651509            $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
     1510        }
    14661511
    14671512        $notice .= '<p>' . sprintf( __( '<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>' ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ), esc_url( $browsehappy ) ) . '</p>';
     
    14711516
    14721517    /**
    1473     * Filters the notice output for the 'Browse Happy' nag meta box.
    1474     *
    1475     * @since 3.2.0
    1476     *
    1477     * @param string $notice   The notice content.
    1478     * @param array  $response An array containing web browser information.
    1479     */
     1518     * Filters the notice output for the 'Browse Happy' nag meta box.
     1519     *
     1520     * @since 3.2.0
     1521     *
     1522     * @param string $notice   The notice content.
     1523     * @param array  $response An array containing web browser information.
     1524     */
    14801525    echo apply_filters( 'browse-happy-notice', $notice, $response );
    14811526}
     
    14901535    $response = wp_check_browser_version();
    14911536
    1492     if ( $response && $response['insecure'] )
     1537    if ( $response && $response['insecure'] ) {
    14931538        $classes[] = 'browser-insecure';
     1539    }
    14941540
    14951541    return $classes;
     
    15041550 */
    15051551function wp_check_browser_version() {
    1506     if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
     1552    if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
    15071553        return false;
     1554    }
    15081555
    15091556    $key = md5( $_SERVER['HTTP_USER_AGENT'] );
    15101557
    1511     if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
     1558    if ( false === ( $response = get_site_transient( 'browser_' . $key ) ) ) {
    15121559        // include an unmodified $wp_version
    15131560        include( ABSPATH . WPINC . '/version.php' );
    15141561
    1515         $url = 'http://api.wordpress.org/core/browse-happy/1.1/';
     1562        $url     = 'http://api.wordpress.org/core/browse-happy/1.1/';
    15161563        $options = array(
    15171564            'body'       => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
    1518             'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' )
     1565            'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
    15191566        );
    15201567
     
    15251572        $response = wp_remote_post( $url, $options );
    15261573
    1527         if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
     1574        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
    15281575            return false;
     1576        }
    15291577
    15301578        /**
     
    15421590        $response = json_decode( wp_remote_retrieve_body( $response ), true );
    15431591
    1544         if ( ! is_array( $response ) )
     1592        if ( ! is_array( $response ) ) {
    15451593            return false;
     1594        }
    15461595
    15471596        set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
     
    15991648        <ul>
    16001649        <?php if ( current_theme_supports( 'widgets' ) || current_theme_supports( 'menus' ) ) : ?>
    1601             <li><div class="welcome-icon welcome-widgets-menus"><?php
    1602                 if ( current_theme_supports( 'widgets' ) && current_theme_supports( 'menus' ) ) {
    1603                     printf( __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ),
    1604                         admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' ) );
    1605                 } elseif ( current_theme_supports( 'widgets' ) ) {
    1606                     echo '<a href="' . admin_url( 'widgets.php' ) . '">' . __( 'Manage widgets' ) . '</a>';
    1607                 } else {
    1608                     echo '<a href="' . admin_url( 'nav-menus.php' ) . '">' . __( 'Manage menus' ) . '</a>';
    1609                 }
    1610             ?></div></li>
     1650            <li><div class="welcome-icon welcome-widgets-menus">
     1651            <?php
     1652            if ( current_theme_supports( 'widgets' ) && current_theme_supports( 'menus' ) ) {
     1653                printf(
     1654                    __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ),
     1655                    admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' )
     1656                );
     1657            } elseif ( current_theme_supports( 'widgets' ) ) {
     1658                echo '<a href="' . admin_url( 'widgets.php' ) . '">' . __( 'Manage widgets' ) . '</a>';
     1659            } else {
     1660                echo '<a href="' . admin_url( 'nav-menus.php' ) . '">' . __( 'Manage menus' ) . '</a>';
     1661            }
     1662            ?>
     1663            </div></li>
    16111664        <?php endif; ?>
    16121665        <?php if ( current_user_can( 'manage_options' ) ) : ?>
Note: See TracChangeset for help on using the changeset viewer.