Skip to content

Commit

Permalink
Deleting guest authors is less confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Hum committed Jun 29, 2017
1 parent 39276d1 commit d404fec
Showing 1 changed file with 45 additions and 16 deletions.
61 changes: 45 additions & 16 deletions php/class-coauthors-guest-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,36 +463,65 @@ function view_guest_authors_list() {
wp_die( esc_html( sprintf( __( "%s can't be deleted because it doesn't exist.", 'co-authors-plus' ), $this->labels['singular'] ) ) );
}

// get post count
global $coauthors_plus;
$term = $coauthors_plus->get_author_term( $guest_author );
if ( $term ) {
$count = $term->count;
} else {
$count = 0;
}

echo '<div class="wrap">';
echo '<div class="icon32" id="icon-users"><br/></div>';
echo '<h2>' . esc_html( sprintf( __( 'Delete %s', 'co-authors-plus ' ), $this->labels['plural'] ) ) . '</h2>';
echo '<p>' . esc_html( sprintf( __( 'You have specified this %s for deletion:', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '</p>';
echo '<p>#' . esc_html( $guest_author->ID . ': ' . $guest_author->display_name ) . '</p>';
echo '<p>' . esc_html( sprintf( __( 'What should be done with posts assigned to this %s?', 'co-authors-plus' ), strtolower( $this->labels['singular'] ) ) ) . '</p>';
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>';

if ( $count === 0 ) {
$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>';
}
else if ( $count === 1 ) {
$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>';
}
else {
$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>';
}
echo $post_count_message;
if ( $count > 0 ) {
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>';
}
echo '<form method="POST" action="' . esc_url( add_query_arg( 'page', 'view-guest-authors', admin_url( $this->parent_page ) ) ) . '">';
// Hidden stuffs
echo '<input type="hidden" name="action" value="delete-guest-author" />';
wp_nonce_field( 'delete-guest-author' );
echo '<input type="hidden" id="id" name="id" value="' . esc_attr( (int) $_GET['id'] ) . '" />';
echo '<fieldset><ul style="list-style-type:none;">';
// Reassign to another user
echo '<li class="hide-if-no-js"><label for="reassign-another">';
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>';
echo '<input type="hidden" id="leave-assigned-to" name="leave-assigned-to" style="width:200px;" />';
echo '</li>';
// Leave mapped to a linked account
if ( get_user_by( 'login', $guest_author->linked_account ) ) {
echo '<li><label for="leave-assigned">';
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 );
echo '</label></li>';
if ( $count > 0 ) {
echo '<li class="hide-if-no-js"><label for="reassign-another">';
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>';
echo '<input type="hidden" id="leave-assigned-to" name="leave-assigned-to" style="width:200px;" />';
echo '</li>';
// Leave mapped to a linked account
if ( get_user_by( 'login', $guest_author->linked_account ) ) {
echo '<li><label for="leave-assigned">';
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 ) );
echo '</label></li>';
}
// Remove bylines from the posts
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' );
}
else {
echo '<input type="hidden" id="remove-byline" class="reassign-option" name="reassign" value="remove-byline" checked="checked"/>';
}
// Remove bylines from the posts
echo '<li><label for="remove-byline">';
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' );
echo '</label></li>';
echo '</ul></fieldset>';
submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true, array( 'disabled' => 'disabled' ) );
if ( $count === 0 ) {
submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true );
}
else {
submit_button( __( 'Confirm Deletion', 'co-authors-plus' ), 'secondary', 'submit', true, array( 'disabled' => 'disabled' ) );
}
echo '</form>';
echo '</div>';
} else {
Expand Down

1 comment on commit d404fec

@paulschreiber
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to run this through PHPCS, adding Yoda conditions and inlining } else { statements to make the rest of the code.

Please sign in to comment.