BP_Admin_Setting_Activity

Main activity settings class.

Description

Source

File: bp-core/admin/settings/bp-admin-setting-activity.php

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
class BP_Admin_Setting_Activity extends BP_Admin_Setting_tab {
 
    public function initialize() {
        $this->tab_label = __( 'Activity', 'buddyboss' );
        $this->tab_name  = 'bp-activity';
        $this->tab_order = 40;
    }
 
    public function is_active() {
        return bp_is_active( 'activity' );
    }
 
    public function settings_save() {
        parent::settings_save();
 
        $bp = buddypress();
        $active_components = $bp->active_components;
 
        // Flag for activate the blogs component
        $is_blog_component_active = false;
 
        // Get all active custom post type.
        $post_types = get_post_types( [ 'public' => true ] );
 
        foreach ( $post_types as $cpt ) {
            // Exclude all the custom post type which is already in BuddyPress Activity support.
            if ( in_array( $cpt,
                [ 'forum', 'topic', 'reply', 'page', 'attachment', 'bp-group-type', 'bp-member-type' ] ) ) {
                continue;
            }
 
            $enable_blog_feeds = isset( $_POST["bp-feed-custom-post-type-$cpt"] );
 
            if ( $enable_blog_feeds ) {
                $is_blog_component_active = true;
            }
 
        }
 
        if ( $is_blog_component_active ) {
            $active_components['blogs'] = '1';
        } else {
            unset( $active_components['blogs'] );
        }
 
        // Save settings and upgrade schema.
        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
        require_once( $bp->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
 
        $bp->active_components = $active_components;
        bp_core_install( $bp->active_components );
        bp_core_add_page_mappings( $bp->active_components );
        bp_update_option( 'bp-active-components', $bp->active_components );
 
    }
 
    public function register_fields() {
        $this->add_section( 'bp_activity', __( 'Activity Settings', 'buddyboss' ) );
 
        // Blog Feeds Option (will sync with "blogs" component)
//      $this->add_checkbox_field( 'bp-enable-blog-feeds', __( 'Blog Posts', 'buddyboss' ), [
//          'input_text' => __( 'Automatically publish new blog posts into the activity feed', 'buddyboss' )
//      ] );
 
        // Allow subscriptions setting.
        $this->add_field( '_bp_enable_heartbeat_refresh', __( 'Activity auto-refresh', 'buddyboss' ), 'bp_admin_setting_callback_heartbeat', 'intval' );
 
        // Allow autoload
        $this->add_field( '_bp_enable_activity_autoload', __( 'Activity auto-load', 'buddyboss' ), 'bp_admin_setting_callback_enable_activity_autoload', 'intval' );
 
        // Allow follow.
        $this->add_field( '_bp_enable_activity_follow', __( 'Follow', 'buddyboss' ), 'bp_admin_setting_callback_enable_activity_follow', 'intval' );
 
        // Allow like.
        $this->add_field( '_bp_enable_activity_like', __( 'Likes', 'buddyboss' ), 'bp_admin_setting_callback_enable_activity_like', 'intval' );
 
        // Allow link preview.
        $this->add_field( '_bp_enable_activity_link_preview', __( 'Link Previews', 'buddyboss' ), 'bp_admin_setting_callback_enable_activity_link_preview', 'intval' );
 
        // Allow subscriptions setting.
        if ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) {
            // $this->add_field( '_bp_enable_akismet', __( 'Akismet', 'buddyboss' ), 'bp_admin_setting_callback_activity_akismet', 'intval' );
        }
 
        // Activity Settings Tutorial
        $this->add_field( 'bp-activity-settings-tutorial','', 'bp_activity_settings_tutorial' );
 
        $this->add_section( 'bp_custom_post_type', __( 'Posts in Activity Feeds', 'buddyboss' ) );
 
        // create field for default Platform activity feed.
        $get_default_platform_activity_types = bp_platform_default_activity_types();
        $is_first = true;
        foreach ( $get_default_platform_activity_types as $type ) {
            $name = $type['activity_name'];
            $class = ( true === $is_first ) ? 'child-no-padding-first' : 'child-no-padding';
            $type['class'] = $class;
            $this->add_field( "bp-feed-platform-$name", ( true === $is_first ) ? __( 'BuddyBoss Platform', 'buddyboss' ) : '', 'bp_feed_settings_callback_platform', 'intval', $type );
            $is_first = false;
        }
 
        // Get all active custom post type.
        $post_types = get_post_types( [ 'public' => true ] );
 
        // Exclude BP CPT
        $bp_exclude_cpt = [ 'forum', 'topic', 'reply', 'page', 'attachment', 'bp-group-type', 'bp-member-type' ];
 
        $bp_excluded_cpt = array();
        foreach ( $post_types as $post_type ) {
            // Exclude all the custom post type which is already in BuddyPress Activity support.
            if ( in_array( $post_type, $bp_exclude_cpt ) ) {
                continue;
            }
 
            $bp_excluded_cpt[] = $post_type;
        }
 
        // flag for adding conditional CSS class.
        $count       = 0;
        $description = 0;
 
        foreach ( $bp_excluded_cpt as $key => $post_type ) {
 
            $fields = [];
 
            $fields['args'] = [
                    'post_type' => $post_type,
                    'description' => false,
            ];
 
            if ( 'post' === $post_type ) {
                // create field for each of custom post type.
                $this->add_field( "bp-feed-custom-post-type-$post_type", __( 'WordPress', 'buddyboss' ), 'bp_feed_settings_callback_post_type', 'intval', $fields['args'] );
                // Activity commenting on post and comments.
                $this->add_field( 'bp-disable-blogforum-comments', __( 'Post Comments', 'buddyboss' ), 'bp_admin_setting_callback_blogforum_comments', 'bp_admin_sanitize_callback_blogforum_comments' );
            } else {
                if ( 0 === $description ) {
                    $fields['args']['description'] = true;
                    $description =1;
                }
                if ( 0 === $count ) {
                    $fields['args']['class'] = 'child-no-padding-first';
                    // create field for each of custom post type.
                    $this->add_field( "bp-feed-custom-post-type-$post_type", __( 'Custom Post Types', 'buddyboss' ), 'bp_feed_settings_callback_post_type', 'intval', $fields['args'] );
                } else {
                    $fields['args']['class'] = 'child-no-padding';
                    // create field for each of custom post type.
                    $this->add_field( "bp-feed-custom-post-type-$post_type", '', 'bp_feed_settings_callback_post_type', 'intval', $fields['args'] );
                }
                $count++;
            }
        }
 
        // Posts in Activity Tutorial
        $this->add_field( 'bp-posts-in-activity-tutorial','', 'bp_posts_in_activity_tutorial' );
    }
 
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Methods

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.