Making WordPress.org

Changeset 4301


Ignore:
Timestamp:
10/27/2016 06:31:28 AM (7 years ago)
Author:
dd32
Message:

Plugin Directory: Add plugin committer management to the new plugin admin.

See #2111.

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

Legend:

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

    r4125 r4301  
    2121        new Routes\SVN_Access();
    2222        new Routes\Zip_Management();
     23        new Routes\Plugin_Committers();
    2324    }
    2425
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-committers.php

    r4278 r4301  
    3939        <style>
    4040            <?php // TODO: Yes, these need to be moved into the CSS somewhere. ?>
    41             h3 a.addnew:before {
    42                 content: '+';
    43             }
    4441            ul.committer-list {
    4542                list-style: none;
     
    5350            ul.committer-list a.remove {
    5451                color: red;
     52                cursor: pointer;
    5553                visibility: hidden;
    5654            }
     
    5957            }
    6058        </style>
    61         <h3><?php _e( 'Committers', 'wporg-plugins' ); ?> <a href="#" class="addnew"><?php _e( 'Add', 'wporg-plugins' ); ?></button></h3>
     59
     60        <h3><?php _e( 'Committers', 'wporg-plugins' ); ?></h3>
    6261
    6362        <ul class="committer-list">
    6463        <?php foreach ( $committers as $committer ) {
    65             echo '<li>' .
     64            echo '<li data-user="' . esc_attr( $committer->user_nicename ) . '">' .
    6665                get_avatar( $committer->ID, 32 ) .
    6766                '<a href="' . esc_url( 'https://profiles.wordpress.org/' . $committer->user_nicename ) . '">' . Template::encode( $committer->display_name ) . '</a>' .
    68                 '<br><small>' . esc_html( $committer->user_email ) . ' ' .
    69                 '<a href="#" class="remove">' . __( 'Remove', 'wporg-plugins' ) . '</a>' .
     67                '<br><small>' .
     68                ( current_user_can( 'plugin_review' ) ? esc_html( $committer->user_email ) . ' ' : '' ) .
     69                '<a class="remove">' . __( 'Remove', 'wporg-plugins' ) . '</a>' .
    7070                '</small>' .
    7171                '</li>';
    7272        } ?>
     73        <li class="new" data-template="<?php echo esc_attr( '<li><img src="" class="avatar avatar-32 photo" height="32" width="32"><a class="profile" href=""></a><br><small><span class="email"></span> <a class="remove">' . __( 'Remove', 'wporg-plugins' ) . '</a></small></li>' ); ?>">
     74            <input type="text" name="committer" placeholder="<?php esc_attr_e( 'Login, Slug, or Email.', 'wporg-plugins' ); ?>">
     75            <input type="submit" value="<?php esc_attr_e( 'Add', 'wporg-plugins' ); ?>">
     76        </li>
     77
    7378        </ul>
     79        <script>
     80            var rest_api_url = <?php echo wp_json_encode( get_rest_url() ); ?>,
     81                rest_api_nonce = <?php echo wp_json_encode( wp_create_nonce( 'wp_rest' ) ); ?>,
     82                plugin_slug = <?php echo wp_json_encode( $post->post_name ); ?>;
    7483
     84        jQuery( 'ul.committer-list' ).on( 'click', 'a.remove', function(e) {
     85            e.preventDefault();
     86
     87            var $this = jQuery( this ),
     88                $row = $this.parents('li'),
     89                user_nicename = $row.data( 'user' ),
     90                url = rest_api_url + 'plugins/v1/plugin/' + plugin_slug + '/committers/' + user_nicename + '/?_wpnonce=' + rest_api_nonce;
     91
     92            jQuery.post({
     93                url: url,
     94                method: 'DELETE',
     95            }).success( function( result ) {
     96                if ( true === result ) {
     97                    $row.slideUp( 500, function() {
     98                        $row.remove();
     99                    } );
     100                } else {
     101                    alert( result.messsage );
     102                }
     103            } ).fail( function( result ) {
     104                result = jQuery.parseJSON( result.responseText );
     105                if ( typeof result.message !== undefined ) {
     106                    alert( result.message );
     107                }
     108            } );
     109        } );
     110
     111        jQuery( 'ul.committer-list' ).on( 'click', 'li.new input[type="submit"]', function(e) {
     112            e.preventDefault();
     113
     114            var $this = jQuery( this ),
     115                $row = $this.parents('li'),
     116                $list = $row.parents('ul'),
     117                $new_user_input = $row.find( 'input[name="committer"]' ),
     118                user_to_add = $new_user_input.val(),
     119                url = rest_api_url + 'plugins/v1/plugin/' + plugin_slug + '/committers/?_wpnonce=' + rest_api_nonce;
     120
     121            jQuery.post({
     122                url: url,
     123                dataType: 'json',
     124                data: {
     125                    committer: user_to_add
     126                }
     127            }).done( function( result ) {
     128                if ( typeof result.name !== "undefined" ) {
     129                    $newrow = jQuery( $row.data('template') );
     130                    $newrow.data('user', result.nicename );
     131                    $newrow.find('img').attr( 'src', result.avatar );
     132                    $newrow.find('a.profile').attr('href', result.profile ).html( result.name );
     133                    if ( typeof result.email !== "undefined" ) {
     134                        $newrow.find('span.email').text( result.email );
     135                    }
     136                    $row.before( $newrow );
     137                    $new_user_input.val('');
     138                } else {
     139                    alert( result.messsage );
     140                }
     141            } ).fail( function( result ) {
     142                result = jQuery.parseJSON( result.responseText );
     143                if ( typeof result.message !== undefined ) {
     144                    alert( result.message );
     145                }
     146            } );
     147        } );
     148           
     149        </script>
    75150
    76151        <?php
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-contributors.php

    r4278 r4301  
    2929        $post = get_post();
    3030
    31         $contributors = (array) wp_list_pluck( (array)get_the_terms( $post, 'plugin_contributors' ), 'name' );
    32         $contributors = array_map( function( $user_nicename ) {
    33             return get_user_by( 'slug', $user_nicename );
    34         }, $contributors );
     31        if ( $contributors = get_the_terms( $post, 'plugin_contributors' ) ) {
     32            $contributors = (array) wp_list_pluck( $contributors, 'name' );
     33            $contributors = array_map( function( $user_nicename ) {
     34                return get_user_by( 'slug', $user_nicename );
     35            }, $contributors );
     36        } else {
     37            return;
     38        }
    3539
    3640        echo $args['before_widget'];
Note: See TracChangeset for help on using the changeset viewer.