我有一个我正在使用的小部件,它允许用户输入一个短代码,并将其显示在侧栏中。但它不正常工作。我可以输入短代码,但它没有输出。此外,它还接缝以剥离[],如果包含size=35,则在点击保存按钮后将剥离35。以下是部分代码:
//Set Shortcode 1 title
$sc1title = apply_filters( \'Shortcode 1 Title\', $instance[\'sc1title\'] );
//Display Shortcode 1 title
if ( ! empty( $sc1title ) )
echo $args[\'before_sc1title\'] . "<h3>$sc1title</h3>" . $args[\'after_sc1title\'];
//Do Shortcode 1
//echo do_shortcode(\'sc1\');
//echo do_shortcode($this->shortcodes[$instance[\'sc1\']]);
echo do_shortcode(\'[sc1]\');
echo "<br>";
//Set Shortcode 2 title
$sc2title = apply_filters( \'Shortcode 2 Title\', $instance[\'sc2title\'] );
//Display Shortcode 2 title
if ( ! empty( $sc2title ) )
echo $args[\'before_sc1title\'] . "<h3>$sc2title</h3>" . $args[\'after_sc1title\'];
//Do Shortcode 1
//echo do_shortcode(\'sc2\');
echo do_shortcode($this->shortcodes[$instance[\'sc2\']]);
echo $args[\'after_widget\'];
// Display after widget code
echo $after_widget;
}
// Update the widget settings.
public function update( $new_instance, $old_instance ) {
$instance[\'title\'] = strip_tags( stripslashes($new_instance[\'title\']) );
$instance[\'mtitle\'] = strip_tags( stripslashes($new_instance[\'mtitle\']) );
$instance[\'nav_menu\'] = (int) $new_instance[\'nav_menu\'];
$instance[\'sc1title\'] = strip_tags( stripslashes($new_instance[\'sc1title\']) );
$instance[\'sc1\'] = strip_tags( stripslashes($new_instance[\'sc1\']) );
$instance[\'sc2title\'] = strip_tags( stripslashes($new_instance[\'sc2title\']) );
$instance[\'sc2\'] = strip_tags( stripslashes($new_instance[\'sc2\']) );
return $instance;
}
// Displays the form on the widget page
public function form( $instance ) {
$title = isset( $instance[\'title\'] ) ? $instance[\'title\'] : \'\';
$nav_menu = isset( $instance[\'nav_menu\'] ) ? $instance[\'nav_menu\'] : \'\';
$mtitle = isset( $instance[\'mtitle\'] ) ? $instance[\'mtitle\'] : \'\';
$sc1title = isset( $instance[\'sc1title\'] ) ? $instance[\'sc1title\'] : \'\';
$sc1 = isset( $instance[\'sc1\'] ) ? $instance[\'sc1\'] : \'\';
$sc2title = isset( $instance[\'sc2title\'] ) ? $instance[\'sc2title\'] : \'\';
$sc2 = isset( $instance[\'sc2\'] ) ? $instance[\'sc2\'] : \'\';
// Get menus
$menus = wp_get_nav_menus( array( \'orderby\' => \'name\' ) );
// If no menus exists, direct the user to go and create some.
if ( !$menus ) {
echo \'<p>\'. sprintf( __(\'No menus have been created yet. <a href="%s">Create some</a>.\'), admin_url(\'nav-menus.php\') ) .\'</p>\';
return;
}
?>
<p>
<label for="<?php echo $this->get_field_id( \'title\' ); ?>"><?php _e( \'Title:\', \'wpspprofwid\' ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id(\'title\'); ?>" name="<?php echo $this->get_field_name(\'title\'); ?>" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( \'mtitle\' ); ?>"><?php _e( \'Menu Title:\' ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id(\'mtitle\'); ?>" name="<?php echo $this->get_field_name(\'mtitle\'); ?>" value="<?php echo $mtitle; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( \'nav_menu\' ); ?>"><?php _e( \'Select Menu:\' ); ?></label>
<select id="<?php echo $this->get_field_id( \'nav_menu\' ); ?>" name="<?php echo $this->get_field_name(\'nav_menu\'); ?>">
<?php
foreach ( $menus as $menu ) {
echo \'<option value="\' . $menu->term_id . \'"\'
. selected( $nav_menu, $menu->term_id, false )
. \'>\'. $menu->name . \'</option>\';
}
?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id( \'sc1title\' ); ?>"><?php _e( \'Shortcode 1 Title:\' ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id(\'sc1title\'); ?>" name="<?php echo $this->get_field_name(\'sc1title\'); ?>" value="<?php echo $sc1title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( \'sc1\' ); ?>"><?php _e( \'Shortcode 1:\' ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id(\'sc1\'); ?>" name="<?php echo $this->get_field_name(\'sc1\'); ?>" value="<?php echo $sc1; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( \'sc1title\' ); ?>"><?php _e( \'Shortcode 2 Title:\' ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id(\'sc2title\'); ?>" name="<?php echo $this->get_field_name(\'sc2title\'); ?>" value="<?php echo $sc2title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( \'sc2\' ); ?>"><?php _e( \'Shortcode 2:\' ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id(\'sc2\'); ?>" name="<?php echo $this->get_field_name(\'sc2\'); ?>" value="<?php echo $sc2; ?>" />
</p>