uo_display_add_tin_canny_media_button
Filters whether the Tin Can media button should display on post edit pages.
add_filter( 'uo_display_add_tin_canny_media_button', $callback, 10, 1 );
Description
Filters whether to display the Tin Can media button on the WordPress admin edit screen. Developers can use this to conditionally hide the button based on custom logic, returning `false` to prevent its display. This hook is fired within the admin media button rendering process.
Usage
add_filter( 'uo_display_add_tin_canny_media_button', 'your_function_name', 10, 1 );
Parameters
-
$is_post_edit_page(mixed) - This parameter indicates whether the current page is a WordPress post or page edit screen.
Return Value
The filtered value.
Examples
/**
* Conditionally show the Uncanny Articulate and Captivate media button.
*
* This filter allows developers to control when the 'Add Uncanny Articulate/Captivate'
* media button appears in the WordPress editor. By default, it appears on post
* and page edit screens, and in visual builders. This example demonstrates
* how to disable the button on custom post types named 'course'.
*
* @param bool $is_post_edit_page Whether the current screen is a post edit page.
* @return bool Whether the media button should be displayed.
*/
add_filter( 'uo_display_add_tin_canny_media_button', function( $is_post_edit_page ) {
// If the current screen is not considered an edit page by default, keep it that way.
if ( ! $is_post_edit_page ) {
return false;
}
// Check if we are on a custom post type edit screen.
// For this example, let's assume 'course' is a custom post type.
// We'll use get_current_screen() to get reliable information about the current admin page.
$screen = get_current_screen();
// Ensure $screen is valid and we are on a post edit screen.
if ( $screen && 'post' === $screen->base ) {
// If the post type is 'course', disable the media button.
if ( 'course' === $screen->post_type ) {
return false;
}
}
// Otherwise, allow the button to be displayed.
return true;
}, 10, 1 ); // Priority 10, accepts 1 argument.
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/uncanny-articulate-and-captivate/classes/Admin/MediaButton.php:57
public static function show_media_button() {
$is_post_edit_page = in_array(
basename( $_SERVER['PHP_SELF'] ),
array(
'post.php',
'page.php',
'page-new.php',
'post-new.php',
'customize.php',
'admin-ajax.php',
)
);
// Detect visual builder frontend.
$is_divi = ! empty( ultc_get_filter_var( 'et_fb', '' ) );
$is_beaver = ultc_filter_has_var( 'fl_builder' );
if ( ! is_admin() && ( $is_beaver || $is_divi ) ) {
$is_post_edit_page = true;
}
$display_add_tin_canny_media = apply_filters( 'uo_display_add_tin_canny_media_button', $is_post_edit_page );
return $display_add_tin_canny_media;
}