douyuefu1372 2017-01-13 16:41
浏览 82
已采纳

WordPress - add_filter函数和字符串参数?

I found this filter in a piece of code:

$output  = apply_filters( 'envira_gallery_output_dynamic_position', $output, $id, $item, $data, $i, 'bottom-right' );

My assumption was, that I can make use of it like this:

add_filter( 'envira_gallery_output_dynamic_position', 'custom_gallery_output_dynamic_position', 10, 6);

function custom_gallery_output_dynamic_position($output, $id, $item, $data, $i, 'bottom-right' ) {

But because of the 'bottom-right' I get a 500 server error:

PHP Parse error:  syntax error, unexpected ''bottom-right'' (T_CONSTANT_ENCAPSED_STRING), expecting variable (T_VARIABLE)

Does anybody know how I can use this filter correctly?

Thanks!

  • 写回答

1条回答 默认 最新

  • duanbiaojin8860 2017-01-13 17:02
    关注

    There must be variable name:

    function custom_gallery_output_dynamic_position($output, $id, $item, $data, $i, $position) {
    

    You can define it with default value:

    function custom_gallery_output_dynamic_position($output, $id, $item, $data, $i, $position='bottom-right') {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 代写个MATLAB代码,有偿
  • ¥15 ansys electronics 2021 R1安装报错,错误代码2,如图
  • ¥15 Dev-c++打字不出现中文,但出现日文
  • ¥30 搭建面包板由NE555N和SN74LS90N组成的计时电路时出了问题
  • ¥15 无源定位系统的时差估计误差标准差
  • ¥15 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?