acf_field_wysiwyg::render_field()publicACF 3.6

Create the HTML interface for your field

Метод класса: acf_field_wysiwyg{}

Хуки из метода

Возвращает

null. Ничего (null).

Использование

$acf_field_wysiwyg = new acf_field_wysiwyg();
$acf_field_wysiwyg->render_field( $field );
$field(массив) (обязательный)
An array holding all the field's data

Список изменений

С версии 3.6 Введена.

Код acf_field_wysiwyg::render_field() ACF 6.0.4

<?php
function render_field( $field ) {

	// enqueue
	acf_enqueue_uploader();

	// vars
	$id             = uniqid( 'acf-editor-' );
	$default_editor = 'html';
	$show_tabs      = true;

	// get height
	$height = acf_get_user_setting( 'wysiwyg_height', 300 );
	$height = max( $height, 300 ); // minimum height is 300

	// detect mode
	if ( ! user_can_richedit() ) {

		$show_tabs = false;

	} elseif ( $field['tabs'] == 'visual' ) {

		// case: visual tab only
		$default_editor = 'tinymce';
		$show_tabs      = false;

	} elseif ( $field['tabs'] == 'text' ) {

		// case: text tab only
		$show_tabs = false;

	} elseif ( wp_default_editor() == 'tinymce' ) {

		// case: both tabs
		$default_editor = 'tinymce';

	}

	// must be logged in to upload
	if ( ! current_user_can( 'upload_files' ) ) {

		$field['media_upload'] = 0;

	}

	// mode
	$switch_class = ( $default_editor === 'html' ) ? 'html-active' : 'tmce-active';

	// filter
	add_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 );

	$field['value'] = is_string( $field['value'] ) ? $field['value'] : '';
	$field['value'] = apply_filters( 'acf_the_editor_content', $field['value'], $default_editor );

	// attr
	$wrap = array(
		'id'           => 'wp-' . $id . '-wrap',
		'class'        => 'acf-editor-wrap wp-core-ui wp-editor-wrap ' . $switch_class,
		'data-toolbar' => $field['toolbar'],
	);

	// delay
	if ( $field['delay'] ) {
		$wrap['class'] .= ' delay';
	}

	// vars
	$textarea = acf_get_textarea_input(
		array(
			'id'    => $id,
			'class' => 'wp-editor-area',
			'name'  => $field['name'],
			'style' => $height ? "height:{$height}px;" : '',
			'value' => '%s',
		)
	);

	?>
<div <?php echo acf_esc_attrs( $wrap ); ?>>
	<div id="wp-<?php echo esc_attr( $id ); ?>-editor-tools" class="wp-editor-tools hide-if-no-js">
		<?php if ( $field['media_upload'] ) : ?>
		<div id="wp-<?php echo esc_attr( $id ); ?>-media-buttons" class="wp-media-buttons">
			<?php
			if ( ! function_exists( 'media_buttons' ) ) {
				require ABSPATH . 'wp-admin/includes/media.php';
			}
			do_action( 'media_buttons', $id );
			?>
		</div>
		<?php endif; ?>
			<?php if ( user_can_richedit() && $show_tabs ) : ?>
			<div class="wp-editor-tabs">
				<button id="<?php echo esc_attr( $id ); ?>-tmce" class="wp-switch-editor switch-tmce" data-wp-editor-id="<?php echo esc_attr( $id ); ?>" type="button"><?php echo __( 'Visual', 'acf' ); ?></button>
				<button id="<?php echo esc_attr( $id ); ?>-html" class="wp-switch-editor switch-html" data-wp-editor-id="<?php echo esc_attr( $id ); ?>" type="button"><?php echo _x( 'Text', 'Name for the Text editor tab (formerly HTML)', 'acf' ); ?></button>
			</div>
		<?php endif; ?>
	</div>
	<div id="wp-<?php echo esc_attr( $id ); ?>-editor-container" class="wp-editor-container">
			<?php if ( $field['delay'] ) : ?>
			<div class="acf-editor-toolbar"><?php _e( 'Click to initialize TinyMCE', 'acf' ); ?></div>
		<?php endif; ?>
			<?php printf( $textarea, $field['value'] ); ?>
	</div>
</div>
	<?php

}