elementor
1 year ago
logs
1 month ago
strong-testimonials-beaver-block
1 year ago
submodules
8 months ago
class-strong-gutemberg.php
1 year ago
class-strong-log.php
1 year ago
class-strong-mail.php
1 year ago
class-strong-testimonials-average-shortcode.php
1 year ago
class-strong-testimonials-count-shortcode.php
1 year ago
class-strong-testimonials-defaults.php
1 month ago
class-strong-testimonials-form.php
1 month ago
class-strong-testimonials-order.php
1 year ago
class-strong-testimonials-privacy.php
1 year ago
class-strong-testimonials-render.php
1 month ago
class-strong-testimonials-templates.php
1 year ago
class-strong-testimonials-view-shortcode.php
1 week ago
class-strong-testimonials-view-widget.php
1 year ago
class-strong-view-display.php
1 day ago
class-strong-view-form.php
1 day ago
class-strong-view-slideshow.php
1 day ago
class-strong-view.php
1 day ago
class-walker-strong-category-checklist-front.php
1 year ago
deprecated.php
1 year ago
filters.php
1 month ago
functions-activation.php
1 month ago
functions-content.php
11 months ago
functions-image.php
5 months ago
functions-rating.php
1 year ago
functions-template-form.php
1 week ago
functions-template.php
4 months ago
functions-views.php
1 year ago
functions.php
1 month ago
l10n-polylang.php
1 year ago
l10n-wpml.php
1 year ago
post-types.php
1 week ago
retro.php
1 year ago
scripts.php
1 month ago
l10n-wpml.php
239 lines
| 1 | <?php |
| 2 | /** |
| 3 | * ---------------------------------------- |
| 4 | * WPML |
| 5 | * ---------------------------------------- |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Add translation actions & filters. |
| 10 | */ |
| 11 | function wpmtst_l10n_filters_wpml() { |
| 12 | |
| 13 | // Admin style |
| 14 | add_action( 'admin_head-wpml-string-translation/menu/string-translation.php', 'wpmtst_admin_scripts_wpml' ); |
| 15 | add_action( 'admin_head-edit-tags.php', 'wpmtst_admin_scripts_wpml' ); |
| 16 | |
| 17 | // Translate |
| 18 | remove_filter( 'wpmtst_l10n', 'wpmtst_l10n_default' ); |
| 19 | add_filter( 'wpmtst_l10n', 'wpmtst_l10n_wpml', 10, 3 ); |
| 20 | add_filter( 'wpmtst_l10n_cats', 'wpmtst_wpml_translate_object_ids', 10, 2 ); |
| 21 | add_filter( 'get_term', 'wpmtst_wpml_get_term', 10, 2 ); |
| 22 | |
| 23 | // Update strings |
| 24 | add_action( 'update_option_wpmtst_custom_forms', 'wpmtst_form_fields_wpml', 10, 2 ); |
| 25 | add_action( 'update_option_wpmtst_form_options', 'wpmtst_form_options_wpml', 10, 2 ); |
| 26 | add_action( 'wpmtst_view_saved', 'wpmtst_update_view_wpml' ); |
| 27 | |
| 28 | // Help |
| 29 | add_action( 'wpmtst_before_form_settings', 'wpmtst_help_link_wpml' ); |
| 30 | add_action( 'wpmtst_before_fields_settings', 'wpmtst_help_link_wpml' ); |
| 31 | add_action( 'wpmtst_after_notification_fields', 'wpmtst_help_link_wpml' ); |
| 32 | } |
| 33 | add_action( 'init', 'wpmtst_l10n_filters_wpml', 20 ); |
| 34 | |
| 35 | /** |
| 36 | * @param $string |
| 37 | * @param $context |
| 38 | * @param $name |
| 39 | * |
| 40 | * @return mixed |
| 41 | */ |
| 42 | function wpmtst_l10n_wpml( $l10n_string, $context, $name ) { |
| 43 | return apply_filters( 'wpml_translate_single_string', $l10n_string, $context, $name ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Find the equivalent term ID in the current language. |
| 48 | * |
| 49 | * @since 2.2.3 |
| 50 | * |
| 51 | * @param $term |
| 52 | * @param $tax |
| 53 | * @return mixed |
| 54 | */ |
| 55 | function wpmtst_wpml_get_term( $term, $tax ) { |
| 56 | if ( 'wpm-testimonial-category' === $tax ) { |
| 57 | $term->term_id = apply_filters( 'wpmtst_wpml_translate_object_ids', $term->term_id ); |
| 58 | } |
| 59 | |
| 60 | return $term; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the translated object ID (post_type or term) or original if missing |
| 65 | * |
| 66 | * @param $object_id integer|string|array The ID/s of the objects to check and return |
| 67 | * @param object|string $type object type: post, page, {custom post type name}, nav_menu, nav_menu_item, category, tag etc. |
| 68 | * @return string|array of object ids |
| 69 | */ |
| 70 | function wpmtst_wpml_translate_object_ids( $object_id, $type = 'wpm-testimonial-category' ) { |
| 71 | |
| 72 | // if array |
| 73 | if ( is_array( $object_id ) ) { |
| 74 | $translated_object_ids = array(); |
| 75 | foreach ( $object_id as $id ) { |
| 76 | $translated_object_ids[] = apply_filters( 'wpml_object_id', $id, $type, true ); |
| 77 | } |
| 78 | return $translated_object_ids; |
| 79 | } elseif ( is_string( $object_id ) ) { |
| 80 | // check if we have a comma separated ID string |
| 81 | $is_comma_separated = strpos( $object_id, ',' ); |
| 82 | |
| 83 | if ( false !== $is_comma_separated ) { |
| 84 | // explode the comma to create an array of IDs |
| 85 | $object_id = explode( ',', $object_id ); |
| 86 | |
| 87 | $translated_object_ids = array(); |
| 88 | foreach ( $object_id as $id ) { |
| 89 | $translated_object_ids[] = apply_filters( 'wpml_object_id', $id, $type, true ); |
| 90 | } |
| 91 | |
| 92 | // make sure the output is a comma separated string (the same way it came in!) |
| 93 | return implode( ',', $translated_object_ids ); |
| 94 | } else { |
| 95 | // if we don't find a comma in the string then this is a single ID |
| 96 | return apply_filters( 'wpml_object_id', intval( $object_id ), $type, true ); |
| 97 | } |
| 98 | } else { |
| 99 | // if int |
| 100 | return apply_filters( 'wpml_object_id', $object_id, $type, true ); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Load custom style for WPML. |
| 106 | * |
| 107 | * @since 1.21.0 |
| 108 | */ |
| 109 | function wpmtst_admin_scripts_wpml() { |
| 110 | $plugin_version = get_option( 'wpmtst_plugin_version' ); |
| 111 | wp_enqueue_style( 'wpmtst-admin-style-wpml', WPMTST_ADMIN_URL . 'css/wpml.css', array(), $plugin_version ); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Register form field strings. |
| 116 | * |
| 117 | * @param $oldvalue |
| 118 | * @param $newvalue |
| 119 | * @param string $option |
| 120 | */ |
| 121 | function wpmtst_form_fields_wpml( $oldvalue, $newvalue, $option = 'wpmtst_custom_forms' ) { |
| 122 | // Reverse field order to match the form. |
| 123 | $wpml = $newvalue[1]['fields']; |
| 124 | krsort( $wpml ); |
| 125 | foreach ( $wpml as $field ) { |
| 126 | $name = $field['name'] . ' : '; |
| 127 | $context = 'strong-testimonials-form-fields'; |
| 128 | |
| 129 | /* Translators: A form field on the String Translation screen. */ |
| 130 | if ( isset( $field['after'] ) ) { |
| 131 | do_action( 'wpml_register_single_string', $context, $name . __( 'after', 'strong-testimonials' ), $field['after'] ); |
| 132 | } |
| 133 | |
| 134 | if ( isset( $field['before'] ) ) { |
| 135 | do_action( 'wpml_register_single_string', $context, $name . __( 'before', 'strong-testimonials' ), $field['before'] ); |
| 136 | } |
| 137 | |
| 138 | if ( isset( $field['placeholder'] ) ) { |
| 139 | do_action( 'wpml_register_single_string', $context, $name . __( 'placeholder', 'strong-testimonials' ), $field['placeholder'] ); |
| 140 | } |
| 141 | |
| 142 | if ( isset( $field['label'] ) ) { |
| 143 | do_action( 'wpml_register_single_string', $context, $name . __( 'label', 'strong-testimonials' ), $field['label'] ); |
| 144 | } |
| 145 | |
| 146 | if ( isset( $field['text'] ) ) { |
| 147 | do_action( 'wpml_register_single_string', $context, $name . __( 'text', 'strong-testimonials' ), $field['text'] ); |
| 148 | } |
| 149 | |
| 150 | if ( isset( $field['default_form_value'] ) ) { |
| 151 | do_action( 'wpml_register_single_string', $context, $name . __( 'default form value', 'strong-testimonials' ), $field['default_form_value'] ); |
| 152 | } |
| 153 | |
| 154 | if ( isset( $field['default_display_value'] ) ) { |
| 155 | do_action( 'wpml_register_single_string', $context, $name . __( 'default display value', 'strong-testimonials' ), $field['default_display_value'] ); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Register form option strings. |
| 162 | * |
| 163 | * @param $oldvalue |
| 164 | * @param $newvalue |
| 165 | * @param string $option |
| 166 | */ |
| 167 | function wpmtst_form_options_wpml( $oldvalue, $newvalue, $option = 'wpmtst_form_options' ) { |
| 168 | // Form messages. Reverse field order to match the form. |
| 169 | $context = 'strong-testimonials-form-messages'; |
| 170 | $wpml = $newvalue['messages']; |
| 171 | krsort( $wpml ); |
| 172 | foreach ( $wpml as $key => $field ) { |
| 173 | // We can translate here because the description was localized when added. |
| 174 | do_action( 'wpml_register_single_string', $context, $field['description'], $field['text'] ); |
| 175 | } |
| 176 | |
| 177 | // Form notification |
| 178 | $context = 'strong-testimonials-notification'; |
| 179 | do_action( 'wpml_register_single_string', $context, __( 'Email message', 'strong-testimonials' ), $newvalue['email_message'] ); |
| 180 | do_action( 'wpml_register_single_string', $context, __( 'Email subject', 'strong-testimonials' ), $newvalue['email_subject'] ); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Register "Read more" link text. |
| 185 | * |
| 186 | * @since 2.11.17 |
| 187 | * |
| 188 | * @param $options |
| 189 | */ |
| 190 | function wpmtst_readmore_wpml( $options ) { |
| 191 | $context = 'strong-testimonials-read-more'; |
| 192 | |
| 193 | /* Translators: %s is the View ID. */ |
| 194 | $string = sprintf( __( 'View %s : Read more (testimonial)', 'strong-testimonials' ), $options['id'] ); |
| 195 | do_action( 'wpml_register_single_string', $context, $string, $options['more_post_text'] ); |
| 196 | |
| 197 | /* Translators: %s is the View ID. */ |
| 198 | $string = sprintf( __( 'View %s : Read less (testimonial)', 'strong-testimonials' ), $options['id'] ); |
| 199 | do_action( 'wpml_register_single_string', $context, $string, $options['less_post_text'] ); |
| 200 | |
| 201 | /* Translators: %s is the View ID. */ |
| 202 | $string = sprintf( __( 'View %s : Read more (page or post)', 'strong-testimonials' ), $options['id'] ); |
| 203 | do_action( 'wpml_register_single_string', $context, $string, $options['more_page_text'] ); |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Update strings after updating a view. |
| 208 | * |
| 209 | * @since 2.11.17 |
| 210 | * |
| 211 | * @param $view |
| 212 | */ |
| 213 | function wpmtst_update_view_wpml( $view ) { |
| 214 | wpmtst_readmore_wpml( |
| 215 | array( |
| 216 | 'id' => $view['id'], |
| 217 | 'more_post_text' => $view['data']['more_post_text'], |
| 218 | 'less_post_text' => $view['data']['less_post_text'], |
| 219 | 'more_page_text' => $view['data']['more_page_text'], |
| 220 | ) |
| 221 | ); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Help link on various settings screens. |
| 226 | * |
| 227 | * @param $context |
| 228 | */ |
| 229 | function wpmtst_help_link_wpml( $context ) { |
| 230 | echo '<p>'; |
| 231 | echo '<span class="dashicons dashicons-info icon-blue"></span> '; |
| 232 | printf( |
| 233 | // translators: %s is the URL to the WPML String Translations page for the specific context. |
| 234 | wp_kses_post( __( 'Translate these fields in <a href="%s">WPML String Translations</a>', 'strong-testimonials' ) ), |
| 235 | esc_url( admin_url( 'admin.php?page=wpml-string-translation%2Fmenu%2Fstring-translation.php&context=strong-testimonials-' . $context ) ) |
| 236 | ); |
| 237 | echo '</p>'; |
| 238 | } |
| 239 |