Last active
January 23, 2019 20:12
-
-
Save Log1x/cfabc5fca56f06dfd571d07bc68ca53f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
namespace App; | |
if (class_exists('TinyMCE')) { | |
return; | |
} | |
/** | |
* TinyMCE | |
*/ | |
class TinyMCE | |
{ | |
/** | |
* Constructor | |
*/ | |
public function __construct() | |
{ | |
if (is_admin()) { | |
add_action('init', [$this, 'init']); | |
} | |
} | |
/** | |
* Initialize the TinyMCE object | |
*/ | |
public function init() | |
{ | |
// Check if user has proper permissions & has rich editing enabled. | |
if (!current_user_can('edit_posts') && !current_user_can('edit_pages') || get_user_option('rich_editing') !== 'true') { | |
return; | |
} | |
// Setup the filters | |
add_filter('mce_external_plugins', [$this, 'plugins']); | |
add_filter('mce_buttons', [$this, 'buttons']); | |
} | |
/** | |
* Add plugins to the TinyMCE / Visual Editor | |
* | |
* @param array $plugin_array | |
* @return array | |
*/ | |
public function plugins($plugin_array) | |
{ | |
$plugin_array['app'] = \App\asset_path('scripts/tinymce.js'); | |
return $plugin_array; | |
} | |
/** | |
* Add buttons to the TinyMCE / Visual Editor | |
* | |
* @param array $buttons | |
* @return array | |
*/ | |
public function buttons($buttons) | |
{ | |
array_push($buttons, '', 'app'); | |
return $buttons; | |
} | |
} | |
new TinyMCE(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment