Edit File by line
/home/zeestwma/richards.../wp-inclu.../widgets
File: class-wp-widget-text.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Widget API: WP_Widget_Text class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Widgets
[5] Fix | Delete
* @since 4.4.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class used to implement a Text widget.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 2.8.0
[12] Fix | Delete
*
[13] Fix | Delete
* @see WP_Widget
[14] Fix | Delete
*/
[15] Fix | Delete
class WP_Widget_Text extends WP_Widget {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Whether or not the widget has been registered yet.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 4.8.1
[21] Fix | Delete
* @var bool
[22] Fix | Delete
*/
[23] Fix | Delete
protected $registered = false;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Sets up a new Text widget instance.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 2.8.0
[29] Fix | Delete
*/
[30] Fix | Delete
public function __construct() {
[31] Fix | Delete
$widget_ops = array(
[32] Fix | Delete
'classname' => 'widget_text',
[33] Fix | Delete
'description' => __( 'Arbitrary text.' ),
[34] Fix | Delete
'customize_selective_refresh' => true,
[35] Fix | Delete
'show_instance_in_rest' => true,
[36] Fix | Delete
);
[37] Fix | Delete
$control_ops = array(
[38] Fix | Delete
'width' => 400,
[39] Fix | Delete
'height' => 350,
[40] Fix | Delete
);
[41] Fix | Delete
parent::__construct( 'text', __( 'Text' ), $widget_ops, $control_ops );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Adds hooks for enqueueing assets when registering all widget instances of this widget class.
[46] Fix | Delete
*
[47] Fix | Delete
* @param int $number Optional. The unique order number of this widget instance
[48] Fix | Delete
* compared to other instances of the same class. Default -1.
[49] Fix | Delete
*/
[50] Fix | Delete
public function _register_one( $number = -1 ) {
[51] Fix | Delete
parent::_register_one( $number );
[52] Fix | Delete
if ( $this->registered ) {
[53] Fix | Delete
return;
[54] Fix | Delete
}
[55] Fix | Delete
$this->registered = true;
[56] Fix | Delete
[57] Fix | Delete
if ( $this->is_preview() ) {
[58] Fix | Delete
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/*
[62] Fix | Delete
* Note that the widgets component in the customizer will also do
[63] Fix | Delete
* the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
[64] Fix | Delete
*/
[65] Fix | Delete
add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
[66] Fix | Delete
[67] Fix | Delete
/*
[68] Fix | Delete
* Note that the widgets component in the customizer will also do
[69] Fix | Delete
* the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
[70] Fix | Delete
*/
[71] Fix | Delete
add_action( 'admin_footer-widgets.php', array( 'WP_Widget_Text', 'render_control_template_scripts' ) );
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Determines whether a given instance is legacy and should bypass using TinyMCE.
[76] Fix | Delete
*
[77] Fix | Delete
* @since 4.8.1
[78] Fix | Delete
*
[79] Fix | Delete
* @param array $instance {
[80] Fix | Delete
* Instance data.
[81] Fix | Delete
*
[82] Fix | Delete
* @type string $text Content.
[83] Fix | Delete
* @type bool|string $filter Whether autop or content filters should apply.
[84] Fix | Delete
* @type bool $legacy Whether widget is in legacy mode.
[85] Fix | Delete
* }
[86] Fix | Delete
* @return bool Whether Text widget instance contains legacy data.
[87] Fix | Delete
*/
[88] Fix | Delete
public function is_legacy_instance( $instance ) {
[89] Fix | Delete
[90] Fix | Delete
// Legacy mode when not in visual mode.
[91] Fix | Delete
if ( isset( $instance['visual'] ) ) {
[92] Fix | Delete
return ! $instance['visual'];
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
// Or, the widget has been added/updated in 4.8.0 then filter prop is 'content' and it is no longer legacy.
[96] Fix | Delete
if ( isset( $instance['filter'] ) && 'content' === $instance['filter'] ) {
[97] Fix | Delete
return false;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
// If the text is empty, then nothing is preventing migration to TinyMCE.
[101] Fix | Delete
if ( empty( $instance['text'] ) ) {
[102] Fix | Delete
return false;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
$wpautop = ! empty( $instance['filter'] );
[106] Fix | Delete
$has_line_breaks = ( str_contains( trim( $instance['text'] ), "\n" ) );
[107] Fix | Delete
[108] Fix | Delete
// If auto-paragraphs are not enabled and there are line breaks, then ensure legacy mode.
[109] Fix | Delete
if ( ! $wpautop && $has_line_breaks ) {
[110] Fix | Delete
return true;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
// If an HTML comment is present, assume legacy mode.
[114] Fix | Delete
if ( str_contains( $instance['text'], '<!--' ) ) {
[115] Fix | Delete
return true;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
// In the rare case that DOMDocument is not available we cannot reliably sniff content and so we assume legacy.
[119] Fix | Delete
if ( ! class_exists( 'DOMDocument' ) ) {
[120] Fix | Delete
// @codeCoverageIgnoreStart
[121] Fix | Delete
return true;
[122] Fix | Delete
// @codeCoverageIgnoreEnd
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
$doc = new DOMDocument();
[126] Fix | Delete
[127] Fix | Delete
// Suppress warnings generated by loadHTML.
[128] Fix | Delete
$errors = libxml_use_internal_errors( true );
[129] Fix | Delete
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
[130] Fix | Delete
@$doc->loadHTML(
[131] Fix | Delete
sprintf(
[132] Fix | Delete
'<!DOCTYPE html><html><head><meta charset="%s"></head><body>%s</body></html>',
[133] Fix | Delete
esc_attr( get_bloginfo( 'charset' ) ),
[134] Fix | Delete
$instance['text']
[135] Fix | Delete
)
[136] Fix | Delete
);
[137] Fix | Delete
libxml_use_internal_errors( $errors );
[138] Fix | Delete
[139] Fix | Delete
$body = $doc->getElementsByTagName( 'body' )->item( 0 );
[140] Fix | Delete
[141] Fix | Delete
// See $allowedposttags.
[142] Fix | Delete
$safe_elements_attributes = array(
[143] Fix | Delete
'strong' => array(),
[144] Fix | Delete
'em' => array(),
[145] Fix | Delete
'b' => array(),
[146] Fix | Delete
'i' => array(),
[147] Fix | Delete
'u' => array(),
[148] Fix | Delete
's' => array(),
[149] Fix | Delete
'ul' => array(),
[150] Fix | Delete
'ol' => array(),
[151] Fix | Delete
'li' => array(),
[152] Fix | Delete
'hr' => array(),
[153] Fix | Delete
'abbr' => array(),
[154] Fix | Delete
'acronym' => array(),
[155] Fix | Delete
'code' => array(),
[156] Fix | Delete
'dfn' => array(),
[157] Fix | Delete
'a' => array(
[158] Fix | Delete
'href' => true,
[159] Fix | Delete
),
[160] Fix | Delete
'img' => array(
[161] Fix | Delete
'src' => true,
[162] Fix | Delete
'alt' => true,
[163] Fix | Delete
),
[164] Fix | Delete
);
[165] Fix | Delete
$safe_empty_elements = array( 'img', 'hr', 'iframe' );
[166] Fix | Delete
[167] Fix | Delete
foreach ( $body->getElementsByTagName( '*' ) as $element ) {
[168] Fix | Delete
/** @var DOMElement $element */
[169] Fix | Delete
$tag_name = strtolower( $element->nodeName );
[170] Fix | Delete
[171] Fix | Delete
// If the element is not safe, then the instance is legacy.
[172] Fix | Delete
if ( ! isset( $safe_elements_attributes[ $tag_name ] ) ) {
[173] Fix | Delete
return true;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
// If the element is not safely empty and it has empty contents, then legacy mode.
[177] Fix | Delete
if ( ! in_array( $tag_name, $safe_empty_elements, true ) && '' === trim( $element->textContent ) ) {
[178] Fix | Delete
return true;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
// If an attribute is not recognized as safe, then the instance is legacy.
[182] Fix | Delete
foreach ( $element->attributes as $attribute ) {
[183] Fix | Delete
/** @var DOMAttr $attribute */
[184] Fix | Delete
$attribute_name = strtolower( $attribute->nodeName );
[185] Fix | Delete
[186] Fix | Delete
if ( ! isset( $safe_elements_attributes[ $tag_name ][ $attribute_name ] ) ) {
[187] Fix | Delete
return true;
[188] Fix | Delete
}
[189] Fix | Delete
}
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
// Otherwise, the text contains no elements/attributes that TinyMCE could drop, and therefore the widget does not need legacy mode.
[193] Fix | Delete
return false;
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
/**
[197] Fix | Delete
* Filters gallery shortcode attributes.
[198] Fix | Delete
*
[199] Fix | Delete
* Prevents all of a site's attachments from being shown in a gallery displayed on a
[200] Fix | Delete
* non-singular template where a $post context is not available.
[201] Fix | Delete
*
[202] Fix | Delete
* @since 4.9.0
[203] Fix | Delete
*
[204] Fix | Delete
* @param array $attrs Attributes.
[205] Fix | Delete
* @return array Attributes.
[206] Fix | Delete
*/
[207] Fix | Delete
public function _filter_gallery_shortcode_attrs( $attrs ) {
[208] Fix | Delete
if ( ! is_singular() && empty( $attrs['id'] ) && empty( $attrs['include'] ) ) {
[209] Fix | Delete
$attrs['id'] = -1;
[210] Fix | Delete
}
[211] Fix | Delete
return $attrs;
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* Outputs the content for the current Text widget instance.
[216] Fix | Delete
*
[217] Fix | Delete
* @since 2.8.0
[218] Fix | Delete
*
[219] Fix | Delete
* @global WP_Post $post Global post object.
[220] Fix | Delete
*
[221] Fix | Delete
* @param array $args Display arguments including 'before_title', 'after_title',
[222] Fix | Delete
* 'before_widget', and 'after_widget'.
[223] Fix | Delete
* @param array $instance Settings for the current Text widget instance.
[224] Fix | Delete
*/
[225] Fix | Delete
public function widget( $args, $instance ) {
[226] Fix | Delete
global $post;
[227] Fix | Delete
[228] Fix | Delete
$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
[229] Fix | Delete
[230] Fix | Delete
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
[231] Fix | Delete
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
[232] Fix | Delete
[233] Fix | Delete
$text = ! empty( $instance['text'] ) ? $instance['text'] : '';
[234] Fix | Delete
$is_visual_text_widget = ( ! empty( $instance['visual'] ) && ! empty( $instance['filter'] ) );
[235] Fix | Delete
[236] Fix | Delete
// In 4.8.0 only, visual Text widgets get filter=content, without visual prop; upgrade instance props just-in-time.
[237] Fix | Delete
if ( ! $is_visual_text_widget ) {
[238] Fix | Delete
$is_visual_text_widget = ( isset( $instance['filter'] ) && 'content' === $instance['filter'] );
[239] Fix | Delete
}
[240] Fix | Delete
if ( $is_visual_text_widget ) {
[241] Fix | Delete
$instance['filter'] = true;
[242] Fix | Delete
$instance['visual'] = true;
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
/*
[246] Fix | Delete
* Suspend legacy plugin-supplied do_shortcode() for 'widget_text' filter for the visual Text widget to prevent
[247] Fix | Delete
* shortcodes being processed twice. Now do_shortcode() is added to the 'widget_text_content' filter in core itself
[248] Fix | Delete
* and it applies after wpautop() to prevent corrupting HTML output added by the shortcode. When do_shortcode() is
[249] Fix | Delete
* added to 'widget_text_content' then do_shortcode() will be manually called when in legacy mode as well.
[250] Fix | Delete
*/
[251] Fix | Delete
$widget_text_do_shortcode_priority = has_filter( 'widget_text', 'do_shortcode' );
[252] Fix | Delete
$should_suspend_legacy_shortcode_support = ( $is_visual_text_widget && false !== $widget_text_do_shortcode_priority );
[253] Fix | Delete
if ( $should_suspend_legacy_shortcode_support ) {
[254] Fix | Delete
remove_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority );
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
// Override global $post so filters (and shortcodes) apply in a consistent context.
[258] Fix | Delete
$original_post = $post;
[259] Fix | Delete
if ( is_singular() ) {
[260] Fix | Delete
// Make sure post is always the queried object on singular queries (not from another sub-query that failed to clean up the global $post).
[261] Fix | Delete
$post = get_queried_object();
[262] Fix | Delete
} else {
[263] Fix | Delete
// Nullify the $post global during widget rendering to prevent shortcodes from running with the unexpected context on archive queries.
[264] Fix | Delete
$post = null;
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
// Prevent dumping out all attachments from the media library.
[268] Fix | Delete
add_filter( 'shortcode_atts_gallery', array( $this, '_filter_gallery_shortcode_attrs' ) );
[269] Fix | Delete
[270] Fix | Delete
/**
[271] Fix | Delete
* Filters the content of the Text widget.
[272] Fix | Delete
*
[273] Fix | Delete
* @since 2.3.0
[274] Fix | Delete
* @since 4.4.0 Added the `$widget` parameter.
[275] Fix | Delete
* @since 4.8.1 The `$widget` param may now be a `WP_Widget_Custom_HTML` object in addition to a `WP_Widget_Text` object.
[276] Fix | Delete
*
[277] Fix | Delete
* @param string $text The widget content.
[278] Fix | Delete
* @param array $instance Array of settings for the current widget.
[279] Fix | Delete
* @param WP_Widget_Text|WP_Widget_Custom_HTML $widget Current text or HTML widget instance.
[280] Fix | Delete
*/
[281] Fix | Delete
$text = apply_filters( 'widget_text', $text, $instance, $this );
[282] Fix | Delete
[283] Fix | Delete
if ( $is_visual_text_widget ) {
[284] Fix | Delete
[285] Fix | Delete
/**
[286] Fix | Delete
* Filters the content of the Text widget to apply changes expected from the visual (TinyMCE) editor.
[287] Fix | Delete
*
[288] Fix | Delete
* By default a subset of the_content filters are applied, including wpautop and wptexturize.
[289] Fix | Delete
*
[290] Fix | Delete
* @since 4.8.0
[291] Fix | Delete
*
[292] Fix | Delete
* @param string $text The widget content.
[293] Fix | Delete
* @param array $instance Array of settings for the current widget.
[294] Fix | Delete
* @param WP_Widget_Text $widget Current Text widget instance.
[295] Fix | Delete
*/
[296] Fix | Delete
$text = apply_filters( 'widget_text_content', $text, $instance, $this );
[297] Fix | Delete
} else {
[298] Fix | Delete
// Now in legacy mode, add paragraphs and line breaks when checkbox is checked.
[299] Fix | Delete
if ( ! empty( $instance['filter'] ) ) {
[300] Fix | Delete
$text = wpautop( $text );
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
/*
[304] Fix | Delete
* Manually do shortcodes on the content when the core-added filter is present. It is added by default
[305] Fix | Delete
* in core by adding do_shortcode() to the 'widget_text_content' filter to apply after wpautop().
[306] Fix | Delete
* Since the legacy Text widget runs wpautop() after 'widget_text' filters are applied, the widget in
[307] Fix | Delete
* legacy mode here manually applies do_shortcode() on the content unless the default
[308] Fix | Delete
* core filter for 'widget_text_content' has been removed, or if do_shortcode() has already
[309] Fix | Delete
* been applied via a plugin adding do_shortcode() to 'widget_text' filters.
[310] Fix | Delete
*/
[311] Fix | Delete
if ( has_filter( 'widget_text_content', 'do_shortcode' ) && ! $widget_text_do_shortcode_priority ) {
[312] Fix | Delete
if ( ! empty( $instance['filter'] ) ) {
[313] Fix | Delete
$text = shortcode_unautop( $text );
[314] Fix | Delete
}
[315] Fix | Delete
$text = do_shortcode( $text );
[316] Fix | Delete
}
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
// Restore post global.
[320] Fix | Delete
$post = $original_post;
[321] Fix | Delete
remove_filter( 'shortcode_atts_gallery', array( $this, '_filter_gallery_shortcode_attrs' ) );
[322] Fix | Delete
[323] Fix | Delete
// Undo suspension of legacy plugin-supplied shortcode handling.
[324] Fix | Delete
if ( $should_suspend_legacy_shortcode_support ) {
[325] Fix | Delete
add_filter( 'widget_text', 'do_shortcode', $widget_text_do_shortcode_priority );
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
echo $args['before_widget'];
[329] Fix | Delete
if ( ! empty( $title ) ) {
[330] Fix | Delete
echo $args['before_title'] . $title . $args['after_title'];
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
$text = preg_replace_callback( '#<(video|iframe|object|embed)\s[^>]*>#i', array( $this, 'inject_video_max_width_style' ), $text );
[334] Fix | Delete
[335] Fix | Delete
?>
[336] Fix | Delete
<div class="textwidget"><?php echo $text; ?></div>
[337] Fix | Delete
<?php
[338] Fix | Delete
echo $args['after_widget'];
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Injects max-width and removes height for videos too constrained to fit inside sidebars on frontend.
[343] Fix | Delete
*
[344] Fix | Delete
* @since 4.9.0
[345] Fix | Delete
*
[346] Fix | Delete
* @see WP_Widget_Media_Video::inject_video_max_width_style()
[347] Fix | Delete
*
[348] Fix | Delete
* @param array $matches Pattern matches from preg_replace_callback.
[349] Fix | Delete
* @return string HTML Output.
[350] Fix | Delete
*/
[351] Fix | Delete
public function inject_video_max_width_style( $matches ) {
[352] Fix | Delete
$html = $matches[0];
[353] Fix | Delete
$html = preg_replace( '/\sheight="\d+"/', '', $html );
[354] Fix | Delete
$html = preg_replace( '/\swidth="\d+"/', '', $html );
[355] Fix | Delete
$html = preg_replace( '/(?<=width:)\s*\d+px(?=;?)/', '100%', $html );
[356] Fix | Delete
return $html;
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
/**
[360] Fix | Delete
* Handles updating settings for the current Text widget instance.
[361] Fix | Delete
*
[362] Fix | Delete
* @since 2.8.0
[363] Fix | Delete
*
[364] Fix | Delete
* @param array $new_instance New settings for this instance as input by the user via
[365] Fix | Delete
* WP_Widget::form().
[366] Fix | Delete
* @param array $old_instance Old settings for this instance.
[367] Fix | Delete
* @return array Settings to save or bool false to cancel saving.
[368] Fix | Delete
*/
[369] Fix | Delete
public function update( $new_instance, $old_instance ) {
[370] Fix | Delete
$new_instance = wp_parse_args(
[371] Fix | Delete
$new_instance,
[372] Fix | Delete
array(
[373] Fix | Delete
'title' => '',
[374] Fix | Delete
'text' => '',
[375] Fix | Delete
'filter' => false, // For back-compat.
[376] Fix | Delete
'visual' => null, // Must be explicitly defined.
[377] Fix | Delete
)
[378] Fix | Delete
);
[379] Fix | Delete
[380] Fix | Delete
$instance = $old_instance;
[381] Fix | Delete
[382] Fix | Delete
$instance['title'] = sanitize_text_field( $new_instance['title'] );
[383] Fix | Delete
if ( current_user_can( 'unfiltered_html' ) ) {
[384] Fix | Delete
$instance['text'] = $new_instance['text'];
[385] Fix | Delete
} else {
[386] Fix | Delete
$instance['text'] = wp_kses_post( $new_instance['text'] );
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
$instance['filter'] = ! empty( $new_instance['filter'] );
[390] Fix | Delete
[391] Fix | Delete
// Upgrade 4.8.0 format.
[392] Fix | Delete
if ( isset( $old_instance['filter'] ) && 'content' === $old_instance['filter'] ) {
[393] Fix | Delete
$instance['visual'] = true;
[394] Fix | Delete
}
[395] Fix | Delete
if ( 'content' === $new_instance['filter'] ) {
[396] Fix | Delete
$instance['visual'] = true;
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
if ( isset( $new_instance['visual'] ) ) {
[400] Fix | Delete
$instance['visual'] = ! empty( $new_instance['visual'] );
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
// Filter is always true in visual mode.
[404] Fix | Delete
if ( ! empty( $instance['visual'] ) ) {
[405] Fix | Delete
$instance['filter'] = true;
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
return $instance;
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
/**
[412] Fix | Delete
* Enqueues preview scripts.
[413] Fix | Delete
*
[414] Fix | Delete
* These scripts normally are enqueued just-in-time when a playlist shortcode is used.
[415] Fix | Delete
* However, in the customizer, a playlist shortcode may be used in a text widget and
[416] Fix | Delete
* dynamically added via selective refresh, so it is important to unconditionally enqueue them.
[417] Fix | Delete
*
[418] Fix | Delete
* @since 4.9.3
[419] Fix | Delete
*/
[420] Fix | Delete
public function enqueue_preview_scripts() {
[421] Fix | Delete
require_once dirname( __DIR__ ) . '/media.php';
[422] Fix | Delete
[423] Fix | Delete
wp_playlist_scripts( 'audio' );
[424] Fix | Delete
wp_playlist_scripts( 'video' );
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
/**
[428] Fix | Delete
* Loads the required scripts and styles for the widget control.
[429] Fix | Delete
*
[430] Fix | Delete
* @since 4.8.0
[431] Fix | Delete
*/
[432] Fix | Delete
public function enqueue_admin_scripts() {
[433] Fix | Delete
wp_enqueue_editor();
[434] Fix | Delete
wp_enqueue_media();
[435] Fix | Delete
wp_enqueue_script( 'text-widgets' );
[436] Fix | Delete
wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
[437] Fix | Delete
wp_add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' );
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
/**
[441] Fix | Delete
* Outputs the Text widget settings form.
[442] Fix | Delete
*
[443] Fix | Delete
* @since 2.8.0
[444] Fix | Delete
* @since 4.8.0 Form only contains hidden inputs which are synced with JS template.
[445] Fix | Delete
* @since 4.8.1 Restored original form to be displayed when in legacy mode.
[446] Fix | Delete
*
[447] Fix | Delete
* @see WP_Widget_Text::render_control_template_scripts()
[448] Fix | Delete
* @see _WP_Editors::editor()
[449] Fix | Delete
*
[450] Fix | Delete
* @param array $instance Current settings.
[451] Fix | Delete
*/
[452] Fix | Delete
public function form( $instance ) {
[453] Fix | Delete
$instance = wp_parse_args(
[454] Fix | Delete
(array) $instance,
[455] Fix | Delete
array(
[456] Fix | Delete
'title' => '',
[457] Fix | Delete
'text' => '',
[458] Fix | Delete
)
[459] Fix | Delete
);
[460] Fix | Delete
?>
[461] Fix | Delete
<?php if ( ! $this->is_legacy_instance( $instance ) ) : ?>
[462] Fix | Delete
<?php
[463] Fix | Delete
[464] Fix | Delete
if ( user_can_richedit() ) {
[465] Fix | Delete
add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
[466] Fix | Delete
$default_editor = 'tinymce';
[467] Fix | Delete
} else {
[468] Fix | Delete
$default_editor = 'html';
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
/** This filter is documented in wp-includes/class-wp-editor.php */
[472] Fix | Delete
$text = apply_filters( 'the_editor_content', $instance['text'], $default_editor );
[473] Fix | Delete
[474] Fix | Delete
// Reset filter addition.
[475] Fix | Delete
if ( user_can_richedit() ) {
[476] Fix | Delete
remove_filter( 'the_editor_content', 'format_for_editor' );
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
// Prevent premature closing of textarea in case format_for_editor() didn't apply or the_editor_content filter did a wrong thing.
[480] Fix | Delete
$escaped_text = preg_replace( '#</textarea#i', '&lt;/textarea', $text );
[481] Fix | Delete
[482] Fix | Delete
?>
[483] Fix | Delete
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" class="title sync-input" type="hidden" value="<?php echo esc_attr( $instance['title'] ); ?>">
[484] Fix | Delete
<textarea id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>" class="text sync-input" hidden><?php echo $escaped_text; ?></textarea>
[485] Fix | Delete
<input id="<?php echo $this->get_field_id( 'filter' ); ?>" name="<?php echo $this->get_field_name( 'filter' ); ?>" class="filter sync-input" type="hidden" value="on">
[486] Fix | Delete
<input id="<?php echo $this->get_field_id( 'visual' ); ?>" name="<?php echo $this->get_field_name( 'visual' ); ?>" class="visual sync-input" type="hidden" value="on">
[487] Fix | Delete
<?php else : ?>
[488] Fix | Delete
<input id="<?php echo $this->get_field_id( 'visual' ); ?>" name="<?php echo $this->get_field_name( 'visual' ); ?>" class="visual" type="hidden" value="">
[489] Fix | Delete
<p>
[490] Fix | Delete
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
[491] Fix | Delete
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
[492] Fix | Delete
</p>
[493] Fix | Delete
<?php
[494] Fix | Delete
if ( ! isset( $instance['visual'] ) ) {
[495] Fix | Delete
$widget_info_message = __( 'This widget may contain code that may work better in the &#8220;Custom HTML&#8221; widget. How about trying that widget instead?' );
[496] Fix | Delete
} else {
[497] Fix | Delete
$widget_info_message = __( 'This widget may have contained code that may work better in the &#8220;Custom HTML&#8221; widget. If you have not yet, how about trying that widget instead?' );
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function