WPSEO_Metabox_Editor

Handles all things with the metabox in combination with the WordPress editor.

Defined (1)

The class is defined in the following location(s).

/admin/metabox/class-metabox-editor.php  
  1. class WPSEO_Metabox_Editor { 
  2.  
  3. /** 
  4. * Registers hooks to WordPress 
  5. */ 
  6. public function register_hooks() { 
  7. add_filter( 'mce_css', array( $this, 'add_css_inside_editor' ) ); 
  8. add_filter( 'tiny_mce_before_init', array( $this, 'add_custom_element' ) ); 
  9.  
  10. /** 
  11. * Adds our inside the editor CSS file to the list of CSS files to be loaded inside the editor. 
  12. * @param string $css_files The CSS files that WordPress wants to load inside the editor. 
  13. * @return string The CSS files WordPress wants to load and our CSS file. 
  14. */ 
  15. public function add_css_inside_editor( $css_files ) { 
  16. $asset_manager = new WPSEO_Admin_Asset_Manager(); 
  17. $styles = $asset_manager->special_styles(); 
  18. /** @var WPSEO_Admin_Asset $inside_editor */ 
  19. $inside_editor = $styles['inside-editor']; 
  20.  
  21. $url = $inside_editor->get_url( WPSEO_Admin_Asset::TYPE_CSS, WPSEO_FILE ); 
  22.  
  23. if ( '' === $css_files ) { 
  24. $css_files = $url; 
  25. else { 
  26. $css_files .= ', ' . $url; 
  27.  
  28. return $css_files; 
  29.  
  30. /** 
  31. * Adds a custom element to the tinyMCE editor that we need for marking the content. 
  32. * @param array $tinymce_config The tinyMCE config as configured by WordPress. 
  33. * @return array The new tinyMCE config with our added custom elements. 
  34. */ 
  35. public function add_custom_element( $tinymce_config ) { 
  36. if ( ! empty( $tinymce_config['custom_elements'] ) ) { 
  37. $custom_elements = $tinymce_config['custom_elements']; 
  38.  
  39. $custom_elements .= ', ~yoastmark'; 
  40. else { 
  41. $custom_elements = '~yoastmark'; 
  42.  
  43. $tinymce_config['custom_elements'] = $custom_elements; 
  44.  
  45. return $tinymce_config;