ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-kirki-field-editor.php (2370B)


      1 <?php
      2 /**
      3  * Override field methods
      4  *
      5  * @package     Kirki
      6  * @subpackage  Controls
      7  * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
      8  * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
      9  * @since       2.2.7
     10  */
     11 
     12 if ( ! class_exists( 'Kirki_Field_Editor' ) ) {
     13 
     14 	/**
     15 	 * Field overrides.
     16 	 */
     17 	class Kirki_Field_Editor extends Kirki_Field {
     18 
     19 		/**
     20 		 * Constructor.
     21 		 * Since editor fields only work properly if there's a single tinyMCE instance
     22 		 * We'll be adding a global editor using the add_editor method.
     23 		 *
     24 		 * @access public
     25 		 * @param string $config_id    The ID of the config we want to use.
     26 		 *                             Defaults to "global".
     27 		 *                             Configs are handled by the Kirki_Config class.
     28 		 * @param array  $args         The arguments of the field.
     29 		 */
     30 		public function __construct( $config_id = 'global', $args = array() ) {
     31 
     32 			// Call the parent-class constructor.
     33 			parent::__construct( $config_id, $args );
     34 
     35 			// Add the editor.
     36 			add_action( 'customize_controls_print_footer_scripts', array( __CLASS__, 'add_editor' ) );
     37 
     38 		}
     39 
     40 		/**
     41 		 * Sets the control type.
     42 		 *
     43 		 * @access protected
     44 		 */
     45 		protected function set_type() {
     46 
     47 			$this->type = 'kirki-editor';
     48 
     49 		}
     50 
     51 		/**
     52 		 * Sets the $sanitize_callback
     53 		 *
     54 		 * @access protected
     55 		 */
     56 		protected function set_sanitize_callback() {
     57 
     58 			// If a custom sanitize_callback has been defined,
     59 			// then we don't need to proceed any further.
     60 			if ( ! empty( $this->sanitize_callback ) ) {
     61 				return;
     62 			}
     63 			$this->sanitize_callback = 'wp_kses_post';
     64 
     65 		}
     66 
     67 		/**
     68 		 * Adds the global textarea
     69 		 *
     70 		 * @static
     71 		 * @access public
     72 		 */
     73 		public static function add_editor() {
     74 			wp_enqueue_script( 'tiny_mce' );
     75 
     76 			echo '<div id="kirki_editor_pane" class="hide">';
     77 			wp_editor( '', 'kirki-editor', array(
     78 				'_content_editor_dfw' => false,
     79 				'drag_drop_upload'    => true,
     80 				'tabfocus_elements'   => 'content-html,save-post',
     81 				'editor_height'       => 200,
     82 				'default_editor'      => 'tinymce',
     83 				'teeny'               => true,
     84 				'tinymce'             => array(
     85 					'resize'             => false,
     86 					'wp_autoresize_on'   => false,
     87 					'add_unload_trigger' => false,
     88 				),
     89 			) );
     90 			echo '</div>';
     91 			do_action( 'admin_footer' );
     92 			do_action( 'admin_print_footer_scripts' );
     93 		}
     94 	}
     95 }