I am new and a bit of troublesome on how Wordpress work as I have plan to use it as CMS for my commercial website. I have been figuring out on how to make an image that I have retrieved from user's Facebook photo and save it as upload file in Wordpress.
Let me explain first.
I have created a Facebook test user and able to get their Facebook information after their registration (by getting some basic info and use wp_insert_user()
). I have no problem retrieving basic user information as I just save it in my Wordpress site with update_user_meta
. I also able to get user's Facebook photos image link with Facebook API.
But right now I need those image to be save as Wordpress media so that users can manipulate them (update or delete). I tried to make like; during user registration, my website able to get the users photos file and save it in my site. When user have logged in, they will able to view their Facebook photos in my site and they able to delete the photos and upload a new one if they wanted to.
Let say for example, this is the retrieved user profile photo:-
http://graph.facebook.com/118114855253013/picture?type=large
and user's Facebook cover photo:-
https://scontent.xx.fbcdn.net/hphotos-xft1/v/t1.0-9/12931266_119567738441058_7589195259803266908_n.jpg?oh=d709e39e7525c69e96a2b1695d4930fa&oe=57C011F2
from Facebook API:-
$response = $fb->get('/me?fields=id, name, cover, picture, albums{name,photos{source}}', $longLivedAccessToken);
$user = $response->getGraphUser();
$coverpic = $user['cover']['source'];
$profilepic = 'http://graph.facebook.com/' . $user['id'] . '/picture?type=large';
Usually I will directly save it to user meta along with other basic information for example:-
update_user_meta( $user_id, 'coverpic', $coverpic );
update_user_meta( $user_id, 'profilepic', $profilepic );
But that just link the images from Facebook. I may be need to change that update_user_meta()
method and change it into I don't know, maybe Wordpress upload function such as wp_handle_upload()
or wp_insert_attachment()
or maybe other related functions that is quite confusing for me. But I have been reading Wordpress documentation for days and having hard time on applying them in my current situation. I have been figuring out on how to save it in Wordpress media and make it able to be manipulated by the users themselves in their front end profile page after their 'Wordpress Login via Facebook' in my site.
I do really need help here guys. My programming brain is so slow, I might kill myself to become good at it...