Multisite Language Switcher Simple, powerful and easy to use

Hooks, filters & actions

The Multisite Language Switcher provides some filters and actions, which are very useful for programmers who want to interact with the plugin from their functions and classes.

And again: Always backup your files and database prior to work on your site, better safe than sorry.

Read first the introduction provided by the WordPress community if you don't know what hooks are.

msls_admin_icon_get_edit_new

If you want to change the link of the admin icon in case there is no object connected then this filter is for you. The default is that the link points to the 'create new page' of this object type.

Example:

This would add the parameter 'abc' with the value 'xyz' to the url path.

msls_admin_language_section \ msls_admin_main_section \ msls_admin_advanced_section

If you want to add custom input fields to the existing sections in the settings of the plugin then you can use one of these actions.

This would add an input field 'custom field' to the main-section of the settings-page.

msls_admin_register

If you want to add a completely customized settings section to the configuration-pages of the Multisite Language Switcher then you can use this action.

Example:

This would add a section with the id 'custom section' and an input field 'custom field' to the settings-page of the plugin.

msls_admin_validate

You can use this filter if you want to add some custom validation for an input field in the configuration page of the plugin.

Example:

This can be useful if you have added your own input fields to this page using an action hook like 'msls_admin_register'.

msls_blog_collection_construct

You can easily manipulate the blog collection.

Example:

This would exclude the blog with the ID 1 from the collection.

msls_blog_collection_description

The description string of every blog is not fixed. You can override it.

Example:

This would give the blog with the ID 1 the description 'abc' and the blog with the ID 2 the name 'xyz.

msls_filter_string

You can override the string for the output of the translation hint. $output contains the original string and $links is an array of generated links to the available translations.

Example:

You can use the following code if you want to remove this filter completely:

remove_action( 'the_content', 'msls_content_filter' );

msls_head_hreflang

The plugin creates automatically hreflang annotations in the head of the generated HTML using the code of the language only (eg. en, de, fr). You can easily override this value:

Example:

You can use the following code if you want to remove these tags completely:

remove_action( 'wp_head', 'msls_head' );

msls_link_create

There is also a way to manipulate the inner HTML in the generated links. Just create your own MslsLink class.

Example:

This adds label tags to the descriptional text after the flag icon.

msls_main_save

With this action you can call a completely customized save-routine.

Example:

Use this action only if you exactly know what you do!

msls_meta_box_render_input_button

You can change or hide the button of the meta box in the edit-screen with this filter.

Example:

This wraps the code of the submit-button into HTML comments.

msls_meta_box_suggest_args / msls_post_tag_suggest_args

Maybe you will find it useful to be able to override the WP_Query $args for the auto-complete search-field in the meta box which you can see in the edit-screen of the various post-types or taxonomies of your WordPress site.

Example:

This would limit the output of the results to a maximum of 5 posts.

msls_meta_box_render_select_hierarchical

This is only valid for hierarchical post types that use the HTML select (and not the new autocomplete inputs)in the meta box.

This adds various poststati to the array _$args for wp\dropdown_pages even if this function does not expect this. But inside the function is a call to get\pages_ that can use this param.

msls_meta_box_suggest_post / msls_post_tag_suggest_term

You can even manipulate the WP_Post- or Term-objects in the result-set created in 'msls_meta_box_suggest_args' or 'msls_post_tag_suggest_args'.

Example:

This would add the post_id to the title of the posts in the autocomplete-field of the meta box.

msls_options_get_available_languages

You can create a custom function to filter the available languages used in the language section of the plugin-settings.

Example:

Even if it is still not fully tested, it seems to be a smart way to add a language without the language files installed. In this case it would solve the issue with the American flag and the Union Jack.

msls_options_get_flag_url

You can set the path to the flag-icons in the admin settings of the plugin but you can also override the path with a filter.

Example:

This 'sets' the path to the flag icons to the directory 'images' in the active theme.

msls_options_get_permalink

I decided to add a filter to the implementation of get_permalink in the plugin so that I can offer a workaround for the issues with the possibility to localize the slugs of custom post types.

Example:

This replaces the 'products'-part in the URL with 'produkte' if $language is 'de_DE'.

msls_output_get

You can use this filter if you want to change the format of the generated links to the translations in your blog.

Example:

This would transform the absolute URL in a relative one and would add the css-class 'current' to the link of the current blog.

msls_output_get_tags

You can configure the output-tags in the admin settings of the plugin but you can also override these with a filter.

This would override completely the configuration without looking for existing values.

Fork me on GitHub