Filter uncanny-automator

automator_thrive_apprentice_allowed_post_types

Filters the post types allowed for Thrive Apprentice integrations, allowing customization of available content types.

add_filter( 'automator_thrive_apprentice_allowed_post_types', $callback, 10, 1 );

Description

Filters the allowed post types for Thrive Apprentice content integration. Developers can modify this array to include or exclude specific Thrive Apprentice content types when they are processed or displayed within the plugin.


Usage

add_filter( 'automator_thrive_apprentice_allowed_post_types', 'your_function_name', 10, 1 );

Parameters

$allowed_post_types (mixed)
This parameter contains an array of post types that are considered valid content types within Thrive Apprentice for use with the Automator plugin.

Return Value

The filtered value.


Examples

/**
 * Example of modifying the allowed post types for Thrive Apprentice content.
 *
 * This filter allows developers to add or remove post types that are considered
 * valid content items within Thrive Apprentice courses.
 *
 * @param array $allowed_post_types An array of post types currently allowed.
 * @return array The modified array of allowed post types.
 */
add_filter(
	'automator_thrive_apprentice_allowed_post_types',
	function ( $allowed_post_types ) {
		// Example: Add a custom post type 'my_custom_course_content' if it exists.
		// This might be useful if you have a custom integration with Thrive Apprentice.
		if ( post_type_exists( 'my_custom_course_content' ) ) {
			$allowed_post_types[] = 'my_custom_course_content';
		}

		// Example: Remove a default post type if you don't want it to be selectable.
		// For instance, if you never want assessments to be part of Automator recipes.
		$key = array_search( 'tva_assessment', $allowed_post_types, true );
		if ( false !== $key ) {
			unset( $allowed_post_types[ $key ] );
		}

		// Always return the modified array.
		return $allowed_post_types;
	},
	10, // Priority: 10 is the default, adjust if needed.
	1   // Accepted Args: Only one argument ($allowed_post_types) is passed.
);

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/integrations/thrive-apprentice/helpers/thrive-apprentice-helpers.php:920

public function get_content_types( $structure ) {
		$content_items = array();

		$allowed_post_types = array( 'tva_lesson', 'tva_module', 'tva_assessment' );
		$allowed_post_types = apply_filters( 'automator_thrive_apprentice_allowed_post_types', $allowed_post_types );

		// If structure is empty or not an array, return empty array
		if ( empty( $structure ) || ! is_array( $structure ) ) {
			return $content_items;
		}

		// Loop through each item in the structure
		foreach ( $structure as $item ) {
			// Skip if item is not an object
			if ( ! is_object( $item ) ) {
				continue;
			}

			// Check if current item has required properties
			if ( isset( $item->post_type ) && isset( $item->post_title ) && in_array( $item->post_type, $allowed_post_types, true ) ) {
				$content_items[] = array(
					'value' => $item->post_type,
					'text'  => ucfirst( str_replace( 'tva_', '', $item->post_type ) ),
				);
			}

			// If item has nested structure and it's not empty, recursively search it
			if ( isset( $item->structure ) && ! empty( $item->structure ) && is_array( $item->structure ) ) {
				$nested_items = $this->get_content_types( $item->structure );
				if ( ! empty( $nested_items ) ) {
					$content_items = array_merge( $content_items, $nested_items );
				}
			}
		}

		// Remove duplicates based on value
		$content_items = array_unique( $content_items, SORT_REGULAR );

		return $content_items;
	}

Scroll to Top