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
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
| 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.