扩展 Wordpress XML-RPC 以包含自定义帖子类型和分类法

发布于 2024-12-09 05:41:50 字数 177 浏览 0 评论 0原文

我正在尝试插入具有自定义帖子类型的帖子,我还想附加自定义分类法。大多数可用的补丁都已过时,仅适用于“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2024-12-16 05:41:50

我意识到这是一个老话题,但在过去的几周里我一直在想同样的事情,并完全重写了该文件的一些内容以适应我需要它做的事情。对于我的实现,我有一个名为“博客”的自定义帖子类型,以及名为“blog_categories”和“blog_tags”的自定义分类法。是的,有点多余,但这是一种实验。

如果您看一下 class-wp-xmlrpc-server.php,您会发现它有点混乱(根据您使用的 WP 版本,它可能更好或更差)。我发现在不破坏任何内容的情况下进行此操作的最简单方法是继续将分类功能更改为通用功能而不是类别并发布特定功能。这涉及查找 wp_get_post_categorieswp_get_post_tags 的所有实例,并将它们替换为更通用的 wp_get_object_terms,然后替换 get_categories > 与get_terms。一旦使用 categoriestags 作为分类法,您可以执行以下两件事之一:

  1. 在我的情况下,XML-RPC 只需要像默认那样工作,除了更改 < code>post 到 blogcategoriesblog_categories 等。我刚刚替换了文字,我的新 XML-RPC 允许我像平常一样使用 Live Writer,但它会使用我的自定义帖子类型和分类法。
  2. 如果您需要可用于处理多种帖子类型和分类法的函数,则需要更深入地挖掘并重写这些函数(理想情况下,重写它们以处理 0-n 分类法和任何帖子类型)。如果您想使用 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 of wp_get_post_categories and wp_get_post_tags and replacing them with the more generic wp_get_object_terms, and replacing get_categories with get_terms. Once this works using categories and tags as the taxonomy, you can do one of two things:

  1. In my situation, XML-RPC just needed to work like default, except change post to blog, categories to blog_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.
  2. If you need functions available to work with multiple post types and taxonomies, you'll need to dig a little deeper and rewrite the functions (ideally, rewrite them to work with 0-n taxonomies and any post type). Consider backwards compatibility if you want to use existing software like Live Writer. Also consider capabilities - if you have custom roles for your custom post types, then you should consider replacing the capability checks with something like: 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文