php - 重力表单/WordPress 填充来自 ACF 字段的单选按钮选项
问题描述
我正在尝试从 ACF 字段中填充单选按钮中的选项。我想出了下面的解决方案,基本上只是字符串替换。但是,此解决方案仅在视觉前端有效。例如,当收到管理员通知时,它仍然返回原始文本“Valg 1:, Valg 2: or valg3”。
我怎样才能使代码在管理员通知等中工作?
我一直在寻找各种重力形式过滤器,但由于某种原因无法使其工作:
gform_pre_render
gform_pre_validation
gform_pre_submission_filter
gform_admin_pre_render
我的代码:
add_filter( 'gform_field_choice_markup_pre_render_16_11', function ( $choice_markup, $choice, $field, $value ) {
if ( $field->get_input_type() == 'radio' ) :
if( get_field('valg_checkbox') == 'Valg1' ) {
switch ( rgar( $choice, 'text' ) ) {
case "Valg 1:":
$description = get_field('valg_1');
$current = "Valg 1";
break;
}
} elseif ( get_field('valg_checkbox') == 'Valg2' ) {
switch ( rgar( $choice, 'text' ) ) {
case "Valg 1:":
$description = get_field('valg_1');
$current = "Valg 1";
break;
case "Valg 2:":
$description = get_field('valg_2');
$current = "Valg 2";
break;
} } else {
switch ( rgar( $choice, 'text' ) ) {
case "Valg 1:":
$description = get_field('valg_1');
$current = "Valg 1";
break;
case "Valg 2:":
$description = get_field('valg_2');
$current = "Valg 2";
break;
case "Valg 3:":
$description = get_field('valg_3');
$current = "Valg 3";
break;
}
}
endif;
return str_replace( ">".$current, ">".$description, $choice_markup);
}, 10, 4 );
解决方案
推荐阅读
- c# - UWP C# Windows IoT Core UART RS485 多次传输后出错
- azure - 有人可以解释一下 Azure AD 应用程序访问和 refresh_token 的超时和验证吗?
- if-statement - 使用 if 语句根据全局变量值执行不同的命令
- html - 获取特定的字符串使用 xpath
- python - python - 如何在python上使用numpy将许多具有不同名称的txt文件连接到一个数组中?
- php - Wordpress cron wp_schedule_single_event – 操作并不总是有效
- postgresql - 从数字 ID 迁移到 UUID
- c# - 使用 XDocument.Descendants 获取所有“信号”,但只需要某些“信号”
- c# - 如何在一种方法中转换两种几乎相同的方法?
- javascript - 根据请求动态注入 HTML 和 CSS