bp_activity_admin_edit_metabox_type( object $item )

Activity type metabox for the Activity admin edit screen.


Description Description


Parameters Parameters

$item

(Required) Activity item.


Top ↑

Source Source

File: bp-activity/bp-activity-admin.php

function bp_activity_admin_edit_metabox_type( $item ) {
	$bp = buddypress();

	$actions  = array();
	$selected = $item->type;

	// Walk through the registered actions, and build an array of actions/values.
	foreach ( bp_activity_get_actions() as $action ) {
		$action = array_values( (array) $action );

		for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) {
			/**
			 * Don't take in account:
			 * - a mis-named Friends activity type from before BP 1.6,
			 * - The Group's component 'activity_update' one as the Activity component is using it.
			 */
			if ( 'friends_register_activity_action' === $action[$i]['key'] || 'bp_groups_format_activity_action_group_activity_update' === $action[$i]['format_callback'] ) {
				continue;
			}

			$actions[ $action[$i]['key'] ] = $action[$i]['value'];
		}
	}

	// Sort array by the human-readable value.
	natsort( $actions );

	/*
	 * If the activity type is not registered properly (eg, a plugin has
	 * not called bp_activity_set_action()), add the raw type to the end
	 * of the list.
	 */
	if ( ! isset( $actions[ $selected ] ) ) {
		_doing_it_wrong( __FUNCTION__, sprintf( __( 'This activity item has a type (%s) that is not registered using bp_activity_set_action(), so no label is available.', 'buddypress' ), $selected ), '2.0.0' );
		$actions[ $selected ] = $selected;
	}

	?>

	<label for="bp-activities-type" class="screen-reader-text"><?php
		/* translators: accessibility text */
		esc_html_e( 'Select activity type', 'buddypress' );
	?></label>
	<select name="bp-activities-type" id="bp-activities-type">
		<?php foreach ( $actions as $k => $v ) : ?>
			<option value="<?php echo esc_attr( $k ); ?>" <?php selected( $k,  $selected ); ?>><?php echo esc_html( $v ); ?></option>
		<?php endforeach; ?>
	</select>

<?php
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.