12, 'pagination_mode' => 'numbers', 'sort_order' => 'DESC', 'card_title_limit' => 48, 'related_count' => 3, 'show_navigation' => 1, 'show_category_menu' => 1, 'category_icons' => array(), 'media_menu_order' => array(), 'show_archive_hero' => 1, 'hero_image_id' => 0, 'hero_eyebrow' => 'Video & Music Gallery', 'hero_title' => '7S Medya', 'hero_description' => 'Sinemanın sesini, müziğin hikayesini, unutulmaz anları bir arada keşfedin.', 'hero_quote' => '', 'hero_eyebrow_size' => 12, 'hero_eyebrow_mobile' => 11, 'hero_title_size' => 72, 'hero_title_mobile' => 48, 'hero_description_size' => 18, 'hero_description_mobile' => 15, 'hero_quote_size' => 19, 'hero_quote_mobile' => 15, 'show_archive_filters' => 1, 'show_featured' => 1, 'featured_title' => '', 'featured_layout' => 'editorial_1_4', 'featured_area_title_size' => 32, 'show_popular' => 1, 'popular_title' => 'Most Liked', 'popular_period' => 'month', 'popular_count' => 8, 'popular_like_color' => '#a13b43', 'show_sharing' => 1, 'show_likes' => 1, 'share_facebook' => 1, 'share_x' => 1, 'share_whatsapp' => 1, 'share_telegram' => 1, 'share_linkedin' => 1, 'share_reddit' => 1, 'share_pinterest' => 1, 'share_copy' => 1, 'featured_order' => array(), 'autoplay_video' => 0, 'autoplay_audio' => 0, 'youtube_nocookie' => 1, 'archive_slug' => 'galeri', 'single_slug' => 'galeri', 'width_mode' => 'theme', 'custom_width' => 1440, 'text_color' => '#161616', 'muted_color' => '#696969', 'line_color' => '#dedede', 'surface_color' => '#f4f4f4', 'typography_mode' => 'theme', 'hero_title_font' => 'editorial_serif', 'hero_text_font' => 'system_sans', 'hero_title_weight' => 600, 'hero_text_weight' => 400, 'title_font' => 'editorial_serif', 'featured_font' => 'system_sans', 'body_font' => 'system_sans', 'single_title_font' => 'editorial_serif', 'title_weight' => 600, 'featured_weight' => 600, 'single_title_weight' => 600, 'body_weight' => 400, 'card_title_size' => 21, 'card_title_mobile' => 19, 'featured_title_size' => 24, 'featured_title_mobile' => 18, 'single_title_size' => 62, 'single_title_mobile' => 36, 'content_text_size' => 18, 'content_text_mobile' => 17, ); } public static function install_defaults(): void { if ( false === get_option( self::OPTION, false ) ) { add_option( self::OPTION, self::defaults() ); } } public static function all(): array { $saved = get_option( self::OPTION, array() ); return wp_parse_args( is_array( $saved ) ? $saved : array(), self::defaults() ); } public static function get( string $key, mixed $fallback = null ): mixed { $settings = self::all(); return array_key_exists( $key, $settings ) ? $settings[ $key ] : $fallback; } public static function enabled( string $key ): bool { return self::value_is_enabled( self::get( $key, 0 ) ); } private static function value_is_enabled( mixed $value ): bool { if ( is_bool( $value ) ) { return $value; } if ( is_int( $value ) || is_float( $value ) ) { return 0 < (float) $value; } if ( is_string( $value ) ) { return in_array( strtolower( trim( $value ) ), array( '1', 'true', 'yes', 'on', 'enabled' ), true ); } return ! empty( $value ); } /** * Return the saved featured content order as unique post IDs. * * @return int[] */ public static function featured_order(): array { $order = self::get( 'featured_order', array() ); return is_array( $order ) ? array_values( array_unique( array_filter( array_map( 'absint', $order ) ) ) ) : array(); } /** * Update only the featured order without resetting unrelated settings. * * @param int[] $ids Ordered post IDs. */ public static function update_featured_order( array $ids ): void { $settings = self::all(); $settings['featured_order'] = array_values( array_unique( array_filter( array_map( 'absint', $ids ) ) ) ); update_option( self::OPTION, $settings, false ); } public static function menu(): void { add_submenu_page( 'edit.php?post_type=sg7g_media', __( '7S Video & Music Gallery Settings', '7sgaleri' ), __( 'Settings', '7sgaleri' ), 'manage_options', 'sg7g-settings', array( __CLASS__, 'render_page' ) ); } public static function register(): void { register_setting( 'sg7g_settings_group', self::OPTION, array( 'type' => 'array', 'sanitize_callback' => array( __CLASS__, 'sanitize' ), 'default' => self::defaults(), ) ); } public static function sanitize( mixed $input ): array { $input = is_array( $input ) ? $input : array(); $defaults = self::defaults(); $old = self::all(); $clean = array(); $clean['posts_per_page'] = min( 48, max( 1, absint( $input['posts_per_page'] ?? $defaults['posts_per_page'] ) ) ); $clean['pagination_mode'] = in_array( (string) ( $input['pagination_mode'] ?? '' ), array( 'numbers', 'load_more', 'infinite' ), true ) ? (string) $input['pagination_mode'] : $defaults['pagination_mode']; $clean['sort_order'] = in_array( strtoupper( (string) ( $input['sort_order'] ?? '' ) ), array( 'ASC', 'DESC' ), true ) ? strtoupper( (string) $input['sort_order'] ) : $defaults['sort_order']; $clean['card_title_limit'] = min( 200, max( 0, absint( $input['card_title_limit'] ?? $defaults['card_title_limit'] ) ) ); $clean['related_count'] = min( 12, max( 0, absint( $input['related_count'] ?? $defaults['related_count'] ) ) ); $featured_order = isset( $input['featured_order'] ) && is_array( $input['featured_order'] ) ? $input['featured_order'] : array(); $clean['featured_order'] = array_values( array_unique( array_filter( array_map( 'absint', $featured_order ) ) ) ); $clean['featured_title'] = sanitize_text_field( (string) ( $input['featured_title'] ?? $old['featured_title'] ?? $defaults['featured_title'] ) ); $featured_layout = (string) ( $input['featured_layout'] ?? $old['featured_layout'] ?? $defaults['featured_layout'] ); if ( 'spotlight' === $featured_layout ) { $featured_layout = 'editorial_1_4'; } $clean['featured_layout'] = in_array( $featured_layout, array( 'editorial_1_4', 'editorial_2_3' ), true ) ? $featured_layout : $defaults['featured_layout']; $clean['featured_area_title_size'] = max( 1, absint( $input['featured_area_title_size'] ?? $defaults['featured_area_title_size'] ) ); $clean['popular_title'] = sanitize_text_field( (string) ( $input['popular_title'] ?? $defaults['popular_title'] ) ); $clean['hero_image_id'] = absint( $input['hero_image_id'] ?? $defaults['hero_image_id'] ); $clean['hero_eyebrow'] = sanitize_text_field( (string) ( $input['hero_eyebrow'] ?? $defaults['hero_eyebrow'] ) ); $clean['hero_title'] = sanitize_text_field( (string) ( $input['hero_title'] ?? $defaults['hero_title'] ) ); $clean['hero_description'] = sanitize_text_field( (string) ( $input['hero_description'] ?? $defaults['hero_description'] ) ); $clean['hero_quote'] = sanitize_text_field( (string) ( $input['hero_quote'] ?? $defaults['hero_quote'] ) ); $clean['category_icons'] = array(); $category_icons = isset( $input['category_icons'] ) && is_array( $input['category_icons'] ) ? $input['category_icons'] : array(); $allowed_category_icons = array_keys( SG7G_Archive_UI::category_icon_options() ); foreach ( $category_icons as $term_id => $icon_key ) { $term_id = absint( $term_id ); $icon_key = sanitize_key( (string) $icon_key ); if ( $term_id > 0 && in_array( $icon_key, $allowed_category_icons, true ) ) { $clean['category_icons'][ $term_id ] = $icon_key; } } $available_menu_keys = array_keys( self::media_menu_items( $clean ) ); $submitted_menu_order = isset( $input['media_menu_order'] ) && is_array( $input['media_menu_order'] ) ? $input['media_menu_order'] : array(); $clean['media_menu_order'] = array_values( array_unique( array_filter( array_map( static function ( mixed $item ) use ( $available_menu_keys ): string { $item = sanitize_key( (string) $item ); return in_array( $item, $available_menu_keys, true ) ? $item : ''; }, $submitted_menu_order ) ) ) ); $clean['popular_period'] = in_array( (string) ( $input['popular_period'] ?? '' ), array( 'week', 'month', 'all' ), true ) ? (string) $input['popular_period'] : $defaults['popular_period']; $popular_count = absint( $input['popular_count'] ?? $defaults['popular_count'] ); $clean['popular_count'] = in_array( $popular_count, array( 4, 8, 12 ), true ) ? $popular_count : $defaults['popular_count']; $popular_like_color = sanitize_hex_color( (string) ( $input['popular_like_color'] ?? '' ) ); $clean['popular_like_color'] = $popular_like_color ?: $defaults['popular_like_color']; if ( function_exists( 'mb_substr' ) ) { $clean['featured_title'] = mb_substr( $clean['featured_title'], 0, 120 ); $clean['popular_title'] = mb_substr( $clean['popular_title'], 0, 120 ); } else { $clean['featured_title'] = substr( $clean['featured_title'], 0, 120 ); $clean['popular_title'] = substr( $clean['popular_title'], 0, 120 ); } foreach ( array( 'show_navigation', 'show_category_menu', 'show_archive_hero', 'show_archive_filters', 'show_featured', 'show_popular', 'show_sharing', 'show_likes', 'share_facebook', 'share_x', 'share_whatsapp', 'share_telegram', 'share_linkedin', 'share_reddit', 'share_pinterest', 'share_copy', 'autoplay_video', 'autoplay_audio', 'youtube_nocookie' ) as $boolean_key ) { $clean[ $boolean_key ] = empty( $input[ $boolean_key ] ) ? 0 : 1; } $clean['archive_slug'] = self::sanitize_slug( $input['archive_slug'] ?? $defaults['archive_slug'], $defaults['archive_slug'] ); $clean['single_slug'] = self::sanitize_slug( $input['single_slug'] ?? $defaults['single_slug'], $defaults['single_slug'] ); $clean['width_mode'] = in_array( (string) ( $input['width_mode'] ?? '' ), array( 'theme', 'custom' ), true ) ? (string) $input['width_mode'] : $defaults['width_mode']; $clean['custom_width'] = min( 2200, max( 640, absint( $input['custom_width'] ?? $defaults['custom_width'] ) ) ); $clean['typography_mode'] = in_array( (string) ( $input['typography_mode'] ?? '' ), array( 'theme', 'custom' ), true ) ? (string) $input['typography_mode'] : $defaults['typography_mode']; $font_options = array( 'theme', 'system_sans', 'editorial_serif', 'classic_serif' ); foreach ( array( 'hero_title_font', 'hero_text_font', 'title_font', 'featured_font', 'single_title_font', 'body_font' ) as $font_key ) { $font_value = (string) ( $input[ $font_key ] ?? '' ); $clean[ $font_key ] = in_array( $font_value, $font_options, true ) ? $font_value : $defaults[ $font_key ]; } foreach ( array( 'hero_title_weight', 'hero_text_weight', 'title_weight', 'featured_weight', 'single_title_weight', 'body_weight' ) as $weight_key ) { $weight = absint( $input[ $weight_key ] ?? $defaults[ $weight_key ] ); $clean[ $weight_key ] = in_array( $weight, array( 400, 500, 600, 700 ), true ) ? $weight : $defaults[ $weight_key ]; } $size_ranges = array( 'card_title_size' => array( 14, 32 ), 'card_title_mobile' => array( 14, 28 ), 'featured_title_size' => array( 16, 40 ), 'featured_title_mobile' => array( 14, 30 ), 'single_title_size' => array( 32, 88 ), 'single_title_mobile' => array( 28, 60 ), 'content_text_size' => array( 14, 24 ), 'content_text_mobile' => array( 14, 22 ), 'hero_eyebrow_size' => array( 9, 20 ), 'hero_eyebrow_mobile' => array( 9, 18 ), 'hero_title_size' => array( 32, 110 ), 'hero_title_mobile' => array( 28, 78 ), 'hero_description_size' => array( 12, 30 ), 'hero_description_mobile' => array( 12, 24 ), 'hero_quote_size' => array( 12, 28 ), 'hero_quote_mobile' => array( 12, 24 ), ); foreach ( $size_ranges as $size_key => $range ) { $clean[ $size_key ] = min( $range[1], max( $range[0], absint( $input[ $size_key ] ?? $defaults[ $size_key ] ) ) ); } $clean['card_title_mobile'] = min( $clean['card_title_mobile'], $clean['card_title_size'] ); $clean['featured_title_mobile'] = min( $clean['featured_title_mobile'], $clean['featured_title_size'] ); $clean['single_title_mobile'] = min( $clean['single_title_mobile'], $clean['single_title_size'] ); $clean['content_text_mobile'] = min( $clean['content_text_mobile'], $clean['content_text_size'] ); $clean['hero_eyebrow_mobile'] = min( $clean['hero_eyebrow_mobile'], $clean['hero_eyebrow_size'] ); $clean['hero_title_mobile'] = min( $clean['hero_title_mobile'], $clean['hero_title_size'] ); $clean['hero_description_mobile'] = min( $clean['hero_description_mobile'], $clean['hero_description_size'] ); $clean['hero_quote_mobile'] = min( $clean['hero_quote_mobile'], $clean['hero_quote_size'] ); foreach ( array( 'text_color', 'muted_color', 'line_color', 'surface_color' ) as $color_key ) { $color = sanitize_hex_color( (string) ( $input[ $color_key ] ?? '' ) ); $clean[ $color_key ] = $color ?: $defaults[ $color_key ]; } if ( $old['archive_slug'] !== $clean['archive_slug'] || $old['single_slug'] !== $clean['single_slug'] ) { update_option( 'sg7g_flush_rewrite_rules', 1, false ); } return $clean; } private static function sanitize_slug( mixed $value, string $fallback ): string { $slug = sanitize_title( (string) $value ); return '' !== $slug ? $slug : $fallback; } public static function maybe_flush_rewrite_rules(): void { if ( ! current_user_can( 'manage_options' ) || ! get_option( 'sg7g_flush_rewrite_rules' ) ) { return; } flush_rewrite_rules( false ); delete_option( 'sg7g_flush_rewrite_rules' ); } public static function rewrite_conflict_notice(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } $screen = get_current_screen(); if ( ! $screen || ( 'sg7g_media' !== $screen->post_type && ! str_contains( (string) $screen->id, 'sg7g-settings' ) ) ) { return; } $archive_slug = (string) self::get( 'archive_slug', 'galeri' ); $page = get_page_by_path( $archive_slug, OBJECT, 'page' ); if ( ! $page instanceof WP_Post || ! in_array( $page->post_status, array( 'publish', 'private', 'future' ), true ) ) { return; } printf( '
%1$s %2$s