Making WordPress.org

Changeset 7380


Ignore:
Timestamp:
07/06/2018 05:31:55 PM (7 years ago)
Author:
obenland
Message:

Plugins: Display plugins the author supports

Fixes #3701.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-author-card.php

    r7309 r7380  
    3838            return;
    3939        }
     40
     41        $author_support_rep = get_posts( [
     42            'post_type'      => 'plugin',
     43            'post_status'    => 'any',
     44            'posts_per_page' => -1,
     45            'tax_query'      => [
     46                [
     47                    'taxonomy' => 'plugin_support_reps',
     48                    'field'    => 'slug',
     49                    'terms'    => $author->user_nicename,
     50                ],
     51            ],
     52        ] );
    4053
    4154        $author_commit    = Tools::get_users_write_access_plugins( $author );
     
    5871                <strong><a href="//profiles.wordpress.org/<?php echo $author->user_nicename; ?>"><?php echo $author->user_login; ?></a></strong>
    5972                <?php
    60                     $author_links = array(
    61                         sprintf(
    62                             '<a href="//make.wordpress.org/pluginrepo/?s=%s" title="%s">P2</a>',
    63                             urlencode( esc_attr( $author->user_nicename ) ),
    64                             esc_attr__( 'Click to search Pluginrepo P2 for mentions of this author', 'wporg-plugins' )
    65                         ),
    66                         sprintf(
    67                             '<a href="https://supportpress.wordpress.org/plugins/?q=%s&status=&todo=Search+%%C2%%BB" title="%s">SP</a>',
    68                             urlencode( esc_attr( $author->user_nicename ) ),
    69                             esc_attr__( 'Click to search Pluginrepo SupportPress for mentions of this author', 'wporg-plugins' )
    70                         ),
    71                     );
    72                     vprintf( '<span class="profile-sp-link">[ %s | %s ]</span>', $author_links );
     73                $author_links = array(
     74                    sprintf(
     75                        '<a href="//make.wordpress.org/pluginrepo/?s=%s" title="%s">P2</a>',
     76                        urlencode( esc_attr( $author->user_nicename ) ),
     77                        esc_attr__( 'Click to search Pluginrepo P2 for mentions of this author', 'wporg-plugins' )
     78                    ),
     79                    sprintf(
     80                        '<a href="https://supportpress.wordpress.org/plugins/?q=%s&status=&todo=Search+%%C2%%BB" title="%s">SP</a>',
     81                        urlencode( esc_attr( $author->user_nicename ) ),
     82                        esc_attr__( 'Click to search Pluginrepo SupportPress for mentions of this author', 'wporg-plugins' )
     83                    ),
     84                );
     85                vprintf( '<span class="profile-sp-link">[ %s | %s ]</span>', $author_links );
    7386                ?>
    7487
     
    8194                    <span class="profile-sp-link">
    8295                    <?php
    83                         printf(
    84                             '[ <a href="https://supportpress.wordpress.org/plugins/?sender=%s&status=&todo=Search" title="%s">SP</a> ]',
    85                             esc_attr( $author->user_email ),
    86                             esc_attr__( 'Click to search Pluginrepo SupportPress for emails sent to/from this email address', 'wporg-plugins' )
    87                         );
     96                    printf(
     97                        '[ <a href="https://supportpress.wordpress.org/plugins/?sender=%s&status=&todo=Search" title="%s">SP</a> ]',
     98                        esc_attr( $author->user_email ),
     99                        esc_attr__( 'Click to search Pluginrepo SupportPress for emails sent to/from this email address', 'wporg-plugins' )
     100                    );
    88101                    ?>
    89102                    </span>
    90103                </div>
    91104                <div class="profile-join">
    92                 <?php
     105                    <?php
    93106                    /* translators: 1: time ago, 2: registration date */
    94107                    printf(
     
    97110                        date( 'Y-M-d', strtotime( $author->user_registered ) )
    98111                    );
    99                 ?>
     112                    ?>
    100113                </div>
    101114            </div>
     
    203216
    204217                echo '<ul>';
    205                 foreach ( $all_plugins as $plugin ) {
    206                     echo '<li>';
    207                     $note         = false;
    208                     $extra        = '';
    209                     $classes      = $tooltips = array();
    210                     $last_updated = get_post_meta( $plugin->ID, 'last_updated', true );
    211 
    212                     if ( in_array( $plugin->post_name, wp_list_pluck( $author_plugins, 'post_name' ) ) ) {
    213                         $tooltips[] = __( 'This user submitted this plugin.', 'wporg-plugins ' );
    214                         $classes[]  = 'plugin-owner';
    215                         if ( ! in_array( $plugin->post_name, $author_commit ) ) {
    216                             $note       = true;
    217                             $tooltips[] = __( 'The user is not a current committer.', 'wporg-plugins' );
    218                         }
    219                     }
    220 
    221                     $plugin_slug = $plugin->post_name;
    222                     if ( in_array( $plugin->post_status, array( 'new', 'pending' ) ) ) {
    223                         /* translators: %s: time ago */
    224                         $extra     .= sprintf(
    225                             __( '(requested %s ago)', 'wporg-plugins' ),
    226                             human_time_diff( strtotime( $last_updated ) )
    227                         );
    228                         $tooltips[] = __( 'Requested, remains unapproved.', 'wporg-plugins' );
    229                         $classes[]  = 'profile-plugin-requested';
    230 
    231                     } elseif ( 'rejected' === $plugin->post_status ) {
    232                         $tooltips[]  = __( 'Plugin was rejected.', 'wporg-plugins' );
    233                         $classes[]   = 'profile-plugin-rejected';
    234                         $plugin_slug = substr( $plugin_slug, 9, - 9 );
    235 
    236                     } elseif ( 'closed' === $plugin->post_status ) {
    237                         /* translators: %s: close/disable reason */
    238                         $extra     .= sprintf(
    239                             __( '(closed: %s)', 'wporg-plugins' ),
    240                             Template::get_close_reason( $plugin )
    241                         );
    242                         $tooltips[] = __( 'Plugin is closed.', 'wporg-plugins' );
    243                         $classes[]  = 'profile-plugin-closed';
    244 
    245                     } elseif ( 'disabled' === $plugin->post_status ) {
    246                         /* translators: %s: close/disable reason */
    247                         $extra     .= sprintf(
    248                             __( '(disabled: %s)', 'wporg-plugins' ),
    249                             Template::get_close_reason( $plugin )
    250                         );
    251                         $tooltips[] = __( 'Plugin is disabled (updates are active).', 'wporg-plugins' );
    252                         $classes[]  = 'profile-plugin-closed';
    253                         $note       = true;
    254 
    255                     } else {
    256                         // Plugin is some fashion of open.
    257                         if ( 'approved' === $plugin->post_status ) {
    258                             $note       = true;
    259                             $tooltips[] = __( 'Plugin is approved, but has no data.', 'wporg-plugins' );
    260                             $classes[]  = 'profile-plugin-open-unused';
    261                         } elseif ( strtotime( '-2 years' ) > strtotime( $last_updated ) ) {
    262                             $tooltips[] = __( 'Plugin is open but has not been updated in more than two years.', 'wporg-plugins' );
    263                             $classes[]  = 'profile-plugin-open-old';
    264                         } else {
    265                             $tooltips[] = __( 'Plugin is open.', 'wporg-plugins' );
    266                         }
    267                         $classes[] = 'profile-plugin-open';
    268                     }
    269 
    270                     echo '<span>';
    271 
    272                     printf(
    273                         '<a class="%1$s" title="%2$s" href="%3$s">%4$s</a>',
    274                         esc_attr( implode( ' ', $classes ) ),
    275                         esc_attr( implode( ' ', $tooltips ) ),
    276                         esc_attr( get_permalink( $plugin ) ),
    277                         $plugin->post_name
    278                     );
    279 
    280                     if ( $note ) {
    281                         echo '*';
    282                     }
    283 
    284                     $plugin_links = array(
    285                         sprintf(
    286                             '<a href="%s" title="%s">%s</a>',
    287                             esc_url( get_edit_post_link( $plugin->ID, '' ) ),
    288                             esc_attr__( 'Edit this plugin', 'wporg-plugins' ),
    289                             __( 'Edit', 'wporg-plugins' )
    290                         ),
    291                         sprintf(
    292                             '<a href="//make.wordpress.org/pluginrepo/?s=%s" title="%s">P2</a>',
    293                             urlencode( esc_attr( $plugin_slug ) ),
    294                             esc_attr__( 'Click to search Plugin Team P2 for mentions of this plugin', 'wporg-plugins' )
    295                         ),
    296                         sprintf(
    297                             '<a href="https://supportpress.wordpress.org/plugins/?q=%s&status=&todo=Search+%%C2%%BB" title="%s">SP</a>',
    298                             urlencode( esc_attr( $plugin_slug ) ),
    299                             esc_attr__( 'Click to search Plugin SupportPress for mentions of this plugin', 'wporg-plugins' )
    300                         ),
    301                     );
    302                     vprintf( '<span class="profile-sp-link">[ %s | %s | %s ]</span>', $plugin_links );
    303 
    304                     if ( $extra ) {
    305                         echo ' ' . $extra;
    306                     }
    307 
    308                     echo '</span></li>' . "\n";
    309                 }
     218                self::display_plugin_links( $all_plugins, $author_plugins, $author_commit );
    310219                echo '</ul>';
    311220            }
    312             ?>
     221
     222            if ( ! empty( $author_support_rep ) ) :
     223                ?>
     224                <p><strong><?php esc_html_e( 'Support Rep for:', 'wporg-plugins' ); ?></strong></p>
     225                <ul>
     226                    <?php self::display_plugin_links( $author_support_rep, $author_plugins, $author_commit ); ?>
     227                </ul>
     228            <?php endif; ?>
    313229        </div>
    314230
     
    342258        );
    343259    }
     260
     261    /**
     262     * Displays a list of the passed plugins with their meta information.
     263     *
     264     * @param array $all_plugins    All plugins associated with this author.
     265     * @param array $author_plugins Other plugins by this author.
     266     * @param array $author_commit  Plugins the author has commit access to.
     267     */
     268    protected static function display_plugin_links( $all_plugins, $author_plugins, $author_commit ) {
     269        foreach ( $all_plugins as $plugin ) {
     270            echo '<li>';
     271            $note         = false;
     272            $extra        = '';
     273            $classes      = $tooltips = array();
     274            $last_updated = get_post_meta( $plugin->ID, 'last_updated', true );
     275
     276            if ( in_array( $plugin->post_name, wp_list_pluck( $author_plugins, 'post_name' ) ) ) {
     277                $tooltips[] = __( 'This user submitted this plugin.', 'wporg-plugins ' );
     278                $classes[]  = 'plugin-owner';
     279                if ( ! in_array( $plugin->post_name, $author_commit ) ) {
     280                    $note       = true;
     281                    $tooltips[] = __( 'The user is not a current committer.', 'wporg-plugins' );
     282                }
     283            }
     284
     285            $plugin_slug = $plugin->post_name;
     286            if ( in_array( $plugin->post_status, array( 'new', 'pending' ) ) ) {
     287                /* translators: %s: time ago */
     288                $extra     .= sprintf(
     289                    __( '(requested %s ago)', 'wporg-plugins' ),
     290                    human_time_diff( strtotime( $last_updated ) )
     291                );
     292                $tooltips[] = __( 'Requested, remains unapproved.', 'wporg-plugins' );
     293                $classes[]  = 'profile-plugin-requested';
     294
     295            } elseif ( 'rejected' === $plugin->post_status ) {
     296                $tooltips[]  = __( 'Plugin was rejected.', 'wporg-plugins' );
     297                $classes[]   = 'profile-plugin-rejected';
     298                $plugin_slug = substr( $plugin_slug, 9, - 9 );
     299
     300            } elseif ( 'closed' === $plugin->post_status ) {
     301                /* translators: %s: close/disable reason */
     302                $extra     .= sprintf(
     303                    __( '(closed: %s)', 'wporg-plugins' ),
     304                    Template::get_close_reason( $plugin )
     305                );
     306                $tooltips[] = __( 'Plugin is closed.', 'wporg-plugins' );
     307                $classes[]  = 'profile-plugin-closed';
     308
     309            } elseif ( 'disabled' === $plugin->post_status ) {
     310                /* translators: %s: close/disable reason */
     311                $extra     .= sprintf(
     312                    __( '(disabled: %s)', 'wporg-plugins' ),
     313                    Template::get_close_reason( $plugin )
     314                );
     315                $tooltips[] = __( 'Plugin is disabled (updates are active).', 'wporg-plugins' );
     316                $classes[]  = 'profile-plugin-closed';
     317                $note       = true;
     318
     319            } else {
     320                // Plugin is some fashion of open.
     321                if ( 'approved' === $plugin->post_status ) {
     322                    $note       = true;
     323                    $tooltips[] = __( 'Plugin is approved, but has no data.', 'wporg-plugins' );
     324                    $classes[]  = 'profile-plugin-open-unused';
     325                } elseif ( strtotime( '-2 years' ) > strtotime( $last_updated ) ) {
     326                    $tooltips[] = __( 'Plugin is open but has not been updated in more than two years.', 'wporg-plugins' );
     327                    $classes[]  = 'profile-plugin-open-old';
     328                } else {
     329                    $tooltips[] = __( 'Plugin is open.', 'wporg-plugins' );
     330                }
     331                $classes[] = 'profile-plugin-open';
     332            }
     333
     334            echo '<span>';
     335
     336            printf(
     337                '<a class="%1$s" title="%2$s" href="%3$s">%4$s</a>',
     338                esc_attr( implode( ' ', $classes ) ),
     339                esc_attr( implode( ' ', $tooltips ) ),
     340                esc_attr( get_permalink( $plugin ) ),
     341                $plugin->post_name
     342            );
     343
     344            if ( $note ) {
     345                echo '*';
     346            }
     347
     348            vprintf( '<span class="profile-sp-link">[ %s | %s | %s ]</span>', [
     349                sprintf(
     350                    '<a href="%s" title="%s">%s</a>',
     351                    esc_url( get_edit_post_link( $plugin->ID, '' ) ),
     352                    esc_attr__( 'Edit this plugin', 'wporg-plugins' ),
     353                    __( 'Edit', 'wporg-plugins' )
     354                ),
     355                sprintf(
     356                    '<a href="//make.wordpress.org/pluginrepo/?s=%s" title="%s">P2</a>',
     357                    urlencode( esc_attr( $plugin_slug ) ),
     358                    esc_attr__( 'Click to search Plugin Team P2 for mentions of this plugin', 'wporg-plugins' )
     359                ),
     360                sprintf(
     361                    '<a href="https://supportpress.wordpress.org/plugins/?q=%s&status=&todo=Search+%%C2%%BB" title="%s">SP</a>',
     362                    urlencode( esc_attr( $plugin_slug ) ),
     363                    esc_attr__( 'Click to search Plugin SupportPress for mentions of this plugin', 'wporg-plugins' )
     364                ),
     365            ] );
     366
     367            if ( $extra ) {
     368                echo ' ' . $extra;
     369            }
     370
     371            echo '</span></li>' . "\n";
     372        }
     373    }
    344374}
Note: See TracChangeset for help on using the changeset viewer.