0

I'm trying to add multiple shortcode custom buttons to the TinyMCE wordpress editor. I have writed this code and it's working fine but the buttons are loaded only on the visual editor mode, Is it possible to add them also to the html editor?

My class to register the buttons

<?php

if( !defined( 'ABSPATH' ) ){
  exit;
}

class customTinyMCE {

  public function __construct()
  {
    add_action( 'init', [$this, 'shortcodeButtonsInit'] );
  }


  public function shortcodeButtonsInit() : void
  {
    if( current_user_can('edit_posts') && current_user_can('edit_pages') ){
      add_filter("mce_external_plugins", [$this, 'registerTinymcePlugin'] );
      add_filter('mce_buttons', [$this, 'addTinymceButtons'] );
    }
  }

  public function registerTinymcePlugin( array $plugin_array ) : array
  {
    $plugin_array['bs_shortcodes'] = PLUGIN_DIR.'/js/shortcodes.js';
    return $plugin_array;
  }

  public function addTinymceButtons( array $buttons ) : array
  {
    array_push( $buttons, "ct_button", "c_button", "p_button", "sw_button", "ml_button" );
    return $buttons;
  }

}

Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.