wpmetabox / meta-box

The best plugin for WordPress custom fields and custom meta boxes
https://metabox.io
1.18k stars 423 forks source link

WYSIWYG buttons missing when using MB Settings page #1261

Open lmeyer opened 5 years ago

lmeyer commented 5 years ago

Hello,

Issue Overview

When using wysiwyg in MB Settings page, some buttons like "text color selection" are missing in the wysiwyg.

I think it's because tinyMCE is not already fully initialized by wordpress before it displays it on the post edition page. As the default editor is not displayed in the settings page, buttons are missing.

I'm using latest version of plugins.

Steps to Reproduce (for bugs)

<?php 
add_filter( 'mb_settings_pages', 'gdl_options_page' );
function gdl_options_page( $settings_pages )
{
    $settings_pages[] = array(
        'id'          => 'gdl-settings',
        'option_name' => 'gdl_settings',
        'menu_title'  => __( 'Options du thème', 'gdl' ),
        'parent'      => 'themes.php',
        'icon_url'    => 'dashicons-admin-appearance',
        'submit_button' => 'Enregistrer'
    );
    return $settings_pages;
}

add_filter( 'rwmb_meta_boxes', 'gdl_options_meta_boxes' );
function gdl_options_meta_boxes( $meta_boxes )
{
     $meta_boxes[] = array(
        'id'             => 'private',
        'title'          => __( 'Contenu pour les articles privées', 'gdl' ),
        'settings_pages' => 'gdl-settings',
        'fields'         => array(
            array(
                'name' => __( 'Contenu', 'gdl' ),
                'id'   => 'gdl_private_content',
                'type' => 'wysiwyg',
            ),
        ),
    );

    return $meta_boxes;
}

Expected Behavior

Same buttons than the default wysiwyg editor shown in post edition.

Current Behavior

Not all buttons

Related Issues and/or PRs

It's maybe linked to #913.

rilwis commented 5 years ago

Hi @lmeyer ,

The "text color selection" is not part of the default editor. Is it added by a 3rd-party plugin? If so, it's the plugin's responsibility to make it works for all editors. Meta Box doesn't handle the changes in the editor's button at all.

ribeiroeder commented 4 years ago

Hi, I think I can help with this bug. I also had this problem, and it is often related to the fact that TinyMCE editor was changed (adding or removing buttons) by another plugin or function.

But to solve it, you just have to re-declare the TinyMCE buttons in your own metabox function, here is an edition:

function gdl_options_meta_boxes( $meta_boxes )
{
     $meta_boxes[] = array(
        'id'             => 'private',
        'title'          => __( 'Contenu pour les articles privées', 'gdl' ),
        'settings_pages' => 'gdl-settings',
        'fields'         => array(
            array(
                'name' => __( 'Contenu', 'gdl' ),
                'id'   => 'gdl_private_content',
                'type' => 'wysiwyg',
      'tinymce'       => array ( 
              'toolbar1' => 'formatselect, bold, italic, underline, bullist, numlist, blockquote, alignleft, aligncenter, alignright, fullscreen',
              'toolbar2' => 'strikethrough, forecolor, pastetext, removeformat, charmap, link, unlink, redo, undo, wp_help, styleselect',
              'plugins' => 'charmap, colorpicker, hr, lists, media, paste, tabfocus, textcolor, fullscreen, wordpress, wpautoresize, wpeditimage, wpemoji, wpgallery, wplink, wpdialogs, wptextpattern, wpview'
              ),
            ),
        ),
    );

    return $meta_boxes;
}