acesso direto
if (!defined('ABSPATH')) {
exit;
}
/**
* ===== CONFIGURAÇÕES BÁSICAS DO TEMA =====
*/
// Define constantes do tema
define('ANIMENEW_VERSION', '1.0.0');
define('ANIMENEW_THEME_DIR', get_template_directory());
define('ANIMENEW_THEME_URL', get_template_directory_uri());
/**
* Setup do tema
*/
function animenew_theme_setup() {
// Suporte a tradução
load_theme_textdomain('animenew', ANIMENEW_THEME_DIR . '/languages');
// Suporte automático ao feed RSS
add_theme_support('automatic-feed-links');
// Suporte ao título dinâmico
add_theme_support('title-tag');
// Suporte a imagens destacadas
add_theme_support('post-thumbnails');
// Tamanhos de imagem personalizados
add_image_size('animenew-card', 400, 225, true); // 16:9 para cards
add_image_size('animenew-featured', 800, 450, true); // Featured posts
add_image_size('animenew-large', 1200, 675, true); // Posts individuais
// Suporte a HTML5
add_theme_support('html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
));
// Suporte a logo customizável
add_theme_support('custom-logo', array(
'height' => 50,
'width' => 200,
'flex-width' => true,
'flex-height' => true,
));
// Suporte a refresh seletivo no customizer
add_theme_support('customize-selective-refresh-widgets');
// Registrar menus
register_nav_menus(array(
'primary' => __('Menu Principal', 'animenew'),
'footer' => __('Menu do Rodapé', 'animenew'),
));
}
add_action('after_setup_theme', 'animenew_theme_setup');
/**
* ===== ENFILEIRAMENTO DE SCRIPTS E ESTILOS =====
*/
function animenew_scripts() {
// CSS principal
wp_enqueue_style(
'animenew-style',
ANIMENEW_THEME_URL . '/style.css',
array(),
ANIMENEW_VERSION
);
// Font Awesome para ícones
wp_enqueue_style(
'font-awesome',
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css',
array(),
'6.0.0'
);
// JavaScript principal
wp_enqueue_script(
'animenew-script',
ANIMENEW_THEME_URL . '/assets/js/main.js',
array('jquery'),
ANIMENEW_VERSION,
true
);
// Localizar script para AJAX
wp_localize_script('animenew-script', 'animenew_ajax', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('animenew_nonce'),
));
// Comment reply script
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'animenew_scripts');
/**
* ===== ÁREAS DE WIDGETS =====
*/
function animenew_widgets_init() {
// Sidebar principal
register_sidebar(array(
'name' => __('Sidebar Principal', 'animenew'),
'id' => 'sidebar-1',
'description' => __('Widgets da sidebar principal', 'animenew'),
'before_widget' => '',
'before_title' => '
',
));
// Área do rodapé
register_sidebar(array(
'name' => __('Rodapé', 'animenew'),
'id' => 'footer-1',
'description' => __('Widgets do rodapé', 'animenew'),
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
));
}
add_action('widgets_init', 'animenew_widgets_init');
/**
* ===== FUNÇÕES AUXILIARES =====
*/
/**
* Obter excerpt personalizado
*/
function animenew_get_excerpt($limit = 150) {
$excerpt = get_the_excerpt();
if (strlen($excerpt) > $limit) {
$excerpt = substr($excerpt, 0, $limit) . '...';
}
return $excerpt;
}
/**
* Obter tempo de leitura estimado
*/
function animenew_reading_time() {
$content = get_post_field('post_content', get_the_ID());
$word_count = str_word_count(strip_tags($content));
$reading_time = ceil($word_count / 200); // 200 palavras por minuto
if ($reading_time == 1) {
return '1 min de leitura';
} else {
return $reading_time . ' min de leitura';
}
}
/**
* Formatar data em português
*/
function animenew_format_date($date = null) {
if (!$date) {
$date = get_the_date('Y-m-d');
}
$months = array(
'01' => 'Janeiro', '02' => 'Fevereiro', '03' => 'Março',
'04' => 'Abril', '05' => 'Maio', '06' => 'Junho',
'07' => 'Julho', '08' => 'Agosto', '09' => 'Setembro',
'10' => 'Outubro', '11' => 'Novembro', '12' => 'Dezembro'
);
$date_parts = explode('-', $date);
$day = $date_parts[2];
$month = $months[$date_parts[1]];
$year = $date_parts[0];
return $day . ' de ' . $month . ' de ' . $year;
}
/**
* ===== BREADCRUMBS =====
*/
function animenew_breadcrumbs() {
if (is_home() || is_front_page()) return;
$separator = ' > ';
$home_title = 'Home';
echo '';
}
/**
* ===== PAGINAÇÃO CUSTOMIZADA =====
*/
function animenew_pagination($pages = '', $range = 4) {
$showitems = ($range * 2) + 1;
global $paged;
if (empty($paged)) $paged = 1;
if ($pages == '') {
global $wp_query;
$pages = $wp_query->max_num_pages;
if (!$pages) {
$pages = 1;
}
}
if (1 != $pages) {
echo "\n";
}
}
/**
* ===== OTIMIZAÇÕES DE PERFORMANCE =====
*/
// Remove query strings dos recursos estáticos
function animenew_remove_script_version($src) {
$parts = explode('?ver', $src);
return $parts[0];
}
add_filter('script_loader_src', 'animenew_remove_script_version', 15, 1);
add_filter('style_loader_src', 'animenew_remove_script_version', 15, 1);
// Desabilitar emojis para melhor performance
function animenew_disable_emojis() {
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
}
add_action('init', 'animenew_disable_emojis');
/**
* ===== SEO BÁSICO =====
*/
// Meta tags básicas
function animenew_meta_tags() {
if (is_single()) {
global $post;
$excerpt = animenew_get_excerpt(160);
echo '' . "\n";
if (has_post_thumbnail()) {
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
echo '' . "\n";
}
}
}
add_action('wp_head', 'animenew_meta_tags');
/**
* ===== LIMPEZA DO WP_HEAD =====
*/
// Remove links desnecessários
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head');
/**
* ===== CUSTOMIZAÇÕES DO ADMIN =====
*/
// Adicionar thumbnail na listagem de posts
function animenew_add_thumbnail_column($columns) {
$columns['thumbnail'] = 'Imagem';
return $columns;
}
add_filter('manage_posts_columns', 'animenew_add_thumbnail_column');
function animenew_show_thumbnail_column($column_name, $post_id) {
if ($column_name == 'thumbnail') {
if (has_post_thumbnail($post_id)) {
echo get_the_post_thumbnail($post_id, 'thumbnail');
} else {
echo 'Sem imagem';
}
}
}
add_action('manage_posts_custom_column', 'animenew_show_thumbnail_column', 10, 2);
/**
* ===== COMPATIBILIDADE COM PLUGINS =====
*/
/**
* Compatibilidade com Yoast SEO
*/
function animenew_yoast_compatibility() {
// Remover breadcrumbs próprios se Yoast estiver ativo
if (function_exists('yoast_breadcrumb')) {
remove_action('animenew_breadcrumbs', 'animenew_breadcrumbs');
// Usar breadcrumbs do Yoast
function animenew_yoast_breadcrumbs() {
if (function_exists('yoast_breadcrumb') && !is_front_page()) {
yoast_breadcrumb('');
}
}
add_action('animenew_breadcrumbs', 'animenew_yoast_breadcrumbs');
}
}
add_action('init', 'animenew_yoast_compatibility');
/**
* Compatibilidade com WP Rocket
*/
function animenew_wp_rocket_compatibility() {
// Adicionar preload para recursos críticos
add_action('wp_head', function() {
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
}, 1);
}
add_action('init', 'animenew_wp_rocket_compatibility');
/**
* Compatibilidade com WooCommerce
*/
function animenew_woocommerce_support() {
add_theme_support('woocommerce');
add_theme_support('wc-product-gallery-zoom');
add_theme_support('wc-product-gallery-lightbox');
add_theme_support('wc-product-gallery-slider');
}
add_action('after_setup_theme', 'animenew_woocommerce_support');
/**
* Compatibilidade com Contact Form 7
*/
function animenew_cf7_compatibility() {
// Estilos personalizados para formulários
add_action('wp_enqueue_scripts', function() {
if (function_exists('wpcf7_enqueue_scripts')) {
wp_add_inline_style('animenew-style', '
.wpcf7-form {
background: var(--secondary-color);
padding: 2rem;
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
}
.wpcf7-form input,
.wpcf7-form textarea {
background: var(--background-darker);
border: 1px solid var(--border-color);
color: var(--text-color);
padding: 0.75rem;
border-radius: var(--border-radius);
width: 100%;
margin-bottom: 1rem;
}
.wpcf7-form input[type="submit"] {
background: var(--primary-color);
color: white;
border: none;
cursor: pointer;
font-weight: 600;
transition: var(--transition);
}
.wpcf7-form input[type="submit"]:hover {
background: #cc003a;
}
');
}
});
}
add_action('init', 'animenew_cf7_compatibility');
/**
* Compatibilidade com Jetpack
*/
function animenew_jetpack_compatibility() {
// Suporte a funcionalidades do Jetpack
add_theme_support('infinite-scroll', array(
'container' => 'posts-container',
'render' => 'animenew_infinite_scroll_render',
'footer' => 'page',
));
add_theme_support('jetpack-responsive-videos');
add_theme_support('jetpack-social-menu');
}
add_action('after_setup_theme', 'animenew_jetpack_compatibility');
/**
* Render function para Jetpack Infinite Scroll
*/
function animenew_infinite_scroll_render() {
while (have_posts()) {
the_post();
get_template_part('template-parts/content', 'card');
}
}
/**
* Compatibilidade com Elementor
*/
function animenew_elementor_compatibility() {
// Suporte a widgets do Elementor
add_theme_support('elementor');
// Registrar áreas de widget para Elementor
if (did_action('elementor/loaded')) {
add_action('elementor/widgets/widgets_registered', function() {
// Registrar widgets customizados se necessário
});
}
}
add_action('init', 'animenew_elementor_compatibility');
/**
* Compatibilidade com plugins de cache
*/
function animenew_cache_compatibility() {
// Otimizações para W3 Total Cache, WP Super Cache, etc.
if (!is_admin()) {
// Adicionar headers de cache
add_action('send_headers', function() {
if (!is_user_logged_in() && !is_admin()) {
header('Cache-Control: public, max-age=3600');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
}
});
}
}
add_action('init', 'animenew_cache_compatibility');
/**
* Compatibilidade com plugins de SEO (geral)
*/
function animenew_seo_plugins_compatibility() {
// RankMath, All in One SEO, etc.
remove_action('wp_head', 'animenew_meta_tags'); // Remove nossas meta tags se plugin SEO ativo
if (function_exists('rank_math') ||
function_exists('aioseo') ||
class_exists('WPSEO_Options')) {
// Plugin SEO detectado, usar suas meta tags
return;
}
// Caso contrário, usar nossas meta tags
add_action('wp_head', 'animenew_meta_tags');
}
add_action('wp_head', 'animenew_seo_plugins_compatibility', 1);
/**
* Compatibilidade com GDPR/LGPD plugins
*/
function animenew_gdpr_compatibility() {
// Cookie Notice, GDPR Cookie Compliance, etc.
add_action('wp_footer', function() {
if (function_exists('cn_cookies_accepted') ||
function_exists('gdpr_cookie_is_accepted')) {
echo '';
}
});
}
add_action('init', 'animenew_gdpr_compatibility');
/**
* ===== AJAX HANDLERS PARA PLUGINS =====
*/
/**
* AJAX para incrementar visualizações
*/
function animenew_ajax_increment_views() {
check_ajax_referer('animenew_nonce', 'nonce');
$post_id = intval($_POST['post_id']);
if ($post_id) {
$views = get_post_meta($post_id, 'views', true);
$views = $views ? $views + 1 : 1;
update_post_meta($post_id, 'views', $views);
wp_send_json_success(array('views' => $views));
}
wp_send_json_error();
}
add_action('wp_ajax_increment_post_views', 'animenew_ajax_increment_views');
add_action('wp_ajax_nopriv_increment_post_views', 'animenew_ajax_increment_views');
/**
* AJAX para busca instantânea
*/
function animenew_ajax_instant_search() {
check_ajax_referer('animenew_nonce', 'nonce');
$query = sanitize_text_field($_POST['query']);
$posts = get_posts(array(
'post_type' => 'post',
'posts_per_page' => 5,
's' => $query,
'post_status' => 'publish'
));
$results = array();
foreach ($posts as $post) {
$results[] = array(
'title' => get_the_title($post->ID),
'url' => get_permalink($post->ID),
'thumbnail' => get_the_post_thumbnail_url($post->ID, 'thumbnail'),
'category' => get_the_category($post->ID)[0]->name ?? ''
);
}
wp_send_json_success($results);
}
add_action('wp_ajax_instant_search', 'animenew_ajax_instant_search');
add_action('wp_ajax_nopriv_instant_search', 'animenew_ajax_instant_search');
/**
* AJAX para carregar mais posts
*/
function animenew_ajax_load_more_posts() {
check_ajax_referer('animenew_nonce', 'nonce');
$page = intval($_POST['page']);
$posts = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => $page,
'post_status' => 'publish'
));
if ($posts->have_posts()) {
ob_start();
while ($posts->have_posts()) {
$posts->the_post();
get_template_part('template-parts/content', 'card');
}
wp_reset_postdata();
$html = ob_get_clean();
wp_send_json_success(array('posts' => $html));
}
wp_send_json_error();
}
add_action('wp_ajax_load_more_posts', 'animenew_ajax_load_more_posts');
add_action('wp_ajax_nopriv_load_more_posts', 'animenew_ajax_load_more_posts');
/**
* Compatibilidade com Linguise
*/
function animenew_linguise_compatibility() {
// Detectar se Linguise está ativo
if (function_exists('linguise_init') || class_exists('Linguise')) {
// 1. Garantir que JavaScript não interfira com tradução
add_action('wp_enqueue_scripts', function() {
wp_add_inline_script('animenew-script', '
// Aguardar Linguise carregar antes de inicializar funcionalidades
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
// Re-inicializar eventos após tradução
if (window.AnimeNewUtils) {
window.AnimeNewUtils.reinitAfterTranslation();
}
}, 1000);
});
');
});
// 2. Adicionar classes para elementos que não devem ser traduzidos
add_action('wp_head', function() {
echo '';
});
// 3. Meta tags para Linguise
add_action('wp_head', function() {
echo '' . "\n";
echo '' . "\n";
}, 5);
// 4. Configurações de cache compatíveis
add_filter('linguise_cache_enabled', '__return_true');
// 5. Garantir URLs corretas para diferentes idiomas
add_filter('theme_mod_custom_logo', 'animenew_linguise_logo_url');
add_filter('home_url', 'animenew_linguise_home_url', 10, 2);
}
}
add_action('init', 'animenew_linguise_compatibility');
/**
* Ajustar URL do logo para diferentes idiomas
*/
function animenew_linguise_logo_url($logo_id) {
if (function_exists('linguise_get_current_language_code')) {
$current_lang = linguise_get_current_language_code();
if ($current_lang && $current_lang !== 'pt') {
// Manter mesmo logo para todos os idiomas
return $logo_id;
}
}
return $logo_id;
}
/**
* Garantir URLs corretas para home
*/
function animenew_linguise_home_url($url, $path) {
if (function_exists('linguise_get_current_language_code')) {
$current_lang = linguise_get_current_language_code();
if ($current_lang && $current_lang !== 'pt') {
// Linguise já gerencia as URLs
return $url;
}
}
return $url;
}
/**
* Textos traduzíveis do tema
*/
function animenew_linguise_translatable_strings() {
// Registrar strings para tradução automática
$strings = array(
'Últimas Notícias' => __('Latest News', 'animenew'),
'Ver Mais' => __('View More', 'animenew'),
'Leia Mais' => __('Read More', 'animenew'),
'Compartilhe' => __('Share', 'animenew'),
'Resultado de' => __('Search results for', 'animenew'),
'Posts Relacionados' => __('Related Posts', 'animenew'),
'Página não encontrada' => __('Page not found', 'animenew'),
'Voltar ao topo' => __('Back to top', 'animenew'),
'Menu' => __('Menu', 'animenew'),
'Buscar' => __('Search', 'animenew'),
'Por' => __('By', 'animenew'),
'Em' => __('In', 'animenew'),
'Tags' => __('Tags', 'animenew'),
'Home' => __('Home', 'animenew'),
'Contato' => __('Contact', 'animenew'),
'Sobre' => __('About', 'animenew'),
'Política de Privacidade' => __('Privacy Policy', 'animenew'),
'Termos de Uso' => __('Terms of Use', 'animenew')
);
return $strings;
}
/**
* Suporte a hreflang para SEO multilíngue
*/
function animenew_linguise_hreflang() {
if (function_exists('linguise_get_available_languages')) {
$languages = linguise_get_available_languages();
$current_url = get_permalink();
foreach ($languages as $lang_code => $lang_name) {
$lang_url = function_exists('linguise_get_language_url')
? linguise_get_language_url($current_url, $lang_code)
: $current_url;
echo '' . "\n";
}
// Adicionar x-default
echo '' . "\n";
}
}
add_action('wp_head', 'animenew_linguise_hreflang');
/**
* Configurações específicas para Linguise
*/
function animenew_linguise_settings() {
// Elementos que NÃO devem ser traduzidos
add_action('wp_head', function() {
echo '';
});
}
add_action('wp_head', 'animenew_linguise_settings', 20);
?>{"version":"1.0","provider_name":"AnimeNew","provider_url":"https:\/\/animenew.com.br","author_name":"Alann","author_url":"https:\/\/animenew.com.br\/author\/alann\/","title":"Novo trailer de BEASTARS","type":"rich","width":600,"height":338,"html":"Novo trailer de BEASTARS<\/a><\/blockquote>