'widget_archive',
'description' => __( 'A monthly archive of your Meetings.', 'ninety-ninety' ),
);
parent::__construct( 'ninety-meeting-archives', __( 'Archives (Meetings)', 'ninety-ninety' ), $widget_ops );
}
/**
* Widget
*
* @param array $args
* @param array $instance
*
* @return void
* @since 1.0.0
*/
public function widget( $args, $instance ) {
$posttype = 'ninety_meeting';
$c = ! empty( $instance['count'] ) ? '1' : '0';
$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives', 'ninety-ninety' ) : $instance['title'], $instance, $this->id_base );
add_filter( 'month_link', array( $this, 'get_month_link_meetings' ), 10, 3 );
add_filter( 'get_archives_link', array( $this, 'trim_post_type' ), 10, 1 );
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
if ( $d ) {
?>
$posttype,
'type' => 'monthly',
'show_post_count' => $c,
) ) );
?>
'',
'posttype' => 'post',
'count' => 0,
'dropdown' => '',
) );
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['posttype'] = strip_tags( $new_instance['posttype'] );
$instance['count'] = $new_instance['count'] ? 1 : 0;
$instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
return $instance;
}
/**
* Form
*
* @param array $instance
*
* @return string|void
* @since 1.0.0
*/
public function form( $instance ) {
$instance = wp_parse_args(
(array) $instance,
array(
'title' => '',
'posttype' => 'post',
'count' => 0,
'dropdown' => '',
)
);
$title = isset( $instance['title'] ) ? sanitize_text_field( $instance['title'] ) : '';
$count = $instance['count'] ? 'checked="checked"' : '';
$dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
?>
id="get_field_id( 'dropdown' ); ?>"
name="get_field_name( 'dropdown' ); ?>"/>
id="get_field_id( 'count' ); ?>"
name="get_field_name( 'count' ); ?>"/>
get_month_permastruct();
if ( ! empty( $monthlink ) ) {
$front = preg_replace( '/\/$/', '', $wp_rewrite->front );
$monthlink = str_replace( '%year%', $year, $monthlink );
$monthlink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $monthlink );
$type_obj = get_post_type_object( $posttype );
$archive_name = ! empty( $type_obj->rewrite['slug'] ) ? $type_obj->rewrite['slug'] : $posttype;
if ( $front ) {
$new_front = $type_obj->rewrite['with_front'] ? $front : '';
$monthlink = str_replace( $front, $new_front . '/' . $archive_name, $monthlink );
$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
} else {
$monthlink = home_url( user_trailingslashit( $archive_name . $monthlink, 'month' ) );
}
} else {
$monthlink = home_url( '?post_type=' . $posttype . '&m=' . $year . zeroise( $month, 2 ) );
}
return $monthlink;
}
/**
* Strip post_type from $link_html
* Don't need it with our rewrites
*
* @param string $link_html
*
* @return mixed
* @since 1.0.0
*/
public function trim_post_type( $link_html ) {
global $wp_rewrite;
if ( ! $wp_rewrite->permalink_structure ) {
return $link_html;
}
$posttype = 'ninety_meeting';
$link_html = str_replace( '?post_type=' . $posttype, '', $link_html );
return $link_html;
}
}