Advertisement
palsushobhan

vendor-twitch-social-profile-link

Aug 27th, 2024 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. add_filter('wcfm_profile_fields_social', function($social_fields, $vendor_id) {
  2.     $vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
  3.     $social_accounts = $vendor_data['social'] ?? array();
  4.     $twitch = $social_accounts['twitch'] ?? '';
  5.     return array_merge(
  6.         $social_fields,
  7.         array(
  8.             "twitch" => array(
  9.                 'label' => __('Twitch', 'wc-frontend-manager') ,
  10.                 'type' => 'text',
  11.                 'class' => 'wcfm-text wcfm_ele',
  12.                 'label_class' => 'wcfm_title wcfm_ele',
  13.                 'value' => $twitch,
  14.                 'placeholder' => __('Twitch Handler', 'wc-frontend-manager')
  15.             )
  16.         )
  17.     );
  18. }, 10, 2);
  19.  
  20. add_filter('wcfm_profile_social_types', function($types) {
  21.     return array_merge(
  22.         $types,
  23.         ['twitch' => 'twitch',]
  24.     );
  25. });
  26.  
  27. add_action('wcfmmp_store_after_social', function($vendor_id) {
  28.     ?>
  29.     <style>
  30.         .store-twitch-logo{
  31.             display: block;
  32.             margin-top: 50%;
  33.             transform: translateY(-50%);
  34.         }
  35.         .store-twitch-logo svg {
  36.             display: block;
  37.             margin: 0 auto;
  38.             width: 15px;
  39.         }
  40.         .store-twitch-logo svg path {
  41.             fill: #17a2b8;
  42.         }
  43.         #wcfmmp-store .social_area ul li:hover .store-twitch-logo svg path {
  44.             fill: #fff;
  45.         }
  46.     </style>
  47.     <?php
  48.     $store_info = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
  49.     if( isset( $store_info['social']['twitch'] ) && !empty( $store_info['social']['twitch'] ) ) { ?>
  50.         <li><a href="<?php echo wcfmmp_generate_social_url( $store_info['social']['twitch'], 'twitch' ); ?>" class="store-twitch-logo" target="_blank">
  51.         <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M2.149 0l-1.612 4.119v16.836h5.731v3.045h3.224l3.045-3.045h4.657l6.269-6.269v-14.686h-21.314zm19.164 13.612l-3.582 3.582h-5.731l-3.045 3.045v-3.045h-4.836v-15.045h17.194v11.463zm-3.582-7.343v6.262h-2.149v-6.262h2.149zm-5.731 0v6.262h-2.149v-6.262h2.149z" fill-rule="evenodd" clip-rule="evenodd"/></svg>
  52.     </a></li>
  53.     <?php }
  54. });
  55. add_filter('wcfm_social_url', function($social_handle, $social) {
  56.     if( $social == 'twitch' && strpos( $social_handle, 'twitch' ) === false) {
  57.         $social_handle = 'https://www.twitch.tv/' . $social_handle;
  58.     }
  59.     return $social_handle;
  60. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement