Plugin Directory


Ignore:
Timestamp:
10/16/2026 07:26:04 AM (3 weeks ago)
Author:
codesnippetspro
Message:

Version v0.10.28

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translate/trunk/Components/SwitcherPlacement.php

    r3717606 r3749853  
    44
    55/**
    6  * Where the switcher sits inside the document when it is placed inline: a
    7  * suggested zone, or an unrestricted anchor (a CSS path plus a position
    8  * relative to it). Stored as a reproducible description, never as viewport
    9  * coordinates, so it survives across page loads. A page placement wins over
    10  * the site-wide one while it exists.
     6 * Where the switcher sits inside the document when it is placed inline: an
     7 * anchor, a CSS path plus the side of that element the switcher sits on.
     8 * Stored as a reproducible description, never as viewport coordinates, so it
     9 * survives across page loads. A page placement wins over the site-wide one
     10 * while it exists. Zones and the prepend and append positions are read for
     11 * placements stored by earlier versions.
    1112 */
    1213class SwitcherPlacement {
    … …  
    1617        public const ZONES = [ 'header', 'before_content', 'after_content', 'sidebar', 'footer' ];
    1718
    18         public const ANCHOR_POSITIONS = [ 'before', 'after', 'prepend', 'append' ];
     19        public const ANCHOR_POSITIONS = [ 'before', 'after', 'left', 'right', 'prepend', 'append' ];
     20
     21        public const ANCHOR_FALLBACKS = [ 'floating', 'none' ];
     22
     23        public const ANCHOR_FALLBACK_KEY = 'anchor_fallback';
    1924
    2025        private const MAX_SELECTOR_LENGTH = 1024;
    … …  
    7479        }
    7580
     81        /** What a page shows when the stored anchor matches none of its elements. */
     82        public static function anchor_fallback(): string {
     83                $switcher = Options::get( 'languages.switcher', [] );
     84                $value    = is_array( $switcher ) ? sanitize_key( (string) ( $switcher[ self::ANCHOR_FALLBACK_KEY ] ?? '' ) ) : '';
     85
     86                return in_array( $value, self::ANCHOR_FALLBACKS, true ) ? $value : 'floating';
     87        }
     88
     89        public static function save_anchor_fallback( string $value ): void {
     90                $value = sanitize_key( $value );
     91                if ( ! in_array( $value, self::ANCHOR_FALLBACKS, true ) ) {
     92                        return;
     93                }
     94                $switcher = Options::get( 'languages.switcher', [] );
     95                $switcher = is_array( $switcher ) ? $switcher : [];
     96                $switcher[ self::ANCHOR_FALLBACK_KEY ] = $value;
     97                Options::update( 'languages.switcher', $switcher );
     98        }
     99
    76100        public static function page_placement( int $post_id ): ?array {
    77101                if ( $post_id <= 0 ) {
Note: See TracChangeset for help on using the changeset viewer.