From 3a56b6422b5961f033bbe4270145aa9cd9c13998 Mon Sep 17 00:00:00 2001 From: les Date: Fri, 2 Jul 2021 22:33:41 +0200 Subject: [PATCH] [WP] support tags, fix #114 --- wp-plugin/gancio.php | 1 - wp-plugin/oauth.php | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/wp-plugin/gancio.php b/wp-plugin/gancio.php index b39d0f1b..60ea1e42 100644 --- a/wp-plugin/gancio.php +++ b/wp-plugin/gancio.php @@ -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. Version: 1.0 Author: Gancio -Author URI: https://gancio.org License: AGPL 3.0 WPGancio is free software: you can redistribute it and/or modify it under the diff --git a/wp-plugin/oauth.php b/wp-plugin/oauth.php index 75470b52..1c902278 100644 --- a/wp-plugin/oauth.php +++ b/wp-plugin/oauth.php @@ -27,6 +27,13 @@ function delete_post ($post_id) { function wpgancio_save_event ($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 if ($event->post_status != 'publish') { return; @@ -45,6 +52,7 @@ function wpgancio_save_event ($post_id) { $body = array ( 'title' => $event->post_title, + 'tags' => $tags, 'description' => $event->post_content, 'start_datetime' => intval($date), 'place_name' => $place_name, @@ -64,13 +72,15 @@ function wpgancio_save_event ($post_id) { $response = $http->request( $instance_url . '/api/event', array( 'method' => 'PUT', 'headers' => array ( - 'Authorization' => 'Bearer ' . get_option('wpgancio_token') - ), 'body' => $body )); + 'Authorization' => 'Bearer ' . get_option('wpgancio_token'), + 'Content-Type' => 'application/json' + ), 'body' => wp_json_encode($body) )); } else { // or create $response = wp_remote_post($instance_url . '/api/event', array( 'headers' => array ( - 'Authorization' => 'Bearer ' . get_option('wpgancio_token') - ), 'body' => $body )); + 'Authorization' => 'Bearer ' . get_option('wpgancio_token'), + 'Content-Type' => 'application/json' + ), 'body' => wp_json_encode($body) )); } if ( is_wp_error( $response ) ) {