'Pensamientos', 'per_page' => (string) FEA_GALLERY_PER_PAGE, 'order' => 'desc', ], $atts, 'fea_galeria'); $dir = fea_gallery_safe_dir((string) $atts['dir']); if ($dir === '') return ''; $order = strtolower((string) $atts['order']) === 'asc' ? 'asc' : 'desc'; $files = fea_gallery_files($dir, $order); if (!$files) { return ''; } $per_page = max(12, min(144, (int) $atts['per_page'])); $total = count($files); $pages = max(1, (int) ceil($total / $per_page)); $param = fea_gallery_page_param($dir); $page = isset($_GET[$param]) ? max(1, (int) $_GET[$param]) : 1; $page = min($page, $pages); $offset = ($page - 1) * $per_page; $visible = array_slice($files, $offset, $per_page); $html = ''; return $html; } add_shortcode('fea_galeria', 'fea_gallery_render'); add_filter('the_content', function ($content) { if (is_admin() || stripos($content, '{gallery}') === false) return $content; return preg_replace_callback( '/\{gallery\}\s*([^{}]+?)\s*\{\/gallery\}/i', function ($m) { return fea_gallery_render(['dir' => trim($m[1])]); }, $content ); }, 8); function fea_random_thought_html(): string { $files = fea_gallery_files('Pensamientos', 'desc'); if (!$files) return ''; $file = $files[array_rand($files)]; $url = fea_gallery_url('Pensamientos', $file); return ''; } function fea_random_thought_excluded(): bool { if (!is_singular('post')) return true; $post_id = get_the_ID(); $excluded_ids = array_filter(array_map('intval', explode(',', (string) FEA_RANDOM_THOUGHT_EXCLUDED_IDS))); if ($post_id && in_array((int) $post_id, $excluded_ids, true)) return true; if ($post_id) { $raw = (string) get_post_field('post_content', $post_id); if (stripos($raw, '{gallery}') !== false || stripos($raw, '[fea_galeria') !== false) { return true; } } $ids = array_filter(array_map('intval', explode(',', (string) FEA_RANDOM_THOUGHT_EXCLUDED_CATS))); foreach ($ids as $id) { if ($id > 0 && has_category($id)) return true; } return false; } add_shortcode('fea_reflexion_aleatoria', function () { return fea_random_thought_html(); }); add_filter('the_content', function ($content) { if (is_admin() || !is_main_query() || !in_the_loop() || fea_random_thought_excluded()) { return $content; } if (strpos($content, 'fea-random-thought') !== false) return $content; $thought = fea_random_thought_html(); return $thought ? $content . $thought : $content; }, 18); function fea_pensamientos_assets_needed(): bool { if (!is_singular()) return false; $post_id = get_queried_object_id(); $raw = $post_id ? (string) get_post_field('post_content', $post_id) : ''; if (stripos($raw, '{gallery}') !== false || stripos($raw, '[fea_galeria') !== false || stripos($raw, '[fea_reflexion_aleatoria') !== false) { return true; } return !fea_random_thought_excluded(); } add_action('wp_head', function () { if (!fea_pensamientos_assets_needed()) return; ?>