Filter uncanny-continuing-education-credits

uoceu_admin_sidebar_try_automator_add

Filters whether to add the Automator section to the admin sidebar.

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

Description

Filters whether to add the "Try Uncanny Automator" item to the admin sidebar. Return `false` to prevent its display. This hook allows developers to programmatically hide the prompt based on certain conditions or user roles.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of a filter for the 'uoceu_admin_sidebar_try_automator_add' hook.
 *
 * This filter allows developers to conditionally prevent the "Try Uncanny Automator"
 * menu item from being added to the Uncanny CEU admin sidebar.
 *
 * For instance, if the user role does not have the 'automator_access' capability,
 * we might want to hide this option to avoid confusion.
 */
add_filter( 'uoceu_admin_sidebar_try_automator_add', function( $should_add ) {

	// Check if the current user has the capability to manage automator features.
	if ( ! current_user_can( 'manage_automator_features' ) ) {
		// If they don't have the capability, return false to prevent adding the menu item.
		return false;
	}

	// Otherwise, return the original value (which is true by default).
	return $should_add;
}, 10, 1 ); // 10 is the priority, 1 is the number of accepted 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/install-automator/install-automator.php:118

public function menu_uncanny_automator() {

		if ( defined( 'AUTOMATOR_BASE_FILE' ) ) {
			return;
		}

		if ( ! apply_filters( 'uoceu_admin_sidebar_try_automator_add', true ) ) {
			return;
		}

		/* translators: Trademarked term */
		$menu_item_text = apply_filters( 'uoceu_admin_sidebar_try_automator_text', sprintf( __( '%s', 'uncanny-ceu' ), 'Automation' ) );

		$menu_item_html = '<span class="ulgm-sidebar-featured-item">' . apply_filters( 'uoceu_admin_sidebar_try_automator_inner_html', '<span class="ulgm-sidebar-featured-item__text">' . esc_html( $menu_item_text ) . '</span>' ) . '</span>';

		add_submenu_page(
			'uncanny-ceu-report',
			$menu_item_text,
			$menu_item_html,
			'manage_options',
			'ceu-install-automator',
			array(
				$this,
				'admin_page_uncanny_automator',
			),
			5
		);
	}


Scroll to Top