@@ -153,21 +153,64 @@ public function register_svg_styles( $fa ) {
153
153
}
154
154
155
155
/**
156
- * Internal use only, not part of this plugin's public API.
157
156
*
158
- * Fetches SVG support style asset(s) for self-hosting.
157
+ * Internal use only, not part of the plugin's public API.
158
+ *
159
+ * Returns the full path to the SVG support stylesheet on the server's filesystem.
159
160
*
160
161
* @param $fa FontAwesome
161
162
* @param $fa_release_provider FontAwesome_Release_Provider
162
163
* @throws ReleaseMetadataMissingException
163
- * @throws ApiRequestException
164
- * @throws ApiResponseException
165
164
* @throws ReleaseProviderStorageException
166
165
* @throws SelfhostSetupException
167
166
* @throws ConfigCorruptionException when called with an invalid configuration
168
- * @return void
167
+ * @internal
168
+ * @ignore
169
+ * @return string
169
170
*/
170
- public function fetch_svg_styles ( $ fa , $ fa_release_provider ) {
171
+ public function selfhost_asset_full_path ( $ fa ) {
172
+ $ options = $ fa ->options ();
173
+ $ concrete_version = $ fa ->concrete_version ( $ options );
174
+
175
+ if ( ! $ concrete_version ) {
176
+ throw new SelfhostSetupException (
177
+ esc_html__ (
178
+ 'Failed to determine Font Awesome version when setting up self-hosted assets. ' ,
179
+ 'font-awesome '
180
+ )
181
+ );
182
+ }
183
+
184
+ $ asset_path = $ this ->selfhost_asset_path ( $ concrete_version );
185
+
186
+ if ( ! $ asset_path || ! isset ( $ asset_path ['dir ' ] ) || ! isset ( $ asset_path ['file ' ] ) ) {
187
+ throw new SelfhostSetupException (
188
+ esc_html__ (
189
+ 'Failed to determine filesystem location for self-hosted asset. Please report this on the plugin support forum so it can be investigated. ' ,
190
+ 'font-awesome '
191
+ )
192
+ );
193
+ }
194
+
195
+ return trailingslashit ( $ asset_path ['dir ' ] ) . $ asset_path ['file ' ];
196
+ }
197
+
198
+ /**
199
+ * Internal use only, not part of the plugin's public API.
200
+ *
201
+ * This checks whether the SVG support stylesheet is present.
202
+ *
203
+ * @param $fa FontAwesome
204
+ * @param $fa_release_provider FontAwesome_Release_Provider
205
+ * @throws ReleaseMetadataMissingException
206
+ * @throws ReleaseProviderStorageException
207
+ * @throws SelfhostSetupException
208
+ * @throws ConfigCorruptionException when called with an invalid configuration
209
+ * @internal
210
+ * @ignore
211
+ * @return bool
212
+ */
213
+ public function is_svg_stylesheet_present ( $ fa ) {
171
214
if ( ! current_user_can ( 'manage_options ' ) ) {
172
215
throw new SelfhostSetupException (
173
216
esc_html__ (
@@ -177,18 +220,58 @@ public function fetch_svg_styles( $fa, $fa_release_provider ) {
177
220
);
178
221
}
179
222
180
- $ options = $ fa ->options ();
181
- $ concrete_version = fa ()->concrete_version ( $ options );
223
+ $ asset_full_path = $ this ->selfhost_asset_full_path ( $ fa );
182
224
183
- if ( ! $ concrete_version ) {
225
+ if ( ! function_exists ( 'WP_Filesystem ' ) ) {
226
+ require_once ABSPATH . 'wp-admin/includes/file.php ' ;
227
+ }
228
+
229
+ if ( ! WP_Filesystem ( false ) ) {
184
230
throw new SelfhostSetupException (
185
231
esc_html__ (
186
- 'Failed to determine Font Awesome version when setting up self-hosted assets. ' ,
232
+ 'Failed to initialize filesystem usage for creating self-hosted assets. Please report this on the plugin support forum so it can be investigated . ' ,
187
233
'font-awesome '
188
234
)
189
235
);
190
236
}
191
237
238
+ global $ wp_filesystem ;
239
+
240
+ return $ wp_filesystem ->exists ( $ asset_full_path );
241
+ }
242
+
243
+ /**
244
+ * Internal use only, not part of this plugin's public API.
245
+ *
246
+ * Fetches SVG support style asset(s) for self-hosting.
247
+ *
248
+ * @param $fa FontAwesome
249
+ * @param $fa_release_provider FontAwesome_Release_Provider
250
+ * @throws ReleaseMetadataMissingException
251
+ * @throws ApiRequestException
252
+ * @throws ApiResponseException
253
+ * @throws ReleaseProviderStorageException
254
+ * @throws SelfhostSetupException
255
+ * @throws ConfigCorruptionException when called with an invalid configuration
256
+ * @return void
257
+ */
258
+ public function fetch_svg_styles ( $ fa , $ fa_release_provider ) {
259
+ if ( ! current_user_can ( 'manage_options ' ) ) {
260
+ throw new SelfhostSetupException (
261
+ esc_html__ (
262
+ 'Current user lacks permissions required to fetch Font Awesome SVG stylesheets for self-hosting. Try logging in as an admin user. ' ,
263
+ 'font-awesome '
264
+ )
265
+ );
266
+ }
267
+
268
+ if ( $ this ->is_svg_stylesheet_present ( $ fa ) ) {
269
+ // Nothing more to do.
270
+ return ;
271
+ }
272
+
273
+ $ concrete_version = $ fa ->concrete_version ( $ fa ->options () );
274
+
192
275
$ asset_path = $ this ->selfhost_asset_path ( $ concrete_version );
193
276
194
277
if ( ! $ asset_path || ! isset ( $ asset_path ['dir ' ] ) || ! isset ( $ asset_path ['file ' ] ) ) {
@@ -217,11 +300,6 @@ public function fetch_svg_styles( $fa, $fa_release_provider ) {
217
300
218
301
global $ wp_filesystem ;
219
302
220
- if ( $ wp_filesystem ->exists ( $ full_asset_path ) ) {
221
- // Nothing more to do.
222
- return ;
223
- }
224
-
225
303
$ resource = $ fa_release_provider ->get_svg_styles_resource ( $ concrete_version );
226
304
227
305
if ( ! $ resource ->source () || ! $ resource ->integrity_key () ) {
0 commit comments