Hook: mam_reviews_providers

Signature

apply_filters( 'mam_reviews_providers', array $providers );
Parameter Type Description
$providers array Map of key => descriptor. Add your descriptor and return the array.

Each descriptor:

Key Type Description
label string Human label (admin/debug only).
class string Class name implementing MAM_Reviews_Provider (typically extending MAM_Reviews_Provider_Base). Must be loadable when the registry boots.
priority int Higher = checked first. Default provider is 0; GeoDirectory and WooCommerce are 20.

What it does

The registry collects every descriptor on this filter and resolves one provider per post: the highest-priority provider whose supports( $post_id, $post_type ) returns true. The built-in default provider registers at priority 0 and supports everything, guaranteeing exactly one match. See How reviews are stored and read for the full resolution algorithm.

Register a provider when a post type stores its ratings somewhere other than plain WP comments and you want app ratings to read/write that native store.


Example — register a provider

add_filter( 'mam_reviews_providers', function ( array $providers ) {
    $providers['my_cpt'] = array(
        'label'    => 'My CPT Ratings',
        'class'    => 'my_cpt_reviews_provider', // implements MAM_Reviews_Provider
        'priority' => 20,                        // beats the default (0)
    );
    return $providers;
} );
class my_cpt_reviews_provider extends MAM_Reviews_Provider_Base {

    public function supports( int $post_id, string $post_type ): bool {
        return 'my_cpt' === $post_type;
    }

    // Implement the storage-specific methods:
    public function get_aggregates( int $post_id ): array { /* … */ }
    public function get_reviews( int $post_id, array $args = array() ): array { /* … */ }
    public function get_user_review( int $post_id, int $user_id ): ?array { /* … */ }
    public function save_review( array $submission ): array { /* write natively */ }

    // get_criteria() and get_all_reviews() are inherited from the base; override
    // get_criteria() to expose multiple rating criteria.
}

Notes

  • A descriptor whose class doesn’t exist when the registry boots is skipped silently — make sure the class file is required before first resolution (plugins_loaded is a safe time to register).
  • save_review() must write through the native path so aggregates recompute (use wp_new_comment(), not wp_insert_comment()). See the provider-model article for why.
  • Return at least one overall criterion from get_criteria(); the reserved id overall may not be reused.

  • How reviews are stored and read (provider model)
  • Plugin: mam-reviews-manager

Metadata

Field Value
Article type Hook Reference
Plugin slug mam-reviews-manager
Applies to plugin version 26.23.0+
Category Extending MAM Suite
Hook type filter
Audience PHP developer
Last verified 2026-06-04
Was this article helpful?
Contents

    Need Support?

    Can't find the answer you're looking for? Don't worry we're here to help!