• Resolved marcomc

    (@marcomc)


    1. I have automator recipe that trigger actions every time a new job_listing is created
    2. I have this code that automatically duplicate a job_listing into any available languages (languages managed by WPML)

    effect: Automator recipe is run for every duplication of the job_listing

    desired behavior: Automator recipe to be run only for the orginal job_listing creation and not for the creation of its duplicates.

    The code that automatically duplicates is this:

    
    
    add_action( 'wp_insert_post', 'my_duplicate_on_publishh' );
    function my_duplicate_on_publishh( $post_id ) {
    
        $post = get_post( $post_id );
    
        // don't save for autosave
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return $post_id;
        }
        // dont save for revisions
        if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
            return $post_id;
        }
        // dont save if it's not a job_listingw
        if ( isset( $post->post_type ) && $post->post_type !== 'job_listing' ) {
            return $post_id;
        }
    
        // we need this to avoid recursion see add_action at the end
        remove_action( 'wp_insert_post', 'my_duplicate_on_publishh' );
    
        // make duplicates if the post being saved
        // #1. itself is not a duplicate of another or
        // #2. does not already have translations
    
        $is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type );
    
        if ( !$is_translated ) {
            do_action( 'wpml_admin_make_post_duplicates', $post_id );
        }
    
        // must hook again - see remove_action further up
        add_action( 'wp_insert_post', 'my_duplicate_on_publishh' );
    }

    Can you tell what Automatio action I could temporary remove to prevent the execution of the automator recipe… kind of :
    remove_action( 'wp_insert_post',.....

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Prevent Automator to trigger multiple times when duplicating WPML translated pos’ is closed to new replies.