Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/27/2024 06:05:30 PM (12 months ago)
Author:
imath
Message:

Activity component: improve PHP code standards using WPCS

See #7228 (branch 12.0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/12.0/src/bp-activity/bp-activity-admin.php

    r13497 r13817  
    1515
    1616// Include WP's list table class.
    17 if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
     17if ( ! class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
    1818
    1919// Per_page screen option. Has to be hooked in extremely early.
    20 if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-activity' == $_REQUEST['page'] )
     20if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-activity' == $_REQUEST['page'] ) {
    2121    add_filter( 'set-screen-option', 'bp_activity_admin_screen_options', 10, 3 );
     22}
    2223
    2324/**
     
    7778
    7879    // $parent_id is required.
    79     if ( empty( $parent_id ) )
     80    if ( empty( $parent_id ) ) {
    8081        die( '-1' );
     82    }
    8183
    8284    // If $root_id not set (e.g. for root items), use $parent_id.
    83     if ( empty( $root_id ) )
     85    if ( empty( $root_id ) ) {
    8486        $root_id = $parent_id;
     87    }
    8588
    8689    // Check that a reply has been entered.
    87     if ( empty( $_REQUEST['content'] ) )
    88         die( __( 'Error: Please type a reply.', 'buddypress' ) );
     90    if ( empty( $_REQUEST['content'] ) ) {
     91        die( esc_html__( 'Error: Please type a reply.', 'buddypress' ) );
     92    }
    8993
    9094    // Check parent activity exists.
    9195    $parent_activity = new BP_Activity_Activity( $parent_id );
    92     if ( empty( $parent_activity->component ) )
    93         die( __( 'Error: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddypress' ) );
     96    if ( empty( $parent_activity->component ) ) {
     97        die( esc_html__( 'Error: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddypress' ) );
     98    }
    9499
    95100    // @todo: Check if user is allowed to create new activity items
    96101    // if ( ! current_user_can( 'bp_new_activity' ) )
    97     if ( ! bp_current_user_can( 'bp_moderate' ) )
     102    if ( ! bp_current_user_can( 'bp_moderate' ) ) {
    98103        die( '-1' );
     104    }
    99105
    100106    // Add new activity comment.
     
    589595
    590596        // If an error occurred, pass back the activity ID that failed.
    591         if ( $error )
     597        if ( $error ) {
    592598            $redirect_to = add_query_arg( 'error', $error, $redirect_to );
    593         else
     599        } else {
    594600            $redirect_to = add_query_arg( 'updated', $activity->id, $redirect_to );
     601        }
    595602
    596603        /**
     
    689696            printf(
    690697                /* translators: 1: activity type. 2: activity author. 3: activity date and time. */
    691                 __( '"%1$s" activity submitted by %2$s on %3$s', 'buddypress' ),
     698                esc_html__( '"%1$s" activity submitted by %2$s on %3$s', 'buddypress' ),
    692699                esc_html( $activity_type ),
     700                // phpcs:ignore WordPress.Security.EscapeOutput
    693701                bp_core_get_userlink( $activity->user_id ),
    694702                sprintf(
    695703                    '<a href="%1$s">%2$s</a>',
    696704                    esc_url( bp_activity_get_permalink( $activity->id, $activity ) ),
    697                     date_i18n( bp_get_option( 'date_format' ), strtotime( $activity->date_recorded ) )
     705                    esc_html( date_i18n( bp_get_option( 'date_format' ), strtotime( $activity->date_recorded ) ) )
    698706                )
    699707            );
     
    761769            <?php
    762770            /* translators: %s: the activity ID */
    763             printf( __( 'Editing Activity (ID #%s)', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) );
     771            printf( esc_html__( 'Editing Activity (ID #%s)', 'buddypress' ), esc_html( number_format_i18n( (int) $_REQUEST['aid'] ) ) );
    764772            ?>
    765773        </h1>
     
    776784                            <div id="postdiv">
    777785                                <div id="bp_activity_action" class="activitybox">
    778                                     <h2><?php _e( 'Action', 'buddypress' ); ?></h2>
     786                                    <h2><?php esc_html_e( 'Action', 'buddypress' ); ?></h2>
    779787                                    <div class="inside">
    780                                         <label for="bp-activities-action" class="screen-reader-text"><?php
    781                                             /* translators: accessibility text */
    782                                             _e( 'Edit activity action', 'buddypress' );
    783                                         ?></label>
     788                                        <label for="bp-activities-action" class="screen-reader-text">
     789                                            <?php
     790                                                /* translators: accessibility text */
     791                                                esc_html_e( 'Edit activity action', 'buddypress' );
     792                                            ?>
     793                                        </label>
    784794                                        <?php wp_editor( stripslashes( $activity->action ), 'bp-activities-action', array( 'media_buttons' => false, 'textarea_rows' => 7, 'teeny' => true, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ) ) ); ?>
    785795                                    </div>
     
    787797
    788798                                <div id="bp_activity_content" class="activitybox">
    789                                     <h2><?php _e( 'Content', 'buddypress' ); ?></h2>
     799                                    <h2><?php esc_html_e( 'Content', 'buddypress' ); ?></h2>
    790800                                    <div class="inside">
    791                                         <label for="bp-activities-content" class="screen-reader-text"><?php
    792                                             /* translators: accessibility text */
    793                                             _e( 'Edit activity content', 'buddypress' );
    794                                         ?></label>
     801                                        <label for="bp-activities-content" class="screen-reader-text">
     802                                            <?php
     803                                                /* translators: accessibility text */
     804                                                esc_html_e( 'Edit activity content', 'buddypress' );
     805                                            ?>
     806                                        </label>
    795807                                        <?php wp_editor( stripslashes( $activity->content ), 'bp-activities-content', array( 'media_buttons' => false, 'teeny' => true, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ) ) ); ?>
    796808                                    </div>
     
    820832                printf(
    821833                    '%1$s <a href="%2$s">%3$s</a>',
    822                     __( 'No activity found with this ID.', 'buddypress' ),
     834                    esc_html__( 'No activity found with this ID.', 'buddypress' ),
    823835                    esc_url( bp_get_admin_url( 'admin.php?page=bp-activity' ) ),
    824                     __( 'Go back and try again.', 'buddypress' )
     836                    esc_html__( 'Go back and try again.', 'buddypress' )
    825837                );
    826838            ?></p>
     
    852864            <div id="minor-publishing-actions">
    853865                <div id="preview-action">
    854                     <a class="button preview" href="<?php echo esc_attr( bp_activity_get_permalink( $item->id, $item ) ); ?>" target="_blank"><?php _e( 'View Activity', 'buddypress' ); ?></a>
     866                    <a class="button preview" href="<?php echo esc_url( bp_activity_get_permalink( $item->id, $item ) ); ?>" target="_blank"><?php esc_html_e( 'View Activity', 'buddypress' ); ?></a>
    855867                </div>
    856868
     
    860872            <div id="misc-publishing-actions">
    861873                <div class="misc-pub-section" id="comment-status-radio">
    862                     <label class="approved" for="activity-status-approved"><input type="radio" name="activity_status" id="activity-status-approved" value="ham" <?php checked( $item->is_spam, 0 ); ?>><?php _e( 'Approved', 'buddypress' ); ?></label><br />
    863                     <label class="spam" for="activity-status-spam"><input type="radio" name="activity_status" id="activity-status-spam" value="spam" <?php checked( $item->is_spam, 1 ); ?>><?php _e( 'Spam', 'buddypress' ); ?></label>
     874                    <label class="approved" for="activity-status-approved"><input type="radio" name="activity_status" id="activity-status-approved" value="ham" <?php checked( $item->is_spam, 0 ); ?>><?php esc_html_e( 'Approved', 'buddypress' ); ?></label><br />
     875                    <label class="spam" for="activity-status-spam"><input type="radio" name="activity_status" id="activity-status-spam" value="spam" <?php checked( $item->is_spam, 1 ); ?>><?php esc_html_e( 'Spam', 'buddypress' ); ?></label>
    864876                </div>
    865877
     
    873885                        <?php
    874886                        /* translators: %s: the date the activity was submitted on */
    875                         printf( __( 'Submitted on: %s', 'buddypress' ), '<strong>' . $date . '</strong>' );
     887                        printf( esc_html__( 'Submitted on: %s', 'buddypress' ), '<strong>' . esc_html( $date ) . '</strong>' );
    876888                        ?>
    877                     </span>&nbsp;<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e( 'Edit', 'buddypress' ); ?></a>
     889                    </span>&nbsp;<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php esc_html_e( 'Edit', 'buddypress' ); ?></a>
    878890
    879891                    <div id='timestampdiv' class='hide-if-js'>
     
    912924?>
    913925
    914     <label class="screen-reader-text" for="bp-activities-link"><?php
    915         /* translators: accessibility text */
    916         _e( 'Link', 'buddypress' );
    917     ?></label>
     926    <label class="screen-reader-text" for="bp-activities-link">
     927        <?php
     928            /* translators: accessibility text */
     929            esc_html_e( 'Link', 'buddypress' );
     930        ?>
     931    </label>
    918932    <input type="url" name="bp-activities-link" id="bp-activities-link" value="<?php echo esc_url( $item->primary_link ); ?>" aria-describedby="bp-activities-link-description" />
    919     <p id="bp-activities-link-description"><?php _e( 'Activity generated by posts and comments uses the link field for a permalink back to the content item.', 'buddypress' ); ?></p>
     933    <p id="bp-activities-link-description"><?php esc_html_e( 'Activity generated by posts and comments uses the link field for a permalink back to the content item.', 'buddypress' ); ?></p>
    920934
    921935<?php
     
    932946?>
    933947
    934     <label class="screen-reader-text" for="bp-activities-userid"><?php
    935         /* translators: accessibility text */
    936         _e( 'Author ID', 'buddypress' );
    937     ?></label>
     948    <label class="screen-reader-text" for="bp-activities-userid">
     949        <?php
     950            /* translators: accessibility text */
     951            esc_html_e( 'Author ID', 'buddypress' );
     952        ?>
     953    </label>
    938954    <input type="number" name="bp-activities-userid" id="bp-activities-userid" value="<?php echo esc_attr( $item->user_id ); ?>" min="1" />
    939955
     
    10201036            sprintf(
    10211037                /* translators: %s: the name of the activity type */
    1022                 __( 'This activity item has a type (%s) that is not registered using bp_activity_set_action(), so no label is available.', 'buddypress' ),
    1023                 $selected
     1038                esc_html__( 'This activity item has a type (%s) that is not registered using bp_activity_set_action(), so no label is available.', 'buddypress' ),
     1039                esc_html( $selected )
    10241040            ),
    10251041            '2.0.0'
     
    10311047    ?>
    10321048
    1033     <label for="bp-activities-type" class="screen-reader-text"><?php
    1034         /* translators: accessibility text */
    1035         esc_html_e( 'Select activity type', 'buddypress' );
    1036     ?></label>
     1049    <label for="bp-activities-type" class="screen-reader-text">
     1050        <?php
     1051            /* translators: accessibility text */
     1052            esc_html_e( 'Select activity type', 'buddypress' );
     1053        ?>
     1054    </label>
    10371055    <select name="bp-activities-type" id="bp-activities-type">
    10381056        <?php foreach ( $actions as $k => $v ) : ?>
     
    10541072?>
    10551073
    1056     <label for="bp-activities-primaryid"><?php _e( 'Primary Item ID', 'buddypress' ); ?></label>
     1074    <label for="bp-activities-primaryid"><?php esc_html_e( 'Primary Item ID', 'buddypress' ); ?></label>
    10571075    <input type="number" name="bp-activities-primaryid" id="bp-activities-primaryid" value="<?php echo esc_attr( $item->item_id ); ?>" min="0" />
    10581076    <br />
    10591077
    1060     <label for="bp-activities-secondaryid"><?php _e( 'Secondary Item ID', 'buddypress' ); ?></label>
     1078    <label for="bp-activities-secondaryid"><?php esc_html_e( 'Secondary Item ID', 'buddypress' ); ?></label>
    10611079    <input type="number" name="bp-activities-secondaryid" id="bp-activities-secondaryid" value="<?php echo esc_attr( $item->secondary_item_id ); ?>" min="0" />
    10621080
    1063     <p><?php _e( 'These identify the object that created this activity. For example, the fields could reference a pair of site and comment IDs.', 'buddypress' ); ?></p>
     1081    <p><?php esc_html_e( 'These identify the object that created this activity. For example, the fields could reference a pair of site and comment IDs.', 'buddypress' ); ?></p>
    10641082
    10651083<?php
     
    11561174                <?php
    11571175                /* translators: %s: the activity ID */
    1158                 printf( __( 'Activity related to ID #%s', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) );
     1176                printf( esc_html__( 'Activity related to ID #%s', 'buddypress' ), esc_html( number_format_i18n( (int) $_REQUEST['aid'] ) ) );
    11591177                ?>
    11601178            <?php else : ?>
    1161                 <?php _ex( 'Activity', 'Admin SWA page', 'buddypress' ); ?>
     1179                <?php echo esc_html_x( 'Activity', 'Admin SWA page', 'buddypress' ); ?>
    11621180            <?php endif; ?>
    11631181
     
    11661184                    <?php
    11671185                    /* translators: %s: the activity search terms */
    1168                     printf( __( 'Search results for &#8220;%s&#8221;', 'buddypress' ), wp_html_excerpt( esc_html( stripslashes( $_REQUEST['s'] ) ), 50 ) );
     1186                    printf( esc_html__( 'Search results for &#8220;%s&#8221;', 'buddypress' ), esc_html( wp_html_excerpt( stripslashes( $_REQUEST['s'] ) ), 50 ) );
    11691187                    ?>
    11701188                </span>
     
    11761194        <?php // If the user has just made a change to an activity item, display the status messages. ?>
    11771195        <?php if ( !empty( $messages ) ) : ?>
    1178             <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?> notice is-dismissible"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div>
     1196            <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?> notice is-dismissible"><p><?php echo implode( "<br/>\n", array_map( 'esc_html', $messages ) ); ?></p></div>
    11791197        <?php endif; ?>
    11801198
     
    11831201
    11841202        <form id="bp-activities-form" action="" method="get">
    1185             <?php $bp_activity_list_table->search_box( __( 'Search all Activity', 'buddypress' ), 'bp-activity' ); ?>
     1203            <?php $bp_activity_list_table->search_box( esc_html__( 'Search all Activity', 'buddypress' ), 'bp-activity' ); ?>
    11861204            <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" />
    11871205            <?php $bp_activity_list_table->display(); ?>
     
    11941212                    <form method="get" action="">
    11951213
    1196                         <h3 id="bp-replyhead"><?php _e( 'Reply to Activity', 'buddypress' ); ?></h3>
    1197                         <label for="bp-activities" class="screen-reader-text"><?php
    1198                             /* translators: accessibility text */
    1199                             _e( 'Reply', 'buddypress' );
    1200                         ?></label>
     1214                        <h3 id="bp-replyhead"><?php esc_html_e( 'Reply to Activity', 'buddypress' ); ?></h3>
     1215                        <label for="bp-activities" class="screen-reader-text">
     1216                            <?php
     1217                                /* translators: accessibility text */
     1218                                esc_html_e( 'Reply', 'buddypress' );
     1219                            ?>
     1220                        </label>
    12011221                        <?php wp_editor( '', 'bp-activities', array( 'dfw' => false, 'media_buttons' => false, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ), 'tinymce' => false, ) ); ?>
    12021222
    12031223                        <p id="bp-replysubmit" class="submit">
    1204                             <a href="#" class="cancel button-secondary alignleft"><?php _e( 'Cancel', 'buddypress' ); ?></a>
    1205                             <a href="#" class="save button-primary alignright"><?php _e( 'Reply', 'buddypress' ); ?></a>
     1224                            <a href="#" class="cancel button-secondary alignleft"><?php esc_html_e( 'Cancel', 'buddypress' ); ?></a>
     1225                            <a href="#" class="save button-primary alignright"><?php esc_html_e( 'Reply', 'buddypress' ); ?></a>
    12061226
    12071227                            <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
Note: See TracChangeset for help on using the changeset viewer.