ID ); $none = __( 'not given', 'spotsend' ); $rows = array( __( 'Received', 'spotsend' ) => get_the_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $post ), __( 'Categories', 'spotsend' ) => $report['categories'] ? implode( ', ', $report['categories'] ) : '', __( 'Description', 'spotsend' ) => $report['description'], __( 'Reported by', 'spotsend' ) => $report['reporter'], ); echo '
| %s | %s |
|---|---|
| %s | %s, %s |
| %s | ', esc_html__( 'Photos', 'spotsend' ) );
foreach ( $report['photos'] as $photo ) {
printf( '%s', esc_url( (string) wp_get_attachment_url( $photo ) ), wp_get_attachment_image( $photo, 'medium' ) );
}
echo ' |
| %s | %s |
' . esc_html( done_label() . $day ) . '
'; } else { printf( '', esc_url( resolve_url( $post->ID ) ), esc_html( resolve_label() ) ); } } function resolve_url( int $report_id ): string { return wp_nonce_url( admin_url( 'admin-post.php?action=raplace_resolve&report=' . $report_id ), 'raplace_resolve_' . $report_id ); } /** * Text of the resolve action: the setting, or "Mark as resolved". The * `spotsend_resolve_label` filter has the last word. */ function resolve_label(): string { $label = (string) setting( 'action_label' ); return (string) apply_filters( 'spotsend_resolve_label', '' !== $label ? $label : __( 'Mark as resolved', 'spotsend' ) ); } add_filter( 'post_row_actions', static function ( $actions, $post ) { if ( POST_TYPE === $post->post_type && 'publish' !== $post->post_status ) { $actions['raplace_resolve'] = sprintf( '%s', esc_url( resolve_url( $post->ID ) ), esc_html( resolve_label() ) ); } return $actions; }, 10, 2 ); add_action( 'admin_post_raplace_resolve', static function () { $report_id = absint( $_GET['report'] ?? 0 ); check_admin_referer( 'raplace_resolve_' . $report_id ); if ( POST_TYPE !== get_post_type( $report_id ) || ! current_user_can( 'edit_post', $report_id ) ) { wp_die( esc_html__( 'You are not allowed to resolve this report.', 'spotsend' ) ); } wp_update_post( array( 'ID' => $report_id, 'post_status' => 'publish', ) ); /** * Fires when a report is marked resolved, before the redirect back to the list. * A handler may redirect elsewhere and exit, for example to a record it created. * * @param int $report_id The resolved report. */ do_action( 'spotsend_resolved', $report_id ); wp_safe_redirect( admin_url( 'edit.php?post_type=' . POST_TYPE . '&raplace_resolved=1' ) ); exit; } ); add_action( 'admin_notices', static function () { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- a display flag only. if ( isset( $_GET['raplace_resolved'] ) ) { /* translators: %s: what a resolved report is called, e.g. "Resolved" */ echo '' . esc_html( sprintf( __( 'Report status changed to "%s".', 'spotsend' ), done_label() ) ) . '