| @@ -23,10 +23,13 @@ | ||
| 23 | 23 | add_filter('wp_insert_post_data', array( $this, 'register_project_templates' ) ); |
| 24 | 24 | |
| 25 | 25 | add_filter('template_include', array( $this, 'view_project_template') ); |
| 26 | 26 | |
| 27 | + add_filter('theme_page_templates', array( $this, 'register_project_templates_update') ); | |
| 28 | + | |
| 29 | + // Initialize template keys without translation (translation happens lazily) | |
| 27 | 30 | $this->templates = array( |
| 28 | - 'template-contact.php' => __('Contact', 'virtue-toolkit'), | |
| 31 | + 'template-contact.php' => 'Contact', | |
| 29 | 32 | ); |
| 30 | 33 | |
| 31 | 34 | } |
| 32 | 35 | |
| @@ -34,9 +37,9 @@ | ||
| 34 | 37 | |
| 35 | 38 | // Create the key used for the themes cache |
| 36 | 39 | $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() ); |
| 37 | 40 | |
| 38 | - $templates = wp_get_theme()->get_page_templates(); | |
| 41 | + $templates = wp_get_theme()->get_page_templates(); | |
| 39 | 42 | |
| 40 | 43 | if ( empty( $templates ) ) { |
| 41 | 44 | $templates = array(); |
| 42 | 45 | } |
| @@ -53,9 +56,21 @@ | ||
| 53 | 56 | |
| 54 | 57 | return $atts; |
| 55 | 58 | |
| 56 | 59 | } |
| 60 | + public function register_project_templates_update($templates ) { | |
| 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 ); | |
| 57 | 68 | |
| 69 | + } | |
| 70 | + return $templates; | |
| 71 | + | |
| 72 | + } | |
| 58 | 73 | /** |
| 59 | 74 | * Checks if the template is assigned to the page |
| 60 | 75 | */ |
| 61 | 76 | public function view_project_template( $template ) { |
| @@ -111,10 +126,13 @@ | ||
| 111 | 126 | add_filter('wp_insert_post_data', array( $this, 'register_project_templates' ) ); |
| 112 | 127 | |
| 113 | 128 | add_filter('template_include', array( $this, 'view_project_template') ); |
| 114 | 129 | |
| 130 | + add_filter('theme_page_templates', array( $this, 'register_project_templates_update') ); | |
| 131 | + | |
| 132 | + // Initialize template keys without translation (translation happens lazily) | |
| 115 | 133 | $this->templates = array( |
| 116 | - 'page-contact.php' => __('Contact', 'virtue-toolkit'), | |
| 134 | + 'page-contact.php' => 'Contact', | |
| 117 | 135 | ); |
| 118 | 136 | |
| 119 | 137 | } |
| 120 | 138 | |
| @@ -139,8 +157,21 @@ | ||
| 139 | 157 | // available templates |
| 140 | 158 | wp_cache_add( $cache_key, $templates, 'themes', 1800 ); |
| 141 | 159 | |
| 142 | 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; | |
| 143 | 174 | |
| 144 | 175 | } |
| 145 | 176 | |
| 146 | 177 | /** |