[WP] support tags, fix #114
This commit is contained in:
@@ -5,7 +5,6 @@ Plugin URI: https://gancio.org
|
|||||||
Description: Connects an user of a gancio instance to a Wordpress user so that published events are automatically pushed with Gancio API.
|
Description: Connects an user of a gancio instance to a Wordpress user so that published events are automatically pushed with Gancio API.
|
||||||
Version: 1.0
|
Version: 1.0
|
||||||
Author: Gancio
|
Author: Gancio
|
||||||
Author URI: https://gancio.org
|
|
||||||
License: AGPL 3.0
|
License: AGPL 3.0
|
||||||
|
|
||||||
WPGancio is free software: you can redistribute it and/or modify it under the
|
WPGancio is free software: you can redistribute it and/or modify it under the
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ function delete_post ($post_id) {
|
|||||||
function wpgancio_save_event ($post_id) {
|
function wpgancio_save_event ($post_id) {
|
||||||
$event = get_post( $post_id );
|
$event = get_post( $post_id );
|
||||||
|
|
||||||
|
function tagName ($tag) {
|
||||||
|
return $tag->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp_tags = get_the_terms( $event, 'event-tag' );
|
||||||
|
$tags = array_map('tagName', $tmp_tags);
|
||||||
|
|
||||||
// do not save if it's a draft
|
// do not save if it's a draft
|
||||||
if ($event->post_status != 'publish') {
|
if ($event->post_status != 'publish') {
|
||||||
return;
|
return;
|
||||||
@@ -45,6 +52,7 @@ function wpgancio_save_event ($post_id) {
|
|||||||
|
|
||||||
$body = array (
|
$body = array (
|
||||||
'title' => $event->post_title,
|
'title' => $event->post_title,
|
||||||
|
'tags' => $tags,
|
||||||
'description' => $event->post_content,
|
'description' => $event->post_content,
|
||||||
'start_datetime' => intval($date),
|
'start_datetime' => intval($date),
|
||||||
'place_name' => $place_name,
|
'place_name' => $place_name,
|
||||||
@@ -64,13 +72,15 @@ function wpgancio_save_event ($post_id) {
|
|||||||
$response = $http->request( $instance_url . '/api/event', array(
|
$response = $http->request( $instance_url . '/api/event', array(
|
||||||
'method' => 'PUT',
|
'method' => 'PUT',
|
||||||
'headers' => array (
|
'headers' => array (
|
||||||
'Authorization' => 'Bearer ' . get_option('wpgancio_token')
|
'Authorization' => 'Bearer ' . get_option('wpgancio_token'),
|
||||||
), 'body' => $body ));
|
'Content-Type' => 'application/json'
|
||||||
|
), 'body' => wp_json_encode($body) ));
|
||||||
} else { // or create
|
} else { // or create
|
||||||
$response = wp_remote_post($instance_url . '/api/event', array(
|
$response = wp_remote_post($instance_url . '/api/event', array(
|
||||||
'headers' => array (
|
'headers' => array (
|
||||||
'Authorization' => 'Bearer ' . get_option('wpgancio_token')
|
'Authorization' => 'Bearer ' . get_option('wpgancio_token'),
|
||||||
), 'body' => $body ));
|
'Content-Type' => 'application/json'
|
||||||
|
), 'body' => wp_json_encode($body) ));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_wp_error( $response ) ) {
|
if ( is_wp_error( $response ) ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user