/** * Portfolio Vimeo hover thumbnails — Salient child theme */ // ── 1. Meta box dans l'éditeur portfolio ───────────────────────────────────── add_action( 'add_meta_boxes', function () { add_meta_box( 'vimeo_hover_url', 'Vimeo — hover thumbnail', function ( $post ) { wp_nonce_field( 'vimeo_hover_save', 'vimeo_hover_nonce' ); $val = get_post_meta( $post->ID, '_vimeo_hover_id', true ); echo '

'; echo ''; echo '

La vidéo démarre au survol de la vignette (muette, en boucle).

'; }, 'portfolio', 'side' ); } ); // ── 2. Sauvegarde ──────────────────────────────────────────────────────────── add_action( 'save_post_portfolio', function ( $post_id ) { if ( ! isset( $_POST['vimeo_hover_nonce'] ) ) return; if ( ! wp_verify_nonce( $_POST['vimeo_hover_nonce'], 'vimeo_hover_save' ) ) return; if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( ! current_user_can( 'edit_post', $post_id ) ) return; if ( isset( $_POST['vimeo_hover_id'] ) ) { $raw = sanitize_text_field( $_POST['vimeo_hover_id'] ); if ( preg_match( '/vimeo\.com\/(\d+)/', $raw, $m ) ) { $raw = $m[1]; } update_post_meta( $post_id, '_vimeo_hover_id', $raw ); } } ); // ── 3. Thumbnail Vimeo (mis en cache 24h) ──────────────────────────────────── function get_vimeo_thumbnail( $vimeo_id ) { $key = 'vimeo_thumb_' . $vimeo_id; $cached = get_transient( $key ); if ( $cached !== false ) return $cached; $response = wp_remote_get( 'https://vimeo.com/api/oembed.json?url=' . urlencode( 'https://vimeo.com/' . $vimeo_id ) . '&width=1280', [ 'timeout' => 10 ] ); $thumb = ''; if ( ! is_wp_error( $response ) ) { $data = json_decode( wp_remote_retrieve_body( $response ), true ); $thumb = $data['thumbnail_url'] ?? ''; } set_transient( $key, $thumb, DAY_IN_SECONDS ); return $thumb; } // ── 4. Enqueue scripts ─────────────────────────────────────────────────────── add_action( 'wp_enqueue_scripts', function () { $posts = get_posts( [ 'post_type' => 'portfolio', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => [ [ 'key' => '_vimeo_hover_id', 'compare' => 'EXISTS', ] ], ] ); if ( empty( $posts ) ) return; $map = []; foreach ( $posts as $pid ) { $vid = get_post_meta( $pid, '_vimeo_hover_id', true ); if ( $vid ) { $map[ (int) $pid ] = [ 'id' => $vid, 'thumb' => get_vimeo_thumbnail( $vid ), ]; } } if ( empty( $map ) ) return; wp_enqueue_script( 'vimeo-player', 'https://player.vimeo.com/api/player.js', [], null, true ); wp_enqueue_script( 'vimeo-hover-thumb', get_stylesheet_directory_uri() . '/assets/js/vimeo-hover.js', [ 'vimeo-player' ], '1.3.0', true ); wp_add_inline_script( 'vimeo-hover-thumb', 'window.nectarVimeoMap = ' . wp_json_encode( $map ) . ';', 'before' ); } ); // ── 5. Preconnect Vimeo ────────────────────────────────────────────────────── add_action( 'wp_head', function () { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; }, 1 ); add_action( 'wp_enqueue_scripts', 'salient_child_enqueue_styles', 100); function salient_child_enqueue_styles() { $nectar_theme_version = nectar_get_theme_version(); wp_enqueue_style( 'salient-child-style', get_stylesheet_directory_uri() . '/style.css', '', $nectar_theme_version ); if ( is_rtl() ) { wp_enqueue_style( 'salient-rtl', get_template_directory_uri(). '/rtl.css', array(), '1', 'screen' ); } } https://louise-bistrot.com/page-sitemap.xml 2026-05-18T11:17:02+00:00