803c742a9f
・管理画面メニュー(サブメニュー)の修正 ・1ページ表示件数の追加 ・pre_get_postするクエリの追加 ・検索用設定の追加
134 lines
3.5 KiB
PHP
134 lines
3.5 KiB
PHP
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
} // Exit if accessed directly
|
|
|
|
if ( ! class_exists( 'APOP' ) ) {
|
|
require_once __DIR__ . '/../util/apop-order-setting.php';
|
|
|
|
class APOP {
|
|
|
|
use APOP_ORDER_SETTING;
|
|
|
|
const TEMPLATE_DIR = __DIR__ . '/../template/';
|
|
|
|
public function __construct() {
|
|
add_action( 'admin_menu', array( $this, 'add_pages' ) );
|
|
}
|
|
|
|
public function add_pages() {
|
|
add_menu_page(
|
|
'APO +',
|
|
'APO +',
|
|
'level_8',
|
|
'apop_post_sort',
|
|
array( $this, 'display_setting_page' ),
|
|
'',
|
|
50
|
|
);
|
|
add_submenu_page(
|
|
'apop_post_sort', // parent_slug
|
|
'Sort taxonomy', // page_title
|
|
'設定', // menu_title
|
|
'administrator', // capability
|
|
'apop_post_sort', // menu_slug
|
|
array( $this, 'display_setting_page' ) // function
|
|
);
|
|
add_submenu_page(
|
|
'apop_post_sort', // parent_slug
|
|
'Select taxonomy', // page_title
|
|
'並べ替え', // menu_title
|
|
'administrator', // capability
|
|
'apop_post_sort_setting', // menu_slug
|
|
array( $this, 'show_option_page' ) // function
|
|
);
|
|
}
|
|
|
|
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', //カスタムタクソノミー設定
|
|
);
|
|
foreach ( $settings as $setting ) {
|
|
$opt = $_POST[ $setting ];
|
|
update_option( $setting, $opt );
|
|
}
|
|
require_once self::TEMPLATE_DIR . 'success.php';
|
|
|
|
}
|
|
|
|
require_once self::TEMPLATE_DIR . 'setting.php';
|
|
}
|
|
|
|
|
|
public function show_option_page() {
|
|
|
|
//検索の投稿表示順設定
|
|
if ( isset( $_POST['_apop_post_search'] ) ) {
|
|
check_admin_referer( 'sh_options' );
|
|
$this->update_search_sort( 'search' );
|
|
require_once self::TEMPLATE_DIR . 'success.php';
|
|
}
|
|
|
|
if ( isset( $_POST['_apop_search_order'] ) ) {
|
|
check_admin_referer( 'sh_options' );
|
|
update_option( '_apop_search_order', $_POST['_apop_search_order'] );
|
|
require_once self::TEMPLATE_DIR . 'success.php';
|
|
}
|
|
|
|
//カテゴリーの投稿表示順設定
|
|
if ( isset( $_POST['_apop_post_category'] ) ) {
|
|
check_admin_referer( 'sh_options' );
|
|
$this->update_post_sort( 'category' );
|
|
require_once self::TEMPLATE_DIR . 'success.php';
|
|
}
|
|
|
|
//タグの投稿表示順設定
|
|
if ( isset( $_POST['_apop_post_post_tag'] ) ) {
|
|
check_admin_referer( 'sh_options' );
|
|
$this->update_post_sort( 'post_tag' );
|
|
require_once self::TEMPLATE_DIR . 'success.php';
|
|
}
|
|
|
|
//カスタム分類の投稿表示順設定
|
|
if ( isset( $_POST['_apop_post_tax'] ) ) {
|
|
check_admin_referer( 'sh_options' );
|
|
$this->update_post_sort( 'tax' );
|
|
require_once self::TEMPLATE_DIR . 'success.php';
|
|
}
|
|
|
|
require_once self::TEMPLATE_DIR . 'order.php';
|
|
}
|
|
|
|
//投稿表示順の設定
|
|
private function update_post_sort( $target ) {
|
|
$target = '_apop_post_' . $target;
|
|
$posts_sort = $_POST[ $target ]['post_sort'];
|
|
foreach ( $posts_sort as $cat_id => $posts ) {
|
|
$sort_key = $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'];
|
|
foreach ( $posts_sort as $post_id => $sort ) {
|
|
update_post_meta( $post_id, '_apop_post_search', $sort );
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|