我按照的建议创建了一些自定义概要文件字段Thomas Griffin 和Stephanie Leary. 像这样:
function change_contactmethod( $contactmethods ) {
// Add some fields
$contactmethods[\'twitter\'] = \'Twitter Name (no @)\';
$contactmethods[\'phone\'] = \'Phone Number\';
$contactmethods[\'title\'] = \'Title\';
// Remove AIM, Yahoo IM, Google Talk/Jabber
unset($contactmethods[\'aim\']);
unset($contactmethods[\'yim\']);
unset($contactmethods[\'jabber\']);
// make it go!
return $contactmethods;
}
add_filter(\'user_contactmethods\',\'change_contactmethod\',10,1);
我想为重力表单创建一个自定义合并标记,以通过用户的电话号码输出($contactmethods[\'phone\']
).我可以通过两种不同的方式检索此信息:
方式1:
function phone() {
$userid = get_current_user_id();
$user_info = get_userdata($userid);
return get_user_meta($userid, \'phone\', true);
}
或方式2:function phone() {
echo the_author_meta(\'phone\', $current_author->ID);
}
我甚至可以创建[phone]
通过添加短代码:add_shortcode(\'phone\', \'phone\');
当我尝试添加[phone]
短代码作为重力表单中的默认输入值,它不处理短代码。重力有一种叫做短标签的东西,我从documentation on Gravity 那个{user:[meta_key]}
可以作为{user:phone}
, 但我还没有将其设置为合并标记。我对JavaScript不太熟悉,我所做的设置此合并标记的工作不起作用:add_action("gform_admin_pre_render", "add_merge_tags");
function add_merge_tags($form){
$mergeTags["phone"] = the_author_meta(\'phone\', $current_author->ID);
?>
<script type="text/javascript">
gform.addFilter("gform_merge_tags", "add_merge_tags");
function add_merge_tags(mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option){
mergeTags["phone"].tags.push({ tag: \'{phone}\', label: \'Phone\' });
return mergeTags;
}
</script>
<?php
//return the form object from the php hook
return $form;
}
如何为添加的自定义元字段创建自定义合并标记?或者如何允许我的字段输入读取[phone]
短代码?