Making WordPress.org


Ignore:
Timestamp:
02/18/2022 03:02:37 AM (3 years ago)
Author:
dd32
Message:

Support Forums: Add unsubscription links to plugin/theme/tag subscription emails.

Note: This does not add unsubscription links to bbPress emails, only the ones this plugin adds.
Emails from bbPress for forum / topic subscription ('notify me of replies') will not have these links.

See #5505, #3456.

File:
1 edited

Legend:

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

    r10673 r11580  
    249249    public function always_load() {
    250250        // Add filters necessary for determining which compat file to use.
    251         add_action( 'bbp_init',              array( $this, 'register_taxonomy' ) );
    252         add_filter( 'query_vars',            array( $this, 'add_query_var' ) );
    253         add_action( 'bbp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ) );
    254         add_filter( 'term_link',             array( $this, 'get_term_link' ), 10, 3 );
     251        add_action( 'bbp_init',                 array( $this, 'register_taxonomy' ) );
     252        add_filter( 'query_vars',               array( $this, 'add_query_var' ) );
     253        add_action( 'bbp_add_rewrite_rules',    array( $this, 'add_rewrite_rules' ) );
     254        add_filter( 'term_link',                array( $this, 'get_term_link' ), 10, 3 );
     255        add_filter( 'get_' . $this->taxonomy(), array( $this, 'get_term' ) );
    255256    }
    256257
     
    743744        }
    744745
    745         do_action( 'bbp_template_notices' );
    746 
    747746        $term_subscription = '';
    748747        if ( $this->term ) {
     
    772771
    773772    /**
    774      * Term subscriptions use `get_term_link` for the redirect. This needs to be
    775      * filtered to redirect to the appropriate theme/plugin support view.
     773     * Correct the link to the compat terms.
    776774     *
    777      * @param string $termlink The term link
    778      * @param object $term The term object
    779      * @param string $taxonomy The taxonomy object
     775     * @param string $term_link The term link
     776     * @param object $term      The term object
     777     * @param string $taxonomy  The taxonomy object
    780778     * @return string The term link, or the support view link
    781779     */
    782     public function get_term_link( $termlink, $term, $taxonomy ) {
    783         if ( ! class_exists( 'WordPressdotorg\Forums\Term_Subscription\Plugin' ) ) {
    784             return $termlink;
    785         }
    786 
     780    public function get_term_link( $term_link, $term, $taxonomy ) {
    787781        // Only do this for the non-public compat taxonomies.
    788782        if ( $this->taxonomy() != $taxonomy ) {
    789             return $termlink;
    790         }
    791 
    792         // Are we on a view where this needs filtering?
    793         if (
    794             ( bbp_is_single_view() && $this->compat() == bbp_get_view_id() )
    795         ||
    796             bbp_is_subscriptions()
    797         ||
    798             ( isset( $_GET['term_id'] ) && isset( $_GET['taxonomy'] ) )
    799         ) {
    800             // Check that the subscription is to this compat.
    801             if ( $this->taxonomy() == $taxonomy ) {
    802                 $paged = get_query_var( 'paged' ) > 1 ? 'page/' . absint( get_query_var( 'paged' ) ) . '/' : '';
    803                 $termlink = sprintf( home_url( '/%s/%s/%s' ), $this->compat(), $term->slug, $paged );
    804             }
    805         }
    806 
    807         return $termlink;
     783            return $term_link;
     784        }
     785
     786        $paged = '';
     787        if ( get_query_var( 'paged' ) > 1 ) {
     788            $paged = 'page/' . absint( get_query_var( 'paged' ) ) . '/';
     789        }
     790
     791        return sprintf(
     792            home_url( '/%s/%s/%s' ),
     793            $this->compat(),
     794            $term->slug,
     795            $paged
     796        );
     797    }
     798
     799    /**
     800     * Set the term name for the compat terms to that of the directory.
     801     *
     802     * @param \WP_Term $term
     803     * @return \WP_Term
     804     */
     805    public function get_term( $term ) {
     806        // Note: Not using $this->title() here so as to filter other terms of this taxonomy correctly.
     807
     808        $term->name = $this->get_object( $term->slug )->post_title ?? $term->name;
     809
     810        return $term;
    808811    }
    809812
     
    839842        global $wpdb;
    840843
    841         if ( 'theme' == $this->compat() ) {
    842             if ( ! is_null( $this->theme ) ) {
    843                 return $this->theme;
    844             }
    845         } else {
    846             if ( ! is_null( $this->plugin ) ) {
    847                 return $this->plugin;
    848             }
     844        if (
     845            'theme' == $this->compat() &&
     846            ! is_null( $this->theme ) &&
     847            ( ! $slug || $slug === $this->theme->post_name )
     848        ) {
     849            return $this->theme;
     850
     851        } elseif (
     852            'plugin' == $this->compat() &&
     853            ! is_null( $this->plugin ) &&
     854            ( ! $slug || $slug === $this->plugin->post_name )
     855        ) {
     856            return $this->plugin;
    849857        }
    850858
Note: See TracChangeset for help on using the changeset viewer.