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

Social Media Icons: update actions to filters. #2741

Merged
merged 5 commits into from Oct 22, 2015

Conversation

jeherve
Copy link
Member

@jeherve jeherve commented Sep 22, 2015

As actions, it could only echo an additional icon before or after the whole widget.

Once this is fixed, site owners will be able to use the filters like in this example:

function jetpackme_linkedin_company_icon( $html_array ) {
    return
        $html_array +
        array(
            25 =>    // This key can be modified to change the order the new item will appear in the list
                '<a title="Automattic" '
                . 'href="https://www.linkedin.com/company/automattic" '
                . 'class="genericon genericon-linkedin" target="_blank">'
                . '<span class="screen-reader-text">Automattic Company Profile</span></a>'
        );
}
add_filter( 'jetpack_social_media_icons_widget_array', 'jetpackme_linkedin_company_icon' );

@jeherve jeherve added [Type] Bug When a feature is broken and / or not performing as intended [Feature] Extra Sidebar Widgets [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Sep 22, 2015
@jeherve jeherve added this to the 3.8 milestone Sep 22, 2015
@jeherve
Copy link
Member Author

jeherve commented Sep 22, 2015

cc @macmanx2

@samhotchkiss
Copy link
Contributor

I'd lean towards a different tack here, which would be to leave the current hooks, but then, when creating the social icons, create them as an array which we then filter, then implode. This would make it much easier to insert new icons in the middle, change things for a specific icon, etc.

Thoughts?

@jeherve
Copy link
Member Author

jeherve commented Sep 30, 2015

That would work for me.

@zinigor
Copy link
Member

zinigor commented Oct 1, 2015

@samhotchkiss and @jeherve please take a look at my change. I decided to go the way Sam suggested and made the code a little more DRY in the process. This enables users to add any HTML into any place - on the ends of the list as well as in between, also change the order of icons.

@zinigor zinigor force-pushed the update/social-media-icons-filters branch 2 times, most recently from 67a5c7f to 17b95fe Compare October 2, 2015 11:11
@dereksmart
Copy link
Member

@zinigor overall looks nice -- could you please provide an example usage that we can put on our support docs?

My only real concern is there's no back compatibility for people who have set up the before/after icons with the after/before hooks. It won't throw any errors, but still would be an unexpected result of upgrading to 3.8

@macmanx2
Copy link
Contributor

macmanx2 commented Oct 5, 2015

I don't think we'll need to worry too much about folks using the old after/before hooks.

It was never published outside of here, and all the old hooks allowed for was changing the icon. Until this change goes through, there is still no way to provide a custom URL, so we really only have to worry about folks who saw the hooks in code or on GitHub and switched the icons on their existing links, which given the relevance of the icons seems unlikely.

I'm sure there are some who did that, there are always some, but I predict the user and support impact from such a change will be incredibly small.

@soulseekah
Copy link

@zinigor thank you! I was about to start writing a patch for this then found this pull request. Good stuff, I like 👍

@zinigor zinigor self-assigned this Oct 21, 2015
jeherve and others added 3 commits October 21, 2015 19:43
As actions, it could only echo an additional icon before or after the whole widget.
Prior to that we compiled the widget contents using string concatenation, this
change implements array compilation as well as changes filters to enable
users to change order of icons and add their arbitrary HTML in between or
on both ends.
Props to @brendancarr for proposing the original PR.
@zinigor zinigor force-pushed the update/social-media-icons-filters branch from 61c3bf4 to 03be982 Compare October 21, 2015 16:47
@zinigor
Copy link
Member

zinigor commented Oct 21, 2015

Added changes from #2654 and rebased this PR, should be good to go now.

@dereksmart
Copy link
Member

This shows all of the icons that link even if they're not being used.

@dereksmart dereksmart added [Status] In Progress and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Oct 21, 2015
Additionally fixed links appearing even when there are no usernames.
@zinigor
Copy link
Member

zinigor commented Oct 22, 2015

Here's an example of how you can use the newly added filter to add a new social network link:

function jetpackme_linkedin_company_icon( $html_array ) {
    return
        $html_array +
        array(
            25 =>    // This key can be modified to change the order the new item will appear in the list
                '<a title="Automattic" '
                . 'href="https://www.linkedin.com/company/automattic" '
                . 'class="genericon genericon-linkedin" target="_blank">'
                . '<span class="screen-reader-text">Automattic Company Profile</span></a>'
        );
}
add_filter( 'jetpack_social_media_icons_widget_array', 'jetpackme_linkedin_company_icon' );

@jeherve
Copy link
Member Author

jeherve commented Oct 22, 2015

Fixes #2657 and #2653

@dereksmart dereksmart added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] In Progress labels Oct 22, 2015
@dereksmart
Copy link
Member

