<?php

add_filter('widget_text', 'do_shortcode');

// Tiny MCE editor

 function cleanup_shortcode_fix($content) {   
          $array = array (
            '<p>[' => '[', 
            ']</p>' => ']', 
            ']<br />' => ']',
            ']<br>' => ']',
            '<span class="highlight">[' => '[',
            '<span class="highlight-wrap">[' => '[',
            '<span class="highlight-inline">[' => '[',
            ']</span>' => ']'
          );
          $content = strtr($content, $array);
            return $content;
        }
        add_filter('the_content', 'cleanup_shortcode_fix', 10);

		

function load_custom_wp_admin_style(){
    wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/custom-editor-style.css', false, '1.0.0' );
    wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action('admin_enqueue_scripts', 'load_custom_wp_admin_style');

// Enable font size & font family selects in the editor
if ( ! function_exists( 'wpex_mce_buttons' ) ) {
	function wpex_mce_buttons( $buttons ) {
		array_unshift( $buttons, 'fontselect' ); // Add Font Select
		array_unshift( $buttons, 'fontsizeselect' ); // Add Font Size Select
		array_unshift( $buttons, 'styleselect' ); // Add styles
		return $buttons;
	}
}
add_filter( 'mce_buttons_2', 'wpex_mce_buttons' );

// Hooks your functions into the correct filters
function vf_layouts_add_mce_button() {
	// check user permissions
	if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
		return;
	}
	// check if WYSIWYG is enabled
	if ( 'true' == get_user_option( 'rich_editing' ) ) {
		add_filter( 'mce_external_plugins', 'vf_layouts_add_tinymce_plugin' );
		add_filter( 'mce_buttons', 'vf_layouts_register_mce_button' );
	}
}
add_action('admin_head', 'vf_layouts_add_mce_button');

// Declare layouts script for new button
function vf_layouts_add_tinymce_plugin( $plugin_array ) {
	$plugin_array['vf_layouts_mce_button'] = plugin_dir_url( __FILE__ ) .'/js/mce-layouts.js';
	return $plugin_array;
}

// Register layouts new button in the editor
function vf_layouts_register_mce_button( $buttons ) {
	array_push( $buttons, 'vf_layouts_mce_button' );
	return $buttons;
}


// Hooks your functions into the correct filters
function vf_shortcodes_add_mce_button() {
	// check user permissions
	if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
		return;
	}
	// check if WYSIWYG is enabled
	if ( 'true' == get_user_option( 'rich_editing' ) ) {
		add_filter( 'mce_external_plugins', 'vf_shortcodes_add_tinymce_plugin' );
		add_filter( 'mce_buttons', 'vf_shortcodes_register_mce_button' );
	}
}
add_action('admin_head', 'vf_shortcodes_add_mce_button');

// Declare script for new button
function vf_shortcodes_add_tinymce_plugin( $plugin_array ) {
	$plugin_array['vf_shortcodes_mce_button'] = plugin_dir_url( __FILE__ ) .'/js/mce-shortcodes.js';
	return $plugin_array;
}

// Register new button in the editor
function vf_shortcodes_register_mce_button( $buttons ) {
	array_push( $buttons, 'vf_shortcodes_mce_button' );
	return $buttons;
}

function gk_own_styles($config) {
    $temp_array = array(
        array(
            'title' => 'Short underline',
            'block' => 'span',
            'classes' => 'vf-text-underline-short'
        ),
        array(
            'title' => 'Short underline white',
            'block' => 'span',
            'classes' => 'vf-text-underline-short-white'
        ),
        array(
            'title' => 'Info block',
            'block' => 'p',
            'classes' => 'info-block'
        ),
        array(
            'title' => 'Address',
            'block' => 'span',
            'selector' => 'ul',
            'classes' => 'vf-address-block',
            'wrapper' => true,
        )            
    );
    $config['style_formats'] = json_encode( $temp_array );
    return $config;
}
add_filter('tiny_mce_before_init', 'gk_own_styles');
