Plugin Directory

Changeset 3321653


Ignore:
Timestamp:
07/03/2025 10:08:47 AM (9 months ago)
Author:
wedok
Message:

Add version 1.5.3:

  • New image grouping mode setting (none / all / gallery only)
  • Improved standalone image handling in gallery mode
  • Translation loading optimized (Poedit & ja_JP support)
  • Added updated readme.txt and multilingual UI
Location:
wepop/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • wepop/trunk/includes/config.php

    r3319334 r3321653  
    3535        $options = array(
    3636            'show_alt_text' => isset($_POST['show_alt_text']),
    37             'gallery_only_grouping' => isset($_POST['gallery_only_grouping']),
     37            'gallery_only_grouping' => isset($_POST['gallery_only_grouping']), // 旧設定(将来的に廃止)
    3838            'language' => sanitize_text_field($_POST['language']),
     39            'group_mode' => sanitize_text_field($_POST['group_mode']),
    3940        );
    4041
     
    5657        'show_alt_text' => false,
    5758        'gallery_only_grouping' => false,
    58         'language' => 'ja'
     59        'language' => 'ja',
     60        'group_mode' => 'gallery',
    5961    );
    6062
     
    7173            <?php wp_nonce_field('wedok_pop_settings_nonce', 'wedok_pop_nonce'); ?>
    7274            <table class="form-table">
     75
     76                <!-- ① 代替テキストの表示 -->
    7377                <tr>
    7478                    <th scope="row"><?php esc_html_e('Show Alt Text', 'wepop'); ?></th>
     
    8084                    </td>
    8185                </tr>
     86
     87                <!-- ② グループ化モードの設定 -->
    8288                <tr>
    83                     <th scope="row"><?php esc_html_e('Gallery Only Grouping', 'wepop'); ?></th>
     89                    <th scope="row"><?php esc_html_e('Image Grouping Mode', 'wepop'); ?></th>
    8490                    <td>
    8591                        <label>
    86                             <input type="checkbox" name="gallery_only_grouping" <?php checked($options['gallery_only_grouping'], true); ?>>
    87                             <?php esc_html_e('Group only WordPress gallery images', 'wepop'); ?>
     92                            <input type="radio" name="group_mode" value="gallery" <?php checked($options['group_mode'], 'gallery'); ?>>
     93                            <strong><?php _e('Group only gallery images (recommended)', 'wepop'); ?></strong><br>
     94                            <small><?php _e('Only images inside WordPress gallery blocks will be grouped into slideshows. Each gallery will be grouped separately.', 'wepop'); ?></small>
     95                        </label><br><br>
     96
     97                        <label>
     98                            <input type="radio" name="group_mode" value="all" <?php checked($options['group_mode'], 'all'); ?>>
     99                            <strong><?php _e('Group all images in the post', 'wepop'); ?></strong><br>
     100                            <small><?php _e('All images (both standalone and gallery) in the post will be grouped into one slideshow.', 'wepop'); ?></small>
     101                        </label><br><br>
     102
     103                        <label>
     104                            <input type="radio" name="group_mode" value="none" <?php checked($options['group_mode'], 'none'); ?>>
     105                            <strong><?php _e('No grouping', 'wepop'); ?></strong><br>
     106                            <small><?php _e('Each image will open individually without slideshow grouping.', 'wepop'); ?></small>
    88107                        </label>
    89108                    </td>
    90109                </tr>
     110
     111                <!-- ③ 言語設定 -->
    91112                <tr>
    92113                    <th scope="row"><?php esc_html_e('Language', 'wepop'); ?></th>
     
    102123                    </td>
    103124                </tr>
     125
    104126            </table>
    105127            <p class="submit">
  • wepop/trunk/js/popup.js

    r3319334 r3321653  
    1 document.addEventListener('DOMContentLoaded', function() {
     1document.addEventListener('DOMContentLoaded', function () {
    22  const images = document.querySelectorAll('a[data-wepop]');
    33  images.forEach(image => {
     
    99  event.preventDefault();
    1010  const clickedImage = event.currentTarget;
    11   const group = clickedImage.getAttribute('data-group');
    12   let imageUrls;
    13   let currentIndex;
     11  const groupMode = (typeof wedokPopSettings !== 'undefined' && wedokPopSettings.groupMode) ? wedokPopSettings.groupMode : 'gallery';
    1412
    15   if (group) {
    16     const groupImages = document.querySelectorAll(`a[data-wepop][data-group="${group}"]`);
    17     imageUrls = Array.from(groupImages).map(img => img.href);
     13  let imageUrls = [];
     14  let currentIndex = 0;
     15
     16  if (groupMode === 'none') {
     17    imageUrls = [clickedImage.href];
     18
     19  } else if (groupMode === 'all') {
     20    const allImages = document.querySelectorAll('a[data-wepop]');
     21    imageUrls = Array.from(allImages).map(img => img.href);
    1822    currentIndex = imageUrls.indexOf(clickedImage.href);
    19   } else {
    20     imageUrls = [clickedImage.href];
    21     currentIndex = 0;
     23
     24  } else if (groupMode === 'gallery') {
     25    const galleryFigure = clickedImage.closest('.wp-block-gallery');
     26    if (galleryFigure) {
     27      const galleryImages = galleryFigure.querySelectorAll('a[data-wepop]');
     28      imageUrls = Array.from(galleryImages).map(img => img.href);
     29      currentIndex = imageUrls.indexOf(clickedImage.href);
     30    } else {
     31      imageUrls = [clickedImage.href];
     32    }
    2233  }
    23  
     34
    2435  showWepop(imageUrls, currentIndex);
    2536}
     
    2839  const overlay = document.createElement('div');
    2940  overlay.className = 'wepop-overlay';
    30  
     41
    3142  const content = document.createElement('div');
    3243  content.className = 'wepop-content';
    33  
     44
    3445  const imgContainer = document.createElement('div');
    3546  imgContainer.className = 'wepop-img-container';
    36  
     47
    3748  const img = document.createElement('img');
    3849  img.className = 'wepop-img';
    3950  img.src = imageUrls[currentIndex];
    4051  img.alt = '';
    41  
     52
    4253  imgContainer.appendChild(img);
    4354  content.appendChild(imgContainer);
    44  
     55
    4556  const closeBtn = document.createElement('button');
    4657  closeBtn.className = 'wepop-close';
    4758  closeBtn.innerHTML = '&times;';
    4859  closeBtn.addEventListener('click', closeWepop);
    49  
     60
    5061  overlay.appendChild(content);
    5162  overlay.appendChild(closeBtn);
    52  
     63
    5364  if (imageUrls.length > 1) {
    5465    const prevBtn = document.createElement('button');
    5566    prevBtn.className = 'wepop-prev';
    5667    prevBtn.addEventListener('click', () => changeImage(-1));
    57    
     68
    5869    const nextBtn = document.createElement('button');
    5970    nextBtn.className = 'wepop-next';
    6071    nextBtn.addEventListener('click', () => changeImage(1));
    61    
     72
    6273    overlay.appendChild(prevBtn);
    6374    overlay.appendChild(nextBtn);
    6475  }
    65  
     76
    6677  document.body.appendChild(overlay);
    67  
     78
    6879  setTimeout(() => {
    6980    overlay.classList.add('open');
     
    8192    }
    8293  });
    83  
     94
    8495  function closeWepop() {
    8596    overlay.classList.remove('open');
     
    8798      document.body.removeChild(overlay);
    8899    }, 300);
     100    document.removeEventListener('keydown', handleKeyPress);
    89101  }
    90  
     102
    91103  function changeImage(direction) {
    92104    const currentImg = imgContainer.querySelector('.wepop-img');
    93105    const nextIndex = (currentIndex + direction + imageUrls.length) % imageUrls.length;
    94    
     106
    95107    const nextImg = document.createElement('img');
    96108    nextImg.className = 'wepop-img wepop-img-next';
     
    98110    nextImg.alt = '';
    99111    nextImg.style.transform = `translateX(${direction > 0 ? '100%' : '-100%'})`;
    100    
     112
    101113    imgContainer.appendChild(nextImg);
    102 
    103     // Force a reflow
    104114    void nextImg.offsetWidth;
    105115
     
    128138    }
    129139  }
    130  
     140
    131141  if (typeof wedokPopSettings !== 'undefined' && wedokPopSettings.showAltText) {
    132142    const altTextElement = document.createElement('div');
     
    136146    content.appendChild(altTextElement);
    137147  }
    138  
     148
    139149  document.addEventListener('keydown', handleKeyPress);
    140  
     150
    141151  function handleKeyPress(e) {
    142152    if (e.key === 'Escape') {
     
    149159  }
    150160}
    151 
  • wepop/trunk/languages/de.po

    r3319334 r3321653  
     1#, fuzzy
    12msgid ""
    23msgstr ""
    34"Project-Id-Version: WePOP 1.5\n"
    4 "POT-Creation-Date: \n"
    5 "PO-Revision-Date: \n"
     5"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wepop\n"
     6"POT-Creation-Date: 2025-07-03 16:25+0900\n"
     7"PO-Revision-Date: 2025-07-03 17:12+0900\n"
    68"Last-Translator: \n"
    79"Language-Team: \n"
     
    1012"Content-Type: text/plain; charset=UTF-8\n"
    1113"Content-Transfer-Encoding: 8bit\n"
    12 "X-Generator: Poedit 3.5\n"
     14"Plural-Forms: nplurals=2; plural=(n != 1);\n"
     15"X-Generator: Poedit 3.6\n"
    1316
    1417msgid "WePOP Settings"
     
    1922
    2023msgid "Show Alt Text"
    21 msgstr "Alt-Text anzeigen"
     24msgstr "Alternativtext anzeigen"
    2225
    2326msgid "Display alt text below images"
    24 msgstr "Alt-Text unter den Bildern anzeigen"
    25 
    26 msgid "Gallery Only Grouping"
    27 msgstr "Nur Galerie gruppieren"
    28 
    29 msgid "Group only WordPress gallery images"
    30 msgstr "Nur WordPress-Galeriebilder gruppieren"
    31 
    32 msgid "Animation Type"
    33 msgstr "Animationstyp"
    34 
    35 msgid "Scale"
    36 msgstr "Skalieren"
    37 
    38 msgid "Fade"
    39 msgstr "Verblassen"
    40 
    41 msgid "Slide"
    42 msgstr "Gleiten"
     27msgstr "Alternativtext unter Bildern anzeigen"
    4328
    4429msgid "Language"
     
    5641msgid "Invalid request."
    5742msgstr "Ungültige Anfrage."
     43
     44msgid "Image Grouping Mode"
     45msgstr "Bildgruppierungsmodus"
     46
     47msgid "Group only gallery images (recommended)"
     48msgstr "Nur Galerie-Bilder gruppieren (empfohlen)"
     49
     50msgid ""
     51"Only images inside WordPress gallery blocks will be grouped into slideshows. "
     52"Each gallery will be grouped separately."
     53msgstr ""
     54"Nur Bilder innerhalb von WordPress-Galerieblöcken werden zu Diashows "
     55"gruppiert. Jede Galerie wird separat gruppiert."
     56
     57msgid "Group all images in the post"
     58msgstr "Alle Bilder im Beitrag gruppieren"
     59
     60msgid ""
     61"All images (both standalone and gallery) in the post will be grouped into "
     62"one slideshow."
     63msgstr ""
     64"Alle Bilder (einzeln und in Galerien) im Beitrag werden zu einer einzigen "
     65"Diashow gruppiert."
     66
     67msgid "No grouping"
     68msgstr "Keine Gruppierung"
     69
     70msgid "Disables all image grouping in the post. Each image opens individually."
     71msgstr ""
     72"Deaktiviert alle Bildgruppierungen im Beitrag. Jedes Bild wird einzeln "
     73"geöffnet."
  • wepop/trunk/languages/es.po

    r3319334 r3321653  
     1#, fuzzy
    12msgid ""
    23msgstr ""
    34"Project-Id-Version: WePOP 1.5\n"
    4 "POT-Creation-Date: \n"
    5 "PO-Revision-Date: \n"
     5"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wepop\n"
     6"POT-Creation-Date: 2025-07-03 16:25+0900\n"
     7"PO-Revision-Date: 2025-07-03 17:00+0900\n"
    68"Last-Translator: \n"
    79"Language-Team: \n"
     
    1012"Content-Type: text/plain; charset=UTF-8\n"
    1113"Content-Transfer-Encoding: 8bit\n"
    12 "X-Generator: Poedit 3.5\n"
     14"Plural-Forms: nplurals=2; plural=(n != 1);\n"
     15"X-Generator: Poedit 3.6\n"
    1316
    1417msgid "WePOP Settings"
     
    1619
    1720msgid "Settings saved."
    18 msgstr "Configuraciones guardadas."
     21msgstr "Configuración guardada."
    1922
    2023msgid "Show Alt Text"
     
    2326msgid "Display alt text below images"
    2427msgstr "Mostrar texto alternativo debajo de las imágenes"
    25 
    26 msgid "Gallery Only Grouping"
    27 msgstr "Agrupar solo galerías"
    28 
    29 msgid "Group only WordPress gallery images"
    30 msgstr "Agrupar solo imágenes de galería de WordPress"
    31 
    32 msgid "Animation Type"
    33 msgstr "Tipo de animación"
    34 
    35 msgid "Scale"
    36 msgstr "Escala"
    37 
    38 msgid "Fade"
    39 msgstr "Desvanecer"
    40 
    41 msgid "Slide"
    42 msgstr "Deslizar"
    4328
    4429msgid "Language"
     
    5641msgid "Invalid request."
    5742msgstr "Solicitud no válida."
     43
     44msgid "Image Grouping Mode"
     45msgstr "Modo de agrupación de imágenes"
     46
     47msgid "Group only gallery images (recommended)"
     48msgstr "Agrupar solo imágenes de la galería (recomendado)"
     49
     50msgid ""
     51"Only images inside WordPress gallery blocks will be grouped into slideshows. "
     52"Each gallery will be grouped separately."
     53msgstr ""
     54"Solo las imágenes dentro de bloques de galería de WordPress se agruparán en "
     55"presentaciones. Cada galería se agrupará por separado."
     56
     57msgid "Group all images in the post"
     58msgstr "Agrupar todas las imágenes en la entrada"
     59
     60msgid ""
     61"All images (both standalone and gallery) in the post will be grouped into "
     62"one slideshow."
     63msgstr ""
     64"Todas las imágenes (independientes y en galerías) en la entrada se agruparán "
     65"en una sola presentación."
     66
     67msgid "No grouping"
     68msgstr "Sin agrupación"
     69
     70msgid "Disables all image grouping in the post. Each image opens individually."
     71msgstr ""
     72"Desactiva toda la agrupación de imágenes en la entrada. Cada imagen se "
     73"abrirá individualmente."
  • wepop/trunk/languages/fr.po

    r3319334 r3321653  
     1#, fuzzy
    12msgid ""
    23msgstr ""
    34"Project-Id-Version: WePOP 1.5\n"
    4 "POT-Creation-Date: \n"
    5 "PO-Revision-Date: \n"
     5"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wepop\n"
     6"POT-Creation-Date: 2025-07-03 16:25+0900\n"
     7"PO-Revision-Date: 2025-07-03 17:05+0900\n"
    68"Last-Translator: \n"
    79"Language-Team: \n"
     
    1012"Content-Type: text/plain; charset=UTF-8\n"
    1113"Content-Transfer-Encoding: 8bit\n"
    12 "X-Generator: Poedit 3.5\n"
     14"Plural-Forms: nplurals=2; plural=(n > 1);\n"
     15"X-Generator: Poedit 3.6\n"
    1316
    1417msgid "WePOP Settings"
    15 msgstr "Paramètres WePOP"
     18msgstr "Paramètres de WePOP"
    1619
    1720msgid "Settings saved."
     
    2326msgid "Display alt text below images"
    2427msgstr "Afficher le texte alternatif sous les images"
    25 
    26 msgid "Gallery Only Grouping"
    27 msgstr "Grouper uniquement les galeries"
    28 
    29 msgid "Group only WordPress gallery images"
    30 msgstr "Grouper uniquement les images des galeries WordPress"
    31 
    32 msgid "Animation Type"
    33 msgstr "Type d'animation"
    34 
    35 msgid "Scale"
    36 msgstr "Échelle"
    37 
    38 msgid "Fade"
    39 msgstr "Fondu"
    40 
    41 msgid "Slide"
    42 msgstr "Diapositive"
    4328
    4429msgid "Language"
     
    5641msgid "Invalid request."
    5742msgstr "Requête invalide."
     43
     44msgid "Image Grouping Mode"
     45msgstr "Mode de regroupement des images"
     46
     47msgid "Group only gallery images (recommended)"
     48msgstr "Regrouper uniquement les images des galeries (recommandé)"
     49
     50msgid ""
     51"Only images inside WordPress gallery blocks will be grouped into slideshows. "
     52"Each gallery will be grouped separately."
     53msgstr ""
     54"Seules les images dans les blocs de galerie WordPress seront regroupées en "
     55"diaporamas. Chaque galerie sera regroupée séparément."
     56
     57msgid "Group all images in the post"
     58msgstr "Regrouper toutes les images de l’article"
     59
     60msgid ""
     61"All images (both standalone and gallery) in the post will be grouped into "
     62"one slideshow."
     63msgstr ""
     64"Toutes les images (indépendantes et en galerie) de l’article seront "
     65"regroupées en un seul diaporama."
     66
     67msgid "No grouping"
     68msgstr "Aucun regroupement"
     69
     70msgid "Disables all image grouping in the post. Each image opens individually."
     71msgstr ""
     72"Désactive tout regroupement d’images dans l’article. Chaque image s’ouvrira "
     73"individuellement."
  • wepop/trunk/languages/template.pot

    r3319334 r3321653  
     1#, fuzzy
    12msgid ""
    23msgstr ""
    34"Project-Id-Version: WePOP 1.5\n"
    45"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wepop\n"
    5 "POT-Creation-Date: 2024-01-23 12:00+0000\n"
    6 "PO-Revision-Date: 2024-01-23 12:00+0000\n"
    7 "Language: \n"
     6"POT-Creation-Date: 2025-07-03 16:25+0900\n"
     7"PO-Revision-Date: 2025-07-03 16:45+0900\n"
     8"Last-Translator: \n"
    89"Language-Team: \n"
    910"MIME-Version: 1.0\n"
     
    1112"Content-Transfer-Encoding: 8bit\n"
    1213"Plural-Forms: nplurals=1; plural=0;\n"
     14"X-Generator: Poedit 3.6\n"
    1315
    1416msgid "WePOP Settings"
     
    2224
    2325msgid "Display alt text below images"
    24 msgstr ""
    25 
    26 msgid "Gallery Only Grouping"
    27 msgstr ""
    28 
    29 msgid "Group only WordPress gallery images"
    30 msgstr ""
    31 
    32 msgid "Animation Type"
    33 msgstr ""
    34 
    35 msgid "Scale"
    36 msgstr ""
    37 
    38 msgid "Fade"
    39 msgstr ""
    40 
    41 msgid "Slide"
    4226msgstr ""
    4327
     
    5640msgid "Invalid request."
    5741msgstr ""
     42
     43msgid "Image Grouping Mode"
     44msgstr ""
     45
     46msgid "Group only gallery images (recommended)"
     47msgstr ""
     48
     49msgid "Only images inside WordPress gallery blocks will be grouped into slideshows. Each gallery will be grouped separately."
     50msgstr ""
     51
     52msgid "Group all images in the post"
     53msgstr ""
     54
     55msgid "All images (both standalone and gallery) in the post will be grouped into one slideshow."
     56msgstr ""
     57
     58msgid "No grouping"
     59msgstr ""
     60
     61msgid "Disables all image grouping in the post. Each image opens individually."
     62msgstr ""
  • wepop/trunk/languages/zh_CN.po

    r3319334 r3321653  
     1#, fuzzy
    12msgid ""
    23msgstr ""
    34"Project-Id-Version: WePOP 1.5\n"
    4 "POT-Creation-Date: \n"
    5 "PO-Revision-Date: \n"
     5"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wepop\n"
     6"POT-Creation-Date: 2025-07-03 16:25+0900\n"
     7"PO-Revision-Date: 2025-07-03 17:16+0900\n"
    68"Last-Translator: \n"
    79"Language-Team: \n"
     
    1012"Content-Type: text/plain; charset=UTF-8\n"
    1113"Content-Transfer-Encoding: 8bit\n"
    12 "X-Generator: Poedit 3.5\n"
     14"Plural-Forms: nplurals=1; plural=0;\n"
     15"X-Generator: Poedit 3.6\n"
    1316
    1417msgid "WePOP Settings"
     
    2225
    2326msgid "Display alt text below images"
    24 msgstr "在图像下方显示替代文本"
    25 
    26 msgid "Gallery Only Grouping"
    27 msgstr "仅分组图库"
    28 
    29 msgid "Group only WordPress gallery images"
    30 msgstr "仅分组 WordPress 图库图像"
    31 
    32 msgid "Animation Type"
    33 msgstr "动画类型"
    34 
    35 msgid "Scale"
    36 msgstr "缩放"
    37 
    38 msgid "Fade"
    39 msgstr "淡出"
    40 
    41 msgid "Slide"
    42 msgstr "滑动"
     27msgstr "在图片下方显示替代文本"
    4328
    4429msgid "Language"
     
    5540
    5641msgid "Invalid request."
    57 msgstr "无效请求。"
     42msgstr "无效的请求。"
     43
     44msgid "Image Grouping Mode"
     45msgstr "图片分组模式"
     46
     47msgid "Group only gallery images (recommended)"
     48msgstr "仅分组图库中的图片(推荐)"
     49
     50msgid ""
     51"Only images inside WordPress gallery blocks will be grouped into slideshows. "
     52"Each gallery will be grouped separately."
     53msgstr "只有 WordPress 图库模块中的图片会被分组为幻灯片。每个图库将分别分组。"
     54
     55msgid "Group all images in the post"
     56msgstr "分组文章中的所有图片"
     57
     58msgid ""
     59"All images (both standalone and gallery) in the post will be grouped into "
     60"one slideshow."
     61msgstr "文章中的所有图片(包括单独图片和图库)将被分组为一个幻灯片。"
     62
     63msgid "No grouping"
     64msgstr "不分组"
     65
     66msgid "Disables all image grouping in the post. Each image opens individually."
     67msgstr "禁用文章中的所有图片分组。每张图片将单独打开。"
  • wepop/trunk/readme.txt

    r3319461 r3321653  
    55Tested up to: 6.8.1
    66Requires PHP: 7.0
    7 Stable tag: 1.5.2
     7Stable tag: 1.5.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • wepop/trunk/wepop.php

    r3319334 r3321653  
    44Plugin URI: https://wedok.jp/tools/wepop/
    55Description: Simple image popup and gallery plugin for WordPress, built with pure JavaScript and no dependencies.
    6 Version: 1.5.2
     6Version: 1.5.3
    77Author: WeDOK Konta
    88Author URI: https://wedok.jp
     
    2323    $options = get_option('wedok_pop_settings', array());
    2424    $language = isset($options['language']) ? $options['language'] : 'ja';
    25     load_textdomain('wepop', plugin_dir_path(__FILE__) . 'languages/' . $language . '.mo');
     25
     26    // ファイル名マッピング(ja → ja_JP、それ以外はそのまま)
     27    $map = array(
     28        'ja'     => 'ja_JP',
     29        'en'     => 'en',
     30        'fr'     => 'fr',
     31        'de'     => 'de',
     32        'es'     => 'es',
     33        'zh_CN'  => 'zh_CN',
     34    );
     35
     36    $mo_file = isset($map[$language]) ? $map[$language] : 'ja_JP';
     37
     38    load_textdomain('wepop', plugin_dir_path(__FILE__) . 'languages/' . $mo_file . '.mo');
    2639}
    2740add_action('init', 'wedok_pop_load_textdomain');
    2841
     42// デフォルトオプション登録
    2943register_activation_hook(__FILE__, 'wedok_pop_activate');
    3044function wedok_pop_activate() {
    3145    $default_options = array(
    3246        'show_alt_text' => false,
    33         'gallery_only_grouping' => false,
     47        'group_mode' => 'gallery',
    3448        'language' => 'ja'
    3549    );
     
    3953}
    4054
     55// 画像に data-wepop 属性を付与
    4156function wedok_pop_add_attribute($content) {
    4257    $options = get_option('wedok_pop_settings', array());
    43     $galleryOnlyGrouping = !empty($options['gallery_only_grouping']);
     58    $groupMode = isset($options['group_mode']) ? $options['group_mode'] : 'gallery';
    4459
    45     if (!$galleryOnlyGrouping) {
     60    if ($groupMode === 'all') {
    4661        $groupId = uniqid('group-');
    4762        $content = preg_replace_callback(
    48             '/<a\s+[^>]*href=(\"|\')(.*?\.(jpg|jpeg|png|gif))\1[^>]*>/i',
     63            '/<a\s+[^>]*href=(\"|\')(.*?\.(jpg|jpeg|png|gif|webp))\1[^>]*>/i',
    4964            function ($matches) use ($groupId) {
    5065                if (strpos($matches[0], 'data-wepop') === false) {
     
    5570            $content
    5671        );
    57     } else {
     72    } elseif ($groupMode === 'none') {
    5873        $content = preg_replace_callback(
    59             '/<a\s+[^>]*href=(\"|\')(.*?\.(jpg|jpeg|png|gif))\1[^>]*>/i',
     74            '/<a\s+[^>]*href=(\"|\')(.*?\.(jpg|jpeg|png|gif|webp))\1[^>]*>/i',
    6075            function ($matches) {
    6176                if (strpos($matches[0], 'data-wepop') === false) {
     
    6681            $content
    6782        );
     83    } elseif ($groupMode === 'gallery') {
     84        // ギャラリー以外(=.wp-block-gallery で囲まれていない)画像リンクにのみ data-wepop を付与
     85        $content = preg_replace_callback(
     86            '/(<a\s+[^>]*href=(\"|\')(.*?\.(jpg|jpeg|png|gif|webp))\2[^>]*>)/i',
     87            function ($matches) {
     88                $anchor = $matches[1];
     89                if (strpos($anchor, 'data-wepop') !== false) {
     90                    return $anchor;
     91                }
     92                // ギャラリー内の画像を除外する(.wp-block-gallery に囲まれていないもの)
     93                if (!preg_match('/<figure[^>]*class=\"[^"]*wp-block-gallery[^"]*\"[^>]*>.*?' . preg_quote($anchor, '/') . '.*?<\/figure>/is', $anchor)) {
     94                    return str_replace('<a ', '<a data-wepop ', $anchor);
     95                }
     96                return $anchor;
     97            },
     98            $content
     99        );
    68100    }
     101
    69102    return $content;
    70103}
    71104add_filter('the_content', 'wedok_pop_add_attribute');
    72105
     106// Gutenbergギャラリーへの処理
    73107function wedok_pop_process_gutenberg_gallery($block_content, $block) {
    74108    if ($block['blockName'] !== 'core/gallery') {
     
    77111
    78112    $options = get_option('wedok_pop_settings', array());
    79     $galleryOnlyGrouping = !empty($options['gallery_only_grouping']);
     113    $groupMode = isset($options['group_mode']) ? $options['group_mode'] : 'gallery';
    80114
    81     if ($galleryOnlyGrouping) {
     115    if ($groupMode === 'gallery') {
    82116        $groupId = uniqid('gallery-');
    83117        $block_content = preg_replace(
     
    86120            $block_content
    87121        );
    88     } else {
     122    } elseif ($groupMode === 'all' || $groupMode === 'none') {
    89123        $block_content = preg_replace(
    90124            '/<a\s+(?![^>]*data-wepop)/i',
     
    98132add_filter('render_block', 'wedok_pop_process_gutenberg_gallery', 10, 2);
    99133
     134// [gallery] ショートコード対応
    100135function wedok_pop_filter_gallery_shortcode($output, $attr, $instance) {
    101136    $options = get_option('wedok_pop_settings', array());
    102     $galleryOnlyGrouping = !empty($options['gallery_only_grouping']);
     137    $groupMode = isset($options['group_mode']) ? $options['group_mode'] : 'gallery';
    103138
    104     if ($galleryOnlyGrouping) {
     139    if ($groupMode === 'gallery') {
    105140        $groupId = uniqid('gallery-');
    106141        $output = preg_replace(
     
    109144            $output
    110145        );
    111     } else {
     146    } elseif ($groupMode === 'all' || $groupMode === 'none') {
    112147        $output = preg_replace(
    113148            '/<a\s+(?![^>]*data-wepop)/i',
     
    116151        );
    117152    }
     153
    118154    return $output;
    119155}
    120156add_filter('post_gallery', 'wedok_pop_filter_gallery_shortcode', 10, 3);
    121157
     158// スクリプトとCSS読み込み
    122159function wedok_pop_enqueue_scripts() {
    123160    if (wedok_pop_should_apply()) {
     
    128165        wp_localize_script('wepop-lightbox', 'wedokPopSettings', array(
    129166            'showAltText' => !empty($options['show_alt_text']),
    130             'galleryOnlyGrouping' => !empty($options['gallery_only_grouping']),
     167            'groupMode' => isset($options['group_mode']) ? $options['group_mode'] : 'gallery',
    131168            'language' => isset($options['language']) ? $options['language'] : 'ja',
    132169        ));
     
    135172add_action('wp_enqueue_scripts', 'wedok_pop_enqueue_scripts');
    136173
     174// CSS出力
    137175function wedok_pop_print_styles() {
    138176    if (wp_style_is('wepop-style', 'registered')) {
     
    142180add_action('wp_footer', 'wedok_pop_print_styles');
    143181
     182// 適用条件:投稿・固定ページのみ
    144183function wedok_pop_should_apply() {
    145184    if (is_front_page() || is_home()) {
Note: See TracChangeset for help on using the changeset viewer.