-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix adding and deleting legacy widgets
- Loading branch information
1 parent
4e42e00
commit bb85cd8
Showing
3 changed files
with
213 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test Widgets | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-widgets | ||
*/ | ||
|
||
class test_widget extends WP_Widget { | ||
function __construct() { | ||
parent::__construct( | ||
'test_widget', | ||
'Test Widget', | ||
array( 'description' => 'Test widget.' ) | ||
); | ||
} | ||
|
||
public function widget( $args, $instance ) { | ||
$title = apply_filters( 'widget_title', $instance['title'] ); | ||
echo $args['before_widget']; | ||
if ( ! empty ( $title ) ) | ||
echo $args['before_title'] . $title . $args['after_title']; | ||
echo 'Hello Test Widget'; | ||
echo $args['after_widget']; | ||
} | ||
|
||
public function form( $instance ) { | ||
?> | ||
<p> | ||
<label for="<?php echo $this->get_field_id( 'title' ); ?>">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> | ||
<?php | ||
} | ||
|
||
public function update( $new_instance, $old_instance ) { | ||
$instance = array(); | ||
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; | ||
return $instance; | ||
} | ||
} | ||
|
||
function load_test_widget() { | ||
register_widget( 'test_widget' ); | ||
} | ||
|
||
add_action( 'widgets_init', 'load_test_widget' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters