__( 'Display posts with Amazing way', 'pancenjoss_amazing' ) ) // Args ); // Hooks fired when the Widget is activated and deactivated // register_activation_hook( __FILE__, array( $this, 'activate' ) ); // register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); // $this->directory = plugins_url( '/', __FILE__ ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ function widget($args, $instance) { extract( $args ); extract( $instance ); $title = apply_filters( 'widget_title', empty( $title ) ? '' : $title ); // if ( empty($template) ) $template = 'amaz-columns.php'; $post_types = get_post_types(); unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']); if($post_type == 'all') { $post_type_array = $post_types; } else { $post_type_array = $post_type; } $number = $rows*$columns; // Setup the query $i=0; $argss=array(); while($i<$pages_number) { $argss[$i] = array( 'ignore_sticky_posts' => 1, 'cat' => $categories, 'post_type' => $post_type_array, 'post_status' => array('publish', 'inherit'), 'posts_per_page' => $number, 'offset' => $number*$i+$offset, 'orderby' => $orderby, 'order' => $order, ); $i++; } // Get the posts for this instance include ( PJ_AP_PATH . 'views/'.$template ); } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array Updated safe values to be saved. */ function update( $new_instance, $old_instance ) { // Get our defaults to test against // $this->posttypes = get_post_types( array('public' => true ), 'objects' ); // $this->taxonomies = get_taxonomies( array('public' => true ), 'objects' ); // $this->thumbsizes = get_intermediate_image_sizes(); $this->orderbys = array( 'date' => __('Publish Date', 'pancenjoss_amazing'), 'title' => __('Title', 'pancenjoss_amazing'), 'menu_order' => __('Menu Order', 'pancenjoss_amazing'), 'ID' => __('Post ID', 'pancenjoss_amazing'), 'author' => __('Author', 'pancenjoss_amazing'), 'name' => __('Post Slug', 'pancenjoss_amazing'), 'comment_count' => __('Comment Count', 'pancenjoss_amazing'), 'rand' => __('Random', 'pancenjoss_amazing'), ); $this->orders = array( 'ASC' => __('Ascending', 'pancenjoss_amazing'), 'DESC' => __('Descending', 'pancenjoss_amazing'), ); $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['categories'] = $new_instance['categories']; $instance['post_type'] = $new_instance['post_type']; $instance['offset'] = (int) $new_instance['offset']; $instance['orderby'] = ( array_key_exists( $new_instance['orderby'], $this->orderbys ) ? $new_instance['orderby'] : 'date' ); $instance['order'] = ( array_key_exists( $new_instance['order'], $this->orders ) ? $new_instance['order'] : 'DESC' ); $instance['thumbnail'] = ( isset( $new_instance['thumbnail'] ) ? (int) $new_instance['thumbnail'] : '0' ); $instance['post_title'] = ( isset( $new_instance['post_title'] ) ? (int) $new_instance['post_title'] : '0' ); $instance['excerpt_length'] = (int) $new_instance['excerpt_length']; $instance['pages_number'] = (int) $new_instance['pages_number']; $instance['rows'] = (int) $new_instance['rows']; $instance['columns'] = (int) $new_instance['columns']; $instance['img_width'] = (int) $new_instance['img_width']; $instance['img_height'] = (int) $new_instance['img_height']; $instance['template'] = strip_tags( $new_instance['template'] ); return $instance; } function get_amaz_templates(){ $templates = array(); foreach(glob(plugin_dir_path(__FILE__).'/views/amaz*.php') as $file) { $templates[] = basename($file); } foreach(glob(PJ_AP_PATH.'/views/amaz*.php') as $file){ $templates[] = basename($file); } $templates = array_unique($templates); sort($templates); return $templates; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ function form( $instance ) { // $this->posttypes = get_post_types( array('public' => true ), 'objects' ); // $this->taxonomies = get_taxonomies( array('public' => true ), 'objects' ); // $this->thumbsizes = get_intermediate_image_sizes(); $this->orderbys = array( 'date' => __('Publish Date', 'pancenjoss_amazing'), 'title' => __('Title', 'pancenjoss_amazing'), 'menu_order' => __('Menu Order', 'pancenjoss_amazing'), 'ID' => __('Post ID', 'pancenjoss_amazing'), 'author' => __('Author', 'pancenjoss_amazing'), 'name' => __('Post Slug', 'pancenjoss_amazing'), 'comment_count' => __('Comment Count', 'pancenjoss_amazing'), 'rand' => __('Random', 'pancenjoss_amazing'), ); $this->orders = array( 'ASC' => __('Ascending', 'pancenjoss_amazing'), 'DESC' => __('Descending', 'pancenjoss_amazing'), ); $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'categories' => 'all', 'post_type' => 'post', 'offset' => '0', 'orderby' => 'date', 'order' => 'DESC', 'post_title' => '1', 'excerpt_length' => '40', 'pages_number' => '1', 'rows' => '1', 'columns' => '3', 'thumbnail' => '1', 'img_width' => '383', 'img_height' => '200', 'template' => 'amaz-columns.php', ) ); extract( $instance ); $templates = $this->get_amaz_templates(); include ( PJ_AP_PATH. 'views/admin-amazing.php' ); } } // class PJ_Amazing_Posts_Widget