1

i have a custom widget to display two baner in site there are four field for link and img src $name and $email saved value currectlly but $namee and $emaill does not save value!!

<?php
class my_custom_ads extends WP_Widget {
    function __construct() {
        parent::__construct(
            'yiw_pro_widget',
            __('ابزارک اختصاصی تبلیغات قالب', 'wordpress'),
            array( 'description' => __( 'ابزارکی برای قرار دادن تبلیغات 120*-240 و 300*300', 'wordpress' ), )
        );
    }
    public function widget( $args, $instance ) {
        $name = apply_filters( 'widget_title', $instance['name'] );
        $email = apply_filters( 'widget_title', $instance['email'] );
        $namee = apply_filters( 'widget_title', $instance['namee'] );
        $emaill = apply_filters( 'widget_title', $instance['emaill'] );

        echo '<aside class="ads"><h5 style="border-bottom:2px solid #33ad1c;"><a style="background:#33ad1c;">تبلیغات</a></h5><a href="'.$name.'" target="_blank"><img src="'.$email.'" ></a><a href="'.$namee.'" target="_blank"><img src="'.$emaill.'" ></a></aside>';
        echo $args['after_widget'];
    }
    public function form( $instance ) {
        $name   = ( isset( $instance[ 'name' ] ) ) ? $instance[ 'name' ] : '';
        $email  = ( isset( $instance[ 'email' ] ) ) ? $instance[ 'email' ] : '';
        $namee  = ( isset( $instance[ 'namee' ] ) ) ? $instance[ 'namee' ] : '';
        $emaill = ( isset( $instance[ 'emaill' ] ) ) ? $instance[ 'emaill' ] : '';
        ?>


            <p>
                <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e( 'لینک تصویر اول:' ); ?></label>
                <input class="widefat" id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" type="text" value="<?php echo esc_attr( $name ); ?>" />
            </p>
            <p>
                <label for="<?php echo $this->get_field_id( 'email' ); ?>"><?php _e( 'آدرس تصویر اول:' ); ?></label>
                <input class="widefat" id="<?php echo $this->get_field_id( 'email' ); ?>" name="<?php echo $this->get_field_name( 'email' ); ?>" type="text" value="<?php echo esc_attr( $email ); ?>" />
            </p>
            <p>
                <label for="<?php echo $this->get_field_id( 'namee' ); ?>"><?php _e( 'لینک تصویر دوم:' ); ?></label>
                <input class="widefat" id="<?php echo $this->get_field_id( 'namee' ); ?>" name="<?php echo $this->get_field_name( 'namee' ); ?>" type="text" value="<?php echo esc_attr( $namee ); ?>" />
            </p>
            <p>
                <label for="<?php echo $this->get_field_id( 'emaill' ); ?>"><?php _e( 'آدرس تصویر دوم:' ); ?></label>
                <input class="widefat" id="<?php echo $this->get_field_id( 'emaill' ); ?>" name="<?php echo $this->get_field_name( 'emaill' ); ?>" type="text" value="<?php echo esc_attr( $emaill ); ?>" />
            </p>

        <?php
    }
    public function update( $new_instance, $old_instance ) {
        $instance = array();
        $instance['name'] = ( ! empty( $new_instance['name'] ) ) ? strip_tags( $new_instance['name'] ) : '';
        $instance['email'] = ( ! empty( $new_instance['email'] ) ) ? strip_tags( $new_instance['email'] ) : '';
        $instance['namee'] = ( ! empty( $new_instance['namee'] ) ) ? strip_tags( $new_instance['namee'] ) : '';
        $instance['emaill'] = ( ! empty( $new_instance['emaill'] ) ) ? strip_tags( $new_instance['emaill'] ) : '';
        return $instance;
    }
}
function load_my_custom_ads() {
    register_widget( 'my_custom_ads' );
}
add_action( 'widgets_init', 'load_my_custom_ads' );
?>  
  • 1
    your code works well on my computer with a clean wordpress installation. try to desactivate all plugins and try with a basic theme – mmm Oct 10 '16 at 8:25
  • thats right maybe a plugin involved thx – m.javad Koushki Oct 10 '16 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.