post_status !== 'publish') return false; $options = alcastromol_get_cache_options(); $types = isset($options['post_types']) && is_array($options['post_types']) ? $options['post_types'] : []; return in_array($post->post_type, $types, true); } function alcastromol_tailwind_get_post_cache_action_url($post_id, $context = 'admin') { $post_id = absint($post_id); $endpoint = admin_url('admin-post.php'); if ($context === 'front' && function_exists('pll_home_url')) { $endpoint = trailingslashit(pll_home_url()) . 'wp-admin/admin-post.php'; } $url = add_query_arg([ 'action' => 'alcastromol_generate_tailwind_post_cache', 'post_id' => $post_id, 'context' => sanitize_key($context), ], $endpoint); return wp_nonce_url($url, 'alcastromol_generate_tailwind_post_cache_' . $post_id); } function alcastromol_tailwind_add_post_row_action($actions, $post) { if (function_exists('alcastromol_is_module_active') && !alcastromol_is_module_active('cache')) return $actions; if (!current_user_can('manage_options') || !alcastromol_tailwind_post_is_cacheable($post)) return $actions; $actions['alcastromol_tailwind_cache'] = sprintf( '%s', esc_url(alcastromol_tailwind_get_post_cache_action_url($post->ID, 'admin')), esc_attr(sprintf('Generar cache Tailwind para %s', get_the_title($post))), esc_html__('Generar cache Tailwind') ); return $actions; } add_filter('post_row_actions', 'alcastromol_tailwind_add_post_row_action', 20, 2); add_filter('page_row_actions', 'alcastromol_tailwind_add_post_row_action', 20, 2); add_action('admin_post_alcastromol_generate_tailwind_post_cache', function () { $post_id = absint($_REQUEST['post_id'] ?? 0); $context = sanitize_key($_REQUEST['context'] ?? 'admin'); if (!$post_id || !current_user_can('manage_options') || !current_user_can('edit_post', $post_id)) { wp_die('No tienes permisos para generar este cache.'); } check_admin_referer('alcastromol_generate_tailwind_post_cache_' . $post_id); $post = get_post($post_id); if (!$post || !alcastromol_tailwind_post_is_cacheable($post)) { wp_die('Este post type no está activo en la configuración de cache de Tailwind.'); } $url = get_permalink($post_id); $slug = alcastromol_get_post_cache_slug($post_id); $ok = $url && $slug ? alcastromol_cache_url($url, $slug) : false; if ($context === 'front') { wp_redirect($url ?: home_url('/')); exit; } $object = get_post_type_object($post->post_type); $fallback = ($object && $object->show_ui) ? add_query_arg('post_type', $post->post_type, admin_url('edit.php')) : admin_url('edit.php'); $redirect = wp_get_referer() ?: $fallback; $redirect = add_query_arg([ 'tailwind_post_cache' => $ok ? 'generated' : 'failed', 'tailwind_post_id' => $post_id, ], $redirect); wp_safe_redirect($redirect); exit; }); add_action('admin_notices', function () { if (empty($_GET['tailwind_post_cache'])) return; $status = sanitize_key($_GET['tailwind_post_cache']); $post_id = absint($_GET['tailwind_post_id'] ?? 0); if ($status === 'generated') { echo '
Cache Tailwind generado. '; echo $post_id ? 'Entrada #' . esc_html($post_id) . '.' : ''; echo '
No se pudo generar el cache Tailwind de la entrada.
Genera el archivo CSS productivo utilizando el cache HTML actual y Tailwind Standalone CLI.
Tamaño:
· Modificado:
| Modo actual |
· Cambiar a producción |
| CLI detectado | No detectado |
| CSS productivo |
· |