那么您只是在寻找一个调用现有函数的简单快捷码?
下面将创建您正在寻找的短代码,但无可否认,我还没有使用Cimy User Extra Fields插件对其进行测试。将此添加到functions.php
并尝试一下:
function shortcode_cimyFieldValue( $atts ) {
global $current_user;
$user_id = ( is_user_logged_in() ? $current_user->ID : NULL );
/*
* First, check to make sure the get_cimyFieldValue() function
* exists. This way, if the plugin is not installed the site
* doesn\'t blow up...
*/
if( function_exists( \'get_cimyFieldValue\' ) ) {
// Grab the shortcode parameters
extract( shortcode_atts( array(
\'user\' => $user_id,
\'field\' => \'\',
\'value\' => \'\'
), $atts ));
/*
* Call the get_cimyFieldValue() function using any of the
* user-entered parameters
*/
if( $user_id != NULL ) {
return get_cimyFieldValue( $user, $field, $value );
}
}
}
// Adds the above function as as shortcode
add_shortcode( \'my_cimy_field\', \'shortcode_cimyFieldValue\' );
这应该允许您调用短代码
[my_cimy_field]
通过以下任一方式:
[my_cimy_field field="my_field_name"]
或
[my_cimy_field field="my_field_name" value="Sample Field Value"]