Skip to content

Commit

Permalink
Merge pull request #13 from zngly/fix/user-meta
Browse files Browse the repository at this point in the history
fix: user meta
  • Loading branch information
zngly-vlad authored May 18, 2023
2 parents 6c42a77 + 7a67811 commit 8a2102b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.2",
"version": "1.1.3",
"name": "zngly/wp-graphql-acf-mutations",
"description": "ACF Mutations for WP GraphQL",
"homepage": "https://github.com/zngly/wp-graphql-acf-mutations",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-graphql-acf-mutations",
"version": "1.1.2",
"version": "1.1.3",
"description": "wp-graphql-acf-mutations",
"homepage": "https://github.com/zngly/wp-graphql-acf-mutations#readme",
"author": "Vlad-Anton Medves",
Expand Down
12 changes: 5 additions & 7 deletions src/mutations/mutations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use Zngly\ACFM\Mutations\PostObject;
use Zngly\ACFM\Mutations\MediaItem;
use Zngly\ACFM\Mutations\Taxonomy;

use Zngly\ACFM\Mutations\UserObject;
use Zngly\ACFM\Utils as ACFMUtils;

// add_action('graphql_post_object_mutation_update_additional_data', function ($post_id, $input, $post_type_object) {
// if ($post_type_object->name === "my_post_type") {
// if (isset($input['customInput'])) update_post_meta($post_id, 'custom_input', $input['customInput']);
// }
// }, 10, 3);

/**
* Mutations class.
* Maps the above comment to acf fields
Expand All @@ -25,6 +19,7 @@ public static function registerMutations()
{
new MediaItem();
new PostObject();
new UserObject();
new Taxonomy();
}

Expand Down Expand Up @@ -144,6 +139,9 @@ public static function update_single_field($id, $value, $field_name, $field_type

if (self::should_update($value)) update_field($field_name, $value, $post_id);
else delete_field($field_name, $post_id);
} else if ($type_name === 'User') {
if (self::should_update($value)) update_user_meta($id, $field_name, $value);
else delete_user_meta($id, $field_name);
} else {
if (self::should_update($value)) update_field($field_name, $value, $id);
else delete_field($field_name, $id);
Expand Down
15 changes: 15 additions & 0 deletions src/mutations/userObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Zngly\ACFM\Mutations;

use Zngly\ACFM\Mutations;

class UserObject
{
public function __construct()
{
add_action('graphql_user_object_mutation_update_additional_data', function ($user_id, $input, $mutation_name, $context, $info) {
Mutations::updater($user_id, $input, 'User');
}, 10, 5);
}
}
2 changes: 1 addition & 1 deletion wp-graphql-acf-mutations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Adds Advanced Custom Fields Mutations to the WPGraphQL Schema
* Author: Vlad-Anton Medves
* Text Domain: wp-graphql-acf
* Version: v1.1.2
* Version: v1.1.3
* Requires PHP: 7.0
*
* @package WPGraphQL_ACF_Mutations
Expand Down

0 comments on commit 8a2102b

Please sign in to comment.