Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm adding TinyMCE buttons to my plugin and they're working, but I only want these buttons to show up for a certain custom post type. I followed this tutorial if it helps:

http://www.tutorialchip.com/wordpress/wordpress-shortcode-tinymce-button-tutorial-part-2/

How can I have that check if they are editing/posting a post in a custom post type of lets say, newpages?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

If you followed that tutorial you linked then look at the function that registers the buttons:

function mylink_button() {
   if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages'){
     return;
   }
   if ( get_user_option('rich_editing') == 'true' ) {
     add_filter( 'mce_external_plugins', 'add_plugin' );
     add_filter( 'mce_buttons', 'register_button' );
   }
}

and you change it a bit to check for the post type:

function mylink_button() {
        if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages')){
         return;
        }
        if ( get_user_option('rich_editing') == 'true' ) {
            global $typenow;
            if (empty($typenow) && !empty($_GET['post'])) {
                $post = get_post($_GET['post']);
                $typenow = $post->post_type;
            }
            if ("newpages" == $typenow){
                add_filter( 'mce_external_plugins', 'add_plugin' );
                add_filter( 'mce_buttons', 'register_button' );
            }
       }
    }

this way you only register the buttons on your "newpages" type

share|improve this answer
    
Thanks again. :D –  Jared Mar 11 '11 at 2:45
    
Glad i could help. –  Bainternet Mar 11 '11 at 2:51
add comment

Thank you Bainternet. Very useful. I used your solution with one small modification.

Instead of

global $typenow;

I took

global $current_screen;
$current_screen->post_type;

$typenow only returns the correct type, if you are inserting a new post. When you are editing an existing post, it always returns "post". So it's better to use $current_screen->post_type.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.