wordpress插件开发_WordPress插件开发简介

wordpress插件开发

Are you looking for an introduction to WordPress plugin development that will discuss all of the important steps and hold your hand along the way? If so, you’re in luck. This tutorial will outline the basics of what you need to know about designing your own plugins and some pointers on best practices.

您是否正在寻找WordPress插件开发的介绍,该讨论将讨论所有重要步骤并一路过关斩将? 如果是这样,那么您很幸运。 本教程将概述您在设计自己的插件时需要了解的基础知识,以及一些有关最佳做法的指针。

WordPress Plugin Development

什么是WordPress插件? (What Are WordPress Plugins?)

Plugins are one of WordPress’ most powerful assets. In essence, plugins are modules you activate on your website to provide a series of features or elements.

插件是WordPress最强大的资产之一。 本质上,插件是您在网站上激活以提供一系列功能或元素的模块。

The functionality you can add to your website depends on what each specific plugin has been created to do. There are a wide selection of plugins, ranging from simple plugins (such as ones that add styling or small theme changes) all the way to extensive plugins (that provide significant changes such as eCommerce integrations or third party connections).

您可以添加到网站的功能取决于每个特定插件的创建方式。 插件的选择范围很广,从简单的插件(例如添加样式或小的主题更改的插件)一直到扩展的插件(提供重大更改,例如电子商务集成或第三方连接)。

Plugins are different from your theme and work independently, using hooks, filters, shortcode, widgets and custom code to perform their functionality.

插件与您的主题不同,并且可以独立使用钩子,过滤器,短代码,小部件和自定义代码来执行其功能。

优点,缺点和注意事项 (Strengths, Weaknesses & Considerations)

Plugins are great, they provide both developers and admins with a way to extend and re-use functionality. While they are a great tool they do still have both their strengths and weaknesses.

插件很棒,它们为开发人员和管理员提供了一种扩展和重用功能的方法。 尽管它们是一个很好的工具,但是它们仍然具有优点和缺点。

长处 (Strengths)

  • You can add plugins with almost any theme and expect it to work correctly. Plugins were created to be modular so that you can copy into a new project (or distribute) which is great.

    您可以添加几乎任何主题的插件,并期望它能正常工作。 插件的创建是模块化的,因此您可以将其复制到新项目(或分发)中,这很棒。
  • A plugin acts as a container for all of your code and elements. If you were to build similar functionality in the theme you might get the elements mixed up. With a plugin, everything that needs to function exists within a single package.

    插件充当所有代码和元素的容器。 如果要在主题中构建类似的功能,则可能会混淆元素。 使用插件,所有需要运行的功能都存在于单个程序包中。
  • They are easy to make and can take advantage of WordPress’s action and filter hooks.

    它们易于制作,可以利用WordPress的操作和过滤器挂钩。
  • Can be created easily in an Object Orientated fashion, creating more robust and manageable code.

    可以以面向对象的方式轻松创建,从而创建更健壮和可管理的代码。

弱点 (Weaknesses)

  • Limited access to the website’s theme. Plugins can’t output code directly into a location on a theme. A theme has to provide an area for your plugin to output such as the content area or via a widget area.

    对网站主题的访问受限。 插件无法将代码直接输出到主题的某个位置。 主题必须提供一个供插件输出的区域,例如内容区域或通过小部件区域。
  • Plugin conflicts do occur. Sometimes another plugin (or even the theme) will negatively affect your plugin and it can ruin the experience (for example, you could be using the WordPress media uploader and it has been altered and not longer functions as expected, ruining your plugin).

    确实发生插件冲突。 有时,另一个插件(甚至主题)会对您的插件产生负面影响,并且可能破坏体验(例如,您可能正在使用WordPress媒体上传器,并且该插件已被更改且不再能按预期运行,从而破坏了您的插件)。
  • Limited access to templates and design. Plugins are supposed to provide the functionality and the theme provides the styling.

    对模板和设计的访问受限。 插件应提供功能,而主题应提供样式。

核心概念–操作,过滤器,简码,小部件等 (Core Concepts – Actions, Filters, Shortcodes, Widgets and More)

Let’s take a moment to talk about some key aspects of plugin development.

让我们花一点时间讨论插件开发的一些关键方面。

You might be familiar with these areas if you have worked on WordPress themes, however, a solid understanding of how these concepts work will help you build easy to use and maintainable functionality.

如果您曾经处理过WordPress主题,那么您可能熟悉这些领域,但是,对这些概念的工作原理有深入的了解将有助于您构建易于使用和可维护的功能。

动作(挂钩) (Actions (Hooks))

An action hook is an activity that is performed by WordPress at a specific time. When this action is triggered it will find all functions that have been attached to this action and execute them in the correct order.

action挂钩是WordPress在特定时间执行的活动。 触发此操作后,它将找到该操作已附加的所有功能,并以正确的顺序执行它们。

WordPress has dozens of actions defined throughout its core functionality, each action consisting of a unique name. For example, when WordPress is saving a post (such as a post, page or other content type) it will call the action save_postwhich will look for any functions attached to this action.

WordPress在其整个核心功能中定义了许多动作,每个动作都由一个唯一的名称组成。 例如,当WordPress保存帖子(例如帖子,页面或其他内容类型)时,它将调用操作save_post ,该操作将查找与此操作相关的所有功能。

All actions are defined using the do_action() function. This function takes in the following parameters

所有动作均使用do_action()函数定义。 该函数采用以下参数

  • $tag (required)

    $tag (必填)

  • $args (optional one or more variables)

    $args (可选的一个或多个变量)

Overall, each action will have its name (its tag) and also an optional number of additional useful variables (there could be multiple or zero additional variables

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WordPress 开发是为了扩展和定制WordPress功能的过程。在进行开发时,可以使用WordPress提供的两个件目录。主件目录位于wp-content/plugins/下面,是在安装WordPress时自动创建的。另一个件目录位于wp-content/mu-plugins下面,需手动创建。这个目录代表了“必须使用”(Must-Use)的件,不由WordPress自动创建。 为了建立一个合适的件基础,可以遵循一些步骤。首先,要保持合适的代码文档,这对于描述件的功能非常重要。合适的文档将帮助你在将来升级代码时节省时间,也有助于其他开发者理解你的代码逻辑。 在WordPress开发中,可以使用plugins_url()函数来获取在件目录下的任何文件的完整URL。这个函数可以非常有用。 总的来说,WordPress开发需要创建合适的件基础,并根据需要使用WordPress提供的件目录。同时,合理文档化代码和使用相关函数可以提高件的可维护性和可扩展性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [WordPress 开发教程 – Part-1 – WordPress 简介](https://blog.csdn.net/ljguo212/article/details/7620075)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [WordPress 开发教程 – Part-2 – WordPress 件基础](https://blog.csdn.net/ljguo212/article/details/7620071)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值