Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix category creation error when using xmlrpc #1443

Merged
merged 2 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions var/Typecho/Widget/Helper/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Typecho\Widget\Helper;

use Typecho\Cookie;
use Typecho\Request;
use Typecho\Validate;
use Typecho\Widget\Helper\Form\Element;

Expand Down Expand Up @@ -131,10 +132,10 @@ public function getInput(string $name)
public function getAllRequest(): array
{
$result = [];
$source = (self::POST_METHOD == $this->getAttribute('method')) ? $_POST : $_GET;
$request = Request::getInstance();

foreach ($this->inputs as $name => $input) {
$result[$name] = $source[$name] ?? null;
$result[$name] = $request->get($name, null);
}
return $result;
}
Expand Down Expand Up @@ -204,10 +205,10 @@ public function validate(): array
public function getParams(array $params): array
{
$result = [];
$source = (self::POST_METHOD == $this->getAttribute('method')) ? $_POST : $_GET;
$request = Request::getInstance();

foreach ($params as $param) {
$result[$param] = $source[$param] ?? null;
$result[$param] = $request->get($param, null);
}

return $result;
Expand Down
8 changes: 6 additions & 2 deletions var/Widget/XmlRpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ public function mwNewPost(int $blogId, string $userName, string $password, array
*/
public function wpNewCategory(int $blogId, string $userName, string $password, array $category): int
{

/** 开始接受数据 */
$input['name'] = $category['name'];
$input['slug'] = Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
Expand All @@ -474,6 +473,11 @@ public function wpNewCategory(int $blogId, string $userName, string $password, a
$categoryWidget = CategoryEdit::alloc(null, $input, function (CategoryEdit $category) {
$category->insertCategory();
});

if (!$categoryWidget->have()) {
throw new Exception(_t('分类不存在'), 404);
}

return $categoryWidget->mid;
}

Expand Down Expand Up @@ -1833,7 +1837,7 @@ public function action()
'wp.suggestCategories' => [$this, 'wpSuggestCategories'],
'wp.uploadFile' => [$this, 'mwNewMediaObject'],

/** New Wordpress API since 2.9.2 */
/** New WordPress API since 2.9.2 */
'wp.getUsersBlogs' => [$this, 'wpGetUsersBlogs'],
'wp.getTags' => [$this, 'wpGetTags'],
'wp.deleteCategory' => [$this, 'wpDeleteCategory'],
Expand Down