Conversation
| private function get_structured_field_values( $post_id ) { | ||
| $post = get_post( $post_id ); | ||
| if ( ! $post ) { | ||
| return array(); | ||
| } | ||
|
|
||
| $fields = self::parse_structured_content( $post->post_content ); | ||
| if ( ! empty( $fields ) ) { | ||
| return $fields; | ||
| } | ||
|
|
||
| $fallback = array(); | ||
| $schema = $this->get_dynamic_fields_schema_for_post( $post_id ); | ||
| if ( ! empty( $schema ) ) { | ||
| foreach ( $schema as $row ) { | ||
| if ( empty( $row['slug'] ) ) { | ||
| continue; | ||
| } | ||
| $slug = sanitize_key( $row['slug'] ); | ||
| if ( '' === $slug ) { | ||
| continue; | ||
| } | ||
| $meta_key = 'resolate_field_' . $slug; | ||
| $value = get_post_meta( $post_id, $meta_key, true ); | ||
| if ( '' === $value ) { | ||
| continue; | ||
| } | ||
| $type = isset( $row['type'] ) ? sanitize_key( $row['type'] ) : 'textarea'; | ||
| if ( ! in_array( $type, array( 'single', 'textarea', 'rich' ), true ) ) { | ||
| $type = 'textarea'; | ||
| } | ||
| $fallback[ $slug ] = array( | ||
| 'value' => (string) $value, | ||
| 'type' => $type, | ||
| ); | ||
| } | ||
| } elseif ( $post_id > 0 ) { | ||
| $saved = get_post_meta( $post_id, 'resolate_annexes', true ); | ||
| if ( is_array( $saved ) ) { | ||
| $annexes = $saved; } | ||
| } | ||
| if ( ! empty( $annexes ) ) { | ||
| $blocks[] = '<!-- wp:heading {"level":2} -->' . "\n" . '<h2>' . esc_html__( 'Anexos', 'resolate' ) . '</h2>' . "\n" . '<!-- /wp:heading -->'; | ||
| $roman = function ( $num ) { | ||
| $map = array( | ||
| 'M' => 1000, | ||
| 'CM' => 900, | ||
| 'D' => 500, | ||
| 'CD' => 400, | ||
| 'C' => 100, | ||
| 'XC' => 90, | ||
| 'L' => 50, | ||
| 'XL' => 40, | ||
| 'X' => 10, | ||
| 'IX' => 9, | ||
| 'V' => 5, | ||
| 'IV' => 4, | ||
| 'I' => 1, | ||
| ); | ||
| $res = ''; | ||
| foreach ( $map as $rom => $int ) { | ||
| while ( $num >= $int ) { | ||
| $res .= $rom; | ||
| $num -= $int; } | ||
| } | ||
| return $res; | ||
| }; | ||
| foreach ( $annexes as $i => $anx ) { | ||
| $title = isset( $anx['title'] ) ? sanitize_text_field( $anx['title'] ) : ''; | ||
| $text = isset( $anx['text'] ) ? wp_kses_post( $anx['text'] ) : ''; | ||
| $blocks[] = '<!-- wp:heading {"level":3} -->' . "\n" . '<h3>' . esc_html( sprintf( 'Anexo %s', $roman( $i + 1 ) ) ) . ( $title ? ': ' . esc_html( $title ) : '' ) . '</h3>' . "\n" . '<!-- /wp:heading -->'; | ||
| $blocks[] = '<!-- wp:html -->' . "\n" . $text . "\n" . '<!-- /wp:html -->'; | ||
|
|
||
| return $fallback; | ||
| } |
Check warning
Code scanning / PHPMD
Code Size Rules: CyclomaticComplexity Warning
There was a problem hiding this comment.
💡 Codex Review
https://github.com/erseco/wp-resolate/blob/21e3bbdfe946ccffadc5513c9f64a6d4bdca1c2a/includes/class-resolate-admin-helper.php#L843-L845
Legacy preview drops required wrapper markup
The refactor removed the initial HTML scaffolding and the <div id="content-flow"> element that used to wrap the preview content, but the JS at the bottom still does const flow = document.getElementById("content-flow") and immediately accesses flow.children. When render_legacy_preview() runs, flow is now null and the script throws before rendering pages, so the fallback preview stays blank and cannot print. Consider restoring the container markup or guarding against a missing node before iterating.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
| $fields = array( | ||
| 'title' => get_the_title( $post_id ), | ||
| 'objeto' => wp_strip_all_tags( (string) get_post_meta( $post_id, 'resolate_objeto', true ) ), | ||
| 'antecedentes' => wp_strip_all_tags( (string) get_post_meta( $post_id, 'resolate_antecedentes', true ) ), | ||
| 'fundamentos' => wp_strip_all_tags( (string) get_post_meta( $post_id, 'resolate_fundamentos', true ) ), | ||
| 'dispositivo' => wp_strip_all_tags( (string) get_post_meta( $post_id, 'resolate_dispositivo', true ) ), | ||
| 'firma' => wp_strip_all_tags( (string) get_post_meta( $post_id, 'resolate_firma', true ) ), | ||
| 'margen' => wp_strip_all_tags( isset( $opts['doc_margin_text'] ) ? $opts['doc_margin_text'] : '' ), | ||
| 'title' => get_the_title( $post_id ), | ||
| 'margen' => wp_strip_all_tags( isset( $opts['doc_margin_text'] ) ? $opts['doc_margin_text'] : '' ), | ||
| ); |
There was a problem hiding this comment.
Merge field builder no longer returns legacy meta when no schema
After the change, build_merge_fields() only seeds the array with title and margen (and then iterates over taxonomy schema). For documents that either lack a resolate_doc_type term or have no schema defined—common for posts created before this refactor—the legacy meta keys such as resolate_objeto, resolate_antecedentes, etc. are never read and their placeholders remain empty during export. The previous implementation always included those meta values regardless of taxonomy configuration, so this breaks existing templates for legacy content. A fallback to the old meta keys when no schema/structured sections are available would preserve compatibility.
Useful? React with 👍 / 👎.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68ee046ff9fc83229110bc65449a5ac2