将匿名函数转换为普通函数

时间:2013-11-18 16:03:06

标签: anonymous-function

    add_action( 'wp_footer', function () use($uniqueid, $height, $tileheight, $margin) {
    echo "<script type='text/javascript'>
            jQuery(function () {
                jQuery('." . $uniqueid . "').tilesGallery({
                    responsive: true,
                    anchorVertical: 'middle',
                    anchorHorizontal: 'center',
                    reloadOnResize: true,
                    captionHeight: '100%',
                    height: ".$height.",
                    tileMinHeight: ".$tileheight.",                     
                    margin: ".$margin.",
                });
            });
        </script>";
});

嘿那里,

问题是我不能将此功能用于低于5.3的php版本。如何将其转换为适用于低于5.3的php版本的东西?

提前谢谢!

1 个答案:

答案 0 :(得分:0)

  

只需使用create_function($ args,$ code);
   这里有如何使用create_function()

$function = create_function('', 
'
global $uniqueid, $height, $tileheight, $margin;
    echo "<script type=\"text/javascript\">
            jQuery(function () {
                jQuery(\'.$uniqueid\').tilesGallery({
                    responsive: true,
                    anchorVertical: \'middle\',
                    anchorHorizontal: \'center\',
                    reloadOnResize: true,
                    captionHeight: \'100%\',
                    height: $height,
                    tileMinHeight: $tileheight,                     
                    margin: $margin,
                });
            });
        </script>";
'
);
相关问题