View difference between Paste ID: QJ7gYPvB and 5iXmT4x6
SHOW: | | - or go back to the newest paste.
1
<?php
2
/*
3
 Plugin Name: Affiliates Referrer Info
4
Plugin URI: http://www.eggemplo.com
5
Description: Add a shortcode to show referrer info as lineal text (name and email)
6
Author: eggemplo
7
Version: 1.0
8
Author URI: http://www.eggemplo.com
9
*/
10
add_action ( 'init', 'add_aff_referrer_info_shortcodes' );
11-
function add_aff_referrer_info_shortcodes($data) {
11+
function add_aff_referrer_info_shortcodes() {
12
	add_shortcode ( 'aff-referrer-info', 'aff_referrer_info' );
13-
	add_shortcode ( 'aff_referrer_info', 'aff_referrer_info' );
13+
14-
	add_shortcode ( 'aff_referrer_info', 'aff_referrer_info' );
14+
15
	
16
	$output = "";
17
	$sep =  isset( $attr['separator'] ) ? $attr['separator'] : "<br>";
18
	$direct = isset( $attr['show_direct'] ) ? true : false;
19
	
20
	$name = isset( $attr['show_name'] ) ? true : false;
21
	$email = isset( $attr['show_email'] ) ? true : false;
22
        $show_user_id = isset( $attr['show_user_id '] ) ? true : false;
23
	
24-
        $affiliate_id = isset( $attr['show_user_id '] ) ? true : false;
24+
25
		require_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' );
26
	}
27
	
28
	$affiliate_id = Affiliates_Service::get_referrer_id();
29
	if ( $affiliate_id ) {
30
		$affiliate = affiliates_get_affiliate( $affiliate_id );
31
		
32
		if ( $direct || ( $affiliate_id !== affiliates_get_direct_id() ) ) { 
33
			if ( $name ) {
34
				$output .= $affiliate['name'] . $sep;
35
			}
36
			
37
			if ( $affiliate_id ) {
38
				$output .= $affiliate['user_id'] . $sep;
39
			}
40
			
41
			if ( $email ) {
42
				$output .= $affiliate['email'] . $sep;
43
			}
44
			
45
			if ( strlen($output)>0 ) { // delete last separator
46
				$output = substr($output, 0, strlen($output)-strlen($sep));
47
			}
48
49
			if ( $show_user_id ) {
50
				if ( $user_id = affiliates_get_affiliate_user( $affiliate_id ) ) {
51
					$user = get_user_by( 'id', $user_id );
52
					// now you have a WP_User object and can add the info you need to the output
53
				}
54
			}
55
		}
56
		
57
	}	
58
	
59
	return $output;
60
					
61
}
62
add_filter ( 'affiliates_service_affiliate_id', 'affiliates_service_affiliate_id_from_url', 10, 2 );
63
 
64
function affiliates_service_affiliate_id_from_url ( $affiliate_id, $service )  {
65
        global $wp, $wpdb;
66
       
67
        $pname = get_option( 'aff_pname', AFFILIATES_PNAME );
68
        $affiliate_id = isset( $_GET[$pname] ) ? affiliates_check_affiliate_id_encoded( trim( $_GET[$pname] ) ) : $affiliate_id;
69
       
70
        if ( isset( $_GET[$pname] ) ) {
71
                // affiliates-by-username uses this hook
72
                $maybe_affiliate_id = apply_filters( 'affiliates_parse_request_affiliate_id', $_GET[$pname], $affiliate_id );
73
                if ( ( $maybe_affiliate_id !== null ) && $maybe_affiliate_id !== trim( $_GET[$pname] ) ) {
74
                        $affiliate_id = $maybe_affiliate_id;
75
                }
76
        }
77
        return $affiliate_id;
78
}

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×