$section ) { foreach ( $section['fields'] as $index => $field ) { // Exclude certain fields from the form if ( in_array( $field['name'], $excluded, true ) ) { unset( $fields[ $key ]['fields'][ $index ] ); continue; } // Add the exclude + schedule fields to the end of the source section. if ( 'order' === $field['name'] ) { $fields[ $key ]['fields'][] = array( 'name' => 'exclude', 'label' => __( 'Exclude Videos', 'automatic-youtube-gallery' ), 'description' => __( 'Enter the video IDs or URLs you want to exclude, one per line. These videos will never be imported into this gallery.', 'automatic-youtube-gallery' ), 'type' => 'textarea', 'placeholder' => __( 'Enter one video ID or URL per line', 'automatic-youtube-gallery' ), 'value' => '', 'sanitize_callback' => 'sanitize_textarea_field' ); $fields[ $key ]['fields'][] = array( 'name' => 'schedule', 'label' => __( 'Import Schedule', 'automatic-youtube-gallery' ), 'description' => __( 'How often we automatically check your YouTube source for new videos and import them in the background. Choose "Pause Automatic Imports" to stop these background imports — you can still import on demand by saving the gallery.', 'automatic-youtube-gallery' ), 'type' => 'select', 'options' => ayg_get_import_schedule_options(), 'value' => 86400, 'sanitize_callback' => 'absint' ); } // Add the sort and duration filter fields to the gallery section. if ( 'gallery' === $key && 'per_page' === $field['name'] ) { // Builder galleries render from our own table, so "Videos per Page" can go beyond the // 50-video API cap here — 0 shows all videos on one page. (The shared field keeps its 50 // limit elsewhere, e.g. the global settings page.) $fields[ $key ]['fields'][ $index ]['description'] = __( 'Enter the number of videos to show per page, or 0 to show all videos on a single page.', 'automatic-youtube-gallery' ); unset( $fields[ $key ]['fields'][ $index ]['max'] ); // Add the display-time sort fields right after the per_page field in the gallery section. array_splice( $fields[ $key ]['fields'], $index + 1, 0, array( array( 'name' => 'sort_by', 'label' => __( 'Order Videos By', 'automatic-youtube-gallery' ), 'description' => __( 'Select how imported videos are ordered in this gallery.', 'automatic-youtube-gallery' ), 'type' => 'select', 'options' => array( 'date' => __( 'Published Date', 'automatic-youtube-gallery' ), 'title' => __( 'Title', 'automatic-youtube-gallery' ), 'duration' => __( 'Duration', 'automatic-youtube-gallery' ), 'random' => __( 'Random', 'automatic-youtube-gallery' ) ), 'value' => 'date', 'sanitize_callback' => 'sanitize_key' ), array( 'name' => 'sort_order', 'label' => __( 'Order', 'automatic-youtube-gallery' ), 'description' => __( 'Descending shows newest, Z–A or longest first. Ascending shows oldest, A–Z or shortest first.', 'automatic-youtube-gallery' ), 'type' => 'select', 'options' => array( 'desc' => __( 'Descending', 'automatic-youtube-gallery' ), 'asc' => __( 'Ascending', 'automatic-youtube-gallery' ) ), 'value' => 'desc', 'sanitize_callback' => 'sanitize_key' ), array( 'name' => 'duration_filter', 'label' => __( 'Filter by Duration', 'automatic-youtube-gallery' ), 'description' => __( 'Show only videos longer or shorter than the duration below — handy for including or excluding Shorts.', 'automatic-youtube-gallery' ), 'type' => 'select', 'options' => array( '' => '— ' . __( 'No Filter', 'automatic-youtube-gallery' ) . ' —', 'long' => __( 'Longer Than', 'automatic-youtube-gallery' ), 'short' => __( 'Shorter Than', 'automatic-youtube-gallery' ) ), 'value' => '', 'sanitize_callback' => 'sanitize_key' ), array( 'name' => 'duration', 'label' => __( 'Duration (Seconds)', 'automatic-youtube-gallery' ), 'description' => __( 'The duration threshold in seconds for the filter above. Shorts are typically up to 60 seconds long, so enter 60 to include or exclude Shorts. Has no effect when the filter is set to "No Filter".', 'automatic-youtube-gallery' ), 'type' => 'text', 'value' => '', 'sanitize_callback' => 'ayg_sanitize_int' ) ) ); } // Add a description to the search form field in the search section. if ( 'search' === $key && 'search_form' === $field['name'] ) { $fields[ $key ]['fields'][ $index ]['description'] = __( 'Check this option to enable the search form.', 'automatic-youtube-gallery' ); } } } // Load gallery config when editing $form_data = array( 'id' => $gallery_id, 'title' => '', 'type' => 'playlist', 'theme' => 'classic', 'import_status' => 'idle', 'import_error' => '', 'import_log' => '', 'last_imported_at' => '', 'next_import_at' => '', 'video_count' => 0, 'schedule' => 86400 ); if ( $gallery_id > 0 ) { $gallery = ayg_get_gallery( $gallery_id ); if ( ! $gallery ) { ?>