Looks good, tests well. Thanks for the example filter.

dereksmart added a commit that referenced this pull request Oct 22, 2015
…lters

Social Media Icons: update actions to filters.
@dereksmart dereksmart merged commit e65ffec into master Oct 22, 2015
@dereksmart dereksmart removed the [Status] Ready to Merge Go ahead, you can push that green button! label Oct 22, 2015
@dereksmart dereksmart deleted the update/social-media-icons-filters branch October 22, 2015 15:09
@backpackingseries
Copy link

backpackingseries commented Jun 16, 2018

Hello,

Redirected here from WordPress support forum and posting a query for more eyes and possible help.

I want to add a Flipboard 'Follow us' icon (not a sharing button) to Jetpack Social Icon widget in WordPress.

The Flipboard icon is not part of Genericons font but, Flipboard itself offers a JS code to generate an icon.

<a data-flip-widget="ico" href="https://flipboard.com/@Backpacking73vi?utm_campaign=tools&utm_medium=follow&action=follow"><img src="https://cdn.flipboard.com/badges/flipboard_mbsw.png" alt="Flipboard" /></a><script src="https://cdn.flipboard.com/web/buttons/js/flbuttons.min.js" type="text/javascript"></script>

Though I can use this code in a custom HTML widget to display the icon, but I want it to be part of the Jetpack's social icon widget, such that all social icons (Facebook, Instagram, Flipboard, etc.) are bunched together.

Edit: I have also enqueued fontawesome (that has the Flipboard icon) with the following code:

function wmpudev_enqueue_icon_stylesheet() {
wp_register_style( 'fontawesome', 'http:////maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css' );
wp_enqueue_style( 'fontawesome');
}
add_action( 'wp_enqueue_scripts', 'wmpudev_enqueue_icon_stylesheet' );

With that in place, is there a way I could modify this GitHub code above to add the Flipboard icon?

I am not a programmer. Can someone please help resolve this?

Thank you Kind regards,

@zinigor
Copy link
Member

zinigor commented Jun 27, 2018

Hello @backpackingseries !

We have recently deprecated the widget that this PR is about. Now we are using a different Social Icon Widget to which you can add any links that you want. The problem would be adding the icon to your link, because we don't have one for Flipboard. What I see instead is a link that has icon-chain as a class.

<a href="https://flipboard.com/@Backpacking73vi?utm_campaign=tools&amp;utm_medium=follow&amp;action=follow" target="_self">
     <svg class="icon icon-chain" aria-hidden="true" role="img">
          <use href="#icon-chain" xlink:href="#icon-chain"></use>
      </svg>
</a>

If you have control over your site's theme and can add scripts or styles, you can probably add a style that would target this link with a selector like:

.jetpack-social-widget-item:last-child svg {
    display: none;

}

.jetpack-social-widget-item:last-child a {
    background: black;
}

That's assuming that your link to Flipboard is going to be last. The black background setting is just an example of how you can target the link and change the way it looks.

Hope that helps!

@backpackingseries
Copy link

Hello @zinigor,

Thank you for the help and suggesting a possible solution.

I just got off performance testing / tuning the site and had to remove few fonts that were slowing it down. I also realized that one of the plugin I use already loads Font awesome (that offers an icon for Flipboard) from the disk. However, I am not so sure whether I could tap into the local copy of the font (instead of enqueing it separately and incurring additional latency to fetch it) and will give it try along with the code above.

Though I have control over adding scripts and styles, my programming skills are limited. If it doesn't work, I will just hope for Jetpack (or Genericons) to add the Flipboard and Bloglovin icons to the social widget sometime soon!

Thanks very much once again.

Kind regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extra Sidebar Widgets [Status] Requires String Changes [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants