Browse Source

first commit

main
Paul Pound 3 weeks ago
commit
de59955563
  1. 45
      h5p-core-fonts-fix.php

45
h5p-core-fonts-fix.php

@ -0,0 +1,45 @@
<?php
/**
* Plugin Name: H5P core fonts fix
* Description: Re-adds styles/h5p-fonts.css to H5PCore::$styles, which Pressbooks' vendored h5p-core 1.27 omits.
*
* Pressbooks pins h5p/h5p-core 1.27.0 and requires it eagerly through Composer's
* autoload_files.php, so it defines H5PCore before the H5P plugin's lazy autoloader
* (h5p/autoloader.php) ever gets a chance to. H5PCore::$styles is therefore always the
* 1.27 list, while H5P_Plugin::add_core_assets() resolves those filenames against the
* H5P plugin's own h5p-php-library (1.28+), where the icon @font-face was moved out of
* h5p.css into h5p-fonts.css.
*
* Net effect: h5p-fonts.css never makes it into H5PIntegration.core.styles, so the
* document.write()n content iframe has no 'h5p' icon font and the action bar renders
* Reuse/Embed/Rights of use with tofu boxes instead of icons (and the H5P logo link,
* being icon-only, disappears entirely).
*
* Remove this once Pressbooks' vendored h5p-core catches up with the H5P plugin's
* h5p-php-library.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'plugins_loaded', function () {
if ( ! class_exists( 'H5PCore' ) ) {
return;
}
// add_core_assets() resolves these against plugins_url('h5p/h5p-php-library').
$library_dir = WP_PLUGIN_DIR . '/h5p/h5p-php-library/';
$missing = [];
foreach ( [ 'styles/h5p-fonts.css' ] as $style ) {
if ( ! in_array( $style, H5PCore::$styles, true ) && file_exists( $library_dir . $style ) ) {
$missing[] = $style;
}
}
if ( $missing ) {
// Prepend, mirroring upstream ordering.
H5PCore::$styles = array_merge( $missing, H5PCore::$styles );
}
}, 100 );
Loading…
Cancel
Save