Making WordPress.org

Changeset 13510


Ignore:
Timestamp:
04/12/2024 05:22:33 AM (2 years 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.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    r12505 r13510  
    239239                        $email->send();
    240240                }
     241
     242                Tools::subscribe_user_to_forum_threads( $user, $post );
    241243
    242244                return $result;
     
    407409                }
    408410
     411                Tools::subscribe_user_to_forum_threads( $user, $post );
     412
    409413                return $result;
    410414        }
     
    639643                ] );
    640644        }
     645
     646        /**
     647         * Subscribe a user to the forum topics for a given plugin.
     648         *
     649         * @param WP_User|int $user_id The user to subscribe.
     650         * @param WP_Post     $post    The plugin to subscribe to.
     651         * @return bool
     652         */
     653        public static function subscribe_user_to_forum_threads( $user_id, $post = null ) {
     654                $post = Plugin_Directory::get_plugin_post( $post );
     655
     656                if ( ! $user_id || ! $post || ! defined( 'PLUGIN_API_INTERNAL_BEARER_TOKEN' ) ) {
     657                        return false;
     658                }
     659
     660                if ( $user_id instanceof \WP_User ) {
     661                        $user_id = $user_id->ID;
     662                }
     663
     664                $request = wp_remote_post(
     665                        'https://wordpress.org/support/wp-json/wporg-support/v1/subscribe-user-to-term',
     666                        [
     667                                'body'    => [
     668                                        'type'    => 'plugin',
     669                                        'slug'    => $post->post_name,
     670                                        'user_id' => $user_id,
     671                                ],
     672                                'headers' => [
     673                                        'Authorization' => 'Bearer ' . PLUGIN_API_INTERNAL_BEARER_TOKEN,
     674                                ],
     675                        ]
     676                );
     677
     678                return 200 === wp_remote_retrieve_response_code( $request );
     679        }
    641680}
  • 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        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin-directory-compat.php

    r12447 r13510  
    113113                $this->support_reps = $this->get_support_reps( $slug );
    114114
     115                $this->initialize_term();
     116
    115117                return true;
    116118        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php

    r12892 r13510  
    4040        public $theme_subscriptions  = false; // Defined via Support_Compat
    4141        public $blocks               = false;
     42        public $rest_api             = false;
    4243
    4344        /**
     
    7475                $this->emails       = new Emails;
    7576                $this->audit_log    = new Audit_Log;
     77                $this->rest_api     = new REST_API;
    7678
    7779                // Set a flag to indicate whether this is the global forums, or a locale forum.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php

    r12293 r13510  
    3131include( __DIR__ . '/inc/class-audit-log.php' );
    3232include( __DIR__ . '/inc/class-blocks.php' );
     33include( __DIR__ . '/inc/class-rest-api.php' );
    3334
    3435// Compat-only includes.
Note: See TracChangeset for help on using the changeset viewer.