formfields->get_field_type( 'textfield' )->render_field_inner( $field, $value, $context, $extra, $field_settings );
}
// @since 5.5.12
$value = apply_filters_ref_array( 'wpbdp_fields_text_value_for_rendering', array( $value, null, $field ) );
if ( $this->should_show_wysiwyg_editor( $field ) && $this->can_show_wysiwyg_editor() ) {
$html = $this->render_wysiwyg_editor( $field, $value );
} else {
$html = sprintf(
'',
'wpbdp-field-' . $field->get_id(),
apply_filters( 'wpbdp_fields_text_input_name', 'listingfields[' . $field->get_id() . ']', $field, $context, $extra, $field_settings ),
$value ? esc_attr( $value ) : ''
);
}
return $html;
}
private function should_show_wysiwyg_editor( $field ) {
return 'content' == $field->get_association() && $field->data( 'allow_html' ) && $field->data( 'wysiwyg_editor' );
}
private function can_show_wysiwyg_editor() {
if ( ! function_exists( 'wp_enqueue_editor' ) ) {
return false;
}
$wp_editor_path = ABSPATH . WPINC . '/class-wp-editor.php';
if ( ! file_exists( $wp_editor_path ) ) {
return false;
}
require_once $wp_editor_path;
if ( ! class_exists( '_WP_Editors' ) ) {
return false;
}
if ( ! method_exists( '_WP_Editors', 'parse_settings' ) || ! method_exists( '_WP_Editors', 'editor_settings' ) ) {
return false;
}
return true;
}
private function render_wysiwyg_editor( $field, $value ) {
wp_enqueue_editor();
// _WP_Editors::editor_settings() schedules editor_js() and enqueue_scripts()
// static class methods to print initialization for the core editor.
//
// We call editor_settings() to get the same settings used in the core editor,
// but we don't want the initialization code. If editor_js() and
// enqueue_scripts() are not already scheduled, we will remove them as
// action handlers a few lines below.
if ( is_admin() ) {
$action_name = 'admin_print_footer_scripts';
} else {
$action_name = 'wp_print_footer_scripts';
}
$is_editor_js_scheduled = has_action( $action_name, array( '_WP_Editors', 'editor_js' ) );
$is_enqueue_scripts_scheduled = has_action( $action_name, array( '_WP_Editors', 'enqueue_scripts' ) );
// _WP_Editors does not offers direct access to the TinyMCE and QuickTags
// arrays of settings.
add_filter( 'tiny_mce_before_init', array( $this, 'capture_tinymce_settings' ), 100, 2 );
add_filter( 'quicktags_settings', array( $this, 'capture_quicktag_settings' ), 100, 2 );
$settings = array(
'drag_drop_upload' => false,
'media_buttons' => false,
'quicktags' => ( (bool) $field->data( 'wysiwyg_images' ) ) ? true : false,
);
// Trick _WP_Editors into generating the array of TinyMCE and QuickTags
// settings for us, as it would be generated for the core editor.
$settings = _WP_Editors::parse_settings( 'wpbdp-field-' . $field->get_id(), $settings );
_WP_Editors::editor_settings( 'wpbdp-field-' . $field->get_id(), $settings );
// We are interested in this editor's settings only.
remove_filter( 'tiny_mce_before_init', array( $this, 'capture_tinymce_settings' ), 100 );
remove_filter( 'quicktags_settings', array( $this, 'capture_quicktag_settings' ), 100 );
// Removing _WP_Editors::editor_js if it was not previously configured
// as a handler.
if ( ! $is_editor_js_scheduled ) {
remove_action( $action_name, array( '_WP_Editors', 'editor_js' ), 50 );
}
// Removing _WP_Editors::enqueue_scripts() if it was not previously
// configured as a handler.
if ( ! $is_enqueue_scripts_scheduled ) {
remove_action( $action_name, array( '_WP_Editors', 'enqueue_scripts' ), 1 );
}
$html = sprintf(
'',
'wpbdp-field-' . $field->get_id(),
'listingfields[' . $field->get_id() . ']',
$value ? esc_attr( $value ) : ''
);
$html .= sprintf(
'',
'wpbdp-field-' . $field->get_id(),
$this->parse_tinymce_settings( $this->tinymce_settings ),
$this->parse_tinymce_settings( $this->quicktags_settings )
);
return $html;
}
public function capture_tinymce_settings( $settings, $editor_id ) {
$this->tinymce_settings = $settings;
return $settings;
}
public function capture_quicktag_settings( $settings, $editor_id ) {
$this->quicktags_settings = $settings;
return $settings;
}
/**
* A copy of _WP_Editors::_parse_init().
*
* @since 5.0
*/
private function parse_tinymce_settings( $init ) {
$options = '';
foreach ( $init as $key => $value ) {
if ( is_bool( $value ) ) {
$val = $value ? 'true' : 'false';
$options .= $key . ':' . $val . ',';
continue;
} elseif ( ! empty( $value ) && is_string( $value ) && (
( '{' == $value[0] && '}' == $value[ strlen( $value ) - 1 ] ) ||
( '[' == $value[0] && ']' == $value[ strlen( $value ) - 1 ] ) ||
preg_match( '/^\(?function ?\(/', $value ) ) ) {
$options .= $key . ':' . $value . ',';
continue;
}
$options .= $key . ':"' . $value . '",';
}
return '{' . trim( $options, ' ,' ) . '}';
}
public function get_supported_associations() {
return array( 'title', 'excerpt', 'content', 'meta' );
}
public function render_field_settings( &$field = null, $association = null ) {
$settings = array();
$settings['allow_html'][] = _x( 'Allow HTML input for this field?', 'form-fields admin', 'business-directory-plugin' );
$settings['allow_html'][] = 'data( 'allow_html' ) ? ' checked="checked"' : '' ) . ' />';
$settings['allow_iframes'][] = _x( 'Allow IFRAME tags in content?', 'form-fields admin', 'business-directory-plugin' );
$settings['allow_iframes'][] =
'
' .
'
' . _x( 'Enabling iframe support in your listings can allow users to execute arbitrary scripts on a page if they want, which can possibly infect your site with malware. We do NOT recommend using this setting UNLESS you are posting the listings yourself and have sole control over the content. Are you sure you want to enable this?', 'admin form-fields', 'business-directory-plugin' ) . '