Making WordPress.org


Ignore:
Timestamp:
07/11/2017 11:48:08 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Support Theme: Save some repeated get_post() calls and User_Moderation plugin references to variables for better performance and readability.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php

    r5644 r5651  
    387387 */
    388388function wporg_support_add_moderation_notice() {
    389     $post_time       = mysql2date( 'U', get_post_field( 'post_date', get_the_ID() ) );
    390     $seconds_passed  = current_time( 'timestamp' ) - $post_time;
    391     $hours_passed    = (int) ( $seconds_passed / HOUR_IN_SECONDS );
    392     $post_status     = get_post_status();
    393     $is_moderator    = current_user_can( 'moderate', get_the_ID() );
     389    $post            = get_post();
     390    $post_time       = mysql2date( 'U', $post->post_date );
     391
     392    $hours_passed    = (int) ( ( current_time( 'timestamp' ) - $post_time ) / HOUR_IN_SECONDS );
     393    $is_moderator    = current_user_can( 'moderate', $post->ID );
    394394    $is_user_blocked = ! current_user_can( 'spectate' );
     395
    395396    $notice_class    = '';
    396397    $notices         = array();
    397398
    398     if ( $is_moderator && in_array( $post_status, array( 'archived', 'pending', 'spam' ) ) ) :
    399 
    400         if ( 'spam' === $post_status ) {
     399    if ( $is_moderator && in_array( $post->post_status, array( 'archived', 'pending', 'spam' ) ) ) :
     400
     401        if ( 'spam' === $post->post_status ) {
    401402            $notice_class = 'warning';
    402403
    403             $reporter = get_post_meta( get_the_ID(), '_bbp_akismet_user', true );
     404            $reporter = get_post_meta( $post->ID, '_bbp_akismet_user', true );
    404405
    405406            if ( $reporter ) {
     
    409410                $notices[] = __( 'This post has been flagged as spam.', 'wporg-forums' );
    410411            }
    411         } elseif ( 'archived' === $post_status ) {
    412             $moderator = get_post_meta( get_the_ID(), '_wporg_bbp_moderator', true );
     412        } elseif ( 'archived' === $post->post_status ) {
     413            $moderator = get_post_meta( $post->ID, '_wporg_bbp_moderator', true );
    413414
    414415            if ( $moderator ) {
     
    419420            }
    420421        } else {
    421             $moderator = get_post_meta( get_the_ID(), '_wporg_bbp_moderator', true );
     422            $moderator = get_post_meta( $post->ID, '_wporg_bbp_moderator', true );
    422423
    423424            if ( $moderator ) {
     
    430431
    431432        if ( class_exists( 'WordPressdotorg\Forums\User_Moderation\Plugin' ) ) :
    432             $is_user_flagged = WordPressdotorg\Forums\User_Moderation\Plugin::get_instance()->is_user_flagged( get_post()->post_author );
    433             $moderator       = get_user_meta( get_post()->post_author, WordPressdotorg\Forums\User_Moderation\Plugin::MODERATOR_META, true );
    434             $moderation_date = get_user_meta( get_post()->post_author, WordPressdotorg\Forums\User_Moderation\Plugin::MODERATION_DATE_META, true );
     433            $plugin_instance = WordPressdotorg\Forums\User_Moderation\Plugin::get_instance();
     434            $is_user_flagged = $plugin_instance->is_user_flagged( $post->post_author );
     435            $moderator       = get_user_meta( $post->post_author, $plugin_instance::MODERATOR_META, true );
     436            $moderation_date = get_user_meta( $post->post_author, $plugin_instance::MODERATION_DATE_META, true );
    435437
    436438            if ( $is_user_flagged ) {
     
    457459        endif;
    458460
    459     elseif ( in_array( $post_status, array( 'pending', 'spam' ) ) ) :
     461    elseif ( in_array( $post->post_status, array( 'pending', 'spam' ) ) ) :
    460462
    461463        if ( $is_user_blocked ) {
Note: See TracChangeset for help on using the changeset viewer.