- Create PostGridShortcodeRegistrar for WordPress shortcode registration - Implement RenderPostGridUseCase following Clean Architecture - Add PostGridQueryBuilder for custom WP_Query construction - Add PostGridShortcodeRenderer for HTML/CSS generation - Register shortcode in DIContainer with proper DI - Add shortcode usage guide in post-grid admin panel - Fix sidebar layout: add hide_for_logged_in check to wrapper visibility Shortcode attributes: category, tag, author, posts_per_page, columns, show_pagination, show_thumbnail, show_excerpt, show_meta, etc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace ROITheme\Shared\Application\UseCases\RenderPostGrid;
|
|
|
|
use ROITheme\Shared\Domain\Contracts\PostGridQueryBuilderInterface;
|
|
use ROITheme\Shared\Domain\Contracts\PostGridShortcodeRendererInterface;
|
|
use ROITheme\Shared\Domain\Contracts\ComponentSettingsRepositoryInterface;
|
|
use ROITheme\Shared\Domain\Constants\VisibilityDefaults;
|
|
|
|
/**
|
|
* Caso de uso: Renderizar grid de posts para shortcode
|
|
*
|
|
* RESPONSABILIDAD: Orquestar la obtencion de settings, construccion de query
|
|
* y renderizado del grid. No contiene logica de negocio, solo coordinacion.
|
|
*
|
|
* @package ROITheme\Shared\Application\UseCases\RenderPostGrid
|
|
*/
|
|
final class RenderPostGridUseCase
|
|
{
|
|
private const COMPONENT_NAME = 'post-grid';
|
|
|
|
public function __construct(
|
|
private readonly PostGridQueryBuilderInterface $queryBuilder,
|
|
private readonly PostGridShortcodeRendererInterface $renderer,
|
|
private readonly ComponentSettingsRepositoryInterface $settingsRepository
|
|
) {}
|
|
|
|
/**
|
|
* Ejecuta el caso de uso: obtiene settings, construye query y renderiza
|
|
*
|
|
* @param RenderPostGridRequest $request DTO con atributos del shortcode
|
|
* @return string HTML del grid renderizado
|
|
*/
|
|
public function execute(RenderPostGridRequest $request): string
|
|
{
|
|
// 1. Obtener settings del componente post-grid desde BD
|
|
$settings = $this->getSettings();
|
|
|
|
// 2. Construir query con los parametros del shortcode
|
|
$query = $this->queryBuilder->build($request->toQueryParams());
|
|
|
|
// 3. Renderizar grid con query, settings y opciones
|
|
$html = $this->renderer->render(
|
|
$query,
|
|
$settings,
|
|
$request->toRenderOptions()
|
|
);
|
|
|
|
// 4. Limpiar query (importante para evitar conflictos)
|
|
wp_reset_postdata();
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* Obtiene settings del componente post-grid
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function getSettings(): array
|
|
{
|
|
$settings = $this->settingsRepository->getComponentSettings(self::COMPONENT_NAME);
|
|
|
|
if (empty($settings)) {
|
|
return VisibilityDefaults::getForComponent(self::COMPONENT_NAME);
|
|
}
|
|
|
|
return $settings;
|
|
}
|
|
}
|