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

Updating instructors list does not replace the post_author with the primary instructor #152

Open
thomasplevy opened this issue Jan 26, 2022 · 0 comments
Labels
Type: Bug Bugs and errors

Comments

@thomasplevy
Copy link
Contributor

thomasplevy commented Jan 26, 2022

Reproduction Steps

  • On a course or lesson add a new instructor to the instructors list (someone who is not currently the primary instructor / post author)
  • Reorder the new instructor to the top of the list (making them the new primary)
  • Save changes

Expected Behavior

  • The new primary instructor is set as the post's post_author

Actual Behavior

  • The former instructor is still the posts post_author

Notes

You could also remove the original primary instructor and replace them with a new instructor and the post author won't change.


Something is going wrong here where the primary instructor is supposed to be automatically set as the post_author during updates:

https://github.com/gocodebox/lifterlms/blob/18d938219de427cbf4c57894dc7b81c87ebafd45/includes/models/model.llms.post.instructors.php#L162

It may be that this is running but then being immediately overwritten by the post_author field from the WP core rest call. We may need to:

A) Remove the post_author support for the post types
B) Remove post_author from the REST schema for the post types
C) Change action priority?
D) Add a new on update hook to set the post author to the primary instructor, we already have what appears to be redundant code attempting to to this here:

public function maybe_set_default_instructor( $post_id, $post, $update ) {
if ( $update || ! $post->post_author ) {
return false;
}
$obj = llms_get_post( $post );
if ( ! $obj || ! is_a( $obj, 'LLMS_Post_Model' ) || ! in_array( $obj->get( 'type' ), $this->post_types, true ) ) {
return false;
}
remove_action( 'save_post_course', array( $this, 'maybe_set_instructors' ), 50, 3 );
$obj->instructors()->set_instructors( array( array( 'id' => $post->post_author ) ) );
return true;
}

That code can probably be removed regardless because it's already being done when the instructors are set.

See related gocodebox/lifterlms#1953

@thomasplevy thomasplevy added the Type: Bug Bugs and errors label Jan 26, 2022
@thomasplevy thomasplevy self-assigned this Jan 26, 2022
@thomasplevy thomasplevy moved this to Backlog in Development Feb 25, 2022
@thomasplevy thomasplevy removed their assignment Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bugs and errors
Projects
Status: Backlog
Development

No branches or pull requests

1 participant