WP_Widget_Custom_HTML
- Since
- 4.8.1
- Source
wp-includes/widgets/class-wp-widget-custom-html.php:17
Core class used to implement a Custom HTML widget.
Compatibility
- WordPress
- since 4.8.1
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 3
Every hook that fires from inside WP_Widget_Custom_HTML, in the order it appears in the class, grouped by the method that fires it.
WP_Widget_Custom_HTML::widget()
- apply_filters( widget_title )filter line 136
- apply_filters( widget_text )filter line 150
- apply_filters( widget_custom_html_content )filter line 161
Properties · 2
$registeredboolprotected- Whether or not the widget has been registered yet.
$default_instancearrayprotected- Default instance.
Methods · 9
- __construct()Sets up a new Custom HTML widget instance.
- _register_one()Add hooks for enqueueing assets when registering all widget instances of this widget class.
- _filter_gallery_shortcode_attrs()Filters gallery shortcode attributes.
- widget()Outputs the content for the current Custom HTML widget instance.
- update()Handles updating settings for the current Custom HTML widget instance.
- enqueue_admin_scripts()Loads the required scripts and styles for the widget control.
- form()Outputs the Custom HTML widget settings form.
- render_control_template_scripts()Render form template scripts.
- add_help_text()Add help text to widgets admin screen.
Source code
class WP_Widget_Custom_HTML extends WP_Widget { /** * Whether or not the widget has been registered yet. * * @since 4.9.0 * @var bool */ protected $registered = false; /** * Default instance. * * @since 4.8.1 * @var array */ protected $default_instance = array( 'title' => '', 'content' => '', ); /** * Sets up a new Custom HTML widget instance. * * @since 4.8.1 */ public function __construct() { $widget_ops = array( 'classname' => 'widget_custom_html', 'description' => __( 'Arbitrary HTML code.' ), 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, ); $control_ops = array( 'width' => 400, 'height' => 350, ); parent::__construct( 'custom_html', __( 'Custom HTML' ), $widget_ops, $control_ops ); } /** * Add hooks for enqueueing assets when registering all widget instances of this widget class. * * @since 4.9.0 * * @param int $number Optional. The unique order number of this widget instance * compared to other instances of the same class. Default -1. */ public function _register_one( $number = -1 ) { parent::_register_one( $number ); if ( $this->registered ) { return; } $this->registered = true; /* * Note that the widgets component in the customizer will also do * the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts(). */ add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) ); /* * Note that the widgets component in the customizer will also do * the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts(). */ add_action( 'admin_footer-widgets.php', array( 'WP_Widget_Custom_HTML', 'render_control_template_scripts' ) ); // Note this action is used to ensure the help text is added to the end. add_action( 'admin_head-widgets.php', array( 'WP_Widget_Custom_HTML', 'add_help_text' ) ); } /** * Filters gallery shortcode attributes. * * Prevents all of a site's attachments from being shown in a gallery displayed on a * non-singular template where a $post context is not available. * * @since 4.9.0 * * @param array $attrs Attributes.Changelog
Introduced in 4.8.1. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/widgets/class-wp-widget-custom-html.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.