Wordpress custom plugin tinyMCE

I am just developing plugins in Wordpress. Right 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 similar things.

I am creating a parameter page that I would like to control the variables passed to tinyMCE so that the user can choose which buttons will be displayed and also add a custom stylesheet to the editor.

At this point, my tiny mce editing function works fine! and the options page also saves the data, checkboxes and everything else that I need.

My only problem is I donโ€™t understand how to pass the variables stored in "options.php" to the current tinyMCE function. This is the current function in the 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 minimize the message by adding the entire code of my parameters page, but I may need some direction regarding the approach to passing variables as the value of $ in []. As mentioned earlier, variables were created on the options page and saved by updating the tiny mce function.

I have researched a lot and I cannot find any direct information about this - as usual, I am not looking for someone to do my code, but perhaps to push me in the right direction.

Thank!

CHANGE 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' );
?>

Itโ€™s still hard for me to access stored variables and use them in functions. Any ideas?

+4
1

update_option. my_format_TinyMCE get_option.

0

Source: https://habr.com/ru/post/1629412/


All Articles