Making WordPress.org


Ignore:
Timestamp:
04/12/2024 05:22:33 AM (19 months ago)
Author:
dd32
Message:

Plugin Directory, Support Forums: Automatically subscribe plugin committers and support reps to a plugins forum activity.

Users can opt-out through the unsubscribe link included with all support forum emails.

This is only applied for future committer/support rep changes.

Fixes #7566.

File:
1 edited

Legend:

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

    r12574 r13510  
    289289
    290290            // Set the term for this view so we can reuse it.
    291             $this->term = get_term_by( 'slug', $this->slug(), $this->taxonomy() );
    292 
    293             // New compats won't have any support topics or reviews, so will
    294             // not yet exist as a compat term.
    295             if ( ! $this->term && $this->get_object( $this->slug() ) ) {
    296                 $term_name = $this->slug();
    297                 if ( ! sanitize_title( $term_name ) ) {
    298                     // This happens when the slug is all non-ascii such as %e5%8f%8b%e8%a8%80, which fails to insert.
    299                     $term_name = urldecode( $term_name );
    300                 }
    301                 $term = wp_insert_term( $term_name, $this->taxonomy(), array( 'slug' => $this->slug() ) );
    302 
    303                 // Term exists already? Race-condition, or get_term_by() couldn't find $slug..
    304                 if ( is_wp_error( $term ) && $term->get_error_data( 'term_exists' ) ) {
    305                     $this->term = get_term( $term->get_error_data( 'term_exists' ) );
    306                 } elseif ( ! is_wp_error( $term ) && isset( $term['term_id'] ) ) {
    307                     $this->term = get_term( $term['term_id'] );
    308                 }
    309             }
     291            $this->initialize_term();
    310292
    311293            // Add plugin- and theme-specific filters and actions.
     
    345327
    346328            $this->loaded = true;
     329        }
     330    }
     331
     332    /**
     333     * Initialises the WP_Term for the compat view.
     334     *
     335     * If the term does not exist, it will be created.
     336     */
     337    public function initialize_term() {
     338        if ( ! $this->slug() ) {
     339            return;
     340        }
     341
     342        $this->term = get_term_by( 'slug', $this->slug(), $this->taxonomy() );
     343
     344        if ( $this->term || ! $this->get_object( $this->slug() ) ) {
     345            return;
     346        }
     347
     348        $term_name = $this->slug();
     349        if ( ! sanitize_title( $term_name ) ) {
     350            // This happens when the slug is all non-ascii such as %e5%8f%8b%e8%a8%80, which fails to insert.
     351            $term_name = urldecode( $term_name );
     352        }
     353
     354        $term = wp_insert_term( $term_name, $this->taxonomy(), array( 'slug' => $this->slug() ) );
     355
     356        // Term exists already? Race-condition, or get_term_by() couldn't find $slug..
     357        if ( is_wp_error( $term ) && $term->get_error_data( 'term_exists' ) ) {
     358            $this->term = get_term( $term->get_error_data( 'term_exists' ) );
     359        } elseif ( ! is_wp_error( $term ) && isset( $term['term_id'] ) ) {
     360            $this->term = get_term( $term['term_id'] );
    347361        }
    348362    }
Note: See TracChangeset for help on using the changeset viewer.