| 1 |
<?php |
| 2 |
/** |
| 3 |
* Remove duplicates from the database |
| 4 |
* |
| 5 |
* @package Friends |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Friends; |
| 9 |
|
| 10 |
?> |
| 11 |
<h2><?php esc_html_e( 'Duplicates', 'friends' ); ?></h2> |
| 12 |
<form method="post"> |
| 13 |
<p> |
| 14 |
<?php |
| 15 |
|
| 16 |
$duplicate_count = 0; |
| 17 |
foreach ( $args['friend_posts']->get_posts() as $_post ) { |
| 18 |
if ( ! isset( $args['uniques'][ $_post->ID ] ) ) { |
| 19 |
++$duplicate_count; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
echo esc_html( |
| 24 |
sprintf( |
| 25 |
// translators: %d is the number of duplicates. |
| 26 |
_n( '%d post was identified as aduplicate.', '%d posts were identified as duplicate.', $duplicate_count, 'friends' ), |
| 27 |
$duplicate_count |
| 28 |
) |
| 29 |
); |
| 30 |
echo ' '; |
| 31 |
esc_html_e( 'You can check or uncheck the posts before you click the button to delete them.', 'friends' ); |
| 32 |
?> |
| 33 |
|
| 34 |
</p> |
| 35 |
<p> |
| 36 |
<button type="submit" class="button button-primary"><?php esc_html_e( 'Delete selected duplicates', 'friends' ); ?></button> |
| 37 |
</p> |
| 38 |
<table class="wp-list-table widefat fixed striped" style="margin-top: 2em; margin-bottom: 2em; margin-right: 1em"> |
| 39 |
<tbody> |
| 40 |
<tr> |
| 41 |
<th class="check-column"></th> |
| 42 |
<th class="column-primary column-title"><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Title' ); ?></th> |
| 43 |
<th class="column-primary column-date"><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Date' ); ?></th> |
| 44 |
</tr> |
| 45 |
<?php |
| 46 |
foreach ( $args['friend_posts']->get_posts() as $_post ) { |
| 47 |
$_title = get_the_title( $_post ); |
| 48 |
if ( empty( $_title ) ) { |
| 49 |
$_title = wp_trim_words( get_the_excerpt( $_post ), 10 ); |
| 50 |
} |
| 51 |
|
| 52 |
?> |
| 53 |
<tr> |
| 54 |
<td class="duplicate"><input type="checkbox" name="deleteduplicate[<?php echo esc_attr( $_post->ID ); ?>]" <?php checked( ! isset( $args['uniques'][ $_post->ID ] ) ); ?>></td> |
| 55 |
<td class="title column-title column-primary" data-colname="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_attr_e( 'Title' ); ?>"> |
| 56 |
<?php |
| 57 |
// show the post format as a label. |
| 58 |
$post_format = get_post_format( $_post ); |
| 59 |
if ( ! empty( $post_format ) ) { |
| 60 |
?> |
| 61 |
<span class="post-format-icon post-format-<?php echo esc_attr( $post_format ); ?>" title="<?php echo esc_attr( get_post_format_string( $post_format ) ); ?>"></span> |
| 62 |
<?php |
| 63 |
} |
| 64 |
?> |
| 65 |
<a href="<?php the_permalink( $_post ); ?>" rel="noopener noreferrer"><?php echo esc_html( $_title ); ?></a> |
| 66 |
</td> |
| 67 |
<td class="date column-date" data-colname="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_attr_e( 'Date' ); ?>"><?php echo esc_html( date_i18n( __( 'F j, Y g:i a' ), strtotime( $_post->post_date ) ) ); ?></td> |
| 68 |
</tr> |
| 69 |
<?php |
| 70 |
} |
| 71 |
?> |
| 72 |
</tbody> |
| 73 |
</table> |
| 74 |
<button type="submit" class="button button-primary"><?php esc_html_e( 'Delete selected duplicates', 'friends' ); ?></button> |
| 75 |
|
| 76 |
</form> |
| 77 |
|