我是新来的,如果你能帮我的话,我需要把从函数中获得的值放到我的shortocode函数中,谢谢
$a=4; // value obtained from another function my_function($a); function my_function($i){ $a=$i+1; return $a; } add_shortcode( \'operation\', \'my_function\' );
我是新来的,如果你能帮我的话,我需要把从函数中获得的值放到我的shortocode函数中,谢谢
$a=4; // value obtained from another function my_function($a); function my_function($i){ $a=$i+1; return $a; } add_shortcode( \'operation\', \'my_function\' );
我真的不明白你想做什么。为什么不直接调用shortcode处理程序中的函数呢?这看起来更像一般的PHP问题。
假设我们的functions.php
或者无论您在哪里定义短代码:
$another_var = doSomeFunctionThatReturnsData();
使用现代匿名函数,可以使用use
关键字。add_shortcode(\'operation\', function (array $atts, ?string $content, string $shortcode_tag) use ($another_var): string {
$out = \'The value of my variable is: \' . $another_var;
return $out;
});
使用古老的命名函数作为回调,您可以通过使用global
关键词:function shortcode_operation_handler(array $atts, ?string $content, string $shortcode_tag): string {
global $another_var;
$out = \'The value of my variable is: \' . $another_var;
return $out;
}
add_shortcode(\'operation\', \'shortcode_operation_handler\');
变量名称前的这些单词是参数的类型(更多关于in the PHP documentation). 分号后的类型(:
) 在函数定义中表示its return type.... or you can simply call the function inside your shortcode handler.
将PHP升级到7.4 FastCGI后,我发现以下错误::fread():读取8192字节失败,错误号=21是目录不示例。com/wp/wp包括/功能。php在线5977以及:警告:无法修改标题信息-标题已发送(输出开始于example.com/wp/wp-includes/functions.php:5977)不示例。com/wp/wp admin/admin标题。php第9行我有3个插件都被禁用了。