diff --git a/archive-post-order-plus.php b/archive-post-order-plus.php index 0f0ed7b..1ad5203 100644 --- a/archive-post-order-plus.php +++ b/archive-post-order-plus.php @@ -23,12 +23,13 @@ License: GPLv2 */ /** - * 指定したキーが無ければ、投稿の管理画面表示時にメタボックスを追加する。 - * メタキーは下記のオプションテーブルから取得する - * _apop_normal_order_param - * _apop_search_order_param - * _apop_tax_order_param - * ラベルは「APO+カスタムフィールド:XXXX」とする + * TODO: + 1)カテゴリーのソート用カスタムフィールド取得と設定 + ・保存しているタームIDと投稿が属するタームIDが一致する場合、管理画面に表示する + class.apop.apop_post.php、setting_post_custom_field.php + * 2)uninstall.php + * 投稿とタクソノミーのカスタムフィールド削除方法修正 + * ・delete_post_meta_by_key()を廃止し、WP_QUERYに変更する */ define( 'APOP_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); @@ -36,9 +37,11 @@ define( 'APOP_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); //メイン処理のクラスをインスタンス化 require_once __DIR__ . '/class/class.apop.order.php'; -require_once __DIR__ . '/class/class.apop.ui.php'; +require_once __DIR__ . '/class/class.apop.apop_ui.php'; +require_once __DIR__ . '/class/class.apop.apop_post.php'; $APOP = new APOP; +new APOP_POST; //CSS, JSの読み込み add_action( 'admin_enqueue_scripts', 'register_my_styles' ); diff --git a/class/class.apop.apop_post.php b/class/class.apop.apop_post.php new file mode 100644 index 0000000..b950f84 --- /dev/null +++ b/class/class.apop.apop_post.php @@ -0,0 +1,137 @@ +set_post_types(); + foreach ( $target_posts as $target_post ) { + add_meta_box( 'apo_custom_fields', 'APO+カスタムフィールド', array( + $this, + 'insert_meta_fields' + ), $target_post, 'normal' ); + } + } + + public function insert_meta_fields() { + //通常ソート + $this->create_order_field_data( get_option( '_apop_normal_order_param' ), 'normal' ); + //検索ソート + $this->create_order_field_data( get_option( '_apop_search_order_param' ), 'search' ); + //カテゴリー、タグ、カスタム分類 + $this->create_order_tax_field_data( get_option( '_apop_tax_order_param' ) ); + + $this->labels = array( + 'normal' => '通常', + 'search' => '検索', + 'tax' => 'カテゴリー、タグ、カスタム分類', + ); + + require_once self::TEMPLATE_DIR . 'setting_post_custom_field.php'; + + } + + private function set_post_types() { + $custom_posts = array_values( get_post_types( array( 'public' => true, '_builtin' => false ) ) ); + + return array_merge( array( 'page', 'post', ), $custom_posts ); + } + + private function create_order_field_data( $param, $key, $update = false ) { + foreach ( $this->order_param_keys as $order_param_key ) { + if ( isset( $param[ $order_param_key ]['field']['meta_key'] ) && + ! empty( $param[ $order_param_key ]['field']['meta_key'] ) ) { + if ( $update ) { + $this->name_keys[] = $param[ $order_param_key ]['field']['meta_key']; + } else { + $this->order_field[ $key ][] = $param[ $order_param_key ]['field']['meta_key']; + } + } + } + } + + private function create_order_tax_field_data( $param, $update = false ) { + $term_ids = $this->create_post_term_ids(); + foreach ( $term_ids as $term_id ) { + foreach ( $this->order_param_keys as $order_param_key ) { + if ( isset( $param[ $term_id ][ $order_param_key ]['field']['meta_key'] ) && + ! empty( $param[ $term_id ][ $order_param_key ]['field']['meta_key'] ) ) { + if ( $update ) { + $this->name_keys[] = $param[ $term_id ][ $order_param_key ]['field']['meta_key']; + } else { + $this->order_field['tax'][] = $param[ $term_id ][ $order_param_key ]['field']['meta_key']; + } + } + } + } + } + + private function create_post_term_ids() { + global $post; + $terms = array(); + $term_ids = array(); + $taxonomy_slugs = array_keys( get_the_taxonomies() ); + foreach ( $taxonomy_slugs as $taxonomy_slug ) { + $terms[] = get_the_terms( $post->ID, $taxonomy_slug ); + + } + foreach ( $terms as $term ) { + foreach ( $term as $tax ) { + $term_ids[] = $tax->term_id; + } + } + + return $term_ids; + } + + private function get_custom_field_data( $custom_filed_name ) { + global $post; + + return get_post_meta( $post->ID, $custom_filed_name, true ); + } + + // カスタムフィールドの値を保存 + public function save_meta_fields( $post_id ) { + $this->get_update_meta_fields(); + if ( count( $this->name_keys ) > 0 ) { + foreach ( $this->name_keys as $name_key ) { + update_post_meta( $post_id, $name_key, $_POST[ $name_key ] ?? '' ); + update_post_meta( $post_id, $name_key, $_POST[ $name_key ] ?? '' ); + } + } + } + + private function get_update_meta_fields() { + //通常ソート + $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_tax_field_data( get_option( '_apop_tax_order_param' ), true ); + } + + } +} diff --git a/class/class.apop.ui.php b/class/class.apop.apop_ui.php similarity index 100% rename from class/class.apop.ui.php rename to class/class.apop.apop_ui.php diff --git a/css/apop-style.css b/css/apop-style.css index cf01823..7c14fa9 100644 --- a/css/apop-style.css +++ b/css/apop-style.css @@ -42,7 +42,8 @@ h3 { .post-order-box-outer { width: 100%; margin: -1px 0 2em; - border-top: 1px solid #999; + border: 1px solid #999; + background: #fff; } .post-order-box:not(:first-child) { @@ -56,9 +57,7 @@ h3 { .list-orders-inner { width: 50%; - margin: 1.5em 1em 0 0; padding: .5em; - border: 1px solid #999; position: relative; } @@ -75,7 +74,8 @@ p.submit.post-order .button-primary { bottom: 1em; } -dl.apop_setting_list { +dl.apop_setting_list, +dl.apop_setting_list_dd { width: 100%; margin-top: .5em; } @@ -92,6 +92,29 @@ dl.apop_setting_list dd:first-of-type { margin-bottom: 2em; } +dl.apop_setting_list_dd dt { + margin-top: 1em; + font-weight: bold; +} + +dl.apop_setting_list_dd dd { + margin: .5em 0; + border-bottom: 1px solid #c3c4c7; +} + +dl.apop_setting_list_dd dd ul { + margin-bottom: 1em; +} + +dl.apop_setting_list_dd dd label { + display: block; + margin-bottom: .3em; +} + +dl.apop_setting_list_dd dd input { + width: 100%; +} + .form-table tr { border-bottom: 1px solid #ccc; } @@ -145,7 +168,7 @@ dl.apop_setting_list dd:first-of-type { .no_registered_exp { width: 100%; - margin-top: 1em; + margin: 1em 0 0 .5em; } .order_setting_list > li { @@ -197,6 +220,16 @@ dl.apop_setting_list dd:first-of-type { cursor: default; } +.apop-submit{ + margin:1em .5em; +} + +.apop-form_table{ + background: #fff; +} +.apop-form_table th{ + padding-left:.5em; +} @media only screen and (max-width: 1264px) { .search_normal_sort .product-list { diff --git a/template/order.php b/template/order.php index b8df2c3..59eaabb 100644 --- a/template/order.php +++ b/template/order.php @@ -13,12 +13,12 @@ $submit_type = APOP_UI::input_post_filter( 'submit_type', 'str' );
-
-
-
-
+ + +
+
+

