base || ! $screen->post_type || ! Plugin::gets_videos( $screen->post_type ) || ! Connection::get() ) { return; } $type = $screen->post_type; add_filter( "manage_{$type}_posts_columns", array( __CLASS__, 'columns' ) ); add_action( "manage_{$type}_posts_custom_column", array( __CLASS__, 'column' ), 10, 2 ); add_filter( is_post_type_hierarchical( $type ) ? 'page_row_actions' : 'post_row_actions', array( __CLASS__, 'row_actions' ), 10, 2 ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue' ) ); } public static function columns( $columns ) { $columns['ojelio'] = __( 'Video', 'ojelio' ); return $columns; } public static function column( $name, $post_id ) { if ( 'ojelio' !== $name ) { return; } $videos = Videos::of_post( $post_id ); echo ''; echo $videos ? esc_html( self::headline( $videos[0] ) ) : '' . esc_html__( 'No video', 'ojelio' ) . ''; echo ''; if ( count( $videos ) > 1 ) { /* translators: %d: how many videos the post has. */ echo '
' . esc_html( sprintf( _n( '%d video', '%d videos', count( $videos ), 'ojelio' ), count( $videos ) ) ) . ''; } } /** A video's state in a few words, as the sidebar says it. */ public static function headline( array $video ) { switch ( $video['status'] ) { case 'queued': return __( 'Waiting to start', 'ojelio' ); case 'running': return __( 'Being made', 'ojelio' ); case 'review': return __( 'Waiting for review in Ojelio', 'ojelio' ); case 'failed': return __( 'Failed', 'ojelio' ); case 'canceled': return __( 'Canceled', 'ojelio' ); case 'removed': return __( 'Removed from Ojelio', 'ojelio' ); case 'completed': if ( ! empty( $video['attachment_id'] ) ) { return __( 'In your Media Library', 'ojelio' ); } return empty( $video['save_error'] ) ? __( 'Saving to your Media Library…', 'ojelio' ) : __( 'Ready in Ojelio, not saved to your Media Library', 'ojelio' ); } return $video['status']; } public static function row_actions( $actions, WP_Post $post ) { if ( current_user_can( 'edit_post', $post->ID ) && 'trash' !== $post->post_status ) { $title = '' !== $post->post_title ? $post->post_title : __( 'Untitled post', 'ojelio' ); $actions['ojelio'] = sprintf( '%s', $post->ID, esc_attr( $title ), esc_url( get_edit_post_link( $post->ID, 'raw' ) ), /* translators: %s: the post's title. */ esc_attr( sprintf( __( 'Create a video of “%s”', 'ojelio' ), $title ) ), esc_html__( 'Create video', 'ojelio' ) ); } return $actions; } public static function enqueue() { $asset_file = OJELIO_DIR . 'build/list.asset.php'; if ( ! is_readable( $asset_file ) ) { return; } $asset = require $asset_file; wp_enqueue_script( 'ojelio-list', plugins_url( 'build/list.js', OJELIO_FILE ), $asset['dependencies'], $asset['version'], true ); wp_set_script_translations( 'ojelio-list', 'ojelio', OJELIO_DIR . 'languages' ); wp_add_inline_style( 'common', '#ojelio-dialog{max-width:440px;width:calc(100% - 32px);border:1px solid #c3c4c7;border-radius:4px;padding:0;box-shadow:0 8px 32px rgba(0,0,0,.2)}' . '#ojelio-dialog::backdrop{background:rgba(0,0,0,.4)}' . '#ojelio-dialog .ojelio-body{padding:16px 20px}' . '#ojelio-dialog h2{margin:0 0 12px;font-size:1.2em}' . '#ojelio-dialog dl{display:grid;grid-template-columns:auto 1fr;gap:4px 12px;margin:0 0 12px}' . '#ojelio-dialog dt{font-weight:600}#ojelio-dialog dd{margin:0}' . '#ojelio-dialog .ojelio-actions{display:flex;gap:8px;justify-content:flex-end;padding:12px 20px;border-top:1px solid #dcdcde;background:#f6f7f7}' . '#ojelio-dialog .notice{margin:8px 0}' . '.column-ojelio{width:12em}' ); } }