Jump to content

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

Edited by subhomoy
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.