Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i have this plugin named toggle-box which insert the shortcode [toggle Title="the title"]text[/toggle] and allows me to use this shortcode to insert toggle boxes in to wordpress blog i as tring to add tiny mce button to the plugin but have been unable to so far. I went through many tutorials but so far have been unable to figure out the right way. So i wil leke to know whats wrong yith mu code and how can i correct it Or how do i add a tiny mce button to the plugin.

My plugin

http://wordpress.org/extend/plugins/toggle-box/

http://plugins.trac.wordpress.org/browser/toggle-box/tags/1.5%20beta/

My plugin code

toggle-box.php

<?php
/**
 * Plugin Name: Toggle box
 * Plugin URI: http://wordpress.org/extend/plugins/toggle-box/
 * Description: This is an awesome custom plugin which adds toggle box functionality in to your theme themes.
 * Author: phantom.omaga
 * Author URI: http://profiles.wordpress.org/users/phantom.omaga/
 * Version: 1.5
**/

//*************************** Toggle Boxes Short Code ***************************//

function togglebox($atts, $content = null) {
    extract(shortcode_atts(array(
        'title'      => '',
    ), $atts));

    $out .= '<h3 class="toggle"><strong><a href="#">' .$title. '</a></strong></h3>';
    $out .= '<div class="toggle-box" style="display: none;"><p>';
    $out .= do_shortcode($content);
    $out .= '</p></div>';

   return $out;
}

add_shortcode('toggle', 'togglebox');


//*************************** Tiny Mce Button Code  ***************************//

add_action('init', 'add_button');  

function add_button() {  
   if ( current_user_can('edit_posts') &&  current_user_can('edit_pages') )  
   {  
     add_filter('mce_external_plugins', 'add_plugin');  
     add_filter('mce_buttons', 'register_button');  
   }  
}  

function register_button($buttons) {  
   array_push($buttons, "toggle");  
   return $buttons;  
}  

function add_plugin($plugin_array) {  
   $plugin_array['toggle'] = plugins_url .'toggle-box/js/mce.js';  
   return $plugin_array;  
}  
//*************************** Get Plugin URL  ***************************//

function get_pluginurl() {
// WP < 2.6
if ( !function_exists('plugins_url') )
    return get_option('siteurl') . '/wp-content/plugins/' . plugin_basename(dirname(__FILE__));
    return plugins_url(plugin_basename(dirname(__FILE__)));
}

//*************************** Calls Toggle Box css and js***************************//

add_action( 'init', 'toggle_box_init' );
function toggle_box_init() {
    if ( ! is_admin() ) {
        wp_enqueue_script( 'toggle-box', plugins_url( 'toggle-box' ) . '/js/toggle-box.js', array( 'jquery' ) );
        wp_enqueue_style( 'toggle-box', plugins_url( 'toggle-box' ) . '/toggle-box.css' );
    }
}

//add_action('wp_head', 'add_togglebox');
?>

http://plugins.trac.wordpress.org/browser/toggle-box/tags/1.5%20beta/toggle-box.php

js/mce.php

(function() {  
    tinymce.create('tinymce.plugins.toggle', {  
        init : function(ed, url) {  
            ed.addButton('toggle', {  
                title : 'Add a toggle box',  
                image : url + '/../../images/mce-toggle.png',  
                onclick : function() {  
                     ed.selection.setContent('[toggle Title="#"]' + ed.selection.getContent() + '[/toggle]');  

                }  
            });  
        },  
        createControl : function(n, cm) {  
            return null;  
        },  
    });  
    tinymce.PluginManager.add('toggle', tinymce.plugins.toggle);  
})();   

http://plugins.trac.wordpress.org/browser/toggle-box/tags/1.5%20beta/js/mce.js

share|improve this question
You also have to add the button into the buttons array, which is part of the code you have commented out, see my answer on this question for clarity or search for user:1468 tinymce(i've given other examples before to). – t31os Dec 7 '11 at 17:49
tried but cant get it to work :( – phantom.omaga Dec 8 '11 at 14:01
Not really much to go on.. – t31os Dec 9 '11 at 14:35
Have in mind that some changes coming soon in 3.3 wpdevel.wordpress.com/2011/12/07/whats-new-javascript-in-3-3 – Philip Dec 10 '11 at 11:29

closed as too localized by toscho Oct 7 '12 at 18:15

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.