只需创建一个不过滤输入的小部件。这可能是您可以构建的具有用户输入的最简单的小部件。
这是我在插件中使用的小部件Magic Widgets.
/**
* Simplified variant of the native text widget class.
*
* @author Fuxia Scholz
* @version 1.0
*/
class Unfiltered_Text_Widget extends WP_Widget
{
/**
* @uses apply_filters( \'magic_widgets_name\' )
*/
public function __construct()
{
// You may change the name per filter.
// Use add_filter( \'magic_widgets_name\', \'your custom_filter\', 10, 1 );
$widgetname = apply_filters( \'magic_widgets_name\', \'Unfiltered Text\' );
parent::__construct(
\'unfiltered_text\'
, $widgetname
, array( \'description\' => \'Pure Markup\' )
, array( \'width\' => 300, \'height\' => 150 )
);
}
/**
* Output.
*
* @param array $args
* @param array $instance
* @return void
*/
public function widget( $args, $instance )
{
echo $instance[\'text\'];
}
/**
* Prepares the content. Not.
*
* @param array $new_instance New content
* @param array $old_instance Old content
* @return array New content
*/
public function update( $new_instance, $old_instance )
{
return $new_instance;
}
/**
* Backend form.
*
* @param array $instance
* @return void
*/
public function form( $instance )
{
$instance = wp_parse_args( (array) $instance, array( \'text\' => \'\' ) );
$text = format_to_edit($instance[\'text\']);
?>
<textarea class="widefat" rows="7" cols="20" id="<?php
echo $this->get_field_id( \'text\' );
?>" name="<?php
echo $this->get_field_name( \'text\' );
?>"><?php
echo $text;
?></textarea>
<?php
/* To enable the preview uncomment the following lines.
* Be aware: Invalid HTML may break the rest of the site and it
* may disable the option to repair the input text.
! empty ( $text )
and print \'<h3>Preview</h3><div style="border:3px solid #369;padding:10px">\'
. $instance[\'text\'] . \'</div>\';
/**/
?>
<?php
}
}
您可以将小部件注册到:
add_action( \'widgets_init\', \'register_unfiltered_text_widget\', 20 );
function register_unfiltered_text_widget()
{
register_widget( \'Unfiltered_Text_Widget\' );
}
现在您在
wp-admin/widgets.php
:
我只放了两个很酷的Youtube视频作为iframes和<hr>
进入小部件
输出: