BP_Attachment_Cover_Image::script_data()

Build script datas for the Uploader UI.


Return Return

(array) The javascript localization data


Source 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 image was uploaded successfully.', 'buddypress' ),
				2 => __( 'There was a problem deleting your cover image. Please try again.', 'buddypress' ),
				3 => __( 'Your cover image was deleted successfully!', 'buddypress' ),
			);
		} 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 image was uploaded successfully.', 'buddypress' ),
				2 => __( 'There was a problem deleting the group cover image. Please try again.', 'buddypress' ),
				3 => __( 'The group cover image was deleted successfully!', 'buddypress' ),
			);
		} else {

			/**
			 * Filters the cover image params to include specific BuddyPress params for your object.
			 * e.g. Cover image for blogs single item.
			 *
			 * @since 2.4.0
			 *
			 * @param array $value The cover image 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 image script data.
		 *
		 * @since 2.4.0
		 *
		 * @param array $script_data Array of data for the cover image.
		 */
		return apply_filters( 'bp_attachments_cover_image_script_data', $script_data );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
2.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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