通常

-
- -

- - +
-
-
-
-
-
+
+
+

検索

-
- -

- +
-
-
-
- APOP_UI::get_cat_tag_list( 'cat', 'category' ) ); - $tax_title_text = 'カテゴリー'; - $submit_type_number = 2; - ?> - +
+
+ APOP_UI::get_cat_tag_list( 'cat', 'category' ) ); + $tax_title_text = 'カテゴリー'; + $submit_type_number = 2; + ?> + +
-
-
-
- APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ) ); - $tax_title_text = 'タグ'; - $submit_type_number = 3; - ?> - +
+
+ APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ) ); + $tax_title_text = 'タグ'; + $submit_type_number = 3; + ?> + +
-
-
-
- APOP_UI::get_cat_tag_list( 'tax', 'taxonomy' ) ); - $tax_title_text = 'カスタム分類'; - $submit_type_number = 4; - ?> - +
+
+ APOP_UI::get_cat_tag_list( 'tax', 'taxonomy' ) ); + $tax_title_text = 'カスタム分類'; + $submit_type_number = 4; + ?> + +
-
+

+
\ No newline at end of file diff --git a/template/order_parts_taxonomy.php b/template/order_parts_taxonomy.php index 0de3ecd..3247133 100644 --- a/template/order_parts_taxonomy.php +++ b/template/order_parts_taxonomy.php @@ -5,56 +5,48 @@
-
- -

name; ?>

- term_id ] ) ) { - $order_target = $order_target_data[ $tax_data->term_id ]; - } else { - $order_target = 1; - } - ?> -
    -
  • - -
  • -
  • - -
  • -
+

name; ?>

+ term_id ] ) ) { + $order_target = $order_target_data[ $tax_data->term_id ]; + } else { + $order_target = 1; + } + ?> +
    +
  • + +
  • +
  • + +
  • +
-
-
    - -
+
+
    + +
+
+
+ term_id ); ?> + +

有効

+
    + +
+
+

無効

+
    -
    - term_id ); ?> - -

    有効

    -
      - -
    -
    -

    無効

    -
      -
      -
      - -

      - - +
      diff --git a/template/setting.php b/template/setting.php index 30b3e70..878e3ce 100644 --- a/template/setting.php +++ b/template/setting.php @@ -1,47 +1,47 @@
      - -

      設定

      - - - - - - - - -
      全体設定 -
      -
      1ページ表示件数
      -
      -
        -
      • - -
      • -
      • -
      • -
      • - -
      • -
      -
      -
      -
      + $opt_per_page = get_option( '_apop_per_page' ); + $default_per_page = get_option( 'posts_per_page' ); + ?> +

      設定

      + + + + + + + + +
      全体設定 +
      +
      1ページ表示件数
      +
      +
        +
      • + +
      • +
      • +
      • +
      • + +
      • +
      +
      +
      +

      \ No newline at end of file diff --git a/template/setting_post_custom_field.php b/template/setting_post_custom_field.php new file mode 100644 index 0000000..8077d83 --- /dev/null +++ b/template/setting_post_custom_field.php @@ -0,0 +1,21 @@ +
      + order_field ) && count( $this->order_field ) > 0 ): ?> +
      + order_field as $type => $items ): ?> +
      labels[ $type ]; ?>
      +
      +
        + + +
      • + +
      • + + +
      +
      + +
      + +
      \ No newline at end of file