function qtranxf_links($links, $file, $plugin_data, $context) { $settings_link = '<a href="options-general.php?page=qtranslate-x">' . qtranxf_translate('Settings') . '</a>'; array_unshift($links, $settings_link); // before other links return $links; }
function qtranxf_add_language_menu_item(&$items, &$menu_order, &$itemid, $key, $language) { global $q_config; //qtranxf_dbg_log('qtranxf_add_language_menu_item: $key: ',$key); $item = $items[$key]; $flag_location = qtranxf_flag_location(); $altlang = null; $url = ''; //options $type = 'LM'; //[LM|AL] $title = 'Language'; //[none|Language|Current] $current = true; //[shown|hidden] $flags = true; //[none|all|items] $lang_names = true; //names=[shown|hidden] $colon = true; //[shown|hidden] $topflag = true; $p = strpos($item->url, '?'); if ($p !== FALSE) { $qs = substr($item->url, $p + 1); $qs = str_replace('#', '', $qs); $pars = array(); parse_str($qs, $pars); if (isset($pars['type']) && stripos($pars['type'], 'AL') !== FALSE) { $type = 'AL'; } if (isset($pars['flags'])) { $flags = stripos($pars['flags'], 'no') === FALSE; if ($flags) { $topflag = stripos($pars['flags'], 'items') === FALSE; } else { $topflag = false; } } if (isset($pars['names'])) { $lang_names = stripos($pars['names'], 'hid') === FALSE; } if (isset($pars['title'])) { $title = $pars['title']; if (stripos($pars['title'], 'no') !== FALSE) { $title = ''; } if (!$topflag && empty($title)) { $title = 'Language'; } } if (isset($pars['colon'])) { $colon = stripos($pars['colon'], 'hid') === FALSE; } if (isset($pars['current'])) { $current = stripos($pars['current'], 'hid') === FALSE; } if (!$lang_names && !$flags) { $flags = true; } } if ($type == 'AL') { foreach ($q_config['enabled_languages'] as $lang) { if ($lang == $language) { continue; } $toplang = $lang; $altlang = $lang; break; } $item->title = empty($title) ? '' : $q_config['language_name'][$toplang]; $item->url = qtranxf_convertURL($url, $altlang, false, true); } else { $toplang = $language; if (empty($title)) { $item->title = ''; } elseif (stripos($title, 'Current') !== FALSE) { $item->title = $q_config['language_name'][$toplang]; } else { $blocks = qtranxf_get_language_blocks($item->title); if (count($blocks) <= 1) { //no customization is done $item->title = qtranxf_translate('Language'); } else { $item->title = qtranxf_use_block($language, $blocks); } } $item->url = '#'; //qtranxf_convertURL($url, $language, false, true); } if ($topflag) { if (!empty($item->title)) { if ($colon) { $item->title .= _x(':', 'Colon after a title. For example, in top item of Language Menu.', 'qtranslate'); } $item->title .= ' '; } $item->title .= '<img src="' . $flag_location . $q_config['flag'][$toplang] . '" alt="' . $q_config['language_name'][$toplang] . '" />'; //.' '.__('Flag', 'qtranslate') } if (empty($item->attr_title)) { $item->attr_title = $q_config['language_name'][$toplang]; } //$item->classes[] = 'qtranxs_flag_'.$language; $item->classes[] = 'qtranxs-lang-menu'; $item->classes[] = 'qtranxs-lang-menu-' . $toplang; //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: top $item: ',$item); $qtransmenu = $item; //find children in case this function was already applied (customize.php on menu change) foreach ($items as $k => $item) { if ($item->menu_item_parent != $qtransmenu->ID) { continue; } unset($items[$k]); } foreach ($q_config['enabled_languages'] as $lang) { if ($type == 'AL') { if ($lang == $language) { continue; } if ($lang == $altlang) { continue; } } elseif (!$current) { if ($lang == $language) { continue; } } $item = new WP_Post((object) array('ID' => ++$itemid)); //add properties required for nav_menu_item, whose absense causes class-wp-customize-setting.php to throw Exception in function __construct //$item->db_id=$item->ID; //$item->url='';//gets assigned later $item->target = ''; $item->description = ''; $item->xfn = ''; //set properties for language menu item $item->menu_item_parent = $qtransmenu->ID; $item->menu_order = ++$menu_order; $item->post_type = 'nav_menu_item'; $item->object = 'custom'; $item->object_id = $qtransmenu->object_id; $item->type = 'custom'; $item->type_label = 'Custom'; $item->title = ''; if ($flags) { $item->title = '<img src="' . $flag_location . $q_config['flag'][$lang] . '" alt="' . $q_config['language_name'][$lang] . '" />'; } if ($lang_names) { if ($flags) { $item->title .= ' '; } $item->title .= $q_config['language_name'][$lang]; } $item->post_title = $item->title; $item->post_name = 'language-menuitem-' . $lang; //if($lang!=$language){ menu url should not be empty $item->url = qtranxf_convertURL($url, $lang, false, true); $item->url = esc_url($item->url); //not sure if this is needed //} $item->attr_title = $q_config['language_name'][$lang]; $item->classes = array(); //$item->classes[] = 'qtranxs_flag_'.$lang; $item->classes[] = 'qtranxs-lang-menu-item'; $item->classes[] = 'qtranxs-lang-menu-item-' . $lang; //qtx specific properties $item->item_lang = $lang; //to store the language assigned $items[] = $item; //qtranxf_dbg_log('qtranxf_add_language_menu_item: language menu $item',$item); } }
function qtranxf_admin_notices_config() { global $q_config; if (empty($q_config['url_info']['errors']) && empty($q_config['url_info']['warnings']) && empty($q_config['url_info']['messages'])) { return; } $screen = get_current_screen(); $link = isset($screen->id) && $screen->id == 'settings_page_qtranslate-x' ? '' : '<a href="' . admin_url('options-general.php?page=qtranslate-x') . '" style="color:magenta">qTranslate‑X</a>: '; if (isset($q_config['url_info']['errors']) && is_array($q_config['url_info']['errors'])) { foreach ($q_config['url_info']['errors'] as $key => $msg) { echo '<div class="error notice is-dismissible" id="qtranxs_error_' . $key . '"><p>' . $link . '<strong><span style="color: red;">' . qtranxf_translate('Error') . '</span></strong>: ' . $msg . '</p></div>'; } unset($q_config['url_info']['errors']); } if (isset($q_config['url_info']['warnings']) && is_array($q_config['url_info']['warnings'])) { foreach ($q_config['url_info']['warnings'] as $key => $msg) { echo '<div class="update-nag notice is-dismissible" id="qtranxs_warning_' . $key . '"><p>' . $link . '<strong><span style="color: blue;">' . qtranxf_translate('Warning') . '</span></strong>: ' . $msg . '</p></div>'; } unset($q_config['url_info']['warnings']); } if (isset($q_config['url_info']['messages']) && is_array($q_config['url_info']['messages'])) { foreach ($q_config['url_info']['messages'] as $key => $msg) { echo '<div class="updated notice is-dismissible" id="qtranxs_message_' . $key . '"><p>' . $link . $msg . '</p></div>'; } unset($q_config['url_info']['messages']); } }