| @@ -17,12 +17,29 @@ | ||
| 17 | 17 | add_filter( 'gkt_icons_list', array( $this, 'add_font_awesome_icons' ), 9 ); |
| 18 | 18 | |
| 19 | 19 | // enqueue icons |
| 20 | 20 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_all_icons_assets' ), 12 ); |
| 21 | - add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_all_icons_assets' ), 12 ); | |
| 21 | + add_action( 'enqueue_block_assets', array( $this, 'enqueue_editor_icons_assets' ), 12 ); | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | + * Enqueue editor assets. | |
| 26 | + * | |
| 27 | + * Icons are rendered inside the block editor canvas, which is always iframed since | |
| 28 | + * WordPress 7.1. `enqueue_block_assets` is the only hook whose output core copies into | |
| 29 | + * that iframe, so icon packs have to be enqueued from there rather than from | |
| 30 | + * `enqueue_block_editor_assets` (which stays outside the canvas). | |
| 31 | + */ | |
| 32 | + public function enqueue_editor_icons_assets() { | |
| 33 | + // The frontend is already covered by the `wp_enqueue_scripts` hook above. | |
| 34 | + if ( ! is_admin() ) { | |
| 35 | + return; | |
| 36 | + } | |
| 37 | + | |
| 38 | + $this->enqueue_all_icons_assets(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 25 | 42 | * Enqueue frontend & editor assets |
| 26 | 43 | */ |
| 27 | 44 | public function enqueue_all_icons_assets() { |
| 28 | 45 | $icons = apply_filters( 'gkt_icons_list', array() ); |
| @@ -29,11 +46,22 @@ | ||
| 29 | 46 | $settings = get_option( 'ghostkit_settings', array() ); |
| 30 | 47 | |
| 31 | 48 | do_action( 'gkt_icons_enqueue_assets' ); |
| 32 | 49 | |
| 50 | + $detected_packs = apply_filters( 'gkt_icons_detected_packs', null ); | |
| 51 | + | |
| 33 | 52 | if ( ! empty( $icons ) ) { |
| 34 | 53 | foreach( $icons as $key => $icon ) { |
| 35 | 54 | $allow_icon = ! isset( $settings[ 'icon_pack_' . $key ] ) || isset( $settings[ 'icon_pack_' . $key ] ) && $settings[ 'icon_pack_' . $key ]; |
| 55 | + | |
| 56 | + if ( | |
| 57 | + null !== $detected_packs | |
| 58 | + && is_array( $detected_packs ) | |
| 59 | + && ! is_admin() | |
| 60 | + && ! in_array( $key, $detected_packs, true ) | |
| 61 | + ) { | |
| 62 | + continue; | |
| 63 | + } | |
| 36 | 64 | |
| 37 | 65 | if ( $allow_icon ) { |
| 38 | 66 | do_action( 'gkt_icons_enqueue_assets__' . $key ); |
| 39 | 67 | } |