Overview

Classes

  • CMLLanguage
  • CMLPost
  • CMLTranslations
  • CMLUtils

Functions

  • cml_dropdown_langs
  • cml_get_browser_lang
  • cml_get_menu
  • cml_get_notice
  • cml_get_the_link
  • cml_is_homepage
  • cml_show_flags
  • Overview
  • Class
  • Tree

Class CMLPost

This class is used to get/set post translation/language or get language by its id

Located at api.php
Methods summary
public static stdObject
# get_language_by_id( int/string $post_id )

return language object by post id

return language object by post id

this function return "null" if post doesn't exists in any language

Parameters

$post_id
int/string
$post_id - id of post/page

Returns

stdObject
public static integer
# get_language_id_by_id( integer $post_id, boolean $meta = false )

return language id by post id

return language id by post id

Parameters

$post_id
integer
$post_id - id of post/page
$meta
boolean
$meta - default false. If true use wp function "get_post_meta", instead of get_language_by_id method to get language of post. In backend I need to get information by post meta, or I'll lost "all languages" ( = 0 ) information.

Returns

integer
public static string
# get_language_slug_by_id( integer $post_id )

get language slug by post id

get language slug by post id

Parameters

$post_id
integer
$post_id post/page id

Returns

string
public static integer
# get_translation( int/string $lang, integer $post_id )

get the translation id, if exists, in selected language

get the translation id, if exists, in selected language

this function will return 0 if no translation is found.

Parameters

$lang
int/string
$lang - language id/slug in which return translation
$post_id
integer
$post_id - post id

Returns

integer
public static
# get_translations( integer $post_id, boolean $force = false )

get all available translations of post

get all available translations of post

This function will return Array containing all info about linked posts

Array(
  • [language slug] => [post_id]
  • ...
  • [indexes] => Array
    In this subarray there are all linked posts, including $post_id
    • [language slug] => [post_id]
    • ...
  • [linked] => Array
    In this subarray there are only linked post indexes
    • [linked language slug] => [linked_id]
    • ...
)

Parameters

$post_id
integer
$post_id - post id
$force
boolean
$force - force to rebuild meta. ( This parameter is used internally by CML ) return Array

Example


Array (
  • [it] => 2552
  • [en] => 541
  • [eo] => 0
  • [indexes] => Array (
    • [it] => 2552
    )
  • [others] => Array (
    • [en] => 541
)
public static
# set_language( int/string $lang, integer $post_id )

set language of post

set language of post

This function will unlink $post_id by its translations

Parameters

$lang
int/string
$lang - post language id/slug
$post_id
integer
$post_id - post id
public static
# set_translation( integer $post_id, int/string $linked_lang, integer $linked_post, integer $post_lang = null )

set single translation to post id

set single translation to post id

This function is used to link 2 posts

When you link a post to single translation, relations with other language will not be losed. If you want remove other relations, you have to use set_language method first.

Parameters

$post_id
integer
$post_id - post to set translation
$linked_lang
int/string
$linked_lang - language id/slug of linked post
$linked_post
integer
$linked_post - post id of translation
$post_lang
integer
$post_lang ( optional ) - language of $post_id. If null, It will get from database
public static
# set_translations( mixed $post_id, mixed $translations, mixed $post_lang = null )

add multiple translations to post id

add multiple translations to post id

This function will update relations only from $post_id with $translations posts, so relations from $post_id and languages than doesn't exists in $translations array will not be broken.

If you need to set relation only from $post_id and $translations, and remove the other one, you have to "break" them using set_language method first.

Parameters

$post_id
mixed
$post_id - post to set translation+
$translations
mixed
$translations - array with language_slug as key and post_id as value. array( "it" => 1, "en" => 2 )...
$post_lang
mixed
$post_lang ( optional ) - set also the language of $post_id

Example:

CMLPost::set_translation( 1, array( "it" => 2, "en" => 3 ) )
public static
# update_meta( mixed $lang, mixed $post_id, mixed $translations = null )
public static array
# get_posts_by_language( int/slug $lang = null )

get indexes of posts that exists in selected language

get indexes of posts that exists in selected language

Parameters

$lang
int/slug
$lang ( optional, if not set will be = current language id ) id / slug of language

Returns

array
public static
# _update_posts_by_language( mixed $lang, mixed $ids )
public static array
# get_posts_by_languages( )

return all posts by languages.

return all posts by languages.

The key of array is the language id

Returns

array
public static
# has_translation( int/string $lang, integer $post_id )

check if $post_id has translation in selected language.

check if $post_id has translation in selected language.

Parameters

$lang
int/string
$lang - language id/slug
$post_id
integer
$post_id - post id return boolean
public static boolean
# has_translations( integer $post_id )

check if $post_id has any translation

check if $post_id has any translation

Parameters

$post_id
integer
$post_id - post id

Returns

boolean
public static boolean
# is_translation( integer $post1, integer $post2 )

check if $post1 is translation of $post2

check if $post1 is translation of $post2

Parameters

$post1
integer
$post1 post id
$post2
integer
$post2 post id

Returns

boolean
API documentation generated by ApiGen 2.8.0