I'm using Cimy User Extra Fields to add more registration fields. I'm also using Contact Form 7 Dynamic Text Extension to pre-populate contact form fields.

I've read, in order to be able to use Cimy fields to pre-populate the contact form i need to add a shortcode. I've read this here.

He say's that you have to add a shortcode which calls a function that is in Cimy User Extra Fields.

The function in Cimy is called get_cimyFieldValue().

Here is the code he is referring to from Dynamic Text Extension.

function cf7_get_current_user($atts){
        'key' => 'user_login',
    ), $atts));

    global $current_user;

    $val = $current_user->$key;
    return $val;
add_shortcode('CF7_get_current_user', 'cf7_get_current_user');

How can i add a shortcode in my functions.php to call get_cimyFieldValue() so i can populate the contact form with fields from Cimy?



From the answer below i've managed to get this to work however it only seems to work if i use a user id. I need it to work with the current user not a predefined user.

1 Answer 1


So you're just looking for a simple shortcode that will call an existing function?

The following will create the shortcode you're looking for, but admittedly I haven't tested it with the Cimy User Extra Fields plugin. Add this to functions.php and try it out:

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' );

This should allow you to call the shortcode [my_cimy_field] in either of the following ways:

[my_cimy_field field="my_field_name"]


[my_cimy_field field="my_field_name" value="Sample Field Value"]

  • I've added this into the functions.php file and haven't made any changes, which is right isn't it? I then put the following shortcode in to my contact form 7 form. [dynamictext* ContactTelNo "my_cimy_field user='1' field='TELEPHONE_NUMBER'"]. I put 1 for the user for admin and TELEPHONE_NUMBER is the name i gave the field in Cimy. However it's not doing anything. Can you think why?
    – Corbula
    Commented Dec 7, 2011 at 16:13
  • Also it needs to work for the current logged in user and not by entering a user ID.
    – Corbula
    Commented Dec 7, 2011 at 17:10
  • ok, it does work it was just me being stupid. However it needs to work for the current user. So instead of user='12' it needs to be the current user and not a pre defined user.
    – Corbula
    Commented Dec 8, 2011 at 16:03
  • I updated the code to grab the current logged in user's ID by default. Setting the user="" option will overwrite this though, so make sure you omit it when using the shortcode. Hope this helps!
    – jhdenham
    Commented Dec 9, 2011 at 20:48
  • Thanks this works, however there is one more minor thing. If the user isn't logged in, instead of displaying an empty field it displays the word Array. Any ideas why?
    – Corbula
    Commented Dec 12, 2011 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.