Making WordPress.org

Changeset 13931


Ignore:
Timestamp:
07/26/2024 04:56:43 AM (2 years 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.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
2 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}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/inc/template-tags.php

    r13728 r13931  
    1414use WordPressdotorg\Plugin_Directory\Template;
    1515use WordPressdotorg\Plugin_Directory\Tools;
     16use WordPressdotorg\Plugin_Directory\Shortcodes\Release_Confirmation;
    1617
    1718/**
     
    258259
    259260function the_unconfirmed_releases_notice() {
    260         $plugin = get_post();
    261 
    262         if ( ! $plugin->release_confirmation || ! current_user_can( 'plugin_admin_edit', $plugin ) ) {
    263                 return;
    264         }
    265 
    266         $releases = Plugin_Directory::get_releases( $plugin ) ?: [];
    267         $warning  = false;
    268 
    269         foreach ( $releases as $release ) {
    270                 if ( ! $release['confirmed'] && $release['confirmations_required'] && empty( $release['discarded'] ) ) {
    271                         $warning = true;
    272                         break;
    273                 }
    274         }
    275 
    276         if ( ! $warning ) {
    277                 return;
    278         }
    279 
    280         printf(
    281                 '<div class="plugin-notice notice notice-info notice-alt"><p>%s</p></div>',
    282                 sprintf(
    283                         __( 'This plugin has <a href="%s">a pending release that requires confirmation</a>.', 'wporg-plugins' ),
    284                         home_url( '/developers/releases/' ) // TODO: Hardcoded URL.
    285                 )
    286         );
     261        return Release_Confirmation::frontend_unconfirmed_releases_notice();
    287262}
    288263
Note: See TracChangeset for help on using the changeset viewer.