• this is my first time writing a plugin for wordpress. it is a widget to play music using html5’s audio player. i have got it to work great, but am having some problems with the checkboxes. i got them to do what i want them to do, and to remember their settings when you open it again, but i am also getting an unexplained appearance of the words “checked=’checked'” in the widget itself in the admin area (the form) that corresponds to it’s state. it looks to me like the format outputted buy the checked() function but i don’t understand why it’s shoing up outside of the html code.

    here’s the code:

    public function form($instance)
    
    {
    	// these are the default widget values
    			$default = array(
    			'title' => __(''),
    
    			'url'=> __(''),
    
    			'loop'=> __(''),
    
    			'auto'=> __('')
    
    			);
    
    	$instance = wp_parse_args( (array)$instance, $default );
    
    // Check values
    	if( $instance) {
    	     $title = esc_attr($instance['title']);
    	     $url = esc_attr($instance['url']);
    	     $loop = checked( '1', $instance['loop']);
    	     $auto = checked( '1', $instance['auto']); // Added
    	} else {
    	     $title = '';
    	     $url = '';
    	     $loop = '';
    	     $auto = ''; // Added
    	}
    
    		//this is the html for the fields in the wp dashboard
    		echo "\r\n";
    
    		echo "<p>";
    
    		echo "<label for='".$this->get_field_id('title')."'>" . __('Title') . ":</label> " ;
    
    		echo "<input type='text' class='widefat' id='".$this->get_field_id('title')."' name='".$this->get_field_name('title')."' value='" . $title . "' placeholder='Please enter the song title here.' />" ;
    
    		echo "</p>";
    
    		echo "<p>";
    
    		echo "<label for='".$this->get_field_id('url')."'>" . __('Music File URL') . ":</label> " ;
    
    		echo "<input type='text' class='widefat' id='".$this->get_field_id('url')."' name='".$this->get_field_name('url')."' value='" . $url . "' placeholder='Please paste song URL here.' />" ;
    
    		echo "</p>";
    
    		echo "<label for='".$this->get_field_id('loop')."'>" . __('Loop?') . ":</label> " ;
    
    		echo "<input type='checkbox' id='".$this->get_field_id('loop')."' name='".$this->get_field_name('loop')."' value='1' ".$loop." />";
    
    		echo "</p>";
    
    		echo "<p>";
    
    		echo "<label for='".$this->get_field_id('auto')."'>" . __('Autoplay?') . ":</label> " ;
    
    		echo "<input type='checkbox'' id='".$this->get_field_id('auto')."' name='".$this->get_field_name('auto')."' value='1' ".$auto." />";
    
    		echo "</p>";
    
    	}

    and a link to what the problem looks like:
    this is a screenshot from dreamweaver.

  • The topic ‘admin area widget display anomaly’ is closed to new replies.