Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

タクソノミーウィジェットにプルダウンを追加 #1098

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions assets/_js/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,18 @@
}, false)

})(window, document, 'veu_socialSet');

const taxonomyWidgetAll = document.querySelectorAll('.veu_widget_taxonmomy');
if (taxonomyWidgetAll.length) {
taxonomyWidgetAll.forEach((taxonomyWidget) => {
taxonomyWidget.addEventListener('change', () => {

taxName = taxonomyWidget.name;
taxValue = taxonomyWidget.value;
if (taxValue !== '') {
document.location.href = vkExOpt.homeUrl + '/?' + taxName + '=' + taxValue;
}

});
});
};
2 changes: 1 addition & 1 deletion assets/js/all.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion inc/other-widget/widget-archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function form( $instance ) {

<!-- タイトル -->
<div style="margin-top:15px;">
<label for="<?php echo $this->get_field_id( 'label' ); ?>"><?php _e( 'Title', 'vk-all-in-one-expansion-unit' ); ?>:</label>
<label for="<?php echo $this->get_field_id( 'label' ); ?>"><?php _e( 'Label to display', 'vk-all-in-one-expansion-unit' ); ?>:</label>
<input type="text" id="<?php echo $this->get_field_id( 'label' ); ?>-title" name="<?php echo $this->get_field_name( 'label' ); ?>" value="<?php echo esc_attr( $instance['label'] ); ?>" class="admin-custom-input">
</div>

Expand Down
128 changes: 87 additions & 41 deletions inc/other-widget/widget-taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,55 @@ public static function veu_widget_description() {

function widget( $args, $instance ) {
$instance = static::get_defaults( $instance );

if ( ! isset( $instance['tax_name'] ) ) {
$instance['tax_name'] = 'category';
}
if ( ! isset( $instance['label'] ) ) {
$instance['label'] = __( 'Category', 'vk-all-in-one-expansion-unit' );
}
if ( ! isset( $instance['form_design'] ) ) {
$instance['form_design'] = 'list';
}

?>
<?php echo $args['before_widget']; ?>
<div class="sideWidget widget_taxonomies widget_nav_menu">
<?php echo $args['before_title'] . $instance['label'] . $args['after_title']; ?>
<ul class="localNavi">

<?php
$tax_args = array(
'echo' => 1,
'style' => 'list',
'show_count' => false,
'show_option_all' => false,
'hide_empty' => $instance['hide_empty'],
'hierarchical' => true,
'title_li' => '',
'taxonomy' => $instance['tax_name'],
);
$tax_args = apply_filters( 'veu_widget_taxlist_args', $tax_args ); // 9.13.0.0
wp_list_categories( $tax_args );
if ( 'list' === $instance['form_design'] ) {
//
$tax_args = array(
'echo' => 1,
'style' => 'list',
'show_count' => false,
'show_option_all' => false,
'hide_empty' => $instance['hide_empty'],
'hierarchical' => true,
'title_li' => '',
'taxonomy' => $instance['tax_name'],
);
$tax_args = apply_filters( 'veu_widget_taxlist_args', $tax_args ); // 9.13.0.0

wp_list_categories( $tax_args );
} elseif ( 'select' === $instance['form_design'] ) {
//
$tax_args = array(
'echo' => 1,
'class' => 'veu_widget_taxonmomy',
'show_option_none' => __( 'Any', 'vk-filter-search-pro' ),
'option_none_value' => '',
'show_count' => false,
'hide_empty' => $instance['hide_empty'],
'hierarchical' => true,
'taxonomy' => $instance['tax_name'],
);
$tax_args = apply_filters( 'veu_widget_taxlist_args', $tax_args ); //

wp_dropdown_categories( $tax_args );
}
?>
</ul>
</div>
Expand All @@ -56,12 +81,13 @@ function widget( $args, $instance ) {

public static function get_defaults( $instance = array() ) {
$defaults = array(
'tax_name' => 'category',
'label' => __( 'Category', 'vk-all-in-one-expansion-unit' ),
'hide' => __( 'Category', 'vk-all-in-one-expansion-unit' ),
'title' => 'Category',
'hide_empty' => false,
'_builtin' => false,
'tax_name' => 'category',
'label' => __( 'Category', 'vk-all-in-one-expansion-unit' ),
'hide' => __( 'Category', 'vk-all-in-one-expansion-unit' ),
'title' => __( 'Category', 'vk-all-in-one-expansion-unit' ),
'form_design' => 'list',
'hide_empty' => false,
'_builtin' => false,
);
return wp_parse_args( (array) $instance, $defaults );
}
Expand All @@ -71,29 +97,37 @@ function form( $instance ) {
$instance = static::get_defaults( $instance );
$taxs = get_taxonomies( array( 'public' => true ), 'objects' );
?>
<p>
<label for="<?php echo $this->get_field_id( 'label' ); ?>"><?php _e( 'Label to display', 'vk-all-in-one-expansion-unit' ); ?></label>
<input type="text" id="<?php echo $this->get_field_id( 'label' ); ?>-title" name="<?php echo $this->get_field_name( 'label' ); ?>" value="<?php echo $instance['label']; ?>" ><br/>
<input type="hidden" name="<?php echo $this->get_field_name( 'hide' ); ?>" ><br/>

<label for="<?php echo $this->get_field_id( 'tax_name' ); ?>"><?php _e( 'Display page', 'vk-all-in-one-expansion-unit' ); ?></label>
<select name="<?php echo $this->get_field_name( 'tax_name' ); ?>" >

<?php foreach ( $taxs as $tax ) { ?>
<option value="<?php echo $tax->name; ?>"
<?php
if ( $instance['tax_name'] == $tax->name ) {
echo 'selected="selected"'; }
?>
><?php echo $tax->labels->name; ?></option>
<?php } ?>
</select><br/><br/>

<input type="checkbox" id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" value="true"
<?php
if ( $instance['hide_empty'] ) {
echo 'checked';}
?>

<!-- タイトル -->
<div style="margin-top:15px;">
<label for="<?php echo $this->get_field_id( 'label' ); ?>"><?php _e( 'Label to display', 'vk-all-in-one-expansion-unit' ); ?>:</label>
<input type="text" id="<?php echo $this->get_field_id( 'label' ); ?>-title" name="<?php echo $this->get_field_name( 'label' ); ?>" value="<?php echo esc_attr( $instance['label'] ); ?>" class="admin-custom-input">
</div>

<input type="hidden" name="<?php echo $this->get_field_name( 'hide' ); ?>" >

<!-- [ Select Taxonomy ] -->
<div>
<label for="<?php echo $this->get_field_id( 'tax_name' ); ?>"><?php _e( 'Category / Taxonomy', 'vk-all-in-one-expansion-unit' ); ?>:</label>
<select name="<?php echo $this->get_field_name( 'tax_name' ); ?>" class="admin-custom-input">
<?php foreach ( $taxs as $tax ) { ?>
<option value="<?php echo $tax->name; ?>"<?php if ( $instance['tax_name'] === $tax->name ) { echo ' selected="selected"'; } ?>>
<?php echo $tax->labels->name; ?>
</option>
<?php } ?>
</select>
</div>

<!-- [ Form format ] -->
<div>
<label for="<?php echo $this->get_field_id( 'form_design' ); ?>"><?php _e( 'Display design', 'vk-all-in-one-expansion-unit' ); ?>:</label>
<select name="<?php echo $this->get_field_name( 'form_design' ); ?>" class="admin-custom-input">
<option value="list" <?php selected( $instance['form_design'], 'list' ); ?>><?php _e( 'Lists', 'vk-all-in-one-expansion-unit' ); ?></option>
<option value="select" <?php selected( $instance['form_design'], 'select' ); ?>><?php _e( 'Drop down', 'vk-all-in-one-expansion-unit' ); ?></option>
</select>
</div>

<input style="margin-top:3px" type="checkbox" id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" value="true"<?php if ( $instance['hide_empty'] ) { echo ' checked';} ?>
/>
<label for="<?php echo $this->get_field_id( 'hide_empty' ); ?>"><?php _e( 'Do not display terms without posts', 'vk-all-in-one-expansion-unit' ); ?></label>
</p>
Expand Down Expand Up @@ -132,6 +166,18 @@ function update( $new_instance, $old_instance ) {

$instance['hide_empty'] = ( isset( $new_instance['hide_empty'] ) && $new_instance['hide_empty'] == 'true' );

$instance['form_design'] = $new_instance['form_design'];

return $instance;
}
}

add_filter(
'vkExUnit_master_js_options',
function( $options ) {
$options['homeUrl'] = home_url( '/' );
return $options;
},
10,
1
);
1 change: 1 addition & 0 deletions initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function veu_print_block_editor_css() {
-------------------------------------------*/
add_action( 'wp_enqueue_scripts', 'veu_print_js' );
function veu_print_js() {

$options = apply_filters( 'vkExUnit_master_js_options', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );

wp_register_script( 'vkExUnit_master-js', plugins_url( '', __FILE__ ) . '/assets/js/all.min.js', array(), VEU_VERSION, true );
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ e.g.

== Changelog ==

[ Specification Change ][ Page top button ] Add #top on body for pagetop btn
[ Specification Change ][ Taxonomy Widget ] Add dropdown mode.
[ Bug fix ] Fix XSS of Widgets, CTA, Custom Post Type Manager.

= 9.99.0 =
[ Specification Change ] Foce Load JS from footer is abolished.
[ Specification Change ] Add #top on body for pagetop btn
[ Fix ] Add a title attribute on Google Tag Manager (noscript)

= 9.98.1 =
Expand Down
Loading