| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin\Metabox |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Handles all things with the metabox in combination with the WordPress editor. |
| 10 |
*/ |
| 11 |
class WPSEO_Metabox_Editor { |
| 12 |
|
| 13 |
/** |
| 14 |
* Registers hooks to WordPress. |
| 15 |
* |
| 16 |
* @codeCoverageIgnore |
| 17 |
*/ |
| 18 |
public function register_hooks() { |
| 19 |
add_filter( 'mce_css', [ $this, 'add_css_inside_editor' ] ); |
| 20 |
add_filter( 'tiny_mce_before_init', [ $this, 'add_custom_element' ] ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Adds our inside the editor CSS file to the list of CSS files to be loaded inside the editor. |
| 25 |
* |
| 26 |
* @param string $css_files The CSS files that WordPress wants to load inside the editor. |
| 27 |
* @return string The CSS files WordPress wants to load and our CSS file. |
| 28 |
*/ |
| 29 |
public function add_css_inside_editor( $css_files ) { |
| 30 |
$asset_manager = new WPSEO_Admin_Asset_Manager(); |
| 31 |
$styles = $asset_manager->special_styles(); |
| 32 |
$inside_editor = $styles['inside-editor']; |
| 33 |
|
| 34 |
$asset_location = new WPSEO_Admin_Asset_SEO_Location( WPSEO_FILE ); |
| 35 |
$url = $asset_location->get_url( $inside_editor, WPSEO_Admin_Asset::TYPE_CSS ); |
| 36 |
|
| 37 |
if ( $css_files === '' ) { |
| 38 |
$css_files = $url; |
| 39 |
} |
| 40 |
else { |
| 41 |
$css_files .= ',' . $url; |
| 42 |
} |
| 43 |
|
| 44 |
return $css_files; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Adds a custom element to the tinyMCE editor that we need for marking the content. |
| 49 |
* |
| 50 |
* @param array $tinymce_config The tinyMCE config as configured by WordPress. |
| 51 |
* |
| 52 |
* @return array The new tinyMCE config with our added custom elements. |
| 53 |
*/ |
| 54 |
public function add_custom_element( $tinymce_config ) { |
| 55 |
if ( ! empty( $tinymce_config['custom_elements'] ) ) { |
| 56 |
$custom_elements = $tinymce_config['custom_elements']; |
| 57 |
|
| 58 |
$custom_elements .= ',~yoastmark'; |
| 59 |
} |
| 60 |
else { |
| 61 |
$custom_elements = '~yoastmark'; |
| 62 |
} |
| 63 |
|
| 64 |
$tinymce_config['custom_elements'] = $custom_elements; |
| 65 |
|
| 66 |
return $tinymce_config; |
| 67 |
} |
| 68 |
} |
| 69 |
|