Filter uncanny-automator

uap_template_library_feed

Filters the data used to populate the template library feed before it is displayed.

add_filter( 'uap_template_library_feed', $callback, 10, 2 );

Description

Filters the template library feed data before it's returned. Developers can modify the feed array to customize which templates or integrations are displayed. This hook fires after the feed is fetched and decoded, allowing for dynamic manipulation of the data.


Usage

add_filter( 'uap_template_library_feed', 'your_function_name', 10, 2 );

Parameters

$feed (mixed)
This parameter holds the raw feed data from the template library, which will be processed and filtered by the hook.
$this (mixed)
This parameter holds the decoded feed data, which is an array representing the available templates.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of using the 'uap_template_library_feed' filter to modify the template library feed.
 *
 * This example demonstrates how to add or remove specific integrations from the feed
 * based on certain conditions, such as user role or active plugins.
 */
add_filter( 'uap_template_library_feed', function( $feed, $object ) {

	// Check if the current user has an administrator role.
	if ( current_user_can( 'manage_options' ) ) {
		// If the user is an admin, ensure all integrations are present.
		// This is a hypothetical example; in a real scenario, you might fetch
		// a full list of available integrations and merge it if necessary.
		// For now, we'll assume the original feed already contains all relevant integrations.
	} else {
		// If the user is not an admin, remove specific integrations that might
		// require administrative privileges or are not intended for regular users.
		// Let's say we want to remove 'advanced_analytics' and 'crm_pro' for non-admins.
		if ( isset( $feed['integrations'] ) && is_array( $feed['integrations'] ) ) {
			$feed['integrations'] = array_filter( $feed['integrations'], function( $integration ) {
				return ! in_array( $integration['id'], array( 'advanced_analytics', 'crm_pro' ), true );
			});
		}
	}

	// You could also add new entries or modify existing ones.
	// For example, add a custom integration for specific users:
	if ( current_user_can( 'edit_posts' ) ) {
		$feed['integrations'][] = array(
			'id'          => 'custom_plugin_integration',
			'name'        => 'My Custom Plugin Integration',
			'description' => 'An integration for my custom plugin.',
			'settings_url' => admin_url( 'admin.php?page=my_custom_plugin_settings' ),
		);
	}

	// Always return the modified feed.
	return $feed;

}, 10, 2 ); // Priority 10, accepts 2 arguments.
?>

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/core/lib/class-recipe-template-library.php:139

public function get_library_feed() {

		// Get the feed file.
		$response = wp_remote_get( $this->api_base . $this->library_directory . self::LIBRARY_FILE );
		if ( is_wp_error( $response ) ) {
			return array();
		}

		// Decode the feed.
		$feed = json_decode( wp_remote_retrieve_body( $response ), true );

		// Populate integration data.
		$feed['integrations'] = $this->populate_integration_data( $feed );

		return apply_filters( 'uap_template_library_feed', $feed, $this );
	}


Scroll to Top