name = 'text_editor'; $this->label = __( 'Text Editor', 'frontend-admin' ); $this->category = 'content'; $this->public = false; $this->defaults = array( 'tabs' => 'all', 'toolbar' => 'full', 'media_upload' => 1, 'default_value' => '', 'delay' => 0, 'maxlength' => '', 'show_remaining_characters' => 0, 'remaining_characters_text' => '', ); } /* * prepare_field() * * Prepares field setting prior to rendering field in form * * @param $field - an array holding all the field's data * @return $field * * @type action * @since 3.6 * @date 23/01/13 */ function prepare_field( $field ) { $field = array_merge( $this->defaults, $field ); if( feadmin_edit_mode() ){ $field['type'] = 'textarea'; $field['rows'] = 14; } return $field; } /** * Create the HTML interface for your field * * @param array $field An array holding all the field's data * * @type action * @since 3.6 * @date 23/01/13 */ function render_field( $field ) { $js_deps = include_once FEA_DIR . '/assets/build/frontend-text-editor/index.asset.php'; $js_url = FEA_URL . 'assets/build/frontend-text-editor/index.js'; if( is_array( $js_deps ) ){ $js_deps['dependencies'][] = 'wp-tinymce'; wp_enqueue_script( 'fea-text-editor', $js_url, $js_deps['dependencies'], $js_deps['version'], true ); wp_enqueue_style( 'fea-text-editor', FEA_URL . '/assets/build/frontend-text-editor.css', array(), $js_deps['version'] ); wp_add_inline_script( 'fea-text-editor', 'window.feaTextEditorSettings = ' . wp_json_encode( array( 'content' => $field['value'], //'toolbar' => $field['toolbar'], 'rows' => isset( $field['rows'] ) ? $field['rows'] : '', 'maxlength' => isset( $field['maxlength'] ) ? $field['maxlength'] : '', ) ) . ';', 'before' ); } // The saved rich text is the editor's working copy: it is printed as stored so the editor loads it unchanged. // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped echo '
'. $field['value'] .'
'; // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped } /* * render_field_settings() * * Create extra options for your field. This is rendered when editing a field. * The value of $field['name'] can be used (like bellow) to save extra data to the $field * * @type action * @since 3.6 * @date 23/01/13 * * @param $field - an array holding all the field's data */ function render_field_settings( $field ) { acf_render_field_setting( $field, array( 'label' => __( 'Default Value', 'frontend-admin' ), 'instructions' => __( 'Appears when creating a new post', 'frontend-admin' ), 'type' => 'textarea', 'name' => 'default_value', ) ); acf_render_field_setting( $field, array( 'label' => __( 'Delay initialization?', 'frontend-admin' ), 'instructions' => __( 'TinyMCE will not be initialized until field is clicked', 'frontend-admin' ), 'name' => 'delay', 'type' => 'true_false', 'ui' => 1, 'conditions' => array( 'field' => 'tabs', 'operator' => '!=', 'value' => 'text', ), ) ); // maxlength acf_render_field_setting( $field, array( 'label' => __( 'Character Limit', 'frontend-admin' ), 'instructions' => __( 'Leave blank for no limit', 'frontend-admin' ), 'type' => 'number', 'name' => 'maxlength', ) ); $this->remaining_characters_setting( $field ); } /** * This filter is applied to the $value after it is loaded from the db, and before it is returned to the template * * @type filter * @since 3.6 * @date 23/01/13 * * @param mixed $value The value which was loaded from the database * @param mixed $post_id The $post_id from which the value was loaded * @param array $field The field array holding all the field options * * @return mixed $value The modified value */ function format_value( $value, $post_id, $field ) { // Bail early if no value or not a string. if ( empty( $value ) || ! is_string( $value ) ) { return $value; } $value = apply_filters( 'acf_the_content', $value ); // Follow the_content function in /wp-includes/post-template.php return str_replace( ']]>', ']]>', $value ); } /** * validate_value * * Validates a field's value. Mirrors the client-side limit enforced in the * TinyMCE editor, counting visible (non-HTML) characters. * * @param (bool|string) Whether the value is vaid or not. * @param mixed $value The field value. * @param array $field The field array. * @param string $input The HTML input name. * @return (bool|string) */ function validate_value( $valid, $value, $field, $input ) { if ( ! empty( $field['maxlength'] ) && is_string( $value ) && acf_strlen( wp_strip_all_tags( $value ) ) > $field['maxlength'] ) { return sprintf( /* translators: %d: number */ __( 'Value must not exceed %d characters', 'frontend-admin' ), $field['maxlength'] ); } return $valid; } } endif; // class_exists check ?>