什么是add_action('init [英] What is add_action( 'init

查看:241
本文介绍了什么是add_action('init的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们在wordpress中使用这种类型的东西?有人可以向我解释吗?为什么我们在wordpress函数中使用init?或者,什么是init?

Why do we use this type of thing in wordpress? Can anyone explain it to me please? Why do we use init in wordpress functions? Or, what is init?

推荐答案

使用添加操作,而不是将函数硬编码到WordPress中.使用add_action的好处是,您可以让核心的wordpress函数跟踪已添加的内容,并且这样做可以通过稍后取消注册来覆盖先前添加的功能.

Add action is used instead of hard-coding a function into WordPress. The benefit to using add_action is that you allow core wordpress functions to keep track of what has been added, and by doing so, can override previously added functions by de-registering them later on.

例如:

您下载的插件的定义的操作/方法名为

You download a plugin with a defined action/method named

add_action( 'init', 'crappy_method' );

您需要使用自己的函数覆盖crappy函数:

You need to override the crappy function with your own:

remove_action('init', 'crappy_method' );
add_action( 'init', 'my_even_crappier_method' );

通过执行此操作,您可以复制原始方法并对其进行自定义,而无需更改原始文件.这对于插件非常有用,因此您以后可以更新它们而不会丢失所做的更改.

By doing this you can copy the original method and customize it without changing the original files. This is very useful with plugins so that you can update them later on without losing your changes.

这篇关于什么是add_action('init的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