WordPress.org

Ready to get started?Download WordPress

Forums

Hook naming inconsistency, support for custom post types (2 posts)

  1. drtanz
    Member
    Posted 1 year ago #

    There is a naming inconsistency with the following hooks. I suggest they all have the wp_ prefix. Also I suggest that there be specific hooks for custom post types. For example, how can I hook my function to the deletion of my custom post type?

    Saving
    add_action('save_post', 'custom_save_function');

    Trashing
    add_action('wp_trash_post', 'custom_trash_function');

    Restoring
    add_action('untrash_post', 'custom_restore_function');

    Deleting
    add_action('delete_post', 'custom_delete_function');

  2. There is no need for post type specific hooks. The post type can be filtered in the call back function.

    add_action( 'trashed_post', 'cpt_trash_post' );
    function cpt_trash_post( $post_id ) {
        if ( 'my_cpt_name' != get_post_type( $post_id ) )
              return;
    
         //Continue with your function
    }

    This is how most WordPress hooks and filters are engineered. It's common practice to do conditional checks in call back functions.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.