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 ''; foreach ( $rows as $label => $value ) { printf( '', esc_html( $label ), nl2br( esc_html( '' !== $value ? $value : $none ) ) ); } if ( '' !== $report['lat'] ) { printf( '', esc_html__( 'Coordinates', 'spotsend' ), esc_url( map_link( $report['lat'], $report['lng'] ) ), esc_html( $report['lat'] ), esc_html( $report['lng'] ) ); } if ( $report['photos'] ) { printf( ''; } if ( '' !== $report['email'] ) { printf( '', esc_html__( 'Email', 'spotsend' ), esc_attr( $report['email'] ), esc_html( $report['email'] ) ); } echo ''; if ( $report['resolved'] ) { $day = '' !== $report['resolved_on'] ? ', ' . mysql2date( get_option( 'date_format' ), $report['resolved_on'] ) : ''; echo '

' . esc_html( done_label() . $day ) . '

'; } else { printf( '

%s

', 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() ) ) . '

'; } } ); add_filter( 'manage_' . POST_TYPE . '_posts_columns', static fn( $cols ) => array( 'cb' => $cols['cb'], 'title' => __( 'Place', 'spotsend' ), 'raplace_categories' => __( 'Categories', 'spotsend' ), 'raplace_reporter' => __( 'Reported by', 'spotsend' ), 'raplace_photo' => __( 'Photos', 'spotsend' ), 'raplace_state' => __( 'Status', 'spotsend' ), 'date' => $cols['date'], ) ); add_action( 'manage_' . POST_TYPE . '_posts_custom_column', static function ( $col, $post_id ) { $report = get_report( $post_id ); switch ( $col ) { case 'raplace_categories': echo esc_html( implode( ', ', $report['categories'] ) ); break; case 'raplace_reporter': echo esc_html( $report['reporter'] ); if ( '' !== $report['email'] ) { echo ( '' !== $report['reporter'] ? '
' : '' ) . esc_html( $report['email'] ); } break; case 'raplace_photo': if ( $report['photo'] ) { echo wp_get_attachment_image( $report['photo'], array( 60, 60 ) ); } if ( count( $report['photos'] ) > 1 ) { echo ' +' . (int) ( count( $report['photos'] ) - 1 ); } break; case 'raplace_state': echo esc_html( $report['resolved'] ? done_label() : __( 'Waiting', 'spotsend' ) ); break; } }, 10, 2 ); // Waiting reports counted on the menu item, like pending comments. add_action( 'admin_menu', static function () { global $menu; $pending = (int) ( wp_count_posts( POST_TYPE )->pending ?? 0 ); if ( ! $pending ) { return; } foreach ( $menu as $i => $item ) { if ( 'edit.php?post_type=' . POST_TYPE === ( $item[2] ?? '' ) ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- appending the count badge. $menu[ $i ][0] .= ' ' . $pending . ''; } } }, 99 );