Make WordPress Core

Changeset 50689


Ignore:
Timestamp:
04/07/2021 06:32:01 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in wp-admin/includes/dashboard.php.

Includes minor code layout fixes for better readability.

See #52627.

File:
1 edited

Legend:

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

    r50556 r50689  
    2020function wp_dashboard_setup() {
    2121        global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
     22
    2223        $wp_dashboard_control_callbacks = array();
    2324        $screen                         = get_current_screen();
     
    2930        if ( $response && $response['upgrade'] ) {
    3031                add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
     32
    3133                if ( $response['insecure'] ) {
    3234                        wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
     
    3840        // PHP Version.
    3941        $response = wp_check_php_version();
    40         if ( $response && isset( $response['is_acceptable'] ) && ! $response['is_acceptable'] && current_user_can( 'update_php' ) ) {
     42
     43        if ( $response && isset( $response['is_acceptable'] ) && ! $response['is_acceptable']
     44                && current_user_can( 'update_php' )
     45        ) {
    4146                add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' );
     47
    4248                wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Recommended' ), 'wp_dashboard_php_nag' );
    4349        }
     
    175181 */
    176182function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null, $context = 'normal', $priority = 'core' ) {
     183        global $wp_dashboard_control_callbacks;
     184
    177185        $screen = get_current_screen();
    178         global $wp_dashboard_control_callbacks;
    179186
    180187        $private_callback_args = array( '__widget_basename' => $widget_name );
     
    186193        }
    187194
    188         if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
     195        if ( $control_callback && is_callable( $control_callback ) && current_user_can( 'edit_dashboard' ) ) {
    189196                $wp_dashboard_control_callbacks[ $widget_id ] = $control_callback;
    190                 if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
     197
     198                if ( isset( $_GET['edit'] ) && $widget_id === $_GET['edit'] ) {
    191199                        list($url)    = explode( '#', add_query_arg( 'edit', false ), 2 );
    192200                        $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
     
    213221                $context = 'normal';
    214222        }
     223
    215224        if ( empty( $priority ) ) {
    216225                $priority = 'core';
     
    247256        $columns     = absint( $screen->get_columns() );
    248257        $columns_css = '';
     258
    249259        if ( $columns ) {
    250260                $columns_css = " columns-$columns";
    251261        }
    252 
    253262        ?>
    254263<div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>">
     
    292301        foreach ( array( 'post', 'page' ) as $post_type ) {
    293302                $num_posts = wp_count_posts( $post_type );
     303
    294304                if ( $num_posts && $num_posts->publish ) {
    295305                        if ( 'post' === $post_type ) {
     
    300310                                $text = _n( '%s Page', '%s Pages', $num_posts->publish );
    301311                        }
     312
    302313                        $text             = sprintf( $text, number_format_i18n( $num_posts->publish ) );
    303314                        $post_type_object = get_post_type_object( $post_type );
     315
    304316                        if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
    305317                                printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
     
    309321                }
    310322        }
     323
    311324        // Comments.
    312325        $num_comm = wp_count_comments();
     326
    313327        if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) {
    314328                /* translators: %s: Number of comments. */
    315329                $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) );
    316330                ?>
    317                 <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
     331                <li class="comment-count">
     332                        <a href="edit-comments.php"><?php echo $text; ?></a>
     333                </li>
    318334                <?php
    319335                $moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated );
     
    321337                $text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n );
    322338                ?>
    323                 <li class="comment-mod-count
    324                 <?php
    325                 if ( ! $num_comm->moderated ) {
    326                         echo ' hidden';
    327                 }
    328                 ?>
    329                 "><a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a></li>
     339                <li class="comment-mod-count<?php echo ! $num_comm->moderated ? ' hidden' : ''; ?>">
     340                        <a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a>
     341                </li>
    330342                <?php
    331343        }
     
    354366
    355367        // Check if search engines are asked not to index this site.
    356         if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '0' == get_option( 'blog_public' ) ) {
     368        if ( ! is_network_admin() && ! is_user_admin()
     369                && current_user_can( 'manage_options' ) && ! get_option( 'blog_public' )
     370        ) {
    357371
    358372                /**
     
    379393                 * @param string $content Default text.
    380394                 */
    381                 $content    = apply_filters( 'privacy_on_link_text', __( 'Search engines discouraged' ) );
     395                $content = apply_filters( 'privacy_on_link_text', __( 'Search engines discouraged' ) );
     396
    382397                $title_attr = '' === $title ? '' : " title='$title'";
    383398
     
    427442function wp_network_dashboard_right_now() {
    428443        $actions = array();
     444
    429445        if ( current_user_can( 'create_sites' ) ) {
    430446                $actions['create-site'] = '<a href="' . network_admin_url( 'site-new.php' ) . '">' . __( 'Create a New Site' ) . '</a>';
     
    516532        }
    517533
    518         /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
     534        // Check if a new auto-draft (= no new post_ID) is needed or if the old can be used.
    519535        $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID.
     536
    520537        if ( $last_post_id ) {
    521538                $post = get_post( $last_post_id );
     539
    522540                if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore.
    523541                        $post = get_default_post_to_edit( 'post', true );
     
    529547                $post    = get_default_post_to_edit( 'post', true );
    530548                $user_id = get_current_user_id();
     549
    531550                // Don't create an option if this is a super admin who does not belong to this site.
    532551                if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) {
     
    607626
    608627        echo '<div class="drafts">';
     628
    609629        if ( count( $drafts ) > 3 ) {
    610630                printf(
     
    614634                );
    615635        }
    616         echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>";
     636
     637        echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n";
     638        echo '<ul>';
    617639
    618640        /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
     
    623645                $url   = get_edit_post_link( $draft->ID );
    624646                $title = _draft_or_post_title( $draft->ID );
     647
    625648                echo "<li>\n";
    626649                printf(
     
    633656                        get_the_time( __( 'F j, Y' ), $draft )
    634657                );
     658
    635659                $the_content = wp_trim_words( $draft->post_content, $draft_length );
     660
    636661                if ( $the_content ) {
    637662                        echo '<p>' . $the_content . '</p>';
     
    639664                echo "</li>\n";
    640665        }
    641         echo "</ul>\n</div>";
     666
     667        echo "</ul>\n";
     668        echo '</div>';
    642669}
    643670
     
    657684
    658685        if ( $comment->comment_post_ID > 0 ) {
    659 
    660686                $comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
    661687                $comment_post_url   = get_the_permalink( $comment->comment_post_ID );
     
    953979         */
    954980        $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args );
    955         $posts      = new WP_Query( $query_args );
     981
     982        $posts = new WP_Query( $query_args );
    956983
    957984        if ( $posts->have_posts() ) {
     
    971998
    972999                        $time = get_the_time( 'U' );
    973                         if ( gmdate( 'Y-m-d', $time ) == $today ) {
     1000
     1001                        if ( gmdate( 'Y-m-d', $time ) === $today ) {
    9741002                                $relative = __( 'Today' );
    975                         } elseif ( gmdate( 'Y-m-d', $time ) == $tomorrow ) {
     1003                        } elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) {
    9761004                                $relative = __( 'Tomorrow' );
    9771005                        } elseif ( gmdate( 'Y', $time ) !== $year ) {
     
    10261054                'offset' => 0,
    10271055        );
     1056
    10281057        if ( ! current_user_can( 'edit_posts' ) ) {
    10291058                $comments_query['status'] = 'approve';
     
    10341063                        break;
    10351064                }
     1065
    10361066                foreach ( $possible as $comment ) {
    10371067                        if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) {
    10381068                                continue;
    10391069                        }
     1070
    10401071                        $comments[] = $comment;
    1041                         if ( count( $comments ) == $total_items ) {
     1072
     1073                        if ( count( $comments ) === $total_items ) {
    10421074                                break 2;
    10431075                        }
    10441076                }
     1077
    10451078                $comments_query['offset'] += $comments_query['number'];
    10461079                $comments_query['number']  = $total_items * 10;
     
    11101143        if ( empty( $check_urls ) ) {
    11111144                $widgets = get_option( 'dashboard_widget_options' );
     1145
    11121146                if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) {
    11131147                        echo $loading;
    11141148                        return false;
    11151149                }
     1150
    11161151                $check_urls = array( $widgets[ $widget_id ]['url'] );
    11171152        }
     
    11201155        $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
    11211156        $output    = get_transient( $cache_key );
     1157
    11221158        if ( false !== $output ) {
    11231159                echo $output;
     
    11571193        global $wp_dashboard_control_callbacks;
    11581194
    1159         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 ] ) ) {
     1195        if ( is_scalar( $widget_control_id ) && $widget_control_id
     1196                && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] )
     1197                && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] )
     1198        ) {
    11601199                call_user_func(
    11611200                        $wp_dashboard_control_callbacks[ $widget_control_id ],
     
    11821221function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
    11831222        $widget_options = get_option( 'dashboard_widget_options' );
     1223
    11841224        if ( ! $widget_options ) {
    11851225                $widget_options = array();
     
    12101250                        }
    12111251                }
     1252
    12121253                update_option( 'dashboard_widget_options', $widget_options );
     1254
    12131255                $locale    = get_user_locale();
    12141256                $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
     
    15551597 */
    15561598function wp_dashboard_quota() {
    1557         if ( ! is_multisite() || ! current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) ) {
     1599        if ( ! is_multisite() || ! current_user_can( 'upload_files' )
     1600                || get_site_option( 'upload_space_check_disabled' )
     1601        ) {
    15581602                return true;
    15591603        }
     
    15671611                $percentused = ( $used / $quota ) * 100;
    15681612        }
     1613
    15691614        $used_class  = ( $percentused >= 70 ) ? ' warning' : '';
    15701615        $used        = round( $used, 2 );
     
    17041749
    17051750        $response = get_site_transient( 'browser_' . $key );
     1751
    17061752        if ( false === $response ) {
    17071753                // Include an unmodified $wp_version.
     
    17201766                $response = wp_remote_post( $url, $options );
    17211767
    1722                 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
     1768                if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
    17231769                        return false;
    17241770                }
Note: See TracChangeset for help on using the changeset viewer.