'array', 'sanitize_callback' => 'Captionwright\\sanitize_settings', 'default' => array(), ) ); } ); add_filter( 'plugin_action_links_' . plugin_basename( CAPTIONWRIGHT_FILE ), function ( $links ) { array_unshift( $links, '' . esc_html__( 'Captions', 'captionwright' ) . '' ); return $links; } ); add_filter( 'media_row_actions', function ( $actions, $post ) { if ( is_media( $post->ID ) ) { $actions['captionwright'] = '' . esc_html__( 'Captions', 'captionwright' ) . ''; } return $actions; }, 10, 2 ); add_filter( 'attachment_fields_to_edit', function ( $fields, $post ) { if ( is_media( $post->ID ) ) { $tracks = get_tracks( $post->ID ); $fields['captionwright'] = array( 'label' => __( 'Captions', 'captionwright' ), 'input' => 'html', 'html' => sprintf( '%2$s', esc_url( admin_url( 'upload.php?page=' . PAGE . '&media=' . $post->ID ) ), $tracks /* translators: %s: comma-separated languages */ ? esc_html( sprintf( __( 'Edit captions (%s)', 'captionwright' ), implode( ', ', wp_list_pluck( $tracks, 'label' ) ) ) ) : esc_html__( 'Generate captions', 'captionwright' ) ), ); } return $fields; }, 10, 2 ); add_action( 'admin_enqueue_scripts', function ( $hook ) { if ( 'media_page_' . PAGE !== $hook ) { return; } wp_enqueue_style( 'captionwright-admin', CAPTIONWRIGHT_URL . 'assets/admin.css', array(), CAPTIONWRIGHT_VERSION . '.' . filemtime( CAPTIONWRIGHT_DIR . 'assets/admin.css' ) ); wp_enqueue_script( 'captionwright-admin', CAPTIONWRIGHT_URL . 'assets/admin.js', array( 'wp-api-fetch', 'wp-hooks', 'wp-i18n' ), CAPTIONWRIGHT_VERSION . '.' . filemtime( CAPTIONWRIGHT_DIR . 'assets/admin.js' ), true ); wp_set_script_translations( 'captionwright-admin', 'captionwright' ); $langs = array(); foreach ( languages() as $code => $name ) { $langs[] = array( 'code' => $code, 'name' => $name, ); } /** * Filters the configuration passed to the Media → Captions screen script. * * @param array $config Configuration. */ $config = apply_filters( 'captionwright_admin_config', array( 'workerUrl' => add_query_arg( 'ver', CAPTIONWRIGHT_VERSION . '-' . filemtime( CAPTIONWRIGHT_DIR . 'assets/worker.js' ), CAPTIONWRIGHT_URL . 'assets/worker.js' ), 'settings' => settings(), 'models' => models(), 'languages' => $langs, ) ); wp_add_inline_script( 'captionwright-admin', 'window.captionwrightConfig = ' . wp_json_encode( $config ) . ';', 'before' ); /** * Fires after the Captions screen assets are enqueued, so add-ons can add theirs. */ do_action( 'captionwright_admin_enqueue' ); } ); /** * Whether the Generate buttons can be used (the browser engine needs consent; * add-ons with other engines can allow it anyway). * * @return bool */ function can_generate() { return (bool) apply_filters( 'captionwright_can_generate', settings()['consent'] ); } /** * Media rows for the screen. * * @param int $paged Page number. * @return array{items:array>,pages:int} */ function media_rows( $paged ) { $q = new \WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => array( 'video', 'audio' ), 'posts_per_page' => 20, 'paged' => max( 1, $paged ), 'orderby' => 'date', 'order' => 'DESC', ) ); $items = array(); foreach ( $q->posts as $p ) { $meta = wp_get_attachment_metadata( $p->ID ); $items[] = array( 'id' => $p->ID, 'title' => get_the_title( $p ), 'mime' => $p->post_mime_type, 'url' => (string) wp_get_attachment_url( $p->ID ), 'length' => is_array( $meta ) && ! empty( $meta['length_formatted'] ) ? $meta['length_formatted'] : '', 'filesize' => is_array( $meta ) && ! empty( $meta['filesize'] ) ? (int) $meta['filesize'] : 0, 'tracks' => get_tracks( $p->ID ), ); } return array( 'items' => $items, 'pages' => (int) $q->max_num_pages, ); } /** * Render Media → Captions. */ function render_page() { $s = settings(); $paged = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only pagination. $rows = media_rows( $paged ); $model = models(); ?>

>

1 ) { echo '
'; echo wp_kses_post( paginate_links( array( 'base' => add_query_arg( 'paged', '%#%' ), 'format' => '', 'current' => max( 1, $paged ), 'total' => $rows['pages'], ) ) ); echo '
'; } ?>