You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* When Saving/Publishing a Course from the Course editor, usually three primary network calls are made from the Gutenberg editor serially -
74
+
*
75
+
* 1. The first call is initiated automatically by GB the moment we click the Publish/Update button, it saves the whole block `markup` of the course, but doesn't save the structure of the course, so no lessons or modules.
76
+
* 2. After first call is successful, Sensei explicitly makes a second call to save the structure of the course, i.e. the lessons and modules.
77
+
* 3. After the second call is successful, Sensei triggers the Post save call again, similar to the first call.
78
+
*
79
+
* When we click on the Publish button for a new Course containing new unsaved lessons, the first call (1) publishes the Draft course, new lessons are not saved yet.
80
+
* So if we try to find lessons under this Course at this point with this `publish_course` hook, we'll only get existing lessons, not the new ones.
81
+
*
82
+
* The second call (2) saves the new lessons and modules of the course. This is not a Post save/publish call, so it doesn't trigger the `publish_course` hook.
83
+
*
84
+
* When the second call is successful, Sensei triggers the Post save call again, which invokes this `publish_course`. By this time, the new lessons are saved and we can find and publish them.
85
+
* An important point is `publish_course` hook is invoked even when 'Update' is clicked on an already published course. So before publishing the lessons using this hook, we need to check if the course is being published or just being updated.
86
+
*/
72
87
if ( ! current_user_can( 'publish_post', $course_id ) ) {
73
88
return;
74
89
}
75
90
91
+
// In parallel to the 3 calls mentioned above, GB also initiates some calls to save metabox data, they also trigger this hook. But we don't want to process anything for them.
// This is the first call made, it's not the structure saving call, so the added/updated lessons are not yet saved at this point.
91
-
// So we set the flag to publish lessons on the next call, which is made after the structure is saved.
111
+
// If it's the main publish call, we set this flag to use in the call (3) which will come later to determine if the call is made as part of the publishing sequence or just a normal update sequence.
if ( ! $is_main_publish_call && ! $is_publishing_started ) {
98
-
// If its not the "Publish" call and the flag is not set, then we don't need to publish lessons.
99
-
// Because it that case it's just a normal "Update" call.
119
+
// If it's not the main publish call and the flag is not set, then it's just an update call sequence, We don't publish anything in normal update sequence, so we return early.
0 commit comments