Skip to content

Commit

Permalink
Plugin Directory: Release Confirmation: Move the front-end notice log…
Browse files Browse the repository at this point in the history
…ic from the theme to the Shortcode.

See #344.
See #7704.


git-svn-id: https://meta.svn.wordpress.org/sites/trunk@13931 74240141-8908-4e6f-9713-ba540dce6ec7
  • Loading branch information
dd32 committed Jul 26, 2024
1 parent e13c5e1 commit bec5b5c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,12 @@ static function get_actions( $plugin, $data ) {
}

static function can_access() {
// Plugin reviewers can always access the release management functionality.
if ( current_user_can( 'plugin_review' ) ) {
if ( ! is_user_logged_in() ) {
return false;
}

// Plugin reviewers can always access the release management functionality, in wp-admin.
if ( current_user_can( 'plugin_review' ) && is_admin() ) {
return true;
}

Expand Down Expand Up @@ -358,4 +362,40 @@ static function template_redirect() {
// A page with this shortcode has no need to be indexed.
add_filter( 'wporg_noindex_request', '__return_true' );
}

/**
* Displays the notice on the plugin front-end.
*
* @param WP_Post $post The currently displayed post.
* @return void
*/
static function frontend_unconfirmed_releases_notice( $post = null ) {
$post = get_post( $post );

if ( ! $post->release_confirmation || ! current_user_can( 'plugin_admin_edit', $post ) ) {
return;
}

$releases = Plugin_Directory::get_releases( $post ) ?: [];
$warning = false;

foreach ( $releases as $release ) {
if ( ! $release['confirmed'] && $release['confirmations_required'] && empty( $release['discarded'] ) ) {
$warning = true;
break;
}
}

if ( ! $warning ) {
return;
}

printf(
'<div class="plugin-notice notice notice-info notice-alt"><p>%s</p></div>',
sprintf(
__( 'This plugin has <a href="%s">a pending release that requires confirmation</a>.', 'wporg-plugins' ),
home_url( '/developers/releases/' ) // TODO: Hardcoded URL.
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use WordPressdotorg\Plugin_Directory\Readme\Validator as Readme_Validator;
use WordPressdotorg\Plugin_Directory\Template;
use WordPressdotorg\Plugin_Directory\Tools;
use WordPressdotorg\Plugin_Directory\Shortcodes\Release_Confirmation;

/**
* Returns a list of authors.
Expand Down Expand Up @@ -257,33 +258,7 @@ function get_plugin_status_notice( $post = null ) {
}

function the_unconfirmed_releases_notice() {
$plugin = get_post();

if ( ! $plugin->release_confirmation || ! current_user_can( 'plugin_admin_edit', $plugin ) ) {
return;
}

$releases = Plugin_Directory::get_releases( $plugin ) ?: [];
$warning = false;

foreach ( $releases as $release ) {
if ( ! $release['confirmed'] && $release['confirmations_required'] && empty( $release['discarded'] ) ) {
$warning = true;
break;
}
}

if ( ! $warning ) {
return;
}

printf(
'<div class="plugin-notice notice notice-info notice-alt"><p>%s</p></div>',
sprintf(
__( 'This plugin has <a href="%s">a pending release that requires confirmation</a>.', 'wporg-plugins' ),
home_url( '/developers/releases/' ) // TODO: Hardcoded URL.
)
);
return Release_Confirmation::frontend_unconfirmed_releases_notice();
}

function the_no_self_management_notice() {
Expand Down

0 comments on commit bec5b5c

Please sign in to comment.