__( 'Site name', 'all-in-one-utilities' ), 'summary' => __( 'What happened, e.g. "3 duplicate(s) removed"', 'all-in-one-utilities' ), 'count' => __( 'Number of duplicates', 'all-in-one-utilities' ), 'post_list' => __( 'List of each duplicate and the post that was kept, with links, followed by a link to review them', 'all-in-one-utilities' ), 'review_url' => __( 'Address of the Tools → Duplicate Posts page', 'all-in-one-utilities' ), ); } /** * {@inheritDoc} */ protected function html_variables(): array { return array( 'post_list' ); } /** * Nothing to hook: the scheduled scan (`Feature`) sends it. * * @return void */ public function register(): void {} /** * Send the report. * * @param array $pairs Duplicates found/removed. * @param bool $deleted Whether this run removed them. * @return bool */ public function send_report( array $pairs, bool $deleted ): bool { $count = count( $pairs ); $summary = $deleted /* translators: %d: number of duplicates */ ? sprintf( _n( '%d duplicate removed', '%d duplicates removed', $count, 'all-in-one-utilities' ), $count ) /* translators: %d: number of duplicates */ : sprintf( _n( '%d duplicate found (report only, nothing was deleted)', '%d duplicates found (report only, nothing was deleted)', $count, 'all-in-one-utilities' ), $count ); $review_url = ToolsScreen::url( AdminPage::TAB ); $items = ''; foreach ( $pairs as $pair ) { $id = (int) $pair['id']; $kept = (int) $pair['org_id']; // A removed post is in the Trash, where its editor won't open: // link to that type's Trash list, where it can be restored. $dupe_url = $deleted ? add_query_arg( array( 'post_status' => 'trash', 'post_type' => get_post_type( $id ) ? get_post_type( $id ) : 'post', ), admin_url( 'edit.php' ) ) : self::edit_url( $id ); $items .= '
  • ' . sprintf( /* translators: 1: linked post title, 2: duplicate post id, 3: linked kept post id */ __( '%1$s (#%2$d) -- kept %3$s', 'all-in-one-utilities' ), '“' . esc_html( (string) $pair['title'] ) . '”', $id, '#' . $kept . '' ) . '
  • '; } $post_list = ''; if ( '' !== $items ) { $post_list = '

    ' . esc_html( $deleted ? __( 'See the activity log in Tools → Duplicate Posts', 'all-in-one-utilities' ) : __( 'Review and remove them in Tools → Duplicate Posts', 'all-in-one-utilities' ) ) . '

    '; } return $this->send( $this->recipients(), array( 'site_name' => wp_specialchars_decode( (string) get_option( 'blogname' ), ENT_QUOTES ), 'summary' => $summary, 'count' => (string) $count, 'post_list' => $post_list, 'review_url' => $review_url, ), array( 'pairs' => $pairs ) ); } /** * A post's edit screen. Built directly rather than with * get_edit_post_link(), which returns nothing when there's no logged-in * user -- as in the cron run that sends this email. * * @param int $post_id Post ID. * @return string */ private static function edit_url( int $post_id ): string { return add_query_arg( array( 'post' => $post_id, 'action' => 'edit', ), admin_url( 'post.php' ) ); } }