Making WordPress.org

Changeset 5764


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

Support Forums: Don't save or display a site URL for the topic if it's empty.

See #363.

File:
1 edited

Legend:

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

    r5757 r5764  
    377377     */
    378378    public function display_extra_topic_fields() {
     379        $site_url = get_post_meta( bbp_get_topic_id(), self::SITE_URL_META, true );
     380
    379381        // Display site URL for logged-in users.
    380         if ( is_user_logged_in() ) {
    381             $site_url = get_post_meta( bbp_get_topic_id(), self::SITE_URL_META, true );
    382 
     382        if ( is_user_logged_in() && $site_url ) {
    383383            printf( '<p>%1$s <a href="%2$s" rel="nofollow">%2$s</a></p>',
    384384                __( 'Site URL:', 'wporg-forums' ),
     
    411411            $site_url = esc_url_raw( apply_filters( 'pre_user_url', $_POST['site_url'] ) );
    412412
    413             $protocols = implode( '|', array( 'http', 'https' ) );
    414             if ( ! preg_match( '/^(' . $protocols . '):/is', $site_url ) ) {
    415                 $site_url = 'http://' . $site_url;
     413            if ( $site_url ) {
     414                $protocols = implode( '|', array( 'http', 'https' ) );
     415                if ( ! preg_match( '/^(' . $protocols . '):/is', $site_url ) ) {
     416                    $site_url = 'http://' . $site_url;
     417                }
     418
     419                update_post_meta( $topic_id, self::SITE_URL_META, $site_url );
     420            } elseif ( 'bbp_edit_topic' === current_action() ) {
     421                delete_post_meta( $topic_id, self::SITE_URL_META );
    416422            }
    417 
    418             update_post_meta( $topic_id, self::SITE_URL_META, $site_url );
    419423        }
    420424    }
Note: See TracChangeset for help on using the changeset viewer.