Displaying a Language Specific Course

Generally speaking the following technique can be used in any case in which the learner should see a different course based on some user-based criteria, like language.

In this example, our use case is we have a user profile field that contains the learner's selected language.

It is then possible to use the bright_course_id PHP level filter to set the course GUID based on this profile field.

For example, see the snippet below. In this case, the learner's selected language is in
a user meta field called 'language'.

function localized_course_id($course_guid,$attrs) {

  $bright = \Bright\Wordpress::getInstance();
  $current_user = $bright->getCurrentUser();
  $language = get_user_meta($current_user->ID, 'language', TRUE);
  if (empty($language))
    $language = 'english';

  $languages = array (
    'english' => '1922c3842-984f-4977-bd51-5a783a3c6013',
    'french' => 'FR0215cd23-d7d3-4805-b182-2efb8afb0e8f',
    'dutch' => 'NLad14066c-5890-4ed4-8249-1c96c99485e3',
    'german' => 'DE2bf8bb56-4c20-4513-adce-c19fd4b38a48'
  );

  if (array_key_exists($language,$languages))
    return $languages[$language];
  return $languages['english'];
}

To install this use

add_filter('bright_course_id', 'localized_course_id',1,2);

For this to work correctly you must leave the course_id= attribute blank in your
shortcode.