Bundled Themes: Twenty Twenty Social Icons Filter.
Adds a Social Icons Filter to Twenty Twenty that allows for new icons to be added to the theme by filter. Props JarretC, nielslange, acosmin, desrosj. Fixes #48713. Built from https://develop.svn.wordpress.org/trunk@48180 git-svn-id: http://core.svn.wordpress.org/trunk@47949 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9a43a62970
commit
cc1af8ddb5
|
@ -29,6 +29,30 @@ if ( ! class_exists( 'TwentyTwenty_SVG_Icons' ) ) {
|
||||||
} else {
|
} else {
|
||||||
$arr = array();
|
$arr = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters Twenty Twenty's array of icons.
|
||||||
|
*
|
||||||
|
* The dynamic portion of the hook name, `$group`, refers to
|
||||||
|
* the name of the group of icons, either "ui" or "social".
|
||||||
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
*
|
||||||
|
* @param array $arr Array of icons.
|
||||||
|
*/
|
||||||
|
$arr = apply_filters( "twentytwenty_svg_icons_{$group}", $arr );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters an SVG icon's color.
|
||||||
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
*
|
||||||
|
* @param array $color The icon color.
|
||||||
|
* @param array $icon The icon name.
|
||||||
|
* @param array $group The icon group.
|
||||||
|
*/
|
||||||
|
$color = apply_filters( 'twentytwenty_svg_icon_color', $color, $icon, $group );
|
||||||
|
|
||||||
if ( array_key_exists( $icon, $arr ) ) {
|
if ( array_key_exists( $icon, $arr ) ) {
|
||||||
$repl = '<svg class="svg-icon" aria-hidden="true" role="img" focusable="false" ';
|
$repl = '<svg class="svg-icon" aria-hidden="true" role="img" focusable="false" ';
|
||||||
$svg = preg_replace( '/^<svg /', $repl, trim( $arr[ $icon ] ) ); // Add extra attributes to SVG code.
|
$svg = preg_replace( '/^<svg /', $repl, trim( $arr[ $icon ] ) ); // Add extra attributes to SVG code.
|
||||||
|
@ -51,8 +75,29 @@ if ( ! class_exists( 'TwentyTwenty_SVG_Icons' ) ) {
|
||||||
static $regex_map; // Only compute regex map once, for performance.
|
static $regex_map; // Only compute regex map once, for performance.
|
||||||
if ( ! isset( $regex_map ) ) {
|
if ( ! isset( $regex_map ) ) {
|
||||||
$regex_map = array();
|
$regex_map = array();
|
||||||
$map = &self::$social_icons_map; // Use reference instead of copy, to save memory.
|
|
||||||
foreach ( array_keys( self::$social_icons ) as $icon ) {
|
/**
|
||||||
|
* Filters Twenty Twenty's array of domain mappings for social icons.
|
||||||
|
*
|
||||||
|
* By default, each Icon ID is matched against a .com TLD. To override this behavior,
|
||||||
|
* specify all the domains it covers (including the .com TLD too, if applicable).
|
||||||
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
*
|
||||||
|
* @param array $social_icons_map Array of default social icons.
|
||||||
|
*/
|
||||||
|
$map = apply_filters( 'twentytwenty_social_icons_map', self::$social_icons_map );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters Twenty Twenty's array of social icons.
|
||||||
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
*
|
||||||
|
* @param array $social_icons Array of default social icons.
|
||||||
|
*/
|
||||||
|
$social_icons = apply_filters( 'twentytwenty_svg_icons_social', self::$social_icons );
|
||||||
|
|
||||||
|
foreach ( array_keys( $social_icons ) as $icon ) {
|
||||||
$domains = array_key_exists( $icon, $map ) ? $map[ $icon ] : array( sprintf( '%s.com', $icon ) );
|
$domains = array_key_exists( $icon, $map ) ? $map[ $icon ] : array( sprintf( '%s.com', $icon ) );
|
||||||
$domains = array_map( 'trim', $domains ); // Remove leading/trailing spaces, to prevent regex from failing to match.
|
$domains = array_map( 'trim', $domains ); // Remove leading/trailing spaces, to prevent regex from failing to match.
|
||||||
$domains = array_map( 'preg_quote', $domains );
|
$domains = array_map( 'preg_quote', $domains );
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.5-alpha-48179';
|
$wp_version = '5.5-alpha-48180';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue