WordPress.org

Making WordPress.org

Changeset 3516


Ignore:
Timestamp:
06/21/2016 09:42:13 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Add a method to retrieve all the users who receive plugin commits.

For now, this also includes the bbPress subscribers until the final switch over.

See #1597

File:
1 edited

Legend:

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

    r3511 r3516  
    255255        return in_array( $user->ID, $users, true );
    256256    }
     257
     258    /**
     259     * Retrieve a list of users who are subscribed to plugin commits.
     260     *
     261     * @param string $plugin_slug       The plugin to retrieve subscribers for.
     262     * @param bool   $include_committers Whether to include Plugin Committers in the list. Default false.
     263     * @return array Array of \WP_User's who are subscribed.
     264     */
     265    public static function get_plugin_subscribers( $plugin_slug, $include_committers = false ) {
     266        global $wpdb;
     267        $post = Plugin_Directory::get_plugin_post( $plugin_slug );
     268        if ( ! $post ) {
     269            return false;
     270        }
     271
     272        $users = array();
     273
     274        // These users are subscribed the plugin commits.
     275        $subscribers = get_post_meta( $post->ID, '_commit_subscribed', true ) ?: array();
     276        foreach ( $subscribers as $subscriber_id ) {
     277            $users[] = get_user_by( 'id', $subscriber_id );
     278        }
     279
     280        // Plugin Committers are always subscrived to plugin commits.
     281        $committers  = self::get_plugin_committers( $plugin_slug );
     282        foreach ( $committers as $committer ) {
     283            $users[] = get_user_by( 'login', $committer );
     284        }
     285
     286        // Include the subscribers from the bbPress plugin directory until we've fully migrated.
     287        $bbpress_subscribers = maybe_unserialize( $wpdb->get_var( $wpdb->prepare( 'SELECT m.meta_value FROM ' . PLUGINS_TABLE_PREFIX . 'topics t JOIN ' . PLUGINS_TABLE_PREFIX . 'meta m ON ( m.object_type = "bb_topic" AND m.object_id = t.topic_id AND m.meta_key = "commit_subscribed") WHERE t.topic_slug = %s', $plugin_slug ) ) );
     288        if ( $bbpress_subscribers ) {
     289            foreach ( array_keys( $bbpress_subscribers ) as $subscriber_id ) {
     290                $users[] = get_user_by( 'id', $subscriber_id );
     291            }
     292        }
     293
     294        $users = array_filter( $users );
     295
     296        return $users;
     297    }
    257298}
Note: See TracChangeset for help on using the changeset viewer.