Making WordPress.org


Ignore:
Timestamp:
07/26/2024 04:56:43 AM (18 months ago)
Author:
dd32
Message:

Plugin Directory: Release Confirmation: Move the front-end notice logic from the theme to the Shortcode.

See https://github.com/WordPress/wordpress.org/pull/344.
See #7704.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-release-confirmation.php

    r13930 r13931  
    285285
    286286    static function can_access() {
    287         // Plugin reviewers can always access the release management functionality.
    288         if ( current_user_can( 'plugin_review' ) ) {
     287        if ( ! is_user_logged_in() ) {
     288            return false;
     289        }
     290
     291        // Plugin reviewers can always access the release management functionality, in wp-admin.
     292        if ( current_user_can( 'plugin_review' ) && is_admin() ) {
    289293            return true;
    290294        }
     
    359363        add_filter( 'wporg_noindex_request', '__return_true' );
    360364    }
     365
     366    /**
     367     * Displays the notice on the plugin front-end.
     368     *
     369     * @param WP_Post $post The currently displayed post.
     370     * @return void
     371     */
     372    static function frontend_unconfirmed_releases_notice( $post = null ) {
     373        $post = get_post( $post );
     374
     375        if ( ! $post->release_confirmation || ! current_user_can( 'plugin_admin_edit', $post ) ) {
     376            return;
     377        }
     378
     379        $releases = Plugin_Directory::get_releases( $post ) ?: [];
     380        $warning  = false;
     381
     382        foreach ( $releases as $release ) {
     383            if ( ! $release['confirmed'] && $release['confirmations_required'] && empty( $release['discarded'] ) ) {
     384                $warning = true;
     385                break;
     386            }
     387        }
     388
     389        if ( ! $warning ) {
     390            return;
     391        }
     392
     393        printf(
     394            '<div class="plugin-notice notice notice-info notice-alt"><p>%s</p></div>',
     395            sprintf(
     396                __( 'This plugin has <a href="%s">a pending release that requires confirmation</a>.', 'wporg-plugins' ),
     397                home_url( '/developers/releases/' ) // TODO: Hardcoded URL.
     398            )
     399        );
     400    }
    361401}
Note: See TracChangeset for help on using the changeset viewer.