Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: admin can change product author from rest api #1913

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion includes/Abstracts/DokanRESTController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,19 @@ public function create_item( $request ) {

$object->save();

$author_id = dokan_get_current_user_id();

if ( current_user_can( 'manage_options' ) ) {
$post_author = absint( $request->get_param( 'post_author' ) );
$author = new \WP_User( $post_author );
$author_id = ( ! empty( $post_author ) && $author->exists() && user_can( $author->ID, 'dokan_add_product' ) ) ? $author->ID : $author_id;
}

//Update post author
wp_update_post(
array(
'ID' => $object->get_id(),
'post_author' => dokan_get_current_user_id(),
'post_author' => $author_id,
)
);

Expand Down Expand Up @@ -149,6 +157,23 @@ public function update_item( $request ) {
}

$object->save();

$author_id = dokan_get_current_user_id();
shohag121 marked this conversation as resolved.
Show resolved Hide resolved

if ( current_user_can( 'manage_options' ) ) {
$post_author = absint( $request->get_param( 'post_author' ) );
$author = new \WP_User( $post_author );
$author_id = ( ! empty( $post_author ) && $author->exists() && user_can( $author->ID, 'dokan_add_product' ) ) ? $author->ID : $author_id;
}

//Update post author
wp_update_post(
array(
'ID' => $object->get_id(),
'post_author' => $author_id,
)
);

$this->update_additional_fields_for_object( $object, $request );

/**
Expand Down