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