• Resolved szed

    (@szed)


    Hi !
    For an automatic WP install, i need to :
    ? Create lang (FR / EN) in PHP – is there a add_lang($name,$code,$other_params) function ?
    ? Create a page EN with a FR translation – so maybe a function who tell “this page is the translation of this page”.

    Does anything like that exist ?

    Thanks!

    https://www.ads-software.com/plugins/polylang/

    Edit : for the second question, i find : pll_set_post_language which will do the job i think.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chouby

    (@chouby)

    Hi!

    Please have a look to PLL_Admin_Model::add_language() in admin/admin-model.php

    Thread Starter szed

    (@szed)

    Thanks !
    I tried

    if ( class_exists('PLL_Admin_Model') ) {
    				$PLL_Admin_Model = new PLL_Admin_Model;
    				$args_FR = array(
    					'name' => 'Fran?ais',
    					'slug' => 'fr',
    					'locale' => 'fr_FR',
    					'rtl' => '0',
    					'term_group' => '0'
    				);
    				$args_EN = array(
    					'name' => 'English',
    					'slug' => 'en',
    					'locale' => 'en_GB',
    					'rtl' => '0',
    					'term_group' => '0'
    				);
    				if($lang_default && $lang_default == 'fr'){
    					$lang = $PLL_Admin_Model->add_language($args_FR);
    					$lang = $PLL_Admin_Model->add_language($args_EN);
    				} else {
    					$lang = $PLL_Admin_Model->add_language($args_EN);
    					$lang = $PLL_Admin_Model->add_language($args_FR);
    				}
    			}

    But i got a lot of warning :

    Warning: Missing argument 1 for PLL_Model::__construct(), called in /home/****/public_html/wp-content/plugins/ngfnetwork/*****.php on line 483 and defined in /home/****/public_html/wp-content/plugins/polylang/include/model.php on line 20

    Notice: Undefined index: default_lang in /home/*****/public_html/wp-content/plugins/polylang/include/links-directory.php on line 117

    then a message

    Polylang has been deactivated because you upgraded from a too old version.
    Please upgrade first to 0.9.8 before ugrading to 1.8.4.

    ??

    Thread Starter szed

    (@szed)

    Hi !
    I’m close.

    Adding one language work.
    But i can’t add two because of the “add_settings_error( ‘general’, ‘pll_languages_created’, __( ‘Language added.’, ‘polylang’ ), ‘updated’ );” applied to first language.

    When i call add_language for my second lang, add_language start by the validade_lang function which return false because of this previous add_settings_error.

    Any idea how to do this, without editing your plugin ?
    I am looking for something like renove_settings_error which i could call between my two add_language…

    Thanks !

    Thread Starter szed

    (@szed)

    Ok,
    i did it with

    $installEN = $PLL_Admin_Model->add_language($args_EN);
    global $wp_settings_errors;
    $wp_settings_errors= '';
    $installFR = $PLL_Admin_Model->add_language($args_FR);

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Create lang in php’ is closed to new replies.