1. Customize
  2. Expansions
  3. Events for create and delete a CPT

Events for create and delete a CPT

Intentionally GamiPress events for new content publishment and deletion are restricted to post and pages, simply because there are the two main elements coming from a clear install, probably you will think, Why?

When this feature was built, we have in mind other integrations like the WooCommerce integration.

On a normal blog, your authors are blog post writers, but on WooCommerce, your products authors are vendors, so we want a separate handler for this event because is not the same a blog post than a store product.

But this not means that is imposible to add support for a custom post type (CPT), precisely GamiPress is extremely extensible and you can add support to any registered post type.

function my_prefix_activity_triggers_for_cpt_creation_and_deletion( $triggers ) {

    // Replace this with the CPT you want, for example: event
    $my_prefix_post_type = 'custom-post-type';

    $post_type = get_post_type_object( $my_prefix_post_type );

    $triggers[__( 'Custom Post Type Events', 'gamipress' )] = array(
        "gamipress_publish_{$my_prefix_post_type}" => sprintf( __( 'Publish a new %s', 'gamipress' ), $post_type->labels->singular_name ),
        "gamipress_delete_{$my_prefix_post_type}" => sprintf( __( 'Delete a %s', 'gamipress' ), $post_type->labels->singular_name ),
    );

    return $triggers;

}
add_filter( 'gamipress_activity_triggers', 'my_prefix_activity_triggers_for_cpt_creation_and_deletion' );
Was this article helpful to you? Yes 1 No

How can we help?