3
如何将外部变量传递给过滤器/操作
我发现自己需要将自定义数据传递给第三方插件提供的过滤器。我见过的所有方法都非常复杂,很难缠住我的头。 举个例子: $score = 42; //Some crazy calculation I don't want to repeat. function add_score_to_title($title) { return 'Quiz Results (' . $score . '/') - ' . $title; } add_filter( 'aioseop_title_single', 'add_score_to_title'); 如何将$score变量传递给add_score_to_title()? 我最终要做的是将变量添加到全局$wp对象中。因此,您最终得到以下结果: global $wp; $score = 42; //Some crazy calculation I don't want to repeat. $wp->some_random_name_for_score = $score; …