From 59e11dbb14186f6a1cba3d1a0841d46d3b292b2e Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 9 May 2021 18:11:10 +0900 Subject: [PATCH] =?UTF-8?q?WP=20PLUGIN=20=E3=82=A2=E3=83=BC=E3=82=AB?= =?UTF-8?q?=E3=82=A4=E3=83=96=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=AE=E6=8A=95?= =?UTF-8?q?=E7=A8=BF=E8=A1=A8=E7=A4=BA=E9=A0=86=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・タクソノミーの1ページ表示数をタクソノミー毎のなるよう修正 ・タクソノミーの1ページ表示数変更に合わせてJSを修正 ・タクソノミーの1ページ表示数変更に合わせてテンプレートファイル分割 ・バグ修正:タームIDが無い存在しない場合にpre_get_postでセットしないよう修正 ・バグ修正:通常と検索のpre_get_postでメタキー指定が漏れていたので追加 ・バグ修正:カスタムタクソノミーのpre_get_postでメタキー指定が異なっていたので修正 --- archive-post-oder-plus.php | 8 +- class/class.apop.ui.php | 48 ++++++- css/apop-style.css | 16 ++- js/apop-style.js | 91 +++++++------ template/order.php | 7 +- template/setting.php | 200 +--------------------------- template/setting_parts_taxonomy.php | 65 +++++++++ util/apop-order-setting.php | 33 +++-- 8 files changed, 205 insertions(+), 263 deletions(-) create mode 100644 template/setting_parts_taxonomy.php diff --git a/archive-post-oder-plus.php b/archive-post-oder-plus.php index 2db47bf..536fa30 100644 --- a/archive-post-oder-plus.php +++ b/archive-post-oder-plus.php @@ -22,6 +22,9 @@ License: GPLv2 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +define( 'APOP_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); +define( 'APOP_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); + //メイン処理のクラスをインスタンス化 require_once __DIR__ . '/class/class.apop.order.php'; require_once __DIR__ . '/class/class.apop.ui.php'; @@ -31,10 +34,9 @@ $APOP = new APOP; //CSS, JSの読み込み add_action( 'admin_enqueue_scripts', 'register_my_styles' ); function register_my_styles() { - $plugin_url = plugin_dir_url( __FILE__ ); - wp_enqueue_style( 'hrc_post_style', $plugin_url . 'css/apop-style.css' ); + wp_enqueue_style( 'hrc_post_style', APOP_PLUGIN_URL . 'css/apop-style.css' ); wp_enqueue_script( 'jquery-ui-sortable' ); - wp_enqueue_script( 'post-sort-cat-order_js', $plugin_url . 'js/apop-style.js' ); + wp_enqueue_script( 'post-sort-cat-order_js', APOP_PLUGIN_URL . 'js/apop-style.js' ); } $APOP->set_query(); diff --git a/class/class.apop.ui.php b/class/class.apop.ui.php index 48c8b26..3201500 100644 --- a/class/class.apop.ui.php +++ b/class/class.apop.ui.php @@ -32,7 +32,7 @@ if ( ! class_exists( 'APOP_UI' ) ) { return implode( PHP_EOL, $list ); } - private static function crate_non_registerd_mark( $no_order ) { + private static function crate_non_registerd_mark( $no_order ): string { if ( ! empty( $no_order ) ) { return '■'; } @@ -44,6 +44,8 @@ if ( ! class_exists( 'APOP_UI' ) ) { return array( 'post_status' => array( 'publish', 'draft' ), 'posts_per_page' => - 1, + 'orderby' => 'meta_value_num', + 'order' => 'ASC', 'meta_query' => array( 'relation' => 'OR', array( @@ -58,13 +60,20 @@ if ( ! class_exists( 'APOP_UI' ) ) { ); } - - public static function get_all_taxonomies( $key ) { + private static function get_all_taxonomies( $key ) { if ( $key !== 'taxonomy' ) { return get_terms( array( 'taxonomy' => $key, 'get' => 'all' ) ); } + $all_custom_tax = get_taxonomies( array( 'public' => true, '_builtin' => false ) ); + $custom_tax_list = []; + foreach ( $all_custom_tax as $custom_tax ) { + $custom_tax_list = array_merge( $custom_tax_list, get_terms( array( + 'taxonomy' => $custom_tax, + 'get' => 'all' + ) ) ); + } - return get_taxonomies( array( 'public' => true, '_builtin' => false ) ); + return $custom_tax_list; } public static function get_cat_tag_list( $target, $key ): array { @@ -221,6 +230,37 @@ value="' . $sort_num . '"> ); } + public static function disp_tax_setting( $key, $title, $order_name ) { + $tax_data = APOP_UI::get_all_taxonomies( $key ); + if ( count( $tax_data ) > 0 ) { + $order_name = $order_name; + $order_tax = $key == 'post_tag' ? 'tag' : $key; + echo '' . $title . '設定'; + include APOP_PLUGIN_PATH . 'template/setting_parts_taxonomy.php'; + echo ''; + } + } + + public static function create_tax_per_page( $opt_per_page, $type, $id ): array { + $cat_per_page = $opt_per_page[ $type ][ $id ] ?? 'default'; + $checked = ''; + $cat_per_page_num = ''; + if ( isset( $opt_per_page[ $type ][ $id ] ) ) { + if ( $opt_per_page[ $type ][ $id ] != 'default' + && $opt_per_page[ $type ][ $id ] != '-1' + && $opt_per_page[ $type ][ $id ] != 'all' ) { + $checked = ' checked="checked"'; + $cat_per_page_num = $cat_per_page; + } + } + + return array( + '_per_page' => $cat_per_page, + '_checked' => $checked, + '_per_page_num' => $cat_per_page_num, + ); + } + public static function create_search_normal_list( $type ): array { $name_key = 'apop_' . $type . '_order_param'; $order_param = get_option( '_' . $name_key ); diff --git a/css/apop-style.css b/css/apop-style.css index c60f8e5..8e6650c 100644 --- a/css/apop-style.css +++ b/css/apop-style.css @@ -58,7 +58,7 @@ h3 { } .list-orders-inner { - width: calc((100% - 10px) / 2); + width: 45%;; margin: 1.5em 1em 0 0; padding: .5em; border: 1px solid #999; @@ -66,7 +66,7 @@ h3 { } .list-orders-inner.search_inner { - width: calc((100% - 10px) / 2); + width: 50%; } .apop_normal_order_target, @@ -82,7 +82,6 @@ h3 { p.submit.post-order .button-primary { position: absolute; bottom: 1em; - right: 1.5em; } dl.apop_setting_list { @@ -162,6 +161,17 @@ dl.apop_setting_list dd:first-of-type { margin-top: 1em; } +.order_setting_list > li { + padding: 1em; + border: 1px solid #ccc; +} + +.select_per_page { + margin-top: 1em; + padding-top: 1em; + border-top: 1px solid #ccc; +} + @media only screen and (max-width: 1264px) { .search_normal_sort .product-list { display: block; diff --git a/js/apop-style.js b/js/apop-style.js index f97ade7..c85a73d 100644 --- a/js/apop-style.js +++ b/js/apop-style.js @@ -10,12 +10,11 @@ jQuery(function ($) { change_search_order(); change_normal_order(); + //Tax select + select_tax(); + //per page - disp_tax_per_page(); - change_normal_per_page(); change_search_per_page(); - change_cat_per_page(); - change_tag_per_page(); change_tax_per_page(); @@ -99,56 +98,41 @@ jQuery(function ($) { }) } - function disp_tax_per_page() { - let box_count = $('.order_setting_list').length; - for (let i = 0; i < box_count; i++) { - $('.order_setting_list:eq(' + i + ')').click(function () { - let en_count = $('.order_setting_list:eq(' + i + ') [name^="_apop_"]:checked').length; - if (en_count == 0) { - $(this).parent().next('dt').addClass('hide_list').next('dd').addClass('hide_list'); - } else { - $(this).parent().next('dt').removeClass('hide_list').next('dd').removeClass('hide_list'); - } - }); - } - } + function select_tax() { + let select_cat_checkbox = $('.select_cat_checkbox'); + let input_chk_size = select_cat_checkbox.length; + let i = 0; + + for (i; i < input_chk_size; i++) { + let chk = $('.select_cat_checkbox:eq(' + i + '):checked').length; + if (chk == 1) { + $('.select_cat:eq(' + i + ')').siblings('.select_per_page').show(); + } else { + $('.select_cat:eq(' + i + ')').siblings('.select_per_page').hide(); + } + } + + select_cat_checkbox.click(function () { + let checked = $(this).prop('checked'); + if (checked) { + $(this).parent().parent().siblings('.select_per_page').show(200); + } else { + $(this).parent().parent().siblings('.select_per_page').hide(200); + } + }); - function change_normal_per_page() { - let per_page_cat = $('.per_page_normal'); - let per_page_input = $('.per_page_normal_input'); - change_per_page(per_page_cat, per_page_input); } function change_search_per_page() { let per_page_cat = $('.per_page_search'); let per_page_input = $('.per_page_search_input'); - change_per_page(per_page_cat, per_page_input); - } - function change_cat_per_page() { - let per_page_cat = $('.per_page_cat'); - let per_page_input = $('.per_page_cat_input'); - change_per_page(per_page_cat, per_page_input); - } - - function change_tag_per_page() { - let per_page_cat = $('.per_page_tag'); - let per_page_input = $('.per_page_tag_input'); - change_per_page(per_page_cat, per_page_input); - } - - function change_tax_per_page() { - let per_page_cat = $('.per_page_tax'); - let per_page_input = $('.per_page_tax_input'); - change_per_page(per_page_cat, per_page_input); - } - - function change_per_page(per_page_cat, per_page_input) { if (per_page_input.val() == '') { per_page_input.prop('disabled', true); } else { per_page_input.prop('disabled', false); } + per_page_cat.click(function () { if ($(this).val() != 'default' && $(this).val() != '-1' && $(this).val() != 'all') { per_page_input.prop('disabled', false); @@ -159,4 +143,27 @@ jQuery(function ($) { }) } + function change_tax_per_page() { + let set_number = $('.set_number'); + let input_chk_size = set_number.length; + + let i = 0; + for (i; i < input_chk_size; i++) { + let input_num_box = $('.set_number:eq(' + i + ')').siblings('.per_page_cat_input'); + if (input_num_box.val() == '') { + input_num_box.prop('disabled', true); + } else { + input_num_box.prop('disabled', false); + } + } + + $('.per_page_cat').click(function () { + if ($(this).hasClass('set_number')) { + $(this).siblings('.per_page_cat_input').prop('disabled', false); + } else { + $(this).parents('li').find('.per_page_cat_input').val('').prop('disabled', true); + } + }); + } + }); \ No newline at end of file diff --git a/template/order.php b/template/order.php index 3537a6c..5834128 100644 --- a/template/order.php +++ b/template/order.php @@ -33,7 +33,7 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' ); value="1">標準
  • + value="2">ドラッグソート
    @@ -45,7 +45,7 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
    - + @@ -72,7 +72,8 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' ); value="1">標準
  • + value="2">ドラッグソート +
    diff --git a/template/setting.php b/template/setting.php index e80415d..30b3e70 100644 --- a/template/setting.php +++ b/template/setting.php @@ -1,17 +1,8 @@ - -

    設定

    @@ -47,194 +38,9 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' ); - 0 ): $disp = false; ?> - - カテゴリー設定 - -
    -
    対象
    -
    -
      - - term_id ] ?? ''; - APOP_UI::is_disp_per_page( $disp, $check_slug ); - ?> -
    • -
      - -
      -
    • - -
    -
    - >1ページ表示件数 - > - -
      -
    • - -
    • -
    • -
    • -
    • -
    • -
    • - -
    • -
    - -
    - - - - 0 ): $disp = false; ?> - - タグ設定 - -
    -
    対象
    -
    -
      - - term_id ] ?? ''; - APOP_UI::is_disp_per_page( $disp, $check_slug ); - ?> -
    • -
      - -
      -
    • - -
    -
    - >1ページ表示件数 - > -
      -
    • - -
    • -
    • -
    • -
    • -
    • -
    • -
    • -
    - -
    - - - - - 0 ): $disp = false; ?> - - カスタム分類 - -
    -
    対象
    -
    -
      - - - term_id ] ?? ''; - APOP_UI::is_disp_per_page( $disp, $check_slug ); - ?> -
    • -
      - -
      -
    • - - -
    -
    - >1ページ表示件数 - > - -
      -
    • - -
    • -
    • -
    • -
    • -
    • -
    • -
    • -
    - -
    - - - + + +

    diff --git a/template/setting_parts_taxonomy.php b/template/setting_parts_taxonomy.php new file mode 100644 index 0000000..0c185e1 --- /dev/null +++ b/template/setting_parts_taxonomy.php @@ -0,0 +1,65 @@ + + +
    +
    対象
    +
    +
      + + term_id ] ?? ''; + APOP_UI::is_disp_per_page( $disp, $check_slug ); + ?> +
    • +
      + +
      + term_id ); ?> +
      +
        +
      • + +
      • +
      • +
      • +
      • +
      • +
      • + +
      • +
      +
      +
    • + +
    +
    +
    +query_vars['category_name'] ); - $this->set_orderby( $query, $cat->term_id, 'category', 'cat' ); + if ( isset( $cat->term_id ) ) { + $this->set_orderby( $query, $cat->term_id, 'category', 'cat' ); + } } if ( is_tag() ) { $tag = get_term_by( 'slug', $query->query_vars['tag'], 'post_tag' ); - $this->set_orderby( $query, $tag->term_id, 'post_tag', 'tag' ); + if ( isset( $tag->term_id ) ) { + $this->set_orderby( $query, $tag->term_id, 'post_tag', 'tag' ); + } } if ( is_tax() ) { - $this->set_orderby( $query, get_queried_object_id(), 'tax', 'tax' ); + if ( get_queried_object_id() ) { + $this->set_orderby( $query, get_queried_object_id(), 'tax', 'tax' ); + } } } - private function set_per_page( $query, $target ) { + private function set_per_page( $query, $target, $id = null ) { $per_page_option = get_option( '_apop_per_page' ); + if ( is_null( $id ) ) { + $per_page_option_data = $per_page_option[ $target ]; + } else { + $per_page_target = $target == 'tax' ? 'taxonomy' : $target; + $per_page_option_data = $per_page_option[ $per_page_target ][ $id ]; + } - if ( ! isset( $per_page_option[ $target ] ) ) { + if ( ! isset( $per_page_option_data ) ) { return; } - if ( $per_page_option[ $target ] == 'default' ) { + if ( $per_page_option_data == 'default' ) { return; } - if ( $per_page_option[ $target ] == 'all' ) { + if ( $per_page_option_data == 'all' ) { $target = 'search'; } - $query->set( 'posts_per_page', $per_page_option[ $target ] ); + $query->set( 'posts_per_page', $per_page_option_data ); } private function set_search_normal_orderby( $query, $type ) { $apop_order = get_option( '_apop_' . $type . '_order' ) ?? 1; if ( $apop_order == 2 ) { - //$query->set( 'meta_key', '_apop_post_' . $type ); - $query->set( 'meta_query', self::get_all_post_args( '_apop_' . $type . '_order' ) ); $query->set( 'orderby', array( 'meta_value_num' => 'ASC' ) ); + $query->set( 'meta_query', self::get_all_post_args( '_apop_post_' . $type ) ); } else { $apop_order_param = get_option( '_apop_' . $type . '_order_param' ); $sort_param = array( 1 => 'ASC', 2 => 'DESC' ); @@ -89,7 +100,7 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) { //$query->set( 'meta_key', $sort_meta_key ); $query->set( 'meta_query', self::get_all_post_args( $sort_meta_key ) ); $query->set( 'orderby', array( 'meta_value_num' => 'ASC' ) ); - $this->set_per_page( $query, self::get_per_page_tag( $target ) ); + $this->set_per_page( $query, self::get_per_page_tag( $target ), $id ); } else { self::set_search_normal_orderby( $query, 'normal' ); } -- 2.43.0