BP_REST_Media_Endpoint::bp_rest_media_support()

Register custom field for the activity api.

Description

Source

File: bp-media/classes/class-bp-rest-media-endpoint.php

	public function bp_rest_media_support() {
		bp_rest_register_field(
			'activity',      // Id of the BuddyPress component the REST field is about.
			'bp_media_ids', // Used into the REST response/request.
			array(
				'get_callback'    => array( $this, 'bp_media_ids_get_rest_field_callback' ),    // The function to use to get the value of the REST Field.
				'update_callback' => array( $this, 'bp_media_ids_update_rest_field_callback' ), // The function to use to update the value of the REST Field.
				'schema'          => array(                                // The example_field REST schema.
					'description' => 'Activity Medias.',
					'type'        => 'object',
					'context'     => array( 'embed', 'view', 'edit' ),
				),
			)
		);

		bp_rest_register_field(
			'activity',      // Id of the BuddyPress component the REST field is about.
			'media_gif', // Used into the REST response/request.
			array(
				'get_callback'    => array( $this, 'bp_gif_data_get_rest_field_callback' ),
				'update_callback' => array( $this, 'bp_gif_data_update_rest_field_callback' ), // The function to use to update the value of the REST Field.
				'schema'          => array(
					'description' => 'Topic Gifs.',
					'type'        => 'object',
					'context'     => array( 'embed', 'view', 'edit' ),
				),
			)
		);

		register_rest_field(
			'activity_comments',      // Id of the BuddyPress component the REST field is about.
			'bp_media_ids', // Used into the REST response/request.
			array(
				'get_callback'    => array( $this, 'bp_media_ids_get_rest_field_callback' ),    // The function to use to get the value of the REST Field.
				'update_callback' => array( $this, 'bp_media_ids_update_rest_field_callback' ), // The function to use to update the value of the REST Field.
				'schema'          => array(                                // The example_field REST schema.
					'description' => 'Activity Medias.',
					'type'        => 'object',
					'context'     => array( 'embed', 'view', 'edit' ),
				),
			)
		);

		register_rest_field(
			'activity_comments',      // Id of the BuddyPress component the REST field is about.
			'media_gif', // Used into the REST response/request.
			array(
				'get_callback'    => array( $this, 'bp_gif_data_get_rest_field_callback' ),
				'update_callback' => array( $this, 'bp_gif_data_update_rest_field_callback' ), // The function to use to update the value of the REST Field.
				'schema'          => array(
					'description' => 'Topic Gifs.',
					'type'        => 'object',
					'context'     => array( 'embed', 'view', 'edit' ),
				),
			)
		);

		if ( function_exists( 'bp_is_forums_media_support_enabled' ) && true === bp_is_forums_media_support_enabled() ) {
			// Topic Media Photo Support.
			register_rest_field(
				'topics',
				'bbp_media',
				array(
					'get_callback'    => array( $this, 'bbp_media_get_rest_field_callback' ),
					'update_callback' => array( $this, 'bbp_media_update_rest_field_callback' ),
					'schema'          => array(
						'description' => 'Topic Medias.',
						'type'        => 'object',
						'context'     => array( 'embed', 'view', 'edit' ),
					),
				)
			);

			// Reply Media Photo Support.
			register_rest_field(
				'reply',
				'bbp_media',
				array(
					'get_callback'    => array( $this, 'bbp_media_get_rest_field_callback' ),
					'update_callback' => array( $this, 'bbp_media_update_rest_field_callback' ),
					'schema'          => array(
						'description' => 'Topic Medias.',
						'type'        => 'object',
						'context'     => array( 'embed', 'view', 'edit' ),
					),
				)
			);
		}

		if ( function_exists( 'bp_is_forums_gif_support_enabled' ) && true === bp_is_forums_gif_support_enabled() ) {
			// Topic Media Gif Support.
			register_rest_field(
				'topics',
				'bbp_media_gif',
				array(
					'get_callback'    => array( $this, 'bbp_media_gif_get_rest_field_callback' ),
					'update_callback' => array( $this, 'bbp_media_gif_update_rest_field_callback' ),
					'schema'          => array(
						'description' => 'Topic Gifs.',
						'type'        => 'object',
						'context'     => array( 'embed', 'view', 'edit' ),
					),
				)
			);

			// Reply Media Gif Support.
			register_rest_field(
				'reply',
				'bbp_media_gif',
				array(
					'get_callback'    => array( $this, 'bbp_media_gif_get_rest_field_callback' ),
					'update_callback' => array( $this, 'bbp_media_gif_update_rest_field_callback' ),
					'schema'          => array(
						'description' => 'Topic Gifs.',
						'type'        => 'object',
						'context'     => array( 'embed', 'view', 'edit' ),
					),
				)
			);
		}

		if ( function_exists( 'bp_is_messages_media_support_enabled' ) && true === bp_is_messages_media_support_enabled() ) {
			// Messages Media Photo Support.
			bp_rest_register_field(
				'messages',      // Id of the BuddyPress component the REST field is about.
				'bp_media_ids', // Used into the REST response/request.
				array(
					'get_callback'    => array( $this, 'bp_media_ids_get_rest_field_callback_messages' ),
					// The function to use to get the value of the REST Field.
					'update_callback' => array( $this, 'bp_media_ids_update_rest_field_callback_messages' ),
					// The function to use to update the value of the REST Field.
					'schema'          => array(                                // The example_field REST schema.
						'description' => 'Messages Medias.',
						'type'        => 'object',
						'context'     => array( 'view', 'edit' ),
					),
				)
			);
		}

		if ( function_exists( 'bp_is_messages_gif_support_enabled' ) && true === bp_is_messages_gif_support_enabled() ) {
			// Messages Media Gif Support.
			bp_rest_register_field(
				'messages',      // Id of the BuddyPress component the REST field is about.
				'media_gif', // Used into the REST response/request.
				array(
					'get_callback'    => array( $this, 'bp_gif_data_get_rest_field_callback_messages' ),
					'update_callback' => array( $this, 'bp_gif_data_update_rest_field_callback_messages' ),
					// The function to use to update the value of the REST Field.
					'schema'          => array(                                // The example_field REST schema.
						'description' => 'Message Gifs.',
						'type'        => 'object',
						'context'     => array( 'view', 'edit' ),
					),
				)
			);
		}
	}

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.