Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate job offer feature - issue with Polylang #2291

Open
Lens40 opened this issue Jul 7, 2022 · 6 comments
Open

Duplicate job offer feature - issue with Polylang #2291

Lens40 opened this issue Jul 7, 2022 · 6 comments
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request".

Comments

@Lens40
Copy link

Lens40 commented Jul 7, 2022

I run WP Job Manager with Polylang. To display all jobs in all language I duplicate the job offers and sync them with a custom function. This allows the users to modify their job offers in any language and making sure those changes are synced to the other languages as well.

When a job is synced with its translations some taxonomies are create by Polylang to link them together. The duplication of theses taxonomies to the new job offer also creates the issue/conflict with WP Job Manager duplication feature.

When duplicating a job offer WP Job Manager copies all available taxonomies, including the Polylang ones which will link the new job offer to the translations of the old job offer which just was duplicated. This is something that should not happen creating some issues with the translations and linking.

The file where the function is embedded is wp-job-manager-functions.php Line 1527-1535.

$taxonomies = get_object_taxonomies( $post->post_type ); foreach ( $taxonomies as $taxonomy ) { $post_terms = wp_get_object_terms( $post_id, $taxonomy, [ 'fields' => 'slugs' ] ); wp_set_object_terms( $new_post_id, $post_terms, $taxonomy, false ); }

Is there an option to add a filter hook before foreach to remove certain taxonomies? Or limit the copying to only a certain type of taxonomies which are related to WP Job Manager only?

Thanks for your input. Best regards Lens

@Lens40
Copy link
Author

Lens40 commented Jul 8, 2022

Polylang is proposing the following adjustment:

/** * Copy taxonomies. */
$taxonomies = apply_filters( 'wpjm_filter_taxonomy_to_duplicate', get_object_taxonomies( $post->post_type ) ); foreach ( $taxonomies as $taxonomy ) { $post_terms = wp_get_object_terms( $post_id, $taxonomy, [ 'fields' => 'slugs' ] ); wp_set_object_terms( $new_post_id, $post_terms, $taxonomy, false ); }

Allowing them to filter their translation taxonomies by adding a filter into their plugin:

add_filter( 'wpjm_filter_taxonomy_to_duplicate', 'filter_taxo' ); function filter_taxo( $taxonomies ){ $taxonomy_to_remove = array( 'post_translations' ); return array_diff( $taxonomies, $taxonomy_to_remove); }

Is this something you would consider for the next release?

@Gnodesign
Copy link
Collaborator

@dadish @fjorgemota @onubrooks Could we please add a filter to the $taxonomy and include it in 1.37.1? It will allow users to expand the Polylang/WPML (and other multilingual plugins) compatibility from their side as @Lens40 mentioned above.

$taxonomies = get_object_taxonomies( $post->post_type );

@Lens40
Copy link
Author

Lens40 commented Aug 8, 2022

Thanks Gino for supporting that :)

@thabotswana
Copy link

A user provided a solution from WPML for duplicate jobs in Resume Manager in 9002683-zd-a8c:

To solve this issue, the following function will need to be adapted:

Inside /wp-content/plugins/wp-job-manager-resumes/wp-job-manager-resumes/includes/wp-resume-manager-functions.php on line 642:

Replace this function:

function resume_manager_count_user_resumes( $user_id = 0 ) {
    global $wpdb;
 
    if ( ! $user_id ) {
        $user_id = get_current_user_id();
    }
 
    return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_author = %d AND post_type = 'resume' AND post_status IN ( 'publish', 'pending', 'expired', 'hidden' );", $user_id ) );
}

with:

function resume_manager_count_user_resumes( $user_id = 0 ) {
    global $wpdb;
 
    if ( ! $user_id ) {
        $user_id = get_current_user_id();
    }
 
    // Check if WPML is active
    if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
        // Query that excludes translated resumes
        return $wpdb->get_var( $wpdb->prepare( "
            SELECT COUNT(p.ID)
            FROM {$wpdb->posts} p
            LEFT JOIN {$wpdb->prefix}icl_translations t ON p.ID = t.element_id
            WHERE p.post_author = %d
            AND p.post_type = 'resume'
            AND p.post_status IN ( 'publish', 'pending', 'expired', 'hidden' )
            AND t.language_code = %s
            AND t.source_language_code IS NULL;
        ", $user_id, apply_filters( 'wpml_default_language', null ) ) );
    }
 
    // Default query if WPML is not active
    return $wpdb->get_var( $wpdb->prepare( "
        SELECT COUNT(ID)
        FROM {$wpdb->posts}
        WHERE post_author = %d
        AND post_type = 'resume'
        AND post_status IN ( 'publish', 'pending', 'expired', 'hidden' );
    ", $user_id ) );
}

Copy link

github-actions bot commented Nov 7, 2024

Support References

This comment is automatically generated. Please do not edit it.

  • 9002683-zen

@github-actions github-actions bot added the Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". label Nov 7, 2024
@diiegopereira
Copy link

diiegopereira commented Nov 13, 2024

Hi guys, this is Diego from the WPML compatibility team.

We got a new report for this issue here: https://wpml.org/forums/topic/jobmanager-resume-limit-count-is-false/ - the workaround from here resolve the issue.

If you need any help from our team, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request".
Projects
None yet
Development

No branches or pull requests

4 participants