{"id":944883,"date":"2015-02-26T08:19:24","date_gmt":"2015-02-26T16:19:24","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/"},"modified":"2015-03-05T06:14:54","modified_gmt":"2015-03-05T14:14:54","slug":"solution-for-wpml-events-calendar-pro-recurring-events-compatibility","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/","title":{"rendered":"Solution for WPML + Events Calendar PRO Recurring Events Compatibility"},"content":{"rendered":"<p>In reference to <a href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/wpml-events-calendar-pro-recurring-events-compatibility\/#dl_post-28258\" target=\"_blank\">this post<\/a>, we have come up with a solution that works for us to force newly-created Events Calendar PRO recurring events to appear when using WPML Sitepress MultiLingual CMS.<\/p>\n<p>I am happy to share the full source code (developed as a single-file plugin) in hopes that it will a) potentially help other users encountering this frustrating incompatibility and b) support Modern Tribe in finding an official, permanent solution within their codebase as soon as possible.<\/p>\n<p>WPML and Events Calendar PRO are two great plugins, biggest and best of their kind. They really should work together.<\/p>\n<p>Here is the code:<\/p>\n<pre><code>&lt;?php\n\/*\nPlugin Name: WPML Events Calendar PRO Sync\nPlugin URI: http:\/\/www.wordpress.org\/plugins\/\nDescription: Keeps recurring events created in The Events Calendar PRO in sync with WPML Multilingual CMS translation data so that the events show up properly. This plugin is not endorsed by or affiliated with OnTheGoSystems, Inc., makers of WPML Multilingual CMS, or Modern Tribe, Inc., makers of The Events Calendar PRO.\nVersion: 0.1a\nAuthor: Robert Peake\nAuthor URI: http:\/\/www.peakepro.com\/\nText Domain: wpml-ecp-sync\nDomain Path: \/languages\/\n*\/\nif ( !function_exists( &#039;add_action&#039; ) ) {\n    die();\n}\n\nregister_activation_hook(__FILE__, &#039;wpml_ecp_sync_activate&#039;);\n\nfunction wpml_ecp_sync_activate() {\n\tif (!class_exists(&#039;SitePress&#039;)) {\n\t\twpml_ecp_sync_trigger_error_message(__(&#039;This plugin depends upon WPML Multilingual CMS plugin being active&#039;,&#039;wpml-ecp-sync&#039;));\n\t}\t\t\n\tif (!class_exists(&#039;TribeEventsPro&#039;)) {\n\t\twpml_ecp_sync_trigger_error_message(__(&#039;This plugin depends upon the The Events Calendar PRO plugin being active&#039;,&#039;wpml-ecp-sync&#039;));\n\t}\t\t\n}\nfunction wpml_ecp_sync_trigger_error_message($message) {\n    if(isset($_GET[&#039;action&#039;]) &amp;&amp; $_GET[&#039;action&#039;] == &#039;error_scrape&#039;) {\n        echo &#039;&lt;div class=&quot;wrap&quot;&gt;&lt;p style=&quot;font-family: \\&#039;Open Sans\\&#039;,sans-serif; font-size: 13px; color: #444;&quot;&gt;&#039; . $message . &#039;&lt;\/p&gt;&lt;\/div&gt;&#039;;\n        exit;\n    } else {\n        throw new Exception($message);\n    }\n}\n\/* Inserts translation data for everything, but only works if no translations are yet present *\/\nfunction wpml_ecp_init_all() {\n    $s = new SitePress();\n    $languages = $s-&gt;get_languages();\n    foreach($languages as $language) {\n        if (isset($language[&#039;code&#039;]) &amp;&amp; $s-&gt;is_active_language($language[&#039;code&#039;])) {\n            $result = $s-&gt;prepopulate_translations($language[&#039;code&#039;]);\n        }\n    }\n    return $result;\n}\n\/* Inserts translation data for post children that do not yet have translation data *\/\nfunction wpml_ecp_sync_all($post_type = TribeEvents::POSTTYPE) {\n    global $wpdb;\n    $prefix = $wpdb-&gt;prefix;\n    $results = array();\n    $one_translation = $wpdb-&gt;get_var( &quot;SELECT translation_id FROM {$prefix}icl_translations LIMIT 1&quot; );\n    if (!is_numeric($one_translation) ) { \/\/no translations yet, init\n        wpml_ecp_init_all();\n    } else { \/\/translations exist, sync\n        $query =    &quot;SELECT ID,post_parent from {$prefix}posts p\n                    LEFT JOIN {$prefix}icl_translations t \n                    ON p.ID = t.element_id AND t.element_type = &#039;post_{$post_type}&#039;\n                    where post_parent!=0 AND post_type=&#039;{$post_type}&#039;\n                    and post_status IN (&#039;draft&#039;, &#039;publish&#039;,&#039;schedule&#039;,&#039;future&#039;,&#039;private&#039;, &#039;pending&#039;)\n                    and t.element_id is null&quot;;\n        $result = $wpdb-&gt;get_results($query);\n        foreach( $result as $row) {\n            $post_id = $row-&gt;ID;\n            $parent_id = $row-&gt;post_parent;\n            $results[] = wpml_ecp_update_child($post_id,$parent_id);\n        }\n        return $results;\n    }\n}\n\/* updates a single child post with correct translation data based on its parent *\/\nfunction wpml_ecp_update_child($post_id,$parent_id) {\n    global $wpdb;\n    $prefix = $wpdb-&gt;prefix;\n    $results = array();\n    $parent_obj = $wpdb-&gt;get_row($wpdb-&gt;prepare(&quot;select element_type, language_code \n                                                from {$prefix}icl_translations \n                                                where element_id=%d&quot;,\n                                                $parent_id));\n    if($parent_obj &amp;&amp; strlen($parent_obj-&gt;element_type) &gt; 0 &amp;&amp; strlen($parent_obj-&gt;language_code) &gt; 0) {\n        $trid = 1 + $wpdb-&gt;get_var( &quot;SELECT MAX(trid) FROM {$wpdb-&gt;prefix}icl_translations&quot; );\n        $data = array(&#039;element_id&#039; =&gt; $post_id);\n        $data[&#039;element_type&#039;] = $parent_obj-&gt;element_type;\n        $data[&#039;trid&#039;] = $trid;\n        $data[&#039;language_code&#039;] = $parent_obj-&gt;language_code;\n        $query_result = $wpdb-&gt;insert($prefix.&#039;icl_translations&#039;, $data, array(&#039;%d&#039;,&#039;%s&#039;,&#039;%d&#039;,&#039;%s&#039;) );\n        if (!$query_result) {\n            $results[] = array(&#039;status&#039; =&gt; &#039;error&#039;, &#039;parent_id&#039; =&gt; $parent_id, &#039;child_id&#039; =&gt; $post_id, &#039;parent_obj&#039; =&gt; $parent_obj);\n        } else {\n            $results[] = array(&#039;status&#039; =&gt; &#039;OK&#039;, &#039;parent_id&#039; =&gt; $parent_id, &#039;child_id&#039; =&gt; $post_id, &#039;parent_obj&#039; =&gt; $parent_obj);\n        }\n    } else {\n        $results[] = array(&#039;status&#039; =&gt; &#039;error&#039;, &#039;parent_id&#039; =&gt; $parent_id, &#039;child_id&#039; =&gt; $post_id, &#039;parent_obj&#039; =&gt; $parent_obj);\n    }\n    return $results;\n}\n\/* Takes a parent post ID and updates those children who do not yet have translation data *\/\n\/* @TODO: this function currently only handles inserts; modify to handle delete\/update for optimal data tidiness *\/\nfunction wpml_ecp_update_after_save($parent_post_id) {\n    global $wpdb;\n    $prefix = $wpdb-&gt;prefix;\n    $post_type = TribeEvents::POSTTYPE;\n    $results = array();\n    if ( $real_parent_post_id = wp_is_post_revision( $parent_post_id ) ) {\n        $parent_post_id = $real_parent_post_id;\n    }\n    $query =    &quot;SELECT ID,post_parent from {$prefix}posts p\n                LEFT JOIN {$prefix}icl_translations t \n                ON p.ID = t.element_id AND t.element_type = &#039;post_{$post_type}&#039;\n                where post_parent=%s AND post_type=&#039;{$post_type}&#039;\n                and post_status IN (&#039;draft&#039;, &#039;publish&#039;,&#039;schedule&#039;,&#039;future&#039;,&#039;private&#039;, &#039;pending&#039;)\n                and t.element_id is null&quot;;\n    $result = $wpdb-&gt;get_results($wpdb-&gt;prepare($query,$parent_post_id));\n    foreach( $result as $row) {\n        $child_post_id = $row-&gt;ID;\n        wpml_ecp_update_child($child_post_id,$parent_post_id);\n    }\n}\nadd_action( TribeEvents::POSTTYPE.&#039;_update_meta&#039;, &#039;wpml_ecp_update_after_save&#039;, 30, 1);<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-944883","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Solution for WPML + Events Calendar PRO Recurring Events Compatibility -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Solution for WPML + Events Calendar PRO Recurring Events Compatibility -\" \/>\n<meta property=\"og:description\" content=\"In reference to this post, we have come up with a solution that works for us to force newly-created Events Calendar PRO recurring events to appear when using WPML Sitepress MultiLingual CMS. I am happy to share the full source code (developed as a single-file plugin) in hopes that it will a) potentially help other [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/\" \/>\n<meta property=\"article:modified_time\" content=\"2015-03-05T14:14:54+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/\",\"name\":\"Solution for WPML + Events Calendar PRO Recurring Events Compatibility -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2015-02-26T16:19:24+00:00\",\"dateModified\":\"2015-03-05T14:14:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Calendar Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Events Calendar PRO\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Solution for WPML + Events Calendar PRO Recurring Events Compatibility\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Solution for WPML + Events Calendar PRO Recurring Events Compatibility -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/","og_locale":"en_US","og_type":"article","og_title":"Solution for WPML + Events Calendar PRO Recurring Events Compatibility -","og_description":"In reference to this post, we have come up with a solution that works for us to force newly-created Events Calendar PRO recurring events to appear when using WPML Sitepress MultiLingual CMS. I am happy to share the full source code (developed as a single-file plugin) in hopes that it will a) potentially help other [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/","article_modified_time":"2015-03-05T14:14:54+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/","name":"Solution for WPML + Events Calendar PRO Recurring Events Compatibility -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2015-02-26T16:19:24+00:00","dateModified":"2015-03-05T14:14:54+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/solution-for-wpml-events-calendar-pro-recurring-events-compatibility\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Calendar Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/"},{"@type":"ListItem","position":4,"name":"Events Calendar PRO","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/"},{"@type":"ListItem","position":5,"name":"Solution for WPML + Events Calendar PRO Recurring Events Compatibility"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/944883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/944883\/revisions"}],"predecessor-version":[{"id":944988,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/944883\/revisions\/944988"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=944883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}