- availability:
WPML Version: 3.2
- description:
Registers string packages for translation. It allows for strings to registered in bulk* if the package translation plugin is activated after content has been created.
*String packages would otherwise be registered with wpml_register_string and their translations retrieved with wpml_translate_string
Note: This hook requires the WPML String Translation module
- type:
- action
- category:
- Inserting Content
- parameters:
do_action( 'wpml_register_string_packages', string $type, array $existing )
- $type
- (string) (Required) The type of package to register. This matches the ‘kind’ array key in the $packages parameter as documented for wpml_register_string
- $existing
- (array) (Required) An array of existing package names. Use this so that existing packages are not re-registered. This matches the ‘name’ array key in the $packages parameter as documented for wpml_register_string
- hook example usage:
Example using Layouts
add_action('wpml_register_string_packages', 'register_all_for_translation', 10, 2); function register_all_for_translation($type, $existing) { global $wpdb; if ($type == 'layout') { $layouts = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'dd_layouts' AND post_status = 'publish'"); foreach ($layouts as $layout_id) { if (!in_array($layout_id, $existing)) { // register the strings in this layout for translation $this->register_strings_for_translation($layout_id); } } } }