Skip to:
Content
Pages
Categories
Search
Top
Bottom

TinyMCE buttons – how to filter?

  • @dfactory

    Participant

    Hi,
    Is there a way to filter buttons in Fancy editr (for eg. full screen writing) used by bbPress on the frontend – in topics and replies?
    I was trying to filter it ‘bbp_get_the_content’ but I didn’t figure it out.

Viewing 10 replies - 1 through 10 (of 10 total)
  • @hansaplastique

    Participant

    I’ve used the following code to remove some buttons for non-admins.
    This will keep your normal editor in the admin pages as they should stay, yet visitors of my bbPress forum can only use a few buttons.
    You can find a list of “standard” buttons in tinyMCE here.

    Place this code in the functions.php file of your theme.
    (ps. I’m no expert and pretty new to bbPress – but this worked like a charm for me)

    function bbp_mce_override( $args = array() ) {
    $args['teeny'] = false;
    return $args;
    }
    add_filter( 'bbp_after_get_the_content_parse_args', 'bbp_mce_override' );

    // *********************** CUSTOMIZE TINYMCE BUTTONS FOR BBPRESS *****************************
    if (!is_super_admin()) // remove buttons for non admins
    {
    function add_tinymce_buttons($buttons)
    {
    $arr_size=count($buttons);
    // remove blockquote, kitchen-sink, full-screen and the more-button
    $remove_these=array('blockquote','wp_adv','fullscreen','wp_more');

    for ($counter=$arr_size; $counter>=0; $counter--)
    {
    if ( in_array($buttons[$counter],$remove_these) )
    {
    unset($buttons[$counter]);
    }
    }

    // add the "image" button
    array_push($buttons,'image');

    return $buttons;
    }

    // Erase the entire 2nd button bar
    function add_tinymce_buttons_2($buttons)
    {
    unset($buttons);
    return $buttons;
    }

    add_filter('mce_buttons', 'add_tinymce_buttons');
    add_filter('mce_buttons_2', 'add_tinymce_buttons_2');
    }

    @hansaplastique

    Participant

    Sorry that the code looks a little messy, the code-tag didn’t do a very good job at keeping the indentation and there is no edit button …. hmmm.
    I’ll just give it another try.


    function bbp_mce_override( $args = array() ) {
    $args['teeny'] = false;
    return $args;
    }
    add_filter( 'bbp_after_get_the_content_parse_args', 'bbp_mce_override' );

    if (!is_super_admin()) // remove buttons for non admins
    {
    function add_tinymce_buttons($buttons)
    {
    $arr_size=count($buttons);
    $remove_these=array('blockquote','wp_adv','fullscreen','wp_more');

    for ($counter=$arr_size; $counter>=0; $counter--)
    {
    if ( in_array($buttons[$counter],$remove_these) )
    {
    unset($buttons[$counter]);
    }
    }

    array_push($buttons,'image');

    return $buttons;
    }

    function add_tinymce_buttons_2($buttons)
    {
    unset($buttons);
    return $buttons;
    }

    add_filter('mce_buttons', 'add_tinymce_buttons');
    add_filter('mce_buttons_2', 'add_tinymce_buttons_2');
    }

    @hansaplastique

    Participant

    If anyone can tell me how to properly post code I’ll try again. πŸ™

    @netweb

    Keymaster

    Wrap the code in <pre><code></code></pre>

    @dfactory

    Participant

    Thank you Hansaplastique!

    Looks like first function (bbp_mce_override) overrides bbPress tinymce settings and then uses mce buttons same as they appear in the backend (which can be then modified easily).

    @hansaplastique

    Participant

    Thanks Stephen – and here I thought the “code” button would do that for me πŸ˜‰
    I’ll paste the code again, as you can see I removed some buttons (that have no purpose anyway) and added some …


    add_filter('tiny_mce_before_init', 'tinymce_other_css_for_content');

    function bbp_mce_override( $args = array() ) {
    $args['teeny'] = false;
    return $args;
    }
    add_filter( 'bbp_after_get_the_content_parse_args', 'bbp_mce_override' );

    if (!is_super_admin()) // remove/add buttons for non admins
    {
    function add_tinymce_buttons($buttons)
    {
    $arr_size=count($buttons);
    $remove_these=array('blockquote','wp_adv','fullscreen','wp_more');

    for ($counter=$arr_size; $counter>=0; $counter--)
    {
    if ( in_array($buttons[$counter],$remove_these) )
    {
    unset($buttons[$counter]);
    }
    }

    array_push($buttons,'separator','cut','copy','paste','separator','undo','redo','separator','sub','sup','forecolor','backcolor','charmap');

    return $buttons;
    }

    function add_tinymce_buttons_2($buttons)
    {
    unset($buttons);
    return $buttons;
    }

    add_filter('mce_buttons', 'add_tinymce_buttons');
    add_filter('mce_buttons_2', 'add_tinymce_buttons_2');
    }

    For some of these to work I had to expand the allowed_tags in WordPress (be carefull when doing this) using the following code;


    function my_allowed_html_tags_in_comments() {
    define('CUSTOM_TAGS', true);
    global $allowedtags;

    $allowedtags = array(
    'a' => array(
    'href' => array (),
    'title' => array ()),
    'blockquote' => array(
    'cite' => array ()),
    'cite' => array (),
    'code' => array(),
    'em' => array(),
    'strong' => array(),
    'pre' => array(
    'class' => array()),
    'p' => array(
    'style' => array()),
    'span' => array(
    'style' => array()),
    'sup' => array(),
    'sub' => array()
    );
    }

    add_action('init', 'my_allowed_html_tags_in_comments', 10);

    Hope it’s helpful to someone πŸ™‚

    @hansaplastique

    Participant

    I guess the code formatting didn’t work again … wish I could edit.

    @matrixd

    Participant

    HiΒ HansaplastiqueΒ is possible to add at tinyMCE editor the preview button?

    @hansaplastique

    Participant

    I have no idea – it seems that this is a tinyMCE plugin?
    I haven’t played with 3rd party tinyMCE plugins yet – but if you tell me how to install it, then I wouldn’t mind testing it for you.

    Bottomline is that you’ll have to look for the “keyword” to get the button to become visible (in this case “preview” according to this link). Add that keyword to the “array_push” list.

    One plugin I use (WP Smileys) requires that I make a few minor modifications;

    In functions.php (in the code above, just below “add_filter(‘mce_buttons_2’, ‘add_tinymce_buttons_2’);”), I had to add:

    // Restore the smileys plugin
    add_filter(“mce_external_plugins”, “s4w_tinymce_addplugin”);
    add_filter(‘mce_buttons’, ‘s4w_tinymce_registerbutton’);

    @matrixd

    Participant

    Ok thanks for help, I’ll try!

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
Skip to toolbar