Plugin Directory

Changeset 3314285


Ignore:
Timestamp:
06/19/2025 05:15:48 AM (9 months ago)
Author:
itmaroon
Message:

update commit new files and folders

Location:
post-migration/trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • post-migration/trunk/assets/js/post-mi-script.js

    r3295494 r3314285  
    373373              // Object.entries() を使って key-value をループ
    374374              for (const [key, value] of Object.entries(postData.acf_fields)) {
    375                 if (regex.test(value)) {
    376                   // 正規表現でマッチするかチェック
    377                   const file = await extractMediaFile(value);
    378                   // すでに同じファイル名が存在するかをチェック
    379                   const isDuplicate = mediaData.some(
    380                     (existingFile) => existingFile.name === file.name
    381                   );
    382                   if (!isDuplicate) {
    383                     mediaData.push(file);
     375                if (Array.isArray(value)) {
     376                  for (const media_path of value) {
     377                    if (regex.test(media_path)) {
     378                      // 正規表現でマッチするかチェック
     379                      const file = await extractMediaFile(media_path);
     380                      // すでに同じファイル名が存在するかをチェック
     381                      const isDuplicate = mediaData.some(
     382                        (existingFile) => existingFile.name === file.name
     383                      );
     384                      if (!isDuplicate) {
     385                        mediaData.push(file);
     386                      }
     387                    }
     388                  }
     389                } else {
     390                  if (regex.test(value)) {
     391                    // 正規表現でマッチするかチェック
     392                    const file = await extractMediaFile(value);
     393                    // すでに同じファイル名が存在するかをチェック
     394                    const isDuplicate = mediaData.some(
     395                      (existingFile) => existingFile.name === file.name
     396                    );
     397                    if (!isDuplicate) {
     398                      mediaData.push(file);
     399                    }
    384400                  }
    385401                }
  • post-migration/trunk/composer.lock

    r3306091 r3314285  
    8686        {
    8787            "name": "itmar/wpsetting-class-package",
    88             "version": "v1.2.5",
     88            "version": "v1.3.1",
    8989            "source": {
    9090                "type": "git",
    9191                "url": "https://github.com/itmaroon/wpsetting-class-package.git",
    92                 "reference": "be1ab7d46a9ce60465d975a3a26236c635c58169"
     92                "reference": "15b4b285066bd652de9c2f89edb71f9e15667c26"
    9393            },
    9494            "dist": {
    9595                "type": "zip",
    96                 "url": "https://api.github.com/repos/itmaroon/wpsetting-class-package/zipball/be1ab7d46a9ce60465d975a3a26236c635c58169",
    97                 "reference": "be1ab7d46a9ce60465d975a3a26236c635c58169",
     96                "url": "https://api.github.com/repos/itmaroon/wpsetting-class-package/zipball/15b4b285066bd652de9c2f89edb71f9e15667c26",
     97                "reference": "15b4b285066bd652de9c2f89edb71f9e15667c26",
    9898                "shasum": ""
    9999            },
     
    120120            "support": {
    121121                "issues": "https://github.com/itmaroon/wpsetting-class-package/issues",
    122                 "source": "https://github.com/itmaroon/wpsetting-class-package/tree/v1.2.5"
     122                "source": "https://github.com/itmaroon/wpsetting-class-package/tree/v1.3.1"
    123123            },
    124             "time": "2025-05-23T02:21:11+00:00"
     124            "time": "2025-06-19T05:02:18+00:00"
    125125        }
    126126    ],
  • post-migration/trunk/post-migration.php

    r3306091 r3314285  
    55Requires at least: 6.4
    66Requires PHP:      8.2
    7 Version:      1.0.1
     7Version:      1.1.0
    88Author:       Web Creator ITmaroon
    99Author URI:   https://itmaroon.net
     
    571571                $media_urls[] = $media_url;
    572572              }
     573            } elseif ($field_object['type'] === 'gallery') {
     574              $gallery        = get_field($key, $post->ID);
     575              foreach ($gallery as $value) {
     576                $media_url  = is_numeric($value) ? wp_get_attachment_url($value) : (is_array($value) && isset($value['url']) ? $value['url'] : $value);
     577                if ($media_url) {
     578                  $relative_path                    = 'exported_media/' . basename($media_url);
     579                  $post_data['acf_fields'][$key][] = $relative_path;
     580                  $media_urls[] = $media_url;
     581                }
     582              }
    573583            } elseif ($field_object['type'] === 'group') {
    574584              $post_data['acf_fields'][$key] = '_group';
  • post-migration/trunk/readme.txt

    r3306091 r3314285  
    44Requires at least: 6.4
    55Tested up to: 6.8
    6 Stable tag: 1.0.1
     6Stable tag: 1.1.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5454== Changelog ==
    5555
     56= 1.1.0 =
     57Added functionality to ensure proper export and import when gallery is used as an ACF custom field type.
     58
    5659= 1.0.1 =
    5760Update due to the version upgrade of the composer package of wpsetting-class-package
    58 
     61 
    5962= 1.0.0 =
    6063* Release
  • post-migration/trunk/vendor/composer/installed.json

    r3306091 r3314285  
    8686        {
    8787            "name": "itmar/wpsetting-class-package",
    88             "version": "v1.2.5",
    89             "version_normalized": "1.2.5.0",
     88            "version": "v1.3.1",
     89            "version_normalized": "1.3.1.0",
    9090            "source": {
    9191                "type": "git",
    9292                "url": "https://github.com/itmaroon/wpsetting-class-package.git",
    93                 "reference": "be1ab7d46a9ce60465d975a3a26236c635c58169"
     93                "reference": "15b4b285066bd652de9c2f89edb71f9e15667c26"
    9494            },
    9595            "dist": {
    9696                "type": "zip",
    97                 "url": "https://api.github.com/repos/itmaroon/wpsetting-class-package/zipball/be1ab7d46a9ce60465d975a3a26236c635c58169",
    98                 "reference": "be1ab7d46a9ce60465d975a3a26236c635c58169",
     97                "url": "https://api.github.com/repos/itmaroon/wpsetting-class-package/zipball/15b4b285066bd652de9c2f89edb71f9e15667c26",
     98                "reference": "15b4b285066bd652de9c2f89edb71f9e15667c26",
    9999                "shasum": ""
    100100            },
     
    102102                "itmar/loader-package": "^1.0"
    103103            },
    104             "time": "2025-05-23T02:21:11+00:00",
     104            "time": "2025-06-19T05:02:18+00:00",
    105105            "type": "library",
    106106            "installation-source": "dist",
     
    123123            "support": {
    124124                "issues": "https://github.com/itmaroon/wpsetting-class-package/issues",
    125                 "source": "https://github.com/itmaroon/wpsetting-class-package/tree/v1.2.5"
     125                "source": "https://github.com/itmaroon/wpsetting-class-package/tree/v1.3.1"
    126126            },
    127127            "install-path": "../itmar/wpsetting-class-package"
  • post-migration/trunk/vendor/composer/installed.php

    r3306091 r3314285  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => 'fed24b753d0df1eb8f6ced0a027ee03a23b60489',
     6        'reference' => '4da18f909e01e3e6514a50f3255c612ded28f9ce',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-master',
    1515            'version' => 'dev-master',
    16             'reference' => 'fed24b753d0df1eb8f6ced0a027ee03a23b60489',
     16            'reference' => '4da18f909e01e3e6514a50f3255c612ded28f9ce',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
     
    3939        ),
    4040        'itmar/wpsetting-class-package' => array(
    41             'pretty_version' => 'v1.2.5',
    42             'version' => '1.2.5.0',
    43             'reference' => 'be1ab7d46a9ce60465d975a3a26236c635c58169',
     41            'pretty_version' => 'v1.3.1',
     42            'version' => '1.3.1.0',
     43            'reference' => '15b4b285066bd652de9c2f89edb71f9e15667c26',
    4444            'type' => 'library',
    4545            'install_path' => __DIR__ . '/../itmar/wpsetting-class-package',
  • post-migration/trunk/vendor/itmar/wpsetting-class-package/README.md

    r3295494 r3314285  
    2121
    2222## 変更履歴
     23
     24= 1.3.1 = 
     25ItmarDbActionクラスのset_mediaメソッドの$file_path引数に配列がセットされたときの処理を新たに加えた
     26
     27= 1.3.0 = 
     28ItmarDbCacheクラスを新たに加えた
    2329
    2430= 1.2.0 = 
     
    142148set_media($media_array, $post_id, $file_path, $media_type)   
    143149$media_arrayで渡されたアップロードファイルの配列から、ファイル名が$file_pathと一致するものを選び出し、メディアライブラリに登録するとともに、$post_idのIDをもつ投稿に関連付ける。関連付けの方法は次の3とおり。
     150$file_pathが配列で複数のメディアのパスを渡した場合にも対応する。
    144151- アイキャッチ画像
    145152$media_typeがthumbnail
     
    264271```
    265272
    266  
    267 
    268 
    269 
    270 
    271 
    272 
    273  
     273### 名前空間・クラス 
     274\Itmar\WpSettingClassPackage\ItmarDbCache
     275
     276#### クラスの概要 
     277`ItmarDbCache` は `$wpdb` を用いた WordPress の DB 操作にキャッシュ機構を付加するためのユーティリティクラスです。Plugin Check で警告されがちな直接DB呼び出しに対し、キャッシュ処理 (`wp_cache_get` / `wp_cache_set` / `wp_cache_delete`) を適切に加えることで、パフォーマンスとコード品質を両立させます。
     278
     279---
     280
     281#### メソッドの説明 
     282
     283---
     284
     285### `get_var_cached($sql, $cache_key, $expire = 3600)` 
     286SQL文字列を実行し、結果をキャッシュ付きで1行1列取得する。
     287
     288##### 引数 
     289- `string $sql` : 実行するSQL(`$wpdb->prepare()`済み推奨) 
     290- `string $cache_key` : キャッシュキー 
     291- `int $expire` : キャッシュの有効期間(秒)
     292
     293##### 戻り値 
     294- `mixed` : 結果行の1カラム目の値
     295
     296##### 使用例 
     297```php
     298$sql = $wpdb->prepare("SHOW TABLES LIKE %s", $table_name);
     299$result = ItmarDbCache::get_var_cached($sql, 'table_exists_' . md5($table_name));
     300```
     301
     302---
     303
     304### `get_row_cached($sql, $cache_key, $expire = 3600, $output = ARRAY_A)` 
     305SQL文字列を実行し、1行のデータをキャッシュ付きで取得する。
     306
     307##### 引数 
     308- `string $sql` : 実行するSQL 
     309- `string $cache_key` : キャッシュキー 
     310- `int $expire` : キャッシュの有効期間(秒) 
     311- `string $output` : 返却形式。`OBJECT`, `ARRAY_A`, `ARRAY_N` のいずれか(デフォルト:`ARRAY_A`)
     312
     313##### 戻り値 
     314- `mixed` : 1行の結果データ
     315
     316##### 使用例 
     317```php
     318$sql = $wpdb->prepare("SELECT * FROM {$table} WHERE token = %s", $token);
     319$row = ItmarDbCache::get_row_cached($sql, 'row_token_' . md5($token));
     320```
     321
     322---
     323
     324### `update_and_clear_cache($table, $data, $where, ?array $data_format = null, ?array $where_format = null, array $cache_keys = [])` 
     325レコードを更新し、指定したキャッシュキーのキャッシュを削除する。
     326
     327##### 引数 
     328- `string $table` : 対象テーブル名 
     329- `array $data` : 更新データ 
     330- `array $where` : WHERE 条件 
     331- `?array $data_format` : 更新データのフォーマット(`%s`など) 
     332- `?array $where_format` : WHERE 条件のフォーマット 
     333- `array $cache_keys` : 削除対象のキャッシュキー配列
     334
     335##### 戻り値 
     336- `int|false` : 成功時は更新された行数、失敗時は false
     337
     338##### 使用例 
     339```php
     340$result = ItmarDbCache::update_and_clear_cache(
     341    $wpdb->users,
     342    ['user_pass' => $hashed_password],
     343    ['ID' => $user_id],
     344    ['%s'],
     345    ['%d'],
     346    ['user_cache_' . $user_id]
     347);
     348```
     349
     350---
     351
     352### `delete_and_clear_cache($table, $where, ?array $where_format = null, array $cache_keys = [])` 
     353レコードを削除し、指定したキャッシュキーのキャッシュを削除する。
     354
     355##### 引数 
     356- `string $table` : 対象テーブル名 
     357- `array $where` : WHERE 条件 
     358- `?array $where_format` : WHERE 条件のフォーマット 
     359- `array $cache_keys` : 削除対象のキャッシュキー配列
     360
     361##### 戻り値 
     362- `int|false` : 削除された行数、または失敗時は false
     363
     364##### 使用例 
     365```php
     366$result = ItmarDbCache::delete_and_clear_cache(
     367    $table,
     368    ['id' => $row['id']],
     369    ['%d'],
     370    ['row_token_' . md5($row['token'])]
     371);
     372```
     373
     374---
     375
     376### `set_cache_group($group)` 
     377キャッシュのグループ名を変更する。
     378
     379##### 引数 
     380- `string $group` : グループ名(デフォルトは `itmar_cache`)
     381
     382##### 戻り値 
     383- なし
     384
     385##### 使用例 
     386```php
     387ItmarDbCache::set_cache_group('my_plugin_group');
     388```
     389
     390
     391 
     392
     393
     394
     395
     396
     397
     398 
  • post-migration/trunk/vendor/itmar/wpsetting-class-package/src/ItmarDbAction.php

    r3306091 r3314285  
    177177                                    'value' => $value
    178178                                ];
     179                            } else if (is_array($value)) {
     180                                $image_arr = [];
     181                                foreach ($value as $elm) {
     182                                    if (is_string($elm) && preg_match('/exported_media\/(.+?\.[a-zA-Z0-9]+)/u', $elm, $matches)) { //メディアフィールド
     183                                        $image_arr[] = $elm;
     184                                    }
     185                                }
     186                                $acf_mediaURLs[] = [
     187                                    'key' => $key,
     188                                    'value' => $image_arr
     189                                ];
    179190                            }
    180191                        }
     
    233244                if ($content_path) {
    234245                    $media_result = $this->set_media($uploaded_medias, $new_post_id, $content_path, "content");
    235                     $updated_content = str_replace($content_path, $media_result['attachment_url'], $updated_content);
     246                    $updated_content = str_replace($content_path, $media_result['attachment_url'][0], $updated_content);
    236247                    $error_logs[] = $media_result['message'];
    237248                }
     
    276287        add_filter('wp_image_editors', [$this, 'force_gd_editor']);
    277288
     289        //$file_pathが配列の時に備えてすべて配列で対応
     290        $file_names = [];
    278291        //acf_fieldのときはオブジェクトが来るのでそれに対応
    279292        if ($media_type === 'acf_field') {
    280             $file_name = basename($file_path['value']);
    281293            $acf_field = $file_path['key'];
     294            $acf_paths = $file_path['value'];
     295            if (is_array($acf_paths)) { //$file_pathが配列の時(gallery対応)
     296                foreach ($acf_paths as $acf_path) {
     297                    $file_names[] = basename($acf_path);
     298                }
     299            } else {
     300                $file_names[] = basename($acf_paths);
     301            }
    282302        } else {
    283             $file_name = basename($file_path);
    284         }
    285 
    286         // `name` キーに `$file_name` が一致する要素を検索
    287         $matched_files = array_filter($media_array, function ($file) use ($file_name) {
    288             return $file['name'] === $file_name;
    289         });
    290         // 1つだけ取得
    291         $file = reset($matched_files) ?: null;
    292         //取得できなければ終了
    293         if (is_null($file)) {
    294             return array(
    295                 "status" => 'error',
    296                 "message" => esc_html__("File not found (file name:", "wpsetting-class-package") . $file_name . ")",
    297             );
    298         }
    299 
    300         $upload_dir = wp_upload_dir();
    301         $dest_path = $upload_dir['path'] . '/' . basename($file['name']);
    302 
    303 
    304         if (file_exists($dest_path)) {
    305             //既に同じ名前のファイルが存在したらアップロードしない
    306             $attachment_id = $this->get_attachment_id_by_file_path($dest_path);
    307             if ($attachment_id) {
    308                 $result = 'success';
    309                 $message = esc_html__("Processing stopped due to existing file found (media ID:", "wpsetting-class-package") . $attachment_id . ")";
    310             }
    311         } else {
    312             // wp_handle_upload の前準備
    313             require_once(ABSPATH . 'wp-admin/includes/file.php');
    314             require_once(ABSPATH . 'wp-admin/includes/image.php');
    315 
    316             $upload_overrides = array('test_form' => false);
    317             $movefile = wp_handle_upload($file, $upload_overrides);
    318 
    319             if ($movefile && !isset($movefile['error'])) {
    320                 $dest_path = $movefile['file'];
    321                 $file_name = isset($file['name']) ? $file['name'] : basename($dest_path);
    322                 $filetype = wp_check_filetype(basename($dest_path), null);
    323 
    324                 $attachment = array(
    325                     'post_mime_type' => $filetype['type'],
    326                     'post_title'     => sanitize_file_name($file_name),
    327                     'post_content'   => '',
    328                     'post_status'    => 'inherit'
     303            $file_names[] = basename($file_path);
     304        }
     305
     306        //$attachment_idをストックする配列
     307        $attachment_ids = [];
     308        foreach ($file_names as $file_name) {
     309            // `name` キーに `$file_name` が一致する要素を検索
     310            $matched_files = array_filter($media_array, function ($file) use ($file_name) {
     311                return $file['name'] === $file_name;
     312            });
     313            // 1つだけ取得
     314            $file = reset($matched_files) ?: null;
     315            //取得できなければ終了
     316            if (is_null($file)) {
     317                return array(
     318                    "status" => 'error',
     319                    "message" => esc_html__("File not found (file name:", "wpsetting-class-package") . $file_name . ")",
    329320                );
    330 
    331                 $attachment_id = wp_insert_attachment($attachment, $dest_path);
    332                 $attach_data = wp_generate_attachment_metadata($attachment_id, $dest_path);
    333                 wp_update_attachment_metadata($attachment_id, $attach_data);
    334 
    335                 // 成功時のレスポンス
    336                 $result = 'success';
    337                 $message  = esc_html__("File uploaded", "wpsetting-class-package");
    338             } else {
    339                 $result = 'error';
    340                 $message  = esc_html__("Failed to upload file", "wpsetting-class-package");
     321            }
     322
     323            $upload_dir = wp_upload_dir();
     324            $dest_path = $upload_dir['path'] . '/' . basename($file['name']);
     325
     326            if (file_exists($dest_path)) {
     327                //既に同じ名前のファイルが存在したらアップロードしない
     328                $attachment_id = $this->get_attachment_id_by_file_path($dest_path);
     329                if ($attachment_id) {
     330                    $result = 'success';
     331                    $message = esc_html__("Processing stopped due to existing file found (media ID:", "wpsetting-class-package") . $attachment_id . ")";
     332                }
     333                $attachment_ids[] = $attachment_id;
     334            } else {
     335                // wp_handle_upload の前準備
     336                require_once(ABSPATH . 'wp-admin/includes/file.php');
     337                require_once(ABSPATH . 'wp-admin/includes/image.php');
     338
     339                $upload_overrides = array('test_form' => false);
     340                $movefile = wp_handle_upload($file, $upload_overrides);
     341
     342                if ($movefile && !isset($movefile['error'])) {
     343                    $dest_path = $movefile['file'];
     344                    $file_name = isset($file['name']) ? $file['name'] : basename($dest_path);
     345                    $filetype = wp_check_filetype(basename($dest_path), null);
     346
     347                    $attachment = array(
     348                        'post_mime_type' => $filetype['type'],
     349                        'post_title'     => sanitize_file_name($file_name),
     350                        'post_content'   => '',
     351                        'post_status'    => 'inherit'
     352                    );
     353
     354                    $attachment_id = wp_insert_attachment($attachment, $dest_path);
     355                    $attach_data = wp_generate_attachment_metadata($attachment_id, $dest_path);
     356                    wp_update_attachment_metadata($attachment_id, $attach_data);
     357                    $attachment_ids[] = $attachment_id;
     358                    // 成功時のレスポンス
     359                    $result = 'success';
     360                    $message  = esc_html__("File uploaded", "wpsetting-class-package");
     361                } else {
     362                    $result = 'error';
     363                    $message  = esc_html__("Failed to upload file", "wpsetting-class-package");
     364                }
    341365            }
    342366        }
    343367
    344368        // 投稿データにメディア情報を反映
    345         $attachment_url = wp_get_attachment_url($attachment_id);
    346         if ($attachment_id) {
     369
     370        if ($attachment_ids) {
    347371            if ($media_type === 'thumbnail') {
    348                 set_post_thumbnail($post_id, $attachment_id);
     372                set_post_thumbnail($post_id, $attachment_ids[0]);
    349373                $message = esc_html__('Upload thumbnail: ', "wpsetting-class-package") . $message;
    350374            } elseif ($media_type === 'content') {
     
    352376            } elseif ($media_type === 'acf_field') {
    353377                if (!empty($acf_field)) {
    354                     update_field($acf_field, $attachment_id, $post_id);
     378                    if (count($attachment_ids) > 1) {
     379                        update_field($acf_field, $attachment_ids, $post_id);
     380                    } else {
     381                        update_field($acf_field, $attachment_ids[0], $post_id);
     382                    }
     383
    355384                    $message = esc_html__('Uploading acf media: ', "wpsetting-class-package") . $message;
    356385                }
     
    360389        // フィルターを元に戻す
    361390        remove_filter('wp_image_editors', [$this, 'force_gd_editor']);
     391        //呼び出しもとに返すためにURLを取得
     392        $attachment_urls = [];
     393        foreach ($attachment_ids as $attachment_id) {
     394            $attachment_urls[] = wp_get_attachment_url($attachment_id);
     395        }
    362396
    363397        return array(
    364398            "status" => $result,
    365399            "message" => $message,
    366             "attachment_id" => $attachment_id,
    367             "attachment_url" => $attachment_url,
     400            "attachment_id" => $attachment_ids,
     401            "attachment_url" => $attachment_urls,
    368402        );
    369403    }
  • post-migration/trunk/vendor/itmar/wpsetting-class-package/src/ItmarRedirectControl.php

    r3306091 r3314285  
    7979        // すでに index.php が存在する場合はエラー
    8080        if (file_exists($this->index_php_path)) {
    81             $needle = "require __DIR__ . '/{$subdir}/wp-blog-header.php';";
     81            //$needle = "require __DIR__ . '/{$subdir}/wp-blog-header.php';";
    8282            $contents = file_get_contents($this->index_php_path);
    8383
    84             if (strpos($contents, $needle) !== false) {
     84            $pattern = '/require\s+__DIR__\s*\.\s*[\'"]\/\s*' . preg_quote($subdir, '/') . '\s*\/wp-blog-header\.php[\'"];/';
     85            if (preg_match($pattern, $contents)) {
     86
    8587                // ファイルが存在し、require 文も含まれている
    8688                return true;
Note: See TracChangeset for help on using the changeset viewer.