WP PLUGIN アーカイブページの投稿表示順設定

・検索と通常表示のオプションを追加
・項目の表示順を修正
・選択値によって表示/非表示の切り替えやフォームをDisabledにする等修正
・アンインストーラーを追加
This commit is contained in:
2021-05-07 21:19:14 +09:00
parent 803c742a9f
commit bacd6a1d72
8 changed files with 675 additions and 293 deletions
+109 -7
View File
@@ -6,7 +6,16 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'APOP_UI' ) ) {
class APOP_UI {
public static function get_all_search_posts( $type, $exclude_posts = [] ) {
public static function get_order_type( $type ) {
$type_data = get_option( $type );
if ( ! $type_data ) {
return 1;
}
return $type_data;
}
public static function get_all_search_normal_posts( $type, $key, $exclude_posts = [] ) {
$args = [
'post_status' => array( 'publish', 'draft' ),
'posts_per_page' => - 1,
@@ -15,13 +24,14 @@ if ( ! class_exists( 'APOP_UI' ) ) {
if ( $type == 'registered' ) {
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
$args['meta_key'] = '_apop_post_search';
$args['meta_key'] = '_apop_post_' . $key;
} else {
$exclude = implode( ',', $exclude_posts );
if ( ! empty( $exclude ) ) {
$args['exclude'] = $exclude;
}
}
return get_posts( $args );
}
@@ -156,7 +166,7 @@ value="' . $sort_num . '">
foreach ( $target_posts_no_order as $key => $target_post_no_order ) {
$sort_num_no_order = $sort_num + $key + 1;
$list[] = '
<li class="product-list no_order">
<li class="product-list no_order">&#9632;
<span class="sort-num-label">' . $sort_num_no_order . '</span>' . get_the_title( $target_post_no_order->ID ) . '
<input type="hidden" class="list_order"
name="_apop_post_' . self::create_post_sort_key( $tax_data->taxonomy, $tax_key ) . '[post_sort][' . $tax_data->term_id . '][' . $target_post_no_order->ID . ']"
@@ -190,20 +200,112 @@ value="' . $sort_num_no_order . '">
public static function create_cat_per_page( $opt_per_page, $type ): array {
$cat_per_page = $opt_per_page[ $type ] ?? 'default';
$set = '';
$checked = '';
$cat_per_page_num = '';
if ( isset( $opt_per_page[ $type ] ) ) {
if ( $opt_per_page[ $type ] != 'default' && $opt_per_page[ $type ] != '-1' ) {
$set = ' checked="checked"';
if ( $opt_per_page[ $type ] != 'default'
&& $opt_per_page[ $type ] != '-1'
&& $opt_per_page[ $type ] != 'all' ) {
$checked = ' checked="checked"';
$cat_per_page_num = $cat_per_page;
}
}
return array(
'_per_page' => $cat_per_page,
'_set' => $set,
'_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 );
$target_keys = self::set_search_normal_target_keys( $order_param );
$target_values = array(
'date' => '登録日',
'title' => 'タイトル',
'ID' => 'ID',
'modified' => '更新日',
);
$list = array();
foreach ( $target_keys as $target_key ) {
$use = $order_param[ $target_key ]['use'] ?? 0;
$sort = $order_param[ $target_key ]['sort'] ?? 2;
$alert = ! $order_param[ $target_key ]['use'] ? '<p>並べ替えを登録するには「変更を保存」をクリックしてください。</p>' : '';
$no_order_class = ! $order_param[ $target_key ]['use'] ? ' no_order' : '';
$list[] = '<li class="product-list' . $no_order_class . '">
<label>
<input type="hidden" name="_' . $name_key . '[' . $target_key . '][use]" value="0"' . self::set_search_normal_checked( $use, 0 ) . '>
<input type="checkbox" name="_' . $name_key . '[' . $target_key . '][use]" value="1"' . self::set_search_normal_checked( $use, 1 ) . '>
<b>' . $target_values[ $target_key ] . '</b>
</label>
&nbsp;&nbsp;
<label><input class="' . $name_key . '" type="radio"
name="_' . $name_key . '[' . $target_key . '][sort]"
value="1"' . self::set_search_normal_checked( $sort, 1 ) . '>昇順</label>
&nbsp;&nbsp;
<label><input class="' . $name_key . '" type="radio"
name="_' . $name_key . '[' . $target_key . '][sort]"
value="2"' . self::set_search_normal_checked( $sort, 2 ) . '>降順</label>
</li>';
}
return array(
implode( PHP_EOL, $list ),
$alert,
);
}
private static function set_search_normal_target_keys( $post_apop_search_order_param ) {
if ( $post_apop_search_order_param ) {
return array_keys( $post_apop_search_order_param );
}
return array(
'date',
'title',
'ID',
'modified',
);
}
private static function set_search_normal_checked( $param, $default ): string {
if ( $param == $default ) {
return ' checked="checked"';
}
return '';
}
public static function input_post_filter( $var_name, $type ) {
if ( $type == 'array' ) {
return filter_input( INPUT_POST, $var_name, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
}
if ( $type == 'str' ) {
return filter_input( INPUT_POST, $var_name );
}
}
public static function is_disp_per_page( &$disp, $disp_per_page ) {
if ( $disp_per_page ) {
$disp = true;
}
}
public static function create_disp_class( $disp ) {
if ( ! $disp ) {
return ' class="hide_list"';
}
}
public static function create_none_select_msg( $str ) {
return '<p>並べ替えをカスタマイズする' . $str . 'は選択されていません。</p>';
}
public static function none_registerd_alert_msg() {
return '<div class="no_registered_exp">&#9632;の項目は未登録項目です。ドラッグして並び順を変更後に「変更を保存」をクリックしてください。</div>';
}
}
}