ayudawp_compose_output( $content, $buttons_html, $summary_html, $insert_position, $effective_summary_pos ); } /** * Compose the final post output from content, buttons and summary parts * * Implements the position matrix: * - `ai_summary_position === 'before_content'` → summary always at the start. * - `ai_summary_position === 'before_buttons'` / `'after_buttons'` → summary * is glued to the buttons block (first occurrence when buttons are * inserted twice via `auto_insert_position === 'both'`). * * Summary is rendered exactly once regardless of `auto_insert_position`, * because the summary itself is a single piece of per-post data. * * @param string $content Original post content. * @param string $buttons_html Pre-built buttons HTML (may be ''). * @param string $summary_html Pre-built summary HTML (may be ''). * @param string $insert_position Buttons position option. * @param string $summary_pos Effective summary position option. * @return string Composed content. */ private function ayudawp_compose_output( $content, $buttons_html, $summary_html, $insert_position, $summary_pos ) { $has_buttons = '' !== $buttons_html; $has_summary = '' !== $summary_html; /* * Build a single "buttons block with optional inline summary" decided * by $summary_pos. The buttons-relative position ('before_buttons' / * 'after_buttons') anchors the summary to the buttons regardless of * where the buttons themselves get inserted ('before_content', * 'after_content', 'both'). */ if ( $has_buttons && $has_summary && 'before_buttons' === $summary_pos ) { $buttons_block = $summary_html . $buttons_html; } elseif ( $has_buttons && $has_summary && 'after_buttons' === $summary_pos ) { $buttons_block = $buttons_html . $summary_html; } else { $buttons_block = $buttons_html; } // Pre-content summary: only rendered separately when the position is before_content. $pre_summary = ( $has_summary && 'before_content' === $summary_pos ) ? $summary_html : ''; switch ( $insert_position ) { case 'before_content': return $pre_summary . $buttons_block . $content; case 'both': // Summary appears once with the first buttons block; the second block stays plain. return $pre_summary . $buttons_block . $content . $buttons_html; case 'after_content': default: return $pre_summary . $content . $buttons_block; } } }