Created
July 5, 2017 08:40
-
-
Save albionselimaj/3b569012a296cc27ecbe800e97e3a6e2 to your computer and use it in GitHub Desktop.
Override Elementor's 'Icon' control to include custom icon packs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Elementor; | |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
/** | |
* A Font Icon select box. | |
*/ | |
class CASE27_Elementor_Control_Icon extends Control_Base { | |
public function get_type() { | |
return 'icon'; | |
} | |
public static function get_icons() { | |
$icons = []; | |
// Get arrays of icons. | |
$font_awesome_icons = require '/path/to/font-awesome.php'; | |
$material_icons = require '/path/to/material-icons.php'; | |
$custom_icons = require '/path/to/custom-icons.php'; | |
foreach ($font_awesome_icons as $icon) { | |
$icons["fa {$icon}"] = str_replace('fa-', '', $icon); | |
} | |
foreach ($material_icons as $icon) { | |
$icons["material-icons {$icon}"] = $icon; | |
} | |
foreach ($custom_icons as $icon) { | |
$icons[$icon] = str_replace('icon-', '', $icon); | |
} | |
return $icons; | |
} | |
protected function get_default_settings() { | |
return [ | |
'icons' => self::get_icons(), | |
]; | |
} | |
public function content_template() { | |
?> | |
<div class="elementor-control-field"> | |
<label class="elementor-control-title">{{{ data.label }}}</label> | |
<div class="elementor-control-input-wrapper"> | |
<select class="elementor-control-icon" data-setting="{{ data.name }}" data-placeholder="<?php _e( 'Select Icon', 'elementor' ); ?>"> | |
<option value=""><?php _e( 'Select Icon', 'elementor' ); ?></option> | |
<# _.each( data.icons, function( option_title, option_value ) { #> | |
<option value="{{ option_value }}">{{{ option_title }}}</option> | |
<# } ); #> | |
</select> | |
</div> | |
</div> | |
<# if ( data.description ) { #> | |
<div class="elementor-control-field-description">{{ data.description }}</div> | |
<# } #> | |
<?php | |
} | |
} | |
add_action('elementor/controls/controls_registered', function($el) { | |
$el->register_control('icon', new CASE27_Elementor_Control_Icon); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is /path/to/font-awesome.php? Where should I get this file?