Awesome migration / update admin settings * * @param Settings $settings */ public function register_admin_settings( Settings $settings ) { $settings->add_field( Settings::TAB_ADVANCED, Settings::TAB_ADVANCED, 'load_fa4_shim', [ 'label' => esc_html__( 'Load Font Awesome 4 Support', 'elementor' ), 'field_args' => [ 'type' => 'select', 'std' => '', 'options' => [ '' => esc_html__( 'No', 'elementor' ), 'yes' => esc_html__( 'Yes', 'elementor' ), ], 'desc' => esc_html__( 'Font Awesome 4 support script (shim.js) is a script that makes sure all previously selected Font Awesome 4 icons are displayed correctly while using Font Awesome 5 library.', 'elementor' ), ], ] ); } public function register_admin_tools_settings( Tools $settings ) { $settings->add_tab( 'fontawesome4_migration', [ 'label' => esc_html__( 'Font Awesome Upgrade', 'elementor' ) ] ); $settings->add_section( 'fontawesome4_migration', 'fontawesome4_migration', [ 'callback' => function() { echo '

' . esc_html__( 'Font Awesome Upgrade', 'elementor' ) . '

'; echo '

' . // PHPCS - Plain Text esc_html__( 'Access 1,500+ amazing Font Awesome 5 icons and enjoy faster performance and design flexibility.', 'elementor' ) . '
' . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped esc_html__( 'By upgrading, whenever you edit a page containing a Font Awesome 4 icon, Elementor will convert it to the new Font Awesome 5 icon.', 'elementor' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped '

' . esc_html__( 'Please note that the upgrade process may cause some of the previously used Font Awesome 4 icons to look a bit different due to minor design changes made by Font Awesome.', 'elementor' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped '

' . esc_html__( 'The upgrade process includes a database update', 'elementor' ) . ' - ' . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped esc_html__( 'We highly recommend backing up your database before performing this upgrade.', 'elementor' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped '

' . esc_html__( 'This action is not reversible and cannot be undone by rolling back to previous versions.', 'elementor' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped '

'; }, 'fields' => [ [ 'label' => esc_html__( 'Font Awesome Upgrade', 'elementor' ), 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( '%s', self::NEEDS_UPDATE_OPTION . '_upgrade', wp_create_nonce( self::NEEDS_UPDATE_OPTION ), esc_url( $this->get_upgrade_redirect_url() ), esc_html__( 'Upgrade To Font Awesome 5', 'elementor' ) ), ], ], ], ] ); } /** * Get redirect URL when upgrading font awesome. * * @return string */ public function get_upgrade_redirect_url() { if ( ! wp_verify_nonce( Utils::get_super_global_value( $_GET, '_wpnonce' ), 'tools-page-from-editor' ) ) { return ''; } $document_id = ! empty( $_GET['redirect_to_document'] ) ? absint( $_GET['redirect_to_document'] ) : null; if ( ! $document_id ) { return ''; } $document = Plugin::$instance->documents->get( $document_id ); if ( ! $document ) { return ''; } return $document->get_edit_url(); } /** * Ajax Upgrade to FontAwesome 5 */ public function ajax_upgrade_to_fa5() { check_ajax_referer( self::NEEDS_UPDATE_OPTION, '_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Permission denied' ); } delete_option( 'elementor_' . self::NEEDS_UPDATE_OPTION ); wp_send_json_success( [ 'message' => esc_html__( 'Hurray! The upgrade process to Font Awesome 5 was completed successfully.', 'elementor' ) ] ); } /** * Add Update Needed Flag * * @param array $settings * * @return array; */ public function add_update_needed_flag( $settings ) { $settings['icons_update_needed'] = true; return $settings; } public function enqueue_fontawesome_css() { if ( ! self::is_migration_allowed() ) { wp_enqueue_style( 'font-awesome' ); } else { $current_filter = current_filter(); $load_shim = get_option( self::LOAD_FA4_SHIM_OPTION_KEY, false ); if ( 'elementor/editor/after_enqueue_styles' === $current_filter ) { self::enqueue_shim(); } elseif ( 'yes' === $load_shim ) { self::enqueue_shim(); } } } /** * @deprecated 3.1.0 */ public function add_admin_strings() { Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0' ); return []; } /** * Icons Manager constructor */ public function __construct() { if ( is_admin() ) { // @todo: remove once we deprecate fa4 add_action( 'elementor/admin/after_create_settings/' . Settings::PAGE_ID, [ $this, 'register_admin_settings' ], 100 ); } if ( self::is_font_icon_inline_svg() ) { self::$data_manager = new Font_Icon_Svg_Data_Manager(); } add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_fontawesome_css' ] ); add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] ); if ( ! self::is_migration_allowed() ) { add_filter( 'elementor/editor/localize_settings', [ $this, 'add_update_needed_flag' ] ); add_action( 'elementor/admin/after_create_settings/' . Tools::PAGE_ID, [ $this, 'register_admin_tools_settings' ], 100 ); if ( ! empty( $_POST ) ) { // phpcs:ignore -- nonce validation done in callback add_action( 'wp_ajax_' . self::NEEDS_UPDATE_OPTION . '_upgrade', [ $this, 'ajax_upgrade_to_fa5' ] ); } } } }