PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.7
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / metabox / class-metabox-editor.php

class-metabox-editor.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.7, at admin/metabox/class-metabox-editor.php

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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