<?php

use Supertext\Polylang\Helper\Constant;
use Supertext\Polylang\Api\Multilang;
use Supertext\Polylang\Api\Wrapper;
use Comotive\Util\ArrayManipulation;
/** @var Page $context */
$library = $context->getCore()->getLibrary();
$options = $library->getSettingOption();
$languageMap = isset($options[Constant::SETTING_LANGUAGE_MAP]) ? ArrayManipulation::forceArray($options[Constant::SETTING_LANGUAGE_MAP]) : array();
// Laod Languages from Polylang to match with supertext api
$htmlLanguageDropdown = '';
// Create the language matcher dropdown
foreach (Multilang::getLanguages() as $language) {
    // Get anonymous wrapper to get languages
    $api = Wrapper::getInstance();
    $stMapping = $api->getLanguageMapping($language->slug);
    $languageDropdown = '';
    foreach ($stMapping as $languageCode => $languageName) {
        $selected = '';
        if (isset($languageMap[$language->slug]) && $languageMap[$language->slug] == $languageCode) {
            $selected = ' selected';
        }
        $languageDropdown .= '<option value="' . $languageCode . '"' . $selected . '>' . $languageName . '</option>';
    }
    $languageDropdown = '
    <select name="sel_st_language_' . $language->slug . '" id="sel_st_language_' . $language->slug . '">
      <option value="">' . __('Please select', 'polylang-supertext') . '...</option>
      ' . $languageDropdown . '
    </select>';
    $htmlLanguageDropdown .= '
Ejemplo n.º 2
0
 /**
  * Get an API wrapper as an authenticated user
  * @param int $userId
  * @return Wrapper prepared api wrapper
  */
 public function getUserWrapper($userId = 0)
 {
     // Get currently logged in user, if no user given
     if ($userId == 0) {
         $userId = get_current_user_id();
     }
     // Try to find credentials
     $userId = intval($userId);
     $credentials = $this->getUserCredentials($userId);
     // Get the ready to call instance
     return Wrapper::getInstance($credentials['stUser'], $credentials['stApi']);
 }