From 26dcd8e58085a1d6484bea7df9a5a3f267782d7c Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sun, 21 Oct 2018 10:06:48 -0400 Subject: [PATCH] Save actors as objects --- includes/server/actors.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/server/actors.php b/includes/server/actors.php index dca4ce9..42a8349 100644 --- a/includes/server/actors.php +++ b/includes/server/actors.php @@ -2,6 +2,7 @@ namespace pterotype\actors; require_once plugin_dir_path( __FILE__ ) . '../pgp.php'; +require_once plugin_dir_path( __FILE__ ) . 'objects.php'; function get_actor( $id ) { global $wpdb; @@ -155,11 +156,23 @@ function initialize_actors() { function create_actor( $slug, $type ) { global $wpdb; - return $wpdb->query( $wpdb->prepare( + $res = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->prefix}pterotype_actors(slug, type) VALUES(%s, %s)", $slug, $type ) ); + if ( $res === false ) { + return new \WP_Error( + 'db_error', + __( 'Error creating actor', 'pterotype' ) + ); + } + $actor = get_actor_by_slug( $slug ); + $res = \pterotype\objects\upsert_object( $actor ); + if ( is_wp_error( $res ) ) { + return $res; + } + return $res->object; } ?>