Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

save settings of tinymce_advanced WordPress

  • SOLVED

i have customize the plugin tinymce_advanced.

I have change the buttons by default.

i have a multisite installation & when i create a new site, the button by default doesn't appeared in the visual editor. I must save the settings in the options page of the plugin & the buttin appears.

I need a simple code (probably add_action) to an action like "save settings".
My goal : when i create a new site, i have the buttons of tinymce_advanced in the visual editor and i don't need to save settings.

Answers (1)

2012-02-06

John Cotton answers:

I don't think there is a neat way to do this: you want the options set in the database, so you've got to set them

It would probably be best to put some code in a register_activation_hook function and then provide default values for each of the eight update_options listed in tadv_admin.php


Sébastien | French WordpressDesigner comments:

yes, maybe. Could you show me the code ?


John Cotton comments:

From the Codex.....

class MyPlugin {
static function install() {
// default value required for $tadv_toolbars
// default value required for $tadv_options
// default value required for $plugins
// default value required for $toolbar_1
// default value required for $toolbar_2
// default value required for $toolbar_3
// default value required for $toolbar_4
// default value required for $tadv_allbtns


update_option( 'tadv_toolbars', $tadv_toolbars );
update_option( 'tadv_options', $tadv_options );
update_option( 'tadv_plugins', $plugins );
update_option( 'tadv_btns1', $toolbar_1 );
update_option( 'tadv_btns2', $toolbar_2 );
update_option( 'tadv_btns3', $toolbar_3 );
update_option( 'tadv_btns4', $toolbar_4 );
update_option( 'tadv_allbtns', $tadv_allbtns );
}
}
register_activation_hook( __FILE__, array('MyPlugin', 'install') );


It may be that you don't need a default value for each of them but only you know what you want the toolbar to look like!


Sébastien | French WordpressDesigner comments:

OK :-)
could i use this code in function.php ?
and in this case, what's the content of the last line ?
this ?
register_activation_hook( __FILE__, array('MyPlugin', 'install') );


John Cotton comments:

<blockquote>could i use this code in function.php ?</blockquote>
Is the code related to the plugin? If so, it should really go in the plugin.

But if you've moved everything to your theme (ie functions.php), then this would be better (register_activation_hook is only for plugins).

function install() {
// default value required for $tadv_toolbars
// default value required for $tadv_options
// default value required for $plugins
// default value required for $toolbar_1
// default value required for $toolbar_2
// default value required for $toolbar_3
// default value required for $toolbar_4
// default value required for $tadv_allbtns

update_option( 'tadv_toolbars', $tadv_toolbars );
update_option( 'tadv_options', $tadv_options );
update_option( 'tadv_plugins', $plugins );
update_option( 'tadv_btns1', $toolbar_1 );
update_option( 'tadv_btns2', $toolbar_2 );
update_option( 'tadv_btns3', $toolbar_3 );
update_option( 'tadv_btns4', $toolbar_4 );
update_option( 'tadv_allbtns', $tadv_allbtns );
}
add_action( 'switch_theme', 'install' );


That way it will get activated when the theme is first installed.

If there is a change of multiple activations, then clearly - unless you plan on deleting them when the theme is deactivated - you should change the code to not overwrite user settings.


Sébastien | French WordpressDesigner comments:

ok i try that,
and if i use register_activation_hook, i must create a file in the plugin, that's it ?


John Cotton comments:

<blockquote>and if i use register_activation_hook, i must create a file in the plugin, </blockquote>

It's the over way around - it you create the file as a plugin, you should use register_activation_hook.

You just want some code to run when your code is first executed that sets things up. Either of those ways will do that.

What you don't want is the code running every time someone visits a page. Both of those ways avoid that.


Sébastien | French WordpressDesigner comments:

I try to use your code in functions.php like that :

function install() {

// default value required for $tadv_toolbars
$tadv_toolbars = array(
'toolbar_1' => array('fullscreen' ),
'toolbar_2' => array( 'fontsizeselect', 'formatselect', 'pastetext', 'pasteword', 'removeformat', 'separator8', 'charmap', 'print', 'separator9', 'forecolor', 'backcolor', 'emotions', 'separator10', 'sup', 'sub', 'media', 'separator11', 'undo', 'redo', 'attribs', 'wp_help' ),
'toolbar_3' => array(),
'toolbar_4' => array()
);

update_option( 'tadv_toolbars', $tadv_toolbars );

}
add_action( 'switch_theme', 'install' );


i create a site, i change its theme. But in the visual editor no changes...

i have try too with "init" instead of "switch_theme" but the resultat is the same.


John Cotton comments:

<blockquote>i create a site, i change its theme. But in the visual editor no changes..</blockquote>

Well that might because of the values you've set. Sorry, I don't know the plugin well enough to comment on what the settings should be.

But you can check in your database to see if that code has executed - just look in wp_options for the value.

If you're tried 'init' the code must be being executed and if you switched away and back to your theme, then the value will be set.


Sébastien | French WordpressDesigner comments:

by default, in the original plugin the value of $tadv_toolbars is
$tadv_toolbars = array(
'toolbar_1' => array('fullscreen', 'underline', 'italic', 'bold', 'strikethrough', 'separator1', 'bullist', 'numlist', 'outdent', 'indent', 'separator2', 'justifyleft', 'justifycenter', 'justifyright', 'separator3', 'link', 'unlink', 'separator4', 'image', 'styleprops', 'separator12', 'wp_more', 'wp_page', 'separator5', 'spellchecker', 'search', 'separator6' ),
'toolbar_2' => array( 'fontsizeselect', 'formatselect', 'pastetext', 'pasteword', 'removeformat', 'separator8', 'charmap', 'print', 'separator9', 'forecolor', 'backcolor', 'emotions', 'separator10', 'sup', 'sub', 'media', 'separator11', 'undo', 'redo', 'attribs', 'wp_help' ),
'toolbar_3' => array(),
'toolbar_4' => array()
);


i have just change the vale oftoolbar_1 like that :

$tadv_toolbars = array(
'toolbar_1' => array('fullscreen' ),
'toolbar_2' => array( 'fontsizeselect', 'formatselect', 'pastetext', 'pasteword', 'removeformat', 'separator8', 'charmap', 'print', 'separator9', 'forecolor', 'backcolor', 'emotions', 'separator10', 'sup', 'sub', 'media', 'separator11', 'undo', 'redo', 'attribs', 'wp_help' ),
'toolbar_3' => array(),
'toolbar_4' => array()
);


John Cotton comments:

But is it being stored?