Title: ben.IT's Replies | WordPress.org

---

# ben.IT

  [  ](https://wordpress.org/support/users/benit/)

 *   [Profile](https://wordpress.org/support/users/benit/)
 *   [Topics Started](https://wordpress.org/support/users/benit/topics/)
 *   [Replies Created](https://wordpress.org/support/users/benit/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/benit/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/benit/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/benit/engagements/)
 *   [Favorites](https://wordpress.org/support/users/benit/favorites/)

 Search replies:

## Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Polylang] [Plugin : Polylang] – How to get the latest comments for the current language ?](https://wordpress.org/support/topic/plugin-polylang-how-to-get-the-latest-comments-for-the-current-language/)
 *  Thread Starter [ben.IT](https://wordpress.org/support/users/benit/)
 * (@benit)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-polylang-how-to-get-the-latest-comments-for-the-current-language/#post-3143989)
 * Don’t know why either. Thanks for your answer.
    Ben
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Polylang] [Plugin : Polylang] – How to get the latest comments for the current language ?](https://wordpress.org/support/topic/plugin-polylang-how-to-get-the-latest-comments-for-the-current-language/)
 *  Thread Starter [ben.IT](https://wordpress.org/support/users/benit/)
 * (@benit)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-polylang-how-to-get-the-latest-comments-for-the-current-language/#post-3143907)
 * Hi, I find a solution which works using the fine polylang API :
 *     ```
       //Original : does not manage language. display all comments. doesn't care about the comment language
       		//$comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );
       		/************************************************************/
   
       		$current_lng= pll_current_language(); //retrieve current language
       		$lng_objects = get_posts(array(
       		'post_type' => 'post',
       		'lang' => $current_lng, // use language slug in the query
       		'showposts' => 150 //remove if problem. here for perf. this prevents loading all posts.
       ));
       $lng_ids=array() ;
       foreach ($lng_objects as $objects)
       	array_push($lng_ids, $objects->ID) ;
       $string_lng_ids=implode(",", $lng_ids); //build ID string for sql query
   
       global $wpdb;
       $query_lng_comments="
       select wp3_comments.*
       from wp3_comments
       inner join wp3_posts on wp3_posts.ID=wp3_comments.comment_post_ID
       where comment_approved=1
       and wp3_posts.ID in ($string_lng_ids)
       order by comment_date desc
       limit 0,$number
       ";
       $comments=$wpdb->get_results($query_lng_comments);
       /*********************************************************/
       ```
   
 * Hope this could help.
    greetings, ben
 * _[Moderator Note: Please post code or markup snippets between backticks or use
   the code button. As it stands, your code may now have been permanently damaged/
   corrupted by the forum’s parser.]_
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Polylang] [polylang] How can I set defaullt value to polylang translations ?](https://wordpress.org/support/topic/how-can-i-set-defaullt-value-to-polylang-translations/)
 *  Thread Starter [ben.IT](https://wordpress.org/support/users/benit/)
 * (@benit)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/how-can-i-set-defaullt-value-to-polylang-translations/#post-3126678)
 * Hi chouby . Thanks for your answer. I wrote this yesterday to manage translation
   import when setting up the site.
    I my case I need french and english translation:
 *     ```
       <?php
       require_once( ABSPATH.'wp-content/plugins/polylang/include/admin-base.php');
       require_once( ABSPATH.'wp-content/plugins/polylang/include/admin.php');
   
       /**
        * Manage translation object for initial import. Need the string reference, the french translation and the english translation
        *
        *
       */
       class Translation
       {
       	public $termReference ;
       	public $termTranslationFr ;
       	public $termTranslationEn ;
   
       	public function __construct($termReference, $termTranslationFr, $termTranslationEn)
       	{
       		$this->termReference=$termReference ;
       		$this->termTranslationFr=$termTranslationFr;
       		$this->termTranslationEn=$termTranslationEn ;
       	}
       }//end of class Translation
   
       /**
        * Manage translation import. Imports Translation objects.
        * This class allows to import translation to polylang backoffice. polylang sets options in wp3_options.
        * Query to see how polylang options : select * from wp3_options where option_name like 'polylang_mo%'
        * This import mechanism his largely inspired by the 2 followings methods of polylang located in wp-content/plugins/polylang/include/base.php :
        * function mo_export($mo, $lang)
        * function mo_import($lang)
        */
       class TranslationImporter
       {
       	private $tableTranslations ; //contain all Translation objects to import
       	private $moFr ; //MO object for french translation
       	private $moEn ; //MO object for english translation
   
       	private $polylang_mo_fr_code='polylang_mo251' ;
       	private $polylang_mo_en_code='polylang_mo253' ;
   
       	public function __construct()
       	{
       		$this->moEn = new MO();
       		$this->moFr = new MO();
       		$this->tableTranslations = array();
       	}
   
       	/**
       	 * adds a Translation object to
       	 * @param unknown $translation the array tableTranslations
       	 */
       	public function addTranslationToImport($translation)
       	{
       		array_push($this->tableTranslations,$translation);
       	}
   
       	/**
       	 * import translations from tableTranslations attribute to the french MO and english MO attributes.
       	 */
       	public function importTranslationToMo()
       	{
       		foreach ($this->tableTranslations as $row)
       		{
       			//make_entry('reference string ', 'translation')
       			$this->moFr->add_entry($this->moFr->make_entry($row->termReference, $row->termTranslationFr));
       			$this->moEn->add_entry($this->moEn->make_entry($row->termReference, $row->termTranslationEn));
       		}
       	}
   
       	/**
       	 * Update polylang options from the mo attributes which has been fill in with the importTranslationToMo method
       	 */
       	public function updateOptionsFromMO()
       	{
       		$stringsFr = array();
       		foreach ($this->moFr->entries as $entry)
       			$strings[] = array($entry->singular, $this->moFr->translate($entry->singular));
       		update_option('polylang_mo'.'251', $strings);
   
       		$stringsEn = array();
       		foreach ($this->moEn->entries as $entry)
       			$strings[] = array($entry->singular, $this->moEn->translate($entry->singular));
       		update_option('polylang_mo'.'253', $strings);
   
       	}
       }//end of class TranslationImporter
       ```
   
 *     ```
       /**
        * This main script imports translation into polylang.
       */
       require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php') ; //use $_SERVER['DOCUMENT_ROOT'] to refer to WP root while ABSPATH isnt yet set.
       require_once(ABSPATH.'wp-content/plugins/international-int/classes/InternationalIntTranslationImporter.class.php');
       $start_time = microtime(true); //calcul exec time for fun 
   
       $TranslationImporter = new TranslationImporter();
       //add the translations to the importer
       $TranslationImporter->addTranslationToImport(new Translation('annuaire', 'annuaire', 'adress book'));
       $TranslationImporter->addTranslationToImport(new Translation('vos commentaires', 'c fr ', 'c en'));
       $TranslationImporter->addTranslationToImport(new Translation('INTRANET INTERNATIONAL', 'fr ', 'en'));
       $TranslationImporter->addTranslationToImport(new Translation('Evénements clients', 'Evénements clients', 'customers event'));
       $TranslationImporter->addTranslationToImport(new Translation('ref', 'fr ', 'en'));
   
       $TranslationImporter->importTranslationToMo(); //generate MOs in the importer
       $TranslationImporter->updateOptionsFromMO(); //update WP options from MOs importers
   
       echo 'end of translation import. execution took : '.(microtime(true) - $start_time).' seconds.';
       ```
   
 * greetings,
    ben
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Role Scoper (Obsolete - Please install PublishPress Permissions)] [Plugin: Role Scoper] [Role scoper] how to manage visibility of the custom fields ?](https://wordpress.org/support/topic/plugin-role-scoper-role-scoper-how-to-manage-visibility-of-the-custom-fields/)
 *  Thread Starter [ben.IT](https://wordpress.org/support/users/benit/)
 * (@benit)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-role-scoper-role-scoper-how-to-manage-visibility-of-the-custom-fields/#post-3053224)
 * hi kevinB,
    Those methods help me :
 * $role_scoper_group_id = ScoperAdminLib::get_group_by_name(‘my group ‘)->ID;
    
   $group_member = ScoperAdminLib::get_group_members($role_scoper_group_id ) ;
 * enjoy 😉
    greetings, ben
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Role Scoper (Obsolete - Please install PublishPress Permissions)] [Plugin: Role Scoper] Getting the group of the current user to display/add extra custom fields](https://wordpress.org/support/topic/plugin-role-scoper-getting-the-group-of-the-current-user-to-displayadd-extra-custom-fields/)
 *  Thread Starter [ben.IT](https://wordpress.org/support/users/benit/)
 * (@benit)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-role-scoper-getting-the-group-of-the-current-user-to-displayadd-extra-custom-fields/#post-3092083)
 * Hi, I found what I want in rolescoper core source.
    Those methods help me :
 * $role_scoper_group_id = ScoperAdminLib::get_group_by_name(‘my group ‘)->ID;
    
   $group_member = ScoperAdminLib::get_group_members($role_scoper_group_id ) ;
 * enjoy 😉
    greetings, ben
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [package a script called by http in a plugin way](https://wordpress.org/support/topic/package-a-script-called-by-http-in-a-plugin-way/)
 *  Thread Starter [ben.IT](https://wordpress.org/support/users/benit/)
 * (@benit)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/package-a-script-called-by-http-in-a-plugin-way/#post-3055989)
 * Hi, thanks for your answer.
    I’ll try to be more precise.
 * I have already read this resource and know how to write my own (very basic) plugin.
 * I have developed a script which instantiate an XML RPC client to synchronise 
   content between 2 wordpress instances.
 * I perform HTTP requests to run this script : [http://mywpinstance.com/myscript.php](http://mywpinstance.com/myscript.php)
 * now I would like to package it as a plugin.
 *  To perform this, I think I’m gonna try adding a rewrite rule,
    I will call :
   [http://mywpinstance.com/myscript.php](http://mywpinstance.com/myscript.php) 
   which will execute the code of [http://mywpinstance.com/wp-content/plugins/myplugin/myplugin.php](http://mywpinstance.com/wp-content/plugins/myplugin/myplugin.php)
 *  Hope this will work !
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[JSON API] [Plugin: JSON API] How can i create post with attachments?](https://wordpress.org/support/topic/plugin-json-api-how-can-i-create-post-with-attachments/)
 *  [ben.IT](https://wordpress.org/support/users/benit/)
 * (@benit)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-json-api-how-can-i-create-post-with-attachments/#post-2913325)
 * Hi,
    I am also concerned by his issue. Does anybody get an idea/snippet ?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Polylang] [Plugin : Polylang] -How to set language information used by polylang ?](https://wordpress.org/support/topic/how-to-set-language-information-used-by-polylang/)
 *  Thread Starter [ben.IT](https://wordpress.org/support/users/benit/)
 * (@benit)
 * [14 years ago](https://wordpress.org/support/topic/how-to-set-language-information-used-by-polylang/#post-3021352)
 * Thanks for your answer Chouby.
    Inspecting Polylang code, I found what I want
   to set the default language of my posts sended via XML-RPC. I wrote the following
   function which is a snippet of polylang sources :
 *     ```
       <?php
       require('../wp-load.php');
       require_once('../wp-content/plugins/polylang/include/admin-base.php');
       require_once('../wp-content/plugins/polylang/include/admin.php');
   
       /*
       This is a hack from /wp-content/plugins/polylang/include/admin.php line 243 to 262
       * */
       function setDefaultLanguage ($defaultLanguage='fr') {
       	$polylang = new Polylang_Admin();
       	global $wpdb ;
   
       	$untranslated = $polylang->get_untranslated(); var_dump($untranslated);
       	$lang = $polylang->get_language($defaultLanguage); var_dump($lang);
   
       	$values = array();
       	foreach ($untranslated['posts'] as $post_id)
       	{$values[] = $wpdb->prepare("(%d, %d)", $post_id, $lang->term_taxonomy_id); }
       	echo 'values='; var_dump($values);
   
       	if ($values) {
       		echo 'ipmlode values : '.implode(',', $values) ;
       		$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES " . implode(',', $values));
       		wp_update_term_count($lang->term_taxonomy_id, 'language'); // updating term count is mandatory (thanks to AndyDeGroo)
       	}
   
       	$values = array();
       	foreach ($untranslated['terms'] as $term_id)
       	{$values[] = $wpdb->prepare("(%d, %s, %d)", $term_id, '_language', $lang->term_id);}
       	echo 'values='; var_dump($values);
   
       	if ($values)
       	$wpdb->query("INSERT INTO $wpdb->termmeta (term_id, meta_key, meta_value) VALUES " . implode(',', $values));
   
       }
   
       setDefaultLanguage('fr');
       ```
   
 * Ben
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [problem using get_posts inside a function. same code works properly outisde](https://wordpress.org/support/topic/problem-using-get_posts-inside-a-function-same-code-works-properly-outisde/)
 *  Thread Starter [ben.IT](https://wordpress.org/support/users/benit/)
 * (@benit)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/problem-using-get_posts-inside-a-function-same-code-works-properly-outisde/#post-2954648)
 * thanks for your reply, but this doesn’t fix the bug, still the same id returned.
 * any idea ?
    ben

Viewing 9 replies - 1 through 9 (of 9 total)