WP PLUGIN 

・カスタムフィールドの必須チェック漏れの修正
・既存カスタムフィールド選択も可能なよう修正
・ソートのリストに背景色を設定
・並べ替え設定ページの更新ボタン位置を修正
・カテゴリー、タグ、カスタム分類のソート対象選択のラジオボタン並び順を標準、検索と同一になるよう修正
This commit is contained in:
2021-06-25 20:58:52 +09:00
parent c7996062fa
commit f6d64404a7
12 changed files with 202 additions and 57 deletions
+1 -1
View File
@@ -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
*/
+5 -2
View File
@@ -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,6 +72,7 @@ if ( ! class_exists( 'APOP_POST' ) ) {
if ( $update ) {
$this->name_keys[] = $param[ $order_param_key ]['field']['meta_key'];
} else {
$this->custom_field_type[ $key ][] = $param[ $order_param_key ]['field']['custom_field_type'];
$this->order_field[ $key ][] = $param[ $order_param_key ]['field']['meta_key'];
}
}
@@ -93,6 +95,7 @@ if ( ! class_exists( 'APOP_POST' ) ) {
if ( $update ) {
$this->name_keys[] = $param[ $term_id ][ $order_param_key ]['field']['meta_key'];
} else {
$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 );
}
// カスタムフィールドの値を保存
+25 -5
View File
@@ -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 ) {
@@ -299,7 +304,6 @@ value="' . esc_html( $sort_num ) . '">
$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]';
if ( strpos( $target_key, 'custom_field' ) !== false ) {
@@ -338,21 +342,35 @@ 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'];
$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 '<div class="sort-custom-field">
<div class="sort-custom-field-inner"><div class="sort-custom-field-inner-label">カスタムフィールドキー:</div>
<input type="text" class="custom_field_key" name="' . esc_attr( $name_meta_key ) . '" value="' . esc_attr( $meta_key ) . '">
<div class="sort-custom-field-types"><div class="sort-custom-field-inner-label">
<label>
<input type="radio"
class="custom-field-type"
name="' . esc_attr( $name_custom_field_type ) . '"
value="1"' . esc_attr( self::set_search_normal_checked( $custom_field_type, '1' ) ) . '>選択</label>
<label>
<input type="radio"
class="custom-field-type"
name="' . esc_attr( $name_custom_field_type ) . '"
value="2"' . esc_attr( self::set_search_normal_checked( $custom_field_type, '2' ) ) . '>追加</label>
</div>';
self::set_all_customfield_select( $name_meta_key );
echo '<input type="text" class="custom_field_key" name="' . esc_attr( $name_meta_key ) . '" value="' . esc_attr( $meta_key ) . '" required>
</div>
<div class="sort-custom-field-inner">
<div class="sort-custom-field-inner-label">値タイプ:</div>
<label class="sort-custom-field-text-label">
<input type="radio"
class="custom_field_meta_value"
class="custom-field-meta-value"
name="' . esc_attr( $name_value_type ) . '"
value="meta_value"' . esc_attr( self::set_search_normal_checked( $value_type, 'meta_value' ) ) . '>テキスト</label>
<label><input type="radio"
class="custom_field_meta_value"
class="custom-field-meta-value"
name="' . esc_attr( $name_value_type ) . '"
value="meta_value_num"' . esc_attr( self::set_search_normal_checked( $value_type, 'meta_value_num' ) ) . '>数値</label>
</div>
@@ -371,6 +389,7 @@ value="' . esc_html( $sort_num ) . '">
$param[ $target_key ] = array(
'meta_key' => '',
'value_type' => 'meta_value',
'custom_field_type' => '1',
);
}
@@ -384,6 +403,7 @@ value="' . esc_html( $sort_num ) . '">
$param[ $target_key ] = array(
'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',
);
}
}
+1
View File
@@ -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 {
+11 -1
View File
@@ -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;
}
+59 -1
View File
@@ -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();
}
}
}
});
+11 -1
View File
@@ -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
+2 -2
View File
@@ -12,8 +12,8 @@ $submit_type = APOP_UI::input_post_filter( 'apop_submit_type', 'str' );
<li>カスタム分類</li>
</ul>
</nav>
<div class="post-order-box-outer">
<form action="" method="post">
<div class="post-order-box-outer">
<?php wp_nonce_field( 'sh_options' ); ?>
<input id="apop_submit_type" type="hidden" name="apop_submit_type"
value="<?php echo esc_attr( $submit_type ); ?>">
@@ -106,7 +106,7 @@ $submit_type = APOP_UI::input_post_filter( 'apop_submit_type', 'str' );
<?php include APOP_PLUGIN_PATH . 'template/order_parts_taxonomy.php'; ?>
</div>
</div>
</div>
<p class="apop-submit"><input type="submit" name="submit" class="button-primary" value="変更を保存"/></p>
</form>
</div>
</div>
+4 -3
View File
@@ -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;
}
?>
<ul class="sort-menu-list"
@@ -19,13 +19,13 @@
<label>
<input class="sort_menu" type="radio"
name="_apop_tax_sort_type[<?php echo esc_attr( $tax_data->term_id ); ?>]"
value="1"<?php checked( $order_target, 1 ); ?>>ドラッグソート</label>
value="2"<?php checked( $order_target, 2 ); ?>>標準+カスタムフィールドソート</label>
</li>
<li>
<label>
<input class="sort_menu" type="radio"
name="_apop_tax_sort_type[<?php echo esc_attr( $tax_data->term_id ); ?>]"
value="2"<?php checked( $order_target, 2 ); ?>>標準+カスタムフィールドソート</label>
value="1"<?php checked( $order_target, 1 ); ?>>ドラッグソート</label>
</li>
</ul>
@@ -36,6 +36,7 @@
<?php echo APOP_UI::create_order_list( $tax_data, $tax_key ); ?>
</ul>
</div>
<div class="sort_box">
<hr>
<p>並べ替えを登録するには「変更を保存」をクリックしてください</p>
+14 -3
View File
@@ -5,13 +5,24 @@
<dt><?php echo esc_html( $this->labels[ $type ] ); ?></dt>
<dd>
<ul>
<?php foreach ( $items as $item ): ?>
<?php foreach ( $items as $idx => $item ): ?>
<?php if ( ! empty( $item ) ): ?>
<?php
if ( $this->custom_field_type[ $type ][ $idx ] == '2' ) {
$custom_field_prefix = APOP_CUSTOM_FIELD_PREFIX;
} else {
$custom_field_prefix = '';
}
?>
<?php if ( ! empty( $custom_field_prefix ) ): ?>
<li><label><?php echo esc_html( $item ); ?></label>
<input type="text"
name="<?php echo esc_attr( APOP_CUSTOM_FIELD_PREFIX . $item ); ?>"
value="<?php echo esc_attr( $this->get_custom_field_data( $item ) ); ?>"/>
name="<?php echo esc_attr( $custom_field_prefix . $item ); ?>"
value="<?php echo esc_attr( $this->get_custom_field_data( $item, $custom_field_prefix ) ); ?>"/>
</li>
<?php else: ?>
<?php echo esc_html( $item ); ?> ]はカスタムフィールドから設定してください
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
+27
View File
@@ -0,0 +1,27 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! trait_exists( 'CUSTOMFIELD_SELECT' ) ) {
trait CUSTOMFIELD_SELECT {
public static function set_all_customfield_select( $name_meta_key ) {
$selects = self::get_all_custom_fields();
echo '<select class="custom_field_key_select" name="' . esc_attr( $name_meta_key ) . '" required>';
foreach ( $selects as $select ) {
echo '<option value="' . esc_attr( $select->meta_key ) . '">' . esc_html( $select->meta_key ) . '</option>';
}
echo '</select>';
}
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" );
}
}
}
+4
View File
@@ -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 ) {
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';