【发布时间】:2016-08-26 06:46:13
【问题描述】:
我正在使用一个自定义简码,它生成一个自定义贝宝按钮并将特定参数传递给贝宝结帐表单。
我正在使用 str_replace 函数将短代码中定义的属性传递给 html 表单。
如果未在短代码中定义为属性,我想设置默认样式类和默认标题。
我的 php:
function paypal_button_func($attrs){
$class=$attrs['class']; //Added button style class variable
$title=$attrs['title']; //Added button title variable
if( isset( $atts['title'])) //add button title to the form html
{
return $html=str_replace('[title]',$title,$html);
}
//This sets the default title if not defined
else {
return $html=str_replace ('[title]','SIGN UP NOW',$html);
}
这是我的html
<input type="submit" class="[class]" value="[title]" /> <!-- updated class and value for addtl shortcode parameters -->
我成功地使用以下代码将短代码属性传递给 html,但问题是如果属性未在短代码中定义,它会将 [class] 和 [title] 输出为值,即不是我想要发生的。
$html=str_replace('[title]',$title,$html); //add button title assigned to the form
$html=str_replace('[class]',$class,$html); //replaces class assigned to the form
【问题讨论】: