Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add filter to social icons map #2212

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

leogermani
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

COPIED FROM #2170. Props to @philipjohn Just did a minor change.

Introduces a new hook for filtering the social icons map used to determine which logo to show in the social links menu.

With the introduction of Mastodon and the plethora of instances that could be used, including self-hosted instances, it would good to allow plugins and/or child themes to filter the social icons map to add additional mastodon instance addresses. This filter achieves that and can be used like so:

/**
 * Add our mastodon server to social icon map in Newspack.
 * 
 * @param array $social_icons_map Array of matches for social icons.
 * 
 * @return array Modified array of matches for social icons.
 */
function lichfieldlive_newspack_social_icons_map( $social_icons_map ) {
	$social_icons_map['mastodon'] = array_merge(
		$social_icons_map['mastodon'],
		[
			'social.lichfieldlive.co.uk',
		]
	);
	return $social_icons_map;
}
add_filter( 'newspack_social_icons_map', 'lichfieldlive_newspack_social_icons_map' );

It could also be used, for example, by Mastodon plugins such as the ActivityPub plugin to ensure the connected server is recognised. A further change to the Newspack Theme could add a compatibility layer for plugins like ActivityPub.

How to test the changes in this Pull Request:

  1. Create or edit the Social Links Menu
  2. Add a custom link to a Mastodon server account that does not already exist in the Newspack Theme's list (e.g. https://social.lichfieldlive.co.uk/@news)
  3. Using a small plugin, or child theme, create a function to add the social.lichfieldlive.co.uk domain to the social icons map (see the above example)
  4. Observe that the new item in the Social Links Menu has the Mastodon icon correctly applied (see screenshot below)

Screenshot from 2023-08-07 10-43-42

Note that as the social icons map is a static class variable it wasn't possible to add the filter to that array directly to only focus on the Mastodon map, so instead I had to filter the whole list.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@leogermani leogermani requested a review from a team as a code owner December 1, 2023 20:27
@leogermani leogermani self-assigned this Dec 1, 2023
@leogermani leogermani added the [Status] Needs Review The issue or pull request needs to be reviewed label Dec 1, 2023
@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Dec 5, 2023
@leogermani leogermani merged commit 7b6c411 into master Dec 5, 2023
@leogermani leogermani deleted the feat/add-filter-to-social-icon-map branch December 5, 2023 12:48
matticbot pushed a commit that referenced this pull request Dec 15, 2023
# [1.83.0-alpha.1](v1.82.0...v1.83.0-alpha.1) (2023-12-15)

### Features

* add filter to social icons map ([#2212](#2212)) ([7b6c411](7b6c411))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.83.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jan 8, 2024
# [1.83.0](v1.82.0...v1.83.0) (2024-01-08)

### Bug Fixes

* make sidebar donate block button style more specific ([#2217](#2217)) ([10609d7](10609d7))

### Features

* add filter to social icons map ([#2212](#2212)) ([7b6c411](7b6c411))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.83.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants