Making WordPress.org


Ignore:
Timestamp:
08/28/2020 05:36:38 AM (4 years ago)
Author:
dd32
Message:

Plugin Directory: Add an initial run at Release Confirmation for plugins.

This is currently only enabled for plugin review members, as it needs some testing in production prior to being available to others.

Notably, this requires that a plugin be using tagged releases, it doesn't handle trunk releases (yet), that will be added next.

See: #5352

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php

    r9989 r10214  
    1010namespace WordPressdotorg\Plugin_Directory\Theme;
    1111
     12use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    1213use WordPressdotorg\Plugin_Directory\Template;
    1314use WordPressdotorg\Plugin_Directory\Tools;
     
    260261}
    261262
     263function the_unconfirmed_releases_notice() {
     264    $plugin = get_post();
     265
     266    if ( ! $plugin->release_confirmation || ! current_user_can( 'plugin_admin_edit', $plugin ) ) {
     267        return;
     268    }
     269
     270    $confirmations_required = $plugin->release_confirmation;
     271    $releases               = Plugin_Directory::get_releases( $plugin ) ?: [];
     272    $unconfirmed_releases   = wp_list_filter( $confirmed_releases, [ 'confirmed' => false ] );
     273
     274    if ( ! $unconfirmed_releases ) {
     275        return;
     276    }
     277
     278    printf(
     279        '<div class="plugin-notice notice notice-info notice-alt"><p>%s</p></div>',
     280        sprintf(
     281            __( 'This plugin has <a href="%s">a pending release that requires confirmation</a>.', 'wporg-plugins' ),
     282            home_url( '/developers/releases/' ) // TODO: Hardcoded URL.
     283        )
     284    );
     285}
     286
    262287/**
    263288 * Display the ADVANCED Zone.
     
    346371
    347372    echo '<div class="plugin-notice notice notice-error notice-alt"><p>' . esc_html__( '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>';
     373
     374    // Output the Release Confirmation form.
     375    the_plugin_release_confirmation_form();
    348376
    349377    // Output the transfer form.
     
    453481
    454482}
     483
     484function the_plugin_release_confirmation_form() {
     485    $post = get_post();
     486
     487    // Temporary: Plugin Reviewers only.
     488    if ( ! current_user_can( 'edit_post', $post ) ) {
     489        return;
     490    }
     491
     492    if (
     493        ! current_user_can( 'plugin_admin_edit', $post ) ||
     494        'publish' != $post->post_status
     495    ) {
     496        return;
     497    }
     498
     499    $confirmations_required = $post->release_confirmation;
     500
     501    echo '<h4>' . esc_html__( 'Release Confirmation', 'wporg-plugins' ) . '</h4>';
     502    if ( $confirmations_required ) {
     503        echo '<p>' . __( 'Release confirmations for this plugin are <strong>enabled</strong>.', 'wporg-plugins' ) . '</p>';
     504    } else {
     505        echo '<p>' . __( 'Release confirmations for this plugin are <strong>disabled</strong>', 'wporg-plugins' ) . '</p>';
     506    }
     507    echo '<p>' . esc_html__( 'All future releases will require email confirmation before being made available. This increases security and ensures that plugin releases are only made when intended.', 'wporg-plugins' ) . '</p>';
     508
     509    if ( ! $confirmations_required && 'trunk' === $post->stable_tag ) {
     510        echo '<div class="plugin-notice notice notice-warning notice-alt"><p>';
     511            _e( "Release confirmations currently require tagged releases, as you're releasing from trunk they cannot be enabled.", 'wporg-plugins' );
     512        echo '</p></div>';
     513
     514    } else if ( ! $confirmations_required ) {
     515        echo '<div class="plugin-notice notice notice-warning notice-alt"><p>';
     516            _e( '<strong>Warning:</strong> Enabling release confirmations is intended to be a <em>permanent</em> action. There is no way to disable this without contacting the plugins team.', 'wporg-plugins' );
     517        echo '</p></div>';
     518
     519        echo '<form method="POST" action="' . esc_url( Template::get_enable_release_confirmation_link() ) . '" onsubmit="return confirm( jQuery(this).prev(\'.notice\').text() );">';
     520        echo '<p><input class="button" type="submit" value="' . esc_attr__( 'I understand, please enable release confirmations.', 'wporg-plugins' ) . '" /></p>';
     521        echo '</form>';
     522
     523    } else {
     524        /* translators: 1: plugins@wordpress.org */
     525        echo '<p>' . sprintf( __( 'To disable release confirmations, please contact the plugins team by emailing %s.', 'wporg-plugins' ), 'plugins@wordpress.org' ) . '</p>';
     526    }
     527}
Note: See TracChangeset for help on using the changeset viewer.