/** * If the given $source is an error type, it will display an instant message * * @param $source WP_Error|TranslationProxy_Api_Error|Exception */ function icl_handle_error($source) { $error = false; if (is_translationproxy_api_error($source)) { $error = array('message' => $source->getMessage(), 'code' => $source->getCode()); } elseif (is_exception($source)) { $error = array('message' => $source->getMessage(), 'code' => $source->getCode()); } elseif (is_wp_error($source)) { $error = array('message' => $source->get_error_message(), 'data' => $source->get_error_data(), 'code' => $source->get_error_code()); } if ($error) { $message = ''; $message .= '<strong>'; if (isset($error['code']) && $error['code']) { $message .= '#' . $error['code'] . ' '; } $message .= $error['message']; $message .= '</strong>'; if (isset($error['data'])) { foreach ($error['data'] as $data_key => $data_item) { if ($data_key == 'details') { $message .= '<br/>Details: ' . $data_item; } elseif ($data_key == 'service_id') { $message .= '<br/>Service ID: ' . $data_item; } else { $message .= '<br/><pre>' . print_r($data_item, true) . '</pre>'; } } } ICL_AdminNotifier::displayInstantMessage($message, 'error'); } return $error; }
function render() { global $wp_taxonomies; $icl_post_types = $this->sitepress->get_translatable_documents(true); $cposts = array(); $notice = ''; foreach ($icl_post_types as $k => $v) { if (!in_array($k, array('post', 'page'))) { $cposts[$k] = $v; } } $cpt_sync_settings = $this->sitepress->get_setting('custom_posts_sync_option'); foreach ($cposts as $k => $cpost) { if (!isset($cpt_sync_settings[$k])) { $cposts_sync_not_set[] = $cpost->labels->name; } } if (!empty($cposts_sync_not_set)) { $notice = '<p class="updated fade">'; $notice .= sprintf(__("You haven't set your <a %s>synchronization preferences</a> for these custom posts: %s. Default value was selected.", 'sitepress'), 'href="admin.php?page=' . WPML_TM_FOLDER . '/menu/main.php&sm=mcsetup"', '<i>' . join('</i>, <i>', $cposts_sync_not_set) . '</i>'); $notice .= '</p>'; } $icl_post_types = $this->sitepress->get_translatable_documents(true); if ($icl_post_types) { $custom_posts = array(); $icl_post_types = $this->sitepress->get_translatable_documents(true); foreach ($icl_post_types as $k => $v) { if (!in_array($k, array('post', 'page'))) { $custom_posts[$k] = $v; } } $slug_settings = $this->sitepress->get_setting('posts_slug_translation'); foreach ($custom_posts as $k => $custom_post) { $_has_slug = isset($custom_post->rewrite['slug']) && $custom_post->rewrite['slug']; $_translate = !empty($slug_settings['types'][$k]); if ($_has_slug) { $string_id_prepared = $this->wpdb->prepare("SELECT id FROM {$this->wpdb->prefix}icl_strings WHERE name = %s AND value = %s ", array('Url slug: ' . trim($custom_post->rewrite['slug'], '/'), trim($custom_post->rewrite['slug'], '/'))); $string_id = $this->wpdb->get_var($string_id_prepared); if ($slug_settings['on'] && $_translate && !$string_id) { $message = sprintf(__("%s slugs are set to be translated, but they are missing their translation", 'sitepress'), $custom_post->labels->name); $notice .= ICL_AdminNotifier::displayInstantMessage($message, 'error', 'below-h2', true); } } } } $ctaxonomies = array_diff(array_keys((array) $wp_taxonomies), array('post_tag', 'category', 'nav_menu', 'link_category', 'post_format')); $tax_sync_settings = $this->sitepress->get_setting('taxonomies_sync_option'); foreach ($ctaxonomies as $ctax) { if (!isset($tax_sync_settings[$ctax])) { $tax_sync_not_set[] = $wp_taxonomies[$ctax]->label; } } if (!empty($tax_sync_not_set)) { $notice .= '<p class="updated">'; $notice .= sprintf(__("You haven't set your <a %s>synchronization preferences</a> for these taxonomies: %s. Default value was selected.", 'sitepress'), 'href="admin.php?page=' . WPML_TM_FOLDER . '/menu/main.php&sm=mcsetup"', '<i>' . join('</i>, <i>', $tax_sync_not_set) . '</i>'); $notice .= '</p>'; } return $notice; }
function print_translatable_custom_content_status() { global $wp_taxonomies; $icl_post_types = $this->get_translatable_documents(true); $cposts = array(); $notice = ''; foreach ($icl_post_types as $k => $v) { if (!in_array($k, array('post', 'page'))) { $cposts[$k] = $v; } } foreach ($cposts as $k => $cpost) { if (!isset($this->settings['custom_posts_sync_option'][$k])) { $cposts_sync_not_set[] = $cpost->labels->name; } } if (defined('WPML_TM_VERSION') && !empty($cposts_sync_not_set)) { $notice = '<p class="updated fade">'; $notice .= sprintf(__("You haven't set your <a %s>synchronization preferences</a> for these custom posts: %s. Default value was selected.", 'sitepress'), 'href="admin.php?page=' . WPML_TM_FOLDER . '/menu/main.php&sm=mcsetup"', '<i>' . join('</i>, <i>', $cposts_sync_not_set) . '</i>'); $notice .= '</p>'; } $icl_post_types = $this->get_translatable_documents(true); if (defined('WPML_TM_VERSION') && $icl_post_types) { global $wpdb, $sitepress_settings; $default_language = $this->get_default_language(); $custom_posts = array(); $icl_post_types = $this->get_translatable_documents(true); foreach ($icl_post_types as $k => $v) { if (!in_array($k, array('post', 'page'))) { $custom_posts[$k] = $v; } } foreach ($custom_posts as $k => $custom_post) { $_has_slug = isset($custom_post->rewrite['slug']) && $custom_post->rewrite['slug']; $_translate = !empty($sitepress_settings['posts_slug_translation']['types'][$k]); if ($_has_slug) { if (isset($sitepress_settings['st']) && $default_language != $sitepress_settings['st']['strings_language']) { $string_id_prepared = $wpdb->prepare("\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT s.id FROM {$wpdb->prefix}icl_strings s\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_string_translations st\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON st.string_id = s.id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE st.language=%s AND s.value=%s AND s.name LIKE %s\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t", array($default_language, $custom_post->rewrite['slug'], 'URL slug: %')); } else { $string_id_prepared = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}icl_strings WHERE name = %s AND value = %s ", array('Url slug: ' . $custom_post->rewrite['slug'], $custom_post->rewrite['slug'])); } $string_id = $wpdb->get_var($string_id_prepared); if ($_translate && !$string_id) { $message = sprintf(__("%s slugs are set to be translated, but they are missing their translation", 'sitepress'), $custom_post->labels->name); $notice .= ICL_AdminNotifier::displayInstantMessage($message, 'error', 'below-h2', true); } } } } $ctaxonomies = array_diff(array_keys((array) $wp_taxonomies), array('post_tag', 'category', 'nav_menu', 'link_category', 'post_format')); foreach ($ctaxonomies as $ctax) { if (!isset($this->settings['taxonomies_sync_option'][$ctax])) { $tax_sync_not_set[] = $wp_taxonomies[$ctax]->label; } } if (defined('WPML_TM_VERSION') && !empty($tax_sync_not_set)) { $notice .= '<p class="updated">'; $notice .= sprintf(__("You haven't set your <a %s>synchronization preferences</a> for these taxonomies: %s. Default value was selected.", 'sitepress'), 'href="admin.php?page=' . WPML_TM_FOLDER . '/menu/main.php&sm=mcsetup"', '<i>' . join('</i>, <i>', $tax_sync_not_set) . '</i>'); $notice .= '</p>'; } echo $notice; }
/> <br/><br/> <div class="icl_tm_error" id="icl_dup_ovr_warn" style="display: none"> <?php esc_html_e('Any existing content (translations) will be overwritten when creating duplicates.', 'wpml-translation-management'); ?> <br/> <?php esc_html_e("When duplicating content, please first duplicate parent pages to maintain the site's hierarchy.", 'wpml-translation-management'); ?> </div> <?php } else { $message = _('You currently have no active alternate languages!', 'wpml-translation-management'); ICL_AdminNotifier::displayInstantMessage($message, 'error'); } ?> </td> </tr> </tbody> </table> </form> <br /> <?php $ICL_Pro_Translation->get_icl_manually_tranlations_box('icl_cyan_box'); // shows only when translation polling is on and there are translations in progress ?>
?> <?php $_has_slug = isset($custom_post->rewrite['slug']) && $custom_post->rewrite['slug']; $_on = $sitepress_settings['posts_slug_translation']['on'] && $_has_slug && isset($sitepress_settings['custom_posts_sync_option'][$k]) && $sitepress_settings['custom_posts_sync_option'][$k] == 1; $is_hidden = $_on ? '' : 'hidden'; $_translate = !empty($sitepress_settings['posts_slug_translation']['types'][$k]); if ($_has_slug) { if ($default_language != $sitepress_settings['st']['strings_language']) { $string_id_prepared = $wpdb->prepare("\r\n SELECT s.id FROM {$wpdb->prefix}icl_strings s\r\n JOIN {$wpdb->prefix}icl_string_translations st\r\n ON st.string_id = s.id\r\n WHERE st.language=%s AND s.value=%s AND s.name LIKE %s\r\n ", array($default_language, $custom_post->rewrite['slug'], 'URL slug: %')); } else { $string_id_prepared = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}icl_strings WHERE name = %s AND value = %s ", array('Url slug: ' . $custom_post->rewrite['slug'], $custom_post->rewrite['slug'])); } $string_id = $wpdb->get_var($string_id_prepared); if ($_translate && !$string_id) { $message = sprintf(__("%s slugs are set to be translated, but they are missing their translation", 'sitepress'), $custom_post->labels->name); ICL_AdminNotifier::displayInstantMessage($message, 'error', 'below-h2', false); } $_slug_translations = icl_get_string_translations_by_id($string_id); } else { $_slug_translations = false; } ?> <?php if ($_has_slug && isset($sitepress_settings['posts_slug_translation']['on']) && $sitepress_settings['posts_slug_translation']['on']) { ?> <div class="icl_slug_translation_choice <?php echo $is_hidden; ?> "> <p> <label>
public function render($post_type, $custom_post) { $_has_slug = isset($custom_post->rewrite['slug']) && $custom_post->rewrite['slug']; $_on = $this->settings->is_on() && $_has_slug && $this->post_sync_setting->is_sync($post_type); $is_hidden = $_on ? '' : 'hidden'; $_translate = $this->settings->is_translate($post_type); $string_id = null; if ($_has_slug) { list($string_id, $_slug_translations) = WPML_Slug_Translation::get_translations($post_type); if ($this->settings->is_on() && $_translate && !$string_id) { $message = sprintf(__("%s slugs are set to be translated, but they are missing their translation", 'sitepress'), $custom_post->labels->name); ICL_AdminNotifier::displayInstantMessage($message, 'error', 'below-h2', false); } } else { $_slug_translations = false; } if ($_has_slug && $this->settings->is_on()) { ?> <div class="icl_slug_translation_choice <?php echo $is_hidden; ?> "> <p> <label> <input name="translate_slugs[<?php echo $post_type; ?> ][on]" type="checkbox" value="1" <?php checked(1, $_translate, true); ?> /> <?php printf(__('Use different slugs in different languages for %s.', 'sitepress'), $custom_post->labels->name); ?> </label> </p> <table class="js-cpt-slugs <?php if (empty($_translate)) { ?> hidden<?php } ?> "> <?php if ($string_id) { $string = new WPML_ST_String($string_id, $this->wpdb); $string_lang = $string->get_language(); } else { $string_lang = ''; } $string_lang = $string_lang ? $string_lang : $this->sitepress->get_default_language(); $languages = $this->sitepress->get_active_languages(); if (!in_array($string_lang, array_keys($languages))) { $all_languages = $this->sitepress->get_languages(); $languages[$string_lang] = $all_languages[$string_lang]; } $original_slug = WPML_Slug_Translation::get_slug_by_type($post_type); $original_slug = $original_slug ? $original_slug : (isset($custom_post->slug) ? $custom_post->slug : $custom_post->rewrite['slug']); foreach ($languages as $language) { $slug_translation_value = !empty($_slug_translations[$language['code']]['value']) ? $_slug_translations[$language['code']]['value'] : ''; $slug_translation_sample = $original_slug . ' @' . $language['code']; ?> <tr<?php if ($language['code'] == $string_lang) { echo ' style="display:none"'; } ?> > <td> <label for="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]"><?php echo $this->sitepress->get_flag_img($language['code']) . ' ' . $language['display_name']; ?> </label> </td> <td> <input id="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]" class="js-translate-slug" name="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]" type="text" value="<?php echo $slug_translation_value; ?> " placeholder="<?php echo $slug_translation_sample; ?> " data-lang="<?php echo $language['code']; ?> " /> <?php if (isset($_slug_translations[$language['code']]) && $_slug_translations[$language['code']]['status'] != ICL_TM_COMPLETE) { ?> <em class="icl_st_slug_tr_warn"><?php _e("Not marked as 'complete'. Press 'Save' to enable.", 'sitepress'); ?> </em> <?php } ?> </td> </tr> <?php if ($language['code'] == $string_lang) { ?> <tr> <td> <?php $lang_selector = new WPML_Simple_Language_Selector($this->sitepress); $lang_selector->render(array('name' => 'translate_slugs[' . $post_type . '][original]', 'selected' => $language['code'], 'show_please_select' => false, 'echo' => true, 'class' => 'js-translate-slug-original', 'data' => array('slug' => $post_type))); ?> <label for="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]"> <em><?php _e("(original)", 'sitepress'); ?> </em></label> </td> <td><input disabled="disabled" class="disabled" id="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]" name="translate_slugs[<?php echo $post_type; ?> ][langs][<?php echo $language['code']; ?> ]" type="text" value="<?php echo $original_slug; ?> "/> </td> </tr> <?php } } ?> </table> </div> <?php } }