ripristino widget per shortcode

This commit is contained in:
Gianluigi 2022-10-13 01:53:20 +02:00
parent 39033bf507
commit e206a83166
1 changed files with 57 additions and 0 deletions

57
incl/widgets.php Normal file
View File

@ -0,0 +1,57 @@
<?php
#
# widget per gli shortcode
#
class Widget_Shortcode extends WP_Widget {
/** Registrazione del widget */
public function __construct() {
parent::__construct(
'widget_shortcode', // Base ID
'Widget Shortcode', // Name
array( 'description' => __( 'Widget per l\'inserimento degli shortcode nelle sidebar', 'text_domain' ), ) // Args
);
}
/** Back-end del widget */
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
} else {
$title = __( 'blog-post-coauthors', 'text_domain' );
}
?>
<p>
<label for="<?php echo $this->get_field_name( 'title' ); ?>"><?php _e( 'Codice shortcode:' ); ?></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( $title ); ?>" />
</p>
<?php
}
/** Ripulisce i valori del widget man mano che vengono salvati */
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
/** Front-end del widget */
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
extract( $args );
$shortcode = do_shortcode('['.$title.']');
echo $shortcode;
echo $after_widget;
}
}
// class Widget_Shortcode
// Registra Widget_Shortcode
add_action( 'widgets_init', 'register_wdshortcode' );
function register_wdshortcode() {
register_widget( 'Widget_Shortcode' );
}