php – WordPress – 编辑插件的过滤功能

我想知道是否有人可以帮助我.

我有一个名为Paid Memberships Pro的插件.

在注册表单上有一些我想要的字段.

我已经完成了代码并找到了设置哪些字段是必需的而不是必需的地方,如下所示:

//require fields
$pmpro_required_billing_fields = array(
    "bfirstname" => $bfirstname,
    "blastname" => $blastname,
    "baddress1" => $baddress1,
    "bcity" => $bcity,
    "bstate" => $bstate,
    "bzipcode" => $bzipcode,
    "bphone" => $bphone,
    "bcountry" => $bcountry,
    "bemail" => $bemail,
    "CardType" => $CardType,
    "AccountNumber" => $AccountNumber,
    "ExpirationMonth" => $ExpirationMonth,
    "ExpirationYear" => $ExpirationYear,
    "CVV" => $CVV
);
$pmpro_required_billing_fields = apply_filters("pmpro_required_billing_fields", $pmpro_required_billing_fields);
$pmpro_required_user_fields = array(
    "username" => $username,
    "password" => $password,
    "password2" => $password2,
    "bemail" => $bemail,
    "bconfirmemail" => $bconfirmemail
);
$pmpro_required_user_fields = apply_filters("pmpro_required_user_fields", $pmpro_required_user_fields);

这是在其中一个插件核心文件插件/ paid-membership -pro / preheaders / checkout.php中找到的

我想能够覆盖这个,但我不想编辑核心文件,有没有办法可以通过我的主题functions.php文件编辑这个?

例如,将bfirstname和blastname添加到$pmpro_required_user_fields?

任何帮助将不胜感激,我一直在寻找如何做到这一点但我真的不明白它是否可能.

谢谢大家:)

最佳答案 (将此代码放入chid主题function.php文件中)

不是shure,但你可以先尝试使用remove_filters:

remove_filters("pmpro_required_billing_fields", $pmpro_required_billing_fields);
remove_filters("pmpro_required_billing_fields", $pmpro_required_user_fields);

然后,您可以克隆这些数组,自定义它们(并稍微更改它们的名称),然后为该自定义数组重新应用过滤器:

$pmpro_required_billing_fields2 = array(
    /* your custom code goes here */
);
$pmpro_required_billing_fields2 = apply_filters("pmpro_required_billing_fields", $pmpro_required_billing_fields2);

$pmpro_required_user_fields2 = array(
    /* your custom code goes here */
);
$pmpro_required_user_fields2 = apply_filters("pmpro_required_user_fields", $pmpro_required_user_fields2);

这只是一个未经考验的想法,希望它能奏效.

点赞