| @@ -25,10 +25,11 @@ | ||
| 25 | 25 | add_filter('template_include', array( $this, 'view_project_template') ); |
| 26 | 26 | |
| 27 | 27 | add_filter('theme_page_templates', array( $this, 'register_project_templates_update') ); |
| 28 | 28 | |
| 29 | + // Initialize template keys without translation (translation happens lazily) | |
| 29 | 30 | $this->templates = array( |
| 30 | - 'template-contact.php' => __('Contact', 'virtue-toolkit'), | |
| 31 | + 'template-contact.php' => 'Contact', | |
| 31 | 32 | ); |
| 32 | 33 | |
| 33 | 34 | } |
| 34 | 35 | |
| @@ -57,11 +58,15 @@ | ||
| 57 | 58 | |
| 58 | 59 | } |
| 59 | 60 | public function register_project_templates_update($templates ) { |
| 60 | 61 | if ( ! version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) { |
| 62 | + // Translate template names when they're actually needed (after init) | |
| 63 | + $translated_templates = array(); | |
| 64 | + foreach ( $this->templates as $key => $label ) { | |
| 65 | + $translated_templates[ $key ] = __( $label, 'virtue-toolkit' ); | |
| 66 | + } | |
| 67 | + $templates = array_merge( $templates, $translated_templates ); | |
| 61 | 68 | |
| 62 | - $templates = array_merge( $templates, $this->templates ); | |
| 63 | - | |
| 64 | 69 | } |
| 65 | 70 | return $templates; |
| 66 | 71 | |
| 67 | 72 | } |
| @@ -121,10 +126,13 @@ | ||
| 121 | 126 | add_filter('wp_insert_post_data', array( $this, 'register_project_templates' ) ); |
| 122 | 127 | |
| 123 | 128 | add_filter('template_include', array( $this, 'view_project_template') ); |
| 124 | 129 | |
| 130 | + add_filter('theme_page_templates', array( $this, 'register_project_templates_update') ); | |
| 131 | + | |
| 132 | + // Initialize template keys without translation (translation happens lazily) | |
| 125 | 133 | $this->templates = array( |
| 126 | - 'page-contact.php' => __('Contact', 'virtue-toolkit'), | |
| 134 | + 'page-contact.php' => 'Contact', | |
| 127 | 135 | ); |
| 128 | 136 | |
| 129 | 137 | } |
| 130 | 138 | |
| @@ -149,8 +157,21 @@ | ||
| 149 | 157 | // available templates |
| 150 | 158 | wp_cache_add( $cache_key, $templates, 'themes', 1800 ); |
| 151 | 159 | |
| 152 | 160 | return $atts; |
| 161 | + | |
| 162 | + } | |
| 163 | + public function register_project_templates_update($templates ) { | |
| 164 | + if ( ! version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) { | |
| 165 | + // Translate template names when they're actually needed (after init) | |
| 166 | + $translated_templates = array(); | |
| 167 | + foreach ( $this->templates as $key => $label ) { | |
| 168 | + $translated_templates[ $key ] = __( $label, 'virtue-toolkit' ); | |
| 169 | + } | |
| 170 | + $templates = array_merge( $templates, $translated_templates ); | |
| 171 | + | |
| 172 | + } | |
| 173 | + return $templates; | |
| 153 | 174 | |
| 154 | 175 | } |
| 155 | 176 | |
| 156 | 177 | /** |