1

I'm creating a WordPress Widget for show name of advertiser.

When I try to activate the plugin a error

The plugin generated 3 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

I did these things:

1- remove white space before or after the PHP opening or closing tags

2- change encoding to UTF8-BOM

<?php
class adsMain extends WP_Widget {

    public function __construct() {

        parent::__construct(
            'adsMain',
            __( 'تبلیغات', 'text' ),
            array(
                'classname'   => 'adsMain',
                'description' => __( 'برای ایجاد تبلیغات جدید این کادر را به مکان دلخواه خود بکشید.', 'text' )
            )
        ); 
    }
    /**  
     * Front-end display of widget.
     *
     * @see WP_Widget::widget()
     *
     * @param array $args     Widget arguments.
     * @param array $instance Saved values from database.
     */
    public function widget( $args, $instance ) {

        extract( $args );

        $advertiser = apply_filters( 'widget_title', $instance['advertiser'] );

        echo $advertiser;

    }

    /**
      * Sanitize widget form values as they are saved.
      *
      * @see WP_Widget::update()
      *
      * @param array $new_instance Values just sent to be saved.
      * @param array $old_instance Previously saved values from database.
      *
      * @return array Updated safe values to be saved.
      */
    public function update( $new_instance, $old_instance ) {

        $instance = $old_instance;

        $instance['advertiser'] = strip_tags( $new_instance['advertiser'] );

        return $instance;

    }

    /**
      * Back-end widget form.
      *
      * @see WP_Widget::form()
      *
      * @param array $instance Previously saved values from database.
      */
    public function form( $instance ) {

        $advertiser = ( isset($instance['advertiser']) ? esc_attr ( $instance['advertiser'] ) : '' );
?>

        <p>
            <label for="<?php echo $this->get_field_id('advertiser'); ?>"><?php _e('نام شخص / شرکت تبلیغ دهنده:'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('advertiser'); ?>" name="<?php echo $this->get_field_name('advertiser'); ?>" type="text" value="<?php echo $advertiser; ?>" />
        </p>
<?php
    }

}

/* Register uploader */
add_action ('admin_enqueue_scripts', function () {
    wp_register_script('adsMain-script' , plugins_url( '/js/adsMain-script.js', __FILE__ ), array( 'jquery' ), '20160904', true );
    wp_enqueue_script('adsMain-script');
    wp_enqueue_media();
});

/* Register the widget */
add_action('widgets_init', function() {
     register_widget( 'adsMain' );
});
?>
Eposo
  • 55
  • 1
  • 1
  • 10

0 Answers0