BP_REST_Document_Endpoint::bp_rest_document_support()

Added document support for activity, forum and messages.

Description

Source

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

	public function bp_rest_document_support() {

		if ( function_exists( 'bp_is_profile_document_support_enabled' ) && bp_is_profile_document_support_enabled() ) {
			bp_rest_register_field(
				'activity',      // Id of the BuddyPress component the REST field is about.
				'bp_documents', // Used into the REST response/request.
				array(
					'get_callback'    => array( $this, 'bp_documents_get_rest_field_callback' ),
					// The function to use to get the value of the REST Field.
					'update_callback' => array( $this, 'bp_documents_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 Documents.',
						'type'        => 'object',
						'context'     => array( 'embed', 'view', 'edit' ),
					),
				)
			);

			register_rest_field(
				'activity_comments',      // Id of the BuddyPress component the REST field is about.
				'bp_documents', // Used into the REST response/request.
				array(
					'get_callback'    => array( $this, 'bp_documents_get_rest_field_callback' ),    // The function to use to get the value of the REST Field.
					'update_callback' => array( $this, 'bp_documents_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 Documents.',
						'type'        => 'object',
						'context'     => array( 'embed', 'view', 'edit' ),
					),
				)
			);
		}

		if ( function_exists( 'bp_is_messages_document_support_enabled' ) && bp_is_messages_document_support_enabled() ) {
			// Messages Document Support.
			bp_rest_register_field(
				'messages',      // Id of the BuddyPress component the REST field is about.
				'bp_documents', // Used into the REST response/request.
				array(
					'get_callback'    => array( $this, 'bp_documents_get_rest_field_callback_messages' ),
					// The function to use to get the value of the REST Field.
					'update_callback' => array( $this, 'bp_documents_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_forums_document_support_enabled' ) && true === bp_is_forums_document_support_enabled() ) {
			// Topic Document Support.
			register_rest_field(
				'topics',
				'bbp_documents',
				array(
					'get_callback'    => array( $this, 'bbp_document_get_rest_field_callback' ),
					'update_callback' => array( $this, 'bbp_document_update_rest_field_callback' ),
					'schema'          => array(
						'description' => 'Topic Documentss.',
						'type'        => 'object',
						'context'     => array( 'embed', 'view', 'edit' ),
					),
				)
			);

			// Reply Document Support.
			register_rest_field(
				'reply',
				'bbp_documents',
				array(
					'get_callback'    => array( $this, 'bbp_document_get_rest_field_callback' ),
					'update_callback' => array( $this, 'bbp_document_update_rest_field_callback' ),
					'schema'          => array(
						'description' => 'Reply Documents.',
						'type'        => 'object',
						'context'     => array( 'embed', '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.