BP_Attachment_Cover_Image::script_data()

Build script datas for the Uploader UI.

Description

Return

(array) The javascript localization data

Source

File: bp-core/classes/class-bp-attachment-cover-image.php

	public function script_data() {
		// Get default script data.
		$script_data = parent::script_data();

		if ( bp_is_user() ) {
			$item_id = bp_displayed_user_id();

			$script_data['bp_params'] = array(
				'object'          => 'user',
				'item_id'         => $item_id,
				'has_cover_image' => bp_attachments_get_user_has_cover_image( $item_id ),
				'nonces'  => array(
					'remove' => wp_create_nonce( 'bp_delete_cover_image' ),
				),
			);

			// Set feedback messages.
			$script_data['feedback_messages'] = array(
				1 => __( 'Your new cover photo was uploaded successfully.', 'buddyboss' ),
				2 => __( 'There was a problem deleting your cover photo. Please try again.', 'buddyboss' ),
				3 => __( 'Your cover photo was deleted successfully!', 'buddyboss' ),
			);
		} elseif ( bp_is_group() ) {
			$item_id = bp_get_current_group_id();

			$script_data['bp_params'] = array(
				'object'          => 'group',
				'item_id'         => bp_get_current_group_id(),
				'has_cover_image' => bp_attachments_get_group_has_cover_image( $item_id ),
				'nonces'  => array(
					'remove' => wp_create_nonce( 'bp_delete_cover_image' ),
				),
			);

			// Set feedback messages.
			$script_data['feedback_messages'] = array(
				1 => __( 'The group cover photo was uploaded successfully.', 'buddyboss' ),
				2 => __( 'There was a problem deleting the group cover photo. Please try again.', 'buddyboss' ),
				3 => __( 'The group cover photo was deleted successfully!', 'buddyboss' ),
			);
		} else {

			/**
			 * Filters the cover photo params to include specific BuddyPress params for your object.
			 * e.g. cover photo for blogs single item.
			 *
			 * @since BuddyPress 2.4.0
			 *
			 * @param array $value The cover photo specific BuddyPress parameters.
			 */
			$script_data['bp_params'] = apply_filters( 'bp_attachment_cover_image_params', array() );
		}

		// Include our specific js & css.
		$script_data['extra_js']  = array( 'bp-cover-image' );
		$script_data['extra_css'] = array( 'bp-avatar' );

		/**
		 * Filters the cover photo script data.
		 *
		 * @since BuddyPress 2.4.0
		 *
		 * @param array $script_data Array of data for the cover photo.
		 */
		return apply_filters( 'bp_attachments_cover_image_script_data', $script_data );
	}

Changelog

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