I don’t know if this is the best practice, but it looks like you can just check the $_GET array on admin_init for ‘post_type’ and then remove the media_buttons actions as needed:
add_action('admin_init', 'removemediabuttons');
function removemediabuttons() {
if(isset($_GET['post_type']) && $_GET['post_type'] == 'products') {
remove_action( 'media_buttons', 'media_buttons' );
}
}
Thanks jkovis
I was thinking more about this last after i walked away from the computer, and was thinking that would be a solution.
I was just hoping there would be a function like is_custom_post_type()
or something non related that might do the same thing.
The problem is, when you edit the custom post, the get variable post_type is nit there in the url.
Here’s a solution. Maybe someone who knows WordPress can come up with a better one. I only started using WordPress 2 days ago so I don’t totally understand the WordPress way of writing code.
$registered_custom_types = array('product');
add_action('admin_head', 'removemediabuttons');
function removemediabuttons()
{
global $registered_custom_types;
$post_type = null;
$post_id = 0;
if( isset($_GET['post_type']) ) {
$post_type = $_GET['post_type'];
}
else if( isset($_POST['post_type']) ) {
$post_type = $_POST['post_type'];
}
if($post_type)
{
if(in_array($post_type, $registered_custom_types))
{
remove_action( 'media_buttons', 'media_buttons' );
}
}
else
{
if( isset($_GET['post']) ) {
$post_id = $_GET['post'];
}
else if( isset($_POST['post']) ) {
$post_id = $_POST['post'];
}
if($post_id)
{
$post = get_post($post_id);
if(in_array($post->post_type, $registered_custom_types))
{
remove_action( 'media_buttons', 'media_buttons' );
}
}
}
}
OK, learning the WordPress style of doing things.
add_action('admin_head', 'removemediabuttons');
function removemediabuttons()
{
global $post;
if($post->post_type == 'products')
{
remove_action( 'media_buttons', 'media_buttons' );
}
}
doh…I can’t believe I didn’t even think of checking the $post object…good thinking 😉