bp_activity_add_meta_boxes()

Publish Activity for lessons, quizzes and topics with appropriate conditions.

Description

Source

File: bp-integrations/learndash/bp-learndash-filters.php

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
function bp_activity_add_meta_boxes() {
    global $post;
 
    if ( ! bp_is_active( 'activity' ) ) {
        return;
    }
 
    $post_ID = $post->ID;
 
    if (
        (
            'sfwd-courses' == $post->post_type
            || 'sfwd-lessons' == $post->post_type
            || 'sfwd-topic' == $post->post_type
            || 'sfwd-quiz' == $post->post_type
        )
        && !post_type_supports( $post->post_type, 'buddypress-activity' )
    ) {
        return;
    }
 
    // Add Activity when course is published.
    if (
        'sfwd-courses' == $post->post_type
        && $post->post_status == 'publish'
        && post_type_supports( 'sfwd-courses', 'buddypress-activity' )
    ) {
 
        $lesson_bb = learndash_get_course_lessons_list( $post_ID );
        $quizz = learndash_get_course_quiz_list( $post_ID );
 
        if ( !empty( $lesson_bb ) && post_type_supports( 'sfwd-lessons', 'buddypress-activity' ) ) {
            foreach ( $lesson_bb as $lesson ) {
                bp_activity_post_type_publish( $lesson['post']->ID, $lesson['post'] );
            }
        }
 
        if ( !empty( $quizz ) && post_type_supports( 'sfwd-quiz', 'buddypress-activity' ) ) {
            foreach ( $quizz as $quiz ) {
                bp_activity_post_type_publish( $quiz['post']->ID, $quiz['post'] );
            }
        }
 
        if ( !empty( $lesson_bb ) && post_type_supports( 'sfwd-topic', 'buddypress-activity' ) ) {
            foreach ( $lesson_bb as $lesson ) {
                $topics = learndash_get_topic_list( $lesson['post']->ID, $post_ID );
                if ( !empty( $topics ) ) {
                    foreach ( $topics as $topic ) {
                        bp_activity_post_type_publish( $topic->ID, $topic );
                    }
                }
            }
        }
 
        if ( !empty( $lesson_bb ) && post_type_supports( 'sfwd-quiz', 'buddypress-activity' ) ) {
            foreach ( $lesson_bb as $lesson ) {
                $lesson_quiz = learndash_get_lesson_quiz_list( $lesson['post']->ID );
                if ( !empty( $lesson_quiz ) ) {
                    foreach ( $lesson_quiz as $quiz ) {
                        bp_activity_post_type_publish( $quiz['post']->ID, $quiz['post'] );
                    }
                }
            }
        }
    }
 
    // Add Activity when lesson published correctly.
    else if (
        'sfwd-lessons' == $post->post_type
        && $post->post_status == 'publish'
        && post_type_supports( 'sfwd-lessons', 'buddypress-activity' )
    ) {
        if (
            (
                empty( get_post_meta( $post_ID, 'course_id', true ) )
                && learndash_is_sample( $post_ID )
            )
            || (
                !empty( get_post_meta( $post_ID, 'course_id', true ) )
                && 'publish' == get_post_status( get_post_meta( $post_ID, 'course_id', true ) )
            )
            || learndash_is_sample( $post_ID )
        ) {
            bp_activity_post_type_publish( $post_ID, $post );
        }
    }
 
    // Add Activity when topic published correctly.
    else if (
        'sfwd-topic' == $post->post_type
        && $post->post_status == 'publish'
        && post_type_supports( 'sfwd-topic', 'buddypress-activity' )
    ) {
        if (
               !empty( get_post_meta( $post_ID, 'course_id', true ) )
            && !empty( get_post_meta( $post_ID, 'lesson_id', true ) )
            && 'future' === get_post_status( get_post_meta( $post_ID, 'course_id', true ) )
            && 'future' === get_post_status( get_post_meta( $post_ID, 'lesson_id', true ) )
        ) {
            bp_activity_post_type_publish( $post_ID, $post );
        }
    }
 
    // Add Activity when quiz published correctly.
    else if (
        'sfwd-quiz' == $post->post_type
        && $post->post_status == 'publish'
        && post_type_supports( 'sfwd-quiz', 'buddypress-activity' )
    ) {
        if (
            (
                !empty( get_post_meta( $post_ID, 'course_id', true ) )
                && 'future' === get_post_status( get_post_meta( $post_ID, 'course_id', true ) )
            )
            || (
                !empty( get_post_meta( $post_ID, 'lesson_id', true ) )
                && 'future' === get_post_status( get_post_meta( $post_ID, 'lesson_id', true ) )
            )
        ) {
            bp_activity_post_type_publish( $post_ID, $post );
        }
    }
}

Changelog

Changelog
Version Description
BuddyBoss 2.2.3 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.