defaults = array( 'title' => esc_attr__( 'Archives', 'essential-widgets' ), 'limit' => 10, 'type' => 'monthly', 'post_type' => 'post', 'order' => 'DESC', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, ); parent::__construct( 'ew-archive', __( 'EW: Archives', 'essential-widgets' ), array( 'classname' => 'essential-widgets widget_archive ew-archive ewarchive', 'description' => esc_html__( 'Displays a list of categories', 'essential-widgets' ), ), array( 'id_base' => 'ew-archive', ) ); } public function form( $instance ) { $instance = wp_parse_args( (array) $instance, $this->defaults ); $post_types = get_post_types( array( 'name' => 'post' ), 'objects' ); $post_types = array_merge( $post_types, get_post_types( array( 'publicly_queryable' => true, '_builtin' => false ), 'objects' ) ); $type = array( 'alpha' => esc_attr__( 'Alphabetical', 'essential-widgets' ), 'daily' => esc_attr__( 'Daily', 'essential-widgets' ), 'monthly' => esc_attr__( 'Monthly', 'essential-widgets' ), 'postbypost' => esc_attr__( 'Post By Post', 'essential-widgets' ), 'weekly' => esc_attr__( 'Weekly', 'essential-widgets' ), 'yearly' => esc_attr__( 'Yearly', 'essential-widgets' ), ); $order = array( 'ASC' => esc_attr__( 'Ascending', 'essential-widgets' ), 'DESC' => esc_attr__( 'Descending', 'essential-widgets' ), ); $format = array( 'custom' => esc_attr__( 'Plain', 'essential-widgets' ), 'html' => esc_attr__( 'List', 'essential-widgets' ), 'option' => esc_attr__( 'Dropdown', 'essential-widgets' ), ); ?>
defaults ); echo wp_kses_post( $args['before_widget'] ); if ( ! empty( $instance['title'] ) ) { echo wp_kses_post( $args['before_title'] ); $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); echo esc_html( $title ); echo wp_kses_post( $args['after_title'] ); } echo wp_kses_post( $this->shortcode( $instance ) ); echo wp_kses_post( $args['after_widget'] ); } public function shortcode( $atts ) { $atts['echo'] = false; // Ensure limit is integer and not zero $atts_copy = $atts; $atts_copy['limit'] = intval( $atts_copy['limit'] ?? 0 ); if ( $atts_copy['limit'] <= 0 ) { unset( $atts_copy['limit'] ); // prevent SQL error } $atts_copy['post_type'] = sanitize_key( $atts_copy['post_type'] ?? 'post' ); $archives = str_replace( array("\r","\n","\t"), '', wp_get_archives( $atts_copy ) ); $archives = str_replace( ' (', ' (', $archives ); $archives = str_replace( ')', ')', $archives ); $dropdown_id = esc_attr( uniqid( 'wp-block-archives-' ) ); $ew_archives = ''; if ( ! empty( $atts['is_block'] ) && ! empty( $atts['title'] ) ) { $ew_archives .= '