> $tabs Tools tabs. * @return array> */ public function add_tab( array $tabs ): array { if ( ! current_user_can( self::CAP ) ) { return $tabs; } $tabs[ self::TAB ] = array( 'label' => __( 'Duplicate Posts', 'all-in-one-utilities' ), 'description' => __( 'Find posts that share a title with another post of the same type, and move the extra copies to the Trash.', 'all-in-one-utilities' ), 'tips' => array( __( 'Which posts count as duplicates, and which copy is kept, follows the matching rules in Settings → Duplicate Posts.', 'all-in-one-utilities' ), __( 'Nothing is removed until you tick the pairs and confirm; removed posts go to the Trash, where they can be restored.', 'all-in-one-utilities' ), ), 'priority' => 16, 'owner' => 'free', ); return $tabs; } /** * Send the old submenu page's address to the tab, keeping its page * number. * * @return void */ public function redirect_legacy_page(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only redirect. if ( ! isset( $_GET['page'] ) || self::LEGACY_PAGE !== $_GET['page'] || ! current_user_can( self::CAP ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only redirect. $paged = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 0; $url = ToolsScreen::url( self::TAB ); wp_safe_redirect( $paged > 1 ? add_query_arg( 'paged', $paged, $url ) : $url ); exit; } /** * Render the screen. * * @return void */ public function render(): void { if ( ! current_user_can( self::CAP ) ) { return; } $notice = get_transient( 'aiou_duplicate_posts_notice_' . get_current_user_id() ); delete_transient( 'aiou_duplicate_posts_notice_' . get_current_user_id() ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only pagination. $paged = isset( $_GET['paged'] ) ? max( 1, absint( $_GET['paged'] ) ) : 1; $total = DuplicateFinder::count(); $total_pages = (int) ceil( $total / self::PER_PAGE ); $pairs = $total > 0 ? DuplicateFinder::find_pairs( self::PER_PAGE, ( $paged - 1 ) * self::PER_PAGE ) : array(); ?>

1 ) : ?>
pagination_links( $paged, $total_pages ); ?>
#
meta_line( $pair['date'], $pair['author'] ) ); ?>
post_title : $pair['title'] ); ?> #
meta_line( $keeper->post_date, get_the_author_meta( 'display_name', (int) $keeper->post_author ) ) ); ?>

add_query_arg( 'paged', '%#%', ToolsScreen::url( self::TAB ) ), 'format' => '', 'current' => $paged, 'total' => $total_pages, 'type' => 'plain', ) ); if ( $links ) { echo '
' . $links . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- paginate_links() output is already escaped. } } /** * Handle the "Move selected to Trash" bulk action. * * @return void */ public function handle_delete(): void { if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'all-in-one-utilities' ), '', array( 'response' => 403 ) ); } check_admin_referer( 'aiou-duplicate-posts-delete' ); $redirect = wp_get_referer(); $redirect = $redirect ? $redirect : ToolsScreen::url( self::TAB ); $raw_pairs = isset( $_POST['pairs'] ) ? (array) wp_unslash( $_POST['pairs'] ) : array(); if ( empty( $raw_pairs ) ) { $this->notice( $redirect, 'error', __( 'No duplicates were selected.', 'all-in-one-utilities' ) ); } $removed = 0; foreach ( $raw_pairs as $raw_pair ) { $parts = explode( '|', (string) $raw_pair ); if ( 2 !== count( $parts ) ) { continue; } $dupe_id = absint( $parts[0] ); $org_id = absint( $parts[1] ); if ( ! DuplicateFinder::is_valid_pair( $dupe_id, $org_id ) ) { continue; } if ( DuplicateFinder::remove( $dupe_id, DuplicateFinder::force_delete(), $org_id ) ) { ++$removed; } } /* translators: %d: number of duplicates removed */ ( new Feature() )->log( sprintf( __( 'Manually moved %d duplicate(s) to Trash.', 'all-in-one-utilities' ), $removed ) ); /* translators: %d: number of duplicates removed */ $this->notice( $redirect, 'success', sprintf( _n( '%d duplicate moved to Trash.', '%d duplicates moved to Trash.', $removed, 'all-in-one-utilities' ), $removed ) ); } /** * Store a one-time notice and redirect back to the screen. * * @param string $redirect Redirect URL. * @param string $type 'success' or 'error'. * @param string $message Notice text. * @return never */ private function notice( string $redirect, string $type, string $message ) { set_transient( 'aiou_duplicate_posts_notice_' . get_current_user_id(), array( 'type' => $type, 'message' => $message, ), MINUTE_IN_SECONDS ); wp_safe_redirect( $redirect ); exit; } }