WP PLUGIN アーカイブページの投稿表示順設定
・検索と通常表示のオプションを追加 ・項目の表示順を修正 ・選択値によって表示/非表示の切り替えやフォームをDisabledにする等修正 ・アンインストーラーを追加
This commit is contained in:
+77
-33
@@ -29,7 +29,7 @@ if ( ! class_exists( 'APOP' ) ) {
|
||||
add_submenu_page(
|
||||
'apop_post_sort', // parent_slug
|
||||
'Sort taxonomy', // page_title
|
||||
'設定', // menu_title
|
||||
'表示件数・対象設定', // menu_title
|
||||
'administrator', // capability
|
||||
'apop_post_sort', // menu_slug
|
||||
array( $this, 'display_setting_page' ) // function
|
||||
@@ -45,63 +45,108 @@ if ( ! class_exists( 'APOP' ) ) {
|
||||
}
|
||||
|
||||
public function display_setting_page() {
|
||||
if ( isset( $_POST['_apop_cat_order'] )
|
||||
|| isset( $_POST['_apop_tag_order'] )
|
||||
|| isset( $_POST['_apop_tax_order'] ) ) {
|
||||
|
||||
check_admin_referer( 'sh_options' );
|
||||
$settings = array(
|
||||
'_apop_cat_order', //カテゴリー設定
|
||||
'_apop_per_page', //1ページ表示件数
|
||||
'_apop_tag_order', //タグ設定
|
||||
'_apop_tax_order', //カスタムタクソノミー設定
|
||||
);
|
||||
|
||||
$settings = array(
|
||||
'_apop_cat_order', //カテゴリー設定
|
||||
'_apop_per_page', //1ページ表示件数
|
||||
'_apop_tag_order', //タグ設定
|
||||
'_apop_tax_order', //カスタムタクソノミー設定
|
||||
);
|
||||
foreach ( $settings as $setting ) {
|
||||
$opt = $_POST[ $setting ];
|
||||
foreach ( $settings as $setting ) {
|
||||
$opt = APOP_UI::input_post_filter( $setting, 'array' );
|
||||
if ( $opt ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
update_option( $setting, $opt );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
|
||||
}
|
||||
|
||||
require_once self::TEMPLATE_DIR . 'setting.php';
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function show_option_page() {
|
||||
//-------------------------------------
|
||||
// 通常表示
|
||||
// ------------------------------------
|
||||
$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' );
|
||||
|
||||
//検索の投稿表示順設定
|
||||
if ( isset( $_POST['_apop_post_search'] ) ) {
|
||||
if ( $apop_normal_order ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
$this->update_search_sort( 'search' );
|
||||
update_option( '_apop_normal_order', $apop_normal_order );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
|
||||
if ( isset( $_POST['_apop_search_order'] ) ) {
|
||||
//表示順設定
|
||||
if ( $apop_normal_order_param ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
update_option( '_apop_search_order', $_POST['_apop_search_order'] );
|
||||
update_option( '_apop_normal_order_param', $apop_normal_order_param );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
|
||||
//カスタム表示順設定
|
||||
if ( $apop_post_normal ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
$this->update_search_normal_sort( $apop_post_normal, 'normal' );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
// 検索表示
|
||||
// ------------------------------------
|
||||
$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' );
|
||||
|
||||
if ( $apop_search_order ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
update_option( '_apop_search_order', $apop_search_order );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
|
||||
//表示順設定
|
||||
if ( $apop_search_order_param ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
update_option( '_apop_search_order_param', $apop_search_order_param );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
|
||||
//カスタム表示順設定
|
||||
if ( $apop_post_search ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
$this->update_search_normal_sort( $apop_post_search, 'search' );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
// タクソノミー
|
||||
// ------------------------------------
|
||||
$apop_post_category = APOP_UI::input_post_filter( '_apop_post_category', 'array' );
|
||||
$apop_post_post_tag = APOP_UI::input_post_filter( '_apop_post_post_tag', 'array' );
|
||||
$apop_post_tax = APOP_UI::input_post_filter( '_apop_post_tax', 'array' );
|
||||
|
||||
//カテゴリーの投稿表示順設定
|
||||
if ( isset( $_POST['_apop_post_category'] ) ) {
|
||||
if ( $apop_post_category ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
$this->update_post_sort( 'category' );
|
||||
$this->update_post_sort( 'category', $apop_post_category );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
|
||||
//タグの投稿表示順設定
|
||||
if ( isset( $_POST['_apop_post_post_tag'] ) ) {
|
||||
if ( $apop_post_post_tag ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
$this->update_post_sort( 'post_tag' );
|
||||
$this->update_post_sort( 'post_tag', $apop_post_post_tag );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
|
||||
//カスタム分類の投稿表示順設定
|
||||
if ( isset( $_POST['_apop_post_tax'] ) ) {
|
||||
if ( $apop_post_tax ) {
|
||||
check_admin_referer( 'sh_options' );
|
||||
$this->update_post_sort( 'tax' );
|
||||
$this->update_post_sort( 'tax', $apop_post_tax );
|
||||
require_once self::TEMPLATE_DIR . 'success.php';
|
||||
}
|
||||
|
||||
@@ -109,21 +154,20 @@ if ( ! class_exists( 'APOP' ) ) {
|
||||
}
|
||||
|
||||
//投稿表示順の設定
|
||||
private function update_post_sort( $target ) {
|
||||
$target = '_apop_post_' . $target;
|
||||
$posts_sort = $_POST[ $target ]['post_sort'];
|
||||
private function update_post_sort( $target, $post_value ) {
|
||||
$posts_sort = $post_value['post_sort'];
|
||||
foreach ( $posts_sort as $cat_id => $posts ) {
|
||||
$sort_key = $target . '_' . $cat_id;
|
||||
$sort_key = '_apop_post_' . $target . '_' . $cat_id;
|
||||
foreach ( $posts as $post_id => $sort ) {
|
||||
update_post_meta( $post_id, $sort_key, $sort );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function update_search_sort() {
|
||||
$posts_sort = $_POST['_apop_post_search']['post_sort'];
|
||||
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_search', $sort );
|
||||
update_post_meta( $post_id, '_apop_post_' . $key, $sort );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user