/* ============================================================ * インポート画面 * ============================================================ */ function fanza_import_page() { $date_from = isset($_POST['date_from']) ? $_POST['date_from'] : ''; $date_to = isset($_POST['date_to']) ? $_POST['date_to'] : ''; echo '
' . esc_html($result) . '
カテゴリ名 | 記事数 | カテゴリID |
---|---|---|
' . esc_html($cat->name) . ' | '; echo '' . intval($cat->count) . ' | '; echo '' . intval($cat->term_id) . ' | '; echo '
まだFANZA APIから作成されたカテゴリはありません。
'; } } /* ============================================================ * 当日商品自動取得 * ============================================================ */ function fanza_auto_import_today() { $today = current_time('Y-m-d'); // サイトTZ基準の“今日” $auto_import_status = get_fanza_option('auto_import_status'); fanza_add_import_log("自動取得開始 (当日: {$today}, 公開状態: {$auto_import_status})"); try { $result = fanza_fetch_and_insert_posts($today, $today, $auto_import_status); fanza_add_import_log("自動取得完了: " . $result); return $result; } catch (Exception $e) { $error_message = "自動取得エラー: " . $e->getMessage(); fanza_add_import_log($error_message); return $error_message; } } /* ============================================================ * ログ * ============================================================ */ function fanza_add_import_log($message) { $logs = get_option('fanza_auto_import_logs', array()); $logs[] = array( 'date' => current_time('Y-m-d H:i:s'), 'message' => $message ); if (count($logs) > 100) { $logs = array_slice($logs, -100); } update_option('fanza_auto_import_logs', $logs); } /* ============================================================ * APIレート/制限(簡易) * ============================================================ */ function fanza_check_api_limits() { $last_request_time = get_option('fanza_last_api_request', 0); $current_time = time(); if (($current_time - $last_request_time) < 1) { sleep(1); } update_option('fanza_last_api_request', $current_time); $daily_key = 'fanza_daily_requests_' . current_time('Ymd'); // サイトTZで日替わり $daily_requests = get_option($daily_key, 0); if ($daily_requests > 1000) { // 仮想的な日次制限 return false; } update_option($daily_key, $daily_requests + 1); return true; } /* ============================================================ * エラーハンドリング(補助) * ============================================================ */ function fanza_handle_api_error($response_code, $error_message = '') { $errors = array( '100' => 'APIIDが間違っています', '101' => 'アフィリエイトIDが間違っています', '102' => 'サービスが見つかりません', '103' => 'フロアが見つかりません', '900' => 'APIの呼び出し回数が上限に達しました', '999' => 'システムエラーが発生しました' ); if (isset($errors[$response_code])) { return 'FANZA API エラー [' . $response_code . ']: ' . $errors[$response_code]; } return 'FANZA API エラー: ' . $error_message; } function fanza_debug_api_response($url, $data) { if (defined('WP_DEBUG') && WP_DEBUG) { error_log('FANZA API Request URL: ' . $url); error_log('FANZA API Response: ' . json_encode($data, JSON_UNESCAPED_UNICODE)); } } /* ============================================================ * APIデータ取得・投稿登録(全件取得) * - Dedup Coreと連携:比較コード+日付±60日、既存ヘルパOR検索 * ============================================================ */ function fanza_fetch_and_insert_posts($date_from = null, $date_to = null, $post_status = 'publish') { // --- 二重起動ガード(DUGA方式に準拠) --- if (function_exists('fanza_acquire_lock') && !fanza_acquire_lock(10)) { fanza_add_import_log("スキップ:ロック中(前回処理がまだ動作)"); return '前回処理が稼働中のためスキップしました。'; } // --- チェックポイント再開(ブックマーク) --- $bookmark = get_option('fanza_import_bookmark', array()); if (!$date_from && !$date_to && !empty($bookmark['openstt']) && !empty($bookmark['openend'])) { $date_from = $bookmark['openstt']; $date_to = $bookmark['openend']; $offset = isset($bookmark['offset']) ? (int)$bookmark['offset'] : 1; } else { if (!empty($bookmark) && (($bookmark['openstt'] ?? '') !== $date_from || ($bookmark['openend'] ?? '') !== $date_to)) { $offset = 1; delete_option('fanza_import_bookmark'); } } // --- 時間予算(秒) --- $start_time = time(); $time_budget = (int) apply_filters('fanza_time_budget', 50); // ログ $is_auto_import = ($date_from && $date_to && $date_from === current_time('Ymd') && $date_to === current_time('Ymd')); fanza_add_import_log("取得開始 - hits={$hits}, offset={$offset}, カテゴリフィルタ: " . ($category_filter_enabled ? "有効" : "無効") . ", 自動取得: " . ($is_auto_import ? "はい" : "いいえ")); $endpoint = 'https://api.dmm.com/affiliate/v3/ItemList'; $hits = 100; // 開始ログ($hits/$offset 初期化後に出力) $is_auto_import = ($date_from && $date_to && $date_from === current_time('Ymd') && $date_to === current_time('Ymd')); fanza_add_import_log("取得開始 - hits={$hits}, offset={$offset}, カテゴリフィルタ: " . ($category_filter_enabled ? "有効" : "無効") . ", 自動取得: " . ($is_auto_import ? "はい" : "いいえ")); $offset = 1; $total_fetched = 0; $add_count = 0; $update_count = 0; $total_items = null; $api_id = get_fanza_option('api_id'); $affiliate_id = get_fanza_option('affiliate_id'); $site = get_fanza_option('site'); $category_filter_enabled = get_option('fanza_category_filter_enabled', 0); $filter_categories = get_option('fanza_filter_categories', array()); $exclude_categories = get_option('fanza_exclude_categories', array()); while (true) { if (!fanza_check_api_limits()) { return 'APIリクエストの日次上限(仮想)に達しました。'; } $params = [ 'api_id' => $api_id, 'affiliate_id' => $affiliate_id, 'site' => $site, 'service' => 'digital', 'floor' => 'videoa', 'output' => 'json', 'hits' => $hits, 'offset' => $offset, 'sort' => 'date', ]; if ($date_from) $params['gte_date'] = $date_from . 'T00:00:00'; if ($date_to) $params['lte_date'] = $date_to . 'T23:59:59'; $url = $endpoint . '?' . http_build_query($params); $response = wp_remote_get($url, array('timeout' => 30)); if (is_wp_error($response)) { $msg = 'APIリクエスト失敗: ' . $response->get_error_message(); if (function_exists('fanza_release_lock')) { fanza_release_lock(); } return $msg; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); if (isset($data['result']) && isset($data['result']['result_count'])) { fanza_add_import_log("API total(推定): " . intval($data['result']['result_count'])); }if (isset($data['result']['total_count']) && $total_items === null) { $total_items = intval($data['result']['total_count']); } if (empty($data['result']['items'])) break; foreach ($data['result']['items'] as $item) { // ▼ 1) カテゴリマスタ登録(フィルタ前) fanza_register_item_categories_to_master($item); // ▼ 2) カテゴリフィルタ if ($category_filter_enabled) { if (!fanza_should_include_item_by_category($item, $filter_categories, $exclude_categories)) { fanza_add_import_log("カテゴリフィルタでスキップ: " . (isset($item['title']) ? $item['title'] : '(no title)')); continue; } } // ▼ 3) Dedup:タイトル正規化・比較コード抽出・同一候補検索 $fanza_title_for_compare = $item['title'] ?? ''; $signature = function_exists('product_signature') ? product_signature($fanza_title_for_compare) : substr(sha1($fanza_title_for_compare), 0, 16); $title_normalized = function_exists('normalize_product_title') ? normalize_product_title($fanza_title_for_compare) : mb_strtolower(trim($fanza_title_for_compare), 'UTF-8'); // content_id → comparable_code_normalized(h_1324skmj00636 → SKMJ636 等) $comparable_code_normalized = ''; if (!empty($item['content_id']) && function_exists('normalize_comparable_code')) { $comparable_code_normalized = normalize_comparable_code($item['content_id']); } // FANZA側の基準日 $ref_date = $item['date'] ?? ''; $existing = []; $post_id = 0; // ★ 追加:コード一致+日付±60日で既存候補(DUGA由来も含む)を検索 if ($comparable_code_normalized && $ref_date && function_exists('find_existing_by_code_and_date')) { $post_id = find_existing_by_code_and_date($comparable_code_normalized, $ref_date, 60); } // 既存ヘルパOR検索(ID/シグネチャ/正規化キー含む) if (!$post_id && function_exists('find_existing_product_post')) { $post_id = find_existing_product_post([ 'fanza_content_id' => $item['content_id'] ?? '', 'signature' => $signature, 'title_normalized' => $title_normalized, 'comparable_code_normalized' => $comparable_code_normalized, ]); } if ($post_id) { $existing = [ (object)['ID' => (int)$post_id] ]; } else { // メタ: content_id で最後のフォールバック $existing = get_posts([ 'post_type' => 'post', 'meta_key' => 'content_id', 'meta_value' => $item['content_id'] ?? '', 'posts_per_page' => 1, 'post_status' => 'any', ]); } // ▼ 4) 追加/更新 if (!empty($existing)) { $post_id = (int)$existing[0]->ID; $category_ids = get_or_create_fanza_categories($item); wp_update_post([ 'ID' => $post_id, 'post_title' => $item['title'], 'post_content' => isset($item['comment']) ? $item['comment'] : '', 'post_category' => $category_ids, 'post_status' => $post_status, ]); set_fanza_taxonomies($post_id, $item); $update_count++; } else { $category_ids = get_or_create_fanza_categories($item); $post_id = wp_insert_post([ 'post_title' => $item['title'], 'post_content' => isset($item['comment']) ? $item['comment'] : '', 'post_type' => 'post', 'post_status' => $post_status, 'post_category' => $category_ids, ]); if ($post_id) { set_fanza_taxonomies($post_id, $item); } $add_count++; } if (!empty($post_id)) { update_post_meta($post_id, 'product_signature', $signature); } // ▼ 5) メタ保存(Dedup Coreのプレフィクス保存を優先) if ($post_id) { $meta_fields = [ 'content_id' => $item['content_id'] ?? '', 'product_id' => $item['product_id'] ?? '', 'url' => $item['URL'] ?? '', 'affiliateURL' => $item['affiliateURL'] ?? '', 'price' => isset($item['prices']['price']) ? $item['prices']['price'] : '', 'list_price' => isset($item['prices']['list_price']) ? $item['prices']['list_price'] : '', 'maker_name' => isset($item['iteminfo']['maker'][0]['name']) ? $item['iteminfo']['maker'][0]['name'] : '', 'maker_id' => isset($item['iteminfo']['maker'][0]['id']) ? $item['iteminfo']['maker'][0]['id'] : '', 'date' => $item['date'] ?? '', 'volume' => isset($item['volume']) ? $item['volume'] : '', 'review_count' => isset($item['review']['count']) ? $item['review']['count'] : 0, 'review_average' => isset($item['review']['average']) ? $item['review']['average'] : 0, // 正規化メタ 'title_normalized' => $title_normalized, 'comparable_code_normalized' => $comparable_code_normalized, ]; // fanza_* の“カノニカル”は個別保存で直書き update_post_meta($post_id, 'fanza_title_normalized', $title_normalized); update_post_meta($post_id, 'fanza_code_normalized', $comparable_code_normalized); // maker_product の確実な保存 $meta_fields['maker_product'] = isset($item['maker_product']) ? sanitize_text_field($item['maker_product']) : ''; if (defined('WP_DEBUG') && WP_DEBUG) { error_log('FANZA API - maker_product: ' . ($meta_fields['maker_product'] !== '' ? $meta_fields['maker_product'] : 'NOT SET') . ' / content_id: ' . ($item['content_id'] ?? '')); } // 画像各種 if (!empty($item['imageURL'])) { $meta_fields['imageURL_small'] = $item['imageURL']['small'] ?? ''; $meta_fields['imageURL_large'] = $item['imageURL']['large'] ?? ''; $meta_fields['imageURL_list'] = $item['imageURL']['list'] ?? ''; } // サンプル画像 if (!empty($item['sampleImageURL'])) { if (isset($item['sampleImageURL']['sample_s'])) { $meta_fields['sampleImageURL_s'] = json_encode($item['sampleImageURL']['sample_s'], JSON_UNESCAPED_UNICODE); } if (isset($item['sampleImageURL']['sample_l'])) { $meta_fields['sampleImageURL_l'] = json_encode($item['sampleImageURL']['sample_l'], JSON_UNESCAPED_UNICODE); } } // サンプル動画 if (!empty($item['sampleMovieURL'])) { foreach (['size_476_306'=>'sampleMovieURL_476_306','size_560_360'=>'sampleMovieURL_560_360','size_644_414'=>'sampleMovieURL_644_414','size_720_480'=>'sampleMovieURL_720_480'] as $k => $mk) { if (isset($item['sampleMovieURL'][$k])) $meta_fields[$mk] = $item['sampleMovieURL'][$k]; } } // 出演者 $actress_names = []; $actress_ids = []; if (!empty($item['iteminfo']['actress'])) { foreach ($item['iteminfo']['actress'] as $actress) { if (!empty($actress['name'])) $actress_names[] = sanitize_text_field($actress['name']); if (!empty($actress['id'])) $actress_ids[] = sanitize_text_field($actress['id']); } } $meta_fields['actress_name'] = implode(', ', $actress_names); $meta_fields['actress_id'] = implode(', ', $actress_ids); $meta_fields['actress_name_json'] = json_encode($actress_names, JSON_UNESCAPED_UNICODE); $meta_fields['actress_id_json'] = json_encode($actress_ids, JSON_UNESCAPED_UNICODE); $meta_fields['actress_count'] = count($actress_names); for ($i = 0; $i < min(5, count($actress_names)); $i++) { $meta_fields['actress_name_' . ($i + 1)] = $actress_names[$i]; if (isset($actress_ids[$i])) { $meta_fields['actress_id_' . ($i + 1)] = $actress_ids[$i]; } } // シリーズ(先頭のみ) if (!empty($item['iteminfo']['series'][0])) { $meta_fields['series_name'] = sanitize_text_field($item['iteminfo']['series'][0]['name'] ?? ''); $meta_fields['series_id'] = sanitize_text_field($item['iteminfo']['series'][0]['id'] ?? ''); } // レーベル(メーカー) if (!empty($item['iteminfo']['label'][0])) { $meta_fields['label_name'] = $item['iteminfo']['label'][0]['name'] ?? ''; $meta_fields['label_id'] = $item['iteminfo']['label'][0]['id'] ?? ''; } // 監督 if (!empty($item['iteminfo']['director'][0])) { $meta_fields['director_name'] = $item['iteminfo']['director'][0]['name'] ?? ''; $meta_fields['director_id'] = $item['iteminfo']['director'][0]['id'] ?? ''; } // JAN if (!empty($item['jancode'])) { $meta_fields['jancode'] = $item['jancode']; } // ジャンル $genre_names = []; $genre_ids = []; if (!empty($item['iteminfo']['genre'])) { foreach ($item['iteminfo']['genre'] as $genre) { if (!empty($genre['name'])) $genre_names[] = sanitize_text_field($genre['name']); if (!empty($genre['id'])) $genre_ids[] = sanitize_text_field($genre['id']); } } $meta_fields['genre_name'] = implode(', ', $genre_names); $meta_fields['genre_id'] = implode(', ', $genre_ids); $meta_fields['genre_name_json'] = json_encode($genre_names, JSON_UNESCAPED_UNICODE); $meta_fields['genre_id_json'] = json_encode($genre_ids, JSON_UNESCAPED_UNICODE); if (function_exists('upsert_meta_prefixed')) { upsert_meta_prefixed($post_id, $meta_fields, 'fanza'); } else { foreach ($meta_fields as $key => $value) { update_post_meta($post_id, $key, $value); } } } $total_fetched++; } if ($total_items !== null && $total_fetched >= $total_items) break; if (count($data['result']['items']) < $hits) break; // --- 時間予算を超えそうなら安全に中断(次回用ブックマークを保存) --- if ((time() - $start_time) > $time_budget) { fanza_add_import_log("時間予算で一旦終了:次回 offset=" . ($offset + $hits)); update_option('fanza_import_bookmark', array('openstt'=>$date_from, 'openend'=>$date_to, 'offset'=>$offset + $hits)); if (function_exists('fanza_release_lock')) { fanza_release_lock(); } $__result_msg = $add_count . '件を新規追加、' . $update_count . '件を更新しました。(' . $total_fetched . '件取得/時間予算中断)'; fanza_add_import_log("取得完了: " . $__result_msg); return $__result_msg; } $offset += $hits; sleep(1); // API制限対応 } // 完走できたらブックマーク削除 delete_option('fanza_import_bookmark'); if (function_exists('fanza_release_lock')) { fanza_release_lock(); } return $add_count . '件を新規追加、' . $update_count . '件を更新しました。(' . $total_fetched . '件取得)'; } /* ============================================================ * スケジュールイベント * ============================================================ */ add_action('fanza_auto_import_event', function() { if (get_fanza_option('auto_import_enabled')) { fanza_auto_import_today(); } }); add_action('fanza_daily_import_event', function() { $today = current_time('Y-m-d'); // サイトTZ fanza_fetch_and_insert_posts($today, $today); }); /* ============================================================ * 補助:出演者 * ============================================================ */ function get_fanza_performers($post_id) { $names = get_post_meta($post_id, 'actress_name', true); if ($names) return explode(', ', $names); $json_names = get_post_meta($post_id, 'actress_name_json', true); if ($json_names) return json_decode($json_names, true); return []; } function display_fanza_performers($post_id, $separator = ', ') { $performers = get_fanza_performers($post_id); return implode($separator, array_map('esc_html', $performers)); } /* ============================================================ * カテゴリ作成(WPカテゴリ=ジャンル群) * ============================================================ */ function get_or_create_fanza_categories($item) { $category_ids = array(); if (!empty($item['iteminfo']['genre'])) { foreach ($item['iteminfo']['genre'] as $genre) { if (!empty($genre['name'])) { $category_name = sanitize_text_field($genre['name']); $existing_category = get_category_by_slug(sanitize_title($category_name)); if ($existing_category) { $category_ids[] = $existing_category->term_id; } else { $new_category = wp_insert_category(array( 'cat_name' => $category_name, 'category_nicename' => sanitize_title($category_name), 'category_description' => 'FANZA APIから自動作成されたカテゴリ: ' . $category_name )); if (!is_wp_error($new_category) && $new_category != 0) { $category_ids[] = $new_category; error_log('FANZA API: 新規カテゴリ作成 - ' . $category_name . ' (ID: ' . $new_category . ')'); } } } } } if (empty($category_ids)) { $category_ids[] = 1; // 未分類 } return $category_ids; } function get_fanza_categories_stats() { global $wpdb; $categories = $wpdb->get_results(" SELECT t.name, t.term_id, tt.count, tt.description FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'category' AND tt.description LIKE '%FANZA APIから自動作成%' ORDER BY tt.count DESC "); return $categories; } /* ============================================================ * タクソノミー付与(共用タクソノミーに紐付け) * ============================================================ */ function set_fanza_taxonomies($post_id, $item) { // 出演者 if (!empty($item['iteminfo']['actress'])) { $actress_terms = array(); foreach ($item['iteminfo']['actress'] as $actress) { if (!empty($actress['name'])) { $actress_name = sanitize_text_field($actress['name']); $actress_id = !empty($actress['id']) ? sanitize_text_field($actress['id']) : ''; $term = get_or_create_fanza_term($actress_name, 'actress', array( 'description' => 'FANZA出演者ID: ' . $actress_id )); if ($term && !is_wp_error($term)) { $actress_terms[] = $term['term_id']; } } } if (!empty($actress_terms)) { wp_set_object_terms($post_id, $actress_terms, 'actress'); } } // シリーズ if (!empty($item['iteminfo']['series'])) { $series_terms = array(); foreach ($item['iteminfo']['series'] as $series) { if (!empty($series['name'])) { $series_name = sanitize_text_field($series['name']); $series_id = !empty($series['id']) ? sanitize_text_field($series['id']) : ''; $term = get_or_create_fanza_term($series_name, 'series', array( 'description' => 'FANZAシリーズID: ' . $series_id )); if ($term && !is_wp_error($term)) { $series_terms[] = $term['term_id']; } } } if (!empty($series_terms)) { wp_set_object_terms($post_id, $series_terms, 'series'); } } // メーカー → label タクソノミーに if (!empty($item['iteminfo']['maker'])) { $maker_terms = array(); foreach ($item['iteminfo']['maker'] as $maker) { if (!empty($maker['name'])) { $maker_name = sanitize_text_field($maker['name']); $maker_id = !empty($maker['id']) ? sanitize_text_field($maker['id']) : ''; $term = get_or_create_fanza_term($maker_name, 'label', array( 'description' => 'FANZAメーカーID: ' . $maker_id )); if ($term && !is_wp_error($term)) { $maker_terms[] = $term['term_id']; } } } if (!empty($maker_terms)) { wp_set_object_terms($post_id, $maker_terms, 'label'); } } // ジャンル if (!empty($item['iteminfo']['genre'])) { $genre_terms = array(); foreach ($item['iteminfo']['genre'] as $genre) { if (!empty($genre['name'])) { $genre_name = sanitize_text_field($genre['name']); $genre_id = !empty($genre['id']) ? sanitize_text_field($genre['id']) : ''; $term = get_or_create_fanza_term($genre_name, 'genre', array( 'description' => 'FANZAジャンルID: ' . $genre_id )); if ($term && !is_wp_error($term)) { $genre_terms[] = $term['term_id']; } } } if (!empty($genre_terms)) { wp_set_object_terms($post_id, $genre_terms, 'genre'); } } } function get_or_create_fanza_term($term_name, $taxonomy, $args = array()) { $existing_term = get_term_by('name', $term_name, $taxonomy); if ($existing_term) { return array('term_id' => $existing_term->term_id); } $new_term = wp_insert_term($term_name, $taxonomy, $args); if (!is_wp_error($new_term)) { error_log('FANZA API: 新規' . $taxonomy . '作成 - ' . $term_name . ' (ID: ' . $new_term['term_id'] . ')'); return $new_term; } return false; } function get_fanza_taxonomy_stats() { $stats = array(); // 共用タクソノミー名で集計 $taxonomies = array('actress', 'series', 'label', 'genre'); foreach ($taxonomies as $taxonomy) { $terms = get_terms(array( 'taxonomy' => $taxonomy, 'hide_empty' => false, 'orderby' => 'count', 'order' => 'DESC', 'number' => 10 )); $stats[$taxonomy] = $terms; } return $stats; } /* ============================================================ * ダッシュボードウィジェット * ============================================================ */ add_action('wp_dashboard_setup', function() { if (current_user_can('manage_options')) { wp_add_dashboard_widget( 'fanza_auto_import_status', 'FANZA自動取得状況', 'fanza_dashboard_widget' ); } }); function fanza_dashboard_widget() { $auto_import_enabled = get_fanza_option('auto_import_enabled'); $auto_import_time = get_fanza_option('auto_import_time'); $next_scheduled = wp_next_scheduled('fanza_auto_import_event'); echo '自動取得: '; if ($auto_import_enabled) { echo '有効 (毎日 ' . esc_html($auto_import_time) . ')'; } else { echo '無効'; } echo '
'; if ($next_scheduled) { echo '次回実行予定: ' . wp_date('Y年m月d日 H:i', $next_scheduled, wp_timezone()) . '
'; } $logs = get_option('fanza_auto_import_logs', array()); if (!empty($logs)) { echo '最新ログ:
'; echo 'この投稿はFANZA商品ではありません。
'; return; } $product_id = get_post_meta($post->ID, 'product_id', true); $affiliateURL = get_post_meta($post->ID, 'affiliateURL', true); $price = get_post_meta($post->ID, 'price', true); $list_price = get_post_meta($post->ID, 'list_price', true); $maker_name = get_post_meta($post->ID, 'maker_name', true); $maker_product = get_post_meta($post->ID, 'maker_product', true); $date = get_post_meta($post->ID, 'date', true); $volume = get_post_meta($post->ID, 'volume', true); $review_count = get_post_meta($post->ID, 'review_count', true); $review_average = get_post_meta($post->ID, 'review_average', true); echo 'コンテンツID: | ' . esc_html($content_id) . ' |
商品ID: | ' . esc_html($product_id) . ' |
メーカー品番: | ' . esc_html($maker_product) . ' |
価格: | ¥' . esc_html($price) . ' |
定価: | ¥' . esc_html($list_price) . ' |
メーカー: | ' . esc_html($maker_name) . ' |
配信開始日: | ' . esc_html($date) . ' |
収録時間: | ' . esc_html($volume) . ' |
レビュー数: | ' . esc_html($review_count) . '件 |
平均評価: | ' . esc_html($review_average) . '点 |
商品画像:
'; echo 'FANZA商品情報が見つかりません。
'; $output = ''; if ($atts['field'] === 'all' || $atts['field'] === 'basic') { $affiliateURL = get_post_meta($post_id, 'affiliateURL', true); $price = get_post_meta($post_id, 'price', true); $maker_name = get_post_meta($post_id, 'maker_name', true); $maker_product= get_post_meta($post_id, 'maker_product', true); $date = get_post_meta($post_id, 'date', true); $output .= 'メーカー: ' . esc_html($maker_name) . '
'; if ($maker_product) $output .= 'メーカー品番: ' . esc_html($maker_product) . '
'; if ($price) $output .= '価格: ¥' . esc_html($price) . '
'; if ($date) $output .= '配信開始: ' . esc_html($date) . '
'; if ($affiliateURL) $output .= ''; $output .= '出演者: ' . $performers . '
'; } } return $output; }); // 画像 add_shortcode('fanza_product_image', function($atts) { $atts = shortcode_atts(array( 'id' => get_the_ID(), 'size' => 'large', 'class' => 'fanza-product-image' ), $atts); $post_id = intval($atts['id']); $image_field = 'imageURL_' . $atts['size']; $image_url = get_post_meta($post_id, $image_field, true); if (!$image_url) { foreach (['large','list','small'] as $size) { $image_url = get_post_meta($post_id, 'imageURL_' . $size, true); if ($image_url) break; } } if ($image_url) { return '出演: ' . $performers . '
'; } if ($atts['show_maker_product'] === 'true' && $maker_product) { $output .= '品番: ' . esc_html($maker_product) . '
'; } if ($atts['show_price'] === 'true' && $price) { $output .= '¥' . esc_html($price) . '
'; } if ($affiliateURL) { $output .= ''; } $output .= '該当する商品が見つかりませんでした。
'; return $output; }); /* ============================================================ * REST API * ============================================================ */ add_action('rest_api_init', function() { register_rest_route('fanza/v1', '/products', array( 'methods' => 'GET', 'callback' => 'fanza_rest_get_products', 'permission_callback' => '__return_true' )); register_rest_route('fanza/v1', '/product/(?P