Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ipokkel/e0dcf74f47ff74cafefb559b448b62a3 to your computer and use it in GitHub Desktop.
Save ipokkel/e0dcf74f47ff74cafefb559b448b62a3 to your computer and use it in GitHub Desktop.
Add a Fontawesome 5 icon before a URL link on the PMPro Member Directory and Profile pages.
<?php
/**
* This recipe adds a Fontawesome 5 icon before a custom field containing
* a URL on the Member Directory and Profile pages.
*
* This recipe assumes that Fontawesome 5 support is made available either
* via the active theme or a plugin.
*
* WordPress auto-embeds feeds from certain oEmbed providers, e.g. Twitter.
* https://wordpress.org/support/article/embeds/
*
* You may need to disable this for the Member Directory and Profile pages
* to only display a clickable link instead of the feed.
* https://gist.github.com/ipokkel/dde134d098be8b5b6d3a7e63c79d84cc
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function fa_icons_for_pmpro_member_directory_and_profile_pages() {
global $pmpro_pages;
if ( is_page( $pmpro_pages['directory'] ) || is_page( $pmpro_pages['profile'] ) ) {
?>
<!-- Add fontawesome icons to links -->
<script>
jQuery(document).ready(function($){
$('<i class="fab fa-twitter">&nbsp;&nbsp;</i>').insertBefore( $('a[href*="twitter.com/"]') );
$('<i class="fab fa-linkedin">&nbsp;&nbsp;</i>').insertBefore( $('a[href*="linkedin.com/"]') );
});
</script>
<!-- Optional: CSS to hide field headings, reference each field according to the RH input field name used as meta key -->
<style>
p.pmpro_member_directory_linkedin_url strong,
p.pmpro_member_directory_twitter_url strong {
display: none;
}
</style>
<?php
}
}
add_action( 'wp_footer', 'fa_icons_for_pmpro_member_directory_and_profile_pages' );
<?php
/*
Example custom registration fields to capture social network URLs.
*/
function my_pmprorh_init_custom_registration_fields_for_social_urls() {
// don't break if Register Helper is not loaded
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
// define the fields
$fields = array();
$fields[] = new PMProRH_Field(
'twitter_url', // input field name, used as meta key
'text', // field type
array(
'label' => 'Twitter URL', // display custom label, if not used field name will be used
'profile' => true, // show on profile
'memberslistcsv' => true, // include when using export members to csv
'addmember' => true, // include when using add member from admin
)
);
$fields[] = new PMProRH_Field(
'linkedin_url', // input field name, used as meta key
'text', // field type
array(
'label' => 'LinkedIn URL', // display custom label, if not used field name will be used
'profile' => true, // show on profile
'memberslistcsv' => true, // include when using export members to csv
'addmember' => true, // include when using add member from admin
)
);
foreach ( $fields as $field ) {
pmprorh_add_registration_field(
'checkout_boxes ', // location on checkout page
$field // PMProRH_Field object
);
}
unset( $field );
// that's it. see the PMPro Register Helper readme for more information and examples.
}
add_action( 'init', 'my_pmprorh_init_custom_registration_fields_for_social_urls' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment