【发布时间】:2019-12-22 16:00:02
【问题描述】:
我已经编写代码来上传文件夹和 wordpress 媒体库中的文件。 文件将上传到 wordpress 文件夹,但问题是它没有在媒体库中移动。
函数 fb_save_custom_user_profile_fields( $user_id ) {
$uploadUrl= wp_get_upload_dir();
if ( !current_user_can( 'edit_user', $user_id ) )
return FALSE;
$rel = $_POST['relation'];
update_user_meta( $user_id, 'fname_'. $rel, $_POST['fname'] );
update_user_meta( $user_id, 'mname_'.$rel, $_POST['mname'] );
update_user_meta( $user_id, 'lname_'. $rel, $_POST['lname'] );
update_user_meta( $user_id, 'relation', $_POST['relation'] );
update_user_meta( $user_id, 'bod_'. $rel, $_POST['bod'] );
update_user_meta( $user_id, 'education_'.$rel ,$_POST['education'] );
update_user_meta( $user_id, 'occupation_'. $rel, $_POST['occupation'] );
// update_user_meta( $user_id, 'picture_'. $rel, $uploadUrl['url']."/".$_POST['picture'] );
if($_FILES['picture']['name'] != ''){
$uploadedfile = $_FILES['picture'];
$upload_overrides = array( 'test_form' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
$imageurl = "";
if ( $movefile && ! isset( $movefile['error'] ) ) {
$imageurl = $movefile['url'];
echo "url : ".$imageurl;
update_user_meta( $user_id, 'picture_'. $rel, $_FILES['picture']['name'] );
} else {
echo $movefile['error'];
}
}
}
add_action( 'show_user_profile', 'fb_add_custom_user_profile_fields' );
add_action( 'edit_user_profile', 'fb_add_custom_user_profile_fields' );
【问题讨论】:
标签: wordpress