<?php
if ( ! defined( 'ABSPATH' ) ) exit; if ( ! defined( 'CANNECT_SITE_URL' ) ) {
define( 'CANNECT_SITE_URL', 'https://cannect.life' );
}
if ( ! defined( 'CANNECT_LOGO_URL' ) ) {
define( 'CANNECT_LOGO_URL', get_template_directory_uri() . '/assets/images/logo.svg' );
} function cannect_theme_setup(): void {
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'editor-styles' ); // Ativa suporte a estilos no Gutenberg
add_image_size( 'cannect-hero', 1200, 630, true );
add_image_size( 'cannect-desktop-thumb', 600, 400, true );
add_image_size( 'cannect-thumb', 400, 300, true );
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
) );
}
add_action( 'after_setup_theme', 'cannect_theme_setup' );
add_filter( 'document_title_parts', function( $title ) {
if ( isset( $title['site'] ) && isset( $title['title'] ) && $title['site'] === $title['title'] ) {
unset( $title['site'] );
}
return $title;
} ); function cannect_enqueue_scripts(): void {
wp_enqueue_style( 'cannect-google-fonts', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Poppins:wght@400;600;700;800&display=swap', array(), null );
wp_enqueue_script( 'lucide-icons', 'https://unpkg.com/lucide@latest', array(), null, true );
wp_add_inline_script( 'lucide-icons', 'document.addEventListener("DOMContentLoaded", function() { if (window.lucide) { lucide.createIcons(); } });' );
wp_enqueue_style( 'cannect-main-style', get_stylesheet_uri(), array(), '1.4.9' );
$js_paths = array(
'/assets/js/main.js',
'/assets/js/scripts.js',
'/assets/js/app.js',
'/js/main.js',
'/js/scripts.js',
'/script.js',
'/main.js'
);
foreach ( $js_paths as $path ) {
if ( file_exists( get_template_directory() . $path ) ) {
wp_enqueue_script( 'cannect-theme-js', get_template_directory_uri() . $path, array('jquery'), filemtime( get_template_directory() . $path ), true );
wp_localize_script( 'cannect-theme-js', 'cannectAjax', array(
'ajaxurl' => admin_url(//blog.cannect.life/wp-content/themes/cannect-blog/admin-ajax.php)
));
break;
}
}
$custom_css = "
#posts-container { display: grid !important; grid-template-columns: repeat(1, minmax(0, 1fr)) !important; gap: 1.5rem !important; width: 100% !important; box-sizing: border-box !important; }
@media (min-width: 640px) { #posts-container { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; } }
@media (min-width: 1024px) { #posts-container { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; } }
#posts-container article { width: 100% !important; max-width: 100% !important; min-width: 0 !important; float: none !important; flex: none !important; margin: 0 !important; box-sizing: border-box !important; }
#posts-container article h2, #posts-container article h3 { font-size: 0.95rem !important; line-height: 1.4 !important; font-weight: 700 !important; display: block !important; white-space: normal !important; overflow: visible !important; height: auto !important; -webkit-line-clamp: none !important; }
";
wp_add_inline_style( 'cannect-main-style', $custom_css );
}
add_action( 'wp_enqueue_scripts', 'cannect_enqueue_scripts' ); $inc_files = array(
'/inc/sidebar.php',
'/inc/social-embeds.php',
);
foreach ( $inc_files as $file ) {
$filepath = get_template_directory() . $file;
if ( file_exists( $filepath ) ) {
require_once $filepath;
}
}
if ( ! function_exists( 'cannect_render_sidebar' ) ) {
function cannect_render_sidebar(): void {
if ( is_active_sidebar( 'sidebar-1' ) ) {
dynamic_sidebar( 'sidebar-1' );
}
}
} function cannect_transversal_slugs(): array {
return array( 'cannect-noticias', 'central-do-paciente' );
}
function cannect_pillar_category_ids(): array {
$terms = get_categories( array( 'hide_empty' => false, 'exclude' => 1, 'fields' => 'ids' ) );
return ! empty( $terms ) && ! is_wp_error( $terms ) ? $terms : array();
}
function cannect_get_post_author( int $post_id ): array {
$author_id   = (int) get_post_field( 'post_author', $post_id );
$name        = get_the_author_meta( 'display_name', $author_id );
$avatar      = get_avatar_url(//blog.cannect.life/wp-content/themes/cannect-blog/$author_id, array( size => 120) );
$description = get_the_author_meta( 'description', $author_id );
$website     = get_the_author_meta( 'user_url', $author_id );
return array( 'id' => $author_id, 'name' => $name ?: 'Redação Cannect', 'avatar' => $avatar, 'description' => $description, 'website' => $website );
}
function cannect_get_post_reviewer( int $post_id ): array {
$selected_auth   = get_post_meta( $post_id, '_cannect_selected_molongui_author', true );
$reviewer_name   = get_post_meta( $post_id, '_cannect_reviewer_name', true );
$reviewer_avatar = get_post_meta( $post_id, '_cannect_reviewer_avatar', true );
$reviewer_crm    = get_post_meta( $post_id, '_cannect_reviewer_crm', true );
$reviewer_bio    = get_post_meta( $post_id, '_cannect_reviewer_bio', true );
$reviewer_spec   = get_post_meta( $post_id, '_cannect_reviewer_specialty', true );
if ( strpos( $selected_auth, 'guest_' ) !== false ) {
$guest_id = (int) str_replace( 'guest_', '', $selected_auth );
if ( empty( $reviewer_crm ) ) {
$job_title = get_post_meta( $guest_id, '_molongui_guest_author_job_title', true ) ?: get_post_meta( $guest_id, '_molongui_guest_author_title', true );
if ( ! empty( $job_title ) ) $reviewer_crm = $job_title;
}
}
return array( 'name' => $reviewer_name, 'avatar' => $reviewer_avatar, 'crm' => $reviewer_crm ?: 'Junta Médica Cannect', 'bio' => $reviewer_bio, 'specialty' => $reviewer_spec );
}
function cannect_get_faq_pairs( int $post_id ): array {
$faq = get_post_meta( $post_id, '_cannect_faq_pairs', true );
return is_array( $faq ) ? $faq : array();
}
function cannect_columnist_avatar_html( string $name, string $classes = 'w-10 h-10' ): string {
$wordsInit = explode( ' ', trim( $name ) );
$initials  = strtoupper( mb_substr( $wordsInit[0] ?? 'C', 0, 1 ) );
if ( isset( $wordsInit[1] ) ) $initials .= strtoupper( mb_substr( $wordsInit[1], 0, 1 ) );
return sprintf( '<div class="%s rounded-full bg-[#748351]/10 text-[#748351] font-bold flex items-center justify-center text-xs shrink-0 aspect-square border border-[#748351]/20">%s</div>', esc_attr( $classes ), esc_html( $initials ) );
}
function cannect_render_pagination( ?WP_Query $query = null ): void {
global $wp_query;
$target_query = $query ?: $wp_query;
$big   = 999999999;
$pages = paginate_links( array(
'base'      => str_replace( $big, '%#%', esc_url(//blog.cannect.life/wp-content/themes/cannect-blog/get_pagenum_link( $big) ) ),
'format'    => '?paged=%#%',
'current'   => max( 1, get_query_var( 'paged' ) ),
'total'     => $target_query->max_num_pages,
'type'      => 'array',
'prev_text' => '<i data-lucide="chevron-left" class="w-3.5 h-3.5 inline"></i> Anterior',
'next_text' => 'Próximo <i data-lucide="chevron-right" class="w-3.5 h-3.5 inline"></i>',
) );
if ( is_array( $pages ) ) {
echo '<nav class="flex flex-wrap items-center justify-center gap-2 my-10 w-full" aria-label="Navegação de Páginas">';
foreach ( $pages as $page ) {
$is_active  = strpos( $page, 'current' ) !== false;
$btn_styles = $is_active ? 'bg-[#748351] text-white font-bold border-[#748351] shadow-sm' : 'bg-white text-gray-800 hover:bg-[#748351]/10 hover:text-[#748351] border-gray-200';
echo str_replace( 'page-numbers', 'px-3.5 py-2 text-xs rounded-xl border transition-all inline-flex items-center gap-1 font-semibold ' . $btn_styles, $page );
}
echo '</nav>';
}
} function cannect_adjust_search_posts_per_page( $query ): void {
if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
$query->set( 'posts_per_page', 12 );
}
}
add_action( 'pre_get_posts', 'cannect_adjust_search_posts_per_page' );
function cannect_excerpt_meta_line( int $post_id ): string {
$date = get_the_date( 'd \d\e F, Y', $post_id );
$word_count = str_word_count( strip_tags( (string) get_post_field( 'post_content', $post_id ) ) );
return sprintf( '%s • %d min de leitura', $date, max( 1, ceil( $word_count / 200 ) ) );
}
function cannect_get_colunistas_query( int $limit = 6 ): WP_Query {
return new WP_Query( array( 'post_type' => 'post', 'category_name' => 'colunistas', 'posts_per_page' => $limit, 'ignore_sticky_posts' => true, 'orderby' => 'date', 'order' => 'DESC' ) );
} function cannect_process_newsletter_ajax(): void {
check_ajax_referer( 'cannect_newsletter_nonce', 'security' );
$email = isset( $_POST['email'] ) ? sanitize_email( $_POST['email'] ) : '';
if ( ! is_email( $email ) ) wp_send_json_error( array( 'message' => 'Por favor, insira um e-mail válido.' ) );
$subscribers   = get_option( 'cannect_newsletter_subscribers', array() );
$subscribers[] = array( 'email' => $email, 'date' => current_time( 'mysql' ) );
update_option( 'cannect_newsletter_subscribers', $subscribers );
wp_send_json_success( array( 'message' => 'Inscrição realizada com sucesso!' ) );
}
add_action( 'wp_ajax_cannect_newsletter', 'cannect_process_newsletter_ajax' );
add_action( 'wp_ajax_nopriv_cannect_newsletter', 'cannect_process_newsletter_ajax' );
function cannect_ajax_filter_categories(): void {
$cat_id = isset( $_POST['category_id'] ) ? intval( $_POST['category_id'] ) : 0;
$paged  = isset( $_POST['page'] ) ? intval( $_POST['page'] ) : 1;
$args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 9, 'paged' => $paged );
if ( $cat_id > 0 ) $args['cat'] = $cat_id;
$query = new WP_Query( $args );
ob_start();
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
?>
<article class="bg-white border border-gray-100 rounded-2xl overflow-hidden shadow-xs hover:shadow-md transition-all flex flex-col justify-between h-full">
<div>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>" class="block overflow-hidden aspect-video bg-gray-100">
<?php the_post_thumbnail( 'cannect-thumb', array( 'class' => 'w-full h-48 object-cover hover:scale-105 transition-transform duration-300' ) ); ?>
</a>
<?php } else { ?>
<a href="<?php the_permalink(); ?>" class="block overflow-hidden aspect-video bg-[#748351]/10 flex items-center justify-center text-[#748351]"><i data-lucide="newspaper" class="w-10 h-10 opacity-40"></i></a>
<?php } ?>
<div class="p-4 sm:p-5">
<div class="text-[11px] font-medium text-gray-500 mb-2"><?php echo esc_html( get_the_date( 'd \d\e F, Y' ) ); ?></div>
<h2 class="text-sm font-bold text-gray-900 leading-snug mb-2 hover:text-[#748351] transition-colors"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
</div>
<div class="px-4 pb-4 sm:px-5 sm:pb-5 pt-0">
<a href="<?php the_permalink(); ?>" class="text-xs font-bold text-[#748351] hover:underline flex items-center gap-1"><span>Ler artigo completo</span><i data-lucide="arrow-right" class="w-3.5 h-3.5"></i></a>
</div>
</article>
<?php
}
wp_reset_postdata();
} else {
echo '<div class="col-span-full py-12 text-center text-sm text-gray-500 bg-white rounded-2xl border border-gray-100">Nenhum artigo encontrado nesta categoria.</div>';
}
$html = ob_get_clean();
ob_start();
if ( function_exists( 'cannect_render_pagination' ) ) cannect_render_pagination( $query );
$pagination = ob_get_clean();
wp_send_json_success( array( 'html' => $html, 'pagination' => $pagination ) );
}
add_action( 'wp_ajax_cannect_filter_posts', 'cannect_ajax_filter_categories' );
add_action( 'wp_ajax_nopriv_cannect_filter_posts', 'cannect_ajax_filter_categories' );
function cannect_inject_category_filter_js(): void {
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
const categoryLinks = document.querySelectorAll('.category-filter-btn, [data-category-id], .cannect-pill');
const gridContainer = document.getElementById('posts-container');
const paginationContainer = document.getElementById('pagination-container');
if (!gridContainer) return;
categoryLinks.forEach(link => {
link.addEventListener('click', function(e) {
let catId = this.getAttribute('data-category-id');
if (!catId && this.getAttribute('href')?.includes('/category/')) return;
if (catId !== null) {
e.preventDefault();
gridContainer.style.opacity = '0.4';
const formData = new FormData();
formData.append('action', 'cannect_filter_posts');
formData.append('category_id', catId);
fetch('<?php echo esc_url(//blog.cannect.life/wp-content/themes/cannect-blog/admin_url( admin-ajax.php) ); ?>', { method: 'POST', body: formData })
.then(response => response.json())
.then(res => {
if (res.success) {
gridContainer.innerHTML = res.html;
if (paginationContainer) paginationContainer.innerHTML = res.pagination;
if (window.lucide) lucide.createIcons();
}
gridContainer.style.opacity = '1';
}).catch(() => { gridContainer.style.opacity = '1'; });
}
});
});
});
</script>
<?php
}
add_action( 'wp_footer', 'cannect_inject_category_filter_js' ); function cannect_add_custom_post_settings_metabox(): void {
add_meta_box( 'cannect_post_settings_box', '⚙️ Ferramentas do Artigo (Cannect)', 'cannect_render_post_settings_metabox', 'post', 'normal', 'low' );
}
add_action( 'add_meta_boxes', 'cannect_add_custom_post_settings_metabox' );
function cannect_render_post_settings_metabox( WP_Post $post ): void {
wp_nonce_field( 'cannect_save_post_settings', 'cannect_post_settings_nonce' );
$redirect_url  = get_post_meta( $post->ID, '_cannect_redirect_url', true );
$selected_auth = get_post_meta( $post->ID, '_cannect_selected_molongui_author', true );
$reviewer_crm  = get_post_meta( $post->ID, '_cannect_reviewer_crm', true );
$doctor_url    = get_post_meta( $post->ID, '_cannect_doctor_url', true );
$booking_url   = get_post_meta( $post->ID, '_cannect_booking_url', true );
$tldr          = get_post_meta( $post->ID, '_cannect_tldr', true );
$faq           = get_post_meta( $post->ID, '_cannect_faq_pairs', true );
if ( ! is_array( $faq ) ) $faq = array();
$molongui_authors = get_posts( array( 'post_type' => array( 'guest_author', 'molongui_guest_author' ), 'posts_per_page' => -1, 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC' ) );
$wp_users = get_users( array( 'orderby' => 'display_name' ) );
?>
<style>
.cannect-admin-panel { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.cannect-admin-group { background: #fff; border: 1px solid #e2e4e7; padding: 15px; margin-bottom: 15px; border-radius: 4px; box-shadow: 0 1px 1px rgba(0,0,0,0.04); }
.cannect-admin-group h4 { margin: 0 0 12px 0; font-size: 14px; border-bottom: 1px solid #f0f0f1; padding-bottom: 8px; color: #1d2327; }
.cannect-admin-row { margin-bottom: 12px; }
.cannect-admin-row:last-child { margin-bottom: 0; }
.cannect-admin-label { font-weight: 600; display: block; margin-bottom: 4px; font-size: 13px; color: #2c3338; }
.cannect-admin-input { width: 100%; border: 1px solid #8c8f94; border-radius: 4px; padding: 6px 8px; font-size: 13px; box-shadow: none; }
.cannect-admin-input:focus { border-color: #2271b1; outline: none; box-shadow: 0 0 0 1px #2271b1; }
.cannect-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.cannect-faq-item { background: #f6f7f7; border: 1px solid #c3c4c7; padding: 12px; margin-bottom: 10px; border-radius: 4px; position: relative; }
.cannect-remove-faq { color: #d63638; cursor: pointer; font-size: 13px; text-decoration: underline; background: none; border: none; padding: 0; margin-top: 5px; }
.cannect-remove-faq:hover { color: #b32d2e; }
</style>
<div class="cannect-admin-panel">
<div class="cannect-admin-group">
<h4>⚡ Resumo Rápido (TLDR)</h4>
<div class="cannect-admin-row">
<textarea id="cannect_tldr" name="cannect_tldr" rows="3" class="cannect-admin-input" placeholder="Escreva um breve resumo do artigo..."><?php echo esc_textarea( $tldr ); ?></textarea>
</div>
</div>
<div class="cannect-admin-group">
<h4>👨‍⚕️ Revisão Médica</h4>
<div class="cannect-admin-row">
<label class="cannect-admin-label">Selecionar Autor / Revisor:</label>
<select name="cannect_selected_molongui_author" class="cannect-admin-input">
<option value="">-- Selecione o Médico --</option>
<?php if ( ! empty( $molongui_authors ) ) { ?>
<optgroup label="Médicos da Cannect (Molongui)">
<?php foreach ( $molongui_authors as $ga ) { ?>
<option value="guest_<?php echo esc_attr( $ga->ID ); ?>" <?php selected( $selected_auth, 'guest_' . $ga->ID ); ?>><?php echo esc_html( $ga->post_title ); ?></option>
<?php } ?>
</optgroup>
<?php } ?>
<optgroup label="Usuários do Sistema">
<?php foreach ( $wp_users as $u ) { ?>
<option value="user_<?php echo esc_attr( $u->ID ); ?>" <?php selected( $selected_auth, 'user_' . $u->ID ); ?>><?php echo esc_html( $u->display_name ); ?></option>
<?php } ?>
</optgroup>
</select>
</div>
<div class="cannect-grid-2">
<div class="cannect-admin-row">
<label class="cannect-admin-label">CRM do Médico:</label>
<input type="text" name="cannect_reviewer_crm" value="<?php echo esc_attr( $reviewer_crm ); ?>" class="cannect-admin-input" placeholder="Ex: CRM/SP 123456">
</div>
<div class="cannect-admin-row">
<label class="cannect-admin-label">Link da Agenda do Médico:</label>
<input type="url" name="cannect_doctor_url" value="<?php echo esc_url(//blog.cannect.life/wp-content/themes/cannect-blog/$doctor_url); ?>" class="cannect-admin-input" placeholder="https://...">
</div>
</div>
</div>
<div class="cannect-admin-group">
<h4>🔗 Links de Apoio</h4>
<div class="cannect-grid-2">
<div class="cannect-admin-row">
<label class="cannect-admin-label">Link da Barra Inferior (Sticky Bar):</label>
<input type="url" name="cannect_booking_url" value="<?php echo esc_url(//blog.cannect.life/wp-content/themes/cannect-blog/$booking_url); ?>" class="cannect-admin-input" placeholder="https://...">
</div>
<div class="cannect-admin-row">
<label class="cannect-admin-label">Redirecionar Artigo Inteiro (301):</label>
<input type="url" name="cannect_redirect_url" value="<?php echo esc_url(//blog.cannect.life/wp-content/themes/cannect-blog/$redirect_url); ?>" class="cannect-admin-input" placeholder="Deixe em branco para não redirecionar">
</div>
</div>
</div>
<div class="cannect-admin-group">
<h4>❓ Perguntas Frequentes (FAQ)</h4>
<div id="cannect-faq-wrapper">
<?php
if ( ! empty( $faq ) ) {
foreach ( $faq as $pair ) {
?>
<div class="cannect-faq-item">
<div class="cannect-admin-row">
<label class="cannect-admin-label">Pergunta:</label>
<input type="text" name="cannect_faq_q[]" value="<?php echo esc_attr( $pair['q'] ?? '' ); ?>" class="cannect-admin-input">
</div>
<div class="cannect-admin-row">
<label class="cannect-admin-label">Resposta:</label>
<textarea name="cannect_faq_a[]" rows="2" class="cannect-admin-input"><?php echo esc_textarea( $pair['a'] ?? '' ); ?></textarea>
</div>
<button type="button" class="cannect-remove-faq">Remover Pergunta</button>
</div>
<?php
}
}
?>
</div>
<button type="button" class="button button-secondary" id="cannect-add-faq" style="margin-top: 5px;">+ Adicionar Pergunta</button>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const wrapper = document.getElementById('cannect-faq-wrapper');
const addBtn = document.getElementById('cannect-add-faq');
if (addBtn) {
addBtn.addEventListener('click', function() {
const div = document.createElement('div');
div.className = 'cannect-faq-item';
div.innerHTML = `
<div class="cannect-admin-row">
<label class="cannect-admin-label">Pergunta:</label>
<input type="text" name="cannect_faq_q[]" class="cannect-admin-input" placeholder="Escreva a pergunta...">
</div>
<div class="cannect-admin-row">
<label class="cannect-admin-label">Resposta:</label>
<textarea name="cannect_faq_a[]" rows="2" class="cannect-admin-input" placeholder="Escreva a resposta..."></textarea>
</div>
<button type="button" class="cannect-remove-faq">Remover Pergunta</button>
`;
wrapper.appendChild(div);
});
}
if (wrapper) {
wrapper.addEventListener('click', function(e) {
if (e.target && e.target.classList.contains('cannect-remove-faq')) {
e.target.closest('.cannect-faq-item').remove();
}
});
}
});
</script>
<?php
}
function cannect_save_post_settings( int $post_id ): void {
if ( ! isset( $_POST['cannect_post_settings_nonce'] ) \vert{}\vert{} ! wp_verify_nonce( $_POST['cannect_post_settings_nonce'], 'cannect_save_post_settings' ) ) return;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( ! current_user_can( 'edit_post', $post_id ) ) return;
if ( isset( $_POST['cannect_tldr'] ) ) update_post_meta( $post_id, '_cannect_tldr', wp_kses_post($_POST['cannect_tldr'] ) );
if ( isset( $_POST['cannect_redirect_url'] ) ) update_post_meta( $post_id, '_cannect_redirect_url', esc_url_raw($_POST['cannect_redirect_url'] ) );
if ( isset( $_POST['cannect_reviewer_crm'] ) ) update_post_meta( $post_id, '_cannect_reviewer_crm', sanitize_text_field($_POST['cannect_reviewer_crm'] ) );
if ( isset( $_POST['cannect_doctor_url'] ) ) update_post_meta( $post_id, '_cannect_doctor_url', esc_url_raw($_POST['cannect_doctor_url'] ) );
if ( isset( $_POST['cannect_booking_url'] ) ) update_post_meta( $post_id, '_cannect_booking_url', esc_url_raw($_POST['cannect_booking_url'] ) );
if ( isset( $_POST['cannect_faq_q'] ) && isset( $_POST['cannect_faq_a'] ) ) {$questions = $_POST['cannect_faq_q'];$answers   = $_POST['cannect_faq_a'];$faq_pairs = array();
for ( $i = 0; $i < count( $questions );$i++ ) {
$q = sanitize_text_field($questions[$i] );$a = sanitize_textarea_field( $answers[$i] );
if ( ! empty( $q ) && ! empty( $a ) ) {$faq_pairs[] = array( 'q' => $q, 'a' =>$a );
}
}
update_post_meta( $post_id, '_cannect_faq_pairs',$faq_pairs );
} else {
delete_post_meta( $post_id, '_cannect_faq_pairs' );
}
if ( isset( $_POST['cannect_selected_molongui_author'] ) ) {
$selected = sanitize_text_field($_POST['cannect_selected_molongui_author'] );
update_post_meta( $post_id, '_cannect_selected_molongui_author',$selected );
if ( strpos( $selected, 'guest_' ) !== false ) {
$guest_id = (int) str_replace( 'guest_', '',$selected );
$guest    = get_post($guest_id );
if ( $guest ) {
update_post_meta( $post_id, '_cannect_reviewer_name',$guest->post_title );
$molongui_bio = get_post_meta($guest_id, '_molongui_guest_author_bio', true );
update_post_meta( $post_id, '_cannect_reviewer_bio', ! empty( $molongui_bio ) ?$molongui_bio : $guest->post_content );$molongui_job = get_post_meta( $guest_id, '_molongui_guest_author_job_title', true ) ?: get_post_meta($guest_id, '_molongui_guest_author_title', true );
if ( ! empty( $molongui_job ) && empty($_POST['cannect_reviewer_crm'] ) ) {
update_post_meta( $post_id, '_cannect_reviewer_crm', sanitize_text_field($molongui_job ) );
}
$molongui_web = get_post_meta($guest_id, '_molongui_guest_author_web', true );
if ( ! empty( $molongui_web ) ) update_post_meta( $post_id, '_cannect_doctor_url', esc_url_raw($molongui_web ) );
$thumb_id = get_post_thumbnail_id($guest_id );
if ( $thumb_id ) {
$img_src = wp_get_attachment_image_src($thumb_id, 'full' );
if ( $img_src ) update_post_meta($post_id, '_cannect_reviewer_avatar', $img_src[0] ); 				} 			} 		} elseif ( strpos($selected, 'user_' ) !== false ) {
$user_id = (int) str_replace( 'user_', '',$selected );
$user    = get_userdata($user_id );
if ( $user ) {
update_post_meta( $post_id, '_cannect_reviewer_name',$user->display_name );
update_post_meta( $post_id, '_cannect_reviewer_bio', get_the_author_meta( 'description',$user_id ) );
update_post_meta( $post_id, '_cannect_reviewer_avatar', get_avatar_url(//blog.cannect.life/wp-content/themes/cannect-blog/$user_id, array( size => 120) ) );
if ( ! empty( $user->user_url ) ) update_post_meta( $post_id, '_cannect_doctor_url', esc_url_raw($user->user_url ) );
}
}
}
}
add_action( 'save_post', 'cannect_save_post_settings' );
function cannect_execute_post_redirect(): void {
if ( is_single() ) {
$post_id      = get_queried_object_id();
$redirect_url = get_post_meta($post_id, '_cannect_redirect_url', true );
if ( ! empty( $redirect_url ) && filter_var($redirect_url, FILTER_VALIDATE_URL ) ) {
wp_redirect( esc_url_raw( $redirect_url ), 301 );
exit;
}
}
}
add_action( 'template_redirect', 'cannect_execute_post_redirect' ); function cannect_enqueue_block_editor_assets(): void {
wp_enqueue_style( 'cannect-editor-google-fonts', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Poppins:wght@400;600;700;800&display=swap', array(), null );
$editor_css = "
.editor-styles-wrapper,
.editor-styles-wrapper .block-editor-block-list__layout,
.editor-styles-wrapper .wp-block-post-content {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
color: #374151 !important;
font-size: 16px !important;
line-height: 1.7 !important;
}
.editor-styles-wrapper h2,
.editor-styles-wrapper .wp-block-heading h2,
.editor-styles-wrapper h2.wp-block-heading {
font-family: 'Poppins', sans-serif !important;
color: #111827 !important;
font-size: 1.5rem !important;
font-weight: 700 !important;
margin-top: 2rem !important;
margin-bottom: 0.875rem !important;
}
.editor-styles-wrapper h3,
.editor-styles-wrapper .wp-block-heading h3,
.editor-styles-wrapper h3.wp-block-heading {
font-family: 'Poppins', sans-serif !important;
color: #111827 !important;
font-size: 1.25rem !important;
font-weight: 700 !important;
margin-top: 1.5rem !important;
margin-bottom: 0.75rem !important;
}
.editor-styles-wrapper p,
.editor-styles-wrapper .wp-block-paragraph {
font-size: 1rem !important;
line-height: 1.7 !important;
margin-bottom: 1.25rem !important;
color: #374151 !important;
}
.editor-styles-wrapper a,
.editor-styles-wrapper .wp-block-paragraph a {
color: #047857 !important;
font-weight: 700 !important;
text-decoration: underline !important;
text-underline-offset: 3px !important;
}
.editor-styles-wrapper ul,
.editor-styles-wrapper .wp-block-list {
list-style-type: disc !important;
padding-left: 1.5rem !important;
margin-bottom: 1.25rem !important;
}
.editor-styles-wrapper ol {
list-style-type: decimal !important;
padding-left: 1.5rem !important;
margin-bottom: 1.25rem !important;
}
.editor-styles-wrapper blockquote,
.editor-styles-wrapper .wp-block-quote {
border-left: 4px solid #748351 !important;
background: #f0fdf4 !important;
padding: 12px 16px !important;
margin: 1.5rem 0 !important;
border-radius: 0 8px 8px 0 !important;
}
";
wp_register_style( 'cannect-gutenberg-custom-style', false );
wp_enqueue_style( 'cannect-gutenberg-custom-style' );
wp_add_inline_style( 'cannect-gutenberg-custom-style', $editor_css );
}
add_action( 'enqueue_block_editor_assets', 'cannect_enqueue_block_editor_assets' );