Skip to content

Instantly share code, notes, and snippets.

@sjaved87
Last active February 9, 2016 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjaved87/e6c87e90f546b7cefdf4 to your computer and use it in GitHub Desktop.
Save sjaved87/e6c87e90f546b7cefdf4 to your computer and use it in GitHub Desktop.
This mu-plugin will add cimy user extra fields in Membership 2 edit profile form on frontend. Use it as mu-plugin or copy paste the code in fucntions.php file
<?php
function wpmu_add_cimy_extra_fileds_in_edit_form($feilds, $object){
$user_ID = get_current_user_id();
$user_meta_values = get_cimyFieldValue($user_ID, false);
if($user_meta_values){
//Unset now, we will add those later, at the end :)
unset($feilds['submit'], $feilds['_wpnonce'], $feilds['action']);
foreach ( $user_meta_values as $each ){
$feilds['cimy_uef'.$each['NAME']] = array(
'id' => 'cimy_uef_'.$each['NAME'],
'title' => $each['LABEL'],
'type' => $each['TYPE'],
'value' => $each['VALUE'],
);
}
$feilds['submit'] = array(
'id' => 'submit',
'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,
'value' => __( 'Save Changes', 'membership2' ),
);
$feilds['_wpnonce'] = array(
'id' => '_wpnonce',
'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,
'value' => wp_create_nonce( $object->data['action'] ),
);
$feilds['action'] = array(
'id' => 'action',
'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,
'value' => $object->data['action'],
);
}
//$feilds = array_merge($feilds, $my_array);
return $feilds;
}
add_action('ms_view_profile_fields', 'wpmu_add_cimy_extra_fileds_in_edit_form', 99, 2);
function wp_mu_does_it_really_triggers(){
$user_ID = get_current_user_id();
if(isset($_REQUEST['action']) and $_REQUEST['action'] == 'edit_profile'){
foreach ($_REQUEST as $key => $value){
if (preg_match('/cimy_uef_/i',$key)){
$feild_name = preg_replace('/cimy_uef_/i', '', $key);
$result = set_cimyFieldValue($user_ID, $feild_name, $value);
}
}
}
}
add_action('ms_model_member_save', 'wp_mu_does_it_really_triggers');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment