• Resolved andrewlux

    (@andrewlux)


    I’m making my first Wodrpress widget. Something simple that lets you put in social link buttons into a sidebar. I followed tutorials that told me to wrap the widget in a plugin, and I got it working fine, however when I tried to log out or log in again I got just a white screen. I removed the folder from the plugin directory and I could access wp-admin fine. if I’m already logged in and make the plugin i made active, everything works fine. Its just the wp-admin screen is totally white when the plugin is activated.

    Here is the plugin code

    class social_widget extends WP_Widget {
    
      public function __construct(){
          $widget_ops = array('classname' => 'social_widget', 'description' => 'Displays an My widget!' );
          $this->WP_Widget('social_widget', 'Social Buttons', $widget_ops);
    
      }
    
      function widget($args, $instance) {
        extract($args, EXTR_SKIP);
    
        $fb = $instance['facebookk'];
        $link = $instance['linkedd'];
        $twit = $instance['twitterr'];
        echo $before_widget;
    
        if ( $fb ) : ?>
          <a href="<?php echo $fb; ?>" target="_blank"><img id="contlink" src="<?php bloginfo('template_directory'); ?>/images/fb-wht.png"></a>
        <?php endif;
        if ( $link ) : ?>
          <a href="<?php echo $link; ?>" target="_blank"><img id="contlink" src="<?php bloginfo('template_directory'); ?>/images/linkeded-wht.png"></a>
        <?php endif;
        if ( $twit ) : ?>
          <a href="<?php echo $twit; ?>" target="_blank"><img id="contlink" src="<?php bloginfo('template_directory'); ?>/images/twitter-wht.png"></a>
        <?php endif;
        echo $after_widget;
      }
    
    public function form($instance){
    $instance = wp_parse_args( (array) $instance, array( 'facebookk' => 'your mom') ); ?>
    
    <p>
    <label for="<?php echo $this->get_field_id('facebookk'); ?>"><?php _e('Facebookk', 'social_widget'); ?></label>
    <input class="widefat" id="<?php echo $this->get_field_id('facebookk'); ?>" name="<?php echo $this->get_field_name('facebookk'); ?>" type="text" value="<?php echo $instance['facebookk']; ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('linkedd'); ?>"><?php _e('Linkeddin', 'social_widget'); ?></label>
    <input class="widefat" id="<?php echo $this->get_field_id('linkedd'); ?>" name="<?php echo $this->get_field_name('linkedd'); ?>" type="text" value="<?php echo $instance['linkedd']; ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('twitterr'); ?>"><?php _e('Twitterr', 'social_widget'); ?></label>
    <input class="widefat" id="<?php echo $this->get_field_id('twitterr'); ?>" name="<?php echo $this->get_field_name('twitterr'); ?>" type="text" value="<?php echo $instance['twitterr']; ?>" />
    </p>
    <?php
    
      }
    
    public function update($new_instance, $old_instance) {
        $instance = $old_instance;
        $instance['facebookk'] = $new_instance['facebookk'];
        $instance['linkedd'] = $new_instance['linkedd'];
        $instance['twitterr'] = $new_instance['twitterr'];
        return $instance;
      }
    
    }
    
    add_action( 'widgets_init', create_function('', 'return register_widget("social_widget");') );
Viewing 8 replies - 1 through 8 (of 8 total)
  • Can I suggest you something
    please used the WordPress text widget instead of creating a new widget

    I will be more easy an less time consuming

    If then also you want to create a custom Widget let me know

    Ciprian

    (@butterflymedia)

    You should activate the debug mode and you will get the errors displayed on screen.

    In your wp-config.php file, in your root folder, add these lines:

    /* WordPress debug mode for developers. */
    define( 'WP_DEBUG',         true );
    define( 'WP_DEBUG_LOG',     true );
    define( 'WP_DEBUG_DISPLAY', true );
    define( 'SCRIPT_DEBUG',     true );
    define( 'SAVEQUERIES',      true );
    Thread Starter andrewlux

    (@andrewlux)

    Thanks, I fixed the problem, but am super confused as to why there was an issue.
    it was returning

    Warning: Cannot modify header information - headers already sent by (output started at /wp-content/plugins/Social-buttons/text-widget.php:79)
    — In the files wp-login.php and wp-includes/pluggable.php
    — And on multiple lines

    It was telling me that the header info was being sent by line 79 of my plugin, and my code stopped at line 76. I had 3 hard returns after my final ?> to allow for some padding while coding. Apparently these 3 line breaks were cause interference with the header information. I did some tests and if there is more than one line break at the end of the plugin php document, the debug display gives me the same results.

    Is this a known issue with WordPress development that I’ve just never run into? Is this a common thing with php that just illustrates how dumb of a developer I am? I did a google search and can find any info on it, maybe someone smarter than me knows whats up..

    Thanks

    Thread Starter andrewlux

    (@andrewlux)

    Sorry forgot to mark the topic resolved

    Ciprian

    (@butterflymedia)

    This is a common thing with PHP, you shouldn’t have more than one line break after your ?> code.

    Some developers would recommend not having the closing ?> tag.

    Cheers!

    Thread Starter andrewlux

    (@andrewlux)

    Thanks so much, I still have a lot to learn.

    Thanks again!

    Ciprian

    (@butterflymedia)

    You are welcome!

    Moderator bcworkz

    (@bcworkz)

    Ciprian is correct about line breaks, but doesn’t really explain why. I always like to know the reasoning behind why I shouldn’t do things. If “don’t do that” is adequate for you, no need to read further ??

    Plugin files cannot produce any output upon initial load. Any output must be indirect, related to an action or filter hook, shortcode handler, etc. This is because the plugin is loaded before WP sends its headers. As you may know, sending headers with PHP cannot occur once any output has occurred. Output includes any extra whitespace or line breaks after the final ?>. Even the hidden byte order mark sometimes included in UTF-8 files will cause an unexpected output warning when you activate the plugin.

    One way to prevent unexpected output due to extra whitespace is to omit the closing ?>. Then you can have as much whitespace as you want without issue because its considered part of the PHP code.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom plugin not allowing access to wp-admin’ is closed to new replies.