Skip to content

Adding WYSIWYG Editor to StartBox Options

I have been delving more and more into StartBox recently, in total I have built 5 sites using this excellent WordPress Framework.

My latest site which will hopefully be going live very soon needed the ability to allow the user to have an options page that had a WYSIWYG Editor. Currently StartBox does not have this ability, so I took a look under the hood and found it was extremely easy to add this feature into options code.

Here is how I did it

I added the following code to the top of admin_settings.php (this is in StartBox > includes > functions):

add_action('admin_print_scripts', 'add_thejs' );
add_action('admin_print_styles', 'add_thecss' );

function add_thecss()
{
    wp_enqueue_style('thickbox');
}

function add_thejs()
    {
        if ( user_can_richedit() ){
            wp_enqueue_script('editor');
            wp_enqueue_script('media-upload');
            add_action('admin_head', 'wp_tiny_mce');

        }
    }

That adds the relevant scripts and styles for the editor.

Then I simply added this into the elseif statements:

elseif ($setting['type'] == 'wysiwyg') {
$output .= sb_input::wysiwyg( $setting_id, $label, $value, $desc );
}

And finally added a new function:

public function wysiwyg( $id, $label, $value, $desc ) {

        $output = "t" . '<p>'."n";
        $output .= "t" . "t" . '<label for="' . THEME_OPTIONS . '[' . $id . ']' . '">' . $label . '</label><br/>'."n";
        $info = THEME_OPTIONS . '[' . $id . ']';
        $output .= the_editor($value,$info);
        if ($desc) { $output .= "t" . "t" . '<br/><span> ' . $desc . ' </span>'."n"; }
        $output .= "t" . '</p>'."n";
        return $output;
    }

And hey presto it works 🙂

Since using this I have noticed one small bug with the buttons for the editor. For some reason when there are more than one editor on the page the editors (apart fromt the very first one) show both rows of buttons. If anyone of you know of a fix for this please let me know.

As with any of my code snippets make sure you test this before using it on a live site.

The good news is that Brian will be adding this to the next release of StartBox so we can all use it in the future 🙂