Skip to content

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

@thomasplevy

Description

@thomasplevy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions