diff --git a/functions.php b/functions.php index 36ac10c3..e5e06080 100644 --- a/functions.php +++ b/functions.php @@ -311,6 +311,11 @@ if (is_admin() && class_exists('AKSRT_Plate_Meta_Box')) { if (is_admin() && class_exists('AKSRT_Topic_Admin_List')) { AKSRT_Topic_Admin_List::get_instance()->init(); } +// 论坛帖子治理 meta box +if (is_admin() && class_exists('AKSRT_Topic_Meta_Box')) { + AKSRT_Topic_Meta_Box::get_instance()->init(); +} + diff --git a/inc/bootstrap.php b/inc/bootstrap.php index 6f09a3ec..21fcc75a 100644 --- a/inc/bootstrap.php +++ b/inc/bootstrap.php @@ -324,6 +324,7 @@ require_once AKSRT_DIR . '/inc/classes/shop/class-aksrt-product-meta-box.php'; require_once AKSRT_DIR . '/inc/classes/shop/class-aksrt-product-variants-meta-box.php'; require_once AKSRT_DIR . '/inc/classes/forum/class-aksrt-plate-meta-box.php'; require_once AKSRT_DIR . '/inc/classes/forum/class-aksrt-topic-admin-list.php'; +require_once AKSRT_DIR . '/inc/classes/forum/class-aksrt-topic-meta-box.php'; require_once AKSRT_DIR . '/inc/classes/shop/shop-traits/trait-aksrt-shop-part-1.php'; require_once AKSRT_DIR . '/inc/classes/shop/shop-traits/trait-aksrt-shop-part-2.php'; require_once AKSRT_DIR . '/inc/classes/shop/shop-traits/trait-aksrt-shop-part-3.php'; diff --git a/inc/classes/class-aksrt-shop-term-meta.php b/inc/classes/class-aksrt-shop-term-meta.php index 3f1a7568..b6873863 100644 --- a/inc/classes/class-aksrt-shop-term-meta.php +++ b/inc/classes/class-aksrt-shop-term-meta.php @@ -39,6 +39,12 @@ class AKSRT_Shop_Term_Meta { add_action('shop_discount_edit_form_fields', [$this, 'render_discount_edit_fields'], 10, 1); add_action('created_shop_discount', [$this, 'save_discount_term_fields']); add_action('edited_shop_discount', [$this, 'save_discount_term_fields']); + + // Product category inheritance fields. + add_action('aksrt_product_cat_add_form_fields', [$this, 'render_cat_add_fields']); + add_action('aksrt_product_cat_edit_form_fields', [$this, 'render_cat_edit_fields'], 10, 1); + add_action('created_aksrt_product_cat', [$this, 'save_cat_term_fields']); + add_action('edited_aksrt_product_cat', [$this, 'save_cat_term_fields']); } // ─── Taxonomy Registration ─────────────────────────────────── @@ -565,4 +571,110 @@ class AKSRT_Shop_Term_Meta { update_term_meta($term_id, $key, $value); } } + + public function render_cat_add_fields(): void { + foreach ($this->get_cat_field_definitions() as $key => $def) { + echo '
'; + echo ''; + $this->render_cat_field_control($key, $def['default'] ?? '', false); + echo '
'; + } + } + + public function render_cat_edit_fields($term): void { + if (!($term instanceof WP_Term)) { + return; + } + foreach ($this->get_cat_field_definitions() as $key => $def) { + $value = get_term_meta($term->term_id, $key, true); + if ($value === '' || $value === false) { + $value = $def['default'] ?? ''; + } + echo ''; + $this->render_cat_field_control($key, $value, true); + echo ''; + } + } + + /** + * @param mixed $value + */ + private function render_cat_field_control(string $key, $value, bool $edit): void { + $val = (string) $value; + if (in_array($key, ['shop_cat_guest_buy', 'shop_cat_email_fill', 'shop_cat_content_show_bg'], true)) { + echo ''; + return; + } + if (in_array($key, ['shop_cat_service', 'shop_cat_single_tab', 'shop_cat_content_after'], true)) { + echo ''; + return; + } + if ($key === 'shop_cat_shipping_fee') { + $opts = ['' => __('继承', 'aksrt'), 'free' => __('包邮', 'aksrt'), 'fixed' => __('固定运费', 'aksrt'), 'amount' => __('满额包邮', 'aksrt')]; + echo ''; + return; + } + if ($key === 'shop_cat_after_sale') { + $opts = ['' => __('继承', 'aksrt'), 'refund' => __('仅退款', 'aksrt'), 'refund_return' => __('退货退款', 'aksrt'), 'none' => __('不支持', 'aksrt')]; + echo ''; + return; + } + if ($key === 'shop_cat_content_layout') { + $opts = ['' => __('继承', 'aksrt'), 'adapt' => __('自适应', 'aksrt'), 'full' => __('通栏', 'aksrt'), 'sidebar' => __('侧栏', 'aksrt')]; + echo ''; + return; + } + if ($key === 'shop_cat_list_style') { + $opts = ['' => __('继承', 'aksrt'), 'default' => __('默认', 'aksrt'), 'card-lg' => __('大卡片', 'aksrt'), 'card-sm' => __('小卡片', 'aksrt')]; + echo ''; + return; + } + $type = $key === 'shop_cat_limit_buy' ? 'number' : 'text'; + printf( + '', + esc_attr($type), + $edit ? 'regular-text' : '', + esc_attr($key), + esc_attr($key), + esc_attr($val) + ); + } + + public function save_cat_term_fields(int $term_id): void { + if (!current_user_can('manage_categories')) { + return; + } + foreach ($this->get_cat_field_definitions() as $key => $def) { + if (in_array($key, ['shop_cat_guest_buy', 'shop_cat_email_fill', 'shop_cat_content_show_bg'], true)) { + $raw = isset($_POST[$key]) ? '1' : ''; + } else { + if (!isset($_POST[$key])) { + continue; + } + $raw = wp_unslash($_POST[$key]); + } + if (isset($def['sanitize']) && is_callable($def['sanitize'])) { + $value = call_user_func($def['sanitize'], $raw); + } else { + $value = sanitize_text_field((string) $raw); + } + update_term_meta($term_id, $key, $value); + } + } } diff --git a/inc/classes/forum/class-aksrt-topic-meta-box.php b/inc/classes/forum/class-aksrt-topic-meta-box.php new file mode 100644 index 00000000..800088bc --- /dev/null +++ b/inc/classes/forum/class-aksrt-topic-meta-box.php @@ -0,0 +1,191 @@ +ID, '_aksrt_plate_id', true); + $sticky = (int) get_post_meta($post->ID, '_aksrt_sticky', true); + $locked = (int) get_post_meta($post->ID, '_aksrt_locked', true); + $featured = (int) get_post_meta($post->ID, '_aksrt_featured', true); + $review = (string) get_post_meta($post->ID, '_aksrt_review_status', true); + if ($review === '') { + $review = 'approved'; + } + $bbs_type = (string) (get_post_meta($post->ID, '_aksrt_bbs_type', true) ?: 'standard'); + $visibility = (string) (get_post_meta($post->ID, '_aksrt_visibility', true) ?: 'public'); + $allow_view = (string) (get_post_meta($post->ID, '_aksrt_allow_view', true) ?: 'public'); + $pay_price = (float) get_post_meta($post->ID, '_aksrt_pay_price', true); + $pay_credits= (int) get_post_meta($post->ID, '_aksrt_pay_credits', true); + + $plates = get_posts([ + 'post_type' => 'aksrt_forum_plate', + 'post_status' => 'publish', + 'posts_per_page' => 200, + 'orderby' => 'title', + 'order' => 'ASC', + ]); + ?> +

+ + +

+

+ + +

+

+
+ +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+ post_type !== 'aksrt_forum_topic' || !current_user_can('edit_post', $post_id)) { + return; + } + + $plate_id = isset($_POST['aksrt_plate_id']) ? max(0, (int) $_POST['aksrt_plate_id']) : 0; + update_post_meta($post_id, '_aksrt_plate_id', $plate_id); + + $sticky = isset($_POST['aksrt_sticky']) ? max(0, min(3, (int) $_POST['aksrt_sticky'])) : 0; + update_post_meta($post_id, '_aksrt_sticky', $sticky); + update_post_meta($post_id, '_aksrt_locked', !empty($_POST['aksrt_locked']) ? 1 : 0); + update_post_meta($post_id, '_aksrt_featured', !empty($_POST['aksrt_featured']) ? 1 : 0); + + $review = isset($_POST['aksrt_review_status']) ? sanitize_key((string) wp_unslash($_POST['aksrt_review_status'])) : 'approved'; + if (!in_array($review, ['approved', 'pending', 'rejected'], true)) { + $review = 'approved'; + } + update_post_meta($post_id, '_aksrt_review_status', $review); + + $bbs_type = isset($_POST['aksrt_bbs_type']) ? sanitize_key((string) wp_unslash($_POST['aksrt_bbs_type'])) : 'standard'; + if (!in_array($bbs_type, ['standard', 'question'], true)) { + $bbs_type = 'standard'; + } + update_post_meta($post_id, '_aksrt_bbs_type', $bbs_type); + + $visibility = isset($_POST['aksrt_visibility']) ? sanitize_key((string) wp_unslash($_POST['aksrt_visibility'])) : 'public'; + update_post_meta($post_id, '_aksrt_visibility', $visibility); + + $allow_view = isset($_POST['aksrt_allow_view']) ? sanitize_key((string) wp_unslash($_POST['aksrt_allow_view'])) : 'public'; + update_post_meta($post_id, '_aksrt_allow_view', $allow_view); + + update_post_meta($post_id, '_aksrt_pay_price', isset($_POST['aksrt_pay_price']) ? max(0, (float) wp_unslash($_POST['aksrt_pay_price'])) : 0); + update_post_meta($post_id, '_aksrt_pay_credits', isset($_POST['aksrt_pay_credits']) ? max(0, (int) wp_unslash($_POST['aksrt_pay_credits'])) : 0); + + // Keep board taxonomy bridge roughly in sync when plate selected. + if ($plate_id > 0 && taxonomy_exists('aksrt_forum_board')) { + $slug = 'plate-' . $plate_id; + $term = get_term_by('slug', $slug, 'aksrt_forum_board'); + if (!$term) { + $title = get_the_title($plate_id) ?: $slug; + $created = wp_insert_term($title, 'aksrt_forum_board', ['slug' => $slug]); + if (!is_wp_error($created) && !empty($created['term_id'])) { + $term_id = (int) $created['term_id']; + } else { + $term_id = 0; + } + } else { + $term_id = (int) $term->term_id; + } + if ($term_id > 0) { + wp_set_object_terms($post_id, [$term_id], 'aksrt_forum_board', false); + } + } + } +}