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
Reproduction Steps
Expected Behavior
Actual Behavior
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:
lifterlms-blocks/includes/class-llms-blocks-post-instructors.php
Lines 102 to 118 in e8517d9
That code can probably be removed regardless because it's already being done when the instructors are set.
See related gocodebox/lifterlms#1953