22 if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ) ) ) { |
22 if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ) ) ) { |
23 return new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) ); |
23 return new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) ); |
24 } |
24 } |
25 |
25 |
26 /** |
26 /** |
27 * Allows a plugin to override the WordPress.org Translation Install API entirely. |
27 * Allows a plugin to override the WordPress.org Translation Installation API entirely. |
28 * |
28 * |
29 * @since 4.0.0 |
29 * @since 4.0.0 |
30 * |
30 * |
31 * @param bool|array $result The result object. Default false. |
31 * @param bool|array $result The result object. Default false. |
32 * @param string $type The type of translations being requested. |
32 * @param string $type The type of translations being requested. |
54 } |
54 } |
55 |
55 |
56 $request = wp_remote_post( $url, $options ); |
56 $request = wp_remote_post( $url, $options ); |
57 |
57 |
58 if ( $ssl && is_wp_error( $request ) ) { |
58 if ( $ssl && is_wp_error( $request ) ) { |
59 trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); |
59 trigger_error( |
|
60 sprintf( |
|
61 /* translators: %s: support forums URL */ |
|
62 __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
|
63 __( 'https://wordpress.org/support/' ) |
|
64 ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), |
|
65 headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE |
|
66 ); |
60 |
67 |
61 $request = wp_remote_post( $http_url, $options ); |
68 $request = wp_remote_post( $http_url, $options ); |
62 } |
69 } |
63 |
70 |
64 if ( is_wp_error( $request ) ) { |
71 if ( is_wp_error( $request ) ) { |
65 $res = new WP_Error( 'translations_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() ); |
72 $res = new WP_Error( 'translations_api_failed', |
|
73 sprintf( |
|
74 /* translators: %s: support forums URL */ |
|
75 __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
|
76 __( 'https://wordpress.org/support/' ) |
|
77 ), |
|
78 $request->get_error_message() |
|
79 ); |
66 } else { |
80 } else { |
67 $res = json_decode( wp_remote_retrieve_body( $request ), true ); |
81 $res = json_decode( wp_remote_retrieve_body( $request ), true ); |
68 if ( ! is_object( $res ) && ! is_array( $res ) ) { |
82 if ( ! is_object( $res ) && ! is_array( $res ) ) { |
69 $res = new WP_Error( 'translations_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) ); |
83 $res = new WP_Error( 'translations_api_failed', |
|
84 sprintf( |
|
85 /* translators: %s: support forums URL */ |
|
86 __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
|
87 __( 'https://wordpress.org/support/' ) |
|
88 ), |
|
89 wp_remote_retrieve_body( $request ) |
|
90 ); |
70 } |
91 } |
71 } |
92 } |
72 } |
93 } |
73 |
94 |
74 /** |
95 /** |
75 * Filter the Translation Install API response results. |
96 * Filters the Translation Installation API response results. |
76 * |
97 * |
77 * @since 4.0.0 |
98 * @since 4.0.0 |
78 * |
99 * |
79 * @param object|WP_Error $res Response object or WP_Error. |
100 * @param object|WP_Error $res Response object or WP_Error. |
80 * @param string $type The type of translations being requested. |
101 * @param string $type The type of translations being requested. |
92 * |
113 * |
93 * @return array Array of translations, each an array of data. If the API response results |
114 * @return array Array of translations, each an array of data. If the API response results |
94 * in an error, an empty array will be returned. |
115 * in an error, an empty array will be returned. |
95 */ |
116 */ |
96 function wp_get_available_translations() { |
117 function wp_get_available_translations() { |
97 if ( ! defined( 'WP_INSTALLING' ) && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) { |
118 if ( ! wp_installing() && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) { |
98 return $translations; |
119 return $translations; |
99 } |
120 } |
100 |
121 |
101 include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version |
122 include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version |
102 |
123 |
177 // Check if the translation is already installed. |
200 // Check if the translation is already installed. |
178 if ( in_array( $download, get_available_languages() ) ) { |
201 if ( in_array( $download, get_available_languages() ) ) { |
179 return $download; |
202 return $download; |
180 } |
203 } |
181 |
204 |
182 if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
205 if ( ! wp_is_file_mod_allowed( 'download_language_pack' ) ) { |
183 return false; |
206 return false; |
184 } |
207 } |
185 |
208 |
186 // Confirm the translation is one we can download. |
209 // Confirm the translation is one we can download. |
187 $translations = wp_get_available_translations(); |
210 $translations = wp_get_available_translations(); |
220 * @since 4.0.0 |
243 * @since 4.0.0 |
221 * |
244 * |
222 * @return bool Returns true on success, false on failure. |
245 * @return bool Returns true on success, false on failure. |
223 */ |
246 */ |
224 function wp_can_install_language_pack() { |
247 function wp_can_install_language_pack() { |
225 if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
248 if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) { |
226 return false; |
249 return false; |
227 } |
250 } |
228 |
251 |
229 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
252 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
230 $skin = new Automatic_Upgrader_Skin; |
253 $skin = new Automatic_Upgrader_Skin; |