2013-10-23 36 views
0

我正在使用Wordpress並修改某個函數以在有人填寫重力表格時更新用戶元數據。我想要更新的元數據是自定義配置文件信息。我從後端更新數據,但無法通過表單完成。使用自定義配置文件信息更新用戶元數據

我不能真正看到我出錯的地方。

function GF_setup_actions_filters() { 
     $_gf_edit_profile_id = RGFormsModel::get_form_id('25'); 
     add_action('gform_after_submission_25' . $_gf_edit_profile_id, 'GF_update_profile', 100, 2); } 

function GF_get_profile_fields() { 
     $_fields['share_a_little'] = array ('gf_index' => '4', 'wp_meta' => 'share_a_little'); 
     return $_fields; } 

function GF_update_profile($entry, $form) { 
    global $wpdb; 

    if (!is_user_logged_in()) { 
     wp_redirect(home_url()); 
     exit(); 
    } 


    $_user_id = get_current_user_id(); 
    $_user = new stdClass(); 
    $_user->ID = (int) $_user_id; 
    $_userdata = get_user_meta($_user_id); 
    $_user->user_login = $wpdb->escape($_userdata->user_login); 

    $gf_fields = GF_get_profile_fields(); 

    $share_a_little = $entry[$gf_fields['share_a_little']['4']]; 
    update_user_meta($_user->ID, 'share_a_little', $share_a_little); 
} 
+0

「GF_setup_actions_filters」觸發的鉤子在哪裏? – brasofilo

回答

0

這部分是錯誤的。

$_gf_edit_profile_id = RGFormsModel::get_form_id('25'); 
add_action('gform_after_submission_25' . $_gf_edit_profile_id, 'GF_update_profile', 100, 2); } 

如果你的表格ID是25,形式未命名25 該行應改爲:

add_action('gform_after_submission_25', 'GF_update_profile', 100, 2); } 

如果從被稱爲25,你不要;知道該ID的行應該是:

$_gf_edit_profile_id = RGFormsModel::get_form_id('25'); 
add_action('gform_after_submission_' . $_gf_edit_profile_id, 'GF_update_profile', 100, 2); } 

代碼看起來非常相似,我寫了一段時間後更新上利用重力形式的用戶配置文件的文章。你可以閱讀它here與代碼的解釋。

相關問題