Jump to content

need help in creating a simple wordpress plugin


subhomoy

Recommended Posts

Hello everyone i'm creating my first widget but i need help... The problem i'm facing is that whenever i activate the plugin it shows the success message and also shows in the widgets area but the page not showing in the correct manner... Like if page has php error then it stops loading certain parts of the page...

 

I have attached the screenshots of the widget page...

 

 

The code is shown below

<?php
/*
	Plugin Name: My First Widget
	Description: This is my first plugin.
	Plugin URI: www.abc.com
	Version: 1.0.2
	Author: Subhomoy Goswami
	Author URI: www.cde.com
*/
class my_first_plugin extends WP_Widget
{
	function my_first_plugin()
	{
		//parent::__construct(false,$name=__('My First Widget'));
		$widget_ops = array('classname'=>'example', 'description'=>__('This will just show the Title of the widget'),'id_base'=>'my_first_plugin');
		$this->WP_Widget('my_first_plugin',__('My First Widget'));
	}
	/* This will be displayed in the backend of the website i.e The Admin */
	public function form($instance)
	{
		if((isset($instance['name'])) && (isset($instance['email'])))
		{
			$name = $instance['name'];
			$email = $instance['email'];
		}
		else
		{
			$name = __('','bc_widget_title');
			$email = __('','bc_widget_title');
		}
		?>
		<p>Name : <input type="text" name="<?php echo $this->get_field_name('name'); ?>" value="<?php echo $this->esc_attr($name); ?>"</p>
		<p>Email : <input type="text" name="<?php echo $this->get_field_name('email'); ?>" value="<?php echo $this->esc_attr($email); ?>"</p>
		<?php
	}
	/* This is the place where the update takes place */
	public function update($new_instance, $old_instance)
	{
		$instance = $old_instance;
		$instance['name'] = (!empty($new_instance['name']))? strip_tags($new_instance['name']):'';
		$instance['email'] = (!empty($new_instance['email']))? strip_tags($new_instance['email']):'';

		return $instance;
	}
	/* This will be displayed in the web page*/
	public function widget($args,$instance)
	{
		extract($args);
		
		echo $before_widget;
		$name = apply_filters('widget_title',$instance['name']);
		$email = empty($instance['email'])? ' ' : $instance['email'];

		if(!empty($instance['name'])) {echo $before_title.$name.$after_title;}

		echo "<p>Name =".$instance['name']."</p>";
		echo "<p>Email =".$instance['email']."</p>";
                echo $after_widget; 
	}
}

add_action('widgets_init',function(){
	register_widget('my_first_plugin');
});

?>

Any help will be greatly appreciated....

post-126723-0-28242400-1391101312_thumb.png

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.