{"id":68,"date":"2009-08-07T22:30:34","date_gmt":"2009-08-07T20:30:34","guid":{"rendered":"https:\/\/www.opengis.ch\/?p=68"},"modified":"2020-04-29T16:08:00","modified_gmt":"2020-04-29T14:08:00","slug":"wordpress-wpml-iphone-app","status":"publish","type":"post","link":"https:\/\/www.opengis.ch\/fr\/2009\/08\/07\/wordpress-wpml-iphone-app\/","title":{"rendered":"wordpress iphone app with wpml"},"content":{"rendered":"<p>I&rsquo;ve a client using a wordpress multilingual blog with the wpml plugin (<a href=\"https:\/\/wpml.org\/\">wpml.org\/<\/a>) and that wants to use the wordpress iphone app (<a href=\"https:\/\/iphone.wordpress.org\/\">iphone.wordpress.org<\/a>). The app and the plugin work like a charm. the only problem is that in the app you can&rsquo;t set the post language, hence you are (well by now were \ud83d\ude42 ) able to post only using the default language.<br \/>\nI wrote a small PHP script<!--more--> to put in the root dir of your blog that updates the default language of the blog when called. so basically before using the iphone app you call the script using safari (https:\/\/domain.tdl\/blog\/set_post_lang.php?to=de) and then use the iphone application to post to your blog.<br \/>\nThe script requires minimal configuration, you have to set the blog_id (if you have a single install, 0 should be ok, but you can find this by looking at the wp_options table in the DB) and an array of valid languages. Please note that the script uses no authentication methods, up to you to decide if you want to implement it (very easy actually for example with http_auth or with a key). I didn&rsquo;t because the script does something very small and irrelevant from the security point of view.<br \/>\nAnd  here the code, enjoy.<\/p>\n<pre lang='PHP'><?php\n\/**\n * script to change the default language of a wpml installation\n * so that a new post written from fot example the iphone app is set to the right language\n *\n * @use call it like this: www.domain.tld\/set_post_lang.php?to=it\n * @author Marco Bernasocchi   marco@bernawebdesign.ch\n * @copyright LGPLv3\n *\/\n\/\/___________________SETTINGS________________\ndefine(\"BLOG_ID\",  \"0\"); \/\/id of the blog\n$active_languages = array(\"it\", \"de\"); \/\/use lowercase codes of the languages active in your blog\n\/\/___________________SCRIPT__________________\nrequire_once('wp-config.php');\/\/used to get hostname, DB, USER &#038; PASSW\n\/*check if the passed language is a valid one*\/\n$set_to = strtolower($_GET[\"to\"]);\nif(!in_array($set_to, $active_languages)) die('invalid language');\n\/*open DB connection *\/\n$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);\n\/* check connection *\/\nif (mysqli_connect_errno()) {\n    die('DB Connect failed');\n}\n\/* get the actual settings of the wpml plugin *\/\n$query = 'SELECT option_value from `'.DB_NAME.'`.`wp_options`\n          WHERE CONVERT(`wp_options`.`option_name` USING utf8) = \"icl_sitepress_settings\"\n          AND `wp_options`.`blog_id` = '.BLOG_ID.'\n          LIMIT 1;';\nif (($result = $mysqli->query($query)) && $result->num_rows == 1) {\n  while ($row = $result->fetch_assoc()) {\n        $value = $row[\"option_value\"];\n  }\n  \/* free result set *\/\n  $result->close();\n}\nelse die('Error getting the actual setting');\n\/* check if update needed *\/\n$new_pattern = '\"default_language\";s:2:\"'.$set_to.'\"';\n$replace = !preg_match(\"\/$new_pattern\/\",$value);\n\/* change the language then update the DB *\/\nif($replace){\n  $pattern = '\/\"default_language\";s:2:\"[a-z]{2}\"\/';\n  $value = preg_replace($pattern , $new_pattern, $value, 1);\n  $query = 'UPDATE `'.DB_NAME.'`.`wp_options`\n            SET `option_value` = ''.$value.''\n            WHERE CONVERT(`wp_options`.`option_name` USING utf8) = \"icl_sitepress_settings\"\n            AND `wp_options`.`blog_id` = '.BLOG_ID.'\n            LIMIT 1;';\n  if ($result = $mysqli->query($query)) {\n    echo 'Default post language is now set to '.strtoupper($set_to);\n    }\n  else echo 'Problem updating the language, please try again';\n}\nelse echo 'Default post language is already set to '.strtoupper($set_to);\n\/\/close DB connection\n$mysqli->close();\n?><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Solution to use the iphone application for multilingual blogging with wpml<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28],"tags":[125],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-web-development","tag-qgis-org"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":94,"url":"https:\/\/www.opengis.ch\/fr\/2009\/08\/15\/migrating-wordpress-from-gengo-to-wpml\/","url_meta":{"origin":68,"position":0},"title":"migrating wordpress from gengo to wpml","author":"Marco Bernasocchi","date":"15 ao\u00fbt 2009","format":false,"excerpt":"A client of mine used to have a multilingual blog using the Gengo plugin, which I consider by now unfortunatly dead. Fortunately, the guys at https:\/\/www.wpml.org did a great job creating a new plugin that works like a charm. I did the migration from one to the other and I\u2026","rel":"","context":"Dans &quot;Web Development&quot;","block_context":{"text":"Web Development","link":"https:\/\/www.opengis.ch\/fr\/category\/web-development\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":14471,"url":"https:\/\/www.opengis.ch\/fr\/2024\/06\/18\/supercharge-your-fieldwork-with-qfields-project-and-app-wide-plugins\/","url_meta":{"origin":68,"position":1},"title":"Supercharge your fieldwork with QField&rsquo;s project and app-wide plugins","author":"Mathieu","date":"18 juin 2024","format":false,"excerpt":"Imagine digitizing photos of spotted birds onto a vector point layer with a single tap? Now you can, thanks to QField\u2019s new plugin framework. Find all the details in our latest blog post!","rel":"","context":"Dans &quot;QField&quot;","block_context":{"text":"QField","link":"https:\/\/www.opengis.ch\/fr\/category\/gis\/qfield\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/qfield-bird-plugin.gif?fit=640%2C360&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/qfield-bird-plugin.gif?fit=640%2C360&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/qfield-bird-plugin.gif?fit=640%2C360&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":147,"url":"https:\/\/www.opengis.ch\/fr\/2010\/12\/01\/qgis-globe-plugin-installer-script\/","url_meta":{"origin":68,"position":2},"title":"QGis Globe Plugin installer script","author":"Marco Bernasocchi","date":"1 d\u00e9cembre 2010","format":false,"excerpt":"Lately, thanks to ma Master Thesis, I've been co-working on the Globe Plugin for QGis here my install script for a threaded version of QGis with the Globe Plugin. By now the Globe has stereo 3D support, keyboard navigation (try all the num key), mouse navigation, a gui to control\u2026","rel":"","context":"Dans &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.opengis.ch\/fr\/category\/programming\/cpp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":315,"url":"https:\/\/www.opengis.ch\/fr\/2011\/08\/24\/gsoc-2011-final-report\/","url_meta":{"origin":68,"position":3},"title":"GSoC 2011 final report","author":"Marco Bernasocchi","date":"24 ao\u00fbt 2011","format":false,"excerpt":"So, it is over, after 3 months working on QGIS for android as a Google Summer of code project it is now time to wrap up what I did and didn't do. First of all a QGIS android app exists now and it has many features including: - reading\/writing projects\u2026","rel":"","context":"Dans &quot;Android QGIS&quot;","block_context":{"text":"Android QGIS","link":"https:\/\/www.opengis.ch\/fr\/category\/gis\/qfield\/android-qgis\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":15209,"url":"https:\/\/www.opengis.ch\/fr\/2025\/03\/25\/unpacking-key-insights-from-our-qfield-workshop\/","url_meta":{"origin":68,"position":4},"title":"Unpacking key insights from our QField Workshop","author":"Anja Ottiger","date":"25 mars 2025","format":false,"excerpt":"This year, OPENGIS.ch celebrated its 10th anniversary in Bern, with an afternoon full of workshops attended by clients, long-term friends, and colleagues. Here, we will give a glimpse of QField: its vision, where it's headed, and the exciting features future users can look forward to. QField was created on June\u2026","rel":"","context":"Dans &quot;Newsletter 2025 March&quot;","block_context":{"text":"Newsletter 2025 March","link":"https:\/\/www.opengis.ch\/fr\/category\/newsletter\/newsletter-2025-march\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2025\/03\/qfield-rapidmapper.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2025\/03\/qfield-rapidmapper.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2025\/03\/qfield-rapidmapper.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2025\/03\/qfield-rapidmapper.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2025\/03\/qfield-rapidmapper.webp?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":14431,"url":"https:\/\/www.opengis.ch\/fr\/2024\/06\/11\/qfield-3-3-darien-it-is-just-the-beginning\/","url_meta":{"origin":68,"position":5},"title":"QField 3.3 \u201cDari\u00e9n\u201d: It is just the beginning","author":"Mathieu","date":"11 juin 2024","format":false,"excerpt":"Say hello to the game-changing plugin framework \u2013 revolutionizing the way you can enhance your workflows. Plus, we've packed in tons of new features and improvements, including enhanced drawing capabilities. A #QGIS #fieldwork new era\ud83c\udf1f","rel":"","context":"Dans &quot;GIS&quot;","block_context":{"text":"GIS","link":"https:\/\/www.opengis.ch\/fr\/category\/gis\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/33splash.png?fit=959%2C597&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/33splash.png?fit=959%2C597&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/33splash.png?fit=959%2C597&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.opengis.ch\/wp-content\/uploads\/2024\/06\/33splash.png?fit=959%2C597&ssl=1&resize=700%2C400 2x"},"classes":[]}],"jetpack_shortlink":"https:\/\/wp.me\/pbdBtI-16","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":1,"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":11240,"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/posts\/68\/revisions\/11240"}],"wp:attachment":[{"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.opengis.ch\/fr\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}