小部件下显示的小部件选项

时间:2015-06-19 13:53:32

标签: php wordpress widget

我今天制作了我的第一个Wordpress小部件,一切都按照本地Wordpress安装的原样运行(与服务器上的版本相同)。但现在我将它上传到我的服务器,小部件的选项显示在页面上的小部件下,而不是管理员侧的小部件选项位置,我无法弄清楚原因。

以下是代码:

// Creating the widget
class wpb_widget extends WP_Widget {

function __construct() {
parent::__construct(
// Base ID of your widget

'wpb_widget',

// Widget name will appear in UI
__('Taxi prijs calculator', 'wpb_widget_domain'),


// Widget description
array( 'description' => __( 'Taxi prijs calculator', 'wpb_widget_domain' ), )
);

}


// Creating widget front-end
// This is where the action happens
public function widget( $args, $instance ) {
    $title = apply_filters( 'widget_title', $instance['title'] );
    $shadow = $instance['shadow'];
    $maincolor = $instance['maincolor'];
    $textcolor = $instance['textcolor'];
    $shadowcolor = $instance['shadowcolor'];

    // before and after widget arguments are defined by themes
    echo $args['before_widget'];
    if ( ! empty( $title ) )
    echo $args['before_title'] . $title . $args['after_title'];

    //Here is my code for the widget took it out to save space.

    echo $args['after_widget'];
}

// Widget Backend
public function form( $instance ) {

    if ( isset( $instance[ 'title' ] ) ) {
    $title = $instance[ 'title' ];
    }
    else {
    $title = __( 'New title', 'wpb_widget_domain' );
    }

    if ( isset( $instance[ 'shadow' ] ) ) {
        $shadow = $instance[ 'shadow' ];
    }
    else {
        $shadow = __( 'new shadow', 'wpb_widget_domain' );
    }

    if ( isset( $instance[ 'maincolor' ] ) ) {
        $maincolor = $instance[ 'maincolor' ];
    }
    else {
        $maincolor = __( 'new maincolor', 'wpb_widget_domain' );
    }

    if ( isset( $instance[ 'textcolor' ] ) ) {
        $textcolor = $instance[ 'textcolor' ];
    }
    else {
        $textcolor = __( 'new textcolor', 'wpb_widget_domain' );
    }
    if ( isset( $instance[ 'shadowcolor' ] ) ) {
        $shadowcolor = $instance[ 'shadowcolor' ];
    }
    else {
        $shadowcolor = __( 'new shadowcolor', 'wpb_widget_domain' );
    }
    // Widget admin form
    ?>

    <p>
    <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( '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( $title ); ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id( 'shadow' ); ?>"><?php _e( 'Display shadow:' ); ?></label> <br>
    <input type="radio" id="<?php echo $this->get_field_id( 'shadow' ); ?>" name="<?php echo $this->get_field_name( 'shadow' ); ?>" value="yes" <?php if($shadow == "yes" || $shadow = "new shadow"){ echo "checked";}?>>Yes <input type="radio" id="<?php echo $this->get_field_id( 'shadow' ); ?>" name="<?php echo $this->get_field_name( 'shadow' ); ?>" value="no" <?php if($shadow == "no"){ echo "checked";}?>>No
    </p>
    <p>
    <label for="<?php echo $this->get_field_id( 'shadowcolor' ); ?>"><?php _e( 'Shadow color:' ); ?></label><br>
    <input type="color" id="<?php echo $this->get_field_id( 'shadowcolor' ); ?>" name="<?php echo $this->get_field_name( 'shadowcolor' ); ?>" value="<?php if(empty($shadowcolor) || $shadowcolor == "new shadowcolor") { echo "#323232";}else{echo esc_attr( $shadowcolor );} ?>">
    </p>
    <p>
    <label for="<?php echo $this->get_field_id( 'maincolor' ); ?>"><?php _e( 'Main color:' ); ?></label><br>
    <input type="color" id="<?php echo $this->get_field_id( 'maincolor' ); ?>" name="<?php echo $this->get_field_name( 'maincolor' ); ?>" value="<?php if(empty($maincolor) || $maincolor == "new maincolor") { echo "#FDD017";}else{echo esc_attr( $maincolor );} ?>">
    </p>
    <p>
    <label for="<?php echo $this->get_field_id( 'textcolor' ); ?>"><?php _e( 'Text color:' ); ?></label><br>
    <input type="color" id="<?php echo $this->get_field_id( 'textcolor' ); ?>" name="<?php echo $this->get_field_name( 'textcolor' ); ?>" value="<?php if(empty($textcolor) || $textcolor == "new textcolor") { echo "#000000";}else{echo esc_attr( $textcolor );} ?>">
    </p>

    <?php
}

// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
    $instance = array();
    $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
    $instance['shadow'] = ( ! empty( $new_instance['shadow'] ) ) ? strip_tags( $new_instance['shadow'] ) : '';
    $instance['maincolor'] = ( ! empty( $new_instance['maincolor'] ) ) ? strip_tags( $new_instance['maincolor'] ) : '';
    $instance['textcolor'] = ( ! empty( $new_instance['textcolor'] ) ) ? strip_tags( $new_instance['textcolor'] ) : '';
    $instance['shadowcolor'] = ( ! empty( $new_instance['shadowcolor'] ) ) ? strip_tags( $new_instance['shadowcolor'] ) : '';

    return $instance;
}
} // Class wpb_widget ends here

// Register and load the widget
function wpb_load_widget() {

register_widget( 'wpb_widget' );
}

function prefix_add_my_stylesheet() {
// Respects SSL, Style.css is relative to the current file
wp_register_style( 'prefix-style', plugins_url('css/taxi.css', __FILE__) );
wp_enqueue_style( 'prefix-style' );
}
add_action( 'wp_enqueue_scripts', 'prefix_add_my_stylesheet' );
add_action( 'widgets_init', 'wpb_load_widget' );

这就是:

the problem

0 个答案:

没有答案