update
This commit is contained in:
@@ -132,7 +132,8 @@ class WordPressService
|
||||
string $title,
|
||||
string $content,
|
||||
?int $categoryId = null,
|
||||
?int $mediaId = null
|
||||
?int $mediaId = null,
|
||||
?string $excerpt = null
|
||||
): ?int {
|
||||
$auth = $this->requireAuthOption($site, 'createPost');
|
||||
if ($auth === null) {
|
||||
@@ -155,6 +156,10 @@ class WordPressService
|
||||
$postData['featured_media'] = $mediaId;
|
||||
}
|
||||
|
||||
if (is_string($excerpt) && trim($excerpt) !== '') {
|
||||
$postData['excerpt'] = trim($excerpt);
|
||||
}
|
||||
|
||||
$response = $this->requestWp($site, 'POST', 'wp/v2/posts', [
|
||||
'auth' => $auth,
|
||||
'json' => $postData,
|
||||
@@ -171,7 +176,7 @@ class WordPressService
|
||||
}
|
||||
|
||||
// Fall back to XML-RPC.
|
||||
return $this->createPostXmlRpc($site, $auth, $title, $content, $categoryId, $mediaId);
|
||||
return $this->createPostXmlRpc($site, $auth, $title, $content, $categoryId, $mediaId, $excerpt);
|
||||
}
|
||||
|
||||
public function getPublishedPosts(array $site, int $perPage = 100): array|false
|
||||
@@ -188,7 +193,7 @@ class WordPressService
|
||||
'status' => 'publish',
|
||||
'per_page' => $perPage,
|
||||
'page' => $page,
|
||||
'_fields' => 'id,title,content,date,categories',
|
||||
'_fields' => 'id,title,content,date,categories,link',
|
||||
];
|
||||
$options = ['query' => $query];
|
||||
if ($auth !== null) {
|
||||
@@ -434,6 +439,29 @@ class WordPressService
|
||||
return ['success' => false, 'message' => (string) ($retry['message'] ?? 'Blad zmiany permalink.')];
|
||||
}
|
||||
|
||||
public function getPostLink(array $site, int $wpPostId): ?string
|
||||
{
|
||||
if ($wpPostId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$auth = $this->buildAuthOption($site);
|
||||
$options = ['query' => ['_fields' => 'link']];
|
||||
if ($auth !== null) {
|
||||
$options['auth'] = $auth;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->requestWp($site, 'GET', 'wp/v2/posts/' . $wpPostId, $options);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$link = trim((string) ($data['link'] ?? ''));
|
||||
return $link !== '' ? $link : null;
|
||||
} catch (GuzzleException $e) {
|
||||
Logger::warning("WP getPostLink failed for {$site['url']}: " . $e->getMessage(), 'wordpress');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function enableSearchEngineIndexing(array $site): array
|
||||
{
|
||||
$result = $this->callRemoteService($site, 'set_blog_public', ['blog_public' => '1']);
|
||||
@@ -619,12 +647,24 @@ class WordPressService
|
||||
|
||||
// ── XML-RPC fallback methods ──────────────────────────────────────
|
||||
|
||||
private function createPostXmlRpc(array $site, array $auth, string $title, string $content, ?int $categoryId, ?int $mediaId): ?int
|
||||
private function createPostXmlRpc(
|
||||
array $site,
|
||||
array $auth,
|
||||
string $title,
|
||||
string $content,
|
||||
?int $categoryId,
|
||||
?int $mediaId,
|
||||
?string $excerpt
|
||||
): ?int
|
||||
{
|
||||
$fields = '<member><name>post_title</name><value><string>' . $this->xmlEsc($title) . '</string></value></member>'
|
||||
. '<member><name>post_content</name><value><string>' . $this->xmlEsc($content) . '</string></value></member>'
|
||||
. '<member><name>post_status</name><value><string>publish</string></value></member>';
|
||||
|
||||
if (is_string($excerpt) && trim($excerpt) !== '') {
|
||||
$fields .= '<member><name>mt_excerpt</name><value><string>' . $this->xmlEsc(trim($excerpt)) . '</string></value></member>';
|
||||
}
|
||||
|
||||
if ($categoryId) {
|
||||
$fields .= '<member><name>terms</name><value><struct>'
|
||||
. '<member><name>category</name><value><array><data>'
|
||||
|
||||
Reference in New Issue
Block a user