Home › Forums › Backend Issues (wp-admin) › Acf block + custom tinymce button postmeta database duplication › Reply To: Acf block + custom tinymce button postmeta database duplication
I found a solution to my problem by adding the custom button another way :
In functions.php :
// Prevent empty tags from being removed by TinyMCE
add_filter('tiny_mce_before_init', 'add_my_options');
function add_my_options($opt) {
$opt['extended_valid_elements'] = '*[*]';
return $opt;
}
add_action( 'after_setup_theme', 'arch_theme_setup' );
if ( ! function_exists( 'arch_theme_setup' ) ) {
function arch_theme_setup(){
add_action( 'init', 'arch_buttons' );
}
}
if ( ! function_exists( 'arch_buttons' ) ) {
function arch_buttons() {
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
return;
}
add_filter( 'mce_external_plugins', 'arch_add_buttons' );
add_filter( 'mce_buttons', 'arch_register_buttons' );
}
}
if ( ! function_exists( 'arch_add_buttons' ) ) {
function arch_add_buttons( $plugin_array ) {
$plugin_array['archbtn'] = get_template_directory_uri().'/lib/blocks/blockscript/custom-button.js';
return $plugin_array;
}
}
if ( ! function_exists( 'arch_register_buttons' ) ) {
function arch_register_buttons( $buttons ) {
array_push( $buttons, 'archbtn' );
return $buttons;
}
}
custom-button.js :
(function() {
tinymce.PluginManager.add('archbtn', function( editor, url ) {
editor.addButton( 'archbtn', {
type: 'button',
text: 'Ajouter un bouton',
onclick: function() {
editor.insertContent('test');
}
});
});
})();
I still plan on using acf js api for this kind of thing because i found it to be cleaner. But i still don’t understand why my database entry in postmeta table got duplicated everytime tinymce was loaded.
So if anybody knows why it is doing this, i’m very curious and want to understand 🙂 !
Have a nice day
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.