// ────────────────────────────────────────────────────────────────────────
// OCR Labels Report + Clear Button
// ────────────────────────────────────────────────────────────────────────
add_action( 'admin_menu', function(){
add_submenu_page(
'edit.php?post_type=image', // parent: Images CPT
'OCR Labels', // page title
'OCR Labels', // menu title
'manage_options', // capability
'image-ocr-labels', // menu slug
'stoxo_render_ocr_report' // callback
);
}, 20 );
/**
* Render the OCR report table, thumbnails, and a “Clear All” form.
*/
function stoxo_render_ocr_report() {
// handle “Clear All” action
if ( isset( $_POST['stoxo_clear_ocr'] ) && check_admin_referer( 'stoxo_clear_ocr_action', 'stoxo_clear_ocr_nonce' ) ) {
global $wpdb;
// delete all posts’ _ocr_labels meta
delete_post_meta_by_key( '_ocr_labels' );
echo '
';
}
// fetch only posts that have non-empty _ocr_labels
$posts = get_posts( [
'post_type' => 'image',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => '_ocr_labels',
'compare' => 'EXISTS',
],
[
'key' => '_ocr_labels',
'value' => '',
'compare' => '!=',
],
],
] );
echo '';
echo '
OCR Labels (' . count( $posts ) . ' items)
';
// “Clear All” button
echo '
';
echo '
';
echo '';
echo 'Thumb | ';
echo 'ID | ';
echo 'Title | ';
echo 'OCR Text | ';
echo 'Actions | ';
echo '
';
echo '';
if ( empty( $posts ) ) {
echo 'No OCR labels found. |
';
} else {
foreach ( $posts as $p ) {
$text = get_post_meta( $p->ID, '_ocr_labels', true );
// get thumbnail HTML at 150×150
$thumb = has_post_thumbnail( $p->ID )
? get_the_post_thumbnail( $p->ID, [150,150], ['style'=>'width:75px;height:75px;object-fit:cover;border:1px solid #ccc;'] )
: 'No
Thumb
';
printf(
'
%1$s |
%2$u |
%3$s |
%4$s |
Edit
Trash
|
',
$thumb,
$p->ID,
esc_html( get_the_title( $p->ID ) ),
esc_html( $text ),
esc_url( admin_url( 'post.php?post=' . $p->ID . '&action=edit' ) ),
esc_url( get_delete_post_link( $p->ID ) )
);
}
}
echo '
';
echo '
';
}
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/mu-plugins/ocr-scan.php:1) in /var/www/html/wp-includes/pluggable.php on line 1450
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/mu-plugins/ocr-scan.php:1) in /var/www/html/wp-includes/pluggable.php on line 1453