| 1 |
<?php |
| 2 |
/** |
| 3 |
* ConvertKit TinyMCE class |
| 4 |
* |
| 5 |
* @since 1.5.0 |
| 6 |
* @package ConvertKit |
| 7 |
* @author ConvertKit |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* Class ConvertKit_TinyMCE |
| 12 |
*/ |
| 13 |
class ConvertKit_TinyMCE { |
| 14 |
|
| 15 |
/** |
| 16 |
* Constructor |
| 17 |
*/ |
| 18 |
public function __construct() { |
| 19 |
add_action( 'admin_head', array( $this, 'add_buttons' ), 11 ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Filters for adding CK button to TinyMCE editor. |
| 24 |
* |
| 25 |
* @since 1.5.0 |
| 26 |
*/ |
| 27 |
public function add_buttons() { |
| 28 |
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
add_filter( 'mce_external_plugins', array( $this, 'add_tinymce_plugin' ) ); |
| 32 |
add_filter( 'mce_buttons', array( $this, 'register_mce_button' ) ); |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Register the external plugin |
| 38 |
* |
| 39 |
* @since 1.5.0 |
| 40 |
* @param $plugins |
| 41 |
* @return mixed |
| 42 |
*/ |
| 43 |
public function add_tinymce_plugin( $plugins ) { |
| 44 |
|
| 45 |
$plugins['convertkit_button'] = CONVERTKIT_PLUGIN_URL . 'resources/backend/tinymce-buttons.js?' . time(); |
| 46 |
return $plugins; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Register the external plugin. |
| 51 |
* |
| 52 |
* @since 1.5.0 |
| 53 |
* @param $buttons |
| 54 |
* @return array |
| 55 |
*/ |
| 56 |
public function register_mce_button( $buttons ) { |
| 57 |
$buttons[] = 'convertkit_button'; |
| 58 |
|
| 59 |
return $buttons; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
new ConvertKit_TinyMCE(); |
| 66 |
|