- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我尝试使用hook调用静态方法,但是失败了。
我像这样在 test.php 中添加 Action
require_once('class.test.php');
add_action('register_new_user', array('Test','auto_signin'),20);
我的 auto_signin 函数放在 class.test.php 文件中:
namespace MyTest;
echo(12);
class Test {
function __construct()
{
}
public static function auto_signin()
{
echo('hello');
die();
}
}
当我调试它时, Hook register_new_user 确实执行了,并且从全局变量 wp_filters 中,auto_signin 函数已添加到 register_new_user,但该函数从未执行。
最佳答案
您的类 Test
已命名空间,但您在调用 add_action
时未使用任何命名空间。
更新:
add_action('register_new_user', array('Test','auto_signin'),20);
对此:
add_action( 'register_new_user', array( 'MyTest\Test', 'auto_signin' ), 20 );
关于php - 如何使用 add_action Hook 其他类的静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41949961/
Fatal error: Call to undefined function add_action() in D:\xampp\htdocs\excel\wp-content\plugins\Dat
我想根据短代码参数向 head 部分添加样式标签。我编写了一个样式函数,并希望在短代码函数中调用其 add_action。 但是,样式并没有添加到头部。如果我在函数外部调用 add_action ,它
我希望当用户添加评论时,它会同时添加到另一个页面中。为此,我使用这段代码: $the_post_id, 'comment_author' => $comment->c
我可以这样做吗?将参数传递给我的函数?我已经研究过add_action doc但不知道该怎么做。传递两个参数的确切语法是什么样的。特别是如何传递文本和整数参数。 function recent_pos
我在实际教程中问过这个问题,但不确定我是否会在将近 2 个月大的时候得到答案......所以我会在这里看一看...... 教程在这里:Build a WordPress Plugin to Add A
我正在查看我的 functions.php 并想知道为什么代码 A 使用 add_action 而代码 B 使用 add_filter ? CODE A 的主要目标是包括和排除特定类别。 CODE B
我尝试使用hook调用静态方法,但是失败了。 我像这样在 test.php 中添加 Action require_once('class.test.php'); add_action('regis
我正在学习创建一个 wordpress 插件我下载了一个并阅读了代码,我看到了这个我假设“foo”是它将添加操作的标签.. 但是 array() 究竟做了什么? add_action('foo', a
我刚刚接触 Wordpress,我正在尝试使用 OOP 技术编写一个非常简单的插件。我一直在关注本教程:http://www.yaconiello.com/blog/how-to-write-word
我正在尝试找出 do_action 和 add_action 的确切作用。我已经用 add_action 检查了,但是对于 do_action 我现在正在尝试新的。这是我尝试过的。 function
我正在使用钩子(Hook)user_register来写入变量$user_id。我想在函数内调用此 Hook ,并将变量 $pass 从父函数传递到函数 register_pass。一旦到达,$pas
我正在使用写入变量 $user_id 的钩子(Hook) user_register。我想在函数内部调用此 Hook ,并将变量 $pass 从父函数传递给函数 register_pass。一旦到达那
我正在使用命令行实用程序来满足我的项目的一项要求:optparse。 假设我使用如下所示的 add_option 实用程序: parser.add_option('-c','--categories'
我正在尝试从我们的 Contact7 表单之一发布数据,然后将该数据保存在 mysql 表中。我对 WordPress 很陌生。我遵循了其他人的代码。但我没有运气收到表中的数据。我觉得 add_act
我正在尝试编写一个包含多个文件的插件。我确信我之前做的没有问题,但现在我在主题上遇到了问题。 在主插件文件中,我包含了一个文件名 - ydp-includes.php。在 ydp-includes.p
我有一些推特更新的代码- function twitit() { global $wp_query; $thePostName = $wp_query->post->post_name; echo '
我正在尝试在我使用插件 woocomerce 的 Wordpress 中完成付款后添加一个函数( Hook )。 documentation因为 woocommere 表示有一个名为“woocomme
我正在尝试添加自定义端点(自定义端点”是指 WP 无法识别为标准 URL 的任意 URL,例如永久链接等。)我使用 WordPress 插件样板“https://github.com/DevinVin
由于某种原因,以下内容没有将我的 JS 和 CSS 加载到 WordPress 中。该代码位于激活的插件中,否则该插件正在执行。另外,我检查了主题中确实存在 wp_head 。 add_action
我需要在 foreach 循环中动态构建多个 add_action() 函数,循环遍历用户可能创建的各种自定义分类法。 操作 Hook 的名称是“category_add_form_fields”,但
我是一名优秀的程序员,十分优秀!