ARCHIVE POST ORDER PLUS:カスタム投稿アーカイブの追加

カスタム投稿アーカイブ対応
全体設定で「全件」指定時に「全体設定に従う」の設定が反映されないバグの修正
This commit is contained in:
2021-07-19 19:47:26 +09:00
parent b8dcf1c44c
commit 4bc96228bd
16 changed files with 848 additions and 338 deletions
+32 -3
View File
@@ -47,13 +47,17 @@ if ( ! class_exists( 'APOP_POST' ) ) {
$this->create_order_field_data( get_option( '_apop_search_order_param' ), 'search' );
}
//カスタム投稿アーカイブソート
$this->create_order_custompost_data( get_option( '_apop_custompost_archive_order_param' ) );
//カテゴリー、タグ、カスタム分類
$this->create_order_tax_field_data( get_option( '_apop_tax_order_param' ) );
$this->labels = array(
'normal' => __('Your latest posts', APOP_DOMAIN),
'search' => __('Search', APOP_DOMAIN),
'tax' => __('Category, Tag, Custom Taxonomy', APOP_DOMAIN),
'normal' => __( 'Your latest posts', APOP_DOMAIN ),
'search' => __( 'Search', APOP_DOMAIN ),
'tax' => __( 'Category, Tag, Custom Taxonomy', APOP_DOMAIN ),
'custompost' => __( 'Custom posts archive', APOP_DOMAIN ),
);
require_once self::TEMPLATE_DIR . 'setting_post_custom_field.php';
@@ -80,6 +84,29 @@ if ( ! class_exists( 'APOP_POST' ) ) {
}
}
private function create_order_custompost_data( $param, $update = false ) {
global $post_type;
//カスタム投稿タイプでないときは処理を抜ける
if ( $post_type == 'page' || $post_type == 'post' ) {
return;
}
$archive_settings = get_option( '_apop_custompost_archive_sort_type' );
if ( array_key_exists( $post_type, $archive_settings ) && $archive_settings[ $post_type ] == 2 ) {
foreach ( $this->order_param_keys as $order_param_key ) {
if ( isset( $param[ $post_type ][ $order_param_key ]['field']['meta_key'] ) &&
! empty( $param[ $post_type ][ $order_param_key ]['field']['meta_key'] ) ) {
if ( $update ) {
$this->name_keys[] = $param[ $post_type ][ $order_param_key ]['field']['meta_key'];
} else {
$this->custom_field_type['custompost'][] = $param[ $post_type ][ $order_param_key ]['field']['custom_field_type'];
$this->order_field['custompost'][] = $param[ $post_type ][ $order_param_key ]['field']['meta_key'];
}
}
}
}
}
private function create_order_tax_field_data( $param, $update = false ) {
$term_ids = $this->create_post_term_ids();
$sort_types = get_option( '_apop_tax_sort_type' );
@@ -144,6 +171,8 @@ if ( ! class_exists( 'APOP_POST' ) ) {
$this->create_order_field_data( get_option( '_apop_normal_order_param' ), 'normal', true );
//検索ソート
$this->create_order_field_data( get_option( '_apop_search_order_param' ), 'search', true );
//カスタム投稿アーカイブ
$this->create_order_custompost_data( get_option( '_apop_custompost_archive_order_param' ), true );
//カテゴリー、タグ、カスタム分類
$this->create_order_tax_field_data( get_option( '_apop_tax_order_param' ), true );
}
+97 -51
View File
@@ -6,10 +6,11 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'APOP_UI' ) ) {
require_once __DIR__ . '/../util/apop-customfield-select.php';
require_once __DIR__ . '/../util/apop-customposts.php';
class APOP_UI {
use CUSTOMFIELD_SELECT;
use CUSTOMFIELD_SELECT, CUSTOMPOSTS;
public static function get_order_type( $type ) {
$type_data = get_option( $type );
@@ -68,6 +69,17 @@ if ( ! class_exists( 'APOP_UI' ) ) {
);
}
private static function get_all_custom_posts() {
$custom_posts = array_values( get_post_types( array( 'public' => true, '_builtin' => false ) ) );
$custom_post_data = array();
foreach ( $custom_posts as $custom_post ) {
$label = get_post_type_object( $custom_post )->label;
$custom_post_data[ $custom_post ] = $label;
}
return $custom_post_data;
}
private static function get_all_taxonomies( $key ) {
if ( $key !== 'taxonomy' ) {
return get_terms( array( 'taxonomy' => $key, 'get' => 'all' ) );
@@ -255,6 +267,37 @@ value="' . esc_html( $sort_num ) . '">
}
}
public static function disp_customposts_setting( $key, $title, $order_name ) {
$custom_post_data = APOP_UI::get_all_custom_posts();
if ( count( $custom_post_data ) > 0 ) {
$order_name = $order_name;
$order = $key;
echo '<tr><th scope="row">' . esc_html( $title ) . '</th><td>';
include APOP_PLUGIN_PATH . 'template/setting_parts_customposts.php';
echo '</td></tr>';
}
}
public static function create_custom_posts_per_page( $opt_per_page, $type, $slug ): array {
$cat_per_page = $opt_per_page[ $type ][ $slug ] ?? 'default';
$checked = '';
$cat_per_page_num = '';
if ( isset( $opt_per_page[ $type ][ $slug ] ) ) {
if ( $opt_per_page[ $type ][ $slug ] != 'default'
&& $opt_per_page[ $type ][ $slug ] != '-1'
&& $opt_per_page[ $type ][ $slug ] != '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_tax_per_page( $opt_per_page, $type, $id ): array {
$cat_per_page = $opt_per_page[ $type ][ $id ] ?? 'default';
$checked = '';
@@ -287,56 +330,7 @@ value="' . esc_html( $sort_num ) . '">
if ( isset( $order_param_base[ $id ] ) ) {
$order_param = $order_param_base[ $id ];
}
$target_keys = self::set_search_normal_target_keys( $order_param );
$target_values = array(
'date' => __( 'Published', APOP_DOMAIN ),
'title' => __( 'Post Title', APOP_DOMAIN ),
'ID' => 'ID',
'modified' => __( 'Modified', APOP_DOMAIN ),
'custom_field' => __( 'Custom filed 1', APOP_DOMAIN ),
'custom_field_2' => __( 'Custom filed 2', APOP_DOMAIN ),
'custom_field_3' => __( 'Custom filed 3', APOP_DOMAIN ),
'custom_field_4' => __( 'Custom filed 4', APOP_DOMAIN ),
);
$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'];
$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 {
$target_key_check_class = 'sort_' . $target_key . '_check';
}
echo '<li class="product-list' . esc_attr( $no_order_class ) . '">
<div class="product-list-type-label"><b>' . esc_attr( $target_values[ $target_key ] ) . '</b></div>
<div class="product-list-sort-type">
<label>
<input type="hidden" name="' . esc_attr( $name_use_key ) . '"
value="0"' . esc_attr( self::set_search_normal_checked( $use, 0 ) ) . '>
<span class="en_dis_label">' . __( 'Enabled', APOP_DOMAIN ) . '</span><input class="' . esc_html( $target_key_check_class ) . '"
type="checkbox" name="' . esc_attr( $name_use_key ) . '" value="1"' . esc_attr( self::set_search_normal_checked( $use, 1 ) ) . '>
</label>
<label>
<input class="order_param" type="radio"
name="' . esc_attr( $name_sort_key ) . '"
value="1"' . esc_attr( self::set_search_normal_checked( $sort, 1 ) ) . '>' . __( 'Asc', APOP_DOMAIN ) . '</label>
<label>
<input class="order_param" type="radio"
name="' . esc_attr( $name_sort_key ) . '"
value="2"' . esc_attr( self::set_search_normal_checked( $sort, 2 ) ) . '>' . __( 'Desc', APOP_DOMAIN ) . '</label>';
if ( strpos( $target_key, 'custom_field' ) !== false ) {
self::create_custom_field_sort_type( $name_key, $target_key, $cnv_order_params );
}
echo '</div>
</li>';
}
self::create_normal_sort_list( $name_key, $order_param );
}
private static function create_custom_field_sort_type( $name_key, $target_key, $cnv_order_params ) {
@@ -469,5 +463,57 @@ value="' . esc_html( $sort_num ) . '">
}
}
public static function create_normal_sort_list( $name_key, $order_param ) {
$target_keys = self::set_search_normal_target_keys( $order_param );
$target_values = array(
'date' => __( 'Published', APOP_DOMAIN ),
'title' => __( 'Post Title', APOP_DOMAIN ),
'ID' => 'ID',
'modified' => __( 'Modified', APOP_DOMAIN ),
'custom_field' => __( 'Custom filed 1', APOP_DOMAIN ),
'custom_field_2' => __( 'Custom filed 2', APOP_DOMAIN ),
'custom_field_3' => __( 'Custom filed 3', APOP_DOMAIN ),
'custom_field_4' => __( 'Custom filed 4', APOP_DOMAIN ),
);
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'];
$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 {
$target_key_check_class = 'sort_' . $target_key . '_check';
}
echo '<li class="product-list' . esc_attr( $no_order_class ) . '">
<div class="product-list-type-label"><b>' . esc_attr( $target_values[ $target_key ] ) . '</b></div>
<div class="product-list-sort-type">
<label>
<input type="hidden" name="' . esc_attr( $name_use_key ) . '"
value="0"' . esc_attr( self::set_search_normal_checked( $use, 0 ) ) . '>
<span class="en_dis_label">' . __( 'Enabled', APOP_DOMAIN ) . '</span><input class="' . esc_html( $target_key_check_class ) . '"
type="checkbox" name="' . esc_attr( $name_use_key ) . '" value="1"' . esc_attr( self::set_search_normal_checked( $use, 1 ) ) . '>
</label>
<label>
<input class="order_param" type="radio"
name="' . esc_attr( $name_sort_key ) . '"
value="1"' . esc_attr( self::set_search_normal_checked( $sort, 1 ) ) . '>' . __( 'Asc', APOP_DOMAIN ) . '</label>
<label>
<input class="order_param" type="radio"
name="' . esc_attr( $name_sort_key ) . '"
value="2"' . esc_attr( self::set_search_normal_checked( $sort, 2 ) ) . '>' . __( 'Desc', APOP_DOMAIN ) . '</label>';
if ( strpos( $target_key, 'custom_field' ) !== false ) {
self::create_custom_field_sort_type( $name_key, $target_key, $cnv_order_params );
}
echo '</div>
</li>';
}
}
}
}
+84 -20
View File
@@ -7,10 +7,13 @@ if ( ! class_exists( 'APOP' ) ) {
require_once __DIR__ . '/../util/apop-order-setting.php';
require_once __DIR__ . '/../util/apop-customfield-select.php';
require_once __DIR__ . '/../util/apop-customposts.php';
require_once __DIR__ . '/../util/apop-tax.php';
require_once __DIR__ . '/../util/apop-output.php';
class APOP {
use APOP_ORDER_SETTING, CUSTOMFIELD_SELECT;
use APOP_ORDER_SETTING, CUSTOMFIELD_SELECT, CUSTOMPOSTS, TAX, APOP_OUTPUT;
const TEMPLATE_DIR = __DIR__ . '/../template/';
@@ -55,6 +58,7 @@ if ( ! class_exists( 'APOP' ) ) {
'_apop_per_page', //1ページ表示件数
'_apop_tag_order', //タグ設定
'_apop_tax_order', //カスタムタクソノミー設定
'_apop_custompost_archive_order', //カスタム投稿設定
);
foreach ( $settings as $setting ) {
@@ -72,9 +76,26 @@ if ( ! class_exists( 'APOP' ) ) {
public function show_option_page() {
//-------------------------------------
// 最新の投稿表示
// ------------------------------------
//最新の投稿表示
$this->set_new_lists();
// 検索表示
$this->set_search_lists();
// カスタム投稿アーカイブ
$this->set_custompost_archive_list();
// タクソノミー
$this->set_tax_list();
require_once self::TEMPLATE_DIR . 'order.php';
}
//---------------------------------------------------------------------------------
// 最新の投稿表示
//---------------------------------------------------------------------------------
private function set_new_lists() {
$apop_normal_order = APOP_UI::input_post_filter( '_apop_normal_order', 'str' );
$apop_normal_order_param = APOP_UI::input_post_filter( '_apop_normal_order_param', 'array' );
$apop_post_normal = APOP_UI::input_post_filter( '_apop_post_normal', 'array' );
@@ -98,10 +119,12 @@ if ( ! class_exists( 'APOP' ) ) {
$this->update_search_normal_sort( $apop_post_normal, 'normal' );
require_once self::TEMPLATE_DIR . 'success.php';
}
}
//-------------------------------------
// 検索表示
// ------------------------------------
//---------------------------------------------------------------------------------
// 検索結果
//---------------------------------------------------------------------------------
private function set_search_lists() {
$apop_search_order = APOP_UI::input_post_filter( '_apop_search_order', 'str' );
$apop_search_order_param = APOP_UI::input_post_filter( '_apop_search_order_param', 'array' );
$apop_post_search = APOP_UI::input_post_filter( '_apop_post_search', 'array' );
@@ -125,10 +148,60 @@ if ( ! class_exists( 'APOP' ) ) {
$this->update_search_normal_sort( $apop_post_search, 'search' );
require_once self::TEMPLATE_DIR . 'success.php';
}
}
//-------------------------------------
// タクソノミー
// ------------------------------------
//検索結果と最近の投稿の表示順の保存
private function update_search_normal_sort( $apop_post_search_normal, $key ) {
$posts_sort = $apop_post_search_normal['post_sort'];
foreach ( $posts_sort as $post_id => $sort ) {
update_post_meta( $post_id, '_apop_post_' . $key, $sort );
}
}
//---------------------------------------------------------------------------------
// カスタム投稿アーカイブ
//---------------------------------------------------------------------------------
private function set_custompost_archive_list() {
$custompost_archive_sort_type = APOP_UI::input_post_filter( '_apop_custompost_archive_sort_type', 'array' );
$apop_custompost_archive_order_param = APOP_UI::input_post_filter( '_apop_custompost_archive_order_param', 'array' );
$apop_custompost_archive = APOP_UI::input_post_filter( '_apop_customposts', 'array' );
//カスタム投稿アーカイブのソートタイプ設定
if ( $custompost_archive_sort_type ) {
check_admin_referer( 'sh_options' );
update_option( '_apop_custompost_archive_sort_type', $custompost_archive_sort_type );
require_once self::TEMPLATE_DIR . 'success.php';
}
//カスタム投稿アーカイブの標準ソートパラメータ
if ( $apop_custompost_archive_order_param ) {
check_admin_referer( 'sh_options' );
update_option( '_apop_custompost_archive_order_param', $apop_custompost_archive_order_param );
require_once self::TEMPLATE_DIR . 'success.php';
}
//カスタム投稿アーカイブの投稿表示順設定
if ( $apop_custompost_archive ) {
check_admin_referer( 'sh_options' );
$this->update_custom_post_sort( $apop_custompost_archive );
require_once self::TEMPLATE_DIR . 'success.php';
}
}
//カスタム投稿アーカイブ表示順の保存
private function update_custom_post_sort( $post_value ) {
foreach ( $post_value as $custom_post_type => $posts ) {
foreach ( $posts as $post_id => $sort ) {
$sort_key = '_apop_customposts_' . $custom_post_type;
update_post_meta( $post_id, $sort_key, $sort );
}
}
}
//---------------------------------------------------------------------------------
// タクソノミー
//---------------------------------------------------------------------------------
private function set_tax_list() {
$tax_sort_type = APOP_UI::input_post_filter( '_apop_tax_sort_type', 'array' );
$apop_tax_order_param = APOP_UI::input_post_filter( '_apop_tax_order_param', 'array' );
$apop_post_category = APOP_UI::input_post_filter( '_apop_post_category', 'array' );
@@ -169,11 +242,9 @@ if ( ! class_exists( 'APOP' ) ) {
$this->update_post_sort( 'tax', $apop_post_tax );
require_once self::TEMPLATE_DIR . 'success.php';
}
require_once self::TEMPLATE_DIR . 'order.php';
}
//投稿表示順の設定
//タクソノミーの表示順の保存
private function update_post_sort( $target, $post_value ) {
$posts_sort = $post_value['post_sort'];
foreach ( $posts_sort as $cat_id => $posts ) {
@@ -184,13 +255,6 @@ if ( ! class_exists( 'APOP' ) ) {
}
}
private function update_search_normal_sort( $apop_post_search_normal, $key ) {
$posts_sort = $apop_post_search_normal['post_sort'];
foreach ( $posts_sort as $post_id => $sort ) {
update_post_meta( $post_id, '_apop_post_' . $key, $sort );
}
}
}
}