From f6d64404a76a1f50e5e208b8646e7ab58e6d1cb5 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 25 Jun 2021 20:58:52 +0900 Subject: [PATCH] =?UTF-8?q?WP=20PLUGIN=E3=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・カスタムフィールドの必須チェック漏れの修正 ・既存カスタムフィールド選択も可能なよう修正 ・ソートのリストに背景色を設定 ・並べ替え設定ページの更新ボタン位置を修正 ・カテゴリー、タグ、カスタム分類のソート対象選択のラジオボタン並び順を標準、検索と同一になるよう修正 --- archive-post-order-plus.php | 2 +- class/class.apop.apop_post.php | 17 +++--- class/class.apop.apop_ui.php | 82 ++++++++++++++++---------- class/class.apop.order.php | 1 + css/apop-style.css | 12 +++- js/apop-style.js | 60 ++++++++++++++++++- readme.txt | 12 +++- template/order.php | 10 ++-- template/order_parts_taxonomy.php | 7 ++- template/setting_post_custom_field.php | 23 ++++++-- util/apop-customfield-select.php | 27 +++++++++ util/apop-order-setting.php | 6 +- 12 files changed, 202 insertions(+), 57 deletions(-) create mode 100644 util/apop-customfield-select.php diff --git a/archive-post-order-plus.php b/archive-post-order-plus.php index 583318a..791a011 100644 --- a/archive-post-order-plus.php +++ b/archive-post-order-plus.php @@ -5,7 +5,7 @@ Plugin URI: https://develop.n-k-y.net/wordpress/wp_plugin/apop/ Author: NBK45 Author URI: https://develop.n-k-y.net Description: 通常表示、検索表示、タクソノミー毎に投稿の表示順を設定するプラグイン -Version: 1.0.1 +Version: 1.1.0 License: GPLv2 */ diff --git a/class/class.apop.apop_post.php b/class/class.apop.apop_post.php index f17e540..7075010 100644 --- a/class/class.apop.apop_post.php +++ b/class/class.apop.apop_post.php @@ -11,6 +11,7 @@ if ( ! class_exists( 'APOP_POST' ) ) { const TEMPLATE_DIR = __DIR__ . '/../template/'; private $order_field = array(); + private $custom_field_type = array(); private $name_keys = array(); private $order_param_keys = array( 'custom_field', @@ -71,20 +72,21 @@ if ( ! class_exists( 'APOP_POST' ) ) { if ( $update ) { $this->name_keys[] = $param[ $order_param_key ]['field']['meta_key']; } else { - $this->order_field[ $key ][] = $param[ $order_param_key ]['field']['meta_key']; + $this->custom_field_type[ $key ][] = $param[ $order_param_key ]['field']['custom_field_type']; + $this->order_field[ $key ][] = $param[ $order_param_key ]['field']['meta_key']; } } } } private function create_order_tax_field_data( $param, $update = false ) { - $term_ids = $this->create_post_term_ids(); + $term_ids = $this->create_post_term_ids(); $sort_types = get_option( '_apop_tax_sort_type' ); foreach ( $term_ids as $term_id ) { - if(!isset($sort_types[$term_id])){ + if ( ! isset( $sort_types[ $term_id ] ) ) { continue; } - if($sort_types[$term_id] == '1'){ + if ( $sort_types[ $term_id ] == '1' ) { break; } foreach ( $this->order_param_keys as $order_param_key ) { @@ -93,7 +95,8 @@ if ( ! class_exists( 'APOP_POST' ) ) { if ( $update ) { $this->name_keys[] = $param[ $term_id ][ $order_param_key ]['field']['meta_key']; } else { - $this->order_field['tax'][] = $param[ $term_id ][ $order_param_key ]['field']['meta_key']; + $this->custom_field_type['tax'][] = $param[ $term_id ][ $order_param_key ]['field']['custom_field_type']; + $this->order_field['tax'][] = $param[ $term_id ][ $order_param_key ]['field']['meta_key']; } } } @@ -118,10 +121,10 @@ if ( ! class_exists( 'APOP_POST' ) ) { return $term_ids; } - private function get_custom_field_data( $custom_filed_name ) { + private function get_custom_field_data( $custom_filed_name, $prefix ) { global $post; - return get_post_meta( $post->ID, APOP_CUSTOM_FIELD_PREFIX . $custom_filed_name, true ); + return get_post_meta( $post->ID, $prefix . $custom_filed_name, true ); } // カスタムフィールドの値を保存 diff --git a/class/class.apop.apop_ui.php b/class/class.apop.apop_ui.php index 99e910c..80d7321 100644 --- a/class/class.apop.apop_ui.php +++ b/class/class.apop.apop_ui.php @@ -4,8 +4,13 @@ if ( ! defined( 'ABSPATH' ) ) { } // Exit if accessed directly if ( ! class_exists( 'APOP_UI' ) ) { + + require_once __DIR__ . '/../util/apop-customfield-select.php'; + class APOP_UI { + use CUSTOMFIELD_SELECT; + public static function get_order_type( $type ) { $type_data = get_option( $type ); if ( ! $type_data ) { @@ -295,13 +300,12 @@ value="' . esc_html( $sort_num ) . '"> ); $list = array(); foreach ( $target_keys as $target_key ) { - $cnv_order_params = self::set_order_list_param( $order_param, $target_key ); - $use = $cnv_order_params['use']; - $sort = $cnv_order_params['sort']; - $no_order_class = $cnv_order_params['no_order_class']; - $field_metakey_input = ''; - $name_use_key = '_' . $name_key . '[' . $target_key . '][use]'; - $name_sort_key = '_' . $name_key . '[' . $target_key . '][sort]'; + $cnv_order_params = self::set_order_list_param( $order_param, $target_key ); + $use = $cnv_order_params['use']; + $sort = $cnv_order_params['sort']; + $no_order_class = $cnv_order_params['no_order_class']; + $name_use_key = '_' . $name_key . '[' . $target_key . '][use]'; + $name_sort_key = '_' . $name_key . '[' . $target_key . '][sort]'; if ( strpos( $target_key, 'custom_field' ) !== false ) { $target_key_check_class = 'custom_field_check'; } else { @@ -336,27 +340,41 @@ value="' . esc_html( $sort_num ) . '"> } private static function create_custom_field_sort_type( $name_key, $target_key, $cnv_order_params ) { - $meta_key = $cnv_order_params[ $target_key ]['meta_key']; - $value_type = $cnv_order_params[ $target_key ]['value_type']; - $name_meta_key = '_' . $name_key . '[' . $target_key . '][field][meta_key]'; - $name_value_type = '_' . $name_key . '[' . $target_key . '][field][value_type]'; + $meta_key = $cnv_order_params[ $target_key ]['meta_key']; + $value_type = $cnv_order_params[ $target_key ]['value_type']; + $custom_field_type = $cnv_order_params[ $target_key ]['custom_field_type']; + $name_meta_key = '_' . $name_key . '[' . $target_key . '][field][meta_key]'; + $name_value_type = '_' . $name_key . '[' . $target_key . '][field][value_type]'; + $name_custom_field_type = '_' . $name_key . '[' . $target_key . '][field][custom_field_type]'; echo '
-
カスタムフィールドキー:
- -
-
-
値タイプ:
- - -
-
'; +
+ + +
'; + self::set_all_customfield_select( $name_meta_key ); + echo ' +
+
+
値タイプ:
+ + +
+ '; } private static function set_order_list_param( $order_param, $target_key ): array { @@ -369,8 +387,9 @@ value="' . esc_html( $sort_num ) . '"> if ( strpos( $target_key, 'custom_field' ) !== false ) { $param[ $target_key ] = array( - 'meta_key' => '', - 'value_type' => 'meta_value', + 'meta_key' => '', + 'value_type' => 'meta_value', + 'custom_field_type' => '1', ); } @@ -382,8 +401,9 @@ value="' . esc_html( $sort_num ) . '"> ); if ( strpos( $target_key, 'custom_field' ) !== false ) { $param[ $target_key ] = array( - 'meta_key' => $order_param[ $target_key ]['field']['meta_key'] ?? '', - 'value_type' => $order_param[ $target_key ]['field']['value_type'] ?? 'meta_value', + 'meta_key' => $order_param[ $target_key ]['field']['meta_key'] ?? '', + 'value_type' => $order_param[ $target_key ]['field']['value_type'] ?? 'meta_value', + 'custom_field_type' => $order_param[ $target_key ]['field']['custom_field_type'] ?? '1', ); } } diff --git a/class/class.apop.order.php b/class/class.apop.order.php index 90af176..104a1f0 100644 --- a/class/class.apop.order.php +++ b/class/class.apop.order.php @@ -4,6 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) { } // Exit if accessed directly if ( ! class_exists( 'APOP' ) ) { + require_once __DIR__ . '/../util/apop-order-setting.php'; class APOP { diff --git a/css/apop-style.css b/css/apop-style.css index dfa9a04..050c0f2 100644 --- a/css/apop-style.css +++ b/css/apop-style.css @@ -139,7 +139,14 @@ dl.apop-setting-list-dd dd input { } .enable-box .product-list { - padding: 1em 0; + padding: 1em .3em; + background: #eee; +} + +.custom_field_key_select, +.custom_field_key { + display: none; + width: 50%; } .search-normal-sort .product-list { @@ -209,10 +216,13 @@ dl.apop-setting-list-dd dd input { border-top: 1px solid #ccc; } +.sort-custom-field-types, .sort-custom-field-inner { display: flex; + justify-content: space-between; } +.sort-custom-field-types:first-child, .sort-custom-field-inner:first-child { margin-bottom: .5em; } diff --git a/js/apop-style.js b/js/apop-style.js index 592192f..30dc35b 100644 --- a/js/apop-style.js +++ b/js/apop-style.js @@ -18,6 +18,8 @@ jQuery(function ($) { change_normal_field_sort(); + custom_field_select(); + function change_tab_menu() { let apop_submit_type = $('#apop_submit_type'); let order_nav_list = $('.post-order-nav li'); @@ -153,7 +155,7 @@ jQuery(function ($) { function change_normal_field_sort() { let s_box = $('.sort_box'); - let targets = '.custom_field_check, .sort_date_check, .sort_title_check, .sort_ID_check, .sort_modified_check'; + let targets = '.sort_date_check, .sort_title_check, .sort_ID_check, .sort_modified_check'; s_box.find(targets).each(function () { if ($(this).prop('checked') == false) { $(this).parents('.product-list-sort-type').find('.order_param').prop('disabled', true); @@ -174,4 +176,60 @@ jQuery(function ($) { }); } + function custom_field_select() { + let s_box = $('.sort_box'); + let targets = $('.custom-field-type'); + let en_dis_check = $('.custom_field_check'); + + // カスタムフィールドソートの有効・無効を判定する。 + // 有効の場合はカスタムフィールド選択or追加のステータスに応じてテキストエリアとセレクトタグenableに変更し表示を切り替える。 + // 無効の場合はカスタムフィールドのテキストエリアとセレクトタグをDisableにし無効ボックスに移動する。 + s_box.find('.custom_field_check').each(function () { + if ($(this).prop('checked') == false) { + let disable_list = $(this).parents('.sort_box').find('.disable-normal-list'); + $(this).parents('li').appendTo(disable_list); + dis_list($(this)); + } else { + let target_type = $(this).parents('.product-list-sort-type').find('.custom-field-type').filter(':checked').val(); + en_dis_list($(this), target_type); + } + }); + + //有効・無効チェックボックスクリック時 + en_dis_check.on('click', function () { + if ($(this).prop('checked') == true) { + let enable_list = $(this).parents('.sort_box').find('.post-order-list'); + let target_type = $(this).parents('.product-list-sort-type').find('.custom-field-type').filter(':checked').val(); + $(this).parents('.product-list-sort-type').find('.order_param').prop('disabled', false); + $(this).parents('li').appendTo(enable_list).removeClass('no-order').hide().fadeIn(200); + en_dis_list($(this), target_type); + } else { + let disable_list = $(this).parents('.sort_box').find('.disable-normal-list'); + $(this).parents('.product-list-sort-type').find('.order_param').prop('disabled', true); + $(this).parents('li').appendTo(disable_list).addClass('no-order').hide().fadeIn(200); + dis_list($(this)); + } + }); + + //選択・追加のカスタムフィールド種類ラジオボタンのクリック + targets.on('click', function () { + en_dis_list($(this), $(this).val()); + }); + + function dis_list(obj) { + obj.parents('.product-list-sort-type').find('.custom_field_key').prop('disabled', true); + obj.parents('.product-list-sort-type').find('.custom_field_key_select').prop('disabled', true); + } + + function en_dis_list(obj, type) { + if (type == 1) { + obj.parents('.product-list-sort-type').find('.custom_field_key_select').prop('disabled', false).show(); + obj.parents('.product-list-sort-type').find('.custom_field_key').prop('disabled', true).hide(); + } else if (type == 2) { + obj.parents('.product-list-sort-type').find('.custom_field_key').prop('disabled', false).show(); + obj.parents('.product-list-sort-type').find('.custom_field_key_select').prop('disabled', true).hide(); + } + } + } + }); \ No newline at end of file diff --git a/readme.txt b/readme.txt index 7baddee..9a99dfd 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: 投稿,表示順,投稿表示順,カテゴリー,タグ,カスタム分類 Requires at least: 4.9 Tested up to: 5.7.2 Requires PHP: 7.0 -Stable tag: 1.0.0 +Stable tag: 1.1.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -50,6 +50,16 @@ License URI: https://www.gnu.org/licenses/gpl-2.0.html = 1.0.0 = 初回リリース += 1.0.1 = +検索のソート対象にカスタム投稿を追加 + += 1.1.0 = +カスタムフィールドの必須チェック漏れの修正 +既存カスタムフィールド選択も可能なよう修正 +ソートのリストに背景色を設定 +並べ替え設定ページの更新ボタン位置を修正 +カテゴリー、タグ、カスタム分類のソート対象選択のラジオボタン並び順を標準、検索と同一になるよう修正 + == Upgrade Notice == No information diff --git a/template/order.php b/template/order.php index 2e86515..e143c81 100644 --- a/template/order.php +++ b/template/order.php @@ -12,8 +12,8 @@ $submit_type = APOP_UI::input_post_filter( 'apop_submit_type', 'str' );
  • カスタム分類
  • -
    -
    + +
    @@ -106,7 +106,7 @@ $submit_type = APOP_UI::input_post_filter( 'apop_submit_type', 'str' );
    -

    - - + +

    + \ No newline at end of file diff --git a/template/order_parts_taxonomy.php b/template/order_parts_taxonomy.php index 0d6b4c9..f999fd2 100644 --- a/template/order_parts_taxonomy.php +++ b/template/order_parts_taxonomy.php @@ -10,7 +10,7 @@ if ( isset( $order_target_data[ $tax_data->term_id ] ) ) { $order_target = $order_target_data[ $tax_data->term_id ]; } else { - $order_target = 1; + $order_target = 2; } ?> @@ -36,6 +36,7 @@ +

    並べ替えを登録するには「変更を保存」をクリックしてください

    diff --git a/template/setting_post_custom_field.php b/template/setting_post_custom_field.php index 8e7bf44..8f38bee 100644 --- a/template/setting_post_custom_field.php +++ b/template/setting_post_custom_field.php @@ -5,13 +5,24 @@
    labels[ $type ] ); ?>
      - + $item ): ?> -
    • - -
    • + custom_field_type[ $type ][ $idx ] == '2' ) { + $custom_field_prefix = APOP_CUSTOM_FIELD_PREFIX; + } else { + $custom_field_prefix = ''; + } + ?> + +
    • + +
    • + + [ ]はカスタムフィールドから設定してください +
    diff --git a/util/apop-customfield-select.php b/util/apop-customfield-select.php new file mode 100644 index 0000000..f62b216 --- /dev/null +++ b/util/apop-customfield-select.php @@ -0,0 +1,27 @@ +'; + foreach ( $selects as $select ) { + echo ''; + } + echo ''; + } + + private static function get_all_custom_fields() { + global $wpdb; + + //アンダーバーで始まるシステム系のパラメータは除外する + return $wpdb->get_results( 'SELECT DISTINCT meta_key FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key NOT LIKE ' . "'\_%' ORDER BY meta_key ASC" ); + } + } +} \ No newline at end of file diff --git a/util/apop-order-setting.php b/util/apop-order-setting.php index 4c1baef..453b7df 100644 --- a/util/apop-order-setting.php +++ b/util/apop-order-setting.php @@ -90,7 +90,11 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) { private static function set_custom_filed_sort( &$orderby, $order_col, $orders, $sort_param ): array { if ( strpos( $order_col, 'custom_field' ) !== false ) { - $meta_key = APOP_CUSTOM_FIELD_PREFIX . $orders['field']['meta_key']; + if($orders['field']['custom_field_type'] == 2){ + $meta_key = APOP_CUSTOM_FIELD_PREFIX . $orders['field']['meta_key']; + }else{ + $meta_key = $orders['field']['meta_key']; + } $type = 'CHAR'; if ( $orders['field']['value_type'] == 'meta_value_num' ) { $type = 'NUMERIC';