Making WordPress.org

Changeset 9702


Ignore:
Timestamp:
04/06/2020 06:55:34 AM (4 years ago)
Author:
dd32
Message:

Plugin Directory: Introduce a 'Transfer This Plugin' form to reassign ownership of a plugin to another committer.

This does not remove the old owners commit rights, only transfers the ownership of it. The committer may choose to remove their commit rights afterwards.

Fixes #5131.

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

Legend:

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

    r9672 r9702  
    3333        new Routes\Plugin_Support_Reps();
    3434        new Routes\Plugin_Self_Close();
     35        new Routes\Plugin_Self_Transfer();
    3536    }
    3637
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-self-close.php

    r9682 r9702  
    77
    88/**
    9  * An API endpoint for favoriting a particular plugin.
     9 * An API endpoint for closing a particular plugin.
    1010 *
    1111 * @package WordPressdotorg_Plugin_Directory
     
    7575        // Add an audit-log entry as to why this has happened.
    7676        Tools::audit_log(
    77             $plugin,
    78             sprintf( 'Plugin closed. Reason: Author Self-close Request from %s', $_SERVER['REMOTE_ADDR'] )
     77            sprintf( 'Plugin closed. Reason: Author Self-close Request from %s', $_SERVER['REMOTE_ADDR'] ),
     78            $plugin
    7979        );
    8080
     
    9292The WordPress Plugin Directory Team
    9393https://make.wordpress.org/plugins', 'wporg-plugins' ),
    94             $user->display_name,
     94            wp_get_current_user()->display_name,
    9595            gmdate( 'Y-m-d H:i:s \G\M\T' ),
    9696            $plugin->post_title,
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r9699 r9702  
    826826
    827827    /**
     828     * Generates a link to self-transfer a plugin..
     829     *
     830     * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     831     * @return string URL to toggle status.
     832     */
     833    public static function get_self_transfer_link( $post = null ) {
     834        $post = get_post( $post );
     835
     836        return add_query_arg(
     837            array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ),
     838            home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-transfer' )
     839        );
     840    }
     841
     842    /**
    828843     * Returns the reasons for closing or disabling a plugin.
    829844     *
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php

    r9698 r9702  
    338338}
    339339
     340/**
     341 * Display a form to allow a plugin owner to transfer the ownership of a plugin to someone else.
     342 * This does NOT remove their commit ability.
     343 */
     344function the_plugin_self_transfer_form() {
     345    $post = get_post();
     346
     347    if (
     348        ! current_user_can( 'plugin_admin_edit', $post ) ||
     349        'publish' != $post->post_status
     350    ) {
     351        return;
     352    }
     353
     354    echo '<h4>' . esc_html__( 'Transfer This Plugin', 'wporg-plugins' ) . '</h4>';
     355
     356    if ( get_current_user_id() != $post->post_author ) {
     357        $owner = get_user_by( 'id', $post->post_author );
     358        /* translators: %s: Name of plugin owner */
     359        echo '<p>' . esc_html( sprintf(
     360            __( 'This plugin is currently owned by %s, they can choose to transfer ownership rights of the plugin to you.', 'wporg-plugins' ),
     361            $owner->display_name
     362        ) ) . '</p>';
     363        return;
     364    }
     365
     366    echo '<p>' . esc_html__( 'You are the current owner of this plugin, but you can transfer those rights to another person at any time. The new owner must be added as a committer first.', 'wporg-plugins' ) . '</p>';
     367
     368    echo '<div class="plugin-notice notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> Transferring a plugin is intended to be <em>permanent</em>. There is no way to get plugin ownership back unless it has been done maliciously.', 'wporg-plugins' ) . '</p></div>';
     369
     370    $users = [];
     371    foreach ( Tools::get_plugin_committers( $post->post_name ) as $user_login ) {
     372        $user = get_user_by( 'login', $user_login );
     373        if ( $user->ID != get_current_user_id() ) {
     374            $users[] = $user;
     375        }
     376    }
     377    if ( ! $users ) {
     378        echo '<div class="plugin-notice notice notice-error notice-alt"><p>' . __( 'To transfer a plugin, you must first add the new owner as a committer.', 'wporg-plugins' ) . '</p></div>';
     379        return;
     380    }
     381
     382    echo '<form method="POST" action="' . esc_url( Template::get_self_transfer_link() ) . '">';
     383    echo '<p><label for="new_owner">' . esc_html__( 'New Owner', 'wporg-plugins' ) . '</label><br>';
     384    echo '<select name="new_owner">';
     385    foreach ( $users as $user ) {
     386        printf(
     387            '<option value="%d">%s</option>' . "\n",
     388            esc_attr( $user->ID ),
     389            esc_html( $user->display_name . ' (' . $user->user_login . ')' )
     390        );
     391    }
     392    echo '</select></p>';
     393    // Translators: %s is the plugin name, as defined by the plugin itself.
     394    echo '<p><input class="button" type="submit" value="' . esc_attr( sprintf( __( 'Please transfer %s.', 'wporg-plugins' ), get_the_title() ) ) . '" /></p>';
     395    echo '</form>';
     396
     397}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section-advanced.php

    r9698 r9702  
    5050    <div class="plugin-notice notice notice-error notice-alt"><p><?php esc_html_e( 'These features often cannot be undone without intervention. Please do not attempt to use them unless you are absolutely certain. When in doubt, contact the plugins team for assistance.', 'wporg-plugins' ); ?></p></div>
    5151
     52    <?php the_plugin_self_transfer_form(); ?>
     53
    5254    <?php the_plugin_self_close_button(); ?>
     55
    5356</div>
Note: See TracChangeset for help on using the changeset viewer.