post_type ) {
wp_die( esc_html__( 'Invalid attachment ID.', 'robotstxt-mediaaudit' ) );
}
$filename = esc_html( '' !== $post->post_title ? $post->post_title : sprintf( '#%d', $attachment_id ) );
$back_url = admin_url( 'admin.php?page=robotstxt-mediaaudit' );
$index_row = $this->get_index_row( $attachment_id );
echo '
';
echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $filename is already escaped via esc_html() above.
// -----------------------------------------------------------------------
// File Information
// -----------------------------------------------------------------------
echo '
' . esc_html__( 'File Information', 'robotstxt-mediaaudit' ) . '
';
echo '
';
// Thumbnail.
$thumb = wp_get_attachment_image( $attachment_id, 'medium', false, array( 'class' => 'mra-detail-thumb' ) );
if ( $thumb ) {
echo '
' . $thumb . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_get_attachment_image is safe.
}
// -----------------------------------------------------------------------
// Internal Usage
// -----------------------------------------------------------------------
echo '
' . esc_html__( 'Internal Usage', 'robotstxt-mediaaudit' ) . '
';
$usages = MediaListTable::fetch_usages( array( $attachment_id ) );
$context_labels = array(
'featured' => __( 'Featured Image', 'robotstxt-mediaaudit' ),
'content' => __( 'Post Content', 'robotstxt-mediaaudit' ),
'meta' => __( 'Custom Field', 'robotstxt-mediaaudit' ),
);
if ( empty( $usages ) ) {
echo '
' . esc_html__( 'Not used in any post.', 'robotstxt-mediaaudit' ) . '
';
} else {
echo '
';
echo '';
echo '| ' . esc_html__( 'Post', 'robotstxt-mediaaudit' ) . ' | ';
echo '' . esc_html__( 'Type', 'robotstxt-mediaaudit' ) . ' | ';
echo '' . esc_html__( 'Context', 'robotstxt-mediaaudit' ) . ' | ';
echo '' . esc_html__( 'Status', 'robotstxt-mediaaudit' ) . ' | ';
echo '
';
foreach ( $usages as $u ) {
$pid_val = $u['post_id'] ?? null;
$post_id = is_numeric( $pid_val ) ? (int) $pid_val : 0;
$t_raw = $u['post_title'] ?? '';
$post_title = is_string( $t_raw ) && '' !== $t_raw ? $t_raw : sprintf( '#%d', $post_id );
$pt_val = $u['post_type'] ?? null;
$post_type = is_string( $pt_val ) ? $pt_val : '';
$ctx_val = $u['context'] ?? null;
$context = is_string( $ctx_val ) ? $ctx_val : '';
$status_val = $u['post_status'] ?? null;
$status = is_string( $status_val ) ? $status_val : '';
$mk_val = $u['meta_key'] ?? null;
$meta_key = is_string( $mk_val ) ? $mk_val : '';
$ctx_label = isset( $context_labels[ $context ] ) ? $context_labels[ $context ] : esc_html( $context );
if ( '' !== $meta_key ) {
$ctx_label .= ' ' . esc_html( $meta_key ) . '';
}
$edit_link = get_edit_post_link( $post_id );
$post_cell = $edit_link
? sprintf( '%s', esc_url( $edit_link ), esc_html( $post_title ) )
: esc_html( $post_title );
echo '';
echo '| ' . $post_cell . ' | '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $post_cell already escaped above.
echo '' . esc_html( $post_type ) . ' | ';
echo '' . $ctx_label . ' | '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $ctx_label already escaped above.
echo '' . esc_html( $status ) . ' | ';
echo '
';
}
echo '
';
}
// -----------------------------------------------------------------------
// External Scan Results
// -----------------------------------------------------------------------
echo '
' . esc_html__( 'External Scan Results', 'robotstxt-mediaaudit' ) . '
';
$this->render_external_results( $attachment_id );
echo '
'; // .wrap
}
// -------------------------------------------------------------------------
// Private helpers
// -------------------------------------------------------------------------
/**
* Fetches the mra_media_index row for a given attachment ID.
*
* @param int $attachment_id Attachment post ID.
*
* @return array