扩展 Wordpress XML-RPC 以包含自定义帖子类型和分类法
我正在尝试插入具有自定义帖子类型的帖子,我还想附加自定义分类法。大多数可用的补丁都已过时,仅适用于“xmlrpc.php”。现在wordpress中控制该功能的文件是“class-wp-xmlrpc-server.php”。有人可以给我关于如何剖析该文件的建议吗?我更愿意向我的主题文件添加过滤器,而不是覆盖 Wordpress 核心文件。
I am trying to insert a post with a custom post type, which I also want to attach custom taxonomies. Most of the patches available are outdated any only apply to "xmlrpc.php". Now the file in wordpress that controls the function is "class-wp-xmlrpc-server.php". Could someone give me advice on how to dissect the file? I would prefer to add a filter to my theme file rather than overwriting Wordpress core files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到这是一个老话题,但在过去的几周里我一直在想同样的事情,并完全重写了该文件的一些内容以适应我需要它做的事情。对于我的实现,我有一个名为“博客”的自定义帖子类型,以及名为“blog_categories”和“blog_tags”的自定义分类法。是的,有点多余,但这是一种实验。
如果您看一下
class-wp-xmlrpc-server.php
,您会发现它有点混乱(根据您使用的 WP 版本,它可能更好或更差)。我发现在不破坏任何内容的情况下进行此操作的最简单方法是继续将分类功能更改为通用功能而不是类别并发布特定功能。这涉及查找wp_get_post_categories
和wp_get_post_tags
的所有实例,并将它们替换为更通用的wp_get_object_terms
,然后替换get_categories
> 与get_terms
。一旦使用categories
和tags
作为分类法,您可以执行以下两件事之一:blog
,categories
到blog_categories
等。我刚刚替换了文字,我的新 XML-RPC 允许我像平常一样使用 Live Writer,但它会使用我的自定义帖子类型和分类法。user_can('edit'_.$post_type, $postid)
。遗憾的是,Wordpress 是 1 个帖子类型、2 个帖子类型(页面)、n 个帖子类型(自定义)演化模型的牺牲品,而 XML-RPC 并没有像系统的其他部分那样受到人们的喜爱。您可以研究一些过滤器/操作挂钩,但我认为您只需修改核心文件就会更容易。 这意味着您的修改将在核心更新时被覆盖!
希望这对您和其他想要做同样事情的人有一点帮助!
I realize that this is an old topic, but I've been wondering the same thing in the last couple of weeks and totally rewrote some of that file to work with what I needed it to do. For my implementation, I have a custom post type called 'blog', with custom taxonomies called 'blog_categories' and 'blog_tags'. A little redundant, yes, but it was an experiment sort of.
If you take a look at
class-wp-xmlrpc-server.php
, you'll notice that it's a bit messy (depending on the version of WP you are using it may be better or worse). The easiest way I found to go about it without breaking anything was to go ahead and change the taxonomy functions to the generic ones rather than the category and post specific ones. That involves finding all of the instances ofwp_get_post_categories
andwp_get_post_tags
and replacing them with the more genericwp_get_object_terms
, and replacingget_categories
withget_terms
. Once this works usingcategories
andtags
as the taxonomy, you can do one of two things:post
toblog
,categories
toblog_categories
, etc. I just replaced the literals and my new XML-RPC allowed me to use Live Writer like normal, but it would use my custom post type and taxonomies.user_can('edit'_.$post_type, $postid)
.Sadly, Wordpress is victim to the 1 post type, 2 post types (pages), n post types (custom) evolutionary model, and XML-RPC hasn't gotten as much love as the rest of the system. There are some filter/action hooks in there you could investigate, but I think you'll have an easier time just modifying the core file. This means your modifications will be overwritten on core updates though!
Hope this helps a little for you and anyone else looking to do the same thing!