Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Filter languages in bulk tools
- */
- function pm_ignore_lang_posts($default_uri, $native_slug, $object, $slug, $native_uri) {
- global $permalink_manager_uris;
- // 1A. Do not use for native permalinks
- if(!empty($native_uri)) { return $default_uri; }
- // 1B. Use only for bulk tools!
- if(empty($_REQUEST['mode']) || $_REQUEST['mode'] !== 'custom_uris') { return $default_uri; }
- // 1C. Regenerate all items if no language is selected
- if(!empty($_REQUEST['languages']) && is_array($_REQUEST['languages'])) {
- $selected_languages = $_REQUEST['languages'];
- } else {
- return $default_uri;
- }
- // 2. Get language of post/term
- $language_code = Permalink_Manager_Language_Plugins::get_language_code($object);
- // 3. Get object ID
- if(!empty($object->ID)) {
- $object_id = $object->ID;
- } else if(!empty($object->term_taxonomy_id)) {
- $object_id = "tax-{$object->term_taxonomy_id}";
- } else {
- return $default_uri;
- }
- // 4. Restore old custom permalink if post/term has no language set or language is different than selected
- if((empty($language_code) || !in_array($language_code, $selected_languages))) {
- $default_uri = (!empty($permalink_manager_uris[$object_id])) ? $permalink_manager_uris[$object_id] : $default_uri;
- }
- return $default_uri;
- }
- add_filter('permalink_manager_filter_default_post_uri', 'pm_ignore_lang_posts', 99, 5);
- add_filter('permalink_manager_filter_default_term_uri', 'pm_ignore_lang_posts', 99, 5);
- /**
- * Add "Languages field"
- */
- function pm_tools_language_field($fields) {
- $wpml_languages = apply_filters('wpml_active_languages', NULL, 'orderby=id&order=desc');
- if(!empty($wpml_languages)) {
- $all_languages = array();
- foreach($wpml_languages as $language) {
- $all_languages[$language['language_code']] = $language['translated_name'];
- }
- if(!empty($all_languages)) {
- $fields['languages'] = array(
- 'label' => __( 'Select languages', 'permalink-manager' ),
- 'type' => 'checkbox',
- 'container' => 'row',
- 'choices' => $all_languages,
- 'select_all' => '',
- 'unselect_all' => '',
- );
- }
- }
- return $fields;
- }
- add_filter('permalink_manager_tools_fields', 'pm_tools_language_field', 99);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement