tinyMCE custom plugin for WordPress


mark

I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that.

I'm building an "options page" and I want to control the variables passed to the tinyMCE function so the user can choose which buttons to display, as well as add a custom stylesheet to the editor.

At this point, my function of editing the little mce works great! And the options page also holds data, checkboxes and everything else I need.

My only problem is that I don't understand how to pass the variable stored in "options.php" to the current tinyMCE function. Here is the current function in my functions.php file:

function my_format_TinyMCE( $in ) {
    //styles for the editor to provide better visual representation.
    $in['content_css'] = get_template_directory_uri() . "/build/styles/tiny-mce-editor.css";
    $in['block_formats'] = "Paragraph=p; Heading 1=h1; Heading 2=h2";
    $in['toolbar1'] = 'formatselect,bold,italic,underline,superscript,bullist,numlist,alignleft,aligncenter,alignright,link,unlink,spellchecker';
    $in['toolbar2'] = '';
    $in['toolbar3'] = '';
    $in['toolbar4'] = '';
    return $in;
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );

I don't want to clutter this post by adding all the code for my "options page", but I may need some guidance on how to pass variables as $in[] values. As mentioned before, these variables will be created and saved in the Options Page, updating the tiny mce function.

I've done a lot of research, but I can't find any direct information - as usual, I'm not looking for someone to write my code, but maybe push me in the right direction.

Thanks!

edit new code

add_action('admin_menu', 'my_cool_plugin_create_menu');

function my_cool_plugin_create_menu() {
    add_menu_page('My Cool Plugin Settings', 'Cool Settings', 'administrator', __FILE__, 'my_cool_plugin_settings_page' , plugins_url('/images/icon.png', __FILE__) );
    add_action( 'admin_init', 'register_my_cool_plugin_settings' );
}

function register_my_cool_plugin_settings() {
    //register our settings
    register_setting( 'my-cool-plugin-settings-group', 'new_option_name' );
}

function my_cool_plugin_settings_page() {
    ?>
    <div class="wrap">
        <h2>Your Plugin Name</h2>
        <form method="post" action="options.php">
            <?php settings_fields( 'my-cool-plugin-settings-group' ); ?>
            <?php do_settings_sections( 'my-cool-plugin-settings-group' ); ?>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row">New Option Name</th>
                    <td><input type="text" name="new_option_name" value="<?php echo esc_attr( get_option('new_option_name') ); ?>" /></td>
                </tr>

            <?php submit_button(); ?>
        </form>
    </div>
<?php }

function my_format_TinyMCE( $in ) {

    $toolbar = get_option('new_option_name');

    //styles for the editor to provide better visual representation.
    $in['content_css'] = get_template_directory_uri() . "/build/styles/tiny-mce-editor.css";
    $in['block_formats'] = "Paragraph=p; Heading 1=h1; Heading 2=h2";
    $in['toolbar1'] = $toolbar;
    $in['toolbar2'] = '';
    $in['toolbar3'] = '';
    $in['toolbar4'] = '';
    return $in;
}
    add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );
?>

I'm still having trouble accessing stored variables and using them in functions. Any ideas?

Igor Yavych

On the options page, options can be saved using update_option . Then, in your function, you can use get_option to access them .my_format_TinyMCE

Related


tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

WordPress plugin tinymce conflict

tom I am using Wordpress and have installed two plugins on it. Both use the Tinymce WYSIWYG editor. If I activate both plugins at the same time, I get the following error message when the page plugin B is displayed: jquery.js? ver=1.12.3:2 Uncaught Error: Auto

WordPress plugin tinymce conflict

tom I am using Wordpress and have installed two plugins on it. Both use the Tinymce WYSIWYG editor. If I activate both plugins at the same time, I get the following error message when the page plugin B is displayed: jquery.js? ver=1.12.3:2 Uncaught Error: Auto

WordPress plugin tinymce conflict

tom I am using Wordpress and have installed two plugins on it. Both use the Tinymce WYSIWYG editor. If I activate both plugins at the same time, I get the following error message when the page plugin B is displayed: jquery.js? ver=1.12.3:2 Uncaught Error: Auto

Wordpress 4.1 TinyMce Button Plugin

Rexspi I'm trying to add a button on tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled the a

Wordpress 4.1 TinyMce Button Plugin

Rexspi I am trying to add a button to the tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

Wordpress 4.1 TinyMce Button Plugin

Rexspi I'm trying to add a button on tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled the a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

Wordpress 4.1 TinyMce Button Plugin

Rexspi I am trying to add a button to the tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled

Wordpress 4.1 TinyMce Button Plugin

Rexspi I'm trying to add a button on tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled the a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a