Danh sách các Filter và Hook trong Init Review System

Plugin Init Review System cung cấp một số filter cho phép developer tùy biến hành vi chèn tự động, cấu hình shortcode và cấu trúc schema. Dưới đây là toàn bộ danh sách hook nội bộ đã định nghĩa, kèm hướng dẫn sử dụng chi tiết.

Danh sách các Filter và Hook trong Init Review System

1. init_plugin_suite_review_system_auto_insert_enabled_score

Bật hoặc tắt auto-insert khối điểm số (score) tại các vị trí trong bài viết.

Tham số:

  • bool $enabled – Mặc định là true
  • string $position – Vị trí như before, after
  • string $post_type – Loại post hiện tại
// Vô hiệu hóa auto-insert score ở cuối bài viết cho post type 'product'
add_filter('init_plugin_suite_review_system_auto_insert_enabled_score', function($enabled, $position, $post_type) {
    if ($post_type === 'product' && $position === 'after') {
        return false;
    }
    return $enabled;
}, 10, 3);

2. init_plugin_suite_review_system_auto_insert_enabled_vote

Bật hoặc tắt auto-insert khối đánh giá (vote) tại các vị trí trước/sau nội dung hoặc bình luận.

Tham số: Như trên

// Chặn hiện vote form trong khung bình luận nếu là post type 'page'
add_filter('init_plugin_suite_review_system_auto_insert_enabled_vote', function($enabled, $position, $post_type) {
    if ($post_type === 'page') return false;
    return $enabled;
}, 10, 3);

3. init_plugin_suite_review_system_default_score_shortcode

Tuỳ biến shortcode mặc định của khối điểm số được auto-insert.

Tham số: string $shortcode

// Thêm class tuỳ chỉnh khi auto-insert score
add_filter('init_plugin_suite_review_system_default_score_shortcode', function($shortcode) {
    return '[init_review_score icon="true" class="highlight-score"]';
});

4. init_plugin_suite_review_system_default_vote_shortcode

Tuỳ biến shortcode mặc định của khối vote được auto-insert.

Tham số: string $shortcode

// Bật schema mặc định cho block vote
add_filter('init_plugin_suite_review_system_default_vote_shortcode', function($shortcode) {
    return '[init_review_system schema="true"]';
});

5. init_plugin_suite_review_system_schema_type

Điều chỉnh loại schema.org cho block vote.

Tham số:

  • string $type – Schema type mặc định
  • string $post_type – Loại post hiện tại
// Đổi thành Movie nếu post type là 'movie'
add_filter('init_plugin_suite_review_system_schema_type', function($type, $post_type) {
    return $post_type === 'movie' ? 'Movie' : $type;
}, 10, 2);

6. init_plugin_suite_review_system_schema_data

Tuỳ biến nội dung JSON-LD schema cho khối vote.

Tham số:

  • array $schema_data – Dữ liệu schema đã generate
  • int $post_id – ID bài viết
  • string $schema_type – Loại schema đang dùng
// Thêm trường 'author' vào schema
add_filter('init_plugin_suite_review_system_schema_data', function($schema, $post_id, $type) {
    $schema['author'] = get_bloginfo('name');
    return $schema;
}, 10, 3);

Kết luận

Hệ thống hook của Init Review System được thiết kế đơn giản, nhưng đủ mở rộng để bạn có thể điều chỉnh mọi hành vi từ việc hiển thị, schema cho đến xử lý vote.

Bình luận


  • Không có bình luận.

Init Toolbox

Nhấn Ctrl + \ trên máy tính, hoặc vuốt sang trái ở bất kỳ đâu trên mobile.

Đăng nhập





Đang tải...