Posted on Leave a comment

extended_referrer_user shortcode

This shortcode can be used to render information about the referring affiliate’s user account.
This shortcode allows the use of the following attributes:

fields: allows to indicate which fields are to appear. For example first_name, last_name…

add_shortcode( 'extended_referrer_user', 'my_extended_referrer_user' );
function my_extended_referrer_user ( $atts, $content = null ) {
  $atts = shortcode_atts(
    array(
     'fields' => ''
    ),
    $atts
  );
  $fields = null;
  if ( !empty( $atts['fields'] ) ) {
    $fields = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['fields'] ) ) );
  }
  if ( $fields ) {
    require_once AFFILIATES_CORE_LIB . '/class-affiliates-service.php';
    $affiliate_id = Affiliates_Service::get_referrer_id();
    if ( $affiliate_id ) {
      $user_id = affiliates_get_affiliate_user( $affiliate_id );
      if ( ( $affiliate_id !== affiliates_get_direct_id() ) ) {
        if ( $user_id ) {
          foreach ( $fields as $field ) {
            echo get_user_meta($user_id, $field, true) . '
';
          }
        }
      }
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *