feat: Page Editor Phase 1 - Core Infrastructure

- Add is_bot() detection in TemplateOverride.php (30+ bot patterns)
- Add PageSSR.php for server-side rendering of page sections
- Add PlaceholderRenderer.php for dynamic content resolution
- Add PagesController.php REST API for pages/templates CRUD
- Register PagesController routes in Routes.php

API Endpoints:
- GET /pages - list all pages/templates
- GET /pages/{slug} - get page structure
- POST /pages/{slug} - save page
- GET /templates/{cpt} - get CPT template
- POST /templates/{cpt} - save template
- GET /content/{type}/{slug} - get content with template applied
This commit is contained in:
Dwindi Ramadhana
2026-01-11 22:29:30 +07:00
parent 1ff9a36af3
commit 9331989102
6 changed files with 1857 additions and 0 deletions

View File

@@ -648,4 +648,100 @@ class TemplateOverride
return $template;
}
/**
* Detect if current request is from a bot/crawler
* Used to serve SSR content for SEO instead of SPA redirect
*
* @return bool True if request is from a known bot
*/
public static function is_bot()
{
// Get User-Agent
$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
if (empty($user_agent)) {
return false;
}
// Convert to lowercase for case-insensitive matching
$user_agent = strtolower($user_agent);
// Known bot patterns
$bot_patterns = [
// Search engine crawlers
'googlebot',
'bingbot',
'slurp', // Yahoo
'duckduckbot',
'baiduspider',
'yandexbot',
'sogou',
'exabot',
// Generic patterns
'crawler',
'spider',
'robot',
'scraper',
// Social media bots (for link previews)
'facebookexternalhit',
'twitterbot',
'linkedinbot',
'whatsapp',
'slackbot',
'telegrambot',
'discordbot',
// Other known bots
'applebot',
'semrushbot',
'ahrefsbot',
'mj12bot',
'dotbot',
'petalbot',
'bytespider',
// Prerender services
'prerender',
'headlesschrome',
];
// Check if User-Agent contains any bot pattern
foreach ($bot_patterns as $pattern) {
if (strpos($user_agent, $pattern) !== false) {
return true;
}
}
return false;
}
/**
* Serve SSR content for bots
* Renders page structure as static HTML for search engine indexing
*
* @param int $page_id Page ID to render
* @param string $type 'page' or 'template'
* @param array|null $post_data Post data for template rendering (CPT items)
*/
public static function serve_ssr_content($page_id, $type = 'page', $post_data = null)
{
// Get page structure
if ($type === 'page') {
$structure = get_post_meta($page_id, '_wn_page_structure', true);
} else {
// CPT template
$structure = get_option("wn_template_{$type}", null);
}
if (empty($structure) || empty($structure['sections'])) {
return false; // No structure, let normal WP handle it
}
// Will be implemented in PageSSR class
// For now, return false to let normal WP handle
// TODO: Implement PageSSR::render($structure, $post_data)
return false;
}
}