Last active
December 25, 2019 18:43
-
-
Save RiodeJaneiroo/0f614c2b5002f21fa676e2df9e512afc to your computer and use it in GitHub Desktop.
[add button to tinymce]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'after_setup_theme', 'mythemeslug_theme_setup' ); | |
if ( ! function_exists( 'mythemeslug_theme_setup' ) ) { | |
function mythemeslug_theme_setup(){ | |
/********* Registers an editor stylesheet for the theme ***********/ | |
add_action( 'admin_init', 'mythemeslug_theme_add_editor_styles' ); | |
/********* TinyMCE Buttons ***********/ | |
add_action( 'init', 'mythemeslug_buttons' ); | |
} | |
} | |
/********* Registers an editor stylesheet for the theme ***********/ | |
if ( ! function_exists( 'mythemeslug_theme_add_editor_styles' ) ) { | |
function mythemeslug_theme_add_editor_styles() { | |
// add_editor_style( 'custom-editor-style.css' ); | |
} | |
} | |
/********* TinyMCE Buttons ***********/ | |
if ( ! function_exists( 'mythemeslug_buttons' ) ) { | |
function mythemeslug_buttons() { | |
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) { | |
return; | |
} | |
if ( get_user_option( 'rich_editing' ) !== 'true' ) { | |
return; | |
} | |
add_filter( 'mce_external_plugins', 'mythemeslug_add_buttons' ); | |
add_filter( 'mce_buttons', 'mythemeslug_register_buttons' ); | |
} | |
} | |
if ( ! function_exists( 'mythemeslug_add_buttons' ) ) { | |
function mythemeslug_add_buttons( $plugin_array ) { | |
$plugin_array['columns'] = get_template_directory_uri().'/js/tinymce_buttons.js'; | |
return $plugin_array; | |
} | |
} | |
if ( ! function_exists( 'mythemeslug_register_buttons' ) ) { | |
function mythemeslug_register_buttons( $buttons ) { | |
array_push( $buttons, 'columns' ); | |
return $buttons; | |
} | |
} | |
function bmessage( $atts, $content ){ | |
$title = (isset($atts['title'])) ? $atts['title'] : ''; | |
$color = (isset($atts['color'])) ? $atts['color'] : 'green'; | |
$output = '<div class="bMessage bMessage__'.$color.'">'; | |
if($title) $output .= '<div class="bMessage__title subject">'.$title.'</div>'; | |
$output .= '<div class="bMessage__content wysiwyg">'.$content.'</div>'; | |
$output .= '</div>'; | |
return $output; | |
} | |
add_shortcode('message', 'bmessage'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment