feat: Enable search engine indexing for sites and update related configurations

This commit is contained in:
2026-03-04 14:02:20 +01:00
parent 207edca896
commit 7ff7ff3a92
7 changed files with 157 additions and 3 deletions

View File

@@ -469,7 +469,7 @@ PHP;
'admin_password' => $config['admin_pass'],
'admin_password2' => $config['admin_pass'],
'admin_email' => $config['admin_email'],
'blog_public' => 0,
'blog_public' => 1,
],
'timeout' => 60,
'allow_redirects' => true,

View File

@@ -12,7 +12,7 @@ class WordPressService
{
private const BACKPRO_MU_PLUGIN_FILENAME = 'backpro-remote-tools.php';
private const BACKPRO_REMOTE_SERVICE_FILENAME = 'backpro-remote-service.php';
private const BACKPRO_REMOTE_SERVICE_VERSION = '1.3.0';
private const BACKPRO_REMOTE_SERVICE_VERSION = '1.4.0';
private const BACKPRO_NEWS_THEME_SLUG = 'backpro-news-mag';
private const BACKPRO_NEWS_THEME_SOURCE_DIR = 'assets/wp-theme-backpro-news';
private Client $client;
@@ -434,6 +434,41 @@ class WordPressService
return ['success' => false, 'message' => (string) ($retry['message'] ?? 'Blad zmiany permalink.')];
}
public function enableSearchEngineIndexing(array $site): array
{
$result = $this->callRemoteService($site, 'set_blog_public', ['blog_public' => '1']);
if (!empty($result['success'])) {
return [
'success' => true,
'blog_public' => (int) ($result['blog_public'] ?? 1),
'message' => (string) ($result['message'] ?? 'Wlaczono indeksowanie strony.'),
];
}
$ensure = $this->ensureRemoteService($site);
if (empty($ensure['success'])) {
return [
'success' => false,
'message' => (string) ($ensure['message'] ?? $result['message'] ?? 'Brak endpointu BackPRO na WordPress.'),
];
}
$refreshedSite = !empty($site['id']) ? (Site::find((int) $site['id']) ?: $site) : $site;
$retry = $this->callRemoteService($refreshedSite, 'set_blog_public', ['blog_public' => '1']);
if (!empty($retry['success'])) {
return [
'success' => true,
'blog_public' => (int) ($retry['blog_public'] ?? 1),
'message' => (string) ($retry['message'] ?? 'Wlaczono indeksowanie strony.'),
];
}
return [
'success' => false,
'message' => (string) ($retry['message'] ?? 'Nie udalo sie wlaczyc indeksowania strony.'),
];
}
public function ensureRemoteService(array $site): array
{
$siteData = $this->prepareRemoteServiceMetadata($site);
@@ -1047,7 +1082,7 @@ if (!defined('ABSPATH')) {
\$action = (string) (\$_POST['action'] ?? '');
if (\$action === 'ping') {
echo json_encode(['success' => true, 'message' => 'pong', 'version' => '1.3.0']);
echo json_encode(['success' => true, 'message' => 'pong', 'version' => '1.4.0']);
exit;
}
@@ -1117,6 +1152,23 @@ if (\$action === 'activate_theme') {
exit;
}
if (\$action === 'set_blog_public') {
\$blogPublicRaw = (string) (\$_POST['blog_public'] ?? '1');
\$blogPublic = \$blogPublicRaw === '0' ? 0 : 1;
update_option('blog_public', \$blogPublic);
\$applied = (int) get_option('blog_public', 1);
echo json_encode([
'success' => true,
'blog_public' => \$applied,
'message' => \$applied === 1
? 'Indeksowanie przez wyszukiwarki jest wlaczone.'
: 'Indeksowanie przez wyszukiwarki jest wylaczone.',
]);
exit;
}
if (\$action === 'cleanup') {
@unlink(__FILE__);
echo json_encode(['success' => true, 'message' => 'service_deleted']);