Basically what this hook does is it downloads the image, uploads it to the wordpress library and inserts the necessary meta to the event "images" meta.
The image data structure that is stored in event "images" meta is like following:
Will this work without a large array of sizes? Say if I am only uploading through the API a "full" size image and so only upload to the meta data a full size image?
So this will add the image into the media carousel for the event? I presume I can then set the post featured image to equal that first image in the meta data?
You just need to specify the full size url. The other sizes are handled by WordPress during the upload process. The uploaded image will be used as an image for the media carousel yes.
You could also assign the image as a featured image.
The code below seems to be uploading the images correctly to the wordpress database, but the events are not making it into stec rest api to become an event?
The posts work fine until I add in the custom hook below to add the image in. Then the events dont make it through to the REST API so not sure if its missing meta info unless it is linked to the images that we are adding in?
The images are making it onto the server just then not attaching to a posted image so i think the problem is in the custom hook.
Can I add the below hook function into that custom hook in order to get the var_dump?
There is no errors in the debug.log and all of the debug tools are on.
I have noticed that it is creating events within the rest api that are picked up in the counter on the stec dashboard but not in the events management page. So currently the dashboard is reading 300 events when there should be none. Is there an easy way to delete all of that data? I presume they are not pulling through because their json set up is incorrect because of this image processing?
The language bit didnt work but the php code has got be back to zero thank you.
So there are no errors in the log, I have got the image being passed to wordpress uploading to the media library but it is not attaching itself to the post either in the media carousel or as the featured image on the post itself. Any suggestions?
Managed to solve my post thumbnail problem but the images are still not loading into the carousel.
Looks like the data array for the image is fine but it appears that my image is too small for wordpress to make it in a "large size" would that be a specific problem? Does the plugin rely on all 4 standard wordpress sizes being available?
So it when i use get_post_meta($postid) after the function I can see that the meta data is in there for the post.
But it is not within the rest_api which I believe to be the problem. Should it be that we do the image uploading before we upload the post? Then use the rest_insert_stec_events in order to upload the post thumbnail using the media post id?
Hello,
I am currently bringing event information from another platform onto my wordpress server and want to add these into my events calendar.
I have been trying to do that using a curl statement into wp-json/stec/v5/Events but run into a 401 error where that endpoint does not allow posts?
Is there a hook I could use instead if I format the event information into one compatible with STEC?
You need to authorize before trying to insert an event via the api.
In your request add Authorization header.
Example:
$auth example:
where $username is your actual login name
For $app_password you need to go to Dashboard -> Users -> Your profile and scroll down to:
You should use this password and not the one you login with.
Stachethemes Developer
Hi Zhivko,
Appreciate the quick response.
My code is below:
//set auth token for posting
$username = 'admin';
$app_password = '**** **** **** **** **** **** ****';
/**
* Create new event
*/
$new_event = array(
"title" => [
"raw" => "My New Event"
],
"excerpt" => [
"raw" => "Event short description"
],
"content" => [
"raw" => "Event full description"
],
"stec_cal" => 6, // the calendar id number
"meta" => array(
'start_date' => '2023-07-11T12:30',
'end_date' => '2023-07-11T12:30',
'all_day' => true
)
);
// Merge defaults with new event
$new_event = array_replace_recursive($defaults, $new_event);
// Send new event to the api
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://test.surreyunion.org/wp-json/stec/v5/events");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($new_event));
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Accept: application/json','Authorization: $auth'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
// ... do something with the response
echo $response;
curl_close($ch);
$defaults is just an initiation array for stec event.
I am still getting a 401 error. Do you see anything wrong with this?
$auth was missing value and it wasn't correctly added in the header. It was added as a string and not as variable.
Stachethemes Developer
This is amazing thank you Zhivko!
I only have one last question, how do I use this Rest API call to set the featured image of the post? Do I need to add a hook in for that?
I'd suggest you to create e helper function that will handle image uploads.
Here's example.
Assuming this is the event post data:
This array "fn_upload_image" here will hold your images that you want to attach to the event.
It should contain array with image sources.
---
And here's the custom hook that will handle the upload and attaching the image to the event "images" meta data:
---
Basically what this hook does is it downloads the image, uploads it to the wordpress library and inserts the necessary meta to the event "images" meta.
The image data structure that is stored in event "images" meta is like following:
Stachethemes Developer
Will this work without a large array of sizes? Say if I am only uploading through the API a "full" size image and so only upload to the meta data a full size image?
So this will add the image into the media carousel for the event? I presume I can then set the post featured image to equal that first image in the meta data?
You just need to specify the full size url. The other sizes are handled by WordPress during the upload process. The uploaded image will be used as an image for the media carousel yes.
You could also assign the image as a featured image.
Stachethemes Developer
Hi Zhivko,
The code below seems to be uploading the images correctly to the wordpress database, but the events are not making it into stec rest api to become an event?
Anything obvious I should check?
Try to var dump the events ids to see if they are being saved:
If the events are there it is possible they are missing some meta data.
Check if they have read_permission and edit_permission meta values, if their post_status is "publish".
Stachethemes Developer
Hi Zhivko,
The posts work fine until I add in the custom hook below to add the image in. Then the events dont make it through to the REST API so not sure if its missing meta info unless it is linked to the images that we are adding in?
The images are making it onto the server just then not attaching to a posted image so i think the problem is in the custom hook.
Can I add the below hook function into that custom hook in order to get the var_dump?
Cheers!
Do you see any errors in the error_log file? Make sure WP_DEBUG and WP_DEBUG_LOG are set to true in your wp-config.php file.
Stachethemes Developer
Hello Zhivko,
Sorry for the delayed response.
There is no errors in the debug.log and all of the debug tools are on.
I have noticed that it is creating events within the rest api that are picked up in the counter on the stec dashboard but not in the events management page. So currently the dashboard is reading 300 events when there should be none. Is there an easy way to delete all of that data? I presume they are not pulling through because their json set up is incorrect because of this image processing?
Try turning off all settings in Calendar Dashboard -> Settings -> Language and see if the events show up.
---
This php code will delete all events it finds.
Stachethemes Developer
The language bit didnt work but the php code has got be back to zero thank you.
So there are no errors in the log, I have got the image being passed to wordpress uploading to the media library but it is not attaching itself to the post either in the media carousel or as the featured image on the post itself. Any suggestions?
Managed to solve my post thumbnail problem but the images are still not loading into the carousel.
Looks like the data array for the image is fine but it appears that my image is too small for wordpress to make it in a "large size" would that be a specific problem? Does the plugin rely on all 4 standard wordpress sizes being available?
So it when i use get_post_meta($postid) after the function I can see that the meta data is in there for the post.
But it is not within the rest_api which I believe to be the problem. Should it be that we do the image uploading before we upload the post? Then use the rest_insert_stec_events in order to upload the post thumbnail using the media post id?