Automatically Duplicating Added Event Calandar Items on "Publish" with WPML

Home Forums Calendar Products Community Events Automatically Duplicating Added Event Calandar Items on "Publish" with WPML

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1282224
    Michael
    Participant

    What I am trying to achieve is to enable community events publishers using the “Add event to calendar” front-end feature to submit in whatever language and have it automatically duplicated into English as we have two languages and most people on the site are bi-lingual.

    I have found something that seems like is half the solution on WPML forums:
    —-

    /**
    * Duplicate a post/page/custom post on publish or update
    *
    **/
    add_action(‘save_post’, ‘wpml_duplicate_on_publish’);
    function wpml_duplicate_on_publish ( $post_id ) {
    global $sitepress, $iclTranslationManagement;

    // don’t save for autosave
    if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) {
    return $post_id;
    }
    // don’t save for revisions
    if ( isset( $post->post_type ) && $post->post_type == ‘revision’ ) {
    return $post_id;
    }
    // Check permissions
    if ( ‘page’ == $_POST[‘post_type’] ) {
    if ( !current_user_can( ‘edit_page’, $post_id ) ) {
    return $post_id;
    }
    } else {
    if ( !current_user_can( ‘edit_post’, $post_id ) ) {
    return $post_id;
    }
    }

    $master_post_id = $post_id;
    $master_post = get_post($master_post_id);
    $language_details_original = $sitepress->get_element_language_details($master_post_id, ‘post_’ . $master_post->post_type);

    // unhook this function so it doesn’t loop infinitely
    remove_action(‘save_post’, ‘wpml_duplicate_on_publish’);

    foreach($sitepress->get_active_languages() as $lang => $details){
    if($lang != $language_details_original->language_code){
    $iclTranslationManagement->make_duplicate($master_post_id, $lang);
    }
    }

    // re-hook this function
    add_action(‘save_post’, ‘wpml_duplicate_on_publish’);
    }

    REF: https://wpml.org/wpml-hook/wpml_admin_make_post_duplicates/

    This could be a very useful function to have on your plugin as no one likes to submit two events each in a different language since the main calendar is already WMPL ready.

    #1282782
    Cliff
    Member

    Hi, Michael. Thanks for sharing this.

    I understand the concept here, but Community Events doesn’t currently support WPML. However, this user managed to get it working on her own (at least to her satisfaction): https://theeventscalendar.com/support/forums/topic/conflict-with-wpml-anonymously-created-pending-events-hidden-in-admin-panel/

    Are you suggesting that this solution alone would essentially be all that’s needed for you to consider Community Events fully integrated with WPML?

    #1282831
    Michael
    Participant

    I’ve actually been able to fix a bunch of broken issues with WPML and your plugin by creating some custom hacks and walk arounds, it behaves pretty well.

    Except for the front-end submission duplications. I think that if front-end submission can automatically create the same event calendar item in both languages then it is 95% compatible. I haven’t test it with other plugins. I am only using your Community Events and the Core Calendar Pro base.

    #1282882
    Cliff
    Member

    Thanks for that feedback.

    So are you saying the code snippet you shared is working when an event is created via wp-admin but not working when an event is created via the front-end CE form?

    Also, with the specific code snippet you shared, I’d be concerned about post updates, whether done via wp-admin or the CE form.

    For example, if the post_content was “Yellow” and 3 duplicates were created, then the initial post’s content is changed to “Red”, would 3 more duplicates get created — now 3 with “Yellow” and 4 with “Red” exist?

    #1292857
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Automatically Duplicating Added Event Calandar Items on "Publish" with WPML’ is closed to new replies.