2009-03-16 23:02:40 +01:00
|
|
|
<?php
|
2009-03-18 03:43:45 +01:00
|
|
|
/**
|
2015-09-22 15:36:25 +02:00
|
|
|
* Widget API: Default core widgets
|
2009-03-16 23:02:40 +01:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Widgets
|
2015-09-22 15:36:25 +02:00
|
|
|
* @since 2.8.0
|
2009-03-16 23:02:40 +01:00
|
|
|
*/
|
|
|
|
|
2015-09-22 15:36:25 +02:00
|
|
|
/** WP_Widget_Pages class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-pages.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_Links class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-links.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_Search class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-search.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_Archives class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-archives.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!
Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.
Built from https://develop.svn.wordpress.org/trunk@40640
git-svn-id: http://core.svn.wordpress.org/trunk@40501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-05-11 23:11:44 +02:00
|
|
|
/** WP_Widget_Media class */
|
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-media.php' );
|
|
|
|
|
|
|
|
/** WP_Widget_Media_Audio class */
|
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-media-audio.php' );
|
|
|
|
|
|
|
|
/** WP_Widget_Media_Image class */
|
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-media-image.php' );
|
|
|
|
|
|
|
|
/** WP_Widget_Media_Video class */
|
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-media-video.php' );
|
|
|
|
|
|
|
|
/** WP_Widget_Meta class */
|
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-meta.php' );
|
|
|
|
|
2015-09-22 15:36:25 +02:00
|
|
|
/** WP_Widget_Meta class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-meta.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_Calendar class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-calendar.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_Text class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-text.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_Categories class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-categories.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_Recent_Posts class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-recent-posts.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_Recent_Comments class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-recent-comments.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_RSS class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-rss.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Widget_Tag_Cloud class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-tag-cloud.php' );
|
2015-09-22 15:36:25 +02:00
|
|
|
|
|
|
|
/** WP_Nav_Menu_Widget class */
|
2015-09-01 15:49:21 +02:00
|
|
|
require_once( ABSPATH . WPINC . '/widgets/class-wp-nav-menu-widget.php' );
|
2017-07-14 09:41:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Core class used to implement a Custom HTML widget.
|
|
|
|
*
|
|
|
|
* Note that this class is only located in this file in the 4.8 branch
|
|
|
|
* for the sake of automatic updates. In 4.9 and above, it is located at
|
|
|
|
* `wp-includes/widgets/class-wp-widget-custom-html.php`.
|
|
|
|
*
|
|
|
|
* @since 4.8.1
|
|
|
|
*
|
|
|
|
* @see WP_Widget
|
|
|
|
*/
|
|
|
|
class WP_Widget_Custom_HTML extends WP_Widget {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
);
|
|
|
|
$control_ops = array(
|
|
|
|
'width' => 400,
|
|
|
|
'height' => 350,
|
|
|
|
);
|
|
|
|
parent::__construct( 'custom_html', __( 'Custom HTML' ), $widget_ops, $control_ops );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the content for the current Custom HTML widget instance.
|
|
|
|
*
|
|
|
|
* @since 4.8.1
|
|
|
|
*
|
|
|
|
* @param array $args Display arguments including 'before_title', 'after_title',
|
|
|
|
* 'before_widget', and 'after_widget'.
|
|
|
|
* @param array $instance Settings for the current Custom HTML widget instance.
|
|
|
|
*/
|
|
|
|
public function widget( $args, $instance ) {
|
|
|
|
|
|
|
|
$instance = array_merge( $this->default_instance, $instance );
|
|
|
|
|
|
|
|
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
|
|
|
|
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
|
|
|
|
|
2017-07-19 00:19:36 +02:00
|
|
|
/** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
|
|
|
|
$content = apply_filters( 'widget_text', $instance['content'], $instance, $this );
|
2017-07-14 09:41:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters the content of the Custom HTML widget.
|
|
|
|
*
|
|
|
|
* @since 4.8.1
|
|
|
|
*
|
|
|
|
* @param string $content The widget content.
|
|
|
|
* @param array $instance Array of settings for the current widget.
|
|
|
|
* @param WP_Widget_Custom_HTML $this Current Custom HTML widget instance.
|
|
|
|
*/
|
|
|
|
$content = apply_filters( 'widget_custom_html_content', $content, $instance, $this );
|
|
|
|
|
2017-07-21 23:17:37 +02:00
|
|
|
// Inject the Text widget's container class name alongside this widget's class name for theme styling compatibility.
|
|
|
|
$args['before_widget'] = preg_replace( '/(?<=\sclass=["\'])/', 'widget_text ', $args['before_widget'] );
|
|
|
|
|
2017-07-14 09:41:33 +02:00
|
|
|
echo $args['before_widget'];
|
|
|
|
if ( ! empty( $title ) ) {
|
|
|
|
echo $args['before_title'] . $title . $args['after_title'];
|
|
|
|
}
|
2017-07-21 23:17:37 +02:00
|
|
|
echo '<div class="textwidget custom-html-widget">'; // The textwidget class is for theme styling compatibility.
|
2017-07-14 09:41:33 +02:00
|
|
|
echo $content;
|
2017-07-21 23:17:37 +02:00
|
|
|
echo '</div>';
|
2017-07-14 09:41:33 +02:00
|
|
|
echo $args['after_widget'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles updating settings for the current Custom HTML widget instance.
|
|
|
|
*
|
|
|
|
* @since 4.8.1
|
|
|
|
*
|
|
|
|
* @param array $new_instance New settings for this instance as input by the user via
|
|
|
|
* WP_Widget::form().
|
|
|
|
* @param array $old_instance Old settings for this instance.
|
|
|
|
* @return array Settings to save or bool false to cancel saving.
|
|
|
|
*/
|
|
|
|
public function update( $new_instance, $old_instance ) {
|
|
|
|
$instance = array_merge( $this->default_instance, $old_instance );
|
|
|
|
$instance['title'] = sanitize_text_field( $new_instance['title'] );
|
|
|
|
if ( current_user_can( 'unfiltered_html' ) ) {
|
|
|
|
$instance['content'] = $new_instance['content'];
|
|
|
|
} else {
|
|
|
|
$instance['content'] = wp_kses_post( $new_instance['content'] );
|
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the Custom HTML widget settings form.
|
|
|
|
*
|
|
|
|
* @since 4.8.1
|
|
|
|
*
|
|
|
|
* @param array $instance Current instance.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
public function form( $instance ) {
|
|
|
|
$instance = wp_parse_args( (array) $instance, $this->default_instance );
|
|
|
|
?>
|
|
|
|
<p>
|
|
|
|
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
|
|
|
|
<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'] ); ?>"/>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
<label for="<?php echo $this->get_field_id( 'content' ); ?>"><?php _e( 'Content:' ); ?></label>
|
|
|
|
<textarea class="widefat code" rows="16" cols="20" id="<?php echo $this->get_field_id( 'content' ); ?>" name="<?php echo $this->get_field_name( 'content' ); ?>"><?php echo esc_textarea( $instance['content'] ); ?></textarea>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<?php if ( ! current_user_can( 'unfiltered_html' ) ) : ?>
|
|
|
|
<?php
|
|
|
|
$probably_unsafe_html = array( 'script', 'iframe', 'form', 'input', 'style' );
|
|
|
|
$allowed_html = wp_kses_allowed_html( 'post' );
|
|
|
|
$disallowed_html = array_diff( $probably_unsafe_html, array_keys( $allowed_html ) );
|
|
|
|
?>
|
|
|
|
<?php if ( ! empty( $disallowed_html ) ) : ?>
|
|
|
|
<p>
|
|
|
|
<?php _e( 'Some HTML tags are not permitted, including:' ); ?>
|
|
|
|
<code><?php echo join( '</code>, <code>', $disallowed_html ); ?></code>
|
|
|
|
</p>
|
|
|
|
<?php endif; ?>
|
|
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|