Making WordPress.org


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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.