Making WordPress.org


Ignore:
Timestamp:
04/06/2020 06:55:34 AM (6 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.