ID ) ) {
return;
}
add_meta_box( 'vocalstack', __( 'VocalStack transcript', 'vocalstack' ), array( self::class, 'render' ), 'attachment', 'normal', 'high' );
Assets::enqueue( 'media-panel', self::script_data() );
}
/**
* The React root.
*
* @param \WP_Post $post The attachment.
*/
public static function render( \WP_Post $post ): void {
printf( '
', (int) $post->ID );
}
/**
* What the panel needs to know about the site.
*
* @return array
*/
public static function script_data(): array {
return array(
'connected' => '' !== Settings::api_key(),
'settingsUrl' => current_user_can( 'manage_options' ) ? SettingsPage::url() : '',
);
}
/**
* In the media modal: the transcript's state and a link to the edit screen.
*
* @param array> $fields The modal's fields.
* @param \WP_Post $post The attachment.
* @return array>
*/
public static function modal_field( array $fields, \WP_Post $post ): array {
if ( ! Media::is_transcribable( $post->ID ) || ! current_user_can( 'edit_post', $post->ID ) ) {
return $fields;
}
$state = (string) get_post_meta( $post->ID, Media::STATE, true );
$labels = array(
'' => __( 'Not transcribed', 'vocalstack' ),
'done' => __( 'Transcribed', 'vocalstack' ),
'failed' => __( 'Failed', 'vocalstack' ),
);
$label = $labels[ $state ] ?? __( 'Transcribing…', 'vocalstack' );
$link = '' === $state ? __( 'Transcribe', 'vocalstack' ) : __( 'Open transcript', 'vocalstack' );
$fields['vocalstack'] = array(
'label' => __( 'Transcript', 'vocalstack' ),
'input' => 'html',
'html' => sprintf(
'%s · %s',
esc_html( $label ),
esc_url( get_edit_post_link( $post->ID ) . '#vocalstack' ),
esc_html( $link )
),
);
return $fields;
}
}