bp_nouveau_activity_localize_scripts( array $params = array() )

Localize the strings needed for the Activity Post form UI

Description

Parameters

$params

(Optional) Associative array containing the JS Strings needed by scripts.

Default value: array()

Return

(array) The same array with specific strings for the Activity Post form UI if needed.

Source

File: bp-templates/bp-nouveau/includes/activity/functions.php

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
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
function bp_nouveau_activity_localize_scripts( $params = array() ) {
    if ( ! bp_is_activity_component() &&
         ! bp_is_group_activity() &&
         ! bp_is_media_component() &&
         ! bp_is_media_directory() &&
         ! bp_is_group_media() &&
         ! bp_is_group_albums()
    ) { // media popup overlay needs activity scripts
        return $params;
    }
 
    $activity_params = array(
        'user_id'        => bp_loggedin_user_id(),
        'object'         => 'user',
        'backcompat'     => (bool) has_action( 'bp_activity_post_form_options' ),
        'post_nonce'     => wp_create_nonce( 'post_update', '_wpnonce_post_update' ),
        'excluded_hosts' => []
    );
 
    $user_displayname = bp_get_loggedin_user_fullname();
 
    if ( buddypress()->avatar->show_avatars ) {
        $width  = bp_core_avatar_thumb_width();
        $height = bp_core_avatar_thumb_height();
        $activity_params = array_merge( $activity_params, array(
            'avatar_url'        => bp_get_loggedin_user_avatar( array(
                'width'  => $width,
                'height' => $height,
                'html'   => false,
            ) ),
            'avatar_width'      => $width,
            'avatar_height'     => $height,
            'user_display_name' => bp_get_loggedin_user_fullname(),
            'user_domain'       => bp_loggedin_user_domain(),
            'avatar_alt'        => sprintf(
            /* translators: %s = member name */
                __( 'Profile photo of %s', 'buddyboss' ),
                $user_displayname
            ),
        ) );
    }
 
    if ( bp_is_activity_autoload_active() ) {
        $activity_params['autoload'] = true;
    }
 
    if ( bp_is_activity_link_preview_active() ) {
        $activity_params['link_preview'] = true;
    }
 
    /**
     * Filters the included, specific, Action buttons.
     *
     * @since BuddyPress 3.0.0
     *
     * @param array $value The array containing the button params. Must look like:
     * array( 'buttonid' => array(
     *  'id'      => 'buttonid',                            // Id for your action
     *  'caption' => __( 'Button caption', 'text-domain' ),
     *  'icon'    => 'dashicons-*',                         // The dashicon to use
     *  'order'   => 0,
     *  'handle'  => 'button-script-handle',                // The handle of the registered script to enqueue
     * );
     */
    $activity_buttons = apply_filters( 'bp_nouveau_activity_buttons', array() );
 
    if ( ! empty( $activity_buttons ) ) {
        $activity_params['buttons'] = bp_sort_by_key( $activity_buttons, 'order', 'num' );
 
        // Enqueue Buttons scripts and styles
        foreach ( $activity_params['buttons'] as $key_button => $buttons ) {
            if ( empty( $buttons['handle'] ) ) {
                continue;
            }
 
            if ( wp_style_is( $buttons['handle'], 'registered' ) ) {
                wp_enqueue_style( $buttons['handle'] );
            }
 
            if ( wp_script_is( $buttons['handle'], 'registered' ) ) {
                wp_enqueue_script( $buttons['handle'] );
            }
 
            unset( $activity_params['buttons'][ $key_button ]['handle'] );
        }
    }
 
    // Activity Objects
    if ( ! bp_is_single_item() && ! bp_is_user() ) {
        $activity_objects = array(
            'profile' => array(
                'text'                     => __( 'Post in: Profile', 'buddyboss' ),
                'autocomplete_placeholder' => '',
                'priority'                 => 5,
            ),
        );
 
        // the groups component is active & the current user is at least a member of 1 group
        if ( bp_is_active( 'groups' ) && bp_has_groups( array( 'user_id' => bp_loggedin_user_id(), 'max' => 1 ) ) ) {
            $activity_objects['group'] = array(
                'text'                     => __( 'Post in: Group', 'buddyboss' ),
                'autocomplete_placeholder' => __( 'Start typing the group name…', 'buddyboss' ),
                'priority'                 => 10,
            );
        }
 
        /**
         * Filters the activity objects to apply for localized javascript data.
         *
         * @since BuddyPress 3.0.0
         *
         * @param array $activity_objects Array of activity objects.
         */
        $activity_params['objects'] = apply_filters( 'bp_nouveau_activity_objects', $activity_objects );
    }
 
    $activity_strings = array(
        'whatsnewPlaceholder' => sprintf( __( "Write here or use @ to mention someone.", 'buddyboss' ), bp_get_user_firstname( $user_displayname ) ),
        'whatsnewLabel'       => __( 'Post what\'s new', 'buddyboss' ),
        'whatsnewpostinLabel' => __( 'Post in', 'buddyboss' ),
        'postUpdateButton'    => __( 'Post Update', 'buddyboss' ),
        'cancelButton'        => __( 'Cancel', 'buddyboss' ),
        'commentLabel'        => __( '%d Comment', 'buddyboss' ),
        'commentsLabel'       => __( '%d Comments', 'buddyboss' ),
        'loadingMore'         => __( 'Loading...', 'buddyboss' ),
    );
 
    if ( bp_get_displayed_user() && ! bp_is_my_profile() ) {
        $activity_strings['whatsnewPlaceholder'] = sprintf( __( "Write something to %s...", 'buddyboss' ), bp_get_user_firstname( bp_get_displayed_user_fullname() ) );
    }
 
    if ( bp_is_group() ) {
        $activity_strings['whatsnewPlaceholder'] = __( 'Share something with your group...', 'buddyboss' );
        $activity_params = array_merge(
            $activity_params,
            array(
                'object'  => 'group',
                'item_id' => bp_get_current_group_id(),
            )
        );
    }
 
    $params['activity'] = array(
        'params'  => $activity_params,
        'strings' => $activity_strings,
    );
 
    return $params;
}

Changelog

Changelog
Version Description
BuddyPress 3.0.0 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.