prefix = Easy_get_prefix(); /* Set the widget textdomain. */ $this->textdomain = Easy_get_textdomain(); /* Set up the widget options. */ $widget_options = array( 'classname' => 'pages', 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your page links.', $this->textdomain ) ); /* Set up the widget control options. */ $control_options = array( 'width' => 800, 'height' => 350, 'id_base' => "{$this->prefix}-pages" ); /* Create the widget. */ $this->WP_Widget( "{$this->prefix}-pages", esc_attr__( 'Pages', $this->textdomain), $widget_options, $control_options ); } /** * Outputs the widget based on the arguments input through the widget controls. * @since 0.6.0 */ function widget( $args, $instance ) { extract( $args ); /* Set up the arguments for the wp_list_pages() function. */ $args = array( 'sort_column' => $instance['sort_column'], 'sort_order' => $instance['sort_order'], 'depth' => intval( $instance['depth'] ), 'child_of' => intval( $instance['child_of'] ), 'meta_key' => $instance['meta_key'], 'meta_value' => $instance['meta_value'], 'authors' => !empty( $instance['authors'] ) ? join( ', ', $instance['authors'] ) : '', 'include' => !empty( $instance['include'] ) ? join( ', ', $instance['include'] ) : '', 'exclude' => !empty( $instance['exclude'] ) ? join( ', ', $instance['exclude'] ) : '', 'exclude_tree' => $instance['exclude_tree'], 'link_before' => $instance['link_before'], 'link_after' => $instance['link_after'], 'date_format' => $instance['date_format'], 'show_date' => $instance['show_date'], 'number' => intval( $instance['number'] ), 'offset' => intval( $instance['offset'] ), 'hierarchical' => !empty( $instance['hierarchical'] ) ? true : false, 'title_li' => false, 'echo' => false ); /* Open the output of the widget. */ echo $before_widget; /* If a title was input by the user, display it. */ if ( !empty( $instance['title'] ) ) echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; /* Output the page list. */ echo ''; /* Close the output of the widget. */ echo $after_widget; } /** * Updates the widget control options for the particular instance of the widget. * @since 0.6.0 */ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Set the instance to the new instance. */ $instance = $new_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['depth'] = strip_tags( $new_instance['depth'] ); $instance['child_of'] = strip_tags( $new_instance['child_of'] ); $instance['meta_key'] = strip_tags( $new_instance['meta_key'] ); $instance['meta_value'] = strip_tags( $new_instance['meta_value'] ); $instance['exclude_tree'] = strip_tags( $new_instance['exclude_tree'] ); $instance['date_format'] = strip_tags( $new_instance['date_format'] ); $instance['number'] = strip_tags( $new_instance['number'] ); $instance['offset'] = strip_tags( $new_instance['offset'] ); $instance['sort_column'] = $new_instance['sort_column']; $instance['sort_order'] = $new_instance['sort_order']; $instance['show_date'] = $new_instance['show_date']; $instance['link_before'] = $new_instance['link_before']; $instance['link_after'] = $new_instance['link_after']; $instance['hierarchical'] = ( isset( $new_instance['hierarchical'] ) ? 1 : 0 ); return $instance; } /** * Displays the widget control options in the Widgets admin screen. * @since 0.6.0 */ function form( $instance ) { /* Set up the default form values. */ $defaults = array( 'title' => esc_attr__( 'Pages', $this->textdomain), 'depth' => 0, 'number' => '', 'offset' => '', 'child_of' => '', 'include' => array(), 'exclude' => array(), 'exclude_tree' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => array(), 'link_before' => '', 'link_after' => '', 'show_date' => '', 'hierarchical' => true, 'sort_column' => 'post_title', 'sort_order' => 'ASC', 'date_format' => get_option( 'date_format' ) ); /* Merge the user-selected arguments with the defaults. */ $instance = wp_parse_args( (array) $instance, $defaults ); $posts = get_posts( array( 'post_type' => 'page', 'post_status' => 'any', 'post_mime_type' => '', 'orderby' => 'title', 'order' => 'ASC', 'numberposts' => -1 ) ); $authors = array(); foreach ( $posts as $post ) $authors[$post->post_author] = get_the_author_meta( 'display_name', $post->post_author ); $sort_order = array( 'ASC' => esc_attr__( 'Ascending', $this->textdomain ), 'DESC' => esc_attr__( 'Descending', $this->textdomain ) ); $sort_column = array( 'post_author' => esc_attr__( 'Author', $this->textdomain ), 'post_date' => esc_attr__( 'Date', $this->textdomain ), 'ID' => esc_attr__( 'ID', $this->textdomain ), 'menu_order' => esc_attr__( 'Menu Order', $this->textdomain ), 'post_modified' => esc_attr__( 'Modified', $this->textdomain ), 'post_name' => esc_attr__( 'Slug', $this->textdomain ), 'post_title' => esc_attr__( 'Title', $this->textdomain ) ); $show_date = array( '' => '', 'created' => esc_attr__( 'Created', $this->textdomain ), 'modified' => esc_attr__( 'Modified', $this->textdomain ) ); $meta_key = array_merge( array( '' ), (array) get_meta_keys() ); ?>