PageRenderTime 28ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/learnpress/inc/libraries/meta-box/inc/fields/wysiwyg.php

https://gitlab.com/gregtyka/lfmawordpress
PHP | 97 lines | 48 code | 15 blank | 34 comment | 7 complexity | d08692648e316b5991d72327fb1fe407 MD5 | raw file
  1. <?php
  2. // Prevent loading this file directly
  3. defined( 'ABSPATH' ) || exit;
  4. if ( ! class_exists( 'RWMB_Wysiwyg_Field' ) ) {
  5. class RWMB_Wysiwyg_Field extends RWMB_Field {
  6. static $cloneable_editors = array();
  7. /**
  8. * Enqueue scripts and styles
  9. *
  10. * @return void
  11. */
  12. static function admin_enqueue_scripts() {
  13. wp_enqueue_style( 'rwmb-meta-box-wysiwyg', RWMB_CSS_URL . 'wysiwyg.css', array(), RWMB_VER );
  14. }
  15. /**
  16. * Change field value on save
  17. *
  18. * @param mixed $new
  19. * @param mixed $old
  20. * @param int $post_id
  21. * @param array $field
  22. *
  23. * @return string
  24. */
  25. static function value( $new, $old, $post_id, $field ) {
  26. if ( $field['raw'] ) {
  27. $meta = $new;
  28. } else {
  29. if ( $field['clone'] ) {
  30. $meta = array_map( 'wpautop', $new );
  31. } else {
  32. $meta = wpautop( $new );
  33. }
  34. }
  35. return $meta;
  36. }
  37. /**
  38. * Get field HTML
  39. *
  40. * @param mixed $meta
  41. * @param array $field
  42. *
  43. * @return string
  44. */
  45. static function html( $meta, $field ) {
  46. // Using output buffering because wp_editor() echos directly
  47. ob_start();
  48. $field['options']['textarea_name'] = $field['field_name'];
  49. // Use new wp_editor() since WP 3.3
  50. wp_editor( $meta, $field['id'], $field['options'] );
  51. $editor = ob_get_clean();
  52. if ( $field['clone'] ) {
  53. self::$cloneable_editors[$field['id']] = $editor;
  54. add_action( 'admin_print_footer_scripts', array( __CLASS__, 'footer_scripts' ), 51 );
  55. }
  56. return $editor;
  57. }
  58. /**
  59. * Normalize parameters for field
  60. *
  61. * @param array $field
  62. *
  63. * @return array
  64. */
  65. static function normalize_field( $field ) {
  66. $field = wp_parse_args( $field, array(
  67. 'raw' => false,
  68. 'options' => array(),
  69. ) );
  70. $field['options'] = wp_parse_args( $field['options'], array(
  71. 'editor_class' => 'rwmb-wysiwyg',
  72. 'dfw' => true, // Use default WordPress full screen UI
  73. ) );
  74. // Keep the filter to be compatible with previous versions
  75. $field['options'] = apply_filters( 'rwmb_wysiwyg_settings', $field['options'] );
  76. return $field;
  77. }
  78. static function footer_scripts() {
  79. echo '<script> var rwmb_cloneable_editors = ' . json_encode( self::$cloneable_editors ) . ';</script>';
  80. }
  81. }
  82. }