• Resolved Matt Lowe

    (@squelch)


    Hey, great plugin.

    I just wondered if you’d entertain the possibility of adding the following hook into override_type (post-type-switcher.php:509) to make it possible for developers to detect when a post type is switched.

    
    // Bail if it's a revision
    if ( in_array( $postarr['post_type'], array( $post_type, 'revision' ), true ) ) {
        return $data;
    }
    
    // Hook for developers
    do_action( 'post_type_switcher_override_type', $data['post_type'], $post_type, $data, $postarr, $this );
    
    // Update post type
    $data['post_type'] = $post_type;
    

    It would then be possible for devs to do things like (e.g.):

    
    function pts_override_type( $post_type, $new_post_type, $post_data, $postarr, $pts_obj ) {
    
        if ( $post_type === 'oldpost' && $new_post_type === 'newpost' ) {
            add_action( 'edit_post_sqblock', 'pts_oldpost_to_newpost', 10, 2 );
        }
    
    }
    add_action( 'post_type_switcher_override_type', 'pts_override_type', 10, 5 );
    
    /**
     * Called after post saved, but only when post type is switched from
     * "oldpost" to "newpost"
     */
    function pts_oldpost_to_newpost( $post_id, $post ) {
        // Move meta data, create new taxonomy terms, etc
    }
    

    It’s only a small change and the typical end user won’t see any difference, but it would be extremely helpful to developers who need to help customers who are switching the types of literally hundreds of posts, and need some automation to prevent them from going insane!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Feature request: hook for when post type is switched’ is closed to new replies.