设置该字段组在哪些页面的编辑界面中显示。此设置不改变前台页面布局,也不会删除已有字段数据。
+ 'all', 'page_ids' => [] ]; ?> + +按住 Ctrl(Windows)或 Command(Mac)可选择多个页面。选择“仅在指定页面显示”时,至少选择一个页面。
+按住 Ctrl(Windows)或 Command(Mac)可选择多个页面。选择“仅在指定页面显示”时,至少选择一个页面。
From 7ac4e71aa08c08c7954a9175488580cac6a211e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 10:15:38 +0800 Subject: [PATCH 11/40] style: format field group location controls --- assets/css/admin.css | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/assets/css/admin.css b/assets/css/admin.css index 4233cce..088bd53 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -445,3 +445,27 @@ grid-template-columns: repeat(2, minmax(0, 1fr)); } } + + +/* Field group location rules */ +.wem-cf-location-options { + display: flex; + flex-wrap: wrap; + gap: 16px; + margin: 12px 0 16px; +} +.wem-cf-location-options label { + display: inline-flex; + align-items: center; + gap: 6px; +} +.wem-cf-location-pages { + max-width: 640px; +} +.wem-cf-location-pages select { + width: 100%; + min-height: 140px; +} +.wem-cf-location-pages[hidden] { + display: none !important; +} From 450e45dc8862f2e47d9a3b3714ed466bb9118147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 10:16:07 +0800 Subject: [PATCH 12/40] feat: export portable page location references --- includes/transfer/class-exporter.php | 29 ++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/includes/transfer/class-exporter.php b/includes/transfer/class-exporter.php index 7dcdd01..f8077e1 100644 --- a/includes/transfer/class-exporter.php +++ b/includes/transfer/class-exporter.php @@ -15,7 +15,7 @@ public function __construct( Storage $storage ) { } /** - * Build a portable Schema v1 export package from stored definitions only. + * Build a portable Schema v2 export package from stored definitions only. * Runtime definitions injected by filters are intentionally excluded. */ public function package( array $selected_keys = [] ): array { @@ -27,7 +27,7 @@ public function package( array $selected_keys = [] ): array { if ( '' === $key || ! isset( $stored[ $key ] ) || ! is_array( $stored[ $key ] ) ) { continue; } - $groups[ $key ] = $stored[ $key ]; + $groups[ $key ] = $this->portable_group( $stored[ $key ] ); } return [ @@ -39,6 +39,31 @@ public function package( array $selected_keys = [] ): array { ]; } + /** + * Replace site-local Page IDs with path references for portable JSON. + */ + private function portable_group( array $group ): array { + $location = isset( $group['location'] ) && is_array( $group['location'] ) ? $group['location'] : [ 'mode' => 'all' ]; + if ( 'specific_pages' === ( $location['mode'] ?? 'all' ) ) { + $refs = []; + foreach ( array_map( 'absint', (array) ( $location['page_ids'] ?? [] ) ) as $page_id ) { + $page = get_post( $page_id ); + if ( ! $page || 'page' !== $page->post_type ) { + continue; + } + $refs[] = [ + 'path' => trim( (string) get_page_uri( $page_id ), '/' ), + 'slug' => (string) $page->post_name, + 'title' => (string) $page->post_title, + ]; + } + $group['location'] = [ 'mode' => 'specific_pages', 'page_refs' => $refs ]; + } else { + $group['location'] = [ 'mode' => 'all' ]; + } + return $group; + } + public function json( array $selected_keys = [] ) { $package = $this->package( $selected_keys ); From aceb4ac2978bbd7d80119d9f87e4fed856801826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 10:16:09 +0800 Subject: [PATCH 13/40] feat: import schema v1 and v2 location rules --- includes/transfer/class-importer.php | 32 +++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/includes/transfer/class-importer.php b/includes/transfer/class-importer.php index 5b5fded..35d5fb0 100644 --- a/includes/transfer/class-importer.php +++ b/includes/transfer/class-importer.php @@ -36,7 +36,7 @@ public function inspect_json( string $json ) { } $schema_version = isset( $data['schema_version'] ) ? absint( $data['schema_version'] ) : 0; - if ( WEM_CF_SCHEMA_VERSION !== $schema_version ) { + if ( ! in_array( $schema_version, [ 1, WEM_CF_SCHEMA_VERSION ], true ) ) { return new \WP_Error( 'unsupported_schema', sprintf( '当前插件支持 Schema v%d,该文件为 Schema v%d。', WEM_CF_SCHEMA_VERSION, $schema_version ) @@ -48,6 +48,36 @@ public function inspect_json( string $json ) { return new \WP_Error( 'no_groups', '导入文件中没有字段组。' ); } + + if ( 2 === $schema_version ) { + foreach ( $raw_groups as $group_key => &$raw_group ) { + if ( ! is_array( $raw_group ) ) { + continue; + } + $location = isset( $raw_group['location'] ) && is_array( $raw_group['location'] ) ? $raw_group['location'] : [ 'mode' => 'all' ]; + if ( 'specific_pages' !== ( $location['mode'] ?? 'all' ) ) { + $raw_group['location'] = [ 'mode' => 'all' ]; + continue; + } + $page_ids = []; + foreach ( (array) ( $location['page_refs'] ?? [] ) as $page_ref ) { + if ( ! is_array( $page_ref ) || '' === trim( (string) ( $page_ref['path'] ?? '' ) ) ) { + return new \\WP_Error( 'invalid_page_reference', sprintf( '字段组 %s 包含无效的页面引用,未执行导入。', sanitize_key( (string) $group_key ) ) ); + } + $page = get_page_by_path( trim( (string) $page_ref['path'], '/' ), OBJECT, 'page' ); + if ( ! $page || 'page' !== $page->post_type ) { + return new \\WP_Error( 'page_reference_not_found', sprintf( '字段组 %s 引用的页面“%s”在目标站点不存在。请先创建该页面,或在目标站点手动创建字段组。', sanitize_key( (string) $group_key ), sanitize_text_field( (string) ( $page_ref['title'] ?? $page_ref['path'] ) ) ) ); + } + $page_ids[] = (int) $page->ID; + } + if ( empty( $page_ids ) ) { + return new \\WP_Error( 'page_reference_empty', sprintf( '字段组 %s 没有可匹配的指定页面,未执行导入。', sanitize_key( (string) $group_key ) ) ); + } + $raw_group['location'] = [ 'mode' => 'specific_pages', 'page_ids' => array_values( array_unique( $page_ids ) ) ]; + } + unset( $raw_group ); + } + $groups = $this->normalizer->groups( $raw_groups ); if ( empty( $groups ) ) { return new \WP_Error( 'no_valid_groups', '导入文件中没有可识别的字段组。' ); From 368e691ba0b2d732d0524d4e37adc5a0af1c302d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 10:16:12 +0800 Subject: [PATCH 14/40] feat: bump export schema to v2 for location rules --- wem-content-fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wem-content-fields.php b/wem-content-fields.php index 1f7d479..a950006 100644 --- a/wem-content-fields.php +++ b/wem-content-fields.php @@ -15,7 +15,7 @@ } define( 'WEM_CF_VERSION', '1.0.0' ); -define( 'WEM_CF_SCHEMA_VERSION', 1 ); +define( 'WEM_CF_SCHEMA_VERSION', 2 ); define( 'WEM_CF_FILE', __FILE__ ); define( 'WEM_CF_PATH', plugin_dir_path( __FILE__ ) ); define( 'WEM_CF_URL', plugin_dir_url( __FILE__ ) ); From 290652e98cfae965825eddf9f42fa9d7f15d5037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 10:16:24 +0800 Subject: [PATCH 15/40] fix: require Page content type for page location rules --- includes/class-validator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/class-validator.php b/includes/class-validator.php index c168655..444ebd2 100644 --- a/includes/class-validator.php +++ b/includes/class-validator.php @@ -62,6 +62,9 @@ public function validate_group( array $input, array $existing_groups = [], ?stri $location_mode = 'all'; } $page_ids = array_values( array_unique( array_filter( array_map( 'absint', (array) ( $raw_location['page_ids'] ?? [] ) ) ) ) ); + if ( 'specific_pages' === $location_mode && ! in_array( 'page', $post_types, true ) ) { + $errors->add( 'location_post_type_required', '指定页面显示条件必须关联 WordPress 的“页面(Page)”内容类型。' ); + } if ( 'specific_pages' === $location_mode && empty( $page_ids ) ) { $errors->add( 'location_pages_required', '请选择至少一个指定页面。' ); } From d0662e527e331397e856ca8e1159437b569c8f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 10:16:34 +0800 Subject: [PATCH 16/40] docs: describe field group location rules in development --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 7c59efc..5b44c30 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,18 @@ 当前稳定版本:**v1.0.0** Schema:**v1** +## 字段组显示条件(开发中) + +当前功能分支正在为字段组增加页面级显示条件: + +- 默认模式:字段组显示在已关联的内容类型中,保持原有行为。 +- 指定页面模式:字段组仅显示在所选 WordPress Page 的编辑界面。 +- 显示条件只影响后台字段组的适用范围,不会删除已有文章的字段值。 +- JSON Schema v2 使用页面路径引用来迁移指定页面规则;目标站点找不到对应页面时会中止导入,避免意外扩大显示范围。 +- Schema v1 导入仍兼容,旧字段组默认按原来的全局关联规则处理。 + +此功能目前处于独立开发分支,尚未合并到 `main`,请勿将该说明视为已发布版本的现成功能。 + ## 项目定位 ```text From 0994bd2777146308defcffb31573cd4e11385307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 10:16:54 +0800 Subject: [PATCH 17/40] fix: correct importer error class namespace From ab4c2c806346d0eb917d3cec00fd118efd68e5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 10:52:54 +0800 Subject: [PATCH 18/40] fix: correct PHP namespace escaping in importer --- includes/transfer/class-importer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/transfer/class-importer.php b/includes/transfer/class-importer.php index 35d5fb0..a80dc45 100644 --- a/includes/transfer/class-importer.php +++ b/includes/transfer/class-importer.php @@ -62,16 +62,16 @@ public function inspect_json( string $json ) { $page_ids = []; foreach ( (array) ( $location['page_refs'] ?? [] ) as $page_ref ) { if ( ! is_array( $page_ref ) || '' === trim( (string) ( $page_ref['path'] ?? '' ) ) ) { - return new \\WP_Error( 'invalid_page_reference', sprintf( '字段组 %s 包含无效的页面引用,未执行导入。', sanitize_key( (string) $group_key ) ) ); + return new \WP_Error( 'invalid_page_reference', sprintf( '字段组 %s 包含无效的页面引用,未执行导入。', sanitize_key( (string) $group_key ) ) ); } $page = get_page_by_path( trim( (string) $page_ref['path'], '/' ), OBJECT, 'page' ); if ( ! $page || 'page' !== $page->post_type ) { - return new \\WP_Error( 'page_reference_not_found', sprintf( '字段组 %s 引用的页面“%s”在目标站点不存在。请先创建该页面,或在目标站点手动创建字段组。', sanitize_key( (string) $group_key ), sanitize_text_field( (string) ( $page_ref['title'] ?? $page_ref['path'] ) ) ) ); + return new \WP_Error( 'page_reference_not_found', sprintf( '字段组 %s 引用的页面“%s”在目标站点不存在。请先创建该页面,或在目标站点手动创建字段组。', sanitize_key( (string) $group_key ), sanitize_text_field( (string) ( $page_ref['title'] ?? $page_ref['path'] ) ) ) ); } $page_ids[] = (int) $page->ID; } if ( empty( $page_ids ) ) { - return new \\WP_Error( 'page_reference_empty', sprintf( '字段组 %s 没有可匹配的指定页面,未执行导入。', sanitize_key( (string) $group_key ) ) ); + return new \WP_Error( 'page_reference_empty', sprintf( '字段组 %s 没有可匹配的指定页面,未执行导入。', sanitize_key( (string) $group_key ) ) ); } $raw_group['location'] = [ 'mode' => 'specific_pages', 'page_ids' => array_values( array_unique( $page_ids ) ) ]; } From d6d081ccf92f2d1d9ae2b160004c8ae4d92d25d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:13:53 +0800 Subject: [PATCH 19/40] fix: fail closed on invalid location modes --- includes/class-normalizer.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/class-normalizer.php b/includes/class-normalizer.php index 4a5d8dd..88c357e 100644 --- a/includes/class-normalizer.php +++ b/includes/class-normalizer.php @@ -33,8 +33,12 @@ static function ( $value ): bool { ) ); - $location = isset( $input['location'] ) && is_array( $input['location'] ) ? $input['location'] : []; - $location_mode = $this->scalar_string( $location['mode'] ?? 'all' ); + $has_location = isset( $input['location'] ) && is_array( $input['location'] ); + $location = $has_location ? $input['location'] : []; + $location_mode = $has_location ? $this->scalar_string( $location['mode'] ?? '' ) : 'all'; + if ( ! in_array( $location_mode, [ 'all', 'specific_pages' ], true ) ) { + $location_mode = $has_location ? 'invalid' : 'all'; + } $page_ids = array_values( array_unique( array_filter( array_map( 'absint', (array) ( $location['page_ids'] ?? [] ) ) ) ) ); return [ @@ -43,7 +47,7 @@ static function ( $value ): bool { 'description' => $this->scalar_string( $input['description'] ?? '' ), 'post_types' => array_values( array_unique( $post_types ) ), 'location' => [ - 'mode' => in_array( $location_mode, [ 'all', 'specific_pages' ], true ) ? $location_mode : 'all', + 'mode' => $location_mode, 'page_ids' => $page_ids, ], 'fields' => $fields, From ef0b1a769fff4bc1f2462628462c74db2693b3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:13:55 +0800 Subject: [PATCH 20/40] fix: skip groups with invalid location rules From 4450ad79b7c5683a9b2a3a1d99c610ea28002c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:13:57 +0800 Subject: [PATCH 21/40] fix: restrict page rules to Pages only --- includes/class-validator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-validator.php b/includes/class-validator.php index 444ebd2..62c2274 100644 --- a/includes/class-validator.php +++ b/includes/class-validator.php @@ -62,8 +62,8 @@ public function validate_group( array $input, array $existing_groups = [], ?stri $location_mode = 'all'; } $page_ids = array_values( array_unique( array_filter( array_map( 'absint', (array) ( $raw_location['page_ids'] ?? [] ) ) ) ) ); - if ( 'specific_pages' === $location_mode && ! in_array( 'page', $post_types, true ) ) { - $errors->add( 'location_post_type_required', '指定页面显示条件必须关联 WordPress 的“页面(Page)”内容类型。' ); + if ( 'specific_pages' === $location_mode && ( [ 'page' ] !== $post_types ) ) { + $errors->add( 'location_post_type_required', '使用“仅在指定页面显示”时,应用到内容类型必须只选择 Pages。' ); } if ( 'specific_pages' === $location_mode && empty( $page_ids ) ) { $errors->add( 'location_pages_required', '请选择至少一个指定页面。' ); From c5bb0ea76004cba6353623a548810d8b0041daeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:14:00 +0800 Subject: [PATCH 22/40] fix: fail closed for invalid REST location rules --- includes/class-registry.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/class-registry.php b/includes/class-registry.php index d8e0e3f..623500e 100644 --- a/includes/class-registry.php +++ b/includes/class-registry.php @@ -59,9 +59,13 @@ private function register_field( string $post_type, array $field, array $locatio if ( ! current_user_can( $capability ) || ! current_user_can( 'edit_post', (int) $post_id ) ) { return false; } - if ( 'specific_pages' !== ( $location['mode'] ?? 'all' ) ) { + $mode = (string) ( $location['mode'] ?? 'all' ); + if ( 'all' === $mode ) { return true; } + if ( 'specific_pages' !== $mode ) { + return false; + } return 'page' === $post_type && in_array( (int) $post_id, array_map( 'absint', (array) ( $location['page_ids'] ?? [] ) ), true ); }; From f7938a9481ddb7d8111eb0cf853d669d96dfe417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:14:02 +0800 Subject: [PATCH 23/40] fix: preserve invalid location state in export --- includes/transfer/class-exporter.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/transfer/class-exporter.php b/includes/transfer/class-exporter.php index f8077e1..c59bd79 100644 --- a/includes/transfer/class-exporter.php +++ b/includes/transfer/class-exporter.php @@ -58,8 +58,10 @@ private function portable_group( array $group ): array { ]; } $group['location'] = [ 'mode' => 'specific_pages', 'page_refs' => $refs ]; - } else { + } elseif ( 'all' === ( $location['mode'] ?? 'all' ) ) { $group['location'] = [ 'mode' => 'all' ]; + } else { + $group['location'] = [ 'mode' => 'invalid' ]; } return $group; } From ace56babd079637a7d55fe095d5fa25ebec06b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:14:04 +0800 Subject: [PATCH 24/40] fix: reject invalid location rules during import --- includes/transfer/class-importer.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/transfer/class-importer.php b/includes/transfer/class-importer.php index a80dc45..fefabef 100644 --- a/includes/transfer/class-importer.php +++ b/includes/transfer/class-importer.php @@ -55,7 +55,10 @@ public function inspect_json( string $json ) { continue; } $location = isset( $raw_group['location'] ) && is_array( $raw_group['location'] ) ? $raw_group['location'] : [ 'mode' => 'all' ]; - if ( 'specific_pages' !== ( $location['mode'] ?? 'all' ) ) { + if ( ! in_array( (string) ( $location['mode'] ?? 'all' ), [ 'all', 'specific_pages' ], true ) ) { + return new \\WP_Error( 'invalid_location_mode', sprintf( '字段组 %s 的显示条件无效,未执行导入。', sanitize_key( (string) $group_key ) ) ); + } + if ( 'all' === ( $location['mode'] ?? 'all' ) ) { $raw_group['location'] = [ 'mode' => 'all' ]; continue; } From eab36a87076689d97f1a9846854563661f3f4e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:14:19 +0800 Subject: [PATCH 25/40] fix: fail closed when field group location is invalid --- includes/class-definitions.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/class-definitions.php b/includes/class-definitions.php index af075c6..eceee5b 100644 --- a/includes/class-definitions.php +++ b/includes/class-definitions.php @@ -53,10 +53,14 @@ public function for_object( string $post_type, int $post_id ): array { $matched = []; foreach ( $this->for_post_type( $post_type ) as $key => $group ) { $location = isset( $group['location'] ) && is_array( $group['location'] ) ? $group['location'] : []; - if ( 'specific_pages' !== ( $location['mode'] ?? 'all' ) ) { + $mode = (string) ( $location['mode'] ?? 'all' ); + if ( 'all' === $mode ) { $matched[ $key ] = $group; continue; } + if ( 'specific_pages' !== $mode ) { + continue; + } $page_ids = array_map( 'absint', (array) ( $location['page_ids'] ?? [] ) ); if ( 'page' === $post_type && $post_id > 0 && in_array( $post_id, $page_ids, true ) ) { $matched[ $key ] = $group; From e9fb98f37effe54d343a1db6bfe5b06029cab4ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:14:22 +0800 Subject: [PATCH 26/40] fix: correct invalid location import error namespace --- includes/transfer/class-importer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/transfer/class-importer.php b/includes/transfer/class-importer.php index fefabef..47d35c3 100644 --- a/includes/transfer/class-importer.php +++ b/includes/transfer/class-importer.php @@ -56,7 +56,7 @@ public function inspect_json( string $json ) { } $location = isset( $raw_group['location'] ) && is_array( $raw_group['location'] ) ? $raw_group['location'] : [ 'mode' => 'all' ]; if ( ! in_array( (string) ( $location['mode'] ?? 'all' ), [ 'all', 'specific_pages' ], true ) ) { - return new \\WP_Error( 'invalid_location_mode', sprintf( '字段组 %s 的显示条件无效,未执行导入。', sanitize_key( (string) $group_key ) ) ); + return new \WP_Error( 'invalid_location_mode', sprintf( '字段组 %s 的显示条件无效,未执行导入。', sanitize_key( (string) $group_key ) ) ); } if ( 'all' === ( $location['mode'] ?? 'all' ) ) { $raw_group['location'] = [ 'mode' => 'all' ]; From f90a72e0a35dbcc93d7525428f9e4c82e67e1388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:28:36 +0800 Subject: [PATCH 27/40] docs: align schema documentation with v2 development --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5b44c30..83d1e07 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ 插件以 WordPress 原生 API 为核心:字段定义保存到 `wp_options`,实际字段值保存到 `wp_postmeta`,并通过 `register_post_meta()` 接入 WordPress REST API。 当前稳定版本:**v1.0.0** -Schema:**v1** +Schema:**v2(兼容导入 v1)** ## 字段组显示条件(开发中) @@ -84,6 +84,7 @@ key title description post_types[] +location fields[] ``` @@ -260,7 +261,7 @@ JSON 顶层结构: ```json { "format": "wem-content-fields", - "schema_version": 1, + "schema_version": 2, "plugin_version": "1.0.0", "exported_at": "2026-09-16T00:00:00+00:00", "field_groups": {} @@ -302,6 +303,7 @@ JSON 顶层结构: - Field Key 已存在 - Meta Key 已存在 - Schema 数据不合法 +- 指定页面规则无效或无法在目标站点唯一匹配 - Field / Option 定义不合法 如果目标网站当前还没有对应 Post Type,只显示“当前不可用”提醒,不阻止导入。以后该 CPT 注册后,字段组会自动重新生效。 @@ -448,7 +450,7 @@ v1.0.0 暂不包含: - User Meta - Repeater - Relationship -- Conditional Logic +- 字段级 Conditional Logic(根据其他字段值动态显示/隐藏) - Gallery / 多图字段 - 通用文件字段 - Frontend Form From 162a1a3ace0f89b1f1248042c0792dbf9ab1fa46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:29:13 +0800 Subject: [PATCH 28/40] fix: fail closed on malformed location config --- includes/class-normalizer.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/class-normalizer.php b/includes/class-normalizer.php index 88c357e..ef43758 100644 --- a/includes/class-normalizer.php +++ b/includes/class-normalizer.php @@ -33,11 +33,12 @@ static function ( $value ): bool { ) ); - $has_location = isset( $input['location'] ) && is_array( $input['location'] ); + $location_key_exists = array_key_exists( 'location', $input ); + $has_location = $location_key_exists && is_array( $input['location'] ); $location = $has_location ? $input['location'] : []; - $location_mode = $has_location ? $this->scalar_string( $location['mode'] ?? '' ) : 'all'; + $location_mode = ! $location_key_exists ? 'all' : ( $has_location ? $this->scalar_string( $location['mode'] ?? '' ) : 'invalid' ); if ( ! in_array( $location_mode, [ 'all', 'specific_pages' ], true ) ) { - $location_mode = $has_location ? 'invalid' : 'all'; + $location_mode = 'invalid'; } $page_ids = array_values( array_unique( array_filter( array_map( 'absint', (array) ( $location['page_ids'] ?? [] ) ) ) ) ); From b8c545f311e6b10541cd6e532ccd9de385e138d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:29:15 +0800 Subject: [PATCH 29/40] fix: reject malformed location config in schema v2 --- includes/transfer/class-importer.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/transfer/class-importer.php b/includes/transfer/class-importer.php index 47d35c3..accfd0a 100644 --- a/includes/transfer/class-importer.php +++ b/includes/transfer/class-importer.php @@ -54,7 +54,10 @@ public function inspect_json( string $json ) { if ( ! is_array( $raw_group ) ) { continue; } - $location = isset( $raw_group['location'] ) && is_array( $raw_group['location'] ) ? $raw_group['location'] : [ 'mode' => 'all' ]; + if ( array_key_exists( 'location', $raw_group ) && ! is_array( $raw_group['location'] ) ) { + return new \\WP_Error( 'invalid_location_shape', sprintf( '字段组 %s 的显示条件格式无效,未执行导入。', sanitize_key( (string) $group_key ) ) ); + } + $location = isset( $raw_group['location'] ) ? $raw_group['location'] : [ 'mode' => 'all' ]; if ( ! in_array( (string) ( $location['mode'] ?? 'all' ), [ 'all', 'specific_pages' ], true ) ) { return new \WP_Error( 'invalid_location_mode', sprintf( '字段组 %s 的显示条件无效,未执行导入。', sanitize_key( (string) $group_key ) ) ); } From 4380edd9ff983a163472a2e9e801330ab016810c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:29:18 +0800 Subject: [PATCH 30/40] fix: preserve malformed location config during export --- includes/transfer/class-exporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/transfer/class-exporter.php b/includes/transfer/class-exporter.php index c59bd79..39e4f03 100644 --- a/includes/transfer/class-exporter.php +++ b/includes/transfer/class-exporter.php @@ -43,7 +43,7 @@ public function package( array $selected_keys = [] ): array { * Replace site-local Page IDs with path references for portable JSON. */ private function portable_group( array $group ): array { - $location = isset( $group['location'] ) && is_array( $group['location'] ) ? $group['location'] : [ 'mode' => 'all' ]; + $location = ! array_key_exists( 'location', $group ) ? [ 'mode' => 'all' ] : ( is_array( $group['location'] ) ? $group['location'] : [ 'mode' => 'invalid' ] ); if ( 'specific_pages' === ( $location['mode'] ?? 'all' ) ) { $refs = []; foreach ( array_map( 'absint', (array) ( $location['page_ids'] ?? [] ) ) as $page_id ) { From 3a01066c6f112ea570e6178180863d1065c70823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=88=E4=BD=9C=E5=85=B1=E8=B5=A2?= <18604421@qq.com> Date: Sun, 18 Oct 2026 11:34:22 +0800 Subject: [PATCH 31/40] ui: clarify field group location settings --- admin/views/field-group-edit.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/views/field-group-edit.php b/admin/views/field-group-edit.php index c0626ba..c54e13a 100644 --- a/admin/views/field-group-edit.php +++ b/admin/views/field-group-edit.php @@ -115,21 +115,21 @@设置该字段组在哪些页面的编辑界面中显示。此设置不改变前台页面布局,也不会删除已有字段数据。
+先选择适用的内容类型,再决定字段组出现在哪些编辑页面。此设置只影响后台编辑界面,不改变前台布局,也不会删除已有字段数据。
'all', 'page_ids' => [] ]; ?>按住 Ctrl(Windows)或 Command(Mac)可选择多个页面。选择“仅在指定页面显示”时,至少选择一个页面。
+可以选择一个或多个页面。此模式仅适用于 Pages;选择此模式后,系统会自动只保留 Pages。
先选择适用的内容类型,再决定字段组出现在哪些编辑页面。此设置只影响后台编辑界面,不改变前台布局,也不会删除已有字段数据。
'all', 'page_ids' => [] ]; ?>先选择适用的内容类型,再决定字段组出现在哪些编辑页面。此设置只影响后台编辑界面,不改变前台布局,也不会删除已有字段数据。
'all', 'page_ids' => [] ]; ?>