<?php
/**
* Plugin Name: Facebook Page Plugin Widget
* Plugin URI: http://www.imark.co.il
* Description: Adds Facebook Widget
* Version: 1.0
* Author: imark image
* Author URI: http://www.imark.co.il
*/
 
class facebookWidget extends WP_Widget {

	function __construct() {
		// Instantiate the parent object
		parent::__construct( false, 'פייסבוק' );
	}

	function widget($args, $instance) {
	
		extract($args);
		$widget_id = $args['widget_id'];
		
		if (validate_widget($widget_id)) {
		
		$title = $instance[ 'title' ];
		$facebook_url = get_field($widget_id.'_w_fb_url', 'widget');
		if (get_field($widget_id.'_w_fb_posts', 'widget')) {
			$facebook_posts = 'true';
		} else {
			$facebook_posts = 'false';
		}
		if (get_field($widget_id.'_w_fb_faces', 'widget')) {
			$facebook_faces = 'true';
		} else {
			$facebook_faces = 'false';
		}
		
		?>
		<section class="box"><div class="bg"><div class="box_style"></div></div>
		
			<div class="divinb shaded"><div class="padder">
			
				<h2><?php echo $title; ?></h2>
				
				<div class="fb-page" data-href="<?php echo $facebook_url; ?>" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="<?php echo $facebook_faces; ?>" data-show-posts="<?php echo $facebook_posts; ?>"><div class="fb-xfbml-parse-ignore"><blockquote cite="<?php echo $facebook_url; ?>"><a href="<?php echo $facebook_url; ?>">Facebook</a></blockquote></div></div>	
				
			</div></div>
			
		</section>
		<?php
		}
	}

	function update( $new_instance, $old_instance ) {
		// Save widget options
		$instance = array();
		$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';

		return $instance;
	}

	function form( $instance ) {
		
		$title = '';
		
		// Output admin widget options form
		if ( isset( $instance[ 'title' ] ) ) {
			$title = $instance[ 'title' ];
		}
		?>
		<div class="acf-field" style="margin-top:10px;">
			<div class="acf-label">
				<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title' ); ?></label> 
			</div>
			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
		</div>
		<?php 
	}
}

add_action('widgets_init', 'register_facebook_widget');
function register_facebook_widget() {
	register_widget('facebookWidget');
}
?>