wp/wp-content/plugins/portfolio/includes/class-prtfl-widget.php
changeset 21 48c4eec2b7e6
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
       
     1 <?php
       
     2 /**
       
     3  * Display Portfolio Widget
       
     4  */
       
     5 
       
     6 if ( ! defined( 'ABSPATH' ) ) {
       
     7 	die();
       
     8 }
       
     9 
       
    10 /**
       
    11  * Class for Portfoilo widget
       
    12  */
       
    13 class Prtfl_Widget extends WP_Widget {
       
    14 	/**
       
    15 	 * Constructor of class
       
    16 	 */
       
    17 	public function __construct() {
       
    18 		parent::__construct(
       
    19 			'prtfl_widget',
       
    20 			__( 'Latest Portfolio Items', 'portfolio' ),
       
    21 			array( 'description' => __( 'Displays the latest Portfolio projects.', 'portfolio' ) )
       
    22 		);
       
    23 	}
       
    24 
       
    25 	/**
       
    26 	 * Function to displaying widget in front end
       
    27 	 *
       
    28 	 * @param array $args     Array with sidebar settings.
       
    29 	 * @param array $instance Array with widget settings.
       
    30 	 */
       
    31 	public function widget( $args, $instance ) {
       
    32 
       
    33 		$widget_title        = ( ! empty( $instance['widget_title'] ) ) ? apply_filters( 'widget_title', $instance['widget_title'], $instance, $this->id_base ) : '';
       
    34 		$widget_count_posts  = ( ! empty( $instance['widget_count_posts'] ) ) ? $instance['widget_count_posts'] : '';
       
    35 		$widget_count_colums = ( ! empty( $instance['widget_count_colums'] ) ) ? $instance['widget_count_colums'] : '';
       
    36 
       
    37 		$atts['count'] = $widget_count_posts;
       
    38 		$content       = prtfl_latest_items( $atts, $widget_count_colums );
       
    39 		echo wp_kses_post( $args['before_widget'] . $args['before_title'] . $widget_title . $args['after_title'] . $content );
       
    40 	}
       
    41 
       
    42 	/**
       
    43 	 * Function to displaying form
       
    44 	 *
       
    45 	 * @param array $instance Array with widget settings.
       
    46 	 */
       
    47 	public function form( $instance ) {
       
    48 		global $sbscrbr_options;
       
    49 
       
    50 		$widget_title        = isset( $instance['widget_title'] ) ? stripslashes( sanitize_text_field( $instance['widget_title'] ) ) : '';
       
    51 		$widget_count_posts  = isset( $instance['widget_count_posts'] ) ? stripslashes( sanitize_text_field( $instance['widget_count_posts'] ) ) : 5;
       
    52 		$widget_count_colums = isset( $instance['widget_count_colums'] ) ? stripslashes( sanitize_text_field( $instance['widget_count_colums'] ) ) : 3;
       
    53 		?>
       
    54 		<p>
       
    55 			<label for="<?php echo esc_attr( $this->get_field_id( 'widget_title' ) ); ?>">
       
    56 				<?php esc_html_e( 'Title', 'portfolio' ); ?>:
       
    57 				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'widget_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'widget_title' ) ); ?>" type="text" value="<?php echo esc_html( $widget_title ); ?>"/>
       
    58 			</label>
       
    59 		</p>
       
    60 		<p>
       
    61 			<label for="<?php echo esc_attr( $this->get_field_id( 'widget_count_posts' ) ); ?>">
       
    62 				<?php esc_html_e( 'Number of Projects:', 'portfolio' ); ?>:
       
    63 				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'widget_count_posts' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'widget_count_posts' ) ); ?>" type="number" min="1" max="100" value="<?php echo esc_attr( $widget_count_posts ); ?>" />
       
    64 			</label>
       
    65 		</p>
       
    66 		<p>
       
    67 			<label for="<?php echo esc_attr( $this->get_field_id( 'widget_count_colums' ) ); ?>">
       
    68 				<?php esc_html_e( 'Number of Colums:', 'portfolio' ); ?>:
       
    69 				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'widget_count_colums' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'widget_count_colums' ) ); ?>" type="number" min="1" max="100" value="<?php echo esc_attr( $widget_count_colums ); ?>" />
       
    70 			</label>
       
    71 		</p>
       
    72 		<?php
       
    73 	}
       
    74 
       
    75 	/**
       
    76 	 * Function to update widget data
       
    77 	 *
       
    78 	 * @param array $new_instance New data with widget settings.
       
    79 	 * @param array $old_instance New data with widget settings.
       
    80 	 */
       
    81 	public function update( $new_instance, $old_instance ) {
       
    82 		$instance                        = array();
       
    83 		$instance['widget_title']        = ( ! empty( $new_instance['widget_title'] ) ) ? wp_strip_all_tags( $new_instance['widget_title'] ) : null;
       
    84 		$instance['widget_count_posts']  = ( ! empty( $new_instance['widget_count_posts'] ) ) ? wp_strip_all_tags( $new_instance['widget_count_posts'] ) : null;
       
    85 		$instance['widget_count_colums'] = ( ! empty( $new_instance['widget_count_colums'] ) ) ? wp_strip_all_tags( $new_instance['widget_count_colums'] ) : null;
       
    86 		return $instance;
       
    87 	}
       
    88 }