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.

Currently I have successfully added a row of shortcode buttons to the TinyMCE editor in WordPress. The problem is, only admins can see the row, and I need contributors and editors to see it too. I have checked the Codex for add_action and add_filter and I can't see any specific arguments to indicate user roles or anything like that. How can I modify this code so that all logged in users can see the new row instead of just admins? Here is the code I'm using to add the row to the editor window:

// add shortcode buttons to the tinyMCE editor row 3
function add_button_3() {
   if ( current_user_can('edit_posts') &&  current_user_can('edit_pages') )
   {
     add_filter('mce_external_plugins', 'add_plugin_3');
     add_filter('mce_buttons_3', 'register_button_3');
   }
}
//setup array of shortcode buttons to add
function register_button_3($buttons) {
   array_push($buttons, "dropcap", "divider", "quote", "pullquoteleft", "pullquoteright", "boxdark", "boxlight", "togglesimple", "togglebox", "tabs", "signoff", "columns", "smallbuttons", "largebuttons", "lists");  
   return $buttons;
}
//setup array for tinyMCE editor interface
function add_plugin_3($plugin_array) {
   $plugin_array['lists'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['signoff'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['dropcap'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['divider'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['quote'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['pullquoteleft'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['pullquoteright'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['boxdark'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['boxlight'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['togglesimple'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['togglebox'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['tabs'] = get_template_directory_uri().'/js/customcodes.js'; 
   $plugin_array['columns'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['smallbuttons'] = get_template_directory_uri().'/js/customcodes.js';
   $plugin_array['largebuttons'] = get_template_directory_uri().'/js/customcodes.js';
   return $plugin_array;
}
add_action('init', 'add_button_3'); // add the add_button function to the page init
share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

Your if statement wants the user to be able to posts AND pages, which only applies to admins and editors by default. Are you sure editors cannot see the buttons? If you want anybody who can edit posts to see the buttons (e.g. authors and contributors) take out the check for edit_pages or make it an or statement (which is an unlikely situation in most installs, but I suppose it could happen).

So, instead of:

if ( current_user_can('edit_posts') && current_user_can('edit_pages') )

Use

if ( current_user_can('edit_posts') )

or

if ( current_user_can('edit_posts') || current_user_can('edit_pages') )

share|improve this answer
    
Thank you so much - how did I miss that! –  Industrial Themes Sep 7 '11 at 18:09
add comment

My solution would be to first try out the plugin TinyMCE Advanced instead - it is fantastic and give you very good control. Maybe I'm missing something but I have never felt the need to "roll my own".

share|improve this answer
    
I'm developing a commercial theme for resale and I don't want the user to have to install a plugin nor do I want to package third-party code within my theme. –  Industrial Themes Sep 7 '11 at 15:06
    
I see. Sorry i cant answer your question then. –  byronyasgur Sep 7 '11 at 20:03
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.