脚本宝典收集整理的这篇文章主要介绍了php – 如何将变量传递给动作钩子函数?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
function slideshowSettings ($pause_time) { $code = "<script> jquery(function(){ jQuery('#camera_wrap_3').camera({ height: '40%',thumbnails: true,time: ".$pause_time.",fx: '".$transITion_effect."',transPEriod: ".$transition_speed.",autoAdvance: ".$auto_advance.",minHeight: '50px',mobileNavHover: false,imagePath: '".get_template_directory_uri()."/images/' }); }); </script>"; echo $code; } add_action('wp_head','slideshowSettings');
<script> jQuery(function(){ jQuery('#camera_wrap_3').camera({ height: '40%',time:,fx: '',transPeriod:,autoAdvance:,imagePath: 'http://www.brainbuzzmedia.COM/themes/simplybusiness/wp-content/themes/simplybusiness/images/' }); }); </script>
我怎样才能传递这些变量?
>挂钩的动作,在你的情况下“wp_head”
>您要执行的功能,在您的情况下“幻灯片设置”
>执行的优先级,默认值为10
>函数接受的参数数量(但必须通过do_action传递)
如果你需要能够将钩子函数外部的这些值传递给wp_head,我会使用apply_filters来修改一个值:
function slideshowSettings(){ // set up defaults $settings = array('pause_time'=>10,'other'=>999); $random_text = "foo"; // apply filters $settings = apply_filters('slideshow_settings',$settings,$random_text); // set array key/values to VARiables extract( $settings ); // will echo 1000 because value was updated by filter echo $pause_time; // will echo "foobar" because key was added/updated by filter echo $random_text; // ... more code } add_action( 'wp_head','slideshowSettings' ); function customSettings($settings,$random_text){ // get your custom settings and update array $settings['pause_time'] = 1000; $settings['random_text'] = $random_text . "bar"; return $settings; } // add function to filter,PRiority 10,2 arguments ($settings array,$random_text string) add_filter( 'slideshow_settings','customSettings',10,2 );
以上是脚本宝典为你收集整理的php – 如何将变量传递给动作钩子函数?全部内容,希望文章能够帮你解决php – 如何将变量传递给动作钩子函数?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。