私はカスタムペイパルボタンを生成するカスタムショートコードを使用しています&は、特定のパラメータをpaypalチェックアウトフォームに渡します。str_replaceでif/else文を使用してショートコードで変数を追加する
私は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に属性を渡すために、次のコードを使用してして成功したが、問題は、もしあります属性は短コードで定義されていないので、[クラス]と[タイトル]を値として出力しますが、これは起こりたいものではありません。
$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
その短い手は完全に働いた。最後の何時間も私の画面を見ていて、それは私が過ぎて間違っていた。助けてくれてありがとう!!! –