Filter uncanny-learndash-toolkit

ult_admin_sidebar_try_automator_add

Filters the visibility of the "Try Automator" button in the WordPress admin sidebar.

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

Description

Allows developers to conditionally prevent the "Try Automator" section from appearing in the Uncanny Toolkit's admin sidebar. Return `false` to hide this promotional item.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of how to use the ult_admin_sidebar_try_automator_add filter.
 * This example will prevent the "Try Automator" link from appearing in the admin sidebar
 * if the current user's role is 'contributor'.
 */
add_filter( 'ult_admin_sidebar_try_automator_add', 'my_custom_prevent_automator_sidebar_add', 10, 1 );

function my_custom_prevent_automator_sidebar_add( $should_add ) {
	// Check if the current user is a contributor
	if ( current_user_can( 'contributor' ) ) {
		// If the user is a contributor, return false to prevent adding the Automator link.
		return false;
	}

	// Otherwise, return the original value to allow the Automator link to be added.
	return $should_add;
}

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/install-automator.php:36

public function add_try_automator_page() {
		// Check if Automator is already installed
		if ( defined( 'AUTOMATOR_BASE_FILE' ) ) {
			return;
		}
		// Check if we have to render the item
		if ( ! apply_filters( 'ult_admin_sidebar_try_automator_add', true ) ) {
			return;
		}

		// Get the item text
		$menu_item_text = apply_filters( 'ult_admin_sidebar_try_automator_text', __( 'Automation', 'uncanny-learndash-toolkit' ) );

		// Create the link content
		$menu_item_html = '<span class="ult-sidebar-featured-item">' . apply_filters( 'ult_admin_sidebar_try_automator_inner_html', '<span class="ult-sidebar-featured-item__text">' . $menu_item_text . '</span>' ) . '</span>';

		// Add the subpage menu
		add_submenu_page(
			'uncanny-toolkit',
			$menu_item_text,
			$menu_item_html,
			'manage_options',
			'install-automator',
			array( $this, 'install_automator_page' ),
			1
		);

	}


Scroll to Top