Skip to content

Commit

Permalink
add global configuration variables for font directory
Browse files Browse the repository at this point in the history
  • Loading branch information
madhusudhand committed Dec 14, 2023
1 parent 4fb8952 commit 8bfa658
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
13 changes: 4 additions & 9 deletions lib/experimental/fonts/font-library/class-wp-font-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function get_font_collection( $id ) {
* @return string Path of the upload directory for fonts.
*/
public static function get_fonts_dir() {
return path_join( WP_CONTENT_DIR, 'fonts' );
return ( defined( 'WP_FONT_DIR' ) && ! empty( WP_FONT_DIR ) ) ? WP_FONT_DIR : path_join( WP_CONTENT_DIR, 'fonts' );
}

/**
Expand All @@ -119,19 +119,14 @@ public static function get_fonts_dir() {
*
* @type string $path Path to the directory.
* @type string $url URL for the directory.
* @type string $subdir Sub-directory of the directory.
* @type string $basedir Base directory.
* @type string $baseurl Base URL.
* }
* @return array Modified upload directory.
*/
public static function set_upload_dir( $defaults ) {
$defaults['basedir'] = WP_CONTENT_DIR;
$defaults['baseurl'] = content_url();
$defaults['subdir'] = '/fonts';
$defaults['path'] = self::get_fonts_dir();
$defaults['url'] = $defaults['baseurl'] . '/fonts';
$font_url = ( defined( 'WP_FONT_URL' ) && ! empty( WP_FONT_URL ) ) ? set_url_scheme( WP_FONT_URL ) : content_url( 'fonts' );

$defaults['path'] = self::get_fonts_dir();
$defaults['url'] = untrailingslashit( $font_url );
return $defaults;
}

Expand Down
14 changes: 4 additions & 10 deletions phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ class Tests_Fonts_WpFontLibrary_SetUploadDir extends WP_UnitTestCase {

public function test_should_set_fonts_upload_dir() {
$defaults = array(
'subdir' => '/abc',
'basedir' => '/any/path',
'baseurl' => 'http://example.com/an/arbitrary/url',
'path' => '/any/path/abc',
'url' => 'http://example.com/an/arbitrary/url/abc',
'path' => '/any/path/abc',
'url' => 'http://example.com/an/arbitrary/url/abc',
);
$expected = array(
'subdir' => '/fonts',
'basedir' => WP_CONTENT_DIR,
'baseurl' => content_url(),
'path' => path_join( WP_CONTENT_DIR, 'fonts' ),
'url' => content_url() . '/fonts',
'path' => path_join( WP_CONTENT_DIR, 'fonts' ),
'url' => content_url( 'fonts' ),
);
$this->assertSame( $expected, WP_Font_Library::set_upload_dir( $defaults ) );
}
Expand Down

0 comments on commit 8bfa658

Please sign in to comment.