* @copyright Copyright (c) 2008 - 2012, Justin Tadlock
* @link http://themehybrid.com/hybrid-core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/**
* Pages Widget Class
*
* @since 0.6.0
*/
class Hybrid_Widget_Pages extends WP_Widget {
/**
* Set up the widget's unique name, ID, class, description, and other options.
*
* @since 1.2.0
*/
function __construct() {
/* 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.', 'hybrid-core' )
);
/* Set up the widget control options. */
$control_options = array(
'width' => 800,
'height' => 350
);
/* Create the widget. */
$this->WP_Widget(
'hybrid-pages', // $this->id_base
__( 'Pages', 'hybrid-core'), // $this->name
$widget_options, // $this->widget_options
$control_options // $this->control_options
);
}
/**
* Outputs the widget based on the arguments input through the widget controls.
*
* @since 0.6.0
*/
function widget( $sidebar, $instance ) {
extract( $sidebar );
/* Set the $args for wp_list_pages() to the $instance array. */
$args = $instance;
/* Set the $title_li and $echo to false. */
$args['title_li'] = false;
$args['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 '
' . str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages( $args ) ) . '
';
/* 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['date_format'] = strip_tags( $new_instance['date_format'] );
$instance['number'] = strip_tags( $new_instance['number'] );
$instance['offset'] = strip_tags( $new_instance['offset'] );
$instance['include'] = preg_replace( '/[^0-9,]/', '', $new_instance['include'] );
$instance['exclude'] = preg_replace( '/[^0-9,]/', '', $new_instance['exclude'] );
$instance['exclude_tree'] = preg_replace( '/[^0-9,]/', '', $new_instance['exclude_tree'] );
$instance['authors'] = preg_replace( '/[^0-9,]/', '', $new_instance['authors'] );
$instance['post_type'] = $new_instance['post_type'];
$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', 'hybrid-core'),
'post_type' => 'page',
'depth' => 0,
'number' => '',
'offset' => '',
'child_of' => '',
'include' => '',
'exclude' => '',
'exclude_tree' => '',
'meta_key' => '',
'meta_value' => '',
'authors' => '',
'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 );
$post_types = get_post_types( array( 'public' => true, 'hierarchical' => true ), 'objects' );
$sort_order = array( 'ASC' => esc_attr__( 'Ascending', 'hybrid-core' ), 'DESC' => esc_attr__( 'Descending', 'hybrid-core' ) );
$sort_column = array( 'post_author' => esc_attr__( 'Author', 'hybrid-core' ), 'post_date' => esc_attr__( 'Date', 'hybrid-core' ), 'ID' => esc_attr__( 'ID', 'hybrid-core' ), 'menu_order' => esc_attr__( 'Menu Order', 'hybrid-core' ), 'post_modified' => esc_attr__( 'Modified', 'hybrid-core' ), 'post_name' => esc_attr__( 'Slug', 'hybrid-core' ), 'post_title' => esc_attr__( 'Title', 'hybrid-core' ) );
$show_date = array( '' => '', 'created' => esc_attr__( 'Created', 'hybrid-core' ), 'modified' => esc_attr__( 'Modified', 'hybrid-core' ) );
$meta_key = array_merge( array( '' ), (array) get_meta_keys() );
?>