Making WordPress.org

Changeset 5712


Ignore:
Timestamp:
07/23/2017 01:26:46 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Support Forums, User Notes: After [5659], make sure the dynamic elements of note adding/editing form (post ID and permalink) are still dynamic.

See #2272.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php

    r5671 r5712  
    6363
    6464        // Make sure our nonces are in order.
    65         if ( ! bbp_verify_nonce_request( sprintf( 'wporg-bbp-add-user-note_%d_%d', $user_id, $post_id ) ) ) {
     65        if ( ! bbp_verify_nonce_request( sprintf( 'wporg-bbp-add-user-note_%d', $user_id ) ) ) {
    6666            return;
    6767        }
     
    290290
    291291    /**
     292     * Retrieves user notes output for a particular user.
     293     *
     294     * Replaces '###POST_ID###' and '###POST_PERMALINK###' placeholders
     295     * in the note adding/editing form with the current post ID and permalink.
     296     *
     297     * @param int $user_id User ID. Defaults to the current post author.
     298     * @return string User notes output.
     299     */
     300    public function get_user_notes_html( $user_id ) {
     301        $user_notes = $this->get_user_notes( $user_id )->html;
     302
     303        if ( ! bbp_is_single_user_profile() ) {
     304            $post_id = get_the_ID();
     305        } else {
     306            $post_id = 0;
     307        }
     308
     309        $post_permalink = $this->get_user_note_post_permalink( $post_id );
     310
     311        $user_notes = strtr( $user_notes, array(
     312            '###POST_ID###'        => esc_attr( $post_id ),
     313            '###POST_PERMALINK###' => esc_url( $post_permalink ),
     314        ) );
     315
     316        return $user_notes;
     317    }
     318
     319    /**
    292320     * Retrieves permalink to the post associated with a note.
    293321     *
     
    301329     */
    302330    public function get_user_note_post_permalink( $post_id = 0, $user_id = 0, $site_id = 0 ) {
    303         switch_to_blog( $site_id );
     331        if ( $site_id ) {
     332            switch_to_blog( $site_id );
     333        }
    304334
    305335        $post_type = $post_id ? get_post_type( $post_id ) : '';
     
    321351        }
    322352
    323         restore_current_blog();
     353        if ( $site_id ) {
     354            restore_current_blog();
     355        }
    324356
    325357        return $permalink;
     
    334366        if ( ! $user_id ) {
    335367            $user_id = get_the_author_meta( 'ID' );
    336         }
    337 
    338         if ( ! bbp_is_single_user_profile() ) {
    339             $post_id = get_the_ID();
    340         } else {
    341             $post_id = 0;
    342368        }
    343369
     
    354380            $button_label = esc_html__( 'Add your note', 'wporg-forums' );
    355381        }
    356 
    357         $post_permalink = $this->get_user_note_post_permalink( $post_id );
    358382        ?>
    359         <form action="<?php echo esc_url( $post_permalink ); ?>" method="post" class="wporg-bbp-add-user-note">
    360             <?php wp_nonce_field( sprintf( 'wporg-bbp-add-user-note_%d_%d', $user_id, $post_id ) ); ?>
     383        <form action="###POST_PERMALINK###" method="post" class="wporg-bbp-add-user-note">
     384            <?php wp_nonce_field( sprintf( 'wporg-bbp-add-user-note_%d', $user_id ) ); ?>
    361385            <input type="hidden" name="action" value="wporg_bbp_add_user_note">
    362386            <input type="hidden" name="user_id" value="<?php echo esc_attr( $user_id ); ?>">
    363             <input type="hidden" name="post_id" value="<?php echo esc_attr( $post_id ); ?>">
     387            <input type="hidden" name="post_id" value="###POST_ID###">
    364388            <?php if ( $edit_note ) : ?>
    365389                <input type="hidden" name="note_id" value="<?php echo esc_attr( $note_id ); ?>">
     
    436460        ?>
    437461        <div class="<?php echo esc_attr( $class ); ?>" id="wporg-bbp-user-notes-<?php echo esc_attr( $post_id ); ?>">
    438             <?php echo $this->get_user_notes( $user_id )->html; ?>
     462            <?php echo $this->get_user_notes_html( $user_id ); ?>
    439463        </div>
    440464        <?php
     
    464488            <h2 id="user-notes" class="entry-title"><?php esc_html_e( 'User Notes', 'wporg-forums' ); ?></h2>
    465489            <div class="bbp-user-section">
    466                 <?php echo $this->get_user_notes( $user_id )->html; ?>
     490                <?php echo $this->get_user_notes_html( $user_id ); ?>
    467491            </div>
    468492        </div>
Note: See TracChangeset for help on using the changeset viewer.