← Back
Editing: class-directorist-description-field.php
<?php /** * Directorist Description Field class. * */ namespace Directorist\Fields; if ( ! defined( 'ABSPATH' ) ) { exit; } class Description_Field extends Textarea_Field { public $type = 'description'; public function sanitize( $posted_data ) { if ( $this->__get( 'type' ) === 'wp_editor' ) { return self::sanitize_content( $this->get_value( $posted_data ) ?? '' ); } return parent::sanitize( $posted_data ); } /** * Keep rich text without allowing user HTML to configure frontend widgets. */ public static function sanitize_content( $content ) { $allowed_html = wp_kses_allowed_html( 'post' ); foreach ( $allowed_html as &$attributes ) { if ( ! is_array( $attributes ) ) { continue; } if ( isset( $attributes['class'] ) ) { $attributes['class'] = [ 'value_callback' => [ __CLASS__, 'is_content_class' ] ]; } } unset( $attributes ); return wp_kses( $content, $allowed_html ); } public static function is_content_class( $value ) { $value = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' ); // Case-insensitive: pages in quirks mode match class selectors that way. return ! preg_match( '/(?:^|[\x09-\x0d ])directorist-(?:single-map|swiper-listing|swiper-related-listing|single-listing-slider-wrap)(?:$|[\x09-\x0d ])/i', $value ); } } Fields::register( new Description_Field() );
Save File
Cancel