Compare commits
21 Commits
Author | SHA1 | Date |
---|---|---|
|
077e4efd56 | |
|
58a428d22e | |
|
99d9818cf8 | |
|
e4ec3239a1 | |
|
b6a00a2dd6 | |
|
ab9d4348a4 | |
|
459ca3b280 | |
|
af5a01a0fd | |
|
16be5d4c36 | |
|
61bf8885fc | |
|
fd2a8d7f29 | |
|
6220e00ef7 | |
|
87c4adb238 | |
|
14e349cc23 | |
|
a2992fccb9 | |
|
c5c59d0e7c | |
|
79aa199f59 | |
|
9092977be9 | |
|
268ebe4f2b | |
|
b6d4e47d8e | |
|
68a99f3287 |
|
@ -1 +1 @@
|
|||
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-i18n'), 'version' => '16532cdc2e9643455c8b');
|
||||
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-i18n'), 'version' => '7d5db1cbc6bf460346ff');
|
||||
|
|
|
@ -1 +1 @@
|
|||
(()=>{"use strict";var e={338:(e,t,n)=>{var o=n(795);t.H=o.createRoot,o.hydrateRoot},795:e=>{e.exports=window.ReactDOM}},t={};const n=window.React;var o=function n(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,n),r.exports}(338);const i=window.lodash;const r=window.wp.i18n,{IconChooserModal:c}=(0,i.get)(window,["__FontAwesomeOfficialPlugin__","iconChooser"],{});function s(e,t,r){const s=new Event(a||`fontAwesomeIconChooser-${function(e){let t="";for(let e=0;e<16;e++)t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return t}()}`,{bubbles:!0,cancelable:!1});var a;const d=document.createElement("div");return t.appendChild(d),(0,o.H)(d).render((0,n.createElement)(c,{onSubmit:function(t){r(e,function(e){const t=[];if(!e.iconName)return void console.error("Font Awesome Icon Chooser: missing required iconName attribute for shortcode");t.push(`name="${e.iconName}"`);const n=["prefix","style","class","aria-hidden","aria-label","aria-labelledby","title","role"];for(const o of n){const n=(0,i.get)(e,o);n&&t.push(`${o}="${n}"`)}return`[icon ${t.join(" ")}]`}(t.detail))},openEvent:s})),()=>{document.dispatchEvent(s)}}function a(e,t){const n=(0,i.get)(window,`tinymce.editors.${e}`);if(n&&!n.hidden)return void n.insertContent(t);const o=window.QTags&&QTags.getInstance(e),r=function(e){const t=window.getComputedStyle(e);if("none"===t.display)return!1;if("hidden"===t.visibility)return!1;const n=e.getBoundingClientRect();return 0!==n.width&&0!==n.height}(o.canvas);o&&r&&QTags.insertContent(t,e)}function d(){const e=(0,i.get)(window,"__FontAwesomeOfficialPlugin_tinymce__.editors",[]);for(const t of e){const e=document.querySelector(`#fawp-tinymce-${t}`),n=document.querySelector(`#${t}`),o=n.parentElement;if(!n||!e||!o){console.error((0,r.__)("Font Awesome Plugin: could not attach to editor id:","font-awesome"),t);continue}const i=s(t,o,((e,t)=>{a(e,t)}));e.addEventListener("click",i)}}"complete"===document.readyState?d():window.addEventListener("DOMContentLoaded",(()=>{d()}))})();
|
||||
(()=>{"use strict";var t={338:(t,e,n)=>{var o=n(795);e.H=o.createRoot,o.hydrateRoot},795:t=>{t.exports=window.ReactDOM}},e={};const n=window.React;var o=function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}(338);const r=window.lodash;window.wp.i18n;const{IconChooserModal:i}=(0,r.get)(window,["__FontAwesomeOfficialPlugin__","iconChooser"],{}),c={};function s(t,e,c){const s=new Event(a||`fontAwesomeIconChooser-${function(t){let e="";for(let t=0;t<16;t++)e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return e}()}`,{bubbles:!0,cancelable:!1});var a;const d=document.createElement("div");return e.appendChild(d),(0,o.H)(d).render((0,n.createElement)(i,{onSubmit:function(e){c(t,function(t){const e=[];if(!t.iconName)return void console.error("Font Awesome Icon Chooser: missing required iconName attribute for shortcode");e.push(`name="${t.iconName}"`);const n=["prefix","style","class","aria-hidden","aria-label","aria-labelledby","title","role"];for(const o of n){const n=(0,r.get)(t,o);n&&e.push(`${o}="${n}"`)}return`[icon ${e.join(" ")}]`}(e.detail))},openEvent:s})),()=>{document.dispatchEvent(s)}}jQuery(document).on("click",".font-awesome-icon-chooser-media-button",(function(t){const e=function(t){if(c[t])return c[t];const e=document.querySelector(`#${t}`),n=e?.parentElement;if(!n)return;const o=s(t,n,((t,e)=>{!function(t,e){const n=(0,r.get)(window,`tinymce.editors.${t}`);if(n&&!n.hidden)return void n.insertContent(e);const o=window.QTags&&QTags.getInstance(t),i=function(t){const e=window.getComputedStyle(t);if("none"===e.display)return!1;if("hidden"===e.visibility)return!1;const n=t.getBoundingClientRect();return 0!==n.width&&0!==n.height}(o.canvas);o&&i&&QTags.insertContent(e,t)}(t,e)}));return c[t]=o,o}(t.target.getAttribute("data-fa-editor-id"));setTimeout(e,0)}))})();
|
|
@ -8,6 +8,8 @@ import { __ } from '@wordpress/i18n'
|
|||
|
||||
const { IconChooserModal } = get(window, [GLOBAL_KEY, 'iconChooser'], {})
|
||||
|
||||
const ICON_CHOOSER_OPEN_MODAL_BY_EDITOR_ID = {}
|
||||
|
||||
// Creates a new icon chooser with its own open event and submit handler.
|
||||
function newIconChooser(editorId, container, editorInsert) {
|
||||
const modalOpenEvent = createCustomEvent()
|
||||
|
@ -72,31 +74,36 @@ function insertContentIntoEditor(editorId, content) {
|
|||
}
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
const editorIds = get(window, '__FontAwesomeOfficialPlugin_tinymce__.editors', [])
|
||||
|
||||
for (const editorId of editorIds) {
|
||||
const button = document.querySelector(`#fawp-tinymce-${editorId}`)
|
||||
const editor = document.querySelector(`#${editorId}`)
|
||||
const editorContainer = editor.parentElement
|
||||
|
||||
if (!editor || !button || !editorContainer) {
|
||||
console.error(__('Font Awesome Plugin: could not attach to editor id:', 'font-awesome'), editorId)
|
||||
continue
|
||||
}
|
||||
|
||||
const openIconChooser = newIconChooser(editorId, editorContainer, (editorId, content) => {
|
||||
insertContentIntoEditor(editorId, content)
|
||||
})
|
||||
|
||||
button.addEventListener('click', openIconChooser)
|
||||
function getIconChooserOpenModal(editorId) {
|
||||
if (ICON_CHOOSER_OPEN_MODAL_BY_EDITOR_ID[editorId]) {
|
||||
return ICON_CHOOSER_OPEN_MODAL_BY_EDITOR_ID[editorId]
|
||||
}
|
||||
|
||||
const editor = document.querySelector(`#${editorId}`)
|
||||
const editorContainer = editor?.parentElement
|
||||
|
||||
if (!editorContainer) {
|
||||
// The editor might be hidden. Bail early.
|
||||
return
|
||||
}
|
||||
|
||||
const openIconChooser = newIconChooser(editorId, editorContainer, (editorId, content) => {
|
||||
insertContentIntoEditor(editorId, content)
|
||||
})
|
||||
|
||||
ICON_CHOOSER_OPEN_MODAL_BY_EDITOR_ID[editorId] = openIconChooser
|
||||
|
||||
return openIconChooser
|
||||
}
|
||||
|
||||
if (document.readyState === 'complete') {
|
||||
initialize()
|
||||
} else {
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
initialize()
|
||||
})
|
||||
}
|
||||
// Using jQuery seems to be the more idiomatic way to bind click events to the media button
|
||||
// in the WordPress editor. Doing it this way seems to resolve a conflict with the ACF plugin,
|
||||
// where our click event binding on the media button seemed to be removed on us.
|
||||
jQuery(document).on('click', '.font-awesome-icon-chooser-media-button', function(e) {
|
||||
const editorId = e.target.getAttribute('data-fa-editor-id')
|
||||
const iconChooserOpenModal = getIconChooserOpenModal(editorId)
|
||||
// This setTimeout allow for the React component that is the Icon Chooser to be mounted
|
||||
// and ready to receive the event. After the timeout expires, then the "open" event is dispatched.
|
||||
// Without this, the event is dispatched before the React component is mounted and ready to receive it.
|
||||
setTimeout(iconChooserOpenModal, 0)
|
||||
});
|
||||
|
|
|
@ -209,14 +209,14 @@ if ( ! class_exists( 'FortAwesome\FontAwesome_Loader' ) ) :
|
|||
add_action(
|
||||
'admin_notices',
|
||||
function() use ( $e ) {
|
||||
self::emit_admin_error_output( $e );
|
||||
self::emit_admin_error_output( $e, 'error' );
|
||||
}
|
||||
);
|
||||
} catch ( Error $e ) {
|
||||
add_action(
|
||||
'admin_notices',
|
||||
function() use ( $e ) {
|
||||
self::emit_admin_error_output( $e );
|
||||
self::emit_admin_error_output( $e, 'error' );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -249,10 +249,10 @@ if ( ! class_exists( 'FortAwesome\FontAwesome_Loader' ) ) :
|
|||
require_once self::$loaded['path'] . 'includes/class-fontawesome-activator.php';
|
||||
FontAwesome_Activator::activate();
|
||||
} catch ( Exception $e ) {
|
||||
self::emit_admin_error_output( $e, $activation_failed_message );
|
||||
self::emit_admin_error_output( $e, 'error', $activation_failed_message );
|
||||
exit;
|
||||
} catch ( Error $e ) {
|
||||
self::emit_admin_error_output( $e, $activation_failed_message );
|
||||
self::emit_admin_error_output( $e, 'error', $activation_failed_message );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
@ -263,28 +263,41 @@ if ( ! class_exists( 'FortAwesome\FontAwesome_Loader' ) ) :
|
|||
* @internal
|
||||
* @ignore
|
||||
*/
|
||||
public static function emit_admin_error_output( $e, $context_message = '' ) {
|
||||
public static function emit_admin_error_output( $e, $level, $context_message = '' ) {
|
||||
$message_level_class = $level === 'warning' ? 'notice notice-warning is-dismissible' : 'notice notice-error is-dismissible';
|
||||
$header_messsage_error = esc_html__( 'The Font Awesome plugin caught a fatal error', 'font-awesome' );
|
||||
$header_messsage_warning = esc_html__( 'The Font Awesome plugin has a warning', 'font-awesome' );
|
||||
$header_message = $level === 'warning' ? $header_messsage_warning : $header_messsage_error;
|
||||
|
||||
if ( is_admin() && current_user_can( 'manage_options' ) ) {
|
||||
echo '<div class="error">';
|
||||
echo '<p>' . esc_html__( 'The Font Awesome plugin caught a fatal error', 'font-awesome' );
|
||||
echo '<div class="' . esc_html( $message_level_class ) . '">';
|
||||
echo '<p>' . $header_message;
|
||||
if ( is_string( $context_message ) && '' !== $context_message ) {
|
||||
echo ': ' . esc_html( $context_message );
|
||||
} else {
|
||||
echo '.';
|
||||
}
|
||||
echo '</p><p>';
|
||||
echo '</p>';
|
||||
|
||||
if ( ! is_a( $e, 'Exception' ) && ! is_a( $e, 'Error' ) ) {
|
||||
echo '<p>';
|
||||
esc_html_e( 'No error message available.', 'font-awesome' );
|
||||
echo '</p>';
|
||||
} else {
|
||||
self::emit_error_output_to_console( $e );
|
||||
|
||||
if ( boolval( $e->getMessage() ) ) {
|
||||
echo esc_html( $e->getMessage() );
|
||||
$lines = explode("\n", $e->getMessage());
|
||||
|
||||
foreach ($lines as $line) {
|
||||
echo '<p>';
|
||||
echo esc_html( $line );
|
||||
echo '</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo '</p></div>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,10 +421,10 @@ if ( ! class_exists( 'FortAwesome\FontAwesome_Loader' ) ) :
|
|||
require_once self::$loaded['path'] . 'includes/class-fontawesome-activator.php';
|
||||
FontAwesome_Activator::initialize();
|
||||
} catch ( Exception $e ) {
|
||||
self::emit_admin_error_output( $e, $initialization_failed_msg );
|
||||
self::emit_admin_error_output( $e, 'error', $initialization_failed_msg );
|
||||
exit;
|
||||
} catch ( Error $e ) {
|
||||
self::emit_admin_error_output( $e, $initialization_failed_msg );
|
||||
self::emit_admin_error_output( $e, 'error', $initialization_failed_msg );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ require_once trailingslashit( __DIR__ ) . '../defines.php';
|
|||
require_once trailingslashit( __DIR__ ) . 'class-fontawesome.php';
|
||||
require_once trailingslashit( __DIR__ ) . 'class-fontawesome-release-provider.php';
|
||||
require_once trailingslashit( __DIR__ ) . 'class-fontawesome-svg-styles-manager.php';
|
||||
require_once trailingslashit( FONTAWESOME_DIR_PATH ) . 'includes/error-util.php';
|
||||
|
||||
/**
|
||||
* Plugin activation logic.
|
||||
|
@ -24,7 +25,13 @@ class FontAwesome_Activator {
|
|||
* @throws ReleaseProviderStorageException
|
||||
*/
|
||||
public static function activate() {
|
||||
self::initialize();
|
||||
try {
|
||||
self::initialize();
|
||||
} catch ( \Exception $e ) {
|
||||
notify_admin_fatal_error( $e );
|
||||
} catch ( \Error $e ) {
|
||||
notify_admin_fatal_error( $e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +91,9 @@ class FontAwesome_Activator {
|
|||
self::initialize_conflict_detection_options();
|
||||
}
|
||||
|
||||
self::initialize_svg_styles();
|
||||
if ( fa()->is_block_editor_support_enabled() ) {
|
||||
self::initialize_svg_styles();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,6 +149,6 @@ class FontAwesome_Activator {
|
|||
* @throws ConfigCorruptionException
|
||||
*/
|
||||
private static function initialize_svg_styles() {
|
||||
FontAwesome_SVG_Styles_Manager::instance()->fetch_svg_styles( fa(), fa_release_provider() );
|
||||
FontAwesome_SVG_Styles_Manager::instance()->ensure_svg_styles_with_admin_notice_warning( fa(), fa_release_provider() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,7 +135,15 @@ class FontAwesome_Config_Controller extends WP_REST_Controller {
|
|||
$db_item
|
||||
);
|
||||
|
||||
FontAwesome_SVG_Styles_Manager::instance()->fetch_svg_styles( fa(), $this->release_provider() );
|
||||
/**
|
||||
* The admin notices will not be shown as a consequence of any failure in this
|
||||
* function call, since this is a REST controller.
|
||||
* However, this will allow us attempt the fetch, without it causing a fatal error
|
||||
* if it fails.
|
||||
*/
|
||||
if ( fa()->is_block_editor_support_enabled() ) {
|
||||
FontAwesome_SVG_Styles_Manager::instance()->ensure_svg_styles_with_admin_notice_warning( fa(), $this->release_provider() );
|
||||
}
|
||||
|
||||
$return_data = $this->build_item( fa() );
|
||||
return new FontAwesome_REST_Response( $return_data, 200 );
|
||||
|
|
|
@ -626,3 +626,18 @@ class UpgradeException extends FontAwesome_ServerException {
|
|||
* @since 5.0.0
|
||||
*/
|
||||
class SelfhostSetupException extends FontAwesome_ServerException {}
|
||||
|
||||
/**
|
||||
* Thrown when permissions are lacking to setup self-hosting.
|
||||
*
|
||||
* @since 5.0.2
|
||||
*/
|
||||
class SelfhostSetupPermissionsException extends FontAwesome_ServerException {}
|
||||
|
||||
/**
|
||||
* Thrown when the FontAwesome_SVG_Styles_Manager attempts to check for the presence of
|
||||
* the SVG stylesheet via HTTP request, and that request fails.
|
||||
*
|
||||
* @since 5.0.2
|
||||
*/
|
||||
class SvgStylesheetCheckException extends FontAwesome_ServerException {}
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace FortAwesome;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
require_once trailingslashit( FONTAWESOME_DIR_PATH ) . 'includes/error-util.php';
|
||||
|
||||
use Exception;
|
||||
use Error;
|
||||
|
||||
/**
|
||||
* Class FontAwesome_SVG_Styles_Manager
|
||||
*/
|
||||
|
@ -14,6 +22,15 @@ class FontAwesome_SVG_Styles_Manager {
|
|||
*/
|
||||
public const RESOURCE_HANDLE_SVG_STYLES = 'font-awesome-svg-styles';
|
||||
|
||||
/**
|
||||
* The handle used when enqueuing default SVG support styles. This is a stylesheet
|
||||
* that's bundled with the plugin, and will be loaded when a version-specific stylesheet
|
||||
* cannot be loaded for some reason.
|
||||
*
|
||||
* @since 5.0.2
|
||||
*/
|
||||
public const RESOURCE_HANDLE_SVG_STYLES_DEFAULT = 'font-awesome-svg-styles-default';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @ignore
|
||||
|
@ -142,10 +159,36 @@ class FontAwesome_SVG_Styles_Manager {
|
|||
$concrete_version = $fa->concrete_version( $fa->options() );
|
||||
$source = self::selfhost_asset_url( $concrete_version );
|
||||
|
||||
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
|
||||
wp_register_style(
|
||||
self::RESOURCE_HANDLE_SVG_STYLES_DEFAULT,
|
||||
false
|
||||
);
|
||||
|
||||
/**
|
||||
* This is a minimal default style for SVGs, which will always be overriden when the
|
||||
* real stylesheet is loaded successfully. It's only here as a fallback to ensure that,
|
||||
* in the event that the real stylesheet fails to load, the SVG icons are sized
|
||||
* correctly, and aren't HUGE.
|
||||
*/
|
||||
$default_svg_style = <<< EOT
|
||||
.svg-inline--fa {
|
||||
display: inline-block;
|
||||
height: 1em;
|
||||
overflow: visible;
|
||||
vertical-align: -.125em;
|
||||
}
|
||||
EOT;
|
||||
|
||||
wp_add_inline_style(
|
||||
self::RESOURCE_HANDLE_SVG_STYLES_DEFAULT,
|
||||
$default_svg_style
|
||||
);
|
||||
|
||||
wp_register_style(
|
||||
self::RESOURCE_HANDLE_SVG_STYLES,
|
||||
$source,
|
||||
array(),
|
||||
array( self::RESOURCE_HANDLE_SVG_STYLES_DEFAULT ),
|
||||
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
|
||||
null,
|
||||
'all'
|
||||
|
@ -210,9 +253,9 @@ class FontAwesome_SVG_Styles_Manager {
|
|||
* @ignore
|
||||
* @return bool
|
||||
*/
|
||||
public function is_svg_stylesheet_present( $fa ) {
|
||||
public function is_svg_stylesheet_path_present( $fa ) {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
throw new SelfhostSetupException(
|
||||
throw new SelfhostSetupPermissionsException(
|
||||
esc_html__(
|
||||
'Current user lacks permissions required to fetch Font Awesome SVG stylesheets for self-hosting. Try logging in as an admin user.',
|
||||
'font-awesome'
|
||||
|
@ -227,7 +270,7 @@ class FontAwesome_SVG_Styles_Manager {
|
|||
}
|
||||
|
||||
if ( ! WP_Filesystem( false ) ) {
|
||||
throw new SelfhostSetupException(
|
||||
throw new SelfhostSetupPermissionsException(
|
||||
esc_html__(
|
||||
'Failed to initialize filesystem usage for creating self-hosted assets. Please report this on the plugin support forum so it can be investigated.',
|
||||
'font-awesome'
|
||||
|
@ -240,6 +283,136 @@ class FontAwesome_SVG_Styles_Manager {
|
|||
return $wp_filesystem->exists( $asset_full_path );
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use only, not part of the plugin's public API.
|
||||
*
|
||||
* This checks whether the SVG support stylesheet is present by making a HEAD
|
||||
* request on this WordPress server. This can be used when the current process
|
||||
* lacks filesystem permissions for checking the exists of the file on disk.
|
||||
*
|
||||
* @param $version a concrete Font Awesome version
|
||||
* @throws SelfhostSetupException
|
||||
* @throws SvgStylesheetCheckException
|
||||
* @throws ConfigCorruptionException when called with an invalid configuration
|
||||
* @internal
|
||||
* @ignore
|
||||
* @return bool
|
||||
*/
|
||||
public function is_svg_stylesheet_url_present( $version ) {
|
||||
$stylesheet_url = $this->selfhost_asset_url( $version );
|
||||
|
||||
$response = wp_remote_head( $stylesheet_url );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
|
||||
throw SvgStylesheetCheckException::with_wp_error( $response );
|
||||
}
|
||||
|
||||
$response_code = wp_remote_retrieve_response_code( $response );
|
||||
|
||||
return is_int( $response_code ) && $response_code >= 200 && $response_code < 300;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use only, not part of the plugin's public API.
|
||||
*
|
||||
* This checks whether the SVG support stylesheet is present.
|
||||
*
|
||||
* @param $fa FontAwesome
|
||||
* @throws SelfhostSetupException
|
||||
* @throws ConfigCorruptionException when called with an invalid configuration
|
||||
* @internal
|
||||
* @ignore
|
||||
* @return bool
|
||||
*/
|
||||
public function is_svg_stylesheet_present( $fa ) {
|
||||
try {
|
||||
// First, try using the filesystem.
|
||||
return $this->is_svg_stylesheet_path_present( $fa );
|
||||
} catch ( SelfhostSetupPermissionsException $_e ) {
|
||||
// Fallback to checking the URL via HTTP.
|
||||
$version = $fa->concrete_version( $fa->options() );
|
||||
return $this->is_svg_stylesheet_url_present( $version );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use only, not part of this plugin's public API.
|
||||
*
|
||||
* Fetches SVG support style asset(s) for self-hosting, and
|
||||
* and emits an admin notice warning when there's a problem.
|
||||
*
|
||||
* @param $fa FontAwesome
|
||||
* @param $fa_release_provider FontAwesome_Release_Provider
|
||||
* @return void
|
||||
*/
|
||||
public function ensure_svg_styles_with_admin_notice_warning( $fa, $fa_release_provider ) {
|
||||
try {
|
||||
$this->fetch_svg_styles( $fa, $fa_release_provider );
|
||||
} catch ( SelfhostSetupPermissionsException $_e ) {
|
||||
$message_main = __(
|
||||
'We couldn\'t save the stylesheet required to render SVG icons added in the Block Editor. We don\'t have permission to save files on your WordPress site. Make an exception to allow it, or place the stylesheet manually.',
|
||||
'font-awesome'
|
||||
);
|
||||
|
||||
$message_part2 = __(
|
||||
'Due to another issue, we couldn\'t determine the URL where you need to make the stylesheet available.',
|
||||
'font-awesome'
|
||||
);
|
||||
|
||||
$message_part3 = __(
|
||||
'Due to another issue, we couldn\'t find a link to the stylesheet\'s contents for you to manually place.',
|
||||
'font-awesome'
|
||||
);
|
||||
|
||||
try {
|
||||
$concrete_version = $fa->concrete_version( $fa->options() );
|
||||
$url = $this->selfhost_asset_url( $concrete_version );
|
||||
|
||||
$message_part2 = sprintf(
|
||||
/* translators: 1: newline, 2: self-hosted stylesheet URL, */
|
||||
__(
|
||||
'Here\'s the URL on your WordPress server where you need to make the stylesheet available:%1$s%2$s',
|
||||
'font-awesome'
|
||||
),
|
||||
"\n",
|
||||
$url
|
||||
);
|
||||
|
||||
$resource = $fa_release_provider->get_svg_styles_resource( $concrete_version );
|
||||
|
||||
if ( $resource->source() ) {
|
||||
$message_part3 = sprintf(
|
||||
/* translators: 1: newline, 2: Font Awesome CDN stylesheet URL */
|
||||
__(
|
||||
'Here\'s a link to the stylesheet whose contents should be copied to that location on your WordPress site:%1$s%2$s',
|
||||
'font-awesome'
|
||||
),
|
||||
"\n",
|
||||
$resource->source()
|
||||
);
|
||||
}
|
||||
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
|
||||
} catch ( Exception $_e ) {
|
||||
// Silently ignore to use the default notification message.
|
||||
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
|
||||
} catch ( Error $_e ) {
|
||||
// Silently ignore to use the default notification message.
|
||||
}
|
||||
|
||||
$full_message = $message_main . "\n" . $message_part2 . "\n" . $message_part3;
|
||||
$escaped_message = esc_html( $full_message );
|
||||
|
||||
$e = new SelfhostSetupPermissionsException( $escaped_message );
|
||||
|
||||
notify_admin_warning( $e );
|
||||
} catch ( Exception $e ) {
|
||||
notify_admin_warning( $e );
|
||||
} catch ( Error $e ) {
|
||||
notify_admin_warning( $e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use only, not part of this plugin's public API.
|
||||
*
|
||||
|
@ -252,12 +425,18 @@ class FontAwesome_SVG_Styles_Manager {
|
|||
* @throws ApiResponseException
|
||||
* @throws ReleaseProviderStorageException
|
||||
* @throws SelfhostSetupException
|
||||
* @throws SelfhostSetupPermissionsException
|
||||
* @throws ConfigCorruptionException when called with an invalid configuration
|
||||
* @return void
|
||||
*/
|
||||
public function fetch_svg_styles( $fa, $fa_release_provider ) {
|
||||
if ( $this->is_svg_stylesheet_present( $fa ) ) {
|
||||
// Nothing more to do.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
throw new SelfhostSetupException(
|
||||
throw new SelfhostSetupPermissionsException(
|
||||
esc_html__(
|
||||
'Current user lacks permissions required to fetch Font Awesome SVG stylesheets for self-hosting. Try logging in as an admin user.',
|
||||
'font-awesome'
|
||||
|
@ -265,11 +444,6 @@ class FontAwesome_SVG_Styles_Manager {
|
|||
);
|
||||
}
|
||||
|
||||
if ( $this->is_svg_stylesheet_present( $fa ) ) {
|
||||
// Nothing more to do.
|
||||
return;
|
||||
}
|
||||
|
||||
$concrete_version = $fa->concrete_version( $fa->options() );
|
||||
|
||||
$asset_path = $this->selfhost_asset_path( $concrete_version );
|
||||
|
@ -290,7 +464,7 @@ class FontAwesome_SVG_Styles_Manager {
|
|||
}
|
||||
|
||||
if ( ! WP_Filesystem( false ) ) {
|
||||
throw new SelfhostSetupException(
|
||||
throw new SelfhostSetupPermissionsException(
|
||||
esc_html__(
|
||||
'Failed to initialize filesystem usage for creating self-hosted assets. Please report this on the plugin support forum so it can be investigated.',
|
||||
'font-awesome'
|
||||
|
|
|
@ -136,7 +136,7 @@ class FontAwesome {
|
|||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public const PLUGIN_VERSION = '5.0.1';
|
||||
public const PLUGIN_VERSION = '5.0.2-2';
|
||||
/**
|
||||
* The namespace for this plugin's REST API.
|
||||
*
|
||||
|
@ -327,6 +327,17 @@ class FontAwesome {
|
|||
*/
|
||||
protected $old_remove_unregistered_clients = false;
|
||||
|
||||
/**
|
||||
* If true, features required for Block Editor support will be disabled.
|
||||
*
|
||||
* Internal use only, not part of this plugin's public API.
|
||||
*
|
||||
* @deprecated
|
||||
* @internal
|
||||
* @ignore
|
||||
*/
|
||||
protected $disable_block_editor_support = false;
|
||||
|
||||
/**
|
||||
* Returns the singleton instance of the FontAwesome plugin.
|
||||
*
|
||||
|
@ -349,7 +360,13 @@ class FontAwesome {
|
|||
* @ignore
|
||||
*/
|
||||
private function __construct() {
|
||||
/* noop */
|
||||
/**
|
||||
* Determines whether to disable features required for supporting the Block Editor.
|
||||
*
|
||||
* @return bool if `true`, disable Block Editor support
|
||||
* @since 5.0.2
|
||||
*/
|
||||
$this->disable_block_editor_support = apply_filters( 'font_awesome_disable_block_editor_support', false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -391,9 +408,18 @@ class FontAwesome {
|
|||
array( $this, 'process_shortcode' )
|
||||
);
|
||||
|
||||
FontAwesome_SVG_Styles_Manager::instance()->register_svg_styles( $this );
|
||||
if ( $this->is_block_editor_support_enabled() ) {
|
||||
FontAwesome_SVG_Styles_Manager::instance()->register_svg_styles( $this );
|
||||
|
||||
block_init();
|
||||
block_init();
|
||||
|
||||
add_action(
|
||||
'enqueue_block_assets',
|
||||
function () {
|
||||
wp_enqueue_style( FontAwesome_SVG_Styles_Manager::RESOURCE_HANDLE_SVG_STYLES );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->gather_preferences();
|
||||
|
@ -414,13 +440,6 @@ class FontAwesome {
|
|||
wp_set_script_translations( self::ADMIN_RESOURCE_HANDLE, 'font-awesome' );
|
||||
}
|
||||
|
||||
add_action(
|
||||
'enqueue_block_assets',
|
||||
function () {
|
||||
wp_enqueue_style( FontAwesome_SVG_Styles_Manager::RESOURCE_HANDLE_SVG_STYLES );
|
||||
}
|
||||
);
|
||||
|
||||
if ( $this->using_kit() ) {
|
||||
if ( $this->skip_enqueue_kit() ) {
|
||||
// Normally, conflict detection is built into a kit.
|
||||
|
@ -1037,15 +1056,32 @@ class FontAwesome {
|
|||
3
|
||||
);
|
||||
|
||||
try {
|
||||
$svg_styles_manager = FontAwesome_SVG_Styles_Manager::instance();
|
||||
if ( ! $svg_styles_manager->is_svg_stylesheet_present( $this ) ) {
|
||||
$svg_styles_manager->fetch_svg_styles( $this, $this->release_provider() );
|
||||
add_action(
|
||||
'admin_enqueue_scripts',
|
||||
function ( $hook ) {
|
||||
try {
|
||||
if ( $hook === $this->screen_id ) {
|
||||
$this->maybe_refresh_releases();
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
notify_admin_warning( $e );
|
||||
} catch ( Error $e ) {
|
||||
notify_admin_warning( $e );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if ( $this->is_block_editor_support_enabled() ) {
|
||||
try {
|
||||
$svg_styles_manager = FontAwesome_SVG_Styles_Manager::instance();
|
||||
if ( ! $svg_styles_manager->is_svg_stylesheet_present( $this ) ) {
|
||||
$svg_styles_manager->ensure_svg_styles_with_admin_notice_warning( $this, $this->release_provider() );
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
notify_admin_warning( $e );
|
||||
} catch ( Error $e ) {
|
||||
notify_admin_warning( $e );
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
notify_admin_fatal_error( $e );
|
||||
} catch ( Error $e ) {
|
||||
notify_admin_fatal_error( $e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1641,6 +1677,7 @@ class FontAwesome {
|
|||
self::ADMIN_RESOURCE_HANDLE,
|
||||
self::RESOURCE_HANDLE_ICON_CHOOSER,
|
||||
'wp-tinymce',
|
||||
'jquery',
|
||||
),
|
||||
self::PLUGIN_VERSION,
|
||||
true
|
||||
|
@ -1652,8 +1689,6 @@ class FontAwesome {
|
|||
}
|
||||
|
||||
if ( $hook === $this->screen_id ) {
|
||||
$this->maybe_refresh_releases();
|
||||
|
||||
wp_localize_script(
|
||||
self::ADMIN_RESOURCE_HANDLE,
|
||||
self::ADMIN_RESOURCE_LOCALIZATION_NAME,
|
||||
|
@ -1709,14 +1744,17 @@ class FontAwesome {
|
|||
'media_buttons',
|
||||
function ( $editor_id ) {
|
||||
printf(
|
||||
/* translators: 1: open button tag, 2: editor id, 3: remaining button tag open and icon svg tag, 4: close button tag */
|
||||
/* translators: 1: open button tag, 2: editor id value, 3: data attribute for editor id, 4: editor id value, 5: closing data attribute value quote, 6: remaining button tag open and icon svg tag, 7: close button tag */
|
||||
esc_html__(
|
||||
'%1$s%2$s%3$sAdd Font Awesome%4$s',
|
||||
'%1$s%2$s%3$s%4$s%5$s%6$sAdd Font Awesome%7$s',
|
||||
'font-awesome'
|
||||
),
|
||||
'<button type="button" id="fawp-tinymce-',
|
||||
esc_html( $editor_id ),
|
||||
'" class="button font-awesome-icon-chooser-media-button"><svg xmlns="http://www.w3.org/2000/svg" style="height: 1em; box-sizing: content-box; display: inline-block; vertical-align: -.125em;" viewBox="0 0 512 512"><path fill="currentColor" d="M91.7 96C106.3 86.8 116 70.5 116 52C116 23.3 92.7 0 64 0S12 23.3 12 52c0 16.7 7.8 31.5 20 41l0 3 0 352 0 64 64 0 0-64 373.6 0c14.6 0 26.4-11.8 26.4-26.4c0-3.7-.8-7.3-2.3-10.7L432 272l61.7-138.9c1.5-3.4 2.3-7 2.3-10.7c0-14.6-11.8-26.4-26.4-26.4L91.7 96z"/></svg> ',
|
||||
'" data-fa-editor-id="',
|
||||
esc_html( $editor_id ),
|
||||
'" ',
|
||||
'class="button font-awesome-icon-chooser-media-button"><svg xmlns="http://www.w3.org/2000/svg" style="height: 1em; box-sizing: content-box; display: inline-block; vertical-align: -.125em;" viewBox="0 0 512 512"><path fill="currentColor" d="M91.7 96C106.3 86.8 116 70.5 116 52C116 23.3 92.7 0 64 0S12 23.3 12 52c0 16.7 7.8 31.5 20 41l0 3 0 352 0 64 64 0 0-64 373.6 0c14.6 0 26.4-11.8 26.4-26.4c0-3.7-.8-7.3-2.3-10.7L432 272l61.7-138.9c1.5-3.4 2.3-7 2.3-10.7c0-14.6-11.8-26.4-26.4-26.4L91.7 96z"/></svg> ',
|
||||
'</button>'
|
||||
);
|
||||
},
|
||||
|
@ -1824,7 +1862,7 @@ class FontAwesome {
|
|||
*
|
||||
* See: https://wordpress.org/support/topic/plugin-conflicts-with-rankmath
|
||||
*/
|
||||
if ( $enable_icon_chooser && is_gutenberg_page() ) {
|
||||
if ( $enable_icon_chooser && is_gutenberg_page() && $this->is_block_editor_support_enabled() ) {
|
||||
$deps = array_merge( $deps, array( 'wp-blocks', 'wp-editor', 'wp-rich-text', 'wp-block-editor' ) );
|
||||
}
|
||||
|
||||
|
@ -3128,6 +3166,21 @@ EOT;
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to enable Font Awesome support for the Block Editor.
|
||||
*
|
||||
* This can be disabled with the `font_awesome_disable_block_editor_support` filter,
|
||||
* like this:
|
||||
*
|
||||
* `add_filter( 'font_awesome_disable_block_editor_support', '__return_true' );`
|
||||
*
|
||||
* @since 5.0.2
|
||||
* @return bool
|
||||
*/
|
||||
public function is_block_editor_support_enabled() {
|
||||
return ! $this->disable_block_editor_support;
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed
|
||||
|
|
|
@ -4,6 +4,16 @@ namespace FortAwesome;
|
|||
use WP_Error, Exception;
|
||||
require_once __DIR__ . '/../includes/class-fontawesome-command.php';
|
||||
|
||||
/**
|
||||
* Handle fatal errors
|
||||
*
|
||||
* @ignore
|
||||
* @internal
|
||||
*/
|
||||
function notify_admin_warning( $e ) {
|
||||
notify_admin( $e, 'warning' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle fatal errors
|
||||
*
|
||||
|
@ -11,14 +21,26 @@ require_once __DIR__ . '/../includes/class-fontawesome-command.php';
|
|||
* @internal
|
||||
*/
|
||||
function notify_admin_fatal_error( $e ) {
|
||||
notify_admin( $e, 'error' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify admin of error or warning.
|
||||
*
|
||||
* @ignore
|
||||
* @internal
|
||||
*/
|
||||
function notify_admin( $e, $level ) {
|
||||
$notification_level = 'warning' === $level ? 'warning' : 'error';
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( method_exists( 'FortAwesome\FontAwesome_Loader', 'emit_admin_error_output' ) ) {
|
||||
$command = new FontAwesome_Command(
|
||||
function () use ( $e ) {
|
||||
FontAwesome_Loader::emit_admin_error_output( $e );
|
||||
function () use ( $e, $notification_level ) {
|
||||
FontAwesome_Loader::emit_admin_error_output( $e, $notification_level );
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Plugin Name: Font Awesome
|
||||
* Plugin URI: https://fontawesome.com/how-to-use/on-the-web/using-with/wordpress
|
||||
* Description: The official way to use Font Awesome Free or Pro icons on your site, brought to you by the Font Awesome team.
|
||||
* Version: 5.0.1
|
||||
* Version: 5.0.2-2
|
||||
* Author: Font Awesome
|
||||
* Author URI: https://fontawesome.com/
|
||||
* License: GPLv2 (or later)
|
||||
|
|
|
@ -86,4 +86,9 @@ function theme_alpha_fa_classes() {
|
|||
return implode( ' ', $class_list );
|
||||
}
|
||||
|
||||
add_filter( 'font_awesome_skip_enqueue_kit', '__return_true' );
|
||||
// add_filter( 'font_awesome_skip_enqueue_kit', '__return_true' );
|
||||
// add_filter( 'font_awesome_disable_block_editor_support', '__return_true' );
|
||||
|
||||
// add_filter('filesystem_method', function() {
|
||||
// return 'none';
|
||||
// });
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
/*
|
||||
Theme Name: Theme Alpha
|
||||
Theme URI: http://example.com/theme-alpha/
|
||||
Description: Twenty Twenty-Two Child Theme
|
||||
Description: Twenty Twenty-Five Child Theme
|
||||
Author: John Doe
|
||||
Author URI: http://example.com
|
||||
Template: twentytwentytwo
|
||||
Template: twentytwentyfive
|
||||
Version: 0.0.1
|
||||
License: GNU General Public License v2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
|
||||
Text Domain: twenty-twenty-two-child
|
||||
Text Domain: twenty-twenty-five-child
|
||||
*/
|
||||
|
||||
.theme-alpha-explanation {
|
||||
|
|
Loading…
Reference in New Issue