1. Developer Tutorials
  2. Extending Deep Linking in the plugin

Extending Deep Linking in the plugin

In this tutorial, you will learn how to add custom content into the “Deep Linking” system for BuddyBoss App. Deep Linking allows the app to interpret URL links and redirect the user to the relevant native screens within the app.

BuddyBoss App is only capable of opening web links as native screens if a link type is registered on the plugin side. Otherwise, the link will open in an in-app browser that loads the page in a webview.

Many web links are registered already in the app, like someone’s profile, forums, and courses. These registered web links will open as native screens in the app.

Make sure to also read our tutorial for extending Deep Linking in the app.


We are supporting custom post types and taxonomies in Deep linking.

For the archive page of a custom post type, the response will be like this:

{
    "action": "open_archive",
    "namespace": "core",
    "url": "<url>",
    "post_type": "<postTypeSlug>"
}

For a single template URL of a custom post type, the response will be like this. The response will be handled in BuddyBoss App.

{
    "action": "open_<postTypeSlug>",
    "namespace": "core",
    "url": "<url>",
    "item_id":<itemID>,
    "_links": {
        "books": [
            {
                "embeddable": true,
                "href": "<restUrl>"
            }
        ]
    }
}

Using the above response, you can handle Deep Linking mapping for your custom post type.


Shown below are the filters available to update the above response. 

bbapp_deeplinking_cpt_action

This filter is used for updating the value of the above response for a custom post type.

public function update_cpt_action( $action, $post ) {
	if ( $post instanceof \WP_Post && in_array( $post->post_type, $this->arrPostTypes ) ) {
		return 'open_' . $this->arrPostTypesMapping[ $post->post_type ];
	}

	return $action;
}

add_filter( 'bbapp_deeplinking_cpt_action', array( $this, 'update_cpt_action' ), 10, 2 );

bbapp_deeplinking_cpt_namespace

This filter is used for updating the namespace value of the above response for a custom post type.

public function update_cpt_namespace( $namespace, $post_type ) {
	if ( isset( $post_type ) && in_array( $post_type, $this->arrPostTypes ) ) {
		return 'learndash';
	}

	return $namespace;
}

add_filter( 'bbapp_deeplinking_cpt_namespace', array( $this, 'update_cpt_namespace' ), 10, 2 );

bbapp_deeplinking_cpt

This filter is used to add any custom data with the above response for a custom post type.

public function update_cpt_object( $response, $post ) {

	if ( $post->post_type == 'sfwd-courses' ) {
		$response['_link_action'] = 'ld_course';
	}

	return $response;
}

add_filter( 'bbapp_deeplinking_cpt', array( $this, 'update_cpt_object' ), 10, 2 );

bbapp_deeplinking_links

If you want to add other embedded data, you can do so using this response. This will allow you to add custom deep linking details with existing data.

public function update_cpt_links( $links, $data, $version ) {

	$links['author'] = array(
		array(
			'href'       => rest_url( '/wp/v2/users/' . $data['author_id'] ),
			'embeddable' => true,
		),
	);

	return $links;
}

add_filter('bbapp_deeplinking_links', array( $this, 'update_cpt_links' ), 10, 3 );

Add Support for Custom Permalinks

If you want to extend support for deep linking for any other permalink, follow these steps below:

1. Create one class file and extend ‘BuddyBossApp\DeepLinking\Type\TypeAbstract’.

use BuddyBossApp\DeepLinking\Type\TypeAbstract;

class <ClassName> extends TypeAbstract {
   // Class code
}

2. Extend two abstract methods into the newly created class from Step 1.

use BuddyBossApp\DeepLinking\Type\TypeAbstract;

class <ClassName> extends TypeAbstract  {

      public function __construct() {
		parent::__construct();
	}

      function parse( $url ) {
	     // TODO: Implement parse() method.
      }
}

3. In the parse method, write your logic to convert the URL into deep linking data that you will use in BuddyBoss App to handle the given URL.

4. Load this code in the rest_api_init hook. This code is needed for the Deep linking endpoint.
Note:  In BuddyBoss App, deep linking integration code is loaded with 99 priority.

Example Code:

<?php
/**
 * Register Deep linking support for taxonomy.
 */

use BuddyBossApp\DeepLinking\Type\TypeAbstract;

class TaxonomyType extends TypeAbstract {

	/**
	 * parse Taxonomy urls
	 *
	 * @param $url
	 *
	 * @return array|null
	 */
	public function parse( $url ) {
		$url_meta = $this->get_url_data( $url );
		if ( isset( $url_meta['name'] ) && isset( $url_meta['page'] ) && empty( $url_meta['page'] ) ) {
			foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) {
				if ( $t->rewrite['slug'] == $url_meta['name'] ) {

					/**
					 * Filter taxonomy deep linking namespace
					 */
					$namespace = apply_filters( 'bbapp_deeplinking_taxonomy_namespace', 'core', $t );

					/**
					 * Filter taxonomy deep linking data
					 */
					return apply_filters(
						'bbapp_deeplinking_taxonomy',
						array(
							'action'    => 'open_taxonomy',
							'namespace' => $namespace,
							'url'       => $url,
							'taxonomy'  => $t->name,
						),
						$t
					);
				}
			}
		}

		return null;

	}

}

Questions?

We're always happy to help with questions you might have! Search our documentation, contact support, or connect with our sales team.