/wp-content/plugins/pagebuilder-addon/widgets/postslider-widget.php

https://gitlab.com/haque.mdmanzurul/wp-harpar-carolyn · PHP · 177 lines · 119 code · 54 blank · 4 comment · 16 complexity · 6414b52aa30bdf708557ce4d98cc9515 MD5 · raw file

  1. <?php
  2. class VeusePostsliderWidget extends WP_Widget {
  3. /**
  4. * Register widget with WordPress.
  5. */
  6. public function __construct() {
  7. parent::__construct(
  8. 'veuse_postslider_widget', // Base ID
  9. 'Posts slider (Veuse)', // Name
  10. array( 'description' => __( 'Display blog posts in a slider.', 'veuse-uikit' ), ) // Args
  11. );
  12. }
  13. public function widget( $args, $instance ) {
  14. extract( $args );
  15. $title = apply_filters( 'widget_title', $instance['title'] );
  16. $category = $instance['category'];
  17. $perpage = $instance['perpage'];
  18. $orderby = $instance['orderby'];
  19. $order = $instance['order'];
  20. $width = $instance['width'];
  21. $height = $instance['height'];
  22. $category = rtrim($category, ',');
  23. echo $before_widget;
  24. if ( ! empty( $title ) )
  25. echo $before_title . $title . $after_title;
  26. // Do Your Widgety Stuff Here…
  27. echo do_shortcode('[veuse_postslider categories="'. $category .'" orderby="'.$orderby.'" order="'.$order.'" perpage="'.$perpage.'" width="'.$width.'" height="'.$height.'"]');
  28. echo $after_widget;
  29. }
  30. public function update( $new_instance, $old_instance ) {
  31. $instance = array();
  32. $instance['title'] = strip_tags( $new_instance['title'] );
  33. $instance['category'] = strip_tags( $new_instance['category'] );
  34. $instance['perpage'] = strip_tags( $new_instance['perpage'] );
  35. $instance['orderby'] = strip_tags( $new_instance['orderby'] );
  36. $instance['order'] = strip_tags( $new_instance['order'] );
  37. $instance['width'] = strip_tags( $new_instance['width'] );
  38. $instance['height'] = strip_tags( $new_instance['height'] );
  39. return $instance;
  40. }
  41. public function form( $instance ) {
  42. global $widget, $wp_widget_factory, $wp_query;
  43. if ( isset( $instance[ 'title' ] ) ) $title = $instance[ 'title' ]; else $title = __( '', 'text_domain' );
  44. if ( isset( $instance[ 'category' ] ) ) $category = $instance[ 'category' ]; else $category = '';
  45. if ( isset( $instance[ 'perpage' ] ) ) $perpage = $instance[ 'perpage' ]; else $perpage = __( '-1', 'text_domain' );
  46. if ( isset( $instance[ 'orderby' ] ) ) $orderby = $instance[ 'orderby' ]; else $orderby = __( 'date', 'text_domain' );
  47. if ( isset( $instance[ 'order' ] ) ) $order = $instance[ 'order' ]; else $order = __( 'ASC', 'text_domain' );
  48. if ( isset( $instance[ 'width' ] ) ) $width = $instance[ 'width' ]; else $width = '1000';
  49. if ( isset( $instance[ 'height' ] ) ) $height = $instance[ 'height' ]; else $height = '500';
  50. ?>
  51. <p>
  52. <label style="width:80px;" for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  53. <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 ); ?>" />
  54. </p>
  55. <style>
  56. .categoryselector-wrapper {
  57. padding:10px; background: #fff; border:1px solid #eee; overflow: scroll; max-height:180px; margin-bottom: 20px;
  58. }
  59. .categoryselector-wrapper a {
  60. padding:3px 10px 3px 0px; display: block; margin: 0; cursor: pointer; text-decoration: none;
  61. border-bottom:1px dotted #d4d4d4;
  62. }
  63. .categoryselector-wrapper a:hover { color:#2a95c5;}
  64. .categoryselector-wrapper a:after {
  65. content:'';
  66. color:#999;
  67. float:right;
  68. font-weight: bold;
  69. }
  70. .categoryselector-wrapper a.active { font-weight: bold; color:#de4b29;}
  71. .categoryselector-wrapper a.active:after {
  72. content:'x';
  73. color:#de4b29;
  74. }
  75. </style>
  76. <label style="min-width:90px;" for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( "Select categories:",'veuse-uikit' ); ?></label>
  77. <div class="categoryselector-wrapper">
  78. <?php
  79. $categories = get_categories( array('hide_empty' => 1 ));
  80. if( $categories ){
  81. foreach( $categories as $term ){
  82. ?>
  83. <a href="#" data-category-id="<?php echo $term->slug;?>"> <?php echo $term->name;?></a>
  84. <?php
  85. }
  86. }
  87. ?>
  88. </div>
  89. <input id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" type="hidden" value="<?php echo esc_attr( $category );?>" />
  90. <p>
  91. <label style="min-width:90px;" for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( "Order by:",'veuse-uikit' ); ?></label>
  92. <select name="<?php echo $this->get_field_name('orderby');?>">
  93. <option value="title" <?php selected( $orderby, 'title' , true); ?>><?php _e('Post title','veuse-uikit');?></option>
  94. <option value="date" <?php selected( $orderby, 'date' , true); ?>><?php _e('Post date','veuse-uikit');?></option>
  95. </select>
  96. </p>
  97. <p>
  98. <label style="min-width:90px;" for="<?php echo $this->get_field_id( 'order' ); ?>"><?php _e( "Order:",'veuse-uikit' ); ?></label>
  99. <select name="<?php echo $this->get_field_name('order');?>">
  100. <option value="ASC" <?php selected( $order, 'ASC' , true); ?>><?php _e('Ascending','veuse-uikit');?></option>
  101. <option value="DESC" <?php selected( $order, 'DESC' , true); ?>><?php _e('Descending','veuse-uikit');?></option>
  102. </select>
  103. </p>
  104. <p>
  105. <label style="min-width:90px;" for="<?php echo $this->get_field_id( 'perpage' ); ?>"><?php _e( "Per page:",'veuse-uikit' ); ?></label>
  106. <input size="6" id="<?php echo $this->get_field_id( 'perpage' ); ?>" name="<?php echo $this->get_field_name( 'perpage' ); ?>" type="text" value="<?php echo esc_attr( $perpage ); ?>" />
  107. <small><?php _e( "To show all, enter -1",'veuse-uikit' ); ?></small>
  108. </p>
  109. <p>
  110. <label style="min-width:90px;" for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e( "Image width:",'veuse-uikit' ); ?></label>
  111. <input size="6" id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" type="text" value="<?php echo esc_attr( $width ); ?>" />
  112. <small><?php _e( "Numeric value",'veuse-uikit' ); ?></small>
  113. </p>
  114. <p>
  115. <label style="min-width:90px;" for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( "Image height:",'veuse-uikit' ); ?></label>
  116. <input size="6" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo esc_attr( $height ); ?>" />
  117. <small><?php _e( "Numeric value",'veuse-uikit' ); ?></small>
  118. </p>
  119. <?php
  120. }
  121. }
  122. add_action('widgets_init',create_function('','return register_widget("VeusePostsliderWidget");'));
  123. ?>