ここではWordpressの初心者開発者なので、本当に助けが必要です。機能を表示するウィジェットを作成していますが、オプションが保存されません。「保存」を押すと、すべてのボックスが再び空白になります。明らかな何かが欠けていると思います!
私のウィジェットコードの関連部分は次のとおりです。
// First create the widget for the admin panel
class icon_features_widget extends WP_Widget {
function icon_features_widget() {
$widget_ops = array( 'description' => __( 'Displays icon features in a widget', 'icon-feature-widget' ) );
$this->WP_Widget( 'icon_feature_widget', __( 'Icon Feature', 'icon-feature-widget' ), $widget_ops );
}
function form( $instance ) {
$icon_feature_title = isset( $instance['icon_feature_title'] ) ? $instance['icon_feature_title'] : '';
$icon_feature_text = isset( $instance['icon_feature_text'] ) ? $instance['icon_feature_text'] : '';
$icon_feature_link_url = isset( $instance['icon_feature_link_url'] ) ? $instance['icon_feature_link_url'] : '';
$icon_feature_link_text = isset( $instance['icon_feature_link_text'] ) ? $instance['icon_feature_link_text'] : '';
$radioValue = isset( $instance['radioValue'] ) ? $instance['radioValue'] : '';
$icon_feature_icon_class = isset( $instance['icon_feature_icon_class'] ) ? $instance['icon_feature_icon_class'] : '';
$icon_feature_custom_icon_url = isset( $instance['icon_feature_custom_icon_url'] ) ? $instance['icon_feature_custom_icon_url'] : '';
?>
<p>
<label for="icon_feature_title">Title:</label><br />
<input type="text" name="icon_feature_title" id="icon_feature_title" value="<?php echo $icon_feature_title ; ?>" />
</p>
<p>
<label for="icon_feature_text">Text:</label><br />
<textarea name="icon_feature_text" id="icon_feature_text" value="<?php echo $icon_feature_text ; ?>" rows="6" cols="21"/></textarea>
</p>
<p>
<label for="icon_feature_link_url">Link URL:</label><br />
<input type="text" name="icon_feature_link_url" id="icon_feature_link_url" value="<?php echo $icon_feature_link_url ; ?>" />
</p>
<p>
<label for="icon_feature_link_text">Link Text (defaults to "Read More"):</label><br />
<input type="text" name="icon_feature_link_text" id="icon_feature_link_text" value="<?php echo $icon_feature_link_text ; ?>" />
</p>
<p>Choose which icon source you'd like to use.</p>
<p>
<label>
<input type="radio" id="iconRadio" name="whichToDisplay" value="icon" <?php echo ($radioValue == 'icon' || $radioValue == '') ? 'checked="checked"':''; ?>/>
Choose from included icons
</label><br />
<label>
<input type="radio" id="customIconRadio" name="whichToDisplay" value="customIcon" <?php echo ($radioValue == 'customIcon') ? 'checked="checked"':''; ?>/>
Display custom icon
</label><br />
<label>
<input type="radio" id="nothingRadio" name="whichToDisplay" value="nothing" <?php echo ($radioValue == 'nothing') ? 'checked="checked"':''; ?>/>
Display neither
</label><br /><br />
</p>
<p> <!-- REPLACE THIS WITH SOME KIND OF ICON CHOOSER DROPDOWN THING -->
<label for="icon_feature_icon_class">Icon Class:</label><br />
<input type="text" name="icon_feature_icon_class" id="icon_feature_icon_class" value="<?php echo $icon_feature_icon_class ; ?>" />
</p>
<p> <!-- REPLACE THIS WITH A WORDPRESS IMAGE CHOOSER / MEDIA LIBRARY CHOOSER -->
<label for="icon_feature_custom_icon_url">Custom Icon URL:</label><br />
<input type="text" name="icon_feature_custom_icon_url" id="icon_feature_custom_icon_url" value="<?php echo $icon_feature_custom_icon_url ; ?>" />
</p>
<?php
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['icon_feature_title'] = $new_instance['icon_feature_title'];
$instance['icon_feature_text'] = $new_instance['icon_feature_text'];
$instance['icon_feature_link_url'] = $new_instance['icon_feature_link_url'];
$instance['icon_feature_link_text'] = $new_instance['icon_feature_link_text'];
$instance['radioValue'] = $new_instance['radioValue'];
$instance['icon_feature_icon_class'] = $new_instance['icon_feature_icon_class'];
$instance['icon_feature_custom_icon_url'] = $new_instance['icon_feature_custom_icon_url'];
return $instance;
}
どうもありがとう!