Skip to content

Commit d404fec

Browse files
author
Rebecca Hum
committed
Deleting guest authors is less confusing
1 parent 39276d1 commit d404fec

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

php/class-coauthors-guest-authors.php

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -463,36 +463,65 @@ function view_guest_authors_list() {
463463
wp_die( esc_html( sprintf( __( "%s can't be deleted because it doesn't exist.", 'co-authors-plus' ), $this->labels['singular'] ) ) );
464464
}
465465

466+
// get post count
467+
global $coauthors_plus;
468+
$term = $coauthors_plus->get_author_term( $guest_author );
469+
if ( $term ) {
470+
$count = $term->count;
471+
} else {
472+
$count = 0;
473+
}
474+
466475
echo '<div class="wrap">';
467476
echo '<div class="icon32" id="icon-users"><br/></div>';
468477
echo '<h2>' . esc_html( sprintf( __( 'Delete %s', 'co-authors-plus ' ), $this->labels['plural'] ) ) . '</h2>';
469478
echo '<p>' . esc_html( sprintf( __( 'You have specified this %s for deletion:', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '</p>';
470479
echo '<p>#' . esc_html( $guest_author->ID . ': ' . $guest_author->display_name ) . '</p>';
471-
echo '<p>' . esc_html( sprintf( __( 'What should be done with posts assigned to this %s?', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '</p>';
472-
echo '<p class="description">' . esc_html( sprintf( __( "Note: If you'd like to delete the %s and all of their posts, you should delete their posts first and then come back to delete the %s.", 'co-authors-plus' ), strtolower( $this->labels['singular'] ), strtolower( $this->labels['singular'] ) ) ) . '</p>';
480+
481+
if ( $count === 0 ) {
482+
$post_count_message = '<p>' . esc_html( sprintf( __( 'There are %d posts associated with this guest author.', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '</p>';
483+
}
484+
else if ( $count === 1 ) {
485+
$post_count_message = '<p>' . esc_html( sprintf( __( 'There is %d post associated with this guest author. What should be done with the post assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '</p>';
486+
}
487+
else {
488+
$post_count_message = '<p>' . esc_html( sprintf( __( 'There are %d posts associated with this guest author. What should be done with the posts assigned to this %s?', 'co-authors-plus' ), $count, strtolower( $this->labels['singular'] ) ) ) . '</p>';
489+
}
490+
echo $post_count_message;
491+
if ( $count > 0 ) {
492+
echo '<p class="description">' . esc_html( sprintf( __( "Note: If you'd like to delete the %s and all of their posts, you should delete their posts first and then come back to delete the %s.", 'co-authors-plus' ), strtolower( $this->labels['singular'] ), strtolower( $this->labels['singular'] ) ) ) . '</p>';
493+
}
473494
echo '<form method="POST" action="' . esc_url( add_query_arg( 'page', 'view-guest-authors', admin_url( $this->parent_page ) ) ) . '">';
474495
// Hidden stuffs
475496
echo '<input type="hidden" name="action" value="delete-guest-author" />';
476497
wp_nonce_field( 'delete-guest-author' );
477498
echo '<input type="hidden" id="id" name="id" value="' . esc_attr( (int) $_GET['id'] ) . '" />';
478499
echo '<fieldset><ul style="list-style-type:none;">';
479500
// Reassign to another user
480-
echo '<li class="hide-if-no-js"><label for="reassign-another">';
481-
echo '<input type="radio" id="reassign-another" name="reassign" class="reassign-option" value="reassign-another" />&nbsp;&nbsp;' . esc_html__( 'Reassign to another co-author:', 'co-authors-plus' ) . '&nbsp;&nbsp;</label>';
482-
echo '<input type="hidden" id="leave-assigned-to" name="leave-assigned-to" style="width:200px;" />';
483-
echo '</li>';
484-
// Leave mapped to a linked account
485-
if ( get_user_by( 'login', $guest_author->linked_account ) ) {
486-
echo '<li><label for="leave-assigned">';
487-
echo '<input type="radio" id="leave-assigned" class="reassign-option" name="reassign" value="leave-assigned" />&nbsp;&nbsp;' . esc_html( sprintf( __( 'Leave posts assigned to the mapped user, %s.', 'co-authors-plus' ) ), $guest_author->linked_account );
488-
echo '</label></li>';
501+
if ( $count > 0 ) {
502+
echo '<li class="hide-if-no-js"><label for="reassign-another">';
503+
echo '<input type="radio" id="reassign-another" name="reassign" class="reassign-option" value="reassign-another" />&nbsp;&nbsp;' . esc_html__( 'Reassign to another co-author:', 'co-authors-plus' ) . '&nbsp;&nbsp;</label>';
504+
echo '<input type="hidden" id="leave-assigned-to" name="leave-assigned-to" style="width:200px;" />';
505+
echo '</li>';
506+
// Leave mapped to a linked account
507+
if ( get_user_by( 'login', $guest_author->linked_account ) ) {
508+
echo '<li><label for="leave-assigned">';
509+
echo '<input type="radio" id="leave-assigned" class="reassign-option" name="reassign" value="leave-assigned" />&nbsp;&nbsp;' . esc_html( sprintf( __( 'Leave posts assigned to the mapped user, %s.', 'co-authors-plus' ), $guest_author->linked_account ) );
510+
echo '</label></li>';
511+
}
512+
// Remove bylines from the posts
513+
echo '<input type="radio" id="remove-byline" class="reassign-option" name="reassign" value="remove-byline"/>&nbsp;&nbsp;' . esc_html__( 'Remove byline from posts (but leave each post in its current status).', 'co-authors-plus' );
514+
}
515+
else {
516+
echo '<input type="hidden" id="remove-byline" class="reassign-option" name="reassign" value="remove-byline" checked="checked"/>';
489517
}
490-
// Remove bylines from the posts
491-
echo '<li><label for="remove-byline">';
492-
echo '<input type="radio" id="remove-byline" class="reassign-option" name="reassign" value="remove-byline" />&nbsp;&nbsp;' . esc_html__( 'Remove byline from posts (but leave each post in its current status).', 'co-authors-plus' );
493-
echo '</label></li>';
494518
echo '</ul></fieldset>';
495-
submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true, array( 'disabled' => 'disabled' ) );
519+
if ( $count === 0 ) {
520+
submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true );
521+
}
522+
else {
523+
submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true, array( 'disabled' => 'disabled' ) );
524+
}
496525
echo '</form>';
497526
echo '</div>';
498527
} else {

0 commit comments

Comments
 (0